Académique Documents
Professionnel Documents
Culture Documents
Quadrature
In this chapter well look at:
Different techniques for numerically approximating denite
integrals
Matlab for implementing these
Giving bounds on the error in the approximations.
Chapter 6
Quadrature
The failure time for a component is follows a normal
distribution with an average failure time of 3 years and a
standard deviation of 0.8 years. You want to know what
proportion of these components fails within the warranty period
of 1 year.
Youll see that this amounts to nding the value of the integral
1
5
2
e25(x1) /32 dx.
P=
4 2
5(x 1)
then this becomes
If you let t =
4
2.5
1
2
et /2 dt.
P=
2
2
But you dont know an antiderivative for et /2 ???
Quadrature
In other settings, you may not even have a formula for the
function you want to integrate.
Example
Sydney Water can tell how fast water is owing out of
Warragamba Dam at time t. If F (t) is the ow rate at time t
then the volume
t2 of water used between time t1 an t2 is
V = t1 F (t) dt.
In practice there will not be a formula for F (t), although you can
obtain lots of values of the function.
In both examples, to calculate the integral youll need to resort
to numerical methods. The technical term for numerical
integration is quadrature.
Riemann sums
Our denition of the Riemann integral tells us that we can
b
f (x) dx as closely as we like by lower (or
approximate
a
upper) Riemann sums S P = nk =1 (ak ak 1 )f k .
y
f (x)
a0
a1
b = an x
Riemann sums
If f is continuous, then the heights of these rectangles are
actually equal to f (xk ) for some xk in [ak 1 , ak ].
fk
ak 1
xk
ak
n
k =1
wk = (ak ak 1 ).
General quadrature
But:
In practice, nding the minimum points xk is hard
Youd need to calculate an upper and lower Riemann sum
k =1
Quadrature rules
Denition
Let I(f ) =
f (x)dx.
k =1
ba
Subdivide [a, b] into n subintervals of equal length h =
.
n
Let xk = a + kh, j = 0, . . . , n.
On each subinterval, join the endpoints of the graph to form a
trapezoid with area
(f (xk 1 ) + f (xk ))
.
Ak = h
2
f (xk 1 )
f (xk )
xk 1
xk
Trapezoidal rule
Denition (Trapezoidal rule)
The trapezoidal rule is given by
n
n
h
f (x0 ) + 2
Ak =
f (xk ) + f (xn ) .
Tn =
2
k =1
a = x0
k =1
x1
x2
x3 . . . xn1
xn = b
Trapezoidal rule
Example
1
dx by the trapezoidal rule.
x
1
(Exact value: n 2 = 0.693147 . . .)
1
5 6 7
21
= , P = {1, , , , 2},
n = 4 = h =
4
4
4 4 4
8 4 8 1
1
1+ + + +
= 0.69702381
= T4 =
8
5 3 7 2
= error = E4 = I T4 = 0.00387663
1
9 5 11 3 13 7 15
n = 8 = h = , P = {1, , , , , , , , 2}
8
8 4 8 2 8 4 8
= T8 = 0.69412185 = I T8 = 0.00097467
Approximate I =
Trapezoidal rule
Example
Use the Matlab function trapz to approximate the integral
1
cos x
dx.
I=
x
1 1 + e
>> f = @(x) cos(x) ./ ( 1 + exp(x) ); % note dot
>> n = 4;
>> x = linspace(-1,1,n+1); % divide [-1,1]
% by n+1 points
>> y = f(x); % a vector of the y values
>> Tn = trapz(x,y)
Tn =
0.8239
>> % Another way to use trapz
>> h = x(2)-x(1);
>> Tn2 = h * trapz(y)
Tn2 = 0.8239
Midpoint rule
Perhaps a simpler idea would be just to approximate the
integral by taking the height at the midpoint of each interval.
f (xk 1 )
f (mk )
xk 1
mk
f (xk )
xk
Midpoint rule
Denition
Let h = (b a)/n and let mk = a + (k 12 )h for 1 j n.
b
f (x) dx is given by
The midpoint rule approximation to I =
a
a = x0
x1
x2
x3 . . . xn1
xn = b
Midpoint rule
Example
Approximate I =
1
1
dx by the midpoint rule.
x
9 11 13 15
n = 4 = mid points are , , ,
8 8 8 8
1 8
8
8
8
= 0.69121989
= M4 =
+
+
+
4 9 11 13 15
= E4 = 0.00192729
n = 8 = M8 = 0.69266055 = E8 = 0.00048663
n = 16 = M16 = 0.69302521 = E16 = 0.00012197.
Similarly to the trapezoidal rule, En n12 , but they are now
positive and about half the size of those for the trapezoidal rule!
function Mn = midpoint(f,a,b,n)
% integrates the function f from a to b
% by using the midpoint rule with n midpoints,
% i.e., n subintervals.
h = (b-a)/n;
x = [a:h:b];
m = (x(2:end) + x(1:end-1)) / 2;
Mn = sum(h .* f(m));
Simpsons rule
The trapezoidal rule and the midpoint rule approximate the
function f by linear functions over each interval [xk 1 , xk ].
You might hope to do better by approximating f by a quadratic
(or higher order) polynomial on each interval.
There is exactly one quadratic p which agrees with f at the
endpoints xk 1 and xk , and the midpoint mk :
(xmk )(xxk )
p(x) = f (xk 1 ) (xk 1
mk )(xk 1 xk )
(xx
)(xx )
(xx
)(xm )
k
k 1
k
+f (mk ) (mk xkk 1
+
f
(x
)
.
k
)(m
x
)
(x
x
)(x
m
1
k
k
k
k 1
k
k)
Integrating this quadratic is easy (but messy) and gives the
formula x
k
xk xk 1
p(x) dx =
(f (xk 1 ) + 4f (mk ) + f (xk )).
6
xk 1
Important point: You dont need to nd p as you are only
interested in the RHS!
Simpsons rule
Example: x0 = 0, x1 = 2, m1 = 1
f (x0 ) = 3, f (x1 ) = 2, f (m1 ) = 2
give p(x) = 12 x 2 32 x + 3
f (xk 1 )
f (mk )
xk 1
x1
so
f (x) dx
x0
...=
mk
f (xk )
xk
1 2 3
13
x x + 3 dx =
2
2
3
2
(f (x0 ) + 4f (m1 ) + f (x1 ))
6
Simpsons rule
If you add up all the areas now you get that
b
h
f (x) dx
(f (x0 ) + 4f (m1 ) + f (x1 ))
6
a
+(f (x1 ) + 4f (m2 ) + f (x2 )) + (f (x2 ) + 4f (m
3 ) + f (x3 ))
+ + (f (xn1 ) + 4f (mn ) + f (xn ))
h
= (f (x0 ) + 4f (m1 ) + 2f (x1 ) + 4f (m2 ) + 2f (x2 )
6
+ + 2f (xn1 ) + 4f (mn ) + f (xn )).
Notation: Let yk = f (xk ),
for 0 k n.
x
+x
yk = f (mk ) = f k 12 k , for 1 k n.
Simpsons
rule with n intervals of length h is then
h
Sn = 6 y0 + yn + 4(y1 + + yn ) + 2(y1 + + yn1 ) .
h
[y0 + 2(y1 + + yn1 ) + yn ]
2
Mn = h (y1 + y2 + + yn )
h
Sn = [y0 + yn + 4(y1 + + yn ) + 2(y1 + + yn1 )] .
6
Tn =
1
2
Tn + Mn .
3
3
Errors
Theorem
Suppose that f has a continuous second order derivative which
satises |f (x)| K on [a, b]. Then
K (b a)3
K (b a) 2
|I(f ) Tn |
=
h
12
12n2
K (b a)3
K (b a) 2
|I(f ) Mn |
=
h .
24
24n2
a = x0
x1
x2
x3 . . . xn1
xn = b
and
|I Mn | = O
1
n2
as
n .
Notes
ba
.
n
Many books quote
4
|I(f ) Sn | L(ba)
180 h
because they integrate over [x0 , x2 ], [x2 , x4 ], . . . , and
ba
h=
. Note that 2880 = 24 180.
2n
Recall that h =
b
a
f (x) dx = Sn + O
1
n4
as n .
Example
Estimate n if we wish to use Simpsons rule to approximate
2
dx
to within 106 .
1 x
dx
to within 106 .
x
=
=
=
=
=
=
@(x) 1./x;
1; b = 2; n = 10;
linspace(a,b,n+1);
simpson(f,x)
log(2)
% exact value of integral
I-S
x0
g(x) dx =
x0
Proof (continued)
We
by parts twice:
xintegration
x1 now work backwards and use
1
(x x0 )(x1 x)f (x) dx =
(x x0 )(x1 x)g (x) dx
x0
x0
= (x x0 )(x1
x)g (x)
x1
x0
x1
v
(2x + x0 + x1 )g (x) dx
x0
x1
(2x x0 x1 )g (x) dx
x
0
x1 x1
= (2x x0 x1 )g(x)
2g(x) dx
x0
x0
x1
=
2g(x) dx.
=
Thus
x0
|E1 | =
x1
x0
1
g(x) dx =
2
x1
x0
(x x0 )(x1 x)f (x) dx .
Proof (continued)
x
1
1
|E1 | =
(x x0 )(x1 x)f (x) dx
2 x0
1 x1
[x 2 + (x0 + x1 )x x0 x1 ] dx
2 x0
K
K 3
=
(x1 x0 )3 =
h .
12
12
The same estimate holds for each of the n = (b a)/h
intervals, so the total error is
K (b a)3
K 3 K (b a)h2
.
|I(f ) Tn | n h =
=
12
12
12n2
Hence
et /2 dt.
2
We can turn this into nding a proper integral by using the fact
(from Probability) that
0
1
1
2
et /2 dt = .
2
2
and so
2.5
0
1
1
1
2
2
et /2 dt =
et /2 dt.
2
2
2 2.5
To get a bound on our error we need to bound derivatives of
2
f (t) = 1 et /2 on [2.5, 0].
2
f (t) =
e
t 6t + 3 .
2
How big can that get on [2.5, 0]?
2
1 et /2
2
In practice, youd probably just plot f (4) (t) and read off a
suitable upper bound from the graph |f (4) (t)| 1.2 = L.
then
.
2880n4
n4
If we want the error smaller than 109 then
0.041
< 109 n4 > 0.041 109 = 4.1 107
4
n
n > 80.02.
. . . so taking n = 100 should be more than enough!
But: The above error estimate assumes that we can calculate
Sn exactly; or at least to high accuracy.
If you have an error of size 109 in each evaluation of yk and
yk , the total error in calculating S100 might be about
200 109 = 2 107
which is much bigger than the quadrature error.
Sn
0.4937898595
0.4937903330
0.4937903345
0.4937903343
0.4937903347
0.4937903388
0.4937916453
error
5 107
2 109
2 1010
4 1010
3 1011
4 109
2 106
et /2 dt = 0.5 I(f )
2
= 0.00620966534 5 1010 .