Seite - 204 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition
Bild der Seite - 204 -
Text der Seite - 204 -
204 8 SolvingOrdinaryDifferentialEquations
is a candidate).1 This is also an example of a first-order ODE, since the highest
derivativeappearingin theequationisafirstderivative.Whenthehighestderivative
in an ODE is a second derivative, it is a second-order ODE, and so on (a similar
terminologyisusedalso forPDEs).
OrderofODEversusorderofnumerical solutionmethod
Note that an ODE will have an order as just explained. This order, however,
shouldnotbeconfusedwith theorderofanumericalsolutionmethodapplied
to solve that ODE. The latter refers to the convergencerate of the numerical
solutionmethod,addressedat the endof this chapter.We will present several
such solution methods in this chapter, being first-order, second-order or
fourth-order,forexample(andafirst-orderODEmight, inprinciple,besolved
byanyof thesemethods).
The present chapter2 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
deliberatelymadeverysimpleandsimilar,whilewe focus thecomputational ideas.
Then we turn to oscillating mechanical systems, which arise in a wide range of
engineeringsituations.Thedifferentialequationisnowofsecondorder,andtheFor-
ward Euler methoddoesnot performtoo well. This observationmotivates the need
forothersolutionmethods,andwederivetheEuler-Cromerscheme,thesecond-and
fourth-orderRunge-Kutta schemes, as well as a finite difference scheme (the latter
tohandle thesecond-orderdifferentialequationdirectlywithout 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 developingprograms from
scratch, we also demonstrate how to access ready-made implementations of more
advanceddifferentialequationsolvers inPython.
As we progress with more advanced methods, we develop more sophisticated
and reusable programs. In particular, we incorporategood testing strategies, which
allows us to bring solid evidence of correct computations. Consequently, the
beginning—with water tank, population growth and disease modeling examples—
hasa verygentle learningcurve,while that curvegets significantly steeper towards
theendofour sectiononoscillatorysystems.
1 Note that the notation for the derivative may differ. For example, f ′(x) could equally well be
writtenas justf ′ (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). Itfits right inwiththematerialonODEsand
PDEsof the present book.
Programming for Computations – Python
A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition
- Titel
- Programming for Computations – Python
- Untertitel
- A Gentle Introduction to Numerical Simulations with Python 3.6
- Band
- Second Edition
- Autoren
- Svein Linge
- Hans Petter Langtangen
- Verlag
- Springer Open
- Datum
- 2020
- Sprache
- englisch
- Lizenz
- CC BY 4.0
- ISBN
- 978-3-319-32428-9
- Abmessungen
- 17.8 x 25.4 cm
- Seiten
- 356
- Schlagwörter
- Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
- Kategorie
- Informatik