Page - 244 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition
Image of the Page - 244 -
Text of the Page - 244 -
244 8 SolvingOrdinaryDifferentialEquations
Fig. 8.20 Simulation of an oscillating system with different time steps. Upper left: 40 steps per
oscillation period. Upper right: 160 steps per period. Lower left: 2000 steps per period. Lower
right:2000 steps perperiod, but longer simulation
wecanreplaceun in the lastequationbytherecentlycomputedvalueun+1 fromthe
first equation:
un+1 =un+Δtvn, (8.49)
vn+1 =vn−Δtω2un+1 . (8.50)
Before justifying this fix more mathematically, let us try it on the previous
example.The results appear in Fig. 8.21.We see that the amplitudedoes not grow,
but the phase is not entirely correct. After 40 periods (Fig. 8.21 right) we see a
significantdifferencebetween the numerical and the exact solution. DecreasingΔt
decreasestheerror.Forexample,with2000intervalsperperiod,weonlyseeasmall
phaseerrorevenafter50,000periods(!).We cansafelyconcludethat thefixresults
inanexcellentnumericalmethod!
Letus interpret theadjustedschememathematically.Firstweorder(8.49)–(8.50)
such that thedifferenceapproximationsto derivativesbecometransparent:
un+1 −un
Δt =vn, (8.51)
vn+1 −vn
Δt =−ω2un+1 . (8.52)
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