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

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

Image of the Page - 243 -

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

Text of the Page - 243 -

8.4 Oscillating1DSystems:ASecondOrderODE 243 Fig. 8.19 Simulation ofan oscillating system First of all, even before trying to run the program, you should sit down and computetwosteps in the timeloopwithacalculatorsoyouhavesomeintermediate results to compare with. Using X0 = 2, dt = 0.157079632679, and ω = 2, we getu1 = 2,v1 =−1.25663706,u2 = 1.80260791,andv2 =−2.51327412.Such calculations show that the program is seemingly correct. (Later, we can use such values to constructaunit test anda correspondingtest function.) The next step is to reduce the discretization parameterΔt and see if the results become more accurate. Figure 8.20 shows the numerical and exact solution for the casesΔt=P/40,P/160,P/2000.Theresultsclearlybecomebetter,andthefinest resolutiongivesgraphsthatcannotbevisuallydistinguished.Nevertheless,thefinest resolution involves6000computational intervals in total, which is consideredquite much. This is no problem on a modern laptop, however, as the computations take just a fractionofasecond. Although 2000 intervals per oscillation period seem sufficient for an accurate numerical solution, the lower right graph in Fig. 8.20 shows that if we increase the simulation time, here to 20 periods, there is a little growth of the amplitude,which becomessignificantovertime.Theconclusionis that theForwardEulermethodhas a fundamental problem with its growing amplitudes, and that a very small Δt is requiredtoachievesatisfactory results.The longer thesimulation is, thesmallerΔt has tobe. It is certainly time to lookformoreeffectivenumericalmethods! 8.4.4 AMagicFixoftheNumericalMethod In the ForwardEuler scheme, un+1 =un+Δtvn, vn+1 =vn−Δtω2un,
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