Page - 301 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition
Image of the Page - 301 -
Text of the Page - 301 -
9.2 FiniteDifferenceMethods 301
This equation is to be solved for un+1. If f is linear in u, it is a linear equation,
but iff is nonlinear inu, one needs approximate methods for nonlinear equations
(Chap.7).
Inourcase, we haveasystem of linear ODEs(9.9)–(9.11).TheBackwardEuler
schemeapplied to eachequation leads to
un+10 −un0
Δt = s′(tn+1), (9.16)
un+1i −uni
Δt = β
Δx2 (un+1i+1 −2un+1i +un+1i−1)+gi(tn+1), (9.17)
i=1,.. .,N−1,
un+1N −unN
Δt = 2β
Δx2 (un+1N−1 −un+1N )+gi(tn+1). (9.18)
This is a system of linear equations in the unknownsun+1i , i= 0,.. .,N, which is
easy to realize by writing out the equations for the caseN = 3, collecting all the
unknowntermsontheleft-handsideandall theknowntermsontheright-handside:
un+10 =un0 +Δts′(tn+1), (9.19)
un+11 −Δt β
Δx2 (un+12 −2un+11 +un+10 )=un1 +Δtg1(tn+1), (9.20)
un+12 −Δt 2β
Δx2 (un+11 −un+12 )=un2 +Δtg2(tn+1). (9.21)
Asystemof linearequations like this, isusuallywrittenonmatrix formAu=b,
whereA is a coefficient matrix,u= (un+10 ,.. .,nn+1N ) is the vector of unknowns,
andb is a vectorof knownvalues. Thecoefficientmatrix for the case (9.19)–(9.21)
becomes
A= ⎛
⎜
⎝ 1 0 0
−Δt β
Δx2 1+2Δt β
Δx2 −Δt β
Δx2
0 −Δt 2β
Δx2 1+Δt 2β
Δx2 ⎞
⎟
⎠
In the general case (9.16)–(9.18), the coefficient matrix is an (N+1)× (N +1)
matrixwithzeroentries, except for
A1,1 =1 (9.22)
Ai,i−1 =−Δt β
Δx2 , i=2,.. .,N−1 (9.23)
Ai,i+1 =−Δt β
Δx2 , i=2,.. .,N−1 (9.24)
Ai,i =1+2Δt β
Δx2 , i=2,.. .,N−1 (9.25)
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