摘要:
欧拉法% M函数euler.m function[t,y]=euler(odefun,tspan,y0,h) t=tspan(1):h:tspan(2); y(1)=y0; for i=1:length(t)-1 y(i+1)=y(i)+h*feval(odefun,t(i),y(i)); end t=t'; y=y';先保存euler.m,再在命令窗口中执行:>> odefun=inline('y-2*t/y','t','y'); >> [t,y]=euler(odefun,[0,4],1,0.01); 阅读全文