Numerical Methods for ODEs

RK4

/ ar-kay-FOUR /

If Runge-Kutta is the idea of sampling several slopes inside a step and averaging them, RK4 is its most famous concrete recipe — the four-slope formula that, for decades, was the default 'just solve this ODE for me' method. It hits a sweet spot: high enough accuracy that you rarely need anything fancier on a smooth problem, yet simple enough to write in a dozen lines of code.

RK4 takes a single step using four slope evaluations: k1 = f(t_n, y_n), the slope at the start; k2 = f(t_n + h/2, y_n + (h/2)*k1), a slope at the midpoint using k1 to get there; k3 = f(t_n + h/2, y_n + (h/2)*k2), a second, refined midpoint slope; and k4 = f(t_n + h, y_n + h*k3), the slope at the far end. The step is a weighted average that trusts the two midpoint slopes most: y_{n+1} = y_n + (h/6)*(k1 + 2*k2 + 2*k3 + k4). The 1-2-2-1 weighting is no accident — it is exactly the pattern that cancels the error terms through h^4, making the method fourth order, and it echoes Simpson's rule for integration (which RK4 reduces to when f depends only on t).

RK4 is fourth order: its global error is O(h^4), so halving the step cuts the error by 16. That richness is why it long served as the workhorse for non-stiff problems. The honest limits: it costs four f-evaluations per step (worth it only when you want several correct digits and f is smooth); it has a FIXED step, so it cannot adapt to easy and hard regions of the solution (modern solvers use embedded pairs for that); and like all explicit Runge-Kutta methods it is only conditionally stable, hence wrong for stiff equations, where an implicit method is required.

One RK4 step on y' = y, y(0) = 1, h = 0.5: k1 = 1, k2 = f(.25, 1.25) = 1.25, k3 = f(.25, 1.3125) = 1.3125, k4 = f(.5, 1.65625) = 1.65625, so y_1 = 1 + (0.5/6)*(1 + 2.5 + 2.625 + 1.65625) = 1.6484. The true e^0.5 = 1.64872 — RK4 with one step beats forward Euler with dozens.

Four slope samples in a 1-2-2-1 average give fourth-order accuracy per step.

Plain RK4 is fixed-step and explicit — not a stiff solver, and no good for an error-controlled run on its own. Practical libraries use embedded RK pairs (RKF45, Dormand-Prince) for adaptive steps, and implicit RK or BDF for stiff systems.

Also called
classic fourth-order Runge-Kuttathe classical RK methodRK4 method經典四階龍格庫塔法