Advertisement
dmkozyrev

temp.cpp

Apr 9th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. inline double f(const double x, const double a, const double b) {
  7.     return (1-cos(b*x))/(x*x)*exp(-a*x);
  8. }
  9.  
  10. const double pi = acos(-1.0);
  11.  
  12. int main() {
  13.     const double a = 0.5, b = 0.4;
  14.     const double h = 0.01;
  15.     const int N = 10000000;
  16.     double s = 0.5 + 4*f(h, a, b) + f(2*h, a, b);
  17.     double s2 = 0.5 + f(2*h, a, b);
  18.     double x = 2*h;
  19.     for (int i = 1; i < N; ++i) {
  20.         s2 += f(x, a, b);
  21.         s += f(x, a, b);
  22.         x += h;
  23.         s += 4*f(x, a, b);
  24.         x += h;
  25.         s += f(x, a, b);
  26.         s2 += f(x, a, b);
  27.     }
  28.     cout << s * h / 3 << " ?= " << " ?= " << s2 * h
  29.         << " ?= (formula) " << b*b/(2*a)*(1-exp(-a*pi/b));
  30.  
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement