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

Page - 102 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Image of the Page - 102 -

Image of the Page - 102 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Text of the Page - 102 -

102 4 SolvingOrdinaryDifferentialEquations Fig.4.3 Thenumerical solution at points can be extended by linear segments between themesh points derive thedifferential equationmodel and thendiscretize it byanumericalmethod is simply that the discretization can be done in many ways, and we can create (much) more accurate andmore computationally efficient methods than (4.8) or (4.6). This can be useful in many problems! Nevertheless, the Forward Euler scheme is intuitiveandwidelyapplicable, at leastwhen t is chosen tobesmall. Thenumericalsolutionbetweenthemeshpoints Ournumericalmethodcomputestheunknownfunctionuatdiscretemeshpoints t1;t2;: : :;tNt . What ifwewant to evaluate the numerical solution between the mesh points? Themost natural choice is to assume a linear variation between themeshpoints, seeFig.4.3. This is compatiblewith the fact thatwhenweplot thearrayu0;u1;:: :versus t0;t1;: : :, astraight line isdrawnbetween thediscrete points. 4.1.3 ProgrammingtheForwardEulerScheme;theSpecialCase Letuscompute(4.8) inaprogram.The inputvariablesareN0, t,r, andNt. Note that we need to computeNt C1 new valuesN1;:::;NNtC1. A total ofNt C2 valuesareneeded inanarray representationofNn,nD0;:: :;Nt C1. Ourfirstversionof thisprogramis as simpleaspossible: N_0 = input(’Give initial population size N_0: ’) r = input(’Give net growth rate r: ’) dt = input(’Give time step size: ’) N_t = input(’Give number of steps: ’) from numpy import linspace, zeros t = linspace(0, (N_t+1)*dt, N_t+2) N = zeros(N_t+2)
back to the  book Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python
Title
Programming for Computations – Python
Subtitle
A Gentle Introduction to Numerical Simulations with Python
Authors
Svein Linge
Hans Petter Langtangen
Publisher
Springer Open
Date
2016
Language
English
License
CC BY-NC 4.0
ISBN
978-3-319-32428-9
Size
17.8 x 25.4 cm
Pages
248
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