8-9은 생략.
MATLAB강의록(배포용)_10장_수치해석.pdf

오일러 방법에 의한 상미분 방정식 풀이
%ode-euler example1.m
% dydt = (t^3-2*y)/t; y1=4.5

h = 0.001;
y = 4.5;
n=1;
%plot(t,y, '-'); hold on;
for t=1:h:3
    T(n)=t; Y(n)=y; n=n+1;
    dy = ODEexp1(t, y);
    y = y + dy*h;
end
plot(T,Y, 'r');

%ODEexp1.m
function dydt = ODEexp1(t, y)
dydt = (t^3-2*y)/t;

% ode-euler example2.m
% dydt = -2*y; y0=-2;

h = 0.001;
y = -2;
n=1;
%plot(t,y, '-'); hold on;
for t=0:h:3
    T(n)=t; Y(n)=y; n=n+1;
    dy = ODEexp2(t,y);
    y = y + dy*h;
end
X = -2*exp(-2*T);
subplot(211);
plot(T,[Y; X; X-Y]);
subplot(212);
plot(T,X-Y);

%ODEexp2.m
function dydt = ODEexp2(t, y)
dydt = -2*y;