224
8 Solving Ordinary Differential Equations
Remark on the world population
The number of people on the planet (http://en.wikipedia.org/wiki/Population_
growth) follows the model N = r(t)N, where the net reproduction r(t) varies
with time and has decreased since its top in 1990. The current world value
of r is 1.2%, and it is difficult to predict future values. At the moment, the
predictions of the world population point to a growth to 9.6 billion before
declining.
This example shows the limitation of a differential equation model: we
need to know all input parameters, including r(t), in order to predict the
future. It is seldom the case that we know all input parameters. Sometimes
knowledge of the solution from measurements can help estimate missing input
parameters.
8.2.7 Verification: Exact Linear Solution of the Discrete
Equations
How can we verify that the programming of an ODE model is correct? One way, is
to compute convergence rates with a solver and confirm that the rates are according
to expectations. We address convergence rates for ODE solvers later (in Sect. 8.5)
and will then show how a corresponding test function for the ode_FE solver may be
written.
The best verification method, however, is to find a problem where there are no
unknown numerical approximation errors, because we can then compare the exact
solution of the problem with the result produced by our implementation and expect
the difference to be within a very small tolerance. We shall base a unit test on this
idea and implement a corresponding test function (see Sect. 6.6.4) for automatic
verification of our implementation.
It appears that most numerical methods for ODEs will exactly reproduce a
solution u that is linear in t. We may therefore set u = at + b and choose any
f whose derivative is a. The choice f (u, t) = a is very simple, but we may add
anything that is zero, e.g.,
f (u, t) = a + (u − (at + b))
m .
This is a valid f (u, t) for any a, b, and m. The corresponding ODE looks highly
non-trivial, however:
u
= a + (u − (at + b))
m .
Using the general ode_FE function in ode_FE.py, we may write a proper test
function as follows (in file test_ode_FE_exact_linear.py):
def test_ode_FE():
"""Test that a linear u(t)=a*t+b is exactly reproduced."""
Précédent

- 244/350

Suivant