Introduction to differential equations
Numerical solutions
Euler and RK4: step size, error and the connection to Taylor expansion.
about 7 min
Start from a problem
The pendulum equation has no elementary closed-form solution. Yet we still want to know what looks like and to draw its curve.
We need a method that computes an approximate solution using only the four arithmetic operations, and we must be able to estimate its error and know when it breaks down.
Choose "Pendulum": . This equation has no elementary closed-form solution. Yet the experiment draws a curve: it is computed step by step. Increase the step : the red Euler curve drifts away from the blue RK4 curve and may even diverge. Switch back to "Exponential growth", which has an exact solution, and watch the end-point errors of the two methods as changes: halving roughly halves Euler's error and divides RK4's by about 16.
tells us the current slope. From , walk a short step along that slope to get the next approximate point. Smaller steps are more accurate, but how the error shrinks with depends on how refined our "one step" is, and that should be computable with a Taylor expansion.
Definitions
The local truncation error is the difference between one step taken from the exact value and . The global error is after steps. A method with global error has order .
Derivation: the order of Euler's method
Local truncation error , global error .
Taylor-expand the exact solution: . An Euler step is exactly the first two terms, so the local error is .
Global error: let , let be -Lipschitz in , and let the local error be at most . Then Iterating, , using . So the global error is : steps each committing accumulate to .
Higher order: Runge–Kutta
Euler uses only the slope at the left end of each step. Better: sample several slopes inside the step and average them with weights.
Local truncation error , global error .
The full proof expands to order and compares term by term with the expansion of ; it is long. We prove a special case that carries the idea: independent of . Then , , , and which is Simpson's rule, while . Simpson's rule is exact for cubics with error , i.e. . The general case has the same conclusion with a messier expansion. The global follows from the local error by the same accumulation argument as for Euler.
This is where "halve , divide the error by 16" comes from: .
Theorem: why large steps diverge
For with , Euler gives . The true solution decays to ; the numerical one decays iff , i.e. .
Substitute: .
Beyond the factor oscillates and grows, bearing no relation to the true solution. This explains the divergence of the Euler curve at large steps. Such "stiff" problems call for implicit methods, a topic of Numerical analysis.
Halving the step only halves Euler's error; making tiny does not compensate for a low-order method, it just adds work and rounding error. And with too large Euler diverges. Accuracy (order) and stability (a ceiling on ) are separate concerns; both matter.
Application
The pendulum, the three-body problem, the Lorenz system, almost every realistic physical model: numerical solution is the only option. The pendulum curve in the experiment is RK4 with step and four function evaluations per step. The number of steps is ; trading accuracy against work is the daily business of scientific computing.
Numerical methods are not "approximate mathematics". They have theorems of their own: order, convergence and stability are precise, provable statements. Every letter in Euler's global bound has a meaning, and it honestly tells you the error grows exponentially with : the further the forecast, the less reliable.