Aleksandr_Grigoryev

семестровая 2

Dec 17th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. const double PI = 3.14;
  4. const int m = 6;
  5. const double e = 0.3;
  6. double cos(double x)
  7. {
  8.     double t = 1.0;
  9.     double s = 0.0;
  10.     int n = 1;
  11.  
  12.     do
  13.     {
  14.         s+= t;
  15.         t *= -1.0 * x * x / ((2 * n - 1) * (2 * n));
  16.         n++;
  17.     } while (fabs(t) > 0.00001);
  18.  
  19.     return s;
  20. }
  21. double function1(double x)
  22. {
  23.     double psi;
  24.     psi = cos(x)*cos(x);
  25.  
  26.  
  27.     return(psi);
  28. }
  29. double function2(double x)
  30. {
  31.     double  fi;
  32.  
  33.     fi = (2.7*x) / (5.7 - 0.9*x + x*x);
  34.  
  35.     return(fi);
  36. }
  37. double F(double x, double t)
  38. {
  39.     return function2(x)*function1(x + t / (1 + x*x));
  40. }
  41. double integral(double a, double b, double t)
  42. {
  43.     double h, Jn, J2n;
  44.     int i;
  45.     int n = 1;
  46.     do
  47.     {
  48.         Jn = 0;
  49.         h = (b - a) / n;
  50.         for(int i = 1; i < n; i++)
  51.         {
  52.             Jn += F(a + i*h, t);
  53.         }
  54.         Jn += 0.5*(F(a, t) + F(b, t));
  55.         Jn = Jn*h;
  56.         J2n = 0;
  57.         h = (b - a) / (2 * n);
  58.         for (int i = 1; i <2*n; i++)
  59.         {
  60.             J2n += F(a + i*h, t);
  61.         }
  62.         J2n += 0.5*(F(a, t) + F(b, t));
  63.         J2n = J2n*h;
  64.         n++;
  65.     }
  66.     while (fabs(J2n - Jn)>e);
  67.     return J2n;
  68. }  
  69. int  main()
  70. {
  71.     int i;
  72.     double t[m],y[m];
  73.     for (int i = 0; i < m; i++)
  74.     {
  75.         cout << "enter t -2,6 -1,8 -0,2 0,7 1,6 2,5";
  76.         cin >> t[i];
  77.     }
  78.     for (i = 0; i < m; i++)
  79.     {
  80.         y[i] = integral(-2, 0, t[i]);
  81.         cout << " integral = " << y[i] << endl;
  82.     }
  83.  
  84.     system("pause");
  85.     return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment