Runge-Kutta RK4
The classic fourth-order Runge-Kutta method combines four slope evaluations per step for high accuracy without needing derivatives of f.
Four slopes, one accurate step
The classical RK4 method samples the slope four times within each step and blends them into a weighted average. It evaluates f at the start, twice at the midpoint using previous estimates, and once at the end, then advances with y_{n+1} = y_n + (h/6)(k1 + 2k2 + 2k3 + k4). The result is fourth-order accurate.
def rk4(f, y0, t0, h, steps):
t, y = t0, y0
out = [(t, y)]
for _ in range(steps):
k1 = f(t, y)
k2 = f(t+h/2, y+h/2*k1)
k3 = f(t+h/2, y+h/2*k2)
k4 = f(t+h, y+h*k3)
y = y + h/6*(k1 + 2*k2 + 2*k3 + k4)
t = t + h
out.append((t, y))
return out
Why fourth order is popular
RK4's global error is proportional to h^4, so halving the step cuts error by roughly sixteen. This sweet spot of accuracy versus cost, four function evaluations per step, makes RK4 the default explicit solver for smooth nonstiff problems. It needs no derivatives of f and is self-starting, unlike multistep methods.
Limitations
RK4 is explicit and therefore only conditionally stable: on stiff problems it still requires tiny steps despite its high order. Its fixed step gives no error control on its own; embedded pairs solve this. And like all fixed-step methods, it can waste effort on easy regions and under-resolve hard ones.
Embedded pairs
Practical solvers use embedded Runge-Kutta pairs such as Runge-Kutta-Fehlberg or Dormand-Prince, which compute two estimates of different order from the same slopes. Their difference estimates the local error, driving automatic step-size control. Dormand-Prince is the method behind many default adaptive ODE routines.
RK4 and its adaptive descendants integrate the nonstiff, time-resolved dynamics in many physics models, including trajectory and control computations that support breeder Hyperion design studies.