Page - 172 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition
Image of the Page - 172 -
Text of the Page - 172 -
172 6 ComputingIntegralsandTestingCode
exercise). Therefore, we are forced to compute the integral by numerical methods.
Computea result that is right to fourdigits.
Hint Use ideas fromExercise6.9.
Filename:integrate_x2x.py.
Exercise6.11:IntegrateProductsofSine Functions
In this exercisewe shall integrate
Ij,k = ∫ π
−π sin(jx)sin(kx)dx,
wherej andk are integers.
a) Plotsin(x)sin(2x)andsin(2x)sin(3x)forx∈[−π,π] inseparateplots.Explain
whyyouexpect ∫π
−π sinxsin2xdx=0and ∫π
−π sin2xsin3xdx=0.
b) Use the trapezoidal rule tocomputeIj,k forj =1,.. .,10andk=1,.. .,10.
Filename:products_sines.py.
Exercise6.12:RevisitFitofSines toa Function
This is a continuationof Exercise4.13.The task is to approximatea given function
f(t)on [−π,π]byasum ofsines,
SN(t)= N∑
n=1 bnsin(nt). (6.31)
We are nowinterested incomputing theunknowncoefficientsbn such thatSN(t) is
in somesense the best approximation tof(t). One commonway of doing this is to
firstsetupageneralexpressionfortheapproximationerror,measuredby“summing
up” thesquareddeviationofSN fromf :
E= ∫ π
−π (SN(t)−f(t))2dt .
We may view E as a function of b1,.. .,bN. Minimizing E with respect to
b1,.. .,bN willgiveusabestapproximation, in thesense thatweadjustb1,.. .,bN
such thatSN deviatesas little aspossible fromf .
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