func6p12.m
资源名称:数值分析课程设计.zip [点击查看]
上传用户:zhdd911129
上传日期:2007-05-11
资源大小:722k
文件大小:1k
源码类别:
matlab例程
开发平台:
Matlab
- %func6p12.m常微分初值问题
- s=0,t=1,n=100,y1=2
- a=linspace(s,t,n)
- x=t-s
- h=(t-s)/n
- %Euler Rule
- for i=1:n-1
- y11=y1+x/n*sub6p12(a(i),y1)
- y1=y1+x/n/2*(sub6p12(a(i),y1)+sub6p12(a(i+1),y11))
- disp(i)
- end
- %R-K Rule
- y1=2
- for i=1:n-1
- k1=sub6p12(a(i),y1)*h
- k2=sub6p12(a(i)+h/2,y1+k1/2)*h
- k3=sub6p12(a(i)+h/2,y1+k2/2)*h
- k4=sub6p12(a(i)+h,y1+k3)*h
- y1=y1+(k1+2*k2+2*k3+k4)/6
- disp(i)
- end
- %True Value:y(1)=1.41421356237310,y(0.5)=1.78885438199983
- %Euler Rule:y(1)=1.41913670503394,y(0.5)=1.79443366894940
- %R-K Methom:y(1)=1.41915871762530,y(0.5)=1.79446130391271,依然是R-K方法略优于Euler