p6_19.m

来自「Advanced Engineering Mathematics using M」· M 代码 · 共 31 行

M
31
字号
% P6_19.M Test Euler method on Dy=y with h=0.2.% y(n+1)=y(n)+hy(n)=(1+h)y(n)clearn=5y(1)=1T(1)=0yexact(1)=1yerror(1)=0h=0.2for I=1:n; T(I+1)=I*h; y(I+1)=y(I)*(1+h); yexact(I+1)=exp(I*h); yerror(I+1)=y(I+1)-yexact(I+1);end;test=[T' y' yexact' yerror'];disp('       t        yn       exp      error')disp(' ')disp(test)pauseclfplot(T,yexact,'-',T, y,'x')title('First Order Equation, Euler (-x-) and exact solution')xlabel('Time')ylabel('y(t)')legend('Exp', 'Euler')%% Add comments to explain the operation of the M-file.% Add an fprintf statement before the pause to explain%  the display

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?