HomeMathematicsODE Integrator Race — Euler vs RK2 vs RK4

ODE Integrator Race — Euler vs RK2 vs RK4 (2D)

A 2D canvas race between Euler, midpoint (RK2) and classical Runge-Kutta (RK4) integrating the same gravitational orbit, plus a live log-log global-error-vs-step-size chart whose measured regression slope is checked against each method's theoretical convergence order.

Mathematics2DAdvanced60 FPS📱 Mobile-adapted⇄ 3D version
2d-numerical-analysis ↗ Open standalone

Three numerical integrators — first-order Euler, second-order midpoint (RK2), and classical fourth-order Runge-Kutta — chase the same inverse-square gravitational orbit from an identical starting point, using the identical step size h, drawn directly in a top-down 2D phase-space view. Because they discretize the same differential equation with different local truncation error (O(h), O(h²) and O(h⁴) respectively), their trajectories peel away from the true Kepler ellipse at very different rates. Below the orbit, a log-log chart re-runs all three integrators at eight step sizes, measures each run's final-position error against an exact Kepler-equation solution, and fits a regression line whose slope is the method's measured convergence order — a live numerical check that RK4's fourth-order promise is real, not just visually smoother trails.

⚙ Under the hood

Three ODE integrators — Euler, midpoint (RK2) and classical Runge-Kutta (RK4) — solve the same gravitational orbit from an identical start with an identical step size, and their trails visibly diverge from the true ellipse at rates set by their truncation-error order, with live energy-drift readouts per method.

numerical-analysisrunge-kuttaeuler-methododeorbital-mechanicstruncation-error

2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)