MATH 4810Computational Modelling

Module 02 · Unit 2.2 · Lesson 1 of 3

Fourth-Order Runge–Kutta Method

The workhorse of deterministic simulation. Four stage evaluations per step buy fourth-order accuracy — a practical sweet spot that has made RK4 the default choice for non-stiff ODE problems.

Duration ≈ 3 hours Prerequisite Unit 2.1 Feeds Lab 4 · Assignment 2
  1. Lesson 1
  2. Lesson 2
  3. Lesson 3

1 Modelling context

The second-order methods of Unit 2.1 improved on Euler by using the average of two slope estimates. The natural question is whether even better estimates of the average slope can be obtained with additional stage evaluations. The classical Runge–Kutta method answers this question: by combining four carefully chosen slope estimates, it achieves fourth-order accuracy.

Fourth-order Runge–Kutta — RK4 — is the workhorse of deterministic simulation. It is implemented in every serious ODE solver, it appears in every numerical methods textbook, and it is the default choice for non-stiff initial-value problems. The method's appeal is not that it is the most accurate possible, but that it achieves a good balance of accuracy, cost, and simplicity.

Why "the" Runge–Kutta method?

The name Runge–Kutta refers to a family of methods, not a single method. The fourth-order scheme developed in this lesson is the most widely used member of the family, and is often called the Runge–Kutta method without qualification.

2 Learning objectives

By the end of this lesson you will be able to

  • Write out the classical fourth-order Runge–Kutta update rule.
  • Explain the geometric meaning of the four stages.
  • Implement RK4 in a spreadsheet with documented inputs and step size.
  • Verify the method against an analytical solution.
  • Compare RK4 with Euler and second-order methods by accuracy and cost.

3 Prerequisite review

Increment function
The function Φ(t, y, h) that defines how a one-step method advances the solution. Introduced in Unit 2.1.
Order of a method
The exponent p such that the global error scales as O(hp). Developed formally in Unit 2.1, Lesson 3.
Predictor–corrector structure
The pattern of making a preliminary estimate and then correcting it using information from the estimated point. RK4 extends this pattern to four stages.
Numerical verification
The comparison of a numerical solution against an external reference — typically an analytical solution or a known limiting case.

4 Mathematical formulation

Consider the initial-value problem

dy/dt = f(t, y),    y(t₀) = y₀

with step size h. The classical fourth-order Runge–Kutta method advances the solution from (t_n, y_n) to t_{n+1} = t_n + h using four stage evaluations:

k₁ = f(t_n, y_n)
k₂ = f(t_n + h/2,  y_n + (h/2) k₁)
k₃ = f(t_n + h/2,  y_n + (h/2) k₂)
k₄ = f(t_n + h,    y_n + h k₃)

y_{n+1} = y_n + (h/6) ( k₁ + 2 k₂ + 2 k₃ + k₄ )

Geometric interpretation of the stages

The four stages sample the derivative at different points within the step. Each stage refines the estimate of the average slope:

  • k₁ is the slope at the start of the step — the same estimate Euler uses.
  • k₂ is the slope at the midpoint, estimated by taking an Euler half-step using k₁.
  • k₃ is a second slope at the midpoint, refined using k₂ instead of k₁. It is usually close to k₂ but more accurate when the solution curves.
  • k₄ is the slope at the endpoint, estimated by a full Euler step using k₃.

The final update is a weighted average of these four slopes, with the midpoint estimates receiving double weight. The weights (1, 2, 2, 1)/6 are chosen so that the Taylor expansion of the numerical step matches the exact solution through terms of order h⁴, giving a local error of O(h⁵) and a global error of O(h⁴).

Why the weights are (1, 2, 2, 1)/6

The derivation proceeds by expanding the numerical update and the exact solution in Taylor series, then matching coefficients. The algebra is lengthy but the principle is simple: the four stage evaluations provide four degrees of freedom, which are used to match the Taylor expansion through the fourth-order term. This is the same logic as in Unit 2.1, extended to four stages.

The result is that the leading truncation term — the term of order h⁵ — is eliminated, leaving the error of the method dominated by terms of order h⁵ and higher. This is why RK4 achieves fourth-order global accuracy.

Stage points of classical Runge-Kutta within one step A single step from t_n to t_{n+1} with the exact solution shown as a smooth curve. Four stage points are marked: k1 at the start, k2 and k3 at the midpoint (offset horizontally to distinguish them), and k4 at the endpoint. Short line segments from each stage point indicate the slope used at that stage. t_n t_n + h/2 t_n + h k₁ k₂ k₃ k₄ exact solution y(t) stage slopes
Figure 2.6. The four stage points of classical Runge–Kutta within one step. The midpoint is sampled twice — once using k₁ and once using k₂ — to capture the curvature of the solution.

5 Worked example

One RK4 step on dy/dt = y

Take dy/dt = y, y(0) = 1, with step size h = 0.1. Compute one RK4 step by hand.

Stage evaluations.

k₁ = f(0, 1) = 1

