Page - 135 - in Programming for Computations β Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition
Image of the Page - 135 -
Text of the Page - 135 -
6.2 TheCompositeTrapezoidalRule 135
Fig. 6.2 Computing approximately the integral of a function as the sum of the areas of the
trapezoids
h3 = (0.8β0.6), (6.12)
h4 = (1.0β0.8) (6.13)
With v(t) = 3t2et3, each term in (6.9) is readily computed and our approximate
computationgives
β« 1
0 v(t)dtβ1.895 . (6.14)
Compared to the true answer of 1.718, this is off by about 10%. However, note
that we used just four trapezoids to approximate the area. With more trapezoids,
the approximation would have become better, since the straight line segments
at the upper trapezoid side then would follow the graph more closely. Doing
another hand calculation with more trapezoids is not too tempting for a lazy
human, though, but it is a perfect job for a computer! Let us therefore derive
the expressions for approximating the integral by an arbitrary number of trape-
zoids.
6.2.1 TheGeneralFormula
For a given function f(x), we want to approximate the integral β«b
a f(x)dx by n
trapezoids (of equal width). We start out with (6.5) and approximate each integral
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