ODE Solvers: Euler vs RK4

Compare numerical integration methods on classic ODEs

Euler (h)
Midpoint (h)
RK4 (h)
Exact
Euler error: Midpoint error: RK4 error:

Euler's method (1st order) simply steps y_{n+1} = y_n + h·f(xₙ,yₙ). Midpoint method (2nd order) uses a half-step predictor. RK4 (4th order) averages four slope estimates — error scales as h⁴ vs Euler's h¹. Try increasing step size to see each method diverge.