SHARE
TWEET

Untitled

a guest Nov 21st, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. float y(float x) {
  7.     return sinh(pow(x, 2) - 3) + 4.0 / sinh(pow(x, 2) + 3);
  8. }
  9.  
  10. float sinh_teulor(float x, int c) {
  11.     float y = 0;
  12.     float f = 1; // 1! = 1 3!
  13.  
  14.     for (int i = 1; i <= c; ++i) {
  15.         // i 1: x
  16.         // i 2: x ^ 3 / 3 !
  17.         // i 3: x ^ 5 / 5 !
  18.         y += pow(x, i * 2 - 1) / f;
  19.         f *= (2 * i + 1) * (2 * i);
  20.     }
  21.     return y;
  22. }
  23.  
  24. float y_teulor(float x, int c) {
  25.     return sinh_teulor(pow(x, 2) - 3, c) + 4 / sinh_teulor(pow(x, 2) + 3, c);
  26. }
  27.  
  28. int main()
  29. {
  30.     float x, eps;
  31.     cin >> x >> eps;
  32.  
  33.     float y1, y2;
  34.     y1 = y_teulor(x, 1);
  35.     y2 = y_teulor(x, 2);
  36.     int i = 3;
  37.     while (abs(y2 - y1) > eps) {
  38.         y1 = y2;
  39.         y2 = y_teulor(x, i);
  40.         i += 1;
  41.     }
  42.    
  43.     cout << "y~=" << y2 << "\n";
  44.     cout << "y=" << y(x) << "\n";
  45.  
  46.     return 0;
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top