01 · Lesson 10
Numerical methods
A numerical method replaces a continuous or otherwise difficult mathematical problem with finite calculations. It produces an approximation whose accuracy must be investigated, not assumed.
Scenario: an epidemic equation has no convenient formula
Coupled SIR or SEIR equations contain interacting state variables. Even when the model is clearly defined, an explicit formula for every compartment may be unavailable. A computer can approximate the trajectory at selected times.
Euler’s method
For \(dy/dt=f(t,y)\), choose time step \(h>0\). Euler’s update is
The derivative gives a local slope. Multiplying by \(h\) approximates change over one step. Adding that change gives the next state.
Worked one-step interpretation
For medicine elimination \(dA/dt=-0.2A\), with \(A_0=100\) mg and \(h=0.5\) hour,
This is an approximation at \(t=0.5\). The exact exponential solution gives about \(90.48\) mg, so the method has introduced numerical error.
Sources of numerical error
| Error | Meaning |
|---|---|
| Local truncation error | Error introduced during one idealised step |
| Global error | Accumulated difference across the computed interval |
| Round-off error | Finite computer representation of real numbers |
| Statistical error | Finite-sample uncertainty in stochastic simulation; not the same as discretisation error |
Step refinement and convergence
Repeat the calculation using \(h\), \(h/2\) and \(h/4\). If relevant outcomes approach stable values, this provides evidence of numerical convergence. Agreement is not proof that the biological model is correct; it checks the calculation for that model.
Euler’s method is first order: under standard conditions, halving \(h\) approximately halves global discretisation error. Higher-order methods can achieve greater accuracy per step.
Stability and biological validity
A mathematically valid ODE can produce an unstable numerical trajectory when a method or time step is unsuitable. Large steps may create oscillation, negative compartments or artificial growth.
- Check non-negativity and conserved totals.
- Compare against an exact solution when available.
- Compare more than one step size or method.
- Use solver tolerances deliberately.
- Report the method and numerical settings.
The test \(h>0\) is a logical validity condition. A tolerance such as \(|S+I+R-N|<10^{-12}\) instead handles small floating-point discrepancies. These are different uses of comparison.
Beyond ODEs
Numerical methods also approximate PDEs on spatial grids, optimise parameters, solve linear systems, simulate random processes and integrate SDEs. Each method has assumptions and diagnostics appropriate to its problem class.
What this lesson adds
You can now interpret a numerical update, distinguish numerical errors, perform step refinement, and separate numerical verification from biological model validation.