Web-Books
in the Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition
Page - 277 -
  • User
  • Version
    • full version
    • text only version
  • Language
    • Deutsch - German
    • English

Page - 277 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition

Image of the Page - 277 -

Image of the Page - 277 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition

Text of the Page - 277 -

8.6 Exercises 277 Exercise8.13:Use aCrank-NicolsonScheme forPopulationGrowth It is recommendedtodoExercise8.12prior to thepresentone.Herewe lookat the same population growth modelN′(t) = rN(t), N(0) = N0. The time derivative N′(t) can be approximated by various types of finite differences. Exercise 8.12 considersabackwarddifference(Fig.8.22),whileSect.8.2.2explainedtheforward difference (Fig. 8.4). A centered difference is more accurate than a backward or forwarddifference: N′(tn+ 12Δt)≈ N(tn+Δt)−N(tn) Δt = N n+1 −Nn Δt . This type of difference, applied at the point tn+12 = tn + 1 2Δt, is illustrated geometrically inFig.8.23. a) Insert the finite difference approximation in the ODE N′ = rN and solve for the unknownNn+1, assumingNn is already computed and hence known. The resultingcomputationalschemeisoftenreferredtoasaCrank-Nicolsonscheme. b) Implement the algorithm in a) in a function growth_CN(N_0, dt, T) for solvingN′ = rN,N(0)=N0, t∈ (0,T],with timestepΔt (dt). c) Make plots for comparing the Crank-Nicolson scheme with the Forward and BackwardEuler schemes in thesame test problemas inExercise8.12. Filename:growth_CN.py. Exercise8.14:Understand FiniteDifferencesviaTaylorSeries TheTaylor series arounda pointx=a can fora functionf(x)bewritten f(x)=f(a)+ d dx f(a)(x−a)+ 1 2! d2 dx2 f(a)(x−a)2 + 1 3! d3 dx3 f(a)(x−a)3+ . . . = ∞∑ i=0 1 i! di dxi f(a)(x−a)i . For a functionof time, as addressed in our ODE problems,we woulduseu instead off , t insteadofx, anda timepoint tn insteadofa: u(t)=u(tn)+ d dt u(tn)(t− tn)+ 1 2! d2 dt2 u(tn)(t− tn)2 + 1 3! d3 dt3 u(tn)(t− tn)3+ . . . = ∞∑ i=0 1 i! di dti u(tn)(t− tn)i .
back to the  book Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition
Title
Programming for Computations – Python
Subtitle
A Gentle Introduction to Numerical Simulations with Python 3.6
Volume
Second Edition
Authors
Svein Linge
Hans Petter Langtangen
Publisher
Springer Open
Date
2020
Language
English
License
CC BY 4.0
ISBN
978-3-319-32428-9
Size
17.8 x 25.4 cm
Pages
356
Keywords
Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
Category
Informatik
Web-Books
Library
Privacy
Imprint
Austria-Forum
Austria-Forum
Web-Books
Programming for Computations – Python