k₂ = f(0.05, 1 + 0.05 · 1) = f(0.05, 1.05) = 1.05

k₃ = f(0.05, 1 + 0.05 · 1.05) = f(0.05, 1.0525) = 1.0525

k₄ = f(0.1, 1 + 0.1 · 1.0525) = f(0.1, 1.10525) = 1.10525

Weighted update.

y₁ = 1 + (0.1/6) · ( 1 + 2·1.05 + 2·1.0525 + 1.10525 )
   = 1 + (0.1/6) · ( 1 + 2.10 + 2.105 + 1.10525 )
   = 1 + (0.1/6) · 6.31025
   = 1 + 0.1051708
   ≈ 1.1051708

Comparison with the exact solution.

Exact: e0.1 ≈ 1.1051709. The RK4 step is correct to seven significant figures — a striking improvement over the 0.005 error of forward Euler at the same step size.

Over a full interval.

Integrate to t = 1 with h = 0.1 (ten steps). The RK4 solution at t = 1 is 2.71828, correct to six significant figures. Euler's solution at the same step size has an error of 0.125 — more than five orders of magnitude worse.

Effect of halving the step size.

Halving the step size in RK4 reduces the error by a factor of approximately 16 (that is, 2⁴). This is the numerical signature of a fourth-order method and is confirmed formally in the convergence study of Lesson 2.

6 Verification check

Checks to perform

  • Reproduce one RK4 step by hand. Compute all four stages and the weighted update for a single step, and compare against the spreadsheet.
  • Check the conservation property. For a linear problem with a conserved quantity, confirm that the quantity is conserved to within the fourth-order error.
  • Verify against an analytical solution. For dy/dt = y, y(0) = 1, the exact solution is et. Compare RK4 at several step sizes.
  • Confirm fourth-order convergence. Halving the step size should reduce the error by a factor of approximately 16. A factor of 2 or 4 indicates an implementation error.
  • Test the limiting case of constant f. When f(t, y) = a (constant), all four stages coincide and RK4 reduces to y_{n+1} = y_n + a h, which is exact. Verify this.
  • Check the stage indices. Confirm that each stage uses the correct previous stage in its estimate. Swapping k₂ and k₃ produces a method that is neither correct nor obviously wrong.

7 Interpretation

RK4 is not the most accurate method available, nor the cheapest. It is the most useful compromise for non-stiff problems, for three reasons.

  • The accuracy-cost ratio is favourable. Four evaluations per step for fourth-order global error is a better tradeoff than lower-order methods with fewer evaluations. For most problems, achieving a given accuracy with RK4 requires far fewer total evaluations than Euler or second-order methods.
  • It is self-starting. Unlike multistep methods, RK4 requires only the initial condition. It does not need startup procedures or history.
  • It is easy to implement and easy to verify. The four stages are explicit and the update rule is unambiguous. Convergence studies confirm the order numerically with little effort.
Cost of RK4 compared with lower-order methods
Method Evaluations per step Order Steps for error 10⁻⁶ on dy/dt = y Total evaluations
Euler 1 1 ≈ 10⁶ 10⁶
Modified Euler 2 2 ≈ 10³ 2 × 10³
RK4 4 4 ≈ 32 ≈ 128

The table is illustrative, but the pattern is general. For a target accuracy that requires more than three or four significant figures, RK4 outperforms lower-order methods by a wide margin in total cost.

Why not go higher?

Higher-order methods exist — order five, six, and beyond. They require more stage evaluations per step, and the improvement in accuracy per additional stage diminishes. For most problems, the practical choice is between RK4 with a reduced step size and a higher-order method with a larger step. Reducing the step size in RK4 is usually simpler and produces comparable results.

8 Uncertainty and limitations

RK4 inherits the limitations of all explicit one-step methods, and it has some of its own.

Properties of RK4
Property Status Notes
Truncation error Excellent Local O(h⁵), global O(h⁴)
Cost per step Moderate Four evaluations of f
Stability region Limited Larger than Euler's but still conditional
Suitability for stiff problems Poor Explicit; small steps required for stability
Error estimation Not built in Requires step doubling or an embedded method
Conservative systems Not symplectic Energy drifts slowly over long integrations

Two of these deserve elaboration. First, RK4 does not estimate its own error. To adapt the step size during integration, one needs either a step-doubling procedure or an embedded Runge–Kutta pair. These are discussed in Lesson 2. Second, for long integrations of conservative systems — planetary motion, molecular dynamics, Hamiltonian systems — RK4 introduces a slow drift in the conserved quantity. Symplectic integrators, beyond the scope of this course, address this.

Order does not imply suitability

RK4 is an excellent general-purpose method. It is a poor choice for stiff problems and for long integrations of conservative systems. The choice of method depends on the problem, not on the order alone.

9 Common implementation errors

