
3.8 Numerical Solutions 189
Note 3.8.2 (Rule of thumb to set the tolerances) If m is the number of significant
digits required for solution component y
i
,setrtol
i
= 10
−m+1
.Setatol
i
to the value
at which |y
i
| is essentially insignificant.
Letusapplythistothebody temperature example. In this example, there is only
one dependent variable (T in Equation 3.231), and hence we have n = 1, which
means we can omit the index at atol
i
and rtol
i
and simply write atol and rtol instead.
The body temperature example refers to a clinical thermometer that works in a range
roughly between 30 and 42
◦
C, and which displays one digit behind the decimal
point. Therefore, it is clear that we need at least three significant digits here. In
terms of the above ‘‘rule of thumb’’, this means m = 3andrtol= 10
−2
.Regarding
atol, values below 10
−1
can be considered as ‘‘essentially insignificant’’ since only
one digit behind the decimal point is displayed by the clinical thermometer. In
terms of the ‘‘rule of thumb’’ this means we should set atol = 10
−2
. These settings
of atol and rtol can be viewed as the largest values of these tolerances that may give
us the desired result with sufficient accuracy.
However, you should remember that atol and rtol limit the local error of the
algorithm. As explained above, what really counts is the global error, that is, the final
difference between the exact solution of the ODE and the numerical approximation.
In each step of the numerical algorithm, the local errors add up to the global error.
If we are lucky, the signs of the local errors produced in each step of the numerical
algorithms may be randomly distributed and thus cancel out, giving a global error
in a similar order of magnitude as the local errors. Fortunately, this is frequently the
case, that is, we may expect the global errors to be in a similar order of magnitude
as the local errors in many cases. But it may also happen that the local errors add
up to give a much larger global error. You get a fairly reliable idea about the size of
the global error by using the heuristic procedure explained above in our discussion
of Maxima’s
rk command (Note 3.8.1). There it was recommended to compute
numerical solutions for two stepsizes h and h/2, and then to compare the results.
The same can be done here by reducing the tolerances, for example, by an order
of magnitude. If the differences between the numerical solutions obtained in this
way are negligible, you have a good reason to assume a negligible global error, and
hence that your choice of the tolerances was acceptable.
3.8.3.6 The Call of lsoda
Remember that we are still discussing the R code ODEEx1.r in the book software.
The error tolerances
rtolDef and atolDef are the last settings in the ‘‘Program
control parameters’’ section of
ODEEx1.r. If you go through the rest of the code, you
will find several other places where the user needs to do some smaller adjustments,
such as the specification of column names in the data file, setting initial values
for
lsoda using appropriate variable names, and adjusting the plots. Those places
are indicated by commentaries beginning with ‘‘
# User:...’’, such as lines 1–2
in program 3.243. As a last point in our discussion of
ODEEx1.r, let us have a look