Advertisement
Jgug

ODY.R-K-2

Jun 6th, 2012
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <iostream.h>
  2. #include <iomanip.h>
  3. #include <math.h>
  4. #include <stdio.h>
  5.  
  6. double F1(double x,double y1, double y2)
  7. {
  8.     return (y1*exp(x))/(x*y2);
  9. }
  10.  
  11. double F2(double x, double y1, double y2)
  12. {
  13.     return 2*y1+y2-4*x;
  14. }
  15.  
  16. void main(void)
  17. {
  18.     int a=1, b=4;
  19.     int k;
  20.     double n,h,x;
  21.     double Y1,Y2;
  22.     double y1app[1001],y2app[1001];
  23.     cout<<"n="; cin>>n;
  24.     h=(b-a)/n;
  25.     y1app[1]=2;
  26.     y2app[1]=exp(1);
  27.     k=0;
  28.     x=a;
  29.     cout<<"x"<<setw(9)<<"y1"<<setw(12)<<"y1app"<<setw(10)<<"y1app-y1"<<setw(1)<<"y2"<<setw(11)<<"y2app"<<setw(11)<<"y2app-y2"<<endl;
  30.     cout<<"________________________________________________________"<<endl;
  31.     while(k<=n)
  32.     {
  33.         k++;
  34.         Y1=y1app[k]+(h/2)*F1(x,y1app[k],y2app[k]);
  35.         Y2=y2app[k]+(h/2)*F2(x,y1app[k],y2app[k]);
  36.         y1app[k+1]=y1app[k]+h*F1(x+h/2,Y1,Y2);
  37.         y2app[k+1]=y2app[k]+h*F2(x+h/2,Y1,Y2);
  38.         double y1tochn=2*x;
  39.         double y2tochn=exp(x);
  40.         printf("%5.4f\t%4.4f\t%4.4f\t%5.4f\t%4.4f\t%4.4f\t%5.4f\n",x,y1tochn,y1app[k],fabs(y1app[k]-y1tochn),y2tochn,y2app[k],fabs(y2app[k]-y2tochn));
  41.         x+=h;
  42.     }
  43.     cout<<"Shag="<<h<<endl;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement