Numerical Integration Techniques
Numerical Integration Techniques
2024
1 Introduction to Quadrature
Definition 1
Suppose that a = x0 < x1 < · · · < xM = b. A formula of the form.
M
X
Q[f ] = wk f (xk ) = w0 f (x0 ) + w1 f (x1 ) + · · · + wM f (xM ) (1)
k=0
1.5 1.5
y=f(x) y=f(x)
1.0 1.0
0.5 0.5
x x
0.0 0.5 1.0 1.5 2.0 0.0 0.5 1.0 1.5 2.0
(a) (b)
y y
1.5 1.5
y=f(x) y=f(x)
1.0 1.0
0.5 0.5
x x
0.0 0.5 1.0 1.5 2.0 0.0 0.5 1.0 1.5 2.0
(c) (d)
Figure 1: (a) The trapezoidal rule integrates y = P1 (x) over [x0 , x1 ] = [0.0, 0.5]. (b) Simpson’s
rule integrates y = P2 (x) over [x0 , x1 ] = [0.0, 1.0]. (c) Simpson’s 38 rule integrates y = P3 (x) over
[x0 , x3 ] = [0.0, 1.5]. (d) Boole’s rule integrates y = P4 (x) over [x0 , x4 ] = [0.0, 2.0].
Professor Jorge Bacca Numerical methods 2024 6 / 43
Introduction to Quadrature
M Z
X xM M
X
= LM,k (x) dx fk = wk fk .
k=0 x0 k=0
Z x2 Z 2 Z 2
h(t − 1)h(t − 2) h(t − 0)h(t − 2)
f (x) dx ≈ f0 h dt + f1 h dt (15)
x0 0 (−h)(−2h) 0 (h)(−h)
Z 2
h(t − 0)h(t − 1)
+f2 h dt
0 (2h)(h)
Z 2 Z 2 Z 2
h 2 h 2
= f0 (t − 3t + 2) dt − f1 h (t − 2t)dt + f2 (t2 − t) dt
2 0 0 2 0
3 2
t=2 3 t=2
h t 3t t
= f0 − + 2t − f1 h − t2
2 3 2 t=0 3 t=0
t=2
h t3 t2
+f2 −
2 3 2 t=0
h 2 −4 h 2
= f0 − f1 h + f2
2 3 3 2 3
h
= (f0 + 4f1 + f2 )
3
and the proof is complete.
Professor Jorge Bacca Numerical methods 2024 13 / 43
Introduction to Quadrature
Example 1 Consider the function f (x) = 1 + e−x sin(4x), the equally
spaced quadrature nodes x0 = 0.0, x1 = 0.5, x2 = 1.0, x3 = 1.5, and
x4 = 2.0, and the corresponding function values
f0 = 1.00000, f1 = 1.55152, f2 = 0.72159, f3 = 0.93765, and f4 = 1.13390.
Apply the various quadrature formulas (4) through (7).
3
For Simpson’s 8 rule, h = 1/3, and we obtain
Z 1
3(1/3) 1 2
f (x) dx ≈ (f (0) + 3f ( ) + 3f ( ) + f (1))
0 8 3 3
1
= (1.00000 + 3(1.69642) + 3(1.23447) + 0.72159) = 1.31440
8
3
For Simpson’s 8 rule, h = 1/3, and we obtain
Z 1
3(1/3) 1 2
f (x) dx ≈ (f (0) + 3f ( ) + 3f ( ) + f (1))
0 8 3 3
1
= (1.00000 + 3(1.69642) + 3(1.23447) + 0.72159) = 1.31440
8
For Boole’s rule, h = 1/4, and the result is
Z 1
2(1/4) 1 1 3
f (x) dx ≈ (7f (0) + 32f ( ) + 12f ( ) + 32f ( ) + 7f (1))
0 45 4 2 4
1
= (7(1.00000) + 32(1.65534) + 12(1.55152)
90
+32(1.06666) + 7(0.72159)) = 1.30859.
and the approximation 1.30859 from Boole’s rule is best. The area
under each of the Lagrange polynomials P1 (x), P2 (x), P3 (x), and P4 (x)
is shown in Figure 2(a) through (d), respectively.
1.0 1.0
0.5 0.5
x x
0.0 0.2 0.4 0.6 0.8 1.0 0.0 0.2 0.4 0.6 0.8 1.0
y y
y=f(x) y=f(x)
1.5 1.5
1.0 1.0
0.5 0.5
x x
0.0 0.2 0.4 0.6 0.8 1.0 0.0 0.2 0.4 0.6 0.8 1.0
Figure 2: (a) The trapezoidal rule used over [0, 1] yields the approximation 0.86079. (b)
Simpson’s rule used over [0, 1] yields the approximation 1.32128. (c) Simpson’s 83 rule used over
[0, 1] yields the approximation 1.31440. (d) Boole’s rule used over [0, 1] yields the approximation
1.30859.
Simpson’s rule can also be used in this manner. When Simpson’s rule
is applied on the two subintervals [x0 , x2 ] and [x2 , x4 ], it is called a
composite Simpson’s rule:
Z x4 Z x2 Z x4
f (x) dx = f (x) dx + f (x) dx
x0 x0 x2
h h
≈ (f0 + 4f1 + f2 ) + (f2 + 4f3 + f4 ) (17)
3 3
h
= (f0 + 4f1 + 2f2 + 4f3 + f4 ).
3
The next example compares the values obtained with (17), (18), and
(7).
and the approximation 1.30938 from Simpson’s rule is much better than
the value 1.28358 obtained from the trapezoidal rule. Again, the
approximation 1.30859 from Boole’s rule is closest. Graphs for the
areas under the trapezoids and parabolas are shown in Figure 3(a)
and (b), respectively.
y y
1.0 1.0
0.5 0.5
t t
0.00 0.25 0.50 0.75 1.00 0.00 0.25 0.50 0.75 1.00
(a) (b)
Figure 3: (a) The composite trapezoidal rule yields the approximation 1.28358. (b) The
composite Simpson rule yields the approximation 1.30938.
Proof. Apply the trapezoidal rule over each subinterval [xk−1 , xk ]. Use
the additive property of integral for subintervals:
Z b M Z xk M
X hX
f (x)dx = f (x)dx ≈ (f (xk−1 ) + f (xk )) (3)
a xk−1 2
k=1 k=1
√
Figure 4: Approximating the area under the curve y = 2 + sin(2 x) with the composite
trapezoidal rule.
This is an approximation to the integral of f (x) over [a, b], and we write
Z b
f (x)dx ≈ S(f , h) (5)
a
Professor Jorge Bacca Numerical methods 2024 30 / 43
Composite Trapezoidal and Simpson’s Rule
Proof. Apply Simpson’s rule over each subinterval [xk−1 , xk ]. Use the
additive property of the integral for subintervals:
Z b M Z 2xk M
X hX
f (x)dx = f (x)dx ≈ (f (x2k−2 ) + 4f (x2k−1 ) + f (x2k )) (6)
a x2k−2 3
k=1 k=1
√
Figure 5: Approximating the area under the curve y = 2 + sin(2 x) with the composite Simpson
rule.
Error Analysis
The significance of the next two results is to understand that the er-
ror terms ET (f , h) and ES (f , h) for the composite trapezoidal rule and
composite Simpson rule are of the order O(h2 ) and O(h4 ), respectively.
This shows that the error for Simpson’s rule converges to zero faster
than the error for the trapezoidal rule as the step size h decreases to
zero. In cases where the derivatives of f (x) are known, the formulas
Furthermore, if f ∈ C2 [a, b], there exits a value c with a < c < b so that
the error term ET (f , h) has the form
Furthermore, if f ∈ C4 [a, b], there exists a value c with a < c < b so that
the error term ES (f , h) has the form
√
Table 1: Composite trapezoidal rule for f (x) = 2 + sin(2 x) over [1, 6]
Example 8 Find the number M and the step size h so that the error
ET (f , h) for the Rcomposite trapezoidal rule is less than 5 × 10−9 for the
7
approximation 2 dx/x ≈ T(f , h). The integral is f = 1/x and the first two
derivates are f ′ (x) = −1/x2 and f (2) (x) = 2/x3 . The maximum value of
|f (2) (x)| taken over [2, 7] occurs at the end point x = 2, and those we
have the bound |f (2) (c) ≤ |f (2) (2)| = 1/4, for 2 ≤ c ≤ 7. This is used
with formula (9) to obtain
R7
which compares favorably with the true value 2 dx/x = ln(x)|x=7 x=2 =
1.252762968. The error is smaller than predicted because the bound
1/4 for |f (2) (c)| was used. Experimentation shows that it takes about
10.001 function evaluations to achieve the desired accuracy of 5 × 10−9 ,
and when the calculation is performed with M = 10, 000, the result is
5
T f, = 1.252762973.
10, 000
Example 9 Find the number M and the step size h so that the error
ES (f , h) for theRcomposite Simpson rule is less than 5 × 10−9 for the
7
approximation 2 dx/x ≈ S(f , h). The integral is f (x) = 1/x and f (4) (x) =
24/x5 . The maximum value of |f (4) (x)| taken over [2, 7] occurs at the end
point x = 2, and those we have the bound |f (4) (c)| ≤ |f (4) (2)| = 3/4, for
2 ≤ c ≤ 7. This is used with formula (16) to obtain