Advertisement
greedydev

Gaussian

Oct 12th, 2022
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. namespace myfuncs {
  2.     // calculate the power
  3.     double pow(double x, int n) {
  4.         double result = 1;
  5.         for (int i = 0; i < n; i++) {
  6.             result *= x;
  7.         }
  8.         return result;
  9.     }
  10.  
  11.     double gaussian(double x, double eps) {
  12.         double result = 0;
  13.         double term = 1;
  14.         int n = 0;
  15.         while (term > eps) {
  16.             term = pow(x, 2 * n + 1) / (2 * n + 1);
  17.             result += term;
  18.             n++;
  19.         }
  20.         return result;
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement