Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include <random>
  3. #include <math.h>
  4. #include <iostream>
  5. int main()
  6. {
  7.     std::default_random_engine rnd(7);
  8.     std::weibull_distribution<double> distribution(0.5, 1.0);
  9.     double eta = 0;
  10.     double k = 1;
  11.     double s = 0;
  12.     double s1 = 0;
  13.     int N = 100000;
  14.     for (int i = 0; i < N; i++)
  15.     {
  16.         double x = distribution(rnd);
  17.         double y = distribution(rnd);
  18.         eta = 4 * cos(2 * k * pow(x * y, 0.5)) * (exp(-(x+y)+pow(x,0.5)+pow(y,0.5)));
  19.         s += eta;
  20.         s1 += eta * eta;
  21.     }
  22.     std::cout << s << '\n';
  23.     double d = s1 / N - pow(s / N, 2);
  24.     std::cout <<"precise value"<<"\n"<<M_PI/sqrt(1+k*k) << "\n";
  25.     std::cout <<"approximate value"<< "\n" << s / N << "\n";
  26.     std::cout<<"miscalculation"<< "\n" << 3 * sqrt(d / N);
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement