How to plot numerical solution of differential equations? - Programmers Heaven

Howdy, Stranger!

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

Categories

How to plot numerical solution of differential equations?

TulipppTulippp Posts: 2Member
My problem is how to plot the exact and the approximated solutions?
This is the Matlab M-file for solving differential equations with Euler's Method.

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)
for i=1:N
t=a+(i-1)*h;
m=f(t,y);
y=y+h*m;
t=t+h;
g=exp(-t)+2*t-2; (exact solution)
if (g~='N')
err=abs(g-y);
fprintf('%4.2f %12.6f %12.6f %12.6f %8.2e
',t,m,y,g,err)
else
fprintf('%4.2f %12.6f %12.6f
',t,m,y)
end
Sign In or Register to comment.