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>
- #include <stdlib.h>
- double F1(double x,double y, double y2)
- {
- return (y*exp(x))/(x*y2);
- }
- double F2(double x, double y, double y2)
- {
- return 2*y+y2-4*x;
- }
- void main(void)
- {
- int k,j=0;
- double a,b,n,h,x;
- double Y,Y2;
- cout<<"a="; cin>>a; cout<<"b="; cin>>b; cout<<"n="; cin>>n;
- h=(b-a)/n;
- double y[100],y2[100];
- y[1]=2;
- y2[1]=exp(1);
- k=0;
- x=a;
- cout<<setw(4)<<"x"<<setw(8)<<"y1"<<setw(9)<<"y1'"<<setw(9)<<"y1'-y1"<<setw(5)<<"y2"<<setw(10)<<"y2'"<<setw(9)<<"y2'-y2"<<endl;
- while(k<=n)
- {
- k++;
- Y=y[k]+(h/2)*F1(x,y[k],y2[k]);
- Y2=y2[k]+(h/2)*F2(x,y[k],y2[k]);
- y[k+1]=F1(x+h/2,Y,Y2)*h+y[k];
- y2[k+1]=F2(x+h/2,Y,Y2)*h+y2[k];
- y[0]=2*x;
- y2[0]=exp(x);
- printf("%5.4f\t%4.3f\t%4.3f\t%5.4f\t%4.3f\t%4.3f\t%5.4f\n",x,y[0],y[k],fabs(y[k]-y[0]),y2[0],y2[k],fabs(y2[k]-y2[0]));
- x+=h;
- }
- cout<<"Shag="<<h<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement