You are on page 1of 16

CHAPTER 6 (4 LECTURES)

NUMERICAL INTEGRATION

1. Introduction
The general problem is to find the approximate value of the integral of a given function f (x) over
an interval [a, b]. Thus
Z b
I= f (x)dx. (1.1)
a
Problem can be solved by using the Fundamental Theorem of Calculus by finding an anti-derivative
F of f , that is, F 0 (x) = f (x), and then
Z b
f (x)dx = F (b) − F (a).
a
But finding an anti-derivative is not an easy task in general. Hence, it is certainly not a good approach
for numerical computations.
In this chapter we’ll study methods for finding integration rules. We’ll also consider composite versions
of these rules and the errors associated with them.

2. Elements of numerical integration


The basic method involved in approximating the integration is called numerical quadrature and uses
a sum of the type
Z b
f (x)dx ≈ λi f (xi ). (2.1)
a
The method of quadrature is based on the polynomial interpolation. We divide the interval [a, b] in to
a set of distinct nodes {x0 , x1 , x2 , · · · , xn }. Then we approximate the function f (x) by an interpolating
polynomial, say Lagrange interpolating polynomial is used to approximate f (x), i.e.
f (x) = Pn (x) + en
n n
X f (n+1) (ξ) Y
= f (xi )li (x) + (x − xi ).
(n + 1)!
i=0 i=0

Here ξ = ξ(x) ∈ (a, b) and


n
Y x − xj
li (x) = , 0 ≤ i ≤ n.
xi − xj
j=0
j6=i
Therefore
Z b Z b Z b
f (x)dx = Pn (x)dx + en (x)dx
a a a
n Z b Z b n
X 1 (n+1)
Y
= f (xi ) li (x)dx + f (ξ) (x − xi )dx
a (n + 1)! a
i=0 i=0
Xn
= λi f (xi ) + E(f )
i=0

where
Z b
λi = li (x)dx.
a
1
2 NUMERICAL INTEGRATION

Error in the numerical quadrature is given by


Z b n
1 (n+1)
Y
E(f ) = f (ξ) (x − xi )dx.
(n + 1)! a i=0

We can also use Newton divided difference interpolation to approximate the function f (x).

3. Newton-Cotes Formula
b−a
Let all nodes are equally spaced with spacing h = . The number h is also called the step
n
length.
Let x0 = a and xn = b then xi = a + ih, i = 0, 1, · · · , n.
The general quadrature formula is given by
Z b n
X
f (x)dx = λi f (xi ) + E(f ).
a i=0

This formula is called Newton-Cotes formula if all points are equally spaced. We now derive rules by
taking one and two degree interpolating polynomials.

Rb
3.1. Trapezoidal Rule. We derive the Trapezoidal rule for approximating f (x)dx using the linear
a
Lagrange polynomial.
Let x0 = a, x1 = b, and h = b − a.
b=x
Z 1 Zx1
f (x) dx = P1 (x)dx + E(f ).
a=x0 x0

We calculate the both the integrals separately as:

Zx1 Zx1
P1 (x)dx = [l0 (x)f (x0 ) + l1 (x)f (x1 )] dx
x0 x0
Zx1 Zx1
x − x1 x − x0
= f (x0 ) dx + f (x1 ) dx
x0 − x1 x1 − x0
x0 x0
2
x1 x
(x − x0 )2 1
 
(x − x1 )
= f (x0 ) + f (x1 )
2(x0 − x1 ) x0 2(x1 − x0 ) x0
x1 − x0
= [f (x0 ) + f (x1 )]
2
h
= [f (a) + f (b)].
2

Zx1
f (2) (ξ)
E(f ) = (x − x0 )(x − x1 ) dx
2!
x0
Zx1
1
= f (2) (ξ)(x − x0 )(x − x1 ) dx.
2
x0
NUMERICAL INTEGRATION 3

Since (x − x0 )(x − x1 ) does not change its sign in [x0 , x1 ], therefore by the Weighted Mean-Value
Theorem, there exists a point c ∈ (x0 , x1 ) such that
Zx1
f (2) (c)
E(f ) = (x − x0 )(x − x1 ) dx
2
x0

f (2) (c) (x0 − x1 )3


 
=
2 6
h3
= − f (2) (c).
12
Thus the integration formula is
Zb
h h3
f (x)dx = [f (a) + f (b)] − f (2) (c).
2 12
a

Geometrically, it is the area of Trapezium (Trapezoid) with width h and ordinates f (a) and f (b).

3.2. Simpson’s Rule. We take second degree Lagrange interpolating polynomial. We take n =
a+b
2, x0 = a, x1 = , x2 = b, h = (b − a)/2.
2
b=x
Z 2 Zx2
f (x) dx = P2 (x)dx + E(f ).
a=x0 x0

Zx2 Zx2
P2 (x)dx = [l0 (x)f (x0 ) + l1 (x)f (x1 ) + +l2 (x)f (x2 )] dx
x0 x0
= λ0 f (x0 ) + λ1 f (x1 ) + λ2 f (x2 ).
The values of the multipliers λ0 , λ1 , and λ2 are given by
Zx2
(x − x1 )(x − x2 )
λ0 = dx.
(x0 − x1 )(x0 − x2 )
x0

To simply this integral, we substitute x = x0 + ht, dx = h dt and change the limits from 0 to 2
accordingly.
Z 2
(t − 1)(t − 2)
∴ λ0 = h dt = h/3.
0 (0 − 1)(0 − 2)
Similarly
Zx2
(x − x0 )(x − x2 )
λ1 = dx
(x1 − x0 )(x1 − x2 )
x0
2
(t − 0)(t − 2)
Z
= h dt = 4h/3.
0 (1 − 0)(1 − 2)
and
Zx2
(x − x0 )(x − x1 )
λ2 = dx
(x2 − x0 )(x2 − x1 )
x0
Z2
(t − 0)(t − 1)
= h dt = h/3.
(2 − 0)(2 − 1)
0
4 NUMERICAL INTEGRATION

Now error is given by


Z x2
1
E(f ) = f 000 (ξ)(x − x0 )(x − x1 )(x − x2 )dx.
3! x0

Since (x − x0 )(x − x1 )(x − x2 ) changes its sign in the interval [x0 , x1 ], therefore we cannot apply the
Weighted Mean-Value Theorem (as we did in trapezoidal rule).
Also Z x2
(x − x0 )(x − x1 )(x − x2 ) dx = 0.
x0
We can add an interpolation point without affecting the area of the interpolated polynomial, leaving
the error unchanged. We can therefore do our error analysis of Simpson’s rule with any single point
added, since adding any point in [a, b] does not affect the area, we simply double the midpoint, so that
our node set is {x0 = a, x1 = (a + b)/2, x1 = (a + b)/2, x2 = b}. We can now examine the value of the
next interpolating polynomial. Therefore
1 x2 (4)
Z
E(f ) = f (ξ)(x − x0 )(x − x1 )2 (x − x2 )dx.
4! x0
Now the product (x−x0 )(x−x1 )2 (x−x2 ) does not change its sign in [x0 , x1 ], therefore by the Weighted
Mean-Value Theorem, there exists a point c ∈ (x0 , x1 ) such that
Z x2
1 (4)
E(f ) = f (c) (x − x0 )(x − x1 )2 (x − x2 )dx
24 x0
f (4) (c)
= − (x2 − x0 )5
2880
h5
= − f (4) (c).
90
Hence
b
h5
Z    
h a+b
f (x)dx = f (a) + 4f + f (b) − f (4) (c).
a 3 2 90
1
This rule is called Simpson’s rule.
3
Similarly by taking third order Lagrange interpolating polynomial with three nodes a = x0 , x1 , x2 , x3 =
b−a 3
b with h = , we get the next integration formula known as Simpson’s rule.
3 8
Z b
3h 3
f (x)dx = [f (x0 ) + 3f (x1 ) + 3f (x2 ) + f (x3 )] − h5 f (4) (c).
a 8 80
Definition 3.1. The degree of accuracy, or precision, or order of a quadrature formula is the largest
positive integer n such that the formula is exact for xk , for each k = 0, 1, · · · , n.
In other words, an integration method of the form
Z b n Z b n
X 1 (n+1)
Y
f (x)dx = λi f (xi ) + f (ξ) (x − xi )dx
a (n + 1)! a
i=0 i=0

is said to be of order n if it provides exact results for all polynomials of degree less than or equal to n
and the error term will be zero for all polynomials of degree ≤ n.
Trapezoidal rule has degree of precision one and Simpson’s rule has three.
Example 1. Find the value of the integral
Z 1
dx
I=
0 1+x
using trapezoidal and Simpson’s rule. Also obtain a bound on the errors. Compare with exact value.
NUMERICAL INTEGRATION 5

Sol.
1
f (x) =
1+x
By trapezoidal rule
IT = h/2[f (a) + f (b)]
Here a = 0, b = 1, h = b − a = 1.

I = 1/2[1 + 1/2] = 0.75


Exact value
Iexact = ln 2 = 0.693147
Error= |0.75 − 0.693147| = 0.056853
The error bound for the trapezoidal rule is given by
E(f ) ≤ h3 /12 max |f 00 (ξ)|
0≤ξ≤1

2
= 1/12 max
3

0≤ξ≤1 (1 + ξ)
= 1/6
Similarly by using Simpson’s rule with h = (b − a)/2 = 1/2, we obtain
IS = h/3[f (0) + 4f (1/2) + f (1)] = 1/6(1 + 8/3 + 1/2) = 0.69444
Error= |0.75 − 0.69444| = 0.001297.
The error bound for the Simpson’s rule is given by
h5
E(f ) ≤ max |f (4) (ξ)|
90 0≤ξ≤1

1 24
= max
2880 0≤ξ≤1 (1 + ξ)5
= 0.008333.
Example 2. Find the quadrature formula by method of undetermined coefficients
Z 1
f (x)
p dx = α1 f (0) + α2 f (1/2) + α3 f (1)
0 x(1 − x)
which is exact for polynomials of highest possible degree. Then use the formula to evaluate
Z 1
dx
√ .
0 x − x3
Sol. We make the method exact for polynomials up to degree 2.
Z 1
dx
f (x) = 1 : I1 = p = α1 + α2 + α3
0 x(1 − x)
Z 1
xdx
f (x) = x : I2 = p = 1/2α2 + α3
0 x(1 − x)
Z 1
2 x2 dx
f (x) = x : I3 = p = 1/4α2 + α3
0 x(1 − x)
Now Z 1 Z 1 Z 1
dx dx dt
I1 = p = p = √ = [sin−1 t]1−1 = π
x(1 − x) 1 − (2x − 1) 2 1−t 2
0 0 −1
Similarly
I2 = π/2
I3 = 3π/8.
Therefore
α1 + α2 + α3 = π
6 NUMERICAL INTEGRATION

1/2α2 + α3 = π/2
1/4α2 + α3 = 3π/8.
By solving these equations, we obtain α1 = π/4, α2 = π/2, α3 = π/4. Hence
Z 1
f (x)
p dx = π/4[f (0) + 2f (1/2) + f (1)].
0 x(1 − x)
Z 1 Z 1 Z 1
dx dx f (x)dx
I= √ = √ p = p .
x−x 3 1 + x x(1 − x) x(1 − x)
0 0 0

Here f (x) = 1/ 1 + x.
By using the above formula, we obtain
" √ √ #
2 2 2
I = π/4 1 + √ + = 2.62331.
3 2
The exact value of the given integral is
I = 2.6220575.

4. Composite Integration
As the order of integration method is increased, the order of the derivative involved in error term also
increase. Therefore, we can use higher-order method if the integrand is differentiable up to required
degree. We can apply lower-order methods by dividing the whole interval in to subintervals and then
we use any Newton-Cotes or Gauss quadrature method for each subintervals separately.
Composite Trapezoidal Method: We divide the interval [a, b] into N subintervals with step size
b−a
h= and taking nodal points a = x0 < x1 < · · · < xN = b where xi = x0 +i h, i = 1, 2, · · · , N −1.
N
Now
Z b
I = f (x)dx
Za x1 Z x2 Z xN
= f (x)dx + f (x)dx + · · · + f (x)dx.
x0 x1 xN −1

Now use trapezoidal rule for each of the integrals on the right side, we obtain
h
I = [(f (x0 ) + f (x1 )) + (f (x1 ) + f (x2 )) + · · · + (f (xN −1 ) + f (xN )]
2
h3
− [f (2) (ξ1 ) + f (2) (ξ2 ) + · · · + f (2) (ξN )]
12
N −1 N
" #
h X h3 X (2)
= f (x0 ) + f (xN ) + 2 f (xi ) − f (ξi )
2 12
i=1 i=1
This formula is composite trapezoidal rule where where xi−1 ≤ ξi ≤ xi , i = 1, 2, · · · , N.
The error associated with this approximation is
N
h3 X (2)
E(f ) = − f (ξi ).
12
i=1

If f ∈ C 2 [a, b], the Extreme Value Theorem implies that f (2) assumes its maximum and minimum in
[a, b]. Since
min f (2) (x) ≤ f (2) (ξi ) ≤ max f (2) (x).
x∈[a,b] x∈[a,b]
On summing, we have
N
X
N min f (2) (x) ≤ f (2) (ξi ) ≤ N max f (2) (x)
x∈[a,b] x∈[a,b]
i=1
NUMERICAL INTEGRATION 7

and
N
(2) 1 X (2)
min f (x) ≤ f (ξi ) ≤ max f (2) (x).
x∈[a,b] N x∈[a,b]
i=1
By the Intermediate Value Theorem, there is a c ∈ (a, b) such that
N
(2) 1 X (2)
f (c) = f (ξi ).
N
i=1
Therefore
h3
E(f ) = − N f (2) (c),
12
or, since h = (b − a)/N ,
(b − a) 2 (2)
E(f ) = −
h f (c).
12
Composite Simpson’s Method: Simpson’s rule require three abscissas, choose an even integer N
b−a
to produce odd number of nodes with h = . Likewise before, we write
N
Z b
I = f (x)dx
Za x2 Z x4 Z xN
= f (x)dx + f (x)dx + · · · + f (x)dx.
x0 x2 xN −2

Now use Simpson’s rule for each of the integrals on the right side to obtain
h
I = [(f (x0 ) + 4f (x1 ) + f (x2 )) + (f (x2 ) + 4f (x3 ) + f (x4 )) + · · · + (f (xN −2 ) + 4f (xN −1 ) + f (xN )]
3
h5
− [f (4) (ξ1 ) + f (4) (ξ2 ) + · · · + f (4) (ξN/2 )]
 90 
N/2−1 N/2 N/2
h X X h5 X (4)
= f (x0 ) + 2 f (x2i ) + 4 f (x2i−1 ) + f (xN ) − f (ξi ).
3 90
i=1 i=1 i=1

This formula is called composite Simpson’s rule. The error in the integration rule is given by
N
h5 X (4)
E(f ) = − f (ξi ).
90
i=1

If f ∈ C 4 [a, b], the Extreme Value Theorem implies that f (4) assumes its maximum and minimum in
[a, b]. Since
min f (4) (x) ≤ f (4) (ξi ) ≤ max f (4) (x).
x∈[a,b] x∈[a,b]
On summing, we have
N/2
N X N
min f (4) (x) ≤ f (4) (ξi ) ≤ max f (4) (x)
2 x∈[a,b] 2 x∈[a,b]
i=1
and
N/2
(4) 2 X (4)
min f (x) ≤ f (ξi ) ≤ max f (4) (x).
x∈[a,b] N x∈[a,b]
i=1
By the Intermediate Value Theorem, there is a c ∈ (a, b) such that
N/2
2 X (4)
f (4) (c) = f (ξi ).
N
i=1
Therefore
h5
E(f ) = − N f (4) (c),
180
8 NUMERICAL INTEGRATION

or, since h = (b − a)/N ,


(b − a) 4 (4)
E(f ) = − h f (c).
180
Example 3. Determine the values of subintervals n and step-size h required to approximate
Z2
1
dx
x+4
0
to within 10−5 and hence compute the approximation using composite Simpson’s rule.
1 24
Sol. Here f (x) = , therefore f (4) (x) = .
x+4 (x + 4)5
24
∴ max |f (4) (x)| = .
x∈[0,2] 45
Now error in Simpson’s rule is given by
h4 (b − a)f 4 (c)
E(f ) = − .
180
To get desire accuracy, we have
2h4 × 24
< 10−5
45
=⇒ h < 0.44267,
which gives
n ≥ 6.
By taking 6 subintervals with h = 2/6 = 1/3 and using Simpson’s rule, we obtain
1
IS = [f (0) + 4{f (1/3) + f (1) + f (5/3)} + 2{f (2/3) + f (4/3)} + f (2)] = 0.405466.
9
Example 4. Determine values of h (or n) that will ensure an approximation error of less than 0.00002

when approximating sin x dx and employing (a) Composite Trapezoidal rule and (b) Composite Simp-
o
son’s rule.
Sol. (a) The error form for the composite trapezoidal rule for f (x) = sin x on [0, π] is
2
π h 00 π h2 πh2


12 f (c) =
12 (− sin c) = |sin c|.
12
To ensure sufficient accuracy with this technique we need to have
π h2 π h2
|sin c|≤ < 0.0002.
12 12
Since h = π/n implies that n = π/h, we need
1/2
π3 π3

< 0.0002 which implies that n > ≈ 359.44
12n2 12(0.00002)
and the composite trapezoidal rule requires n ≥ 360.
(b) The error form for the composite Simpson’s rule for f (x) = sin x on [0, π] is
4
π h (4) π h4 πh4


180 f (c) =
180 sin c = |sin c|.
180
To ensure sufficient accuracy with this technique we need to have
π h4 π h4
|sin c| ≤ < 0.0002.
180 180
Using again the fact that n = π/h gives
1/4
π5 π5

< 0.0002 which implies that n > ≈ 17.07.
180 n4 180(0.00002)
NUMERICAL INTEGRATION 9

So composite Simpson’s rule requires only n ≥ 18. Composite Simpson’s rule with n = 18 gives
Z π  X 8 9 
π iπ X (2i − 1)π
sin x dx ≈ 2 sin( ) + 4 sin( ) = 2.0000104.
0 54 9 18
i=1 i=1

This is accurate to within about 10−5 because the true value is − cos(π) − (− cos(0)) = 2.
Example 5. The area A inside the closed curve y 2 + x2 = cos x is given by
Z α
1/2
A=4 (cos x − x2 ) dx
0

where α is the positive root of the equation cos x = x2 .


(a) Compute α with three correct decimals.
(b) Use trapezoidal rule to compute the area A with an absolute error less than 0.05.
Sol. (a) Using Newton method to find the root of the equation

f (x) = cos x − x2 = 0,
we obtain the following iteration scheme
cos xk − x2k
xk+1 = xk + , k = 0, 1, 2, · · ·
sin xk + 2xk
Starting with x0 = 0.5, we obtain
0.62758
x1 = 0.5 + = 0.92420
1.47942
−0.25169
x2 = 0.92420 + = 0.82911
2.64655
−0.011882
x3 = 0.82911 + = 0.82414
2.39554
−0.000033
x4 = 0.82414 + = 0.82413.
2.38226
Hence the value of α correct to three decimals is 0.824.
(b) Substituting the value of α, we obtain
Z 0.824
1/2
A=4 (cos x − x2 ) dx.
0

Using composite trapezoidal method by taking h = 0.824, 0.412, and 0.206 respectively, we obtain the
following approximations of the area A.
4(0.824)
A = [1 + 0.017753] = 1.67725
2
4(0.412)
A = [1 + 2(0.864047) + 0.017753] = 2.262578
2
4(0.206)
A = [1 + 2(0.967688 + 0.864047 + 0.658115) + 0.017753] = 2.470951.
2

5. Gauss Quadrature
In the numerical integration method if both nodes xi and multipliers λi are unknown then method is
called Gaussian quadrature. We can obtain the unknowns by making the method exact for polynomials
of degree as high as required. The formulas are derived for the interval [−1, 1] and any interval [a, b]
can be transformed to [−1, 1] by taking the transformation x = At + B which gives a = −A + B and
b−a b+a
b = A + B and after solving we get x = t+ .
2 2
10 NUMERICAL INTEGRATION

As observed in Newton-Cotes quadrature, we can write any integral as


Z 1 n Z1
X f (n+1) (c)
f (x)dx = λi f (xi ) + (x − x0 ) · · · (x − xn ) dx
−1 (n + 1)!
i=0 −1
n
X
= λi f (xi ) + E(f ).
i=0
If product does not change its sign in interval concerned, we can write error as
Z1
f (n+1) (c)
E(f ) = (x − x0 ) · · · (x − xn ) dx.
(n + 1)!
−1

f (n+1) (c)
= C,
(n + 1)!
where
Z1
C= (x − x0 ) · · · (x − xn ) dx.
−1
We can compute the value of C by putting f (x) = xn+1 to obtain
Z b n
n+1
X C
x dx = λi xi n+1 + (n + 1)!
a (n + 1)!
i=0
Z b Xn
=⇒ C = xn+1 dx − λi xi n+1 .
a i=0
The number C is called error constant. By using the notation, we can write error term as following
C
E(f ) = f (n+1) (c).
(n + 1)!
Gauss-Legendre Integration Methods: The technique we have described could be used to de-
termine the nodes and coefficients for formulas that give exact results for higher-degree polynomials.
One-point formula: The formula is given by
Z 1
f (x)dx = λ0 f (x0 ).
−1
The method has two unknowns λ0 and x0 . Make the method exact for f (x) = 1, x, we obtain
Z 1
f (x) = 1 : dx = 2 = λ0
−1
Z 1
f (x) = x : xdx = 0 = λ0 x0 =⇒ x0 = 0.
−1
Therefore one-point formula is given by
Z 1
f (x)dx = 2f (0).
−1
The error in approximation is given by
C 00
E(f ) = f (ξ)
2!
where error constant C is given by
Z 1
C= x2 dx − 2f (0) = 2/3.
−1
Hence
1
E(f ) = f 00 (ξ), −1 < ξ < 1.
3
NUMERICAL INTEGRATION 11

Two-point formula:
Z 1
f (x)dx = λ0 f (x0 ) + λ1 f (x1 ).
−1
The method has four unknowns. Make the method exact for f (x) = 1, x, x2 , x3 , we obtain
Z 1
f (x) = 1 : dx = 2 = λ0 + λ1 (5.1)
−1
Z 1
f (x) = x : xdx = 0 = λ0 x0 + λ1 x1 (5.2)
−1
Z 1
f (x) = x2 : x2 dx = 2/3 = λ0 x20 + λ1 x21 (5.3)
−1
Z 1
f (x) = x3 : x3 dx = 0 = λ0 x30 + λ1 x31 (5.4)
−1

Now eliminate λ0 from second and fourth equation


λ1 x31 − λ1 x1 x20 = 0
which gives
λ1 x1 (x1 − x0 )(x1 + x0 ) = 0
Since λ1 6= 0, x0 6= x1 and x1 6= 0 (if x1 = 0 then by second equation x0 = 0). Therefore x1 = −x0 .
Substituting in second equation, we obtain λ0 = λ1 .
By substituting these values in first equation,
√ we get λ0 = λ1√= 1.
Third equation gives x20 = 1/3 or x0 = ±1/ 3 and x1 = ∓1/ 3.
Therefore, the two-point formula is given by
Z 1    
1 1
f (x)dx = f − √ +f √ .
−1 3 3
The error is given by
C (4)
E(f ) = f (ξ)
4!
and Z 1     
4 1 1 8
C= x dx − f − √ +f √ = .
−1 3 3 45
The error in two-point formula is given by
1 (4)
f (ξ), −1 < ξ < 1.
E(f ) =
135
Three-point formula: By taking n = 2, we obtain
Z 1
f (x)dx = λ0 f (x0 ) + λ1 f (x1 ) + λ2 f (x2 ).
−1

The method has six unknowns. Make the method exact for f (x) = 1, x, x2 , x3 , x4 , x5 , we obtain
f (x) = 1 : 2 = λ0 + λ1 + λ2
f (x) = x : 0 = λ0 x0 + λ1 x1 + λ2 x2
f (x) = x2 : 2/3 = λ0 x20 + λ1 x21 + λ2 x22
f (x) = x3 : 0 = λ0 x30 + λ1 x31 + λ2 x32
f (x) = x4 : 2/5 = λ0 x40 + λ1 x41 + λ2 x42
f (x) = x5 : 0 = λ0 x50 + λ1 x51 + λ2 x52
p
p these equations, we obtain λ0 = λ2 = 5/9 and λ1 = 8/9. x0 = ± 3/5, x1 = 0 and
By solving
x2 = ∓ 3/5.
12 NUMERICAL INTEGRATION

Therefore formula is given by


Z 1 " r ! r !#
1 3 3
f (x)dx = 5f − + 8f (0) + 5f .
−1 9 5 5

The error in three-point formula is given by


C (6)
E5 = f (ξ)
6!
where  r !
6 r !6 
1
−3 −3
Z
6 1 = 8 .
C= x dx − 5 +8×0+5+
−1 9 5 5 175

1
∴ E5 = f (6) (ξ), −1 < ξ < 1.
15750
Note: Legendre polynomials Pn (x) is a monic polynomial of degree n. The first few Legendre poly-
nomials are
P0 (x) = 1,
P1 (x) = x,
1
P2 (x) = x2 − ,
3
3
P3 (x) = x3 − x.
5
Nodes in Gauss-Legendre rules are roots of these polynomials.
Example 6. Evaluate
Z 2
2x
I= 4
dx
1 1+x
using Gauss-Legendre 1 and 2-point formula. Also compare with the exact value.
t+3
Sol. Firstly we change the interval [1, 2] in to [−1, 1] by taking x = , dx = dt/3.
2
Z 2 Z 1
2x 8(t + 3)
I= dx = dt
1 1 + x4 −1 16 + (t + 3)4
Let
8(t + 3)
f (t) = .
16 + (t + 3)4
By 1-point formula
I = 2f (0) = 0.4948
By 2-point formula
   
1 1
I = f −√ +f √ = 0.5434
3 3
Now exact value of the integral is given by
Z 2
2x π
I= 4
dx = tan−1 4 − = 0.5408
1 1+x 4
Example 7. Evaluate
Z 1
3/2
I= (1 − x2 ) cos x dx
−1
using Gauss-Legendre 3-point formula.
NUMERICAL INTEGRATION 13

3/2
Sol. Using Gauss-Legendre 3-point formula with f (x) = (1 − x2 ) cos x, we obtain
" r ! r !#
1 3 3
I = 5f − + 8f (0) + 5f
9 5 5
"   ! r !#
2 3/2
r  3/2
1 3 2 3
= 5 cos +8+5 cos
9 5 5 5 5
= 1.08979.
Example 8. Evaluate Z 1
dx
I=
0 1+x
by subdividing the interval [0, 1] into two equal parts and then by using Gauss-Legendre three-point
formula.
Sol. " r ! r !#
Z 1
1 3 3
f (x)dx = 5f − + 8f (0) + 5f .
−1 9 5 5
Let Z 1 Z 1/2 Z 1
dx dx dx
I= = + = I1 + I2 .
0 1+x 0 1+x 1/2 1 + x
t+1 z+3
Now substitute x = and x = in I1 and I2 , respectively to change the limits to [−1, 1].
4 4
We have dx = dt/4 and dx = dz/4 for integral I1 and I2 , respectively.
Therefore Z 1 " #
dt 1 5 8 5
I1 = = p + + p = 0.405464
−1 t + 5 9 5 − 3/5 5 5 + 3/5
Z 1 " #
dz 1 5 8 5
I2 = = p + + p = 0.287682
−1 z + 7 9 7 − 3/5 7 7 + 3/5
Hence
I = I1 + I2 = 0.405464 + 0.287682 = 0.693146.

Exercises
(1) Given
Z 1
I= x ex dx.
0
Approximate the value of I using trapezoidal and Simpson’s one-third method. Also obtain
the error bounds and compare with exact value of the integral.
(2) Evaluate
Z 1
dx
I=
0 1 + x2
using trapezoidal and Simpson’s rule with 4 and 6 subintervals. Compare with the exact value
of the integral.
(3) Approximate the following integrals using the trapezoidal and Simpson formulas. a. I =
0.25 e+1 1
(cos x)2 dx
R R
b. dx. Find a bound for the error using the error formula, and
−0.25 e x ln x
compare this to the actual error.
R2
(4) The quadrature formula f (x)dx = c0 f (0) + c1 f (1) + c2 f (2) is exact for all polynomials of
0
degree less than or equal to 2. Determine c0 , c1 , and c2 .
R2
(5) The quadrature formula f (x)dx = c0 f (0) + c1 f (1) + c2 f (2) is exact for all polynomials of
0
degree less than or equal to 2. Determine c0 , c1 , and c2 .
14 NUMERICAL INTEGRATION

(6) Determine the values of a, b, and c such that the formula


Z h
f (x)dx = h [af (0) + bf (h/3) + cf (h)]
0
is exact for polynomials of degree as high as possible. Also obtain the degree of the precision.
(7) The length of the curve represented by a function y = f (x) on an interval [a, b] is given by the
integral
Z bp
I= 1 + [f 0 (x)]2 dx.
a
Use the trapezoidal rule and Simpson’s rule with 4 and 6 subintervals compute the length of
the graph of the ellipse given with equation 4x2 + 9y 2 = 36.
(8) Determine the values of n and h required to approximate
Z2
e2x sin 3x dx
0

to within 10−4 . Use composite Trapezoidal and composite Simpson’s rule.


(9) The equation
Z x
1 2
√ e−t /2 dt = 0.45
0 2π
can be solved for x by applying Newton’s method to the function
Z x
1 2 1 2
f (x) = √ e−t /2 dt − 0.45 & f 0 (x) = √ e−x /2 .
0 2π 2π
Note that Newton’s method would require the evaluation of f (xk ) at various xk which can be
estimated using a quadrature formula. Find a solution for f (x) = 0 with error no more than
10−5 using Newton’s method starting with x0 = 0.5 and by means of the composite Simpson’s
rule.
(10) A car laps a race track in 84 seconds. The speed of the car at each 6-second interval is
determined by using a radar gun and is given from the beginning of the lap, in feet/second, by
the entries in the following table.
Time 0 6 12 18 24 30 36 42 48 54 60 66 72 78 84
Speed 124 134 148 156 147 133 121 109 99 85 78 89 104 116 123
How long is the track?
(11) A particle of mass m moving through a fluid is subjected to a viscous resistance R, which is a
function of the velocity v. The relationship between the resistance R, velocity v, and time t is
given by the equation
Zv(t)
m
t= du
R(u)
v(t0 )

Suppose that R(v) = −v v for a particular fluid, where R is in newtons and v is in me-
ters/second. If m = 10 kg and v(0) = 10 m/s, approximate the time required for the particle
to slow to v = 5 m/s.
(12) Evaluate the integral
Z 1
2
e−x cos x dx
−1
by using the Gaussian quadrature with n = 1 and n = 2.
(13) Determine constants a, b, c, and d that will produce a quadrature formula
Z 1
f (x)dx = af (−1) + bf (1) + cf 0 (−1) + df 0 (1)
−1
that has degree of precision 3.
NUMERICAL INTEGRATION 15

(14) Compute by Gaussian quadrature with n = 2 and compare with the exact value of the integral.
Z 3.5
x
√ dx.
2
x −4
3
(15) Evaluate
Z 1
sin x dx
I=
0 2+x
by subdividing the interval [0, 1] into two equal parts and then by using Gaussian quadrature
with n = 2.
(16) Determine the coefficients in the formula
Z 2h
x−1/2 f (x)dx = (2h)1/2 [A0 f (0) + A1 f (h) + A2 f (2h)] + R
0
and calculate the remainder R, while f (3) (x) is constant.
(17) Consider approximating integrals of the form
Z1

I= xf (x)dx
0
in which f (x) has several continuous derivatives on [0, 1].
(a) Find a formula
Z1

xf (x)dx ≈ w1 f (x1 ) = I1
0
which is exact if f (x) is any linear polynomial.
(b) To find a formula
Z1

xf (x)dx ≈ w1 f (x1 ) + w2 f (x2 ) = I2
0
which is exact for all polynomials of degree ≤ 3, set up a system of four equations with unknowns
w1 , w2 , x1 , x2 . Verify that
r ! r !
1 10 1 10
x1 = 5+2 , x2 = 5−2 ,
9 7 9 7
r !
1 7 2
w1 = 5+ , w2 = − w1
15 10 3
is a solution of the system.
(c) Apply I1 and I2 to the evaluation of
Z1

I= xe−x dx = 0.37894469164.
0

Appendix A. Algorithms
Algorithm (Composite Trapezoidal Method):
Step 1 : Inputs: function f (x); end points a and b; and N number of subintervals.
Step 2 : Set h = (b − a)/N .
Step 3 : Set sum = 0
Step 4 : For i = 1 to N − 1
Step 5 : Set x = a + h ∗ i
Step 6 : Set sum = sum+2 ∗ f (x)
end
Step 7 : Set sum = sum+f (a) + f (b)
16 NUMERICAL INTEGRATION

Step 8 : Set ans = sum∗(h/2)


End

Algorithm (Composite Simpson’s Method):


Step 1 : Inputs: function f (x); end points a and b; and N number of subintervals (even).
Step 2 : Set h = (b − a)/N .
Step 3 : Set sum = 0
Step 4 : For i = 1 to N − 1
Step 5 : Set x = a + h ∗ i
Step 6 : If i%2 = 0
sum = sum+2 ∗ f (x)
else
sum = sum+4 ∗ f (x)
end
Step 7 : Set sum = sum+f (a) + f (b)
Step 8 : Set ans = sum∗(h/3)
End

Bibliography
[Burden] Richard L. Burden, J. Douglas Faires and Annette Burden, “Numerical Analysis,” Cengage
Learning, 10th edition, 2015.
[Atkinson] K. Atkinson and W. Han, “Elementary Numerical Analysis,” John Willey and Sons, 3rd
edition, 2004.

You might also like