Equation Systems Numerically
(^) So far we have only applied the so-called Euler method for approximating solutions to
differential equations. It is a good scheme for simple equations, and the adequacy of a
solution can be checked by rerunning the approximation with much shorter time steps.
To do that, you also have to reduce the rate parameters in equivalent ratio. Eventually,
at some extremely small time step, this will always work, reproducing the result for a
somewhat longer step, but it may take an eon of computer time. When the time step is
too large, the derivative for one or more of the curves being simulated can at some
point force the sequence of state values far off the path of a correct solution. This will
not stop the integration; it will just go off into misleading state variable space,
sometimes producing temptingly wonderful but utterly wrong results. This happens
when the real solution is strongly curved or it abruptly shifts direction within a time
step, departing from the exactly linear jumps of the derivative sequence. An example
is shown in Fig. 4.7.
Fig. 4.7 Example of an implicit integration with overly long time steps (dark line from
square to square) departing from the trajectory of the function (the gray curve)
representing the correct solution.
There are a number of ways to check and correct the accuracy of an integration as it
proceeds: Runge–Kutta methods of different orders (the Euler method is order 1) and
other variable time-step or “vicinity checking” schemes. The Marquardt–Levenberg
approach is still widely used. If you become serious about such modeling, spend time
learning its complexities and pitfalls, all of them outside the scope of this book.
(^) There are also programming pitfalls to avoid. Units and conversion factors must be
consistent: state variables in mass or moles, phytoplankton growth rates appropriate to
the irradiance units (watts/area, photons/[area × time)) and so forth. Thresholds like
(P − P 0 ) in a grazing function must not be applied if P < P 0 . And there are others!