Page - 66 - in Programming for Computations β Python - A Gentle Introduction to Numerical Simulations with Python
Image of the Page - 66 -
Text of the Page - 66 -
66 3 Computing Integrals
In themidpointmethod, we construct a rectangle for every sub-intervalwhere
the height equals f at the midpoint of the sub-interval. Let us do this for four
rectangles, using the same sub-intervals aswe had for hand calculationswith the
trapezoidalmethod: Ε0;0:2/, Ε0:2;0:6/, Ε0:6;0:8/, and Ε0:8;1:0 .Weget
1Z
0 f.t/dt h1f 0C0:2
2 Ch2f 0:2C0:6
2
Ch3f 0:6C0:8
2 Ch4f 0:8C1:0
2 ; (3.18)
whereh1,h2,h3, andh4 are thewidths of the sub-intervals, used previouslywith
the trapezoidalmethodanddefined in (3.10)β(3.13).
Withf.t/D3t2et3, theapproximationbecomes1.632.Comparedwith the true
answer (1.718), this is about 5% too small, but it is better thanwhatwe gotwith
the trapezoidalmethod (10%)with the same sub-intervals. More rectangles give
abetter approximation.
3.3.1 TheGeneralFormula
Let us derive a formula for themidpoint method based on n rectangles of equal
width:
bZ
a f.x/dxD x1Z
x0 f.x/dxC x2Z
x1 f.x/dxC : : :C xnZ
xn 1 f.x/dx;
hf x0Cx1
2 Chf x1Cx2
2 C : : :Chf xn 1Cxn
2 ;
(3.19)
h f x0Cx1
2 Cf x1Cx2
2 C : : :Cf xn 1Cxn
2 :
(3.20)
This summaybewrittenmorecompactlyas
bZ
a f.x/dx h n
1X
iD0 f.xi/; (3.21)
wherexi D aC h
2 C ih.
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