Numerical Methods · Module 10 of 10

Numerical Solution of ODEs

Most differential equations cannot be solved by hand. Numerical solvers march the solution forward from its starting value, one step at a time. Euler is the idea in its simplest form; Runge-Kutta is the workhorse that gets it right.

01

Readiness check

This closing module marches ODEs forward. Tick only what you can do closed-notes.

  • Read a first-order ODE dy/dx = f(x, y).
  • Recall a slope as the rate of change.
  • Evaluate a function of two variables.
  • Recall the order O(hn) of an error.
  • Recall what an initial condition specifies.
0 or 1 weak itemsContinue with this module.
2 weak itemsRevisit finite differences in Module 9.
3 or more weak itemsReview differential equations in Mathematics, Module 10.
02

The core idea

An ODE solver steps a known starting value forward using the slope the equation provides. Euler takes one slope per step; Runge-Kutta samples several slopes within the step for far higher accuracy.

Euler: yi+1 = yi + h f(xi, yi)RK4: weighted average of four slopesEuler O(h), RK4 O(h4) global

An initial-value problem gives a first-order ODE dy/dx = f(x, y) and a starting value y(x0). The solution is a curve, and the equation provides its slope at any point. Euler's method takes the simplest step: from the current point, follow the slope f(xi, yi) for a step h to the next point. It is easy but only first-order accurate, and its error accumulates, so the curve drifts. Heun's method improves it by averaging the slope at the start with a predicted slope at the end, a predictor-corrector that is second-order. The fourth-order Runge-Kutta method goes further, sampling four slopes across the step, at the start, twice in the middle, and at the end, and combining them in a weighted average; it is fourth-order accurate, the standard solver for smooth problems. Each step adds a local truncation error; these accumulate into a global error one order lower, so a method's global order is what matters over a full integration.

The skill works when: you step forward with the right slope and know the method's global order.
The skill breaks down when: Euler is used with too large a step, or local and global order are confused.
The concept. A solver advances from the start by following slopes. Euler's single slope per step lets the estimate drift from the true curve; higher-order methods sample more slopes to stay on it.
03

The skills, taught in order

Five skills build from the initial-value problem to Euler, Heun, Runge-Kutta, and the error that accumulates.

10.1 The initial-value problem

A first-order ODE dy/dx = f(x, y) with an initial condition y(x0) = y0 has a unique solution curve. The equation gives the slope everywhere; the solver's job is to trace the curve forward from the known starting point.

10.2 Euler's method

Euler's method steps yi+1 = yi + h f(xi, yi): follow the current slope for one step. It is the simplest solver and the clearest to understand, but its first-order accuracy means small steps are needed and error accumulates.

MethodSlopes per stepGlobal order
Euler1 (at the start)O(h)
Heun2 (start and predicted end)O(h2)
Runge-Kutta 44 (across the step)O(h4)

More slope evaluations per step buy a higher order, so a larger step can be used for the same accuracy.

10.3 Heun's method

Heun's method predicts an end point with Euler, evaluates the slope there, and steps with the average of the start and end slopes. This predictor-corrector cancels the leading Euler error, making it second-order for one extra function evaluation.

10.4 The Runge-Kutta method

The classical fourth-order Runge-Kutta method evaluates four slopes, k1 at the start, k2 and k3 at the midpoint, and k4 at the end, then steps with the weighted average (k1 + 2k2 + 2k3 + k4)/6. Its fourth-order accuracy makes it the default for smooth systems.

10.5 Local and global error

Each step introduces a local truncation error; over many steps these accumulate into a global error one order lower than the local one. A method described by its global order, Euler O(h), RK4 O(h4), tells you how the total error shrinks as the step is reduced.

Engineering connection: every dynamic simulation, from a vehicle model to a chemical reactor, marches its governing ODEs with a Runge-Kutta or related solver.

04

Worked example 1: Euler's method

Solve dy/dx = x + y with y(0) = 1 using Euler's method with h = 0.1, for two steps. The exact solution is y = 2ex − x − 1.

Figure 1. Each Euler step follows the slope from the current point, landing a little below the true curve. After two steps the estimate 1.22 trails the exact 1.243.
  1. ProblemSolve the ODE by Euler for two steps of h = 0.1, as in Figure 1.
  2. Given / finddy/dx = x + y, y(0) = 1, h = 0.1. Find y(0.1) and y(0.2), with errors against the exact solution.
  3. AssumptionsConstant step; the slope is taken at the start of each step.
  4. Modelyi+1 = yi + h f(xi, yi), with f(x, y) = x + y.
  5. Equationsyi+1 = yi + h(xi + yi)exact: y = 2ex − x − 1
  6. SolveStep 1: y(0.1) = 1 + 0.1(0 + 1) = 1.1000 (exact 1.1103, error 0.93%). Step 2: y(0.2) = 1.1 + 0.1(0.1 + 1.1) = 1.1 + 0.12 = 1.2200 (exact 1.2428, error 1.84%).
  7. CheckThe estimates fall below the true values and the error grows from step to step, the accumulation expected of a first-order method on a concave-up curve.
  8. ConclusionEuler traces the solution but drifts: nearly 2 percent low after two steps. Smaller steps or a higher-order method would reduce the drift.
Result. y(0.1) = 1.1000, y(0.2) = 1.2200 (errors 0.9% and 1.8%).
05

Worked example 2: the fourth-order Runge-Kutta method

