%% EULER METHOD %% %% Writen for x'=f(x) with f(x)=-x and x(0)=x0 %% clear all dt=.001; x0=0; t0=0; endtime=1; t=0:dt:endtime; N=(endtime-t0)/dt; x(1)=x0; for n=1:N x(n+1)=x(n)+dt*(x(n)+exp(-x(n))) end plot(t,x,'k') hold on %% END EULER METHOD %%