Numerical Integration
Numerical Integration
8.1 Introduction
has no closed form solution. The function exp(- x 2 ) is a continuous bounded function over
the interval [0, 0.5] and hence the integral exists. But it is not possible to evaluate it
analytically. Numerical technique is also required when the data for variables are available
in the form of table, but no mathematical relationship between them is known, as is often
the case of experimental data.
The purpose of this chapter is to develop the basic methods of numerical integration.
L7 - 1
Fall 23-24
Solution: Here there are two unknowns a and b. So we will use 𝑓(𝑥) = 1 and then 𝑓(𝑥) = 𝑥.[If
there are three unknowns , we will use 𝒇(𝒙) = 𝟏, 𝒇(𝒙) = 𝒙 & 𝒇(𝒙) = 𝒙𝟐 ].
'
Now for 𝑓(𝑥) = 1 we can write 𝑓 *(+ = 1 & 𝑓(ℎ) = 1.
' '
/ 𝑓(𝑥)𝑑𝑥 = / 1 𝑑𝑥 = 𝑎 + 𝑏
) )
ð ℎ = 𝑎 + 𝑏………………………(1)
' '
Now for 𝑓(𝑥) = 𝑥 we can write 𝑓 * + = & 𝑓(ℎ) = ℎ.
( (
' '
ℎ
/ 𝑓(𝑥)𝑑𝑥 = / 𝑥 𝑑𝑥 = 𝑎 𝑓 @ B + 𝑏𝑓(ℎ)
) ) 3
'! '
ð *
= 𝑎 ( + 𝑏ℎ
('
ð 𝑎 + 3𝑏 = …………………….(2)
*
(' '
Solving (1) and (2) we get 𝑎 = +
& 𝑏=+
' (' ' '
Thus we get ∫) 𝑓(𝑥)𝑑𝑥 = + 𝑓 *(+ + + (ℎ)
Here we have limit 0 & h but if the limits are xo & x1 other then 0 & h then the formula changes as
below
,-
3ℎ ℎ ℎ
/ 𝑓(𝑥)𝑑𝑥 = 𝑓 @𝑥𝑜 + B + (𝑥1)
,/ 4 3 4
Now
).0
∫).* 𝑐𝑜𝑠(G1 + 𝑥 * )𝑑𝑥
Here 𝑓(𝑥) = 𝑐𝑜𝑠√1 + 𝑥 * ; 𝑥𝑜 = 0.2, 𝑥1 = 0.8 , ℎ = 0.6
".$
3 ∗ 0.6 0.6
! 𝑐𝑜𝑠(&1 + 𝑥 ! )𝑑𝑥 = 𝑓(0.2 + 0.2) + 𝑓(0.8)
".! 4 4
(∗).2 ).2
= + 𝑓(0.4) + +
𝑓(0.8)
= 0.25619187
If the nodes x r ’s are uniformly distributed in [a, b] with x0 = a , x n = b and the spacing
h = (b - a) / n , the method is known as Newton-Cotes integration method and has the order
n. When both the end points of the interval are included as nodes, the methods are called
closed type methods, otherwise they are called open type methods.
L7 - 2
Fall 23-24
Assume that xr = x0 + rh are equally spaced nodes and f r = f ( xr ). the first few Newton-
Cotes quadrature formulas are listed below:
L7 - 3
Fall 23-24
h
ò x0 f ( x)dx » 2 [ f ( x0 ) + f ( x1)]
x1
h
[ f0 + f1 ]
»
2
where the notation f ( xr ) = f r is used.
where h = ( x2 - x0 ) / 2 .
Simpson’s rule can easily be proved by considering the integral
2h
ò 0 f ( x)dx » af (0) + bf (h) + cf (2h)
h
or ò - h f ( x)dx » af (-h) + bf (0) + cf (h)
and then by translating the axis. This is left as an exercise for the reader.
where h = ( x3 - x0 ) / 3 .
The precision of the rule is 3.
!.#
Example 8.2: Evaluate ∫#.$ 𝑓(𝑥)𝑑𝑥 numerically using the values given below.
x 0.4 0.5 0.7 1.0
f(x) 1.083 1.133 1.287 1.649
Solution: Here subinterval sizes are unequal. Using the Trapezoidal rule in each subinterval
separately, we have
L7 - 4
Fall 23-24
-.)
0.5 − 0.4 0.7 − 0.5
/ 𝑓(𝑥)𝑑𝑥 = (1.133 + 1.083) + (1.287 + 1.133)
).+ 2 2
1.0 − 0.7
+ (1.649 + 1.287)
2
0.1 0.2 0.3
= (2.216) + (2.420) + (2.936) = 0.7932
2 2 2
Example 8.3: The table below shows the values of f (x) at different values of x:
0.1
[𝑓(0.4) + 4 ∗ 𝑓(0.5) + 𝑓(0.6)]
=
3
0.2
+ [𝑓(0.6) + 4 ∗ 𝑓(0.8) + 𝑓(1.0)
3
0.1 0.2
= [1.083 + 4(1.133) + 1.197] + [1.197 + 4(1.377) + 1.649]
3 3
= 0.2271 + 0.5569 = 0.784
8.5 Composite Quadrature Rules
To avoid the use of higher order methods and still obtain accurate results, we use the
composite integration methods. We divide the interval [a, b] into a number of subintervals
and evaluate the integral in each required number of subintervals by a particular method.
Evaluating each integral on the right hand side by the trapezoidal rule
b h h h
òa f ( x)dx » 2 ( f 0 + f1 ) + 2 ( f1 + f 21 ) + × × × + 2 ( f N -1 + f N )
h
» [ f 0 + f N + 2( f1 + f 2 + f 3 + × × × + f N -1 )]
2
L7 - 5
Fall 23-24
Example 8.4 : The values of f (x) are given for different values of x below.
L7 - 6
Fall 23-24
The Simpson’s rule has an error of order O(h ) . In fact, I (1) (2n, h / 2) is exactly the
4
- ,!
Example 8.5 : Evaluate∫) 𝑥 exp * * + 𝑑𝑥using Trapezoidal rule with 1, 2 and 4 subintervals.
Improve the results using Romberg integration.
2
Solution: Here f ( x) = x e x / 2 .
Using the trapezoidal rule we have
1
n = 1, h = (1 - 0) = 1 ; I ( 0) (1,1) = [ f (0) + f (1)] = 0.8244
2
0.5
n = 2, h = 1 = 0.5 ; I ( 0) (2, 0.5) = [ f (0) + f (1) + 2 f (0.5)] = 0.6955
2 2
1
n = 4, h = 1 = 0.25 I (0) (4, 0.25) = [ f (0) + f (1) + 2( f (0.25) + f (0.5) + f (0.75))] = 0.6606
4 2
I ( 0) (2, 0.5) - I ( 0) (1, 1)
First order extrapolated values are I (1) (2, 0.5) = I ( 0) (2, 0.5) +
22 -1
0.6955 - 0.6244
= 0.6955 + = 0.6525
3
I ( 0) (4, 0.25) - I ( 0) (2, 0.5)
And I (1) (4, 0.25) = I ( 0) (4, 0.25) +
22 -1
L7 - 7
Fall 23-24
0.6606 - 0.6955
= 0.6606 + = 0.6490
3
I (1) (4, 0.25) - I (1) (2, 0.5)
Second extrapolated value is I ( 2) (4, 0.25) = I (1) (4, 0.25) +
24 -1
0.6490 - 0.6525
= 0.6490 + = 0.6488
15
Results are summarized below in a Table:
N H 𝑂(ℎ* ) 𝑂(ℎ+ ) 𝑂(ℎ2 )
1 1 0.8244
2 0.5 0.6955 0.6528
4 0.25 0.6606 0.6490 0.6488
8.7 Numerical Evaluation of Double Integrals
Multiple integrals are evaluated by expressing them as iterated integrals. For example a double
integral can be expressed as follows;
6 3!(,)
V 𝑓(𝑥, 𝑦)𝑑𝐴 = / Y/ 𝑓(𝑥, 𝑦)𝑑𝑦Z 𝑑𝑥
8 7 3" (,)
or
; 9! (:)
V 𝑓(𝑥, 𝑦)𝑑𝐴 = / Y/ 𝑓(𝑥, 𝑦)𝑑𝑥 Z 𝑑𝑦
8 < 9" (:)
In computing the iterated integral of the first form, we hold x constant while integrating with
respect to y and then integrate with respect to x(vice versa for second form).
Numerical evaluation of integrals we need to to choose interval length and nodal points where the
functional values to be calculated. For fixed limits, selection of interval length and nodal points
are straight forward but for variable limits interval length and nodal points should be calculated for
a fixed value of other variable. For example in firtst form the interval at 𝑥 = 𝑥= is
𝑓* (𝑥= ) − 𝑓- (𝑥= )
𝑘= =
𝑛
Example 8.6
-.) -.2 *: !
Using Simpson’s rule with 2-subintervals evaluate the double integral∫).2 ∫-.) ,>:
𝑑𝑦𝑑𝑥
The integral is over the rectangular region bounded by0.6 ≤ 𝑥 ≤ 1.0 and 1.0 ≤ 𝑦 ≤ 1.6.
Using 2-subintervals in each direction, we have
1.0 − 0.6 1.6 − 1.0
ℎ= = 0.2 and 𝑘 = = 0.3
2 2
*: !
The integrand is𝑓(𝑥, 𝑦) = ,>:.
Integration using fixed values of 𝑥 = 0.6, 0.8 and 1.0 are as follows:
%.&
0.3
𝐼(0.6) = ! 𝑓(0.6, 𝑦)𝑑𝑦 = [𝑓(0.6,1.0) + 4𝑓(0.6,1.3) + 𝑓(0.6,1.6)]
%." 3
).(
= [1.25 + 4(1.779) + 2.327] = 1.0693
(
%.&
0.3
𝐼(0.8) = ! 𝑓(0.8, 𝑦)𝑑𝑦 = [𝑓(0.8,1.0) + 4𝑓(0.8,1.3) + 𝑓(0.8,1.6)]
%." 3
".'
= [1.111 + 4(1.610) + 2.133] = 0.9684
'
L7 - 8
Fall 23-24
%.&
0.3
𝐼(1.0) = ! 𝑓(1.0, 𝑦)𝑑𝑦 = [𝑓(1.0,1.0) + 4𝑓(1.0,1.3) + 𝑓(1.0,1.6)]
%." 3
".'
= ' [1.0 + 4(1.47) + 1.969] = 0.8849
0.2
= [1.0693 + 4(0.9684) + 0.8849] = 0.38852
3
[MATLAB result is I = 0.38846]
Example 8.7 Using Simpson’s rule with 2-subinervals evaluate the double integral
-.+ ->, !
/ / (1 + 𝑥𝑦)𝑑𝑦𝑑𝑥
-.) ,
Solution: The region of integration is1.0 ≤ 𝑥 ≤ 1.4, 𝑥 ≤ 𝑦 ≤ 1 + 𝑥 *
The integrand is 𝑓(𝑥, 𝑦) = 1 + 𝑥𝑦
-.+?-.)
With 2 equal subintervals for x, the interval length is ℎ = * =0.2. The end points of
subintervals are 1, 1.2 and 1.4.
The interval length for y is variable depending on the values of x.
(1 + 1* ) − 1
For 𝑥 = 1, 𝑘- = = 0.5 and𝑦= = 1, 1.5, 2.0
2
The integral over y is
0.5
𝐼(1, 0.5) = [𝑓(1,1) + 4𝑓(1,1.5) + 𝑓(1,2.0)]
3
0.5
= [2 + 4(2.5) + 3] = 2.5
3
*
(1 + 1.2 ) − 1.2
For 𝑥 = 1.2 , 𝑘* = = 0.62 and𝑦= = 1.2, 1.82, 2.44
2
).2*
The integral over y is𝐼(1.2, 0.62) = ( [𝑓(1.2,1.2) + 4𝑓(1.2,1.82) + 𝑓(1.2, 2.44)]
0.5
= [2.44 + 4(3.184) + 3.928] = 3.9482
3
L7 - 9
Fall 23-24
(1 + 1.4* ) − 1.4
For 𝑥 = 1.4 , 𝑘( = = 0.78 and𝑦= = 1.4, 2.18, 2.96
2
).@0
The integral over y is𝐼(1.4, 0.78) = ( [𝑓(1.4,1.4) + 4𝑓(1.4, 2.18) + 𝑓(1.4, 2.96)]
0.78
= [2.96 + 4(4.052) + 5.144] = 6.3211
3
[ 𝐼(exact) = 1.64061]
Note: Define the function using “anonymous handle”. Format is shown below:
fname=@(argument) <space> formula
operation / (division) and ^ (for power) must preceded with . (dot).
ABC (,:)
For example 𝑓(𝑥, 𝑦) = , ! >: !
may be typed as
ff=@(x,y) sin(x*y)./(x.^2+y.^2))
This will be treated as ff(x,y).
L7 - 10
Fall 23-24
-
Example 8.6: Evaluate ∫) 𝑒 , sin 𝑥 * 𝑑𝑥 numerically to 7 digits using MATLAB command.
fun = @(x)exp(x).*sin(x.^2)
int7 =0.662701
* √, -
Example 8.8: Evaluate ∫) ∫?, 𝑑𝑦 𝑑𝑥 numerically using MATLAB command.
D, ! >: !
>> fun2=@(x,y) 1./sqrt(x.^2+y.^2) % define as @-function
fun2 = @(x,y)1./sqrt(x.^2+y.^2)
ymin = @(x)-x
ymax = @(x)sqrt(x)
int22 =3.811758
?@
Example 8.9: Evaluate ∭F , where R is the region bounded by the coordinate
(ABCBDBE)F
planes and the plane 𝑥 + 𝑦 + 𝑧 = 1, numerically using MATLAB command.
>> clear
>> fun3=@(x,y,z) 1./(x+y+z+1).^2 % define the integrand as a @-function
fun3 = @(x,y,z)1./(x+y+z+1).^2
ymax = @(x)1-x
>>zmax=@(x,y) 1-x-y
zmax = @(x,y)1-x-y
L7 - 11
Fall 23-24
int31 =0.05685282
Exercise 8
1. The table shows the power P supplied to the driving wheels of a car as a function of
the speed 𝑣. If the mass of the car is m=2000 kg, determine the time ∆𝑡 it takes for
the car to accelerate from 1𝑚/𝑠 to 6 𝑚/𝑠. Use the trapezoidal rule for integration.
Hint:
%&
∆𝑡 = 𝑚 3 (𝑣/𝑝)𝑑𝑣
!&
which can be derived from Newton’s law 𝐹 = 𝑚(𝑑𝑣/𝑑𝑡) and the definition of
power 𝑃 = 𝐹𝑣.
L7 - 12
Fall 23-24
x 0 10 20 30 40 50
d 0 4 7 9 12 15
5. The car gives the velocity 𝑣 of a moving particle at time t seconds. Find the
distance covered by the particle in 8 seconds.
t 0 2 4 6 8 9
v 4 6 16 34 60 75
!.*
Evaluate ∫!.# 𝑓(𝑥) 𝑑𝑥 using Tapezoidal rule with 1, 2 and 4 subintervals.
Improve your results using Romberg integration.
9. Using Simpson’s rule with two subintervals evaluate the following double integrals
and also write MATLAB code to evaluate.
!.5 ! '.# !.5
(a) ∫! ∫# Q𝑥 ' + 2R𝑦T𝑑𝑦𝑑𝑥 , (b) ∫!.$ ∫!.# ln(2𝑥 + 𝑦) 𝑑𝑥𝑑𝑦 ,
' ! #.* '
(c) ∫! ∫# (1 + 8𝑥 )𝑑𝑦𝑑𝑥 , (d) ∫#.' ∫# R𝑥 + 𝑦 𝑑𝑦𝑑𝑥 .
#.5 ! 34.(,9) ! '
(e) ∫# ∫# !1,9
𝑑𝑦𝑑𝑥 (f) ∫# ∫! 2exp(𝑦⁄𝑥 ) 𝑑𝑦𝑑𝑥
' ) !
(b) ∫# ∫# ∫# 𝑥𝑦𝑧 𝑑𝑧𝑑𝑦𝑑𝑥
L7 - 14