正文

常微分方程数值解法 之 改进欧拉方法2006-04-23 10:40:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/bakers/13060.html

分享到:

// 改进欧拉方法 比常规欧拉方法 和梯形公式具有更高精度,也称为预测-校正算法 //时间   4.23  上午   //  f(x,y)=x-2*x/y // y(0)=1 #include"stdio.h"#include"iostream"#include"conio.h" using namespace std; double x0,x1,y0,y1; class mend_euler{      public:             mend_euler(double h,int n);             double f(double x,double y);                   private:              double h;              int n;                    }; mend_euler::mend_euler(double a,int b){   int i=1;    h=a;    n=b;      while(i<=n)    {    x1=x0+h;    y1=y0+h/2*(f(x0,y0)+f(x1,y0+h*f(x0,y0)));    cout<<endl; cout<<"x1="<<x1<<"   y1="<<y1<<"  y="<<x0/(1+x0*x0)<<"  e="<<y1-x0/(1+x0*x0)<<endl;    i++;    x0=x1;    y0=y1;    }                    } double mend_euler::f(double x,double y){       return 1/(1+x*x)-2*y*y;       }       int  main(){    double h;     int n;     cout<<endl<<"input x0=";     cin>>x0;     cout<<endl<<"input y0=";     cin>>y0;     cout<<endl<<"intput h=";     cin>>h;     cout<<endl<<"intput n=";     cin>>n;     mend_euler euler(h,n);     getch();     return 1; } 以上程序在 DEV C++中调试通过 注:其中  x0,y0表示初值    h为 步长,   n为节点数目.

阅读(8120) | 评论(2)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

loading...
您需要登录后才能评论,请 登录 或者 注册