5.2 Numerical Integration: I FXD
5.2 Numerical Integration: I FXD
page 5-16
I=
a f (x )dx
(5.2-1)
where f (x) may be (1) a known function with or without exact integral or (2) a set of discrete
data.
When a function to be integrated does not have exact integral or is only known at a set of
discrete data, an approximating function is fit to the available data, or to several subsets of
the data (a process called composite integration), and the resulting polynomial is then
integrated.
I=
a f (x )dx a pn (x )dx
(5.2-2)
f ( x ) pn ( x ) = a0 + a1x + a2 x 2 + . . . + an x n
Eq.(5.2-2) becomes
a ( a0 + a1x + a2 x
b
+ . . . + an x n dx
(5.2-3)
b
a
a
a
I a0 x + 1 x 2 + 2 x 3 + . . . + n x n +1
n +1
2
3
a
(5.2-4)
zar97/09/03
page 5-17
Use a first order and second-order Newtons interpolating polynomial to fit the
set of data given below and estimate the integral of the function using the
resulting interpolation polynomial in the limit of 3.2 x 5.0.
x
f(x)
2.0
0.5
5.0
0.2
8.0
0.125
Solution:
8.0
I 2.0 pn ( x )dx
p1 ( x ) = 0.375 0.0625x
I
8.0
2.0
(0.375 0.0625x ) dx
t = 17.2 %
p2 ( x ) = 0.825 01875
.
x + 0.0125x 2
8.0
t = 2.9 %
zar97/09/03
page 5-18
I. Trapezoidal Rule: fitting a first order polynomial to two discrete data points.
Consider the Newton interpolating polynomial with a = x0 and b = x1 ,
p1 ( x ) = f ( x0 ) +
IT
a [ f ( x0 ) +
I T (b a )
f (b) f (a )
(x a )
ba
f (b) f (a )
( x a )] dx
ba
f (a ) + f (b)
2
or
(5.2-5)
h
[ f a + fb ]
2
h = b a and
Et =
f (a ) = f a , f (b) = f b
1
f ''( )h 3
12
(5.2-6)
h=
ba
n
(5.2-7)
zar97/09/03
page 5-19
b1
b2
bn
n 1
p1 ( x )dx
(5.2-8)
which yields
IT h
f ( x1 ) + f ( x0 )
f ( x2 ) + f ( x1 )
f ( xn ) + f ( xn 1 )
+h
+ . . . +h
2
2
2
(5.2-9)
IT
h
( f 0 + 2 f1 + 2 f 2 + . . . + 2 f n 1 + f n ) or
2
n 1
h
f 0 + 2 f ( xi ) + f n
2
i =1
(5.2-10)
Evaluate the integral of the following function using Trapezoidal rule from x
= 2.0 to 8.0 using (i) single interval and (ii) three subintervals.
f ( x) =
Solution:
(i)
At
x = 2.0,
x = 8.0,
1
x
f(2.0) = 0.5
f(8.0) = 0.125
Using eq.(5.2-6),
IT =
(6.0)
[0.5 + 0125
. ] = 1870
.
2
IT =
( 2.0)
[0.5 + 2(0.25) + 2( 016667
.
) + 0.125] = 1.45834
2
(ii)
Using eq.(5.2-10),
zar97/09/03
page 5-20
II. Simpsons 1/3 Rule: Fitting a second-order polynomial to a set of three discrete data
points. Consider the 2nd-order Lagrange interpolating polynomial with a = x0 and b = x2 ,
the integral becomes
IS
x 2
x x0 x x2
x x0 x x1
x x1 x x2
f ( x0 ) +
f ( x1 ) +
f ( x2 ) dx
x1 x0 x1 x2
x2 x0 x2 x1
0 x1 x0 x2
x0 x
IS
h
[ f ( x0 ) + 4 f ( x1 ) + f ( x2 )]
3
or
ba
, the resulting expression is
2
h
[ f a + 4 fb + f 2 ]
3
(5.2-11)
1 4
Et =
f ( )h5
90
or
(b a ) 5 4
f ()
2880
(5.2-12)
zar97/09/03
page 5-21
Composite Simpsons 1/3 rule: Similar to the trapezoidal rule, the Simpsons 1/3 rule
may be improved by applying the rule to equally spaced subintervals. The integral may be
written as
IS =
xn
b2
x4
bn
. . . + x
n2
p2 ( x )dx
(5.2-13)
IS =
h
[ f ( x0 ) + 4 f ( x1 ) + 2 f ( x2 ) + . . . + 2 f ( xn 2 ) + 4 f ( xn 1 ) + f ( xn ) ]
3
where h =
(5.2-14)
ba
and xk = a + kh; k = 0,1,..., n . Note that the values of the function at the
n
interior points are weighted by 2 and 4. The total weighted function is scales by h/3.
Evaluate the integral of the following function using Simpsons 1/3 rule from x
= 2.0 to 8.0 using (i) single application and (ii) multiple application with h = 1.2.
Example 5.2-2:
f ( x) =
Solution:
(i)
At
x = 2.0,
x = 5.0,
x = 8.0,
1
x
f(2.0) = 0.5
f(5.0) = 0.2
f(8.0) = 0.125
Using eq.(5.2-11),
IS =
( 3.0)
[0.5 + 4(0.2) + 0125
. ] = 14250
.
3
(10
. )
[ 0.5 + 4( 0.33333) + 2( 0.25) + 4( 0.2) + 2(016667
.
) + 4( 014286
.
) + 0125
. ] = 1.3877
3
zar97/09/03
page 5-22
For f(x) = e , estimate the integral of the function for the limit -1 x 1. Use
(a) Trapezoidal rule and (b) Simpsons 1/3 rule. Use a step size h = 0.5 for
both methods.
x
Solution:
IS =
ex dx
for h = 0.5
(0.5) 1.0
[ e + 2 e0.5 + 2 e0 + 2 e0.5 + e1.0 ]
2
(0.5)
IT
( 0.5) 1
e + 4 e0.5 + 2 e0 + 4 e0.5 + e1
3
( 0.5)
IS
zar97/09/03
page 5-23
III. Simpsons 3/8 Rule: Fit a third-order polynomial to a set of four discrete data points
and use it to approximate the integrand.
I =
f ( x) dx p3 ( x) dx
(5.2-15)
ba
,
3
IS
3h
h
[ f ( x0 ) + 3 f ( x1 ) + 3 f ( x2 ) + f ( x 3 )] or
[ f 0 + 3 f1 + 3 f 2 + f 3 ]
8
3
(5.2-16)
Et =
3 4
f ( )h 5
80
or
(b a ) 5 4
f ( )
6480
(5.2-17)
1. Error estimates for the Simpsons 3/8 rule is smaller than that of the
simpsons 1/3 rule.
2. 1/3 rule usually prefered since it attains the same order of accuracy while
using only three points on the curve.
3. 3/8 rule has an odd numder of segments as compared to an even number
of segments for the 1/3 rule.
zar97/09/03
page 5-24
Note: Suppose you wish to to divide the interval into an odd number of segments, you may
employ
(1) a composite trapezoidal rule. However, it is not prefered due to a large TErs.
(2) Simpsons 3/8 rule.
(3) Simpsons 1/3 rule over an even number of segments and the 3/8 rule to the
remaining odd number of segments. This is the most prefered approach.
Composite Simpsons 1/3 and 3/8 rule: use to estimate the integral having an odd
number of inetrvals. The integral may be illustrate as
zar97/09/03
page 5-25
Evaluate the integral of the following function from x = 2.0 to 8.0 using (i) a
single application Simpsons 3/8 rule and (ii) a multiple application 1/3 and 3/8 rule with n =
5.
Example 5.2-2:
f ( x) =
h=
Solution:
1
x
b a 8.0 2.0
=
= 2.0
3
3
(i)
2.0
0.5
x
f(x)
4.0
0.25
6.0
0.16667
8.0
0.125
Using eq.(5.2-16),
I S 3/ 8 =
3(2.0)
[0.5 + 3(0.25) + 3(016667
.
) + 0125
. ] = 14063
.
8
2.0
0.5
3.2
0.3125
4.4
0.22727
5.6
0.17857
6.8
0.14706
8.0
0.125
(12
. )
[0.5 + 4(0.3125) + (0.22727)] = 0.79091
3
3(12
. )
=
[0.22727 + 3(017857
.
) + 3( 014706
.
) + 0125
. ] = 0.59812
8
I S1/ 3 =
I S 3/ 8
8.0 2.0
= 12
.
5
zar97/09/03
page 5-26
For f(x) = e , estimate the integral of the function for the limit -1 x 1. Use
(a) Simpsons 3/8 rule and (b) Simpsons 1/3 rule and 3/8 rule.
x
Solution:
IS =
(a) 3/8 rule,
ex dx
h=
for
1 ( 1) 2
= 3
3
1
3(2 / 3) 1.0
1
+ 3e 3 + 3e 3 + e1.0 ]
[e
8
3( 2 / 3)
I S 3/ 8
h=
b a 1 ( 1)
=
= 0.4 and using eq.(5.2-14) and (5.2-16),
n
5
(0.4) 1
e + 4 e 0 . 6 + e 0 . 2
3
(0.4)
I S1/ 3
3(0.4) 0.2
e + 3e 0.2 + 3e 0.6 + e1.0
8
3(0.4)
.
) + 3(182212
.
) + (2.71828)]
[(0.81873) + 3(122140
8
.
190013
I S1/ 3
I S = I S 1/ 3 + I S 3/ 8 = 0.45091 + 190013
.
= 2.3510
zar97/09/03
page 5-27
f ( x) = 3x5 + x4 + 2 x3 3x2 + x + 10
Estimate the error of the integral in the limit of 1 x 3 for each of the follwing methods (a)
Trapezoidal rule (b) Simpsons 1/3 rule and (c) Simpsons 3/8 rule.
Solution:
1
f ''()h 3
12
''
f max ( x = 3) = 1482
Et =
or
(b a ) 3
f ''( )
12
(b a ) 5 4
f ()
2880
( 3 1) 3
Et =
( 1482) = 988
12
(b) Simpsons 1/3 rule,
1 4
Et =
f ( )h5
90
4
f max ( x = 3) = 1056
Et =
or
( 3 1)5
( 1056) = 11.73
2880
zar97/09/03
page 5-28
For f(x) = e , estimate the error of the integral for the limit -1 x 1. Use (a)
Simpsons 3/8 rule and (b) Simpsons 1/3 rule and 3/8 rule.
x
Solution:
f '( x) = e x
f ''( x) = e x
f 3 ( x) = e x
f 4 ( x) = e x
3 4
Et =
f ( ) h5
or
80
4
f max
( x = 1) = 2.7183
Et =
(b a ) 5 4
f ( )
6480
[1 ( 1)]5
(2.7183) = 0.0134
6480
(b a )5 4
4
f ( )
f max
( x = 0.2) = 0.81873.
2880
[ 0.2 ( 1)]5
Et =
(0.81873) = 0.000093
2880
Et =
(b a )5 4
4
Et =
f ( )
f max
( x = 1) = 2.7183.
6480
[1 ( 0.2)]5
Et =
(2.7183) = 0.00104
6480
Total error estimate Et = 0.00093 + 0.00104 = 0.00114.
zar97/09/03
page 5-29
IT
h
( f 0 + 2 f1 + 2 f 2 + . . . + 2 f n 1 + f n ) or
2
where h =
n 1
h
f 0 + 2 f ( xi ) + f n (5.2-10)
2
i =1
ba
, x0 = a and xn = b. The error formula is given by
n
ET =
(b a )h 2
f ' '( )
12
(5.3-1)
ET =
h2
(b a )h 4 4
f ( )
[ f '(b) f '(a )] +
12
720
(5.3-2)
Eq.(5.2-10) can be used to estimate the integral of the function in the following way,
Start:
h0 = b a
h1 = ho / 2
h2 = h1 / 2
h 3 = h2 / 2
M
hk =
hk 1 (b a ) (b a )
=
=
2
n
2k
(5.3-3)
zar97/09/03
page 5-30
h
(b a )
[ f (a ) + f (b)] = 0 [ f a + f b ]
2
2
h
1 h0
T1,0 = 1 [ f (a ) + 2 f (a + h1 ) + f (b)] =
[ f a + f b ] + h1 f (a + h1 )
2
2 2
1
= T0 ,0 + h1 f (a + h1 )
2
h
T2 ,0 = 2 [ f (a ) + 2 f (a + h2 ) + 2 f (a + 2h2 ) + 2 f (a + 3h2 ) + f (b)]
2
1 h1
=
[ f a + 2 f (a + 2h2 ) + f b ] + h2 [ f (a + h2 ) + f (a + 3h2 )]
2 2
1
= T1,0 + h1 [ f (a + h2 ) + f (a + 3h2 )]
2
M
T0 ,0 =
(5.3-4)
Tk ,0 =
2
1
Tk 1,0 + hk f (a + {2i 1}hk )
2
i =1
for
k = 1,2 ,...
(5.3-5)
which is an improve formula based on the value of previous integral. However, the above
formula gives a very slow improvement or convergence. It may be illustrated through the
following example
Using improved formula
Example 5.3-1:
Solution:
zar97/09/03
page 5-31
Now we may introduce Romberg integration to make the convergence faster. It may be
represented as
I(1,1)
I(2,1)
I(3,1)
:
I(j,1)
I(2,2)
I(3,2)
:
I(j,2)
I(3,3)
:
I(j,3)
...
(5.3-6)
I(j,k)
I j ,k =
4 k 1 I j + 1, k 1 I j , k 1
(5.3-7)
4 k 1 1
Evaluate the integral of the following function using Trapezoidal rule from x
= 2.0 to 8.0 using (i) single interval and (ii) three subintervals.
1
f ( x) =
x
Solution:
# Intervals
I(j,1)
I(j,2)
I(j,3)
I(j,4)
1
2
4
8
6.0
3.0
1.5
0.75
1.8750
1.5375
1.42809
1.39713
1.42500
1.39162
1.38681
1.38939
1.38649
1.38644
zar97/09/03
page 5-32
For f(x) = e , using Romberg integration estimate the integral of the functrion
in the interval [-1,1]. Use up to 4 intervals.
Solution:
h
IT [ f a + fb ]
2
h
I T ( f 0 + 2 f 1 + 2 f 2 + . . . + 2 f n 1 + f n )
2
# Intervals
I(j,1)
I(j,2)
I(j,3)
I(j,4)
zar97/09/03
page 5-33
5.3.2 Gauss Quadrature. Recall that in the Newton-Cotes Integration Formulas, the
formulas are based on the fixed base points.
(b a )
[ f (a ) + f (b)]
2
(5.3-8)
Now, suppose such a constraint of fixed base points is removed, we may get a better
location of the base points which minimizes the error as shown below.
Gauss quadrature is a technique employed to implement that strategy. The approach of our
interest is called Gauss-Legendre formulas.
I c0 f (a ) + c1 f (b)
(5.3-9)
where cs are the unknown constants. There are two situations for which eq.(5.3-8) and,
therefore eq.(5.309) yield the exact integral: y = f(x) = 1 and y = f(x) = x.
zar97/09/03
f(x)
page 5-34
f(x)
(a)
(b)
c0 f (a ) + c1 f (b) =
(b a )/ 2
1dx
c0 f (a ) + c1 f (b) = b a
(a)
(b a )/ 2
and
(b)
ba
ba
f (a ) +
f (b)
2
2
(5.3-10)
zar97/09/03
page 5-35
The two-point
I c0 f ( x0 ) + c1 f ( x1 )
(5.3-9)
The objective in Gauss quadrature is to determine the unknown coefficients cs and the
function arguments xs of the above equation.
y=1
y=x
y = x2
y = x3
c0 f ( x0 ) + c1 f ( x1 ) =
c0 f ( x0 ) + c1 f ( x1 ) =
1dx = 2
(a)
xdx = 0
(b)
1
1
1
zar97/09/03
page 5-36
I f (
1
)
3
+ f(
1
)
3
(h3)
(5.3-10)
1
3
and x =
1
3
that
gives an estimate of integral with a third-order-accurate. The limit of the integral x0 = a and
xn = b can be transformed into x0 = -1 and xn = 1 by performing a change of variable using
linear transformation in the following way,
x = a0 + a1 t
(5.3-11)
a = a0 a1
(5.3-11a)
b = a0 + a1
(5.3-11b)
a0 =
b+a
2
and
a1 =
ba
2
(5.3-12)
x=
(b + a ) + (b a )t
2
(5.3-13)
dx =
ba
dt
2
(5.3-14)
zar97/09/03
page 5-37
I c0 f 0 + c1 f1 + c2 f 2 + . . . + cn 1 f n 1
(5.3-15)
where n is the number of points. The values of cs and xs for up to four point formulas
are given in table 5.3-1 below.
Table 5.3-1: Gauss quadrature parameters
Points
Weighting Factors
Function arguments
cs
xs
c0 = 1.0
c1 = 1.0
x0 = 1 3
x1 = 1 3
c0 = 5 9
c1 = 8 9
c2 = 5 9
x0 = 0.6
x1 = 0.0
x2 = 0.6
c0 = 0.347854845
c1 = 0.652145155
c2 = 0.347854845
c3 = 0.652145155
x0 = -0.861136312
x1 = -0.339981044
x2 = 0.339981044
x3 = 0.861136312
Error
Order
ba 1
b a n 1
I = f (x )dx
f (t )dt =
ci f (xi )
2 1
2 i =0
a
b
(5.3-16)
zar97/09/03
page 5-38
Evaluate the integral of the following function using the two- and three-point
Gauss Quadrature from x = 2.0 to 8.0.
f ( x) =
1
x
Solution:
Using eq.(5.3-13), x = 3t + 5
and thus,
f (t ) =
1
3t + 5
Two-point formula,
(8 2 ) 1
I
. ) f (
f (t )dt = (3.0) (10
2 1
I (3.0)[
1
3( 1
3) + 5
1
)+
3
(10
. )f (
1
)
3
1
] = 1.36364
3(1 3 ) + 5
Three-point formula,
5
8
(8 2 ) 1
5
I
f (t )dt = (3.0) f ( 0.6 ) + f (0) + f ( 0.6 )
9
9
2 1
5
8 1 5
1
1
I (3.0)
+
= 1.38367
+
9 3( 0.6 ) + 5 9 3(0) + 5 9 3( 0.6 ) + 5
zar97/09/03
page 5-39
Solution:
zar97/09/03
page 5-40
5.4 Open Integration Formulas. The open integration formulas are used when the
integral limits extend beyond the range of the data.
I. Two-segments formula:
zar97/09/03
page 5-41
Segment
n
Point
(n - 1)
I (b a ) f ( x1 )
(b a )
f ( x1 ) + f ( x2 )]
2
(b a )
2 f ( x1 ) f ( x2 ) + 2 f ( x3 )]
3
(b a ) 11 f ( x1 ) + f ( x2 ) + f ( x3 ) + 11 f ( x4 )
4
6
95 5
h f
144
(b a ) 11 f ( x1 ) 14 f ( x2 ) + 26 f ( x3 ) 14 f ( x4 ) + 11 f ( x5 )
5
4
41 7
h f
140
Remark:
Formula
Truncation
Error
1 3
h f ' ' ( )
3
3 3
h f ' ' ( )
4
14 5
h f
45
(4)
(4)
( )
( 6)
( )
( )