资源预览内容
第1页 / 共2页
第2页 / 共2页
亲,该文档总共2页全部预览完了,如果喜欢就下载吧!
资源描述
/*This program is to solve the initial value problem of following system of differential equations:dx/dt=x+2*y,x(0)=0,dy/dt=2*x+y,y(0)=2, x(0.2) and y(0.2) are to be calculated*/#include#include#define steplength 0.1 /步?长可根据Y需要a调整?;#define FuncNumber 2 /FuncNumber为a微分?方?程的?数y目?;void main()float x200,Yn20200,reachpoint;int i;x0=0;Yn00=0;Yn10=2; /初?值条?件t;reachpoint=0.2; /所求点?可根据Y需要a调整?;void rightfunctions(float x ,float *Auxiliary,float *Func);void Runge_Kutta(float *x,float reachpoint, float(*Yn)200);Runge_Kutta(x ,reachpoint, Yn);printf(x );for(i=0;i=(reachpoint-x0)/steplength;i+)printf(%f ,xi);printf(nY1 );for(i=0;i=(reachpoint-x0)/steplength;i+)printf(%f ,Yn0i);printf(nY2 );for(i=0;i=(reachpoint-x0)/steplength;i+)printf(%f ,Yn1i);getchar();void rightfunctions(float x ,float *Auxiliary,float *Func)/当右方?程改?变?时,?需要a改?变?; Func0=Auxiliary0+2*Auxiliary1;Func1=2*Auxiliary0+Auxiliary1;void Runge_Kutta(float *x,float reachpoint, float(*Yn)200)int i,j;float FuncFuncNumber,KFuncNumber4,AuxiliaryFuncNumber;for(i=0;i=(reachpoint-x0)/steplength;i+) for(j=0;jFuncNumber;j+)Auxiliaryj=*(Ynj+i);rightfunctions(xi,Auxiliary,Func);for(j=0;jFuncNumber;j+)Kj0=Funcj; Auxiliaryj=*(Ynj+i)+0.5*steplength*Kj0; rightfunctions(xi,Auxiliary,Func);for(j=0;jFuncNumber;j+)Kj1=Funcj;Auxiliaryj=*(Ynj+i)+0.5*steplength*Kj1;rightfunctions(xi,Auxiliary,Func);for(j=0;jFuncNumber;j+) Kj2=Funcj; Auxiliaryj=*(Ynj+i)+steplength*Kj2; rightfunctions(xi,Auxiliary,Func);for(j=0;jFuncNumber;j+)Kj3=Funcj;for(j=0;jFuncNumber;j+)Ynji+1=Ynji+(Kj0+2*Kj1+2*Kj2+Kj3)*steplength/6.0;xi+1=xi+steplength;
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号