Numerical methods for ODEs are one of those subjects where the theory reads cleanly on the page and then punishes you the moment you try it on anything non-trivial. This post walks through three problems I worked on for a numerical analysis course, each less forgiving than the last, and what the numerics actually do once you turn the crank.
The methods
All three problems use the same three integrators. Given a state , a vector field , and step size , each one advances a step as follows.
Forward Euler, one slope and one step:
Modified Euler (Heun's method), the average of two slopes:
Classical fourth-order Runge–Kutta (RK4), four weighted slopes:
where are successive slope estimates along the step. The global error scales as , , and respectively, a gap that looks innocuous on paper and enormous in practice.
Problem 1: exponential growth
Start with the simplest possible test case:
The exact solution is , so . Running each method with (ten steps) to :
| Method | Approx | Error | |---|---|---| | Euler | 2.593742 | | | Modified Euler | 2.714081 | | | RK4 | 2.718280 | |
Euler is off by about , which is typical first-order behaviour. Modified Euler drops the error by roughly two orders of magnitude. RK4 hits six-digit accuracy in ten steps. On a smooth exponential, the order of the method is the whole story.
Extending to with different step sizes makes the gap between methods visible. At , Euler lags far below the exact curve while RK4 overlaps it almost exactly:

At , modified Euler and RK4 both overlap the exact solution and only Euler shows visible error:

By , all four curves are indistinguishable:

The log–log error plot confirms the convergence rates quantitatively. The slopes are , , and . Halving halves Euler's error, quarters modified Euler's, and cuts RK4's by a factor of sixteen:

Problem 2: the Van der Pol oscillator
The Van der Pol equation is a non-conservative oscillator with nonlinear damping:
Introducing turns it into a first-order system:
For , the system has a stable limit cycle. I integrated it with RK4 from two very different initial conditions, and . The time series shows both trajectories settling into the same regular oscillation after about ten time units:

The phase portrait makes the point more cleanly. Both trajectories spiral onto the same closed loop. That is what a limit cycle means: the system forgets where it started.

Things get more interesting at , where the oscillator becomes stiff. It spends most of its time drifting slowly and then executes a sharp jump. With explicit Euler at the relaxation oscillation is clearly visible: slow decay through zero, rapid jump to , repeat:

The phase portrait at this step size traces the egg-shaped limit cycle with its characteristic sharp corners at the fast jumps:

Push the step size to and the solution blows up to order in a handful of steps. The limit cycle is gone:

The phase portrait never closes. The trajectory spirals out wildly before escaping to infinity:

That is the practical meaning of stiffness. A method that works fine on smooth problems can fail catastrophically when the system has sharp transitions, and the cure is not always a higher-order method. Often it is just a smaller step, or an implicit scheme.
Problem 3: gravitational N-body orbits
For planets interacting gravitationally, Newton's laws give first-order ODEs:
Packing the state into a NumPy array of shape (n, 2, 3), with one slot per body for position and one for velocity, each a 3-vector, lets the same rk4 routine handle the two-body and three-body cases without modification.
Two bodies
With , , RK4 produces clean closed ellipses. The lighter body traces the larger ellipse, the heavier body the smaller one, and the centre of mass stays pinned at the origin:

Conservation laws the integrator was never told about fall out for free, because RK4 is accurate enough over twenty time units that the drift is invisible to the eye.
Three bodies: the figure-eight
The three-body problem has no closed-form solution in general, but it does admit remarkable periodic orbits where three equal masses chase each other along a shared curve. The most famous is the figure-eight, discovered by Moore (1993) and Chenciner–Montgomery (2000). With parameters
the three trajectories trace out a single figure-eight curve:

Other known three-body orbits work the same way. Pick the right and the integrator draws the pattern. These runs need a much smaller step (I used ) because small integration errors accumulate over the long period.



What I took away
The tidy version of the story is that higher-order methods beat lower-order methods. That is true on smooth problems and visible within ten steps of an exponential. The less tidy version is that order of accuracy is only part of what determines whether a method is useful. Stiffness kills explicit methods regardless of order. Long-horizon problems, orbits especially, punish any method that fails to preserve the right geometric structure, which is why symplectic integrators exist and why even RK4 eventually drifts.
The full code lives in the course assignment. The point of writing it up here was less about the Python and more about what the plots taught me. Every method has a regime where it is the right tool. The skill worth developing is recognising which regime you are in.