Page - 175 - in Programming for Computations β Python - A Gentle Introduction to Numerical Simulations with Python
Image of the Page - 175 -
Text of the Page - 175 -
5.1 FiniteDifferenceMethods 175
time, is thevisualizationon the screen, but for that purposeonecanvisualize only
a subset of the time steps. However, there are occasions when you need to take
larger time steps with the diffusion equation, especially if interest is in the long-
termbehavioras t !1. Youmust then turn to implicit methods forODEs. These
methodsrequire thesolutionsof linearsystems, if theunderlyingPDEis linear, and
systemsofnonlinearalgebraic equations if theunderlyingPDEisnon-linear.
The simplest implicitmethod is theBackwardEuler scheme,whichputs no re-
strictions on t for stability, but obviously, a large t leads to inaccurate results.
TheBackwardEuler schemefora scalarODEu0 Df.u;t/ reads
unC1 un
t Df.unC1;tnC1/:
This equation is to be solved forunC1. Iff is linear inu, it is a linear equation,
but iff is nonlinear inu, oneneedsapproximatemethods for nonlinear equations
(Chap.6).
Inourcase,wehaveasystemof linearODEs(5.9)β(5.11).TheBackwardEuler
schemeapplied toeachequation leads to
unC10 un0
t D s0.tnC1/; (5.16)
unC1i uni
t D Λ
x2 .unC1iC1 2unC1i CunC1i
1 /Cgi.tnC1/; (5.17)
i D1;:: :;N 1;
unC1N unN
t D 2Λ
x2 .unC1N
1 unC1N /Cgi.tnC1/: (5.18)
This is a systemof linear equations in the unknownsunC1i , i D 0;:: :;N , which
is easy to realize bywriting out the equations for the caseN D 3, collecting all
theunknowntermson the left-handsideandall theknowntermson the right-hand
side:
unC10 Dun0 C ts0.tnC1/; (5.19)
unC11 t Λ
x2 .unC12 2unC11 CunC10 /Dun1 C tg1.tnC1/; (5.20)
unC12 t 2Λ
x2 .unC11 unC12 /Dun2 C tg2.tnC1/: (5.21)
Asystemof linearequations like this, isusuallywrittenonmatrixformAuDb,
whereA is a coefficientmatrix,u D .unC10 ;: : :;nnC1N / is the vector of unknowns,
andb is avectorofknownvalues. Thecoefficientmatrix for thecase (5.19)β(5.21)
becomes
AD 0
B
@ 1 0 0
t Λ
x2 1C2 t Λ
x2 t Λ
x2
0 t 2Λ
x2 1C t 2Λ
x2 1
C
A
back to the
book Programming for Computations β Python - A Gentle Introduction to Numerical Simulations with Python"
Programming for Computations β Python
A Gentle Introduction to Numerical Simulations with Python
- Title
- Programming for Computations β Python
- Subtitle
- A Gentle Introduction to Numerical Simulations with Python
- Authors
- Svein Linge
- Hans Petter Langtangen
- Publisher
- Springer Open
- Date
- 2016
- Language
- English
- License
- CC BY-NC 4.0
- ISBN
- 978-3-319-32428-9
- Size
- 17.8 x 25.4 cm
- Pages
- 248
- Keywords
- Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
- Category
- Informatik