Watch for these

  • Using k₁ instead of k₂ in the k₃ stage. This is the single most common implementation error. k₃ uses k₂; using k₁ reduces the method to something of lower order.
  • Using y_{n+1} in the stage evaluations. All four stages are computed before the update. Using the updated y in stage 4 introduces an implicit structure that changes the method.
  • Getting the weights wrong. The correct weights are 1, 2, 2, 1, divided by 6. A common mistake is to use 1, 1, 1, 1 (Simpson weights without the endpoints) or 1, 4, 1 combined with the wrong stages.
  • Evaluating k₄ at the midpoint instead of the endpoint. k₄ is evaluated at t_n + h, not t_n + h/2.
  • Assuming fourth-order means the answer is correct. A fourth-order method produces a fourth-order accurate solution to the given ODE. If the ODE is the wrong model, the answer is still wrong — no matter how small the truncation error.
  • Ignoring the stability region. RK4 is stable for hλ in a bounded region around the negative real axis. For stiff problems, the stability limit can force impractically small steps.
  • Forgetting to document the step size and update rule. The step size is a modelling parameter and must be recorded alongside the initial conditions and the ODE itself.

10 Independent modelling task

Your turn

  1. Choose an initial-value problem with a known analytical solution. Good options include dy/dt = −y, dy/dt = y − t, or a simple harmonic oscillator.
  2. Implement RK4 in your spreadsheet, alongside the methods from Unit 2.1. Use a clearly labelled input region.
  3. Compute the RK4 solution at h = 0.2, h = 0.1, and h = 0.05. Record the absolute error at the final time.
  4. Tabulate the ratios of successive errors. Confirm that the ratios approach 16, the signature of fourth-order convergence.
  5. Plot the numerical and analytical solutions on the same axes for the largest step size. Compare with the Euler solution at the same step size.
  6. Compute the total number of evaluations of f required by each method to achieve an absolute error of 10⁻⁴. Rank the methods by total cost.
  7. Write a short paragraph on the circumstances in which RK4 is or is not the right choice.

This exercise forms the basis for Laboratory 4 and the ODE simulation component of Assignment 2.

11 Reflection prompt

Reflect before continuing

RK4 is often called "the default method" for non-stiff ODEs. What properties make a method suitable as a default?

Two or three sentences. Consider accuracy, cost, ease of implementation, and the range of problems for which the method works acceptably.

12 Lesson summary

Key takeaways

  • Classical RK4 uses four stage evaluations per step. Each stage estimates the slope at a different point within the step.
  • The update is a weighted average of the stages. The weights are 1, 2, 2, 1, divided by 6.
  • Local error is O(h⁵); global error is O(h⁴). Halving the step size reduces the global error by a factor of approximately 16.
  • RK4 is the practical default for non-stiff problems. The accuracy-cost ratio is favourable, and the method is easy to implement and verify.
  • RK4 is not universally appropriate. It is a poor choice for stiff problems and for long integrations of conservative systems.

Coming next

Lesson 2 develops the numerical practice of convergence studies and step-size selection, including the step-doubling procedure for estimating error during integration.

§ Self-quiz, practice, and homework

Self-quiz

Q1

Classical fourth-order Runge–Kutta uses how many evaluations of f per step?

Show answer

4.

Q2

The correct weights in the RK4 update are:

Show answer

1, 2, 2, 1 (divided by 6).

Q3

k₃ uses which prior stage in its estimate?

Show answer

k₂. Using k₁ would reduce the order.

Q4

Halving the step size in RK4 typically reduces the global error by a factor of approximately:

Show answer

16. 2⁴ = 16.

Q5

RK4 is a poor choice for:

Show answer

Stiff problems and long integrations of conservative systems.

Practice exercises

  1. Apply RK4 by hand to dy/dt = −y, y(0) = 1 with h = 0.2 for one step. Compute all four stages, the update, and the error against e^{−0.2}.
  2. Repeat exercise 1 with h = 0.1 for two steps. Confirm the global error at t = 0.2 is smaller than the single-step error at h = 0.2.
  3. For dy/dt = y cos(t), write the four stages explicitly. Compute one step from (0, 1) with h = 0.1.
  4. Verify that RK4 reduces to y_{n+1} = y_n + a h exactly when f = a is constant.

Homework problems

  1. RK4 implementation and convergence. Implement RK4 in a spreadsheet for dy/dt = −2 y + sin(t), y(0) = 1. Run at h = 0.2, 0.1, 0.05, 0.025. Tabulate the errors at t = 3. Compute the observed order. Produce a log-log plot.
  2. Cost comparison. Compute the total number of evaluations of f required by Euler, modified Euler, and RK4 to reach an absolute error of 10⁻⁵ at t = 3. Present in a table and discuss.
  3. Limitations. Choose a problem where RK4 is a poor choice (e.g. a stiff system, or a long integration of a harmonic oscillator). Demonstrate the limitation numerically and explain it in terms of RK4's properties.

Mini project

Choose a physically meaningful ODE model — a damped oscillator, a predator–prey system, an epidemic model, or similar. Implement RK4, run a convergence study, and compare against a lower-order method. Produce a technical report documenting the model, the implementation, the convergence evidence, and the cost. This is the basis for Laboratory 4 and the ODE simulation component of Assignment 2.

👤