Numerical Integration: Definite Integral, Newton-
Cote’s Quadrature formula, Trapezoidal Rule,
Simpson’s one-third rule, simpson’s three-eight rule,
Errors in quadrature formulae, Romberg’s Algorithm,
Gaussian Quadrature formula.
Numerical Differentiation and Integration
Differentiation and Integration
y f ( xi + x) − f ( xi )
=
x x
dy f ( xi + x) − f ( xi )
= x lim 0
dx x
b
I = f ( x)dx
a
What is Integration?
b
Integration f ( x )dx
a
f(x)
y
The process of measuring the
area under a curve.
b
I = f ( x )dx
a
Where:
f(x) is the integrand
a= lower limit of integration
a b x
b= upper limit of integration
5
Integration
Indefinite Integrals Definite Integrals
2 1 2 1
x x 1
x dx = 2 + c 0 xdx = 2 =
2
0
Indefinite Integrals of a Definite Integrals are
function are functions numbers.
that differ from each
other by a constant.
8
Fundamental Theorem of Calculus
If f is continuous on an interval [a,b],
F is antiderivative of f (i.e., F ' (x) = f(x) )
b
a
f(x)dx = F(b) − F(a)
x2
There is no antiderivative for : e
b
No closed form solution for : e dx x2
a
The Area Under the Curve
One interpretation of the definite integral is:
Integral = area under the curve
f(x)
b
Area = f(x)dx
a
a b
Noncomputer Methods for Differentiation and Integration
• The function to be differentiated or integrated will typically be in one of the
following three forms:
• A simple continuous function such as polynomial, an exponential, or a trigonometric
function.
• A complicated continuous function that is difficult or impossible to differentiate or
integrate directly.
• A tabulated function where values of x and f(x) are given at a number of discrete
points, as is often the case with experimental or field data.
Figure
Newton-Cotes Integration Formulas
• The Newton-Cotes formulas are the most common
numerical integration schemes.
• They are based on the strategy of replacing a
complicated function or tabulated data with an
approximating function that is easy to integrate:
b b
I = f ( x)dx f n ( x)dx
a a
f n ( x) = a0 + a1 x + + an −1 x n −1 + an x n
Figure
Figure
The Trapezoidal Rule
• The Trapezoidal rule is the first of the Newton-Cotes closed
integration formulas, corresponding to the case where the polynomial
is first order: b b
I = f ( x)dx f1 ( x)dx
a a
• The area under this first order polynomial is an estimate of the integral
of f(x) between the limits of a and b:
f (a) + f (b)
I = (b − a) Trapezoidal rule
2
Trapezoidal Rule
• Instead of calculating
approximation rectangles
we will use trapezoids
•
• More accuracy a
x
xi b
• Area of a trapezoid
b2 • Which dimension is the h?
1 • Which is the b1 and the b2
A = ( b1 + b2 ) h h
2
b1
Trapezoidal Rule
• Trapezoidal rule
approximates the integral f(xi-1) f(xi)
dx
b
dx
f ( x)dx f ( x0 ) + 2 f ( x1 ) + 2 f ( x2 ) + ...2 f ( xn −1 ) + f ( xn )
a
2
b−a
where dx =
n
Example 21.1 Single Application of the Trapezoidal Rule
f(x) = 0.2 +25x – 200x2 + 675x3 – 900x4 + 400x5
Integrate f(x) from a=0 to b=0.8
b = 0.8
True integral value : I = f ( x )dx = 1.64053
a =0
Solution: f(a)=f(0) = 0.2 and f(b)=f(0.8) = 0.232
f (a ) + f (b)
Trapezoida l Rule : I = ( b − a )
2
0.2 + 0.232
= 0.8 = 0.1728
2
which represents an error of :
E t = 1.64053 − 0.1728 = 1.46773 t = 89.5%
The Multiple-Application Trapezoidal Rule
• The accuracy can be improved by dividing the
interval from a to b into a number of segments
and applying the method to each segment.
• The areas of individual segments are added to
yield the integral for the entire interval.
b−a
h= n = # of seg. a = x0 b = xn
n
x1 x2 xn
I= f ( x)dx + f ( x)dx + + f ( x)dx
x0 x1 xn−1
Using the trapezoidal rule, we get:
f ( x0 ) + f ( x1 ) f ( x1 ) + f ( x 2 ) f ( x n−1 ) + f ( x n )
I =h +h ++ h
2 2 2
b−a n −1
I= f ( x 0 ) + f ( x n ) + 2 f ( x i )
2n i =1 28
The Error Estimate for
The Multiple-Application Trapezoidal Rule
• Error estimate for one segment is given as:
(b − a)3
Et = f ( )
12
• An error for multiple-application trapezoidal rule can be obtained by summing
the individual errors for each segment:
h3 n "
Ea = f (i ) since f " (i ) nf "
12 i =1
h3 "
Ea = nf where f " is the mean of the second derivative over the interval
12
(b − a) (b − a)3 " (b − a) 2 "
Since h = Ea = 2
f = h f = O(h 2
)
n 12n 12
Thus, if the number of segments is doubled,
the truncation error will be quartered.
Using Data
• Given table of data, use trapezoidal rule to determine area
under the curve
x 2.00 2.10 2.20 2.30 2.40 2.50 2.60
y 4.32 4.57 5.14 5.78 6.84 6.62 6.51
▪ dx = ?
b
dx
f ( x)dx f ( x0 ) + 2 f ( x1 ) + 2 f ( x2 ) + ...2 f ( xn −1 ) + f ( xn )
a
2
Using Data
• Given table of data, use Simpson's rule to determine area
under the curve
x 2.00 2.10 2.20 2.30 2.40 2.50 2.60
y 4.32 4.57 5.14 5.78 6.84 6.62 6.51
b
dx
a
f ( x)dx [ f ( x0 ) + 4 f ( x1 ) + 2 f ( x2 ) + 4 f ( x3 ) + 2 f ( x4 )
3
+ ... + 2 f ( xn −2 ) + 4 f ( xn −1 ) + f ( xn )]
Estimating the Error
For Trapezoid Method
How many equally spaced intervals are
needed to compute 0
sin( x)dx
to 5 decimal digit accuracy?
32
Example
1
sin( x )dx, find h so that error 10−5
2
0
b−a 2
Error h max f ' ' ( x )
12 x[ a ,b]
b = ; a = 0; f ' ( x ) = cos( x ); f ' ' ( x ) = − sin( x )
2 1
f ' ' ( x ) 1 Error h 10−5
12 2
2 6
h 10−5 h 0.00437
(b − a )
n = = 719 intervals
h 0.00437 33
Simpson’s Rules
• More accurate estimate of an integral is obtained if
a high-order polynomial is used to connect the
points. These formulas are called Simpson’s rules.
Simpson’s 1/3 Rule: results when a 2nd order
Lagrange interpolating polynomial is used for f(x)
a=x0 x1 b=x2
b b
I = f ( x)dx f 2 ( x)dx where f 2 ( x ) is a second - order polynomial.
a a
Using a = x0 b = x2
( x − x1 )( x − x2 ) ( x − x0 )( x − x2 ) ( x − x0 )( x − x1 )
x2
I = f ( x0 ) + f ( x1 ) + f ( x2 )dx
x0
( x0 − x1 )( x0 − x 2 ) ( x1 − x0 )( x1 − x 2 ) ( x 2 − x0 )( x 2 − x1 )
after integratio n and algebraic manipulation, the following formula results :
b−a
I
h
f ( x0 ) + 4 f ( x1 ) + f ( x2 ) h= SIMPSON' S 1/3 RULE
3 2
Simpson's Rule
• As before, we divide
the interval into n parts
▪ n must be even
• Instead of straight lines we •
a xi b
draw parabolas through
each group of three consecutive points
▪ This approximates the original curve for finding
definite integral – formula shown below
b
dx
a
f ( x)dx
3
[ f ( x0 ) + 4 f ( x1 ) + 2 f ( x2 ) + 4 f ( x3 ) + 2 f ( x4 )
+ ... + 2 f ( xn −2 ) + 4 f ( xn −1 ) + f ( xn )]
The Multiple-Application Simpson’s 1/3 Rule
• Just as the trapezoidal rule, Simpson’s rule can be improved by dividing the integration
interval into a number of segments of equal width.
• However, it is limited to cases where values are equispaced, there are an even number of
segments and odd number of points.
b−a
h= n = # of seg. a = x0 b = xn
n
x2 x4 xn
I= f ( x)dx + f ( x)dx + + f n −2 ( x)dx
0 2
x0 x2 xn−2
h
I= ( f ( x0 ) + 4 f ( x1 ) + f ( x2 ) )
3
h
+ ( f ( x2 ) + 4 f ( x3 ) + f ( x4 ) ) +
3
h
+ ( f ( xn − 2 ) + 4 f ( xn −1 ) + f ( xn ) )
3
h n −1 n−2
I = f ( x0 ) + 4 f ( xi ) + 2 f ( x j ) + f ( xn )
3 i =1, 3, 5... j = 2 , 4 , 6...
Multiple Segment Simpson’s 1/3rd Rule
b h
f ( x )dx = 3 f ( x0 ) + 4 f ( x1 ) + f ( x3 ) + ... + f ( xn −1 ) + ...
a
... + 2 f ( x2 ) + f ( x4 ) + ... + f ( xn −2 ) + f ( xn )}]
− −
h n 1 n 2
= f ( x 0 ) + 4 f ( xi ) + 2 f ( xi ) + f ( x n )
3 i =1 i =2
i = odd i = even
b−a n −1 n − 2
= f ( x 0 ) + 4 f ( xi ) + 2 f ( xi ) + f ( x n )
3n i =1 i =2
i = odd i = even
Example
Use 4-segment Simpson’s 1/3rd Rule to approximate the distance
covered by a rocket from t= 8 to t=30 as given by
30
140000
x = 2000 ln − 9.8t dt
8 140000 − 2100t
a) Use four segment Simpson’s 1/3rd Rule to find the approximate
value of x.
b) Find the true error, E t for part (a).
c) Find the absolute relative true error, a for part (a).
Solution
a) Using n segment Simpson’s 1/3rd Rule,
30 − 8
h= = 5.5
4
So
f (t 0 ) = f (8)
f (t1 ) = f (8 + 5.5) = f (13.5)
f (t 2 ) = f (13.5 + 5.5) = f (19)
f (t 3 ) = f (19 + 5.5) = f (24.5)
f (t4 ) = f (30)
Solution (cont.)
b−a n −1 n − 2
x= f (t 0 ) + 4 f (t i ) + 2 f (t i ) + f (t n )
3n i =1 i =2
i = odd i = even
30 − 8 3 2
= f (8) + 4 f (t i ) + 2 f (t i ) + f (30)
3(4) i =1 i =2
i = odd i = even
22
= f (8) + 4 f (t1 ) + 4 f (t 3 ) + 2 f (t 2 ) + f (30)
12
Solution (cont.)
cont.
11
= f (8) + 4 f (13.5) + 4 f (24.5) + 2 f (19) + f (30)
6
11
= 177.2667 + 4(320.2469) + 4(676.0501) + 2(484.7455) + 901.6740
6
= 11061.64 m
Solution (cont.)
b) In this case, the true error is
Et = 11061.34 − 11061.64 = −0.30 m
c) The absolute relative true error
11061.34 − 11061.64
t = 100%
11061.34
= 0.0027%
Simpson’s 3/8 Rule
Simpson’s 1/3 and 3/8 rules can be
Fit a 3rd
order Lagrange interpolating applied in tandem to handle
polynomial to four points and integrate multiple applications with odd
number of intervals
b b
I = f ( x)dx f 3 ( x)dx
a a
I f ( x0 ) + 3 f ( x1 ) + 3 f ( x2 ) + f ( x3 )
3h
8
(b − a )
h =
3
f ( x0 ) + 3 f ( x1 ) + 3 f ( x2 ) + f ( x3 )
I (b − a )
8 53
Romberg’s integration
• It is an extrapolation technique which allows us to take a
sequence approximate solutions to an integral and
calculate a better approximation
• This technique assumes that the function we are
integrating is sufficiently differentiable
Romberg’s Formula for Composite Trapezoidal Rule
Romberg’s Formula for Composite Simpson’s 1/3 Rule