Euler Midpoint (RK2) RK4 True ellipse

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

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.