Euler, Improved Euler, and Runge–Kutta
Most initial value problems have no closed-form solution, so the solution is approximated on a grid. Euler's method steps along the tangent line, the improved Euler method averages two slopes, and the classical Runge–Kutta method averages four.
╌╌╌╌
Analytic techniques (integrating factors, separation of variables, series, Laplace transforms) solve a limited catalogue of equations. A generic nonlinear first-order problem
usually has no solution expressible in elementary functions, yet the existence theorem still guarantees a unique solution whenever and are continuous near . A numerical method abandons the search for a formula and instead produces a table of approximate values at prescribed points , each meant to approximate .1 We fix a uniform step size , set , and abbreviate . Each method is a rule for advancing from to .
Euler's method
The oldest and simplest rule comes from three equivalent readings of the same approximation.
- Tangent line. At the differential equation gives the slope . Follow that tangent for a horizontal distance : the height changes by .
- Difference quotient. Replace by the forward difference in the equation and solve for .
- Truncated Taylor series. Expand and drop the quadratic term.
All three yield the Euler formula.
Geometrically the exact solution curve is replaced by a polygon of tangent segments. For a convex solution () every segment lies below the curve, so the approximation drifts steadily downward; a concave solution drifts the other way.
Written as a program the method is a single loop; only line 4 encodes the choice of rule, and the methods that follow replace that single line.
- 1,
- 2output
- 3for from to do
- 4advance along the tangent
- 5
- 6output
- 7end
A test problem
The linear equation
has the exact solution , which lets us monitor the error exactly. Its solutions diverge quickly (the term), so it is deliberately hard to track over a long interval, and differences between methods show clearly.2 Euler's method with several step sizes gives the following values, with the percentage error against shown in parentheses.
| Exact | ||||
|---|---|---|---|---|
Reaching accuracy at requires steps. The accuracy is unimpressive because the error compounds: halving only halves the error, and the error grows with as the solution steepens.
A single step is pure arithmetic. Taking the coarser , so the numbers stay legible, and running five steps by hand:
Truncation error and order
Two errors matter, and they must be kept separate.
Subtracting the Euler step from the exact Taylor expansion isolates the local error. Since the two share the terms , only the quadratic remainder remains:
The local truncation error is proportional to ; a uniform bound is with on the interval.3 The global error accumulates one local error per step over steps, which drops one power of : it can be shown that on any finite interval.4 This scaling defines the method's order.
For the test problem , so the local error near is about times larger than near . A uniform step sized for the hard end wastes effort at the easy end, which motivates adaptive codes that shrink only where is large.
The backward Euler formula
Approximating the same integral by the value at the right endpoint gives the backward Euler formula
The unknown now appears on both sides, so the formula is implicit: each step requires solving an equation. For the linear test problem this is routine algebra, but for nonlinear it needs an iterative solve. Backward Euler is no more accurate than forward Euler (still order 1) and more expensive; its advantage is stability, which matters for stiff problems, where an explicit method forces an impractically small step.
The improved Euler method
Integrating the equation over one step turns the problem into approximating an area:
Euler replaces the integrand by its left-endpoint value : the area of a rectangle. A better estimate averages the endpoint slopes, replacing the rectangle by a trapezoid.
The trapezoid rule uses , but is unknown. Replacing it by the Euler prediction removes the implicitness and gives an explicit two-stage rule.
The cost is two evaluations of per step instead of one.5 For a fixed the improved Euler method does twice the work of Euler, or equivalently matches Euler at half the step.
On the test problem the improved Euler method with ( evaluations) is already slightly more accurate than Euler with ( evaluations): about one-twelfth the work for comparable accuracy.
The Runge–Kutta method
Euler and improved Euler are the first two members of the Runge–Kutta family, which sample at several points inside the step and take a weighted average of the slopes. The classical fourth-order, four-stage method is the standard general-purpose integrator.6
Reading the four slopes: is the slope at the left end; is a midpoint slope reached by an Euler half-step; is a second, corrected midpoint slope; is the slope at the right end reached using . The weighting counts the two midpoint slopes double.
When depends on alone, the four slopes collapse to Simpson's rule for , whose error is consistent with RK4's order. On the test problem RK4 with ( evaluations) matches the accuracy of improved Euler with ( evaluations) at a quarter of the work ( versus error at ); with the value at is correct to four digits ( error).
Comparing the methods
Each added stage raises the order of accuracy and requires more evaluations of per step. Since evaluating dominates the run time, the fair comparison holds the total number of evaluations fixed.
| Method | Evaluations of per step | Local error | Global error | Order |
|---|---|---|---|---|
| Euler | ||||
| Backward Euler | (implicit) | |||
| Improved Euler (Heun) | ||||
| Runge–Kutta (RK4) |
The test problem, evaluated at with roughly equal computational effort, shows the ranking.
| Method | Step | Evaluations to | Value at | Error |
|---|---|---|---|---|
| Euler | ||||
| Improved Euler | ||||
| Runge–Kutta |
At the same evaluations RK4 is more than a hundred times more accurate than improved Euler. A higher-order method is more efficient: for the same work it delivers better accuracy, and for the same accuracy it needs far less work. On a log–log plot of error against step size, a method of order produces a straight line of slope , so halving divides the error by .
Step size, accuracy, and adaptive methods
A method's order fixes how fast error falls as , but it does not fix the right for a given tolerance. Since the local error is proportional to , the step needed for a target tolerance scales like , and the constant depends on derivatives of the unknown solution. Practical codes estimate the local error as they run: compute the step two ways (for instance with a th- and a th-order formula) and use the difference as an error estimate. When the estimate exceeds the tolerance, shrink and retry; when it is comfortably under, grow to save work.
Embedding a higher-order formula that reuses the same slope evaluations adds almost no extra work. The Runge–Kutta–Fehlberg pair (RKF45) computes a fourth- and a fifth-order estimate from one shared set of stages plus one extra, and its 1977 Fortran implementation RKF45 became a template for the adaptive integrators in modern software.7
Footnotes
- Boyce, §8.1 — a numerical method approximates the solution of , on a mesh rather than seeking a closed form. ↩
- Boyce, §8.1, Example 1 — the linear problem , with exact solution , used throughout Ch. 8 to compare methods. ↩
- Boyce, §8.1 — the Euler local truncation error , bounded by . ↩
- Boyce, §8.1, Problem 20 — the global truncation error bound for the Euler method on a finite interval, making it a first-order method. ↩
- Boyce, §8.2 — the improved Euler (Heun) formula as a two-stage predictor–corrector with local error proportional to ; also Simmons, §75. ↩
- Boyce, §8.3 — the classical fourth-order four-stage Runge–Kutta formula, its four-slope weighted average, and the Simpson's-rule reduction when ; also Simmons, §76. ↩
- Boyce, §8.3 — adaptive Runge–Kutta methods and the Runge–Kutta–Fehlberg (RKF45) embedded fourth/fifth-order pair. ↩
╌╌ END ╌╌