+++++++++++++++++++++++++++++++++++++++++++++

The following cell will compute the approximate solution to an equation of the form
                  y' = f(x,y)
 through the point (x0,y0) using "nsteps" steps of Euler's method
 on the interval [left,right].

Clear[f,t,x,y,Deriv,n,i];

nsteps=3;
f[x_,y_]=-2*y;
x0=0.0;
y0=4;
left=0;
right=.6;

h=(right-left)/nsteps;

x=Table[x0+i*h,{i,1,nsteps}];
y=Table[0,{i,1,nsteps}];

y[[1]]=y0+h*f[x0,y0];

Do[
y[[i]]=y[[i-1]]+h*f[x[[i-1]],y[[i-1]]]
,{i,2,nsteps}]
data=Table[{x[[i]],y[[i]]},{i,1,nsteps}];

Prepend[Prepend[data,{x0,y0}],{"(Subscript[x, i])","(Subscript[y, i])"}];
TableForm[%]

dataplot=ListPlot[data,PlotRange->All,PlotLabel->nsteps "steps",PlotStyle->PointSize[0.02]]
Clear[x,y];
Print["Solving y'=",f[x,y],",  y(",x0,")=",y0," using Euler's method"];
Print["      with ",nsteps," steps of size ",h," on the interval [",left,",",right,"]."];
Print[" "];

++++++ the analytical solution +++++++

Clear[y,x,y0];
DSolve[{y'[t]==-2*y[t],y[0]==4},y[t],t]
solution[t_]=y[t]   /. %[[1,1]]

+++++++++++++++++   ++++++++++++++++++++

Show[dataplot,Plot[solution[t],{t,0,.7}]]