Numerical Solution of Differential Equations
What you will be able to do
Given an initial value problem, the learner can carry out Euler and improved Euler steps by hand, evaluating each slope at the point the formula names and tabulating the result against an exact solution where one exists.
What you will be able to do
Given a numerical result or a problem to integrate, the learner can predict how the error responds to halving the step from the method's order, compute the stability limit and recognise when it binds rather than accuracy, select a method and step size for a stated requirement, and say what the computed output does and does not establish.
Orientation
When there is no formula to find
Four units have solved differential equations exactly: separation and integrating factors, the characteristic equation, and eigenvalues for systems. Each produced a formula.
Those equations are a thin slice. Change
and no elementary formula exists. Nothing is wrong with the equation. The right side is a polynomial, smooth everywhere, and the solution through
What remains available is the equation itself. It reports the slope at any point, and that is enough to walk the curve out numerically: from a known point, follow the slope a short distance, ask the equation again at the new point, and repeat. That is Euler's method, and it turns a differential equation into arithmetic.
The answer changes character. Instead of
Two questions follow.
How wrong is it? Every step follows a slope that is exactly right only at its start, while the true solution curves away during the step. Errors accumulate. Halving Euler's step only halves the error, so a tenfold increase in work buys about one extra digit, poor value. Sampling the slope more than once per step does far better: two evaluations quarter the error, four divide it by sixteen.
When does it break? Not always where one would expect. Applied to a rapidly decaying equation with too large a step, Euler returns values that oscillate and grow. One case in this unit produces
Why this matters
Why one slope per step is not enough
Euler's method advances each step using the slope at the step's start. The following figures give its error behaviour before any refinement is introduced.
Take
The answer is
Refining the step helps slowly. Halving
| Euler's | Error | Ratio to previous | ||
|---|---|---|---|---|
| 1 | — | |||
| 2 | ||||
| 4 | ||||
| 8 | ||||
| 16 | ||||
| 32 | ||||
| 64 | ||||
| 128 |
The ratios climb toward 2: halving the step halves the error. This is what first order means. Going from 1 step to 128, which is 128 times the work, reduced the error from
Notice also that the ratio approaches 2 rather than equalling it. Order is a statement about the trend as
The remedy is to look at the slope more than once. The slope at the start of a step is not the slope across it. Evaluating
| Improved Euler | Error | Ratio | ||
|---|---|---|---|---|
| 1 | — | |||
| 2 | ||||
| 4 | ||||
| 8 | ||||
| 16 | ||||
| 32 |
The ratios head for 4. At
Four evaluations do better still. RK4 reaches error
| RK4 | Error | Ratio | |
|---|---|---|---|
| 1 | — | ||
| 2 | |||
| 4 | |||
| 8 | |||
| 16 |
With a single step, RK4 is more accurate than Euler with 128. On this problem, four evaluations per step buy more accuracy than the same total work spent on additional first-order steps.
This comparison uses one smooth, non-stiff equation with a fixed step. It establishes the order of each method on that problem. It does not establish which method to use in general: stiff equations, adaptive step-size control, and error tolerances change the comparison, and solver libraries select among several methods on those grounds.
Definition
Reading the formulas: where each slope is evaluated
Almost every error in applying these formulas is an error about where a slope is evaluated.
Euler: one slope, at the current point. In
**Improved Euler: the second slope is at a predicted point.** The formula
evaluates
The averaging is what earns the second order. Overestimating the slope at one end tends to be compensated by the other, and the leading error term cancels.
RK4: two of the four slopes are at the midpoint. Reading the weights
Note that
Order: what
- It is a statement about small
. The observed ratios in this unit climb toward their limits, Euler's reach at , RK4'sat , rather than attaining them. - It says nothing about the constant
. A higher-order method can be less accurate at coarse steps, though not usually. - It counts steps, not work. Halving
doubles the number of steps, so comparisons between methods must be made per slope evaluation, which is what makes RK4's factor of 16 worth its four evaluations.
Stability: a separate constraint entirely. Applying Euler to
For real
Procedure
Approximating a solution numerically
Input. An initial value problem
Step 1 — Check whether an exact method applies first. If the equation is separable, linear, or constant-coefficient, solve it exactly; a formula is better than a table of numbers. Numerical methods are for when that fails, which is most of the time, but not always.
Step 2 — Choose a method. Use RK4 unless there is a reason not to: four evaluations per step buy fourth-order accuracy, which almost always costs less total work than Euler at the same accuracy. Euler and improved Euler are worth doing by hand for understanding, and Euler remains useful where
Step 3 — Check the stability limit if the equation decays rapidly. Estimate
and this bound can be far more restrictive than accuracy alone would suggest. Ignoring it produces output that grows and alternates in sign.
Step 4 — Choose a step size. Set
Step 5 — Iterate the update. Keep a table of
- Euler:
. - Improved Euler:
; ; . - RK4: the four slopes in order, each built from the previous, then
.
Advance
Step 6 — Estimate the error by halving. With no exact solution to compare against, run the method at
Step 7 — Sanity-check the output. Does it respect what the equation says? A solution of
Step 8 — Report it as what it is. Values at chosen points, with an error estimate and the step size used, not a formula, and not exact.
Where it goes wrong.
- Evaluating
at instead of at the predicted . This silently reduces improved Euler to something no better than Euler. - Forgetting to advance
, so every step uses . Harmless when does not depend on , wrong otherwise. - Assuming smaller is always better. Below the stability limit refinement helps, but round-off eventually sets a floor and the total error stops falling.
- Reading order as a promise at the step in use. Ratios approach
, and as ; at coarse steps they are lower. - Continuing past a blow-up. For
with the solution ceases to exist at , but the arithmetic will happily return numbers for . They mean nothing.
Worked example
Four Euler steps, then the same problem improved
Problem. Approximate
using Euler's method with
Step 1 — Set up.
Step 2 — Iterate
First step, at
The exact value is
Second step, at
Exact
Third step, at
Exact
Fourth step, at
Result.
| Exact | Error | |||
|---|---|---|---|---|
| 0 | ||||
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 |
The error grows at every step: each new error is added to the ones already carried, and the solution's upward curvature means every tangent line falls short.
Step 3 — Refine and watch the ratio. Repeating with smaller steps:
| Euler | Error | ||
|---|---|---|---|
| 4 | |||
| 8 | |||
| 16 | |||
| 32 |
Successive error ratios are
Step 4 — Improved Euler on the first step, for contrast. Back at
Against the exact
Note where
Step 5 — Verify what can be verified. The exact solution checks out:
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,
Theorem
Order of accuracy, and where the exponents come from
Theorem (order of accuracy). Let
with
Where the exponent comes from. Expand the true solution about
Euler's step reproduces only the first two terms, since
Why the global order is one less. Reaching a fixed
which is first order. The same trade explains the others: improved Euler's averaging cancels the
This is why the weights in RK4 are what they are. The coefficients
Verified against computation. For
| Euler ratio | Improved Euler ratio | RK4 ratio | |
|---|---|---|---|
| 2 | |||
| 4 | |||
| 8 | |||
| 16 | |||
| 32 | — | ||
| 64 | — | — | |
| 128 | — | — |
Predicted limits
Two things the theorem does not say.
It does not promise the ratio at any particular
It does not say the error can be driven to zero. The bound
Corollary (choosing a step). If a method of order
For
Warning
A smaller step is not always a better answer
Refinement is the natural response to an inaccurate result, and the order table encourages it. The claim that a smaller
---
Instability: too large a step can produce nonsense, not merely inaccuracy.
Take
Applying Euler with
The computed values are
The true value is about
Why, exactly. Euler on
At
Crossing the limit:
| Euler's | Verdict | |||
|---|---|---|---|---|
| 5 | unstable | |||
| 10 | exactly on the boundary — no decay | |||
| 20 | stable | |||
| 40 | stable | |||
| 100 | stable |
Note
The practical warning is that the required
---
Round-off: too small a step stops helping, then hurts.
Truncation error falls as
with
---
What to do instead. Refine, but verify rather than assume. Compare answers at
Figure
Euler, improved Euler and RK4 at equal cost
The same budget of 32 evaluations of
The coarsest method by step count is the closest by result. Euler ends at
Read the shapes, not just the endpoints. Euler's polyline falls below the curve everywhere and the deficit compounds, because each step uses a slope measured only at its left end on a function that is increasing. The higher-order methods sample within the step, so their error per step is a higher power of
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.
Application
Numerical solution in applied settings
The exact methods in this module cover separable, linear, constant-coefficient and linear-system equations. That list sounds broad and is not. Most equations arising from a real situation fall outside it, and the reason is usually the same: something in the model is nonlinear.
Orbital motion. Newton's law of gravitation gives an inverse-square force, so the equations of motion carry
Epidemics. The standard model has susceptible and infected populations with a transmission term proportional to the product
Weather and climate. The governing equations are nonlinear partial differential equations; discretising space turns them into an enormous system of ordinary differential equations in time, stepped forward numerically. Here the stability limit is not an academic caution. It dictates the time step given the grid spacing, and getting it wrong produces a forecast that blows up rather than one that is merely inaccurate.
Circuits and control. A resistor–inductor–capacitor circuit with linear components is solvable by the characteristic equation of the second-order unit. Add a diode or a transistor, whose current–voltage relation is exponential, and the equation becomes nonlinear. Circuit simulators step it numerically, which is what a SPICE simulation is.
Chemical kinetics. Reaction rates depend on products of concentrations, so kinetics is nonlinear almost by construction. These systems are also frequently stiff: a fast reaction and a slow one in the same mixture give widely separated decay rates, and the stability limit of an explicit method is set by the fastest, forcing tiny steps even when only the slow behaviour is of interest. This is the practical reason implicit methods were developed.
---
What changes when the answer is numerical.
| Exact solution | Numerical solution | |
|---|---|---|
| Output | a function of | numbers at chosen points, for one set of inputs |
| Changing a parameter | substitute and read off | run the computation again |
| Long-run behaviour | read from the formula's structure | inferred from a finite run, or from theory |
| Error | none | present, and requiring estimation |
The second row is the real cost. A formula shows how the answer depends on its inputs, and a table of numbers does not, which is why a parameter study means many runs, and why the eigenvalue reading of the previous unit is so valuable: it extracts qualitative behaviour without solving at all.
Which is why step 1 of the procedure says to look for an exact solution first. Not from nostalgia, but because a formula answers questions a simulation cannot. When none exists, the normal case, the methods here supply numbers, and the order and stability theory says how far to trust them.
And why the earlier units still matter. Their equations serve as the test cases against which methods are checked: