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 - 205 -
  • User
  • Version
    • full version
    • text only version
  • Language
    • Deutsch - German
    • English

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

Image of the Page - 205 -

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

Text of the Page - 205 -

8.1 FillingaWaterTank:TwoCases 205 8.1 FillingaWaterTank:TwoCases If “ordinarydifferential equation” is notamongyour favoriteexpressions, then this section is foryou. Consider a 25 L tank that will be filled with water in two different ways. In the firstcase, thewatervolumethatenters the tankper time (rateofvolumeincrease) is piecewiseconstant,while in the secondcase, it is continuously increasing. Foreachof these twocases,weareaskedtodevelopacodethatcanpredict (i.e., compute)how the total water volumeV in the tank will developwith time t overa period of 3s. Our calculations must be based on the information given: the initial volume of water (1L in both cases), and the volume of water entering the tank per time. 8.1.1 Case1:PiecewiseConstantRate In this simplercase, there is initially1Lofwater in the tank, i.e., V(0)=1L, while the ratesofvolume increasearegivenas: r=1Ls−1, 0s<t<1s, r=3Ls−1, 1s≤ t <2s, r=7Ls−1, 2s≤ t≤3s. Before turning to the programming,we shouldworkout theexact solutionbyhand for thisproblem,since that is rather straight forward.Suchasolutionwill of course be useful for verifying our implementation. In fact, comparing program output to thesehandcalculationsshouldsuffice for thisparticularproblem. Exact Solution by Hand Our reasoning goes like this: For each of the given sub- intervals (on the time axis), the total volumeV of water in the tank will increase linearly. Thus, if we computeV after 1, 2 and 3s, we will have what we need. We get V(0)=1L, V(1)=1L+(1s)(1Ls−1)=2L, V(2)=2L+(1s)(3Ls−1)=5L, V(3)=5L+(1s)(7Ls−1)=12L. We also have what is required for plotting the exact solution, since we can just tell Pythontoplot thecomputedV valuesagainst t for t=0,1,2,3,and letPythonfill
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