204
8 Solving Ordinary Differential Equations
is a candidate). 1 This is also an example of a first-order ODE, since the highest
derivative appearing in the equation is a first derivative. When the highest derivative
in an ODE is a second derivative, it is a second-order ODE, and so on (a similar
terminology is used also for PDEs).
Order of ODE versus order of numerical solution method
Note that an ODE will have an order as just explained. This order, however,
should not be confused with the order of a numerical solution method applied
to solve that ODE. The latter refers to the convergence rate of the numerical
solution method, addressed at the end of this chapter. We will present several
such solution methods in this chapter, being first-order, second-order or
fourth-order, for example (and a first-order ODE might, in principle, be solved
by any of these methods).
The present chapter 2 starts out preparing for ODEs and the Forward Euler
method, which is a first-order method. Then we explain in detail how to solve
ODEs numerically with the Forward Euler method, both single (scalar) first-order
ODEs and systems of first-order ODEs. After the “warm-up” application—filling
of a water tank—aimed at the less mathematically trained reader, we demonstrate
all the mathematical and programming details through two specific applications:
population growth and spreading of diseases. The first few programs we write, are
deliberately made very simple and similar, while we focus the computational ideas.
Then we turn to oscillating mechanical systems, which arise in a wide range of
engineering situations. The differential equation is now of second order, and the Forward Euler method does not perform too well. This observation motivates the need
for other solution methods, and we derive the Euler-Cromer scheme, the second- and
fourth-order Runge-Kutta schemes, as well as a finite difference scheme (the latter
to handle the second-order differential equation directly without reformulating it as
a first-order system). The presentation starts with undamped free oscillations and
then treats general oscillatory systems with possibly nonlinear damping, nonlinear
spring forces, and arbitrary external excitation. Besides developing programs from
scratch, we also demonstrate how to access ready-made implementations of more
advanced differential equation solvers in Python.
As we progress with more advanced methods, we develop more sophisticated
and reusable programs. In particular, we incorporate good testing strategies, which
allows us to bring solid evidence of correct computations. Consequently, the
beginning—with water tank, population growth and disease modeling examples—
has a very gentle learning curve, while that curve gets significantly steeper towards
the end of our section on oscillatory systems.
1 Note that the notation for the derivative may differ. For example, f (x) could equally well be
written as just f (where the dependence on x is to be understood), or as
df
dx .
2 The reader should be aware of another excellent easy-to-read text by the late Prof. Langtangen,
“Finite Difference Computing with Exponential Decay Models” (Springer, open access, 2016,
https://www.springer.com/gp/book/9783319294384). It fits right in with the material on ODEs and
PDEs of the present book.
Précédent

- 224/350

Suivant