Numerical Solution of Differential Equations
Stepping methods that approximate a solution when no formula exists, carried out by hand for Euler and improved Euler, and separately judged: the order of accuracy that says how each responds to a smaller step, the stability limit that can make a smaller step necessary rather than merely better, and what a computed answer does and does not establish.
Definition
A numerical method for the initial value problem
produces approximations
Euler's method. The differential equation gives the slope at any point, so follow it for one step:
This is the tangent line to the solution through
Improved Euler (Heun's method). The slope at the start of a step is generally not the slope across it, so average the slope at both ends, using an Euler step to predict the far end:
Classical Runge–Kutta (RK4). Four slope evaluations, weighted toward the midpoint:
Order of accuracy. A method has order
| Method | Slope evaluations per step | Order | Error when |
|---|---|---|---|
| Euler | 1 | 1 | halved |
| Improved Euler | 2 | 2 | quartered |
| RK4 | 4 | 4 | divided by 16 |
Order describes the trend as
Stability. Accuracy is not the only constraint. Applying Euler to
For
Assumptions and scope
These methods approximate. They return numbers at chosen points, never a formula, and no amount of refinement produces one.
Order describes asymptotic behaviour as
. Observed error ratios approach, and rather than equalling them, and at coarse steps they can be well short. Stability is a separate requirement from accuracy. Euler on
with needs regardless of the accuracy sought.Halving the step doubles the number of steps, so error per step and total work move in opposite directions; the comparison between methods is per unit of work, not per step.
Round-off sets a floor. Below a certain step size, accumulated floating-point error grows while truncation error shrinks, so the total stops improving and eventually worsens.
The methods assume
is defined along the whole path taken. A solution that escapes to infinity in finite time, as does, will produce numbers past the blow-up that mean nothing.
Worked material
Example
An equation with no closed-form solution
The worked example used an equation with a known exact solution, so the error could be measured. That is the exception. Here is the ordinary case.
Problem. Approximate
Why no formula is coming. The right side is a polynomial in two variables, about as simple as a nonlinear equation gets. But it does not separate:
None of that is a defect of the equation. The right side is continuous and differentiable everywhere, so a unique solution through
Solve it numerically with RK4. Since there is no exact answer to compare against, run the method at several step counts and look for agreement:
| Steps | RK4 estimate of | |
|---|---|---|
| 10 | ||
| 100 | ||
| 1000 | ||
| 10000 |
The estimates stop changing. From
to ten decimal places, and the last two rows agreeing is the evidence for it.
This is the error-estimation technique of the procedure block put to work: with no exact solution available, agreement between step sizes is the check. The rapid convergence, three extra digits from
What has and has not been produced. There is now a number, good to ten digits, for a quantity no formula in this corpus can express. What there is not is a function: to know
A caution about going further. Solutions of nonlinear equations can cease to exist in finite time,
Contrast
Same work, three methods
Comparing methods per step is misleading, because a step of RK4 costs four evaluations of
The test.
| Method | Steps | Result | Error | |
|---|---|---|---|---|
| Euler | 32 | |||
| Improved Euler | 16 | |||
| RK4 | 8 |
For identical cost, RK4 is about 8300 times more accurate than Euler and 340 times more accurate than improved Euler. The coarser step of the higher-order method is more than repaid by the exponent.
The gap widens with the budget. Doubling to 64 evaluations:
| Method | Steps | Error at 32 evals | Error at 64 evals | Improvement |
|---|---|---|---|---|
| Euler | 32 → 64 | |||
| Improved Euler | 16 → 32 | |||
| RK4 | 8 → 16 |
Each doubling of effort buys Euler one factor of 2 and RK4 a factor of 15. The advantage compounds, so the more accuracy is wanted, the more decisively the higher-order method wins.
A single RK4 step, costing four evaluations, gives error
When the ranking does not hold.
- When
is not smooth. The order theorem assumes enough derivatives exist. Across a kink in , RK4's four samples straddle the discontinuity and its advantage collapses toward first order. - When stability binds. For a stiff equation the step is capped by the stability limit, not by accuracy. If
must be tiny anyway, the extra accuracy per step is wasted, and an implicit method, which has no such cap, beats all three. - When only a rough answer is wanted. For one or two digits, Euler's simplicity can be worth more than RK4's accuracy, especially by hand.
- When
is cheap and coding time is not. Euler is three lines.
Higher order is not a free improvement, since it costs evaluations per step, but the exponent beats the constant factor as soon as any real accuracy is required. That is why RK4 is the default in step 2 of the procedure, and why the exceptions are about smoothness and stability rather than about accuracy.
Common errors
Common misconception
A smaller step size always gives a better numerical answer, so accuracy is limited only by how long one is willing to compute.
Common misconception
The step size in a numerical method is chosen from the accuracy wanted, so a problem needing only one or two digits may always be integrated with a coarse step.
Related units
Requires
Connected
- Convergence of Infinite Series (related)
- Systems of Linear Differential Equations (related)