常微分初值问题的数值解法课程设计

二:隐式欧拉方法源代码 #include #include #define F(x,y) x+y main() {

int a=0,b=1,i;

double y[50],x[50],h=0.1,n; y[0]=1.0,x[0]=0; n=(b-a)/h; for(i=0;i<=n;i++) { x[i]=a+i*h;

y[i+1]=y[i]+h*(F(x[i],y[i])); y[i+1]=y[i]+h*(F((x[i]+h),y[i+1])); printf(\ }}

三:改进欧拉方法源代码 #include #include #define F(x,y) x+y main()

{double x0=0,y0=1,x1,y1,yp,yc,h=0.1; int a,b,k;

5

a=0,b=1; double n=(b-a)/h; for(k=1;k<=n;k++) {

x1=x0+h;

yp=y0+h*(F(x0,y0)); yc=y0+h*(F(x1,yp)); y1=(yp+yc)/2;

printf(\ x0=x1; y0=y1; }}

四:梯形方法源代码 #include #include #define F(x,y) x+y main()

{double x0=0,y0=1,x1,y1,h=0.1; int a,b,k; a=0,b=1; double n=(b-a)/h; for(k=1;k<=n;k++) {

6

x1=x0+h;

y1=y0+h*(F(x0,y0));

y1=y0+(h/2)*(F(x0,y0)+F(x1,y1)); printf(\ x0=x1; y0=y1; }}

五:R-K方法的源代码 #include #include #define F(x,y) x+y main()

{double x0=0,y0=1,x1,y1,k1,k2,k3,k4,h=0.1; int a,b,k; a=0,b=1; double n=(b-a)/h; for(k=1;k<=n;k++) {

x1=x0+h; k1=F(x0,y0);

k2=F(x0+h/2,y0+h*k1/2); k3=F(x0+h/2,y0+h*k2/2); k4=F(x0+h/2,y0+h*k3);

7

y1=y0+h*(k1+2*k2+2*k3+k4)/6; printf(\ x0=x1; y0=y1; }}

8

联系客服:779662525#qq.com(#替换为@)