Pensieve header: A comparison of Euler, Improved Euler, and Runge-Kutta on $y’=-y$.

Euler[f_,x0_,y0_, x_, n_, p_] := Module[
{h=N[(x-x0)/n, p], xj=N[x0, p], yj=N[y0, p], k1},
Do[
k1=f[xj,yj];
xj=xj+h;
yj=yj+h k1,
{n}
];
yj
]

f1[x_,y_] := -y;
{Euler[f1, 0, 1, 1, #, 10]& /@ {1, 10, (10^2), (10^3), (10^4), (10^5)}, N[1/E, 10]} // Timing

ImprovedEuler[f_,x0_,y0_, x_, n_, p_] := Module[
{h=N[(x-x0)/n, p], xj=N[x0, p], yj=N[y0, p], k1, k2},
Do[
k1=f[xj,yj];
k2=f[xj+h, yj+h k1];
xj=xj+h;
yj=yj+h (k1+k2)/2,
{n}
];
yj
]

ImprovedEuler[f1, 0, 1, 1, #, 10]& /@ {1, 10, (10^2), (10^3), (10^4), (10^5)} // Timing

RungeKutta[f_,x0_,y0_, x_, n_, p_] := Module[
{h=N[(x-x0)/n, p], xj=N[x0, p], yj=N[y0, p], k1, k2, k3, k4},
Do[
k1=f[xj,yj];
k2=f[xj+h/2, yj+h k1/2];
k3=f[xj+h/2, yj+h k2/2];
k4=f[xj+h, yj+h k3];
xj=xj+h;
yj=yj+h (k1+2k2+2k3+k4)/6,
{n}
];
yj
]

{RungeKutta[f1, 0, 1, 1, #, 20]& /@ {1, 10, (10^2), (10^3), (10^4), (10^5)}, N[1/E, 20]} // Timing