⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p6_19.m

📁 Programs for the book Advanced Engineering Mathematics using MATLAB, 2ndEd.
💻 M
字号:
% P6_19.M Test Euler method on Dy=y with h=0.2.
% y(n+1)=y(n)+hy(n)=(1+h)y(n)
clear
n=5
y(1)=1
T(1)=0
yexact(1)=1
yerror(1)=0
h=0.2
for 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)
pause
clf
plot(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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -