SHARE
TWEET

get your ass back here

a guest Nov 21st, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. double funct(double y, double t)
  8. {
  9.     return -25 * y + cos(t) + 25 * sin(t);
  10. }
  11.  
  12. int main()
  13. {
  14.     double h,t=0;
  15.     cin >> h;
  16.     int n = 2 / h;
  17.     double yt,yr;
  18.     vector <double> y(n+1),y1(n+1),y2(n+1),y3(n+1);
  19.     y[0] = 1;
  20.     y1[0] = 1;
  21.     y2[0] = 1;
  22.     y3[0] = 1;
  23.     for (int i = 0; i < n; i++,t+=h)
  24.     {
  25.         y[i + 1] = y[i] + h*funct(y[i], t);
  26.         y1[i + 1] = y1[i] + h / 2 * (funct(y1[i], t) + funct(y1[i] + h * funct(y1[i], t), t + h));
  27.         yt = y2[i] + h * funct(y2[i], t);
  28.         yr = y3[i] + h * funct(y3[i], t);
  29.         y2[i+1] = y2[i] + h * funct(yt, t+h);
  30.         y3[i+1] = y3[i] + (h / 2)*(funct(y3[i], t) + funct(yr, t+h));
  31.         while (abs(yt - y2[i]) >= 1e-12)
  32.         {
  33.             yt = y2[i+1];
  34.             y2[i+1] = y2[i] + h * funct(yt, t+h);
  35.         }
  36.         while (abs(yr - y3[i]) >= 1e-12)
  37.         {
  38.             yr = y3[i+1];
  39.             y3[i+1] = y3[i] + (h / 2)*(funct(y3[i], t) + funct(yr, t+h));
  40.         }
  41.  
  42.     }
  43. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top