Advertisement
Jgug

7ololosh

Jun 5th, 2012
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream.h>
  2. #include <iomanip.h>
  3. #include <math.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6.  
  7. double F1(double x,double y, double y2)
  8. {
  9. return (y*exp(x))/(x*y2);
  10. }
  11.  
  12. double F2(double x, double y, double y2)
  13. {
  14. return 2*y+y2-4*x;
  15. }
  16.  
  17. void main(void)
  18. {
  19. int k,j=0;
  20. double a,b,n,h,x;
  21. double Y,Y2;
  22. cout<<"a="; cin>>a; cout<<"b="; cin>>b; cout<<"n="; cin>>n;
  23. h=(b-a)/n;
  24. double y[100],y2[100];
  25. y[1]=2;
  26. y2[1]=exp(1);
  27. k=0;
  28. x=a;
  29. 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;
  30. while(k<=n)
  31. {
  32. k++;
  33. Y=y[k]+(h/2)*F1(x,y[k],y2[k]);
  34. Y2=y2[k]+(h/2)*F2(x,y[k],y2[k]);
  35. y[k+1]=F1(x+h/2,Y,Y2)*h+y[k];
  36. y2[k+1]=F2(x+h/2,Y,Y2)*h+y2[k];
  37. y[0]=2*x;
  38. y2[0]=exp(x);
  39. 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]));
  40. x+=h;
  41. }
  42. cout<<"Shag="<<h<<endl;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement