clear; close all

% a) h=0.4
h=0.4; n=3;
ta=0:h:n*h;
ya(1)=0;   % Indeksointi alkaa 1:stä Matlabissa.
for k=1:n
    ya(k+1)=ya(k)+h*(ta(k)+ya(k));
end;
[ta;ya]
plot(ta,ya,'r');hold on;plot(ta,ya,'ro')
grid on; 

%b)  h=0.2

h=0.2; n=6;
tb=0:h:n*h;
yb(1)=0;   
for k=1:n
    yb(k+1)=yb(k)+h*(tb(k)+yb(k));
end;
[tb;yb]
plot(tb,yb,'g');plot(tb,yb,'go')

%c) h=0.1

h=0.1; n=12;
tc=0:h:n*h;
yc(1)=0;   
for k=1:n
    yc(k+1)=yc(k)+h*(tc(k)+yc(k));
end;
[tc;yc]
plot(tc,yc,'b');plot(tc,yc,'bx')

loppuarvot=[ya(end),yb(end),yc(end)]
tL=ta(end)
yloppu=exp(tL)-tL-1 
virheet=yloppu-[ya(end),yb(end),yc(end)]
