资源描述:
《微分方程数值解上机报告-常微分方程初值问题数值解法》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、第一章常微分方程初值问题数值解法实验一1、实验题目试用(a)欧拉格式(b)中点格式(c)预报—校正格式(d)经典四级四阶R-K格式编程计算方程:2、程序#include#include#includeconstintN=11;doublefund(doublex,doubley);voidEuler(doublea,doubleh,doubley[]);voidCenter(doublea,doubleh,doubley[]);voidYuJiao(doublea,doubleh,doubley[]);v
2、oidSjSj(doublea,doubleh,doubley[]);voidAdams(doublea,doubleh,doubley[]);voidmain(){doublea,b,h,y[N];inti;charoption;cout<<"请输入定义域区间[a,b]:";27cin>>a>>b;cout<<"请输入初值y[0]:";cin>>y[0];h=(b-a)/(N-1);cout<<"a:欧拉法b:中心法c:预报-校正格式";cout<<"d:经典四级四阶R-K格式";cout<<"e:Adams预报-修正格式f:退出
3、";label:cout<<"请选择算法:";cin>>option;switch(option){case'a':Euler(a,h,y);break;case'b':Center(a,h,y);break;case'c':YuJiao(a,h,y);break;case'd':YuJiao(a,h,y);break;case'e':Adams(a,h,y);break;case'f':exit(1);break;default:{cout<<"选择有错,重新选择!";gotolabel;}}cout<<"计算结果为:xnttyn"<4、r(i=0;i5、1]);}}voidYuJiao(doublea,doubleh,doubley[]){inti;doublesun;doubley_Begin[N]={y[0]};for(i=1;i0.0001){sun=y[i-1]+h/2.0*(fund(a+(i-1)*h,y[i-1])+fund(a+i*h,y_Begin[i]));y_Begin[i]=s
6、un;}y[i]=sun;}}voidSjSj(doublea,doubleh,doubley[]){inti;doublek1,k2,k3,k4;for(i=1;i7、eh,doubley[]){inti;doubleme,x[N];doublek1,k2,k3,k4;for(i=0;i8、N;i++