clear all;
close all;
Delta_t=0.5;
t=0:Delta_t:2.0;
%Preallocating memory
x=zeros(size(t));
x(1)=1.0;
for n=1:length(t)-1
x(n+1)=x(n)+Delta_t*(-8*x(n));
end
plot(t,x,’ko-‘)
hold on
tplot=0:0.01:2.0;
truesolution=@(t)(exp(-8*t))
plot(tplot,truesolution(tplot),’b-‘,’linewidth’,2)
axis([0 2 -2 2])
xlabel(‘t’);
ylabel(‘x(t)’);
legend(‘Euler’,’True’);