Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<windows.h>
- #include <iostream.h>
- #include <iomanip.h>
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
- double F1(double x, double y1, double y2)
- {
- return (y1*exp(x))/y2*x;
- }
- double F2(double x, double y1, double y2)
- {
- return 2*y1+y2-4*x;
- }
- double out(double x, double u1, double Y1, double u2, double Y2)
- {
- printf("%5.4f\t%4.3f\t%4.3f\t%5.4f\t%4.3f\t%4.3f\t%5.4f\n",x,u1,Y1,fabs(u1-Y1),u2,Y2,fabs(u2-Y2));
- return 0;
- }
- void main(void)
- {
- int a=1;
- int b=4;
- int ny=2;
- double u1[1000], u2[1000];
- double h, x;
- double Y1, Y2;
- int nx, np, k;
- cout<<"Vvedite kol-vo shagov setki nx: "<<endl;
- cin>>nx;
- cout<<"Vvedite shag vivoda dannich np: "<<endl;
- cin>>np;
- h=double(b-a)/nx;
- cout<<nx;
- u1[1]=2;
- u2[1]=exp(1);
- k=0;
- x=a;
- while (k<=nx)
- {
- k++;
- Y1 = u1[k]+(h/2)*F1(x, u1[k], u2[k]);
- Y2 = u2[k]+(h/2)*F2(x, u1[k], u2[k]);
- u1[k+1] = F1(x+h/2, Y1, Y2)*h+u1[k];
- u2[k+1] = F2(x+h/2, Y1, Y2)*h+u2[k];
- u1[0]=2*x;
- u2[0]=exp(x);
- out(x, u1[k], u1[0], u2[k], u2[0]);
- x+=h;
- }
- cout<<"Iksov = "<<k<<endl;
- cout<<"Otrezkov = "<<nx<<endl;
- cout<<"Shag = "<<h<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement