Page - 136 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition
Image of the Page - 136 -
Text of the Page - 136 -
136 6 ComputingIntegralsandTestingCode
on the righthandside witha single trapezoid. Indetail,
∫ b
a f(x)dx= ∫ x1
x0 f(x)dx+ ∫ x2
x1 f(x)dx+ . . .+ ∫ xn
xn−1 f(x)dx,
≈hf(x0)+f(x1)
2 +hf(x1)+f(x2)
2 + . . .+
h f(xn−1)+f(xn)
2 (6.15)
Bysimplifying the righthandsideof (6.15)weget
∫ b
a f(x)dx≈ h
2 [f(x0)+2f(x1)+2f(x2)+ . . .+2f(xn−1)+f(xn)]
(6.16)
which ismorecompactlywrittenas
∫ b
a f(x)dx≈h [
1
2 f(x0)+ n−1∑
i=1 f(xi)+ 1
2 f(xn) ]
. (6.17)
CompositeIntegrationRules
The word composite is often used when a numerical integration method is
appliedwith more than one sub-interval.Strictly speaking then, writing, e.g.,
“the trapezoidal method”, should imply the use of only a single trapezoid,
while “the composite trapezoidal method” is the most correct name when
several trapezoids are used. However, this naming convention is not always
followed, so saying just “the trapezoidal method” may point to a single
trapezoidaswell as thecomposite rulewithmanytrapezoids.
6.2.2 AGeneral Implementation
Specific or General Implementation? Suppose we want to compute the specific
integral ∫1
0 v(t)dt, wherev(t)= 3t2et 3
, using the (composite) trapezoidal method
in (6.17). Although simple in principle, the practical steps are often confusing to
many, because the notation in the abstract formulation in (6.17) differs from the
notation in our special problem. Clearly, thef ,x, andh in (6.17) correspond tov,
t, andperhapsΔt for the trapezoidwidth inourspecial problem.
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