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

matlab例程

开发平台:

Matlab

  1. %func6p11.m常微分初值问题
  2. s=0,t=1,n=100,y1=1
  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*sub6p11(a(i),y1)
  9.     y1=y1+x/n/2*(sub6p11(a(i),y1)+sub6p11(a(i+1),y11))
  10.     disp(i)
  11. end
  12. %R-K Rule
  13. y1=1
  14. for i=1:n-1
  15.     k1=sub6p11(a(i),y1)*h
  16.     k2=sub6p11(a(i)+h/2,y1+k1/2)*h
  17.     k3=sub6p11(a(i)+h/2,y1+k2/2)*h
  18.     k4=sub6p11(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)=0.60995168498111510516376506679627, y(0.5)=0.73204284797281271034681566467062
  23. %Euler Rule:y(1)=0.61296795390463,y(0.5)=0.73598135556071
  24. %R-K Methom:y(1)=0.61295629484976,y(0.5)=0.73597167736700,R-K方法略优于Euler