Page - 157 - in Programming for Computations β Python - A Gentle Introduction to Numerical Simulations with Python
Image of the Page - 157 -
Text of the Page - 157 -
4.4 Exercises 157
c) Make plots for comparing the Crank-Nicolson schemewith the Forward and
BackwardEuler schemes in thesame test problemas inExercise4.11.
Filename:growth_CN.py.
Exercise4.13:UnderstandfinitedifferencesviaTaylorseries
TheTaylor series aroundapointxDa can fora functionf.x/bewritten
f.x/Df.a/C d
dx f.a/.x a/C 1
2Ε d2
dx2 f.a/.x a/2
C 1
3Ε d3
dx3 f.a/.x a/3C : : :
D 1X
iD0 1
iΕ di
dxi f.a/.x a/i :
Fora functionof time, as addressed inourODEproblems,wewoulduseu instead
off , t insteadofx, anda timepoint tn insteadofa:
u.t/Du.tn/C d
dt u.tn/.t tn/C 1
2Ε d2
dt2 u.tn/.t tn/2
C 1
3Ε d3
dt3 u.tn/.t tn/3C : : :
D 1X
iD0 1
iΕ di
dti u.tn/.t tn/i :
a) Aforwardfinitedifferenceapproximation to thederivativef 0.a/ reads
u0.tn/ u.tnC t/ u.tn/
t :
Wecan justify this formulamathematically throughTaylor series.Writeup the
Taylor series foru.tn C t/ (around t D tn, as given above), and then solve
the expressionwith respect tou0.tn/. Identify, on the right-handside, thefinite
difference approximationand an infinite series. This series is then the error in
thefinite differenceapproximation. If t is assumedsmall (i.e. t <<1), t
will bemuch larger than t2, whichwill bemuch larger than t3, and so on.
The leading order term in the series for the error, i.e., the errorwith the least
powerof t is agoodapproximationof theerror. Identify this term.
b) Repeat a) forabackwarddifference:
u0.tn/ u.tn/ u.tn t/
t :
This time,writeuptheTaylorseries foru.tn t/around tn. Solvewithrespect
to u0.tn/, and identify the leading order term in the error. How is the error
compared to the forwarddifference?
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