Differential Equations

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('
')
disp(' Euler Method ')
disp('_______________________________________________')
disp('ti f(ti,yi) yi exact error')
disp('_______________________________________________')
fprintf('
')
h=(b-a)/N;
y=y0;
fprintf('%4.2f ----------- %12.6f %12.6f %4.2f
',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
',t,m,y);
end
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories