Advertisement
Jgug

7

Jun 5th, 2012
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include<windows.h>
  2. #include <iostream.h>
  3. #include <iomanip.h>
  4. #include <math.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. double F1(double x, double y1, double y2)
  9. {
  10.     return (y1*exp(x))/y2*x;
  11. }
  12.  
  13. double F2(double x, double y1, double y2)
  14. {
  15.     return 2*y1+y2-4*x;
  16. }
  17.  
  18. double out(double x, double u1, double Y1, double  u2, double Y2)
  19. {
  20.     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));
  21.     return 0;
  22. }
  23.  
  24. void main(void)
  25. {
  26.     int a=1;
  27.     int b=4;
  28.     int ny=2;
  29.     double u1[1000], u2[1000];
  30.     double h, x;
  31.     double Y1, Y2;
  32.     int nx, np, k;
  33.  
  34.     cout<<"Vvedite kol-vo shagov setki nx: "<<endl;
  35.     cin>>nx;
  36.     cout<<"Vvedite shag vivoda dannich np: "<<endl;
  37.     cin>>np;
  38.    
  39.     h=double(b-a)/nx;
  40.     cout<<nx;
  41.     u1[1]=2;
  42.     u2[1]=exp(1);
  43.     k=0;
  44.     x=a;
  45.  
  46.     while (k<=nx)
  47.     {
  48.         k++;
  49.         Y1 = u1[k]+(h/2)*F1(x, u1[k], u2[k]);
  50.         Y2 = u2[k]+(h/2)*F2(x, u1[k], u2[k]);
  51.         u1[k+1] = F1(x+h/2, Y1, Y2)*h+u1[k];
  52.         u2[k+1] = F2(x+h/2, Y1, Y2)*h+u2[k];
  53.         u1[0]=2*x;
  54.         u2[0]=exp(x);
  55.         out(x, u1[k], u1[0], u2[k], u2[0]);
  56.         x+=h;
  57.     }
  58.     cout<<"Iksov = "<<k<<endl;
  59.     cout<<"Otrezkov = "<<nx<<endl;
  60.     cout<<"Shag = "<<h<<endl;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement