CH 8, Math 5 - Lecture - Note Summer 23 24
CH 8, Math 5 - Lecture - Note Summer 23 24
8.1 Introduction
Numerical integration is an essential tool used by scientists and engineers to obtain
approximate values for definite integrals that cannot be solved analytically. For example,
the integral
0.5
−x2
∫0 e dx
2
has no closed form solution. The function exp(−x ) 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.
where x r are called the nodes which are distributed within the limits of integration [a, b],
ω r are called the weighting factors and E is the error.
Example 8.1: Derive the quadrature rule of the form ∫ f ( x ) dx ≈ af ( h3 )+ bf (h) and
0
using this quadrature rule find the following integral to 3 d.p :
L7 - 1
Summer 2023-2024
0.8
∫ cos ( √1+ x 2 ) dx
0.2
Solution: Here there are two unknowns a and b . So, we will use f ( x )=1 and then f ( x )=x .[If
there are three unknowns, we will use f ( x )=1 , f ( x )=x∧f ( x )=x 2].
∫ f ( x ) dx=∫ 1 dx=a+b
0 0
h=a+b ……………………… (1)
Here we have limit 0 & h but if the limits are x 0 & x i other than 0 & h then the formula changes as
below
x1
∫ f ( x ) dx= 34h f ( x 0+ h3 )+ h4 (x 1)
xo
Now
0.8
∫ cos ¿ ¿
0.2
0.8
∫ cos ¿ ¿
0.2
3∗0.6 0.6
¿ f ( 0.4 ) + f ( 0.8 )
4 4
¿ 0.25619187
L7 - 2
Summer 2023-2024
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.
Assume that r
x =x 0 + rh are equally spaced nodes and f r =f ( xr ). the first few
Newton-Cotes quadrature formulas are listed below:
where,
h=x 1−x 0 .
To make the simplification short and simple, the axis is translated to make
x 0 as the
origin. Thus, the formula we are looking for is of the form
h
∫0 f ( x )dx≈af (0)+bf (h)
For two unknown parameters we may assume that the method is exact for f (x)=1 and x .
Thus
h
f ( x )=1 , ∫0 dx= [ x ]h0=h=a+b (1)
[]
2 h
h x h2
f ( x )=1 ,
∫0 x dx= 2 = 2 =bh
0
h
b=
or 2 (2)
From (1), we have
h h
a=h−b=h− =
2 2
The Trapezoidal rule becomes
h h
∫0 f ( x )dx≈ 2 [ f (0 )+f (h )]
To find the precision and an estimate of error, let us take the rule is of the form
h h
∫0 f ( x )dx= 2 [ f (0)+f (h )]+E
2
Taking f ( x )=kx , we have+
h h kh 3 kh 3 1
E=∫ 0 kx 2 dx− kh 2 = − =− kh 3
2 3 2 6
Here E≠0 . Hence the degree of precision is 2−1=1 .
''
Note that f ( x )=2k
''
Assuming that 2 k=f (e ) for 0≤e≤h we can write the error term as
h 2 ''
E=− h f (e )
12 .
L7 - 3
Summer 2023-2024
x ,x
The Trapezoidal rule for arbitrary points 0 1 with step size h can be obtained by
identifying the points 0 by x 0 , h by x 1=x 0 +h . In this case f (0)=f ( x 0 ) and f ( h)=f ( x 1 )
. Thus
x1 h
∫x 0
f ( x )dx≈
2[ 0
f ( x )+f ( x 1 ) ]
h
¿ [ f +f ]
2 0 1
where the notation f ( x r )=f r is used.
1.0
L7 - 4
Summer 2023-2024
Solution: Here subinterval sizes are unequal. Using the Trapezoidal rule in each
subinterval separately, we have
1.0
∫ f ( x ) dx= 0.5−0.4
2
( 1.133+1.083 ) +
0.7−0.5
2
( 1.287+1.133 )
0.4
+ 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:
Solution: Simpson’s rule is applied to two consecutive subintervals of equal length. Thus
for the given data we may divide the subintervals as follows:
1.0 0.6 1.0
∫ f ( x ) dx=∫ f ( x ) dx +∫ f ( x ) dx
0.4 0.4 0.6
0.1
¿
3
[ f ( 0.4 ) +4∗f ( 0.5 ) + f ( 0.6 ) ]
+ 0.2
¿
3
0.1 0.2
¿
3
[ 1.083+ 4 ( 1.133 ) +1.197 ] +
3
[1.197+ 4 ( 1.377 )+ 1.649]
¿ 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 several subintervals and
evaluate the integral in each required number of subintervals by a particular method.
We divide the interval [a, b] into N subintervals [ x r−1 , x r ] , each of length h=(b−a )/ N ,
x 0 =a , x N =b and x r =x 0 + rh, r=1, 2, 3, ¿ ⋅⋅¿ , N ¿. We write
L7 - 5
Summer 2023-2024
b x1 x2 xN
∫a f ( x)dx=∫ x f (x )dx+∫x f ( x)dx+¿⋅¿+∫ x
0 1 N−1
f (x )dx
Example 8.4: The values of f ( x ) are given for different values of x below.
x 0 0.2 0.4 0.6 0.8 1.0 1.2
f(x) 1.000 1.780 1.954 2.000 1.976 1.909 1.814
1 .2
Evaluate I = 0
∫ f ( x)dx
using extrapolation and (i) trapezoidal rule (ii) Simpson’s rule
Solution: (i) Consider the integral with trapezoidal rule.
0 .2
I T (0 .2 )= [1+2(1 . 780+1. 954 +2 .000+1. 976+1 . 909)+1 . 814 ]
2
=0. 1×22 . 078=2 . 208
0.4
I T (0 . 4 )= [ 1+2×1. 954 +2×1 . 976+1. 814 ]
2 = 0 . 2×10 . 674=2. 135
Using Richardson extrapolation
L7 - 6
Summer 2023-2024
( )
1 2
x
Example 8.5 : Evaluate∫ x exp dx using Trapezoidal rule with 1, 2 and 4 subintervals.
0 2
Improve the results using Romberg integration.
2
L7 - 7
Summer 2023-2024
0. 5
1
h= =0 . 5 Ι ( 0) (2 , 0. 5 )= [ f (0 )+f (1 )+2 f (0 . 5)]
n = 2, 2 ; 2 =0. 6955
( 0) 1
h= =0 .25 Ι
1 (4 , 0. 25 )= [ f (0)+f (1)+2( f (0 .25 )+f (0 .5 )+f (0 . 75))] = 0 . 6606
n = 4, 4 2
( 1) Ι ( 0)(2 , 0 . 5)−Ι (0 )(1 , 1)
( 0)
Ι (2 , 0 . 5)=Ι (2 , 0 . 5)+
First order extrapolated values are 22−1
0 .6955−0 . 6244
=0. 6955+ =0 . 6525
3
( 1) ( 0) Ι ( 0) (4 , 0 . 25)−Ι ( 0)(2 , 0 . 5)
Ι (4 , 0 . 25)=Ι ( 4 , 0 . 25)+
And 22 −1
0 . 6606−0. 6955
=0. 6606+ =0 . 6490
3
( 2) ( 1) Ι (1 )(4 , 0 .25 )−Ι (1) (2 , 0. 5 )
Ι (4 , 0 . 25)=Ι ( 4 , 0 .25 )+
Second extrapolated value is 2 4 −1
0 .6490−0 . 6525
=0. 6490+ =0 . 6488
15
Results are summarized below in a Table:
N H O(h )
2
O(h )
4
O(h )
6
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;
( )
❑ b f 2( x )
∬ f ( x , y ) dA=∫ ∫ f ( x , y ) dy dx
R a f 1( x )
or
∫( ∫ )
❑ d g2 ( y )
∬ f ( x , y ) dA= f ( x , y ) dx dy
R c g1 ( y )
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 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 first form the interval at x=x r is
f 2 ( x r ) −f 1 ( x r )
k r=
n
Example 8.6
1.0 1.6 2
2y
Using Simpson’s rule with 2-subintervals evaluate the double integral∫ ∫ dydx
0.6 1.0 x+ y
The integral is over the rectangular region bounded by0.6 ≤ x ≤ 1.0∧1.0 ≤ y ≤1.6 .
Using 2-subintervals in each direction, we have
L7 - 8
Summer 2023-2024
1.0−0.6 1.6−1.0
h= =0.2∧k = =0.3
2 2
2
2y
The integrand is f ( x , y )= .
x+ y
Integration using fixed values of x=0.6 ,0.8∧1.0 are as follows:
1.6
0.3
I ( 0.6 )=∫ f ( 0.6 , y ) dy= [f ( 0.6 , 1.0 ) +4 f ( 0.6 , 1.3 ) + f ( 0.6 ,1.6 ) ]
1.0 3
0.3
¿
3
[ 1.25+ 4 ( 1.779 ) +2.327 ]=1.0693
1.6
0.3
I ( 0.8 )=∫ f ( 0.8 , y ) dy= [f ( 0.8 ,1.0 )+ 4 f ( 0.8 ,1.3 )+ f ( 0.8 , 1.6 ) ]
1.0 3
0.3
¿
3
[ 1.111+4 ( 1.610 ) +2.133 ]=0.9684
1.6
0.3
I ( 1.0 )=∫ f (1.0 , y ) dy= [f ( 1.0 , 1.0 ) +4 f ( 1.0 , 1.3 ) +f ( 1.0 , 1.6 ) ]
1.0 3
0.3
¿
3
[ 1.0+ 4 ( 1.47 ) +1.969 ]=0.8849
Finally combining the integral for x , we have
1.0 1.6
0.2
I(Simp)=∫ ∫ f ( x , y ) dydx ≈ [ I ( 0.6 )+ 4 I ( 0.8 ) + I ( 1.0 )]
0.6 1.0 3
0.2
¿
3
[ 1.0693+ 4 ( 0.9684 )+ 0.8849 ]=0.38852
[MATLAB result is I = 0.38846]
Example 8.7 Using Simpson’s rule with 2-subinervals evaluate the double integral
L7 - 9
Summer 2023-2024
2
1.4 1+ x
∫ ∫ ( 1+ xy ) dydx
1.0 x
Solution: The region of integration is1.0 ≤ x ≤ 1.4 , x ≤ y ≤ 1+ x 2
The integrand is f ( x , y )=1+ xy
1.4−1.0
With 2 equal subintervals for x, the interval length is h= =0.2. The end points of
2
subintervals are 1 ,1.2∧1.4 .
The interval length for y is variable depending on the values of x.
2
(1+1 )−1
For x=1 , k 1 = =0.5∧ y r =1 ,1.5 , 2.0
2
The integral over y is
0.5
I ( 1 , 0.5 )=
3
[ f ( 1 ,1 )+ 4 f ( 1 , 1.5 ) + f ( 1 , 2.0 ) ]
0.5
¿
3
[ 2+ 4 ( 2.5 ) +3 ]=2.5
2
(1+1.2 )−1.2
For x=1.2 , k 2 = =0.62∧ y r =1.2, 1.82 , 2.44
2
0.62
The integral over y is I ( 1.2 , 0.62 )=
3
[ f (1.2 , 1.2 ) +4 f ( 1.2 ,1.82 ) + f ( 1.2, 2.44 ) ]
0.5
¿
3
[ 2.44 +4 (3.184 ) +3.928 ]=3.9482
2
(1+1.4 )−1.4
For x=1.4 , k 3= =0.78∧ y r =1.4 , 2.18 , 2.96
2
0.78
The integral over y is I ( 1.4 ,0.78 )=
3
[ f ( 1.4 , 1.4 ) + 4 f ( 1.4 ,2.18 )+ f ( 1.4 , 2.96 ) ]
0.78
¿
3
[ 2.96+ 4 ( 4.052 )+ 5.144 ]= 6.3211
∫ ∫ ( 1+ xy ) dydx ≈ 0.2
3
[ 2.5+ 4 ( 3.9482 ) +6.3211 ]=1.64092
1.0 x
[I ( 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).
sin (xy )
For example f ( x , y )= may be typed as
x2 + y2
ff=@(x,y) sin(x*y)./(x.^2+y.^2))
This will be treated as ff(x,y).
1
Example 8.6: Evaluate ∫ e sin x dx numerically to 7 digits using MATLAB command.
x 2
fun = @(x)exp(x).*sin(x.^2)
int7 =0.662701
2 √x
1
Example 8.8: Evaluate ∫ ∫ dy dx numerically using MATLAB command.
0 −x √x 2
+y
2
fun2 = @(x,y)1./sqrt(x.^2+y.^2)
ymin = @(x)-x
L7 - 11
Summer 2023-2024
ymax = @(x)sqrt(x)
int22 =3.811758
dV
Example 8.9: Evaluate ∭ 2 , where R is the region bounded by the coordinate
R ( 1+ x+ y+ z )
planes and the plane x + y + z=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
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 v . If the mass of the car is m=2000 kg, determine the time ∆ t it takes for
the car to accelerate from 1m/s to 6 m/s . Use the trapezoidal rule for integration.
Hint:
L7 - 12
Summer 2023-2024
6s
∆ t=m∫ (v / p)dv
1s
which can be derived from Newton’s law F=m(dv / dt) and the definition of power
P=Fv .
5. The car gives the velocity v 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
(a) ∫ f ( x ) dx ≈ af ( 0 ) +bf ( h )+ cf (2 h)
0
h
(b) ∫ f ( x ) dx ≈ af
0
( h3 )+ bf (h)
L7 - 13
Summer 2023-2024
( )
1 1.8 2 1 2 π
x ln (1+ x)
(a) ∫ √1+2 x dx 3
(b) ∫ exp
2
dx (c) ∫ 1+ x 2 dx (d) ∫ 5+sin x
4 cos x
dx
0 1 0 0
9. Using Simpson’s rule with two subintervals evaluate the following double integrals
and also write MATLAB code to evaluate.
1.5 1 2.0 1.5
1 0 1.4 1.0
2 1 0.8 2
0.5 1 1 2
sin(xy )
(e) ∫ ∫ dydx (f) ∫ ∫ 2 exp( y / x)dydx
0 0 1+ xy 0 1
(a) ∫ ∫ ∫ ¿ ¿ ¿¿
0 3 −1
2 3 1
L7 - 14