Euler's Method for the Exponential Function

euler[a_,n_]:=Table[{k*a/n,(1+a/n)^k},{k,0,n}]

Manipulate[
Show[{
Plot[Exp[x],{x,-1,Max[val+1,1]},PlotRange->{-1,Max[Exp[val]+val,2]},PlotStyle->{Thick,Dashed,Black},GridLines->Automatic],
ListPlot[euler[val,step],PlotMarkers->{"+",Large},PlotStyle->Green],
ListLinePlot[euler[val,step],PlotStyle->{Thick,Red}],
Graphics[{
{Thick,Dashed,Purple,Line[{{val,0},{val,Exp[val]}}]},
{Thick,Dashed,Purple,Line[{{0,Exp[val]},{val,Exp[val]}}]},
{Blue,PointSize[Medium],Point[{val,Exp[val]}]},
Text[Style[Row[{Style["y",Italic]," = ",Superscript["E",Style["t",Italic]]}],12,Bold],{-1/2,Exp[-1/2]+Exp[val]/10}],
Text[Style[TraditionalForm[(Subscript[e, step])[val],12,Bold]],{val+1/10,(1+val/step)^step}]
}]
},ImageSize->{550,400},ImagePadding->25,PlotLabel->Column[{Style[Text@TraditionalForm@Row[{(Subscript[e, step])[val]," ≈ ",NumberForm[euler[val,step][[step+1]][[2]]//N,{8,6}]}],14],
Style[Text@TraditionalForm@Row[{e^val," ≈ ",NumberForm[Exp[val]//N,{8,6}]}],14]}]],

{{val,1.,"x"},-1,10,.01,Appearance->"Labeled"},
{{step,3,"approximation step"},1,1000,1,Appearance->"Labeled"},
TrackedSymbols:>{val,step},
SaveDefinitions->True
]

For each value of x, the sequence (Subscript[e, n])(x)=(((1+(x/n)))^n) converges to (e^x). Also, if (Subscript[E, n])(t) is the Euler method approximation to the solution of the differential equation y'=y, y(0)=1 on the interval [0,x] with h=x/n, then (Subscript[E, n])(t) (the red curve) converges to (e^t) for each t in the interval. The points generated by Euler's method are marked in green. Observe that for any n, the error between the approximation and the real value increases with the value of x.

Contributed by: Arnaud Crouzet