Take one step of the same ODE dy/dx = x + y, y(0) = 1, with the classical fourth-order Runge-Kutta method and h = 0.1, and compare to Euler.

Figure 2. Runge-Kutta samples four slopes across the step and averages them. In one step it matches the exact value to six decimals, where Euler was nearly 1 percent low.
  1. ProblemTake one RK4 step of the ODE and compare to Euler, as in Figure 2.
  2. Given / finddy/dx = x + y, y(0) = 1, h = 0.1. Find y(0.1) by RK4 and its error.
  3. AssumptionsSmooth f; the four slope evaluations are exact.
  4. Modelk1 = f(x, y); k2 = f(x + h/2, y + h k1/2); k3 = f(x + h/2, y + h k2/2); k4 = f(x + h, y + h k3); yi+1 = yi + (h/6)(k1 + 2k2 + 2k3 + k4).
  5. Equationsk1 = 0 + 1 = 1k2 = 0.05 + 1.05 = 1.1; k3 = 0.05 + 1.055 = 1.105k4 = 0.1 + 1.1105 = 1.2105
  6. Solvey(0.1) = 1 + (0.1/6)(1 + 2(1.1) + 2(1.105) + 1.2105) = 1 + (0.1/6)(6.6205) = 1 + 0.110342 = 1.110342. Exact is 1.110342, error ≈ 0.0000002.
  7. CheckRK4 matches the exact value to six decimals in a single step, against Euler's 0.93 percent error, the dramatic gain of fourth-order accuracy.
  8. ConclusionRunge-Kutta delivers near-exact results where Euler drifts, for four slope evaluations per step. It is the standard solver because that trade is almost always worth it.
Result. RK4 y(0.1) = 1.110342, essentially exact, versus Euler's 1.1000.
06

Misconceptions and diagnostics

MistakeSymptomDiagnostic questionCorrection
Euler with a large stepSolution drifts or goes unstable"Is the step small enough?"Reduce h or use a higher-order method.
Local vs global order confusedAccuracy over the run misjudged"Is this the local or global order?"Global error is one order below local.
Reusing the start slope in RK4Method collapses to Euler"Did I evaluate all four slopes?"Sample k1 through k4 at their own points.
Ignoring stabilityA stiff system blows up"Is the problem stiff?"Stiff equations need an implicit or specialised solver.
07

Practice ladder

Level 1 · Direct skill

For dy/dx = −y, y(0) = 1, take one Euler step with h = 0.1.

Show answer

y(0.1) = 1 + 0.1(−1) = 0.9. The exact value is e−0.1 = 0.905, so Euler is slightly low.

Level 2 · Mixed concept

Take a second Euler step of that problem to find y(0.2).

Show answer

y(0.2) = 0.9 + 0.1(−0.9) = 0.81. The exact value is e−0.2 = 0.819, so the error grows.

Level 3 · Independent problem

If Euler has 1 percent error at h = 0.1, roughly what error would you expect at h = 0.05, and what about RK4?

Show answer

Euler is O(h), so halving h roughly halves the error to about 0.5 percent. RK4 is O(h4), so halving h cuts its error by a factor of sixteen.

Transfer task | Real engineering

You must simulate a vehicle dynamics model over a long run. Argue for a solver and step size, and how you would confirm the result is accurate.

What good work looks like

Use RK4 (or an adaptive Runge-Kutta) for its fourth-order accuracy, with a step small enough that halving it changes the result negligibly; confirm accuracy by a step-halving convergence check and, where possible, conservation or energy checks over the run.

08

Working with AI, and proving it yourself

Use AI as an examiner, not a solver

"Check that I evaluated all four Runge-Kutta slopes at the right points."
"Give me three ODEs; I will take one Euler step of each."
"Solve this ODE for me." Marching it forward yourself is the skill.
"Which solver is best?" Reasoning from the global order is the point.

Portfolio task

Solve a real first-order ODE by Euler and by RK4, compare both to the exact solution, and show RK4's error falling far faster as you halve the step.

Must include: both solutions, an error comparison, and a step-halving convergence check.
09

Retrieval and spaced review

Closed notes. Answer out loud, then reveal.

1. Write Euler's method.

yi+1 = yi + h f(xi, yi).

2. How does Heun's method improve on Euler?

It averages the start slope with a predicted end slope, reaching second order.

3. How many slopes does RK4 use, and how?

Four, combined as (k1 + 2k2 + 2k3 + k4)/6.

4. Give the global orders of Euler and RK4.

Euler O(h), RK4 O(h4).

5. How does global error relate to local error?

The global error is one order lower than the local truncation error.

TodayFinish this quiz and Levels 1 and 2 of the ladder.
+1 dayRe-derive the Euler and RK4 steps from a blank page.
+3 daysSolve a new ODE by both methods.
+7 daysCombine roots, systems, and solvers into one computational study.
+30 daysCarry these solvers into Finite Element Methods and Computational Fluid Dynamics, and revisit the course through the Numerical Methods hub.
10

Textbook mapping

This module follows Chapra and Canale, Numerical Methods for Engineers, 7th edition. Use these references to read further.

Topic in this moduleWhere to read more
Euler's method and the initial-value problemChapra & Canale, Chapter 25
Heun's method and Runge-KuttaChapra & Canale, Chapter 25
Local and global error, stabilityChapra & Canale, Chapter 25

Chapter numbers refer to the 7th edition. The ODE solvers are standard, so any recent edition will align closely.