Page - 59 - in Programming for Computations β Python - A Gentle Introduction to Numerical Simulations with Python
Image of the Page - 59 -
Text of the Page - 59 -
3.2 TheCompositeTrapezoidalRule 59
Theareasof the4trapezoidsshowninFig.3.2nowconstituteourapproximation
to the integral (3.7):
1Z
0 v.t/dt h1 v.0/Cv.0:2/
2 Ch2 v.0:2/Cv.0:6/
2
Ch3 v.0:6/Cv.0:8/
2 Ch4 v.0:8/Cv.1:0/
2 ; (3.9)
where
h1 D .0:2 0:0/; (3.10)
h2 D .0:6 0:2/; (3.11)
h3 D .0:8 0:6/; (3.12)
h4 D .1:0 0:8/ (3.13)
With v.t/ D 3t2et3, each term in (3.9) is readily computed and our approximate
computationgives
1Z
0 v.t/dt 1:895: (3.14)
Compared to the true answer of 1.718, this is off by about 10%. However, note
thatwe used just 4 trapezoids to approximate the area. Withmore trapezoids, the
approximationwould have become better, since the straight line segments in the
upper trapezoidside thenwouldfollowthegraphmoreclosely.Doinganotherhand
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 integralbyanarbitrarynumberof trapezoids.
3.2.1 TheGeneralFormula
For a given functionf.x/, wewant to approximate the integral Rb
a f.x/dx byn
trapezoids (of equalwidth). We start outwith (3.5) and approximate each integral
on the righthandsidewitha single trapezoid. Indetail,
bZ
a f.x/dxD x1Z
x0 f.x/dxC x2Z
x1 f.x/dxC : : :C xnZ
xn 1 f.x/dx;
hf.x0/Cf.x1/
2 Chf.x1/Cf.x2/
2 C : : :
Chf.xn 1/Cf.xn/
2 (3.15)
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