notesonly.in

One notebook for every subject — open it anywhere.

Log in

Runge-Kutta Methods: RK2, RK4 Explained & Compared

Runge-Kutta methods are numerical techniques for solving ordinary differential equations when exact solutions are hard or impossible to find. Many real-world differential equations cannot be solved with paper-and-pen formulas, so these methods compute approximate values of the solution step by step.

They matter because engineers and scientists use them constantly: simulating a rocket's flight, modelling the spread of a disease, or predicting a circuit's behaviour all rely on numerical ODE solvers. The classic fourth-order Runge-Kutta method (RK4) is one of the most trusted algorithms in all of scientific computing.

Key Concepts

  • Initial value problem: given dy/dx = f(x, y) and y(x₀) = y₀, find y at later points.
  • Step size h: the width of each step along the x-axis. Smaller h gives better accuracy but costs more work.
  • Order: a method of order p has local error proportional to hp⁺¹. RK2 is second order, RK4 is fourth order.
  • Stages: RK2 evaluates f at 2 points per step; RK4 at 4 points.
  • Midpoint method: a popular RK2 method using the slope at the middle of the step.

Formulas

RK2 (midpoint method):

  • k₁ = h·f(xₙ, yₙ)
  • k₂ = h·f(xₙ + h/2, yₙ + k₁/2)
  • yₙ₊₁ = yₙ + k₂

RK4 (classical):

  • k₁ = h·f(xₙ, yₙ)
  • k₂ = h·f(xₙ + h/2, yₙ + k₁/2)
  • k₃ = h·f(xₙ + h/2, yₙ + k₂/2)
  • k₄ = h·f(xₙ + h, yₙ + k₃)
  • yₙ₊₁ = yₙ + (k₁ + 2k₂ + 2k₃ + k₄)/6

Assumptions: f must be sufficiently smooth (Lipschitz continuous). Halving h reduces RK4 error roughly by a factor of 2⁴ = 16, but only down to machine-precision limits.

Worked Example

Solve dy/dx = x + y, y(0) = 1, one RK4 step with h = 0.1:

  1. k₁ = 0.1·(0 + 1) = 0.1
  2. k₂ = 0.1·(0.05 + 1.05) = 0.1·1.1 = 0.11
  3. k₃ = 0.1·(0.05 + 1.055) = 0.1·1.105 = 0.1105
  4. k₄ = 0.1·(0.1 + 1.1105) = 0.1·1.2105 = 0.12105
  5. y(0.1) = 1 + (0.1 + 0.22 + 0.221 + 0.12105)/6 = 1 + 0.66205/6 = 1 + 0.1103417 ≈ 1.11034

The exact solution is y = 2ex − x − 1, giving y(0.1) = 2·1.105170 − 1.1 = 1.11034. The RK4 result matches to 5 decimal places.

Common Misconceptions

  • "RK4 is always the best choice." Not for stiff equations (fast and slow dynamics mixed); those need implicit methods.
  • "Smaller h is always better." Below a point, rounding errors dominate and accuracy stops improving.
  • "RK methods need a formula for y." They need only the rule f(x, y) for the slope, not the answer itself.

Real-World Applications

  • Flight simulators integrate aircraft motion equations with RK4 in real time.
  • Epidemic models (SIR models) are solved numerically with Runge-Kutta methods.
  • Weather and climate models step forward atmospheric ODEs millions of times.

Runge-Kutta methods turn unsolvable differential equations into arithmetic any computer can do. RK2 uses two slope samples per step; RK4 uses four, weighted smartly, giving far higher accuracy for barely more work — which is why RK4 remains the default numerical ODE solver across science and engineering.