What Is the Runge-Kutta Method?
The fourth-order Runge–Kutta method (RK4) is the standard workhorse for solving initial value problems y′ = f(x, y), y(x₀) = y₀ numerically. Where Euler's method samples the slope once per step and walks straight, RK4 samples it four times at the start, twice at the midpoint, and at the end of the step, and blends the four readings into one superbly balanced update:
k₁ = f(xₙ, yₙ) slope at the start
k₂ = f(xₙ + h/2, yₙ + h·k₁/2) slope at the midpoint, reached via k₁
k₃ = f(xₙ + h/2, yₙ + h·k₂/2) midpoint again, corrected via k₂
k₄ = f(xₙ + h, yₙ + h·k₃) slope at the far end
yn+1 = yₙ + (h/6)(k₁ + 2k₂ + 2k₃ + k₄)
The weights 1-2-2-1 over 6 are Simpson's rule in disguise, RK4 is to differential equations what Simpson's rule is to integrals, and it inherits the same fourth-order accuracy: halve the step, and the error drops by a factor of sixteen.
How to Use This Calculator
Enter the right-hand side f(x, y), the initial condition, the step size, and the number of steps. Each step's four slope evaluations k₁ through k₄ are listed so you can verify hand computations stage by stage, RK4 by hand is bookkeeping-heavy, and a mislabeled k is the classic error. The plot shows the RK4 points (indigo) over a fine-step reference (dashed teal); at typical step sizes the two are visually inseparable, which is rather the point.
Worked Example
The same benchmark used on the Euler page: y′ = x + y, y(0) = 1, h = 0.1, ten steps to x = 1. The first step's stages: k₁ = f(0, 1) = 1; k₂ = f(0.05, 1.05) = 1.1; k₃ = f(0.05, 1.055) = 1.105; k₄ = f(0.1, 1.1105) = 1.2105. The update: y(0.1) ≈ 1 + (0.1/6)(1 + 2.2 + 2.21 + 1.2105) = 1.110342. After ten such steps:
y(1) ≈ 3.436559, exact: 2e − 2 = 3.436564
Error ≈ 0.000005, five decimal places, from the same ten steps that left Euler's method wrong in the first decimal (3.187). That head-to-head is the whole argument for higher-order methods: four times the work per step, roughly fifty thousand times the accuracy on this problem.
Why Four Stages Beat Four Small Euler Steps
A fair skeptic asks: RK4 evaluates f four times per step, so why not just take four Euler steps of size h/4? Because error order beats error constant. Four Euler steps of h/4 still leave a first-order method, error ~h/4. RK4's single step of size h carries error ~h⁴. At h = 0.1 that's the difference between 0.025-ish and 0.0000something: the four evaluations are spent canceling error terms systematically (each kᵢ corrects the geometry the previous one missed) rather than merely walking more carefully. This is the deepest lesson in numerical analysis pricing: cleverness about where you sample beats brute force about how often.
Common Mistakes to Avoid
- Using k₁ instead of k₂ inside k₃. The stages chain: k₃'s trial point uses k₂, not k₁, and k₄'s uses k₃ with a full step. Swapping feeds ruins the error cancellation while still producing plausible-looking numbers.
- Forgetting the half steps. k₂ and k₃ are evaluated at xₙ + h/2 with half-scaled y-increments. Using full h in the middle stages silently degrades the method to lower order.
- Assuming RK4 conquers everything. Stiff systems defeat explicit RK4 exactly as they defeat Euler, stability, not accuracy, becomes the binding constraint, and implicit methods take over.
- Chasing accuracy with ever-smaller h. Below a point, roundoff error accumulates faster than truncation error shrinks; there is an optimal h, and production codes find the sweet spot adaptively rather than guessing.
Real-World Applications
RK4 and its adaptive descendants (Runge–Kutta–Fehlberg, Dormand–Prince, the `ode45` inside MATLAB and `solve_ivp` inside SciPy) integrate the equations of motion for spacecraft trajectories, satellite orbit prediction, and missile guidance; simulate chemical reaction networks and pharmacokinetic drug models; and propagate the neuron models of computational neuroscience. When an engineer says "I solved the ODE numerically," the odds are overwhelming that a Runge–Kutta variant did the work.
The method's blend of accuracy, simplicity, and self-starting convenience (no history needed, unlike multistep methods) makes it the default first choice across simulation: flight dynamics in aerospace certification, vehicle handling models in automotive design, power-grid transient analysis, and epidemiological compartment models all lean on it. Even weather models, though they use specialized schemes at scale, prototype their dynamics with RK integrators first.
Frequently Asked Questions
What does "fourth-order" mean exactly?
Global error shrinks like h⁴: halving the step divides the error by 16, and a tenfold refinement buys four extra decimal digits. The local (per-step) error is one order better, h⁵, with the difference absorbed by the ~1/h steps needed to cross the interval.
Why the weights (1, 2, 2, 1)/6?
They're chosen so the update's Taylor expansion matches the true solution's through the h⁴ term, a nonlinear system solved once by Kutta in 1901. The pattern mirrors Simpson's rule because integrating y′ = f(x) with RK4 literally is Simpson's rule; RK4 generalizes it to slopes that depend on y.
What are adaptive Runge-Kutta methods?
Solvers that run two RK formulas of different orders side by side, use their disagreement as a live error estimate, and grow or shrink h automatically, tight steps through fast dynamics, long strides through calm stretches. Dormand–Prince (RK45) is the ubiquitous example; this calculator's fixed step is the concept those tools automate.
Can RK4 solve second-order equations like y″ + y = 0?
Yes, after converting to a first-order system: let v = y′, then y′ = v and v′ = −y, and RK4 advances the pair (y, v) with the same four-stage recipe applied to vectors. The second-order ODE calculator handles the constant-coefficient case symbolically for comparison.
When is Euler actually preferable to RK4?
When f is expensive and accuracy demands are loose (real-time games), when stochastic terms make high order pointless (SDEs use Euler–Maruyama), or when a structure-preserving variant matters more than raw accuracy (symplectic Euler for long orbital simulations). Order isn't everything; matching the method to the problem is.
How do I verify an RK4 hand computation with this tool?
Run a single step (n = 1) and compare your k₁, k₂, k₃, k₄ against the step log, each stage is printed separately. Mismatches at k₂ usually mean a missing half step; at k₄, a half step that shouldn't be there.