# Numerical integration ```LECTURE 21: NUMERICAL INTEGRATION
MINGFENG ZHAO
March 02, 2015
Numerical integration
Definition 1. Let f be integrable on [a, b] and n be a positive integer, then the regular partition of [a, b] with n
subintervals is:
∆x =
b−a
,
n
xk = a + k∆x,
∀k = 0, 1, &middot; &middot; &middot; , n.
Then
b
Z
I. The Midpoint Rule approximation to
f (x) dx using n equally spaced subintervals on [a, b] is:
a
n
X
xk−1 + xk
f
∆x,
M (n) := [f (m1 ) + f (m2 ) + &middot; &middot; &middot; + f (mn )] ∆x =
2
k=1
where mk =
xk−1 + xk
for all k = 1, &middot; &middot; &middot; , n.
2
Z
II. The Trapezoid Rule approximation to
b
f (x) dx using n equally spaced subintervals on [a, b] is:
a
&quot;
#
n−1
X
1
1
T (n) :=
f (x0 ) +
f (xk ) + f (xn ) ∆x.
2
2
k=1
1
2
MINGFENG ZHAO
Z
III. If n is an even integer, the Simpson’s Rule approximation to
b
f (x) dx using n equally spaced subintervals
a
on [a, b] is:
S(n) := [f (x0 ) + 4f (x1 ) + 2f (x2 ) + 4f (x3 ) + &middot; &middot; &middot; + 4f (xn−1 ) + f (xn )]
∆x
.
3
Definition 2. Suppose c is a computed numerical solution to a problem having an exact solution x, then
absolute error
relative error
= |c − x|
|c − x|
|x|
=
if x 6= 0.
1
Example 1. Let c = 0.111 be the approximate value of x = , then
9
1
absolute error = 0.111 − ≈ 0.000111
9
0.111 − 1 9
relative error =
≈ 0.000999 ≈ 0.1%
1
9
LECTURE 21: NUMERICAL INTEGRATION
3
4
Z
x2 dx using the Midpoint Rule with n = 4 subintervals, and find the absolute error and
Example 2. Approximate
2
relative error.
Since a = 2, b = 4 and n = 4, then
∆x =
4−2
= 0.5,
4
x0 = 2,
x1 = 2.5,
x2 = 3,
x3 = 3.5,
and x4 = 4.
Then the midpoints are:
m1 =
x0 + x1
= 2.25,
2
m2 =
x1 + x2
= 2.75,
2
m3 =
x2 + x2
= 3.25,
2
and m4 =
x3 + x4
= 3.75.
2
So
M (4)
=
[f (m1 ) + f (m2 ) + f (m3 ) + f (m4 )] ∆x
=
[2.252 + 2.752 + 3.252 + 3.752 ] &middot; 0.5
=
18.625.
4
56
1 3 x =
, so the absolute error is:
3 2
3
2
18.625 −
56 absolute error = 18.625 − ≈ 0.0417,
and
relative error =
56
3
3
Z
Notice that
4
x2 dx =
Z
Example 3. Approximate
56 3
≈ 0.00223 = 0.223%.
4
x2 dx using the Trapezoid Rule with n = 4 subintervals, and find the absolute error and
2
relative error.
Since a = 2, b = 4 and n = 4, then
∆x =
4−2
= 0.5,
4
x0 = 2,
x1 = 2.5,
x2 = 3,
x3 = 3.5,
and x4 = 4.
So
T (4)
=
=
f (x0 )
f (x4 )
+ f (x1 ) + f (x2 ) + f (x3 ) +
∆x
2
2
1 2
1 2
2
2
2
&middot; 2 + 2.5 + 3 + 3.5 + &middot; 4 &middot; 0.5
2
2
= 18.75
4
4
1 56
Notice that
x2 dx = x3 =
, so the absolute error is:
3
3
2
2
18.75 −
56
absolute error = 18.75 − ≈ 0.083,
and
relative error =
56
3
3
Z
56 3
≈ 0.004 = 0.4%.
4
MINGFENG ZHAO
4
Z
x2 dx using the Simpson’s Rule with n = 4 subintervals, and find the absolute error and
Example 4. Approximate
2
relative error.
Since a = 2, b = 4 and n = 4, then
∆x =
4−2
= 0.5,
4
x0 = 2,
x1 = 2.5,
x2 = 3,
x3 = 3.5,
and x4 = 4.
So
S(4)
=
=
=
Z
Notice that
2
4
[f (x0 ) + 4f (x1 ) + 2f (x2 ) + 4f (x3 ) + f (x4 )]
∆x
3
2
0.5
2 + 4 &middot; 2.52 + 2 &middot; 32 + 4 &middot; 3.52 + 42 &middot;
3
56
3
4
56
1 3 x dx = x =
, so the absolute error is:
3 2
3
56
−
56 56 and
relative error = 3 56
absolute error = − = 0,
3
3
3
2
56 3
= 0%.
Theorem 1. For any positive integer n, then
T (2n) =
T (n) + M (n)
,
2
and
S(2n) =
4T (2n) − T (n)
T (n) + 2M (n)
=
3
3
Theorem 2. Let f be a forth order differentiable function on [a, b], EM , ET and ES be the absolute errors corresponding
Z b
to the Midpoint, Trapezoid and Simpson’s Rule approximation of
f (x) dx using n subintervals. Assume that |f 00 (x)| ≤
a
k and |f (4) (x)| ≤ K for all a ≤ x ≤ b, then
|EM | ≤
k(b − a)3
,
24n2
|ET | ≤
k(b − a)3
,
12n2
and
|ES | ≤
K(b − a)5
if n is even.
180n4
Remark 1. Let f be an integrable function on [a, b], then
a. If f (x) is a linear function, e.g., f (x) = 2x + 1, then both absolute and relative errors of Midpoint Rule and
Z b
Trapezoid Rule approximation of
f (x) dx are 0.
a
b. If f (x) is a cubic or quadratic or linear function, e.g., f (x) = x3 − 2x + 1, then both absolute and relative errors
Z b
of Simpson’s Rule approximation of
f (x) dx are 0.
a
Department of Mathematics, The University of British Columbia, Room 121, 1984 Mathematics Road, Vancouver, B.C.