Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream.h>
- #include <iomanip.h>
- #include <math.h>
- #include <stdio.h>
- double F1(double x,double y1, double y2)
- {
- return (y1*exp(x))/(x*y2);
- }
- double F2(double x, double y1, double y2)
- {
- return 2*y1+y2-4*x;
- }
- void main(void)
- {
- int a=1, b=4;
- int k;
- double n,h,x;
- double Y1,Y2;
- double y1app[1001],y2app[1001];
- cout<<"n="; cin>>n;
- h=(b-a)/n;
- y1app[1]=2;
- y2app[1]=exp(1);
- k=0;
- x=a;
- cout<<"x"<<setw(9)<<"y1"<<setw(12)<<"y1app"<<setw(10)<<"y1app-y1"<<setw(1)<<"y2"<<setw(11)<<"y2app"<<setw(11)<<"y2app-y2"<<endl;
- cout<<"________________________________________________________"<<endl;
- while(k<=n)
- {
- k++;
- Y1=y1app[k]+(h/2)*F1(x,y1app[k],y2app[k]);
- Y2=y2app[k]+(h/2)*F2(x,y1app[k],y2app[k]);
- y1app[k+1]=y1app[k]+h*F1(x+h/2,Y1,Y2);
- y2app[k+1]=y2app[k]+h*F2(x+h/2,Y1,Y2);
- double y1tochn=2*x;
- double y2tochn=exp(x);
- 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));
- x+=h;
- }
- cout<<"Shag="<<h<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement