Risonna

lab3_n2ready?

Nov 24th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. #include<math.h>
  2. #include<iostream>
  3. #define pi acos(-1.0)
  4. using namespace std;
  5. int main()
  6. {
  7.     setlocale(LC_ALL, "RUS");
  8.     double x, b, h, a, y, i, s0, s1, e, p, s, z;
  9.     e = 0.0001;
  10.     b = pi;
  11.     h = pi / 25;
  12.     a = pi / 5;
  13.     i = 1;
  14.     x = a;
  15.     s = 0;
  16.     z = 0;
  17.     for (x = a; x <= b; x = x + h)
  18.     {
  19.         i = 1;
  20.         z++;
  21.         cout << "итерация for " << z << "\n";
  22.         s0 = (pow(-1, i) * cos(i * x)) / (i * i);
  23.         s1 = (pow(-1, (i + 1)) * cos((i + 1) * (x))) / ((i + 1) * (i + 1));
  24.         while (fabs(s1) >= e)
  25.         {
  26.             cout << "итерация while " << i << "\n";
  27.             s0 = (pow(-1, i) * cos(i * x)) / (i * i); cout << "s0=" << s0 << "\n";
  28.             s1 = (pow(-1, (i + 1)) * cos((i + 1) * (x))) / ((i + 1) * (i + 1));
  29.             y = ((x * x) - ((pi * pi) / 3));
  30.             i++;
  31.             //p = fabs(s0 - y);
  32.             s = s + s0;
  33.             //cout << "|s1-s0|=" << fabs(s1 - s0)<<"\n";
  34.             //cout << "|s0-y|=" << p << "\n";
  35.             cout << "y=" << y << "\n";
  36.         }
  37.     }
  38.     cout << "Сумма равна " << s;
  39.     return 0;
  40. }
Add Comment
Please, Sign In to add comment