Euler's Method

We consider the differential equation:

    (dy/dt) = f[t,y] = y
    
    y[a] = α = 1.
    
We will look at this over the range [a,b] = [0,5].

Clear[f,t,y,α,a,b];
f[t_,y_]=y;
α=1;
a=0;
b=5;

Let's solve it analytically

solveit=DSolve[{y'[t]==f[t,y[t]],y[a]==α},y[t],t]

y[t_]=y[t]/.solveit[[1]]

Plot[y[t],{t,a,b}];

Now let's try Euler's method.

Clear[w,i,h,t,plotw,n]

h=0.1;
t[i_]=a+i h;
n=Ceiling[((b-a)/h)];

w[0]=α;
Do[w[i+1]=w[i]+h f[t[i],w[i]],{i,0,n-1}]

list=Table[{t[i],w[i]},{i,0,n}];

plotw[t_]=Interpolation[list][t];
Plot[{y[t],plotw[t]},{t,a,b},PlotStyle->{Red,Blue}]

TableForm[Table[{t[i],y[t[i]],w[i]},{i,0,n}]]