Numerical Integration Techniques Explained
Numerical Integration Techniques Explained
Integration and
Differential Equations
UNIT 2 NUMERICAL INTEGRATION
Structure Page Nos
2.0 Introduction 24
2.1 Objectives 25
2.2 Methods Based on Interpolation 25
2.2.1 Methods Using Lagrange’s Interpolation
2.2.2 Methods Using Newton’s Forward Interpolation
2.3 Composite Integration 34
2.4 Summary 38
2.5 Solutions/Answers 39
2.0 INTRODUCTION
In Unit 1, we developed methods of differentiation to obtain the derivative of a
function f(x), when its values are not known explicitly, but are given in the form of a
table. In this unit, we shall derive numerical methods for evaluating the definite
integrals of such functions f(x). You may recall that in calculus, the definite integral
of f(x) over the interval [a, b] is defined as
b
lim
∫ f (x) dx = h → 0 R[h ]
a
(b − a )
where R[h] is the left-end Riemann sum for n subintervals of length h = and is
n
given by
n −1
R [h ] = ∑ h f (x
k −0
k)
for the nodal points x0, x1, …, xn, where x k = x0 +kh and x0 = a, xn = b.
The need for deriving accurate numerical methods for evaluating the definite integral
arises mainly, when the integrand is either
2 sin( x )
i) a complicated function such as f(x) = e − x or f ( x ) = etc. which have no
x
anti-derivatives expressible in terms of elementary functions, or
Many scientific experiments lead to a table of values and we may not only require an
approximation to the function f(x) but also may require approximate representations
of the integral of the function. Also, for functions the integrals of which can be
calculated analytically, analytical evaluation of the integral may lead to
transcendental, logarithmic or circular functions. The evaluation of these functions
for a given value of x may not be accurate. This motivates us to study numerical
integration methods which can be easily implemented on calculators.
In this unit we shall develop numerical integration methods where in the integral is
approximated by a linear combination of the values of the integrand i.e.
b
∫ f (x) dx = β
a
0 f ( x 0 ) + β1 f ( x 1 ) + ............ + β n f ( x n ) (1)
24
where x0, x1, ………xn are the points which divide the interval [a, b] into n sub- Numerical Integration
intervals and β0, β1, ………βn are the weights to be determined. We shall discuss in
this unit, a few techniques to determine the unknowns in Eqn. (1).
2.1 OBJECTIVES
After going through this unit you should be able to:
• state the basic idea involved in numerical integration methods for evaluating the
definite integral of a given function;
• use numerical integration method to find the definite integral of a function f(x)
whose values are given in the form of a table;
• use trapezoidal and Simpson’s rules of integration to integrate such functions
and find the errors in these formulas.
∫a
f ( x ) dx ≈ ∑β
k =0
k fk (2)
where the n + 1 distinct points xk, k = 0, 1, 2, ………., n are called the nodes or
abscissas which divide the interval [a, b] into n sub-intervals with
(x0 < x1, < x2, ……. < xn-1 < xn) and βk, k =0, 1, ….n, are called the weights of the
integration rule or quadrature formula. We shall denote the exact value of the definite
integral by I and denote the rule of integration by
n
I h [f ] = ∑ β k f k (3)
k =0
b n
E h [f ] = f ( x )dx −
∫ ∑β
k =0
kfk (4)
a
In Eqn. (3) we have 2n+2 unknowns viz., n + 1 nodes xk and the n + 1 weights, βk and
the method can be made exact for polynomials of degree ≤ 2n + 1. Thus, the method
of the form (3) can be of maximum order 2n + 1. But, if some of the values are
prescribed in advance, then the order will be reduced. If all the n + 1 nodes are
prescribed, then we have to determine only n + 1 weights and the corresponding
method will be of maximum order n.
n
f ( x ) ≈ Pn ( x ) = ∑L
k =0
k ( x )f k (5)
π( x ) n +1
E n +1 [Pn ( x )] = f (α) , with x 0 < α < x n (6)
(n + 1)!
( x − x 0 ) ( x − x1 )....( x − x k −1 ) ( x − x k +1 )....( x − x n )
where Lk (x) =
( x k − x 0 ) ( x k − x1 ) ......( x k − x k −1 ) ( x k − x k +1 )....( x k − x n )
and π( x ) = ( x − x 0 ) ( x − x 1 )...( x − x n ) .
We replace the function f(x) in the definite integral (2) by the Lagrange interpolating
polynomial Pn (x) given by Eqn. (5) and obtain
b n b n
I n [f ] = ∫
a
Pn ( x )dx = ∑∫
k =0
a
L k ( x )f k dx = ∑β
k −0
kfk (7)
b
where β k = ∫La
k ( x ) dx. (8)
b b
π( x )
E n [f ] = E n +1 [Pn ( x )] dx =
∫ ∫ (n + 1)!f
n +1
(α)dx (9)
a a
We have
b
M n +1
E n [f ] ≤ ∫ π( x ) dx (10)
(n + 1)!
a
max
where M n +1 = f n+1 ( x )
x0 < x < xn
Let us consider now the case when the nodes xk ‘s are equispaced with x0 = a, xn = b
b−a
with the length of each subinterval as h = . The numerical integration methods
n
given by (7) are then known as Newton-Cotes formulas and the weights βk’s given
by (8) are known as Cotes numbers. Any point x ε [a, b] can be written as x = x0 +
sh.
n
(−1) n − k
βk =
k! (n − k )! ∫
h s(s − 1)(s − 2).........(s − k + 1)(s − k − 1)......(s − n ) ds
0
(12)
n
h n + 2 M n +1
and E n [f ] ≤ ∫ s(s − 1)(s − 2).....(s − n)ds (13)
(n + 1)!
0
We now derive some of the Newton Cotes formulas viz. trapezoidal rule and
Simpson’s rule by using first and second degree Lagrange polynomials with equally
spaced nodes.
Trapezoidal Rule
When n = 1, we have x0 = a, x1= b and h = b─a. Using Eqn. (12) the Cotes numbers
can be found as
1
h
β 0 = − h ∫ (s − 1)ds = ;
0
2
1
h
and ∫
β1 = h s ds =
0
2
.
h
IT [ f ] = [f 0 + f1 ] (14)
2
1
h3 h3 h3
E T [f ] ≤ M2 ∫ s (s − 1) ds = − M2 = M2
2 12 12
0
b
Thus, by trapezoidal rule, ∫ f (x ) dx is given by
a
h h3
I[f ] = (f 0 + f 1 ) − M2
2 12
The reason for calling this formula the trapezoidal rule is that geometrically when f(x)
is a function with positive values then h (f0 + f1)/2 is the area of the trapezium when
height h = b─a and parallel sides as fo and f1. This is an approximation to the area
under the curve y = f(x) above the x-axis bounded by the ordinates x = x1 (see Fig. 1.)
27
Differentiation, Since the error given by Eqn. (15) contains the second derivative, trapezoidal rule
Integration and integrates exactly polynomials of degree ≤ 1.
Differential Equations
P1
a = x0 x1 = b
Fig. 1
1
dx
I= ∫ 1+ x
0
using trapezoidal rule and obtain a bound for the error. The exact value of
I = ln2 = 0.693147 correct to six decimal places.
1 1
IT [f ] = 1 + = 0.75
2 2
1 2 1
ET [f ] ≤ max 3
= = 0.166667
12 (1 + x ) 6
Thus, the error bound retain is much greater than the actual error.
Simpson’s Rule
b−a a+b
For n = 2, we have h = , x 0 = a, x 1 = and x 2 = b.
2 2
2
h h
β0 =
20 ∫
(s − 1) (s − 2) ds =
3
28
2 2 Numerical Integration
4h h h
∫
β1 = h s(s − 2) ds =
0
3
, β2 =
20 ∫
s(s − 1) ds = .
3
h
I S [f ] = [f 0 + 4f1 + f 2 ] (17)
3
b
Eqn. (17) is the Simpson’s rule for approximating I = ∫ f (x ) dx
a
The magnitude of the error of integration is
2
h 4M3
E2[f ] ≤ ∫ s (s − 1) (s − 2) ds
3!
0
h 4M3
1 2
=
3!
0
∫ 1
∫
s (s − 1) (s − 2) ds + s(s − 1) (s − 2) ds
s 4 1 2
h 4M3 2 s4 2
= − s + s + − s + s
3 3
3! 4 4
0
1
h 4M3 1 1
= − =0
3! 4 4
This indicates that Simpson’s rule integrates polynomials of degree 3 also exactly.
Hence, we have to write the error expression (13) with n = 3. We find
5 2
ES [ f ] ≤h M4
∫ s(s − 1) (s − 2) (s − 3) ds
24
0
h 5M 4
1 2
=
24 0 ∫ 1
∫
s(s − 1) (s − 2) (s − 3) ds + s (s − 1) (s − 2) (s − 3) ds
(18)
− h 5M 4
=
90
max
where M 4 = f IV (X)
x0 < x < x2
Since the error in Simpson’s rule contains the fourth derivative, Simpson’s rule
integrates exactly all polynomials of degree ≤ 3.
b
Thus, by Simpson’s rule, ∫ f (x) dx is given by
a
5
h
I S [f ] = [f 0 + 4f 1 + f 2 ] − h M 4
3 90
29
Differentiation, h
Integration and Geometrically, [f 0 + 4f1 + f 2 ] represents the area bounded by the quadratic curve
Differential Equations 3
passing through (x0 , f0), (x1 , f1) and (x2 , f2) above the x-axis and lying between the
ordinates x = x0, x = x2 (see figure. 2).
y
f
P2
x
a= x0 x1 x2 = b
Fig. 2
In case we are given only one tabulated value in the interval [a, b], then h = b – a, and
the interpolating polynomial of degree zero is P0(x) = fk. In this case, we obtain the
rectangular integration rule given by
b
I R [f ] = f k dx ≈ hf k
∫ (19)
a
h 2 M1
ER f ≤ (20)
2
where max
M1 = f '(x )
a < x < b
If the given tabulated value in the interval [a, b] is the value at the mid-point then we
( a + b)
have x k = , and f k = f 1 . In this case h = b – a and we obtain the integration
2 k+
2
rule as
b
I M [f ]= f ∫ 1 dx ≈ hf 1
(21)
k+ k+
a 2 2
Rule (21) is called the mid-point rule. The error in the rule calculated from (13) is
h2
E M [f ]=
1/ 2
2 ∫
−1 / 2
s ds = 0
This shows that mid-point rule integrates polynomials of degree one exactly. Hence
the error for the mid-point rule is given by
30
Numerical Integration
h 3M 2 h 3M 2
E M [f ]≤
1/ 2
2 ∫−1 / 2
s (s − 1) ds =
24
(22)
max
where M 2 = f " ( x ) and h = b – a
a<x<b
∫
2
Example 2 : Evaluate e − x dx, u sin g
0
a) I R [f ]= hf 0, we get I R [f ]=1.
h
c) I T [f ] = [f 0 + f1 ] we get I T [f ] = 1 (1 + 0.36788) = 0.68394.
2 2
Taking h = 0.5 and using Simpson’s rule, we get
h
d) I S [f ] = [f 0 + 4f1 + f 3 ]
3
h
= [f (0) + 4f (0.5) + f (1)]
3
= 0.74718
Exact value of the integral is 0.74682.
E R [f ]= − 0.25318, E M [f ]= − 0.03198
E T [f ] = 0.06288, E s [t ] = − 0.00036.
31
Differentiation, 0.1
∫x
1/ 3
Integration and b) dx
Differential Equations 0
π/4
c) ∫ tan x dx
0
b−a
The step length is given by h = .
n
The Newton’s forward finite difference interpolation formula interpolating this data is
given by
∆2f 0 s (s − 1) (s − 2) ... (s − n + 1) ∆n f 0
f ( x ) ≈ Pn ( x ) = f 0 + s∆f 0 + s(s − 1) + ... + (23)
2 n!
h n +1 s(s − 1) (s − 2) ... (s − n ) n +1
E n [f ]= f (α )
(n + 1) !
Integrating both sides of Eqn. (23) w.r.t. x between the limits a and b, we can
approximate the definite integral I by the numerical integration rule
b 1
s (s − 1) 2
I h [f ] = Pn ( x ) dx = h
∫ ∫ f 0 + s ∆f 0 + ∆ f 0 + ... ds (24)
2
a 0
1
h n + 2 M n +1
E h (f ) ≤
(n + 1) ! 0 ∫
s (s − 1) (s − 2) ... (s − 1) ds
We can obtain the trapezoidal rule (14) from (24) by using linear interpolation i.e.,
f(x) ≈ P1 ( x ) = f 0 + s ∆ f 0 . We then have
1
IT (x ) = h ∫ [f
0
0 + s∆f 0 ]ds
1
s2
= h s f 0 + ∆f 0
2 0
∆f h
= h f 0 + 0 = [f 0 + f1 ]
2 2
32
with the error of integration given by (15). Numerical Integration
Similarly Simpson’s rule (16) can be obtained from (24) by using quadratic
interpolation i.e., f (x) ≈ P2 (x).
Taking x0 = a, x1 = x0 + h, x2 = x0 + 2h = b, we have
b 2
s (s − 1) 2
Is [f ]= ∫ f ( x ) dx ≈ h ∫ f 0 + s ∆f 0 + ∆ f 0 ds
a 0 2
∆2 f 0
= h 2 f 0 + 2∆f 0 +
3
h
= [f n + 4f1 + f 2 ].
3
1
dx
Example 3: Find the approximate value of I = ∫ 1 + x u sin g
0
Simpson’s rule. Obtain the error bound and compare it with the actual error. Also
compare the result obtained here with the one obtained in Example 1.
1
Solution: Here x0 = 0, x1 = 0.5, x2 = 1 and h = .
2
Using Simpson’s rule we have
I s [f ] =
h
[f (0) + 4f (0.5) + f (1)] = 1 1 + 8 + 0.5 = 0.694445
3 6 3
h5 24
E s [f ] ≤ M 4 = 0.00833, where M 4 = max = 24
90 (1 + x ) 5
Here too the actual error is less than the given bound.
Also actual error obtained here is much less than that obtained in Example 1. You
may now try the following exercise.
1.5
∫e
x
Ex. 2) Find an approximation to dx, u sin g
1.1
a) the trapezoidal rule with h = 0.4
b) Simpson’s rule with h = 0.2
The Newton-Cotes formulas as derived above are generally unsuitable for use over
large integration intervals. Consider for instance, an approximation to
4
∫e
x
dx, using Simpson’s rule with h = 2. Here
0
33
Differentiation, 4
∫ e dx ≈ 3 (e )
x 2 0
Integration and + 4e 2 + e 4 = 56.76958.
Differential Equations 0
Since the exact value in this case e4 – e0 = 53.59815, the error is –3.17143. This error
is much larger than what we would generally regard as acceptable. However, large
error is to be expected as the step length h = 2.0 is too large to make the error
expression meaningful. In such cases, we would be required to use higher order
formulas. An alternate approach to obtain more accurate results while using lower
order methods is the use of composite integration methods, which we shall discuss in
the next section.
(b − a )
We divide the interval [a, b] into N subintervals of length h = . We denote the
N
subintervals as
b N xk
∫
I = f ( x ) dx = ∑ ∫
k =1 x k −1
f ( x ) dx (25)
a
Evaluating each of the integrals on the right hand side by trapezoidal rule, we have
N (26)
h
I T [f ] = ∑ [f k −1 + f k ] = h [f 0 + f N + 2(f1 + f 2 + ..... + f N −1 ) ]
k =1
2 2
`
h
3 N
E T [f ] = − ∑
f " (α i ) , x k −1 < α i < x k , for k = 1...., N.
12 i =1
N N
∑ i =1
f " (α i ) = f " (ξ) ∑ 1, where a < ξ < b.
i =1
3
−h
∴E T [f ]= f " (ξ) N, a < ξ < b.
12
− Nh 3
= h f " ( ξ)
12
− ( b − a ) h 2.
= f " (ξ).
12
34
max Numerical Integration
If M 2 = f " (ξ) . Then
a<ξ<b
(b − a ) h 2
E T [f ] ≤ M2 (27)
12
h
I T [f ]= [first ordinate + last ordinate + 2 (sum of the remaining ordinates)].
2
b N x 2k
∫
I = f ( x) dx = ∑ ∫
k =1 x 2 k − 2
f ( x ) dx (28)
a
Evaluating each of the integrals on the right hand side of Eqn. (28) by the Simpson’s
rule, we have
h
N = [f0 + f2N + 4(f1 + f3 +....+ f2N−1) + 2(f2 + f4 + ....+ f2N−2)] (29)
h
Is[f ] =
∑ [f2k−2+4f2k−1+f2k] 3
k=1
3
integration. The error in (29) is obtained from (18) by adding up the errors. Thus we
get
h5
N
E s [f ] = − ∑IV
f (α ) , x 2 k − 2 < α k < x 2 k
90 k =1
N
h5
= −
90
f iv
(ξ ) ∑i =1
1, a < ξ < b
Nh 5 IV
=− f (ξ)
90
(b − a ) h 4 IV
=− f (ξ).
180
max (b − a )
If M 4 = f IV (ξ) write using h =
a ≤ ξ ≤b 2N
(b − a ) 4
E s [f ] ≤ h M4 (30)
180
35
Differentiation, The error is of order h4 and it approaches zero very fast as h → 0. The rule integrates
Integration and exactly polynomials of degree ≤ 3. We can remember the composite Simpson’s rule
Differential Equations
as
h
Is [f ]= [first ordinate + last ordinate + 2 (sum of even ordinates) + 4 (sum of the remaining odd ordinates)]
3
1
dx
Example 4: Evaluate ∫ 1+ x
0
using
(a) Composite trapezoidal rule (b) composite Simpson’s rule with 2, 4 and 8
subintervals.
1
Solution: We give in Table 1 the values of f (x) with h = from x = 0 to x = 1.
8
Table 1
x : 0 1/8 2/8 3/8 4/8 5/8 6/8 7/8 1
We get
1
I T [f ]= [f 0 + 2f 4 + f8 ]= 17 = 0.708333
4 24
1 25
Is [f ]= [f 0 + 4f1 + f 8 ]= = 0.694444
6 36
If N = 4 then h = 0.25 and the ordinates f0, f2, f4, f6, f8 are to be used.
We have
1
I T [f ] = [f 0 + f8 + 2(f 2 + f 4 + f 6 )]= 0.697024
8
1
I T [f ] = [f 0 + f 8 + 4 (f 2 + f 6 ) + 2 f 4 ] = 0.693254
12
We obtain
1
I T [f ] = [f 0 + f8 + 2 (f1 + f 2 + f 3 + f 4 + f 5 + f 6 + f 7 )]= 0.694122
16
1
Is [f ] = [f 0 + f8 + 4 (f1 + f 3 + f 5 + f 7 ) + 2 (f 2 + f 4 + f 6 )]= 0.693147
24
The exact value of the given integral correct to six decimal places is ln2 = 0.693147.
Note that as h decreases, the errors in both trapezoidal and Simpson’s rule also
decreases. Let us consider another example.
1
dx
Example 5: Find the minimum number of intervals required to evaluate
0
1 + x ∫
with
(b − a )5 M 4
E s [f ] ≤
2880 N 4
where
max
M4 = f IV ( x )
0 < x <1
max 24
= = 24
0 < x < 1 (1 + x )5
24 24 * 10 6
≤ 10 − 6 , or N 4 ≥ = 8333.3333
2880 N 4 2880
∴N ≥ 9.5
We find that we cannot take N = 9 since to make use of Simpson’s rule we should
have even number of intervals. We therefore conclude that N = 10 should be the
minimum number of subintervals to obtain the accuracy 1.E – 06 (i.e., 10-6)
1
dx
Ex.3) Evaluate ∫1+ x
0
2
by subdividing the interval (0, 1) into 6 equal parts and
using.
(a) Trapezoidal rule (b) Simpson’s rule. Hence find the value of π and actual errors.
37
Differentiation, Ex.5) The speedometer reading of a car moving on a straight road is given by the
Integration and following table Estimate the distance traveled by the car in 12 minutes using
Differential Equations
(a) Trapezoidal rule (b) Simpson’s rule.
Time : 0 2 4 6 8 10 12
(minutes)
Speedo meter : 0 15 25 40 45 20 0
Reading
0.4
∫
2
Ex.7) Determine N so that composite trapezoidal rule gives the value of e − x dx
0
−x 2
correct upto 3 digits after the decimal point, assuming that e can be calculated
accurately.
2.4 SUMMARY
In this unit, we learnt the following :
b n
∫ f ( x ) dx ≈ ∑β
k =0
k f (x k ) (See Eqn. (21))
a
where the (n+1) distinct nodes x k , k = 0,1, ...., n , with x 0 < x1 < x 2 < .... < x n divide
the interval (a, b) into n subintervals and β k , k = 0,1, ...., n are the weights of the
integration rule. The error of the integration methods is then given by
b n
E h [f ] = f ( x ) dx −
∫ ∑β
k =0
k f (x k ) (see Eqn. (4))
a
38
4) For large integration intervals, the Newton-Cotes formulas are generally Numerical Integration
unsuitable for they give large errors. Composite integration methods can be
used in such cases by dividing the interval into a large number of subintervals
and evaluating the integral in each of the subintervals using one of the
integration rules.
2.5 SOLTIONS/ANSWERS
h
E1) a) I T [f ]= [f 0 + f1 ]= 0.346574
2
h
Is [f ]= [f 0 + 4f1 + f 2 ]
3
0 .5
= [41n 1.5 +1n 2]= 0.385835
3
Also
h 3 max 1 1
E T [f ] ≤ − 2
=− = − 0.083334
12 1 < x < 2 x 12
h5 max 6
E s [f ] ≤ − = − 0.002083
90 1 < x < 2 x 4
b) I T [f ]= 0.023208, E T [f ] = none .
IS [f ]= 0.032296, E S [f ] = none .
c) I T [f ] = 0.39270, E T [f ] = 0.161.
IS [f ]= 0.34778 , E S [f ] = 0.00831.
E2) I T [f ]=1.49718
IS [f ]=1.47754
1
E3) With h = 1/6, the values of f(x) =
1 + x2
From x = 0 to 1 are
= 0.784241
h
IS [f ]= [f 0 + f 6 + 4 (f1 + f 3 + f 5 ) + 2(f 2 + f 4 )]
3
= 0.785398
[ ]10 = π4 .
1
dx
∫0
1+ x 2
= tan −1x Exact π = 3.141593
h
E4) I T [f ]= [f 0 + f 4 + 2(f1 + f 2 + f 3 ) ]
2
12
I= ∫
0
v dt ,
h
I T [v] = [v 0 + v 6 + 2( v1 + v 2 + v 3 + v 4 + v 5 )] =290
2
880
Is [v]= = 293.33.
30
0.1
I T [f ]= [f (0.2) + 2f (0.3) + f (0.4)]= 0.57629
2
0.1
IS [f ]= [f (0.2) + 4f (0.3) + f (0.4)]= 0.574148
3
Es = 9.2 x 10-5
(b − a ) 3 max
E T [f ] = − 2
M2 , M2 = f " (x) .
12 N 0 < x <1
Thus
1 max
E T [f ] ≤ 2
f " (x)
12 N 0 ≤ x ≤1
2 2
f ( x ) = e − x , f " ( x ) = e − x (4x 2 − 2)
2
f " ' ( x ) = e − x 4x (3 − 2 x 2 ) = 0 when or x = 0, x = 1.5
2 103 10 4
< 10 − 03 or N 2 > =
12 N 2 6 60
or
100
N> ≈12.9 .
(60)
41
Differentiation,
Integration and
Differential Equations
42