Advertisement
999ms

Untitled

Mar 12th, 2020
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.72 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <iostream>
  3. #include <conio.h>
  4. using namespace std;
  5.  
  6.  
  7. double func1(double y1, double y2){
  8.     return -501*y1+500*y2;
  9. }
  10.  
  11. double func2(double y1, double y2){
  12.     return 500*y1-501*y2;
  13. }
  14.  
  15. int main(){
  16.     double y1_0,y2_0,h,tmp1,tmp2;
  17.     double* y1 = new double[4];
  18.     double* y2 = new double[4];
  19.     int it,counter=1;
  20.     cout << "Enter initial conditions: " << endl;
  21.     cout << "y1(0) = " ;
  22.     cin >> y1_0;
  23.     cout << endl << "y2(0) = " ;
  24.     cin >> y2_0;
  25.     cout << endl << "Enter amount of needed itrations: ";
  26.     cin >> it;
  27.     cout << endl << "Enter the step h: ";
  28.     cin >> h;
  29.     y1[0]=y1_0;
  30.     y2[0]=y2_0;
  31.     cout <<"Itration: " <<counter<<"\t" << "y1 = " << y1[0] << "\t" << "y2 = " << y2[0] << endl;
  32.     //Находим первые три точки по методу Эйлера
  33.     for (int i=1; i<3; i++){
  34.         y1[i]=y1[i-1]+h*func1(y1[i-1],y2[i-1]);
  35.         y2[i]=y2[i-1]+h*func2(y1[i-1],y2[i-1]);
  36.         counter++;
  37.         cout <<"Itration: " <<counter<<"\t" << "y1 = " << y1[i] << "\t" << "y2 = " << y2[i] << endl;
  38.     }
  39.     while(counter<it){
  40.         int i=3;
  41.         y1[i]=y1[i-1]+h*( (23.0/12.0)*func1(y1[i-1],y2[i-1]) - (16.0/12.0)*func1(y1[i-1],y2[i-2]) + (5.0/12.0)*func1(y1[i-2],y2[i-2]));
  42.         y2[i]=y2[i-1]+h*( (23.0/12.0)*func2(y1[i-1],y2[i-1]) - (16.0/12.0)*func2(y1[i-1],y2[i-2]) + (5.0/12.0)*func2(y1[i-2],y2[i-2]));
  43.         counter++;
  44.         cout <<"Itration: " <<counter<<"\t" << "y1 = " << y1[i] << "\t" << "y2 = " << y2[i] << endl;
  45.        
  46.         y1[i-3]=y1[i-2];
  47.         y1[i-2]=y1[i-1];
  48.         y1[i-1]=y1[i];
  49.  
  50.         y2[i-3]=y2[i-2];
  51.         y2[i-2]=y2[i-1];
  52.         y2[i-1]=y2[i];
  53.     }
  54.     _getch();
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement