Seite - 96 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python
Bild der Seite - 96 -
Text der Seite - 96 -
96 4 SolvingOrdinaryDifferentialEquations
tionmotivates theneedforothersolutionmethods,andwederive theEuler-Cromer
scheme1, the2nd-and4th-orderRunge-Kuttaschemes,aswellasafinitedifference
scheme (the latter tohandle the second-orderdifferential equationdirectlywithout
reformulating it as a first-order system). The presentation starts with undamped
freeoscillationsand then treatsgeneraloscillatorysystemswithpossiblynonlinear
damping, nonlinear spring forces, and arbitrary external excitation. Besides de-
veloping programs from scratch, we also demonstrate how to access ready-made
implementationsofmoreadvanceddifferential equationsolvers inPython.
Aswe progress withmore advancedmethods, we developmore sophisticated
and reusable programs, and inparticular,we incorporategood testing strategies so
thatwebring solid evidence to correct computations. Consequently, thebeginning
with populationgrowth anddiseasemodeling examples has a verygentle learning
curve,while that curve gets significantly steeper towards the end of the treatment
ofdifferential equations foroscillatory systems.
4.1 PopulationGrowth
Ourfirst taste of differential equations regardsmodeling the growth of somepop-
ulation, such as a cell culture, an animal population, or a humanpopulation. The
ideas evenextend trivially to growthofmoney in a bank. LetN.t/be the number
of individuals in thepopulationat time t. Howcanwepredict theevolutionofN.t/
in time? Belowweshall deriveadifferential equationwhose solution isN.t/. The
equation reads
N 0.t/D rN.t/; (4.1)
wherer is anumber.Note thatalthoughN is an integer in real life,wemodelN as
a real-valued function.Weare forced todo thisbecause the solutionofdifferential
equationsare (normallycontinuous) real-valued functions.An integer-valuedN.t/
in themodelwould lead toa lotofmathematicaldifficulties.
With a bit of guessing, youmay realize thatN.t/ D Cert, whereC is any
number. Tomake this solution unique,we need to fixC, done byprescribing the
value ofN at some time, usually t D 0. SayN.0/ is given asN0. ThenN.t/ D
N0e rt.
Ingeneral, adifferentialequationmodelconsists ofadifferential equation, such
as (4.1) and an initial condition, such asN.0/ D N0. With a known initial con-
dition, the differential equation can be solved for the unknown function and the
solution isunique.
It is, of course, very seldomthatwecanfind the solutionof adifferential equa-
tion as easy as in this example. Normally, one has to apply certainmathematical
methods, but these can only handle some of the simplest differential equations.
However,wecaneasily dealwith almost anydifferential equationbyapplyingnu-
mericalmethodsandabit of programming. This is exactly the topicof thepresent
chapter.
1The term scheme is usedas synonymformethodor computational recipe, especially in the con-
textofnumericalmethods fordifferential equations.
Programming for Computations – Python
A Gentle Introduction to Numerical Simulations with Python
- Titel
- Programming for Computations – Python
- Untertitel
- A Gentle Introduction to Numerical Simulations with Python
- Autoren
- Svein Linge
- Hans Petter Langtangen
- Verlag
- Springer Open
- Datum
- 2016
- Sprache
- englisch
- Lizenz
- CC BY-NC 4.0
- ISBN
- 978-3-319-32428-9
- Abmessungen
- 17.8 x 25.4 cm
- Seiten
- 248
- Schlagwörter
- Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
- Kategorie
- Informatik