From: tulip tulipov on
How to compare the approximated solution with exact solution?

Example: The IVP is:
y'=2t-y, y(0)=-1 with N=10. Exact solution is y(t)=exp(-t)+2t-2.
I found the approximate solution, but I have a problem to compare both (exact and approximate)?
Here what I've done:

a=0;
b=1;
y0=-1;
N=10;
fprintf('\n')
disp(' Euler Method ')
disp('_______________________________________________')
disp('ti f(ti,yi) yi exact error')
disp('_______________________________________________')
fprintf('\n')
h=(b-a)/N;
y=y0;
fprintf('%4.2f ----------- %12.6f %12.6f %4.2f\n',a,y,y,0) %prva redica od tabelata, dosega vnesenite pocetni vrednosti
for i=1:N
t=a+(i-1)*h;
m=f(t,y);
y=y+h*m;
fprintf('%4.2f %12.6f %12.6f\n',t,m,y);
end