func6p12.m
上传用户:zhdd911129
上传日期:2007-05-11
资源大小:722k
文件大小:1k
源码类别:

matlab例程

开发平台:

Matlab

  1. %func6p12.m常微分初值问题
  2. s=0,t=1,n=100,y1=2
  3. a=linspace(s,t,n)
  4. x=t-s
  5. h=(t-s)/n
  6. %Euler Rule
  7. for i=1:n-1
  8.     y11=y1+x/n*sub6p12(a(i),y1)
  9.     y1=y1+x/n/2*(sub6p12(a(i),y1)+sub6p12(a(i+1),y11))
  10.     disp(i)
  11. end
  12. %R-K Rule
  13. y1=2
  14. for i=1:n-1
  15.     k1=sub6p12(a(i),y1)*h
  16.     k2=sub6p12(a(i)+h/2,y1+k1/2)*h
  17.     k3=sub6p12(a(i)+h/2,y1+k2/2)*h
  18.     k4=sub6p12(a(i)+h,y1+k3)*h
  19.     y1=y1+(k1+2*k2+2*k3+k4)/6
  20.     disp(i)
  21. end
  22. %True Value:y(1)=1.41421356237310,y(0.5)=1.78885438199983
  23. %Euler Rule:y(1)=1.41913670503394,y(0.5)=1.79443366894940
  24. %R-K Methom:y(1)=1.41915871762530,y(0.5)=1.79446130391271,依然是R-K方法略优于Euler