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

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

Image of the Page - 207 -

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

Text of the Page - 207 -

8.1 FillingaWaterTank:TwoCases 207 8.1.2 Case2:ContinuouslyIncreasingRate This case is more tricky. As in the previous case, there is 1 L of water in the tank from the start. When the tank fills up, however, the rate of volume increase, r, is alwaysequal to the currentvolume of water, i.e., r =V (in units of Ls−1). So, for example, at the time when there is 2L in the tank, water enters the tank at 2Ls−1, whenthereis2.1Linthetank,watercomesinat2.1Ls−1,andsoon.Thus,contrary to what we had in Case 1, r is not constant for any period of time within the 3s interval, it increasescontinuouslyandgivesusasteeperandsteepercurveforV(t). Writing thisupas forCase 1, the informationwehave is V(0)=1L, and, for the rate (inLs−1), r(t)=V(t), 0s<t≤3s . Let us, for simplicity, assume that we also are given the exact solution in this case, which is V(t) = et. This allows us to easily check out the performance of any computational idea that wemight try. So, howcan we compute thedevelopmentofV ,making it compare favorably to thegivensolution? An Idea Clearly, we will be happy with an approximately correct solution, as long as the error can be made “small enough”. In Case 1, we effectively computed connected straight line segments that matched the true development ofV because of piecewise constant r values. Would it be possible to do something similar here in Case 2, i.e., compute straight line segments and use them as an approximation to the true solution curve? If so, it seems we could benefit from a very simple computational scheme! Let us pursue this idea further to see what comes out of it. The First Time Step Considering the very first time step, we should realize that, since we are given the initial volumeV(0)= 1L, we do know the correct volume and correct rate at t = 0, since r(t) = V(t). Thus, using this information and pretending that r stays constant as time increases, we will be able to compute a straight line segment for the very first time step (some Δt must be chosen). This straightlinesegmentwill thenbecometangenttothetruesolutioncurvewhen t=0. The computedvolume at the end of the first time step will have an error,but if our timestepisnot toolarge, thestraight linesegmentwill stayclose tothetruesolution curveand theerror inV shouldbe“small”. The Second Time Step What about the second time step? Well, the volume we computed (with an error) at the end of the first time step, must now serve as the starting volume and (“constant”) rate for the second time step. This allows us to computean approximation to the volumealso at the end of the second time step. If
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