ModestGenius

Task №1

Oct 7th, 2015
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. double Sh(double x, double eps)
  6. {
  7.     double an = x, sum = an;
  8.     int i = 0;
  9.     while (fabs(an) > eps)
  10.      { an *= -(x*x)/((2*i+1)*(2*i+2));
  11.        sum += an;
  12.        i++;
  13.      }
  14.     return sum;
  15. }
  16.  
  17. double Sder(double x, double eps)
  18. {
  19.     double an = 1, sum = an;
  20.     int i = 0;
  21.     while (fabs(an) > eps)
  22.      { an *= -(((x*x*(2*i+3)))/((2*i+1)*(2*i+1)*(2*i+2)));
  23.        sum += an;
  24.        i++;
  25.      }
  26.     return sum;
  27. }
  28.  
  29.  
  30. int main()
  31. {
  32.     double x, eps;
  33.     for (x=0; x<=1.8; x+=0.1)
  34.     {
  35.         cout << "\nSh(" << x << ") = " << Sh(x, eps);
  36.         cout<<"\nSder(" << x << ") = " << Sder(x, eps);
  37.         cout<<"\nSright(" << x << ") = " << (Sh(x+0.1,eps)-Sh(x, eps))/0.1;
  38.         cout<<"\nSleft(" << x << ") = " << (Sh(x, eps)-Sh(x-0.1,eps))/0.1;
  39.         cout<<"\nSaver(" << x << ") = " << (Sh(x+0.1, eps)-Sh(x-0.1,eps))/0.2;
  40.         cout << "\nxcos(" << x << ") = "<< x*cos(x);
  41.         cout << "\n" << endl;
  42.     }
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment