Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <vector>
- using namespace std;
- double funct(double y, double t)
- {
- return -25 * y + cos(t) + 25 * sin(t);
- }
- int main()
- {
- double h,t=0;
- cin >> h;
- int n = 2 / h;
- double yt,yr;
- vector <double> y(n+1),y1(n+1),y2(n+1),y3(n+1);
- y[0] = 1;
- y1[0] = 1;
- y2[0] = 1;
- y3[0] = 1;
- for (int i = 0; i < n; i++,t+=h)
- {
- y[i + 1] = y[i] + h*funct(y[i], t);
- y1[i + 1] = y1[i] + h / 2 * (funct(y1[i], t) + funct(y1[i] + h * funct(y1[i], t), t + h));
- yt = y2[i] + h * funct(y2[i], t);
- yr = y3[i] + h * funct(y3[i], t);
- y2[i+1] = y2[i] + h * funct(yt, t+h);
- y3[i+1] = y3[i] + (h / 2)*(funct(y3[i], t) + funct(yr, t+h));
- while (abs(yt - y2[i]) >= 1e-12)
- {
- yt = y2[i+1];
- y2[i+1] = y2[i] + h * funct(yt, t+h);
- }
- while (abs(yr - y3[i]) >= 1e-12)
- {
- yr = y3[i+1];
- y3[i+1] = y3[i] + (h / 2)*(funct(y3[i], t) + funct(yr, t+h));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement