0% found this document useful (0 votes)
31 views72 pages

Module 5 Numerical Differentiation and Integration

This document discusses numerical differentiation and integration methods, focusing on finite divided differences to estimate derivatives for complex functions. It explains various techniques including forward, backward, and centered differences, and emphasizes the accuracy of centered differences. Additionally, it provides examples and derivations for higher-order derivatives and high-accuracy differentiation formulas.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views72 pages

Module 5 Numerical Differentiation and Integration

This document discusses numerical differentiation and integration methods, focusing on finite divided differences to estimate derivatives for complex functions. It explains various techniques including forward, backward, and centered differences, and emphasizes the accuracy of centered differences. Additionally, it provides examples and derivations for higher-order derivatives and high-accuracy differentiation formulas.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 72

NUMERICAL METHODS

MA 311
MODULE 5: NUMERICAL
DIFFERENTIATION AND
INTEGRATION
Musango Lungu, D Eng

School of Mines and Mineral Sciences


Chemical engineering department

2023 @ copyright M.L.


NUMERICAL DIFFERENTIATION
• The simplest definition of a derivative is the difference approximation:
y f  xi  x   f  xi 

x x (1)
• If x is allowed to approach zero, the difference becomes a derivative:
dy f  xi  x   f  xi 
 lim
dx x  0 x (2)
• The second derivative represents the derivative of the first derivative
2
d y d  dy 
2
  
dx dx  dx  (3)
• The second derivative tells us how fast the slope is changing. It is
commonly referred to as the curvature.
NUMERICAL DIFFERENTIATION

The graphical definition of a derivative: Asx approaches zero in going from


(a) to (c), the difference approximation becomes a derivative.
NUMERICAL DIFFERENTIATION
• Numerical differentiation is employed for complicated continuous
functions for which analytical solutions are impractical or impossible.
• It is also useful for tabulated function, where values of xand f  x are
given at a number of discrete points, as is often the case with
experimental or field data.
• A typical example is the determination of the order of reaction in reaction
engineering.
• The rate of reaction is obtained from a data plot of concentration, CA
versus time, t and expressed as  rA  dC A .
dt
n
• If the reaction rate is expressed by  rA  kC A , taking natural logs on
both sides yields In  rA  Ink  nIn C A  and the order of the reaction
can be estimated.
NUMERICAL DIFFERENTIATION
• The most fundamental numerical techniques use finite divided
differences to estimate derivatives.
• From Taylor series expansion, numerical differentiation methods can be
derived .
• Recall that the Taylor Series is given as :
f  xi  2 f  xi  3 f n  xi  n
f  xi 1   f  xi   f  xi  h  h  h  ...  h  Rn
2! 3! n! (4)
f x  n 1
n 1

where Rn  n  1! h
 
• This is a remainder term included to account for all terms from n + 1 to
infinity.
• x is a value of x that lies somewhere between x and xi 1
NUMERICAL DIFFERENTIATION
Forward difference
f  xi 1   f  xi  (5)
f  xi    O  xi 1  xi 
xi 1  xi
This can be re-written as :
f i
f  xi    O h  (6)
h
Backward difference
• The Taylor series can be expanded backward to calculate a previous value
on basis of a present value:
f  xi  2
f  xi  1   f  xi   f  xi  h  h  ... (7)
2!
• This is re-written as:
f i
f  xi    O h 
h (8)
NUMERICAL DIFFERENTIATION

Graphical depiction of (a) forward, (b) backward, and (c) centered finite-divided
difference approximations of the first derivative.

Central difference
The backward Taylor series expansion is subtracted from the forward Taylor
series expansion :
f  xi  2 (9)
f  xi 1   f  xi   f  xi  h  h  ...
2!
NUMERICAL DIFFERENTIATION
• to yield:
2 f  xi 
f  xi 1   f  xi  1   2 f  xi  h  h 3  ...
3! (10)
• which can be solved for
f  xi 1   f  xi  1  f  xi  2
f  xi    h  ...
2h 6
• or
f  xi 1   f  xi  1 
f  xi    O h 2 
2h (11)
The truncation error is of the order of h2 in contrast to the forward
and backward approximations that were of the order of h.
NUMERICAL DIFFERENTIATION
• Taylor series analysis shows that the centered difference is a more
accurate representation of the derivative .
Example 1
Use forward and backward difference approximations of O(h) and a
centered difference approximation of O(h2) to estimate the first derivative
of f  x   0.1x 4  0.15 x 3  0.5 x 2  0.25 x  1.25 at x 0.5 using a step
size of h = 0.5.
Repeat the computation using h=0.25. Note that the derivative can be
calculated directly as
f  x   0.4 x 3  0.45 x 2  1.0 x  0.25
and can be used to compute the true value as f 0.5   0.9125
NUMERICAL DIFFERENTIATION
Solution
• For h = 0.5, the function can be employed to determine
xi  1 0 f  xi  1  1.25
xi 0.5 f  xi  0.975
xi 1 1.0 f  xi 1  0.25
• These values can be used to compute the forward divided difference
0.25  0.975
f 0.5    1.45 e t 58.9%
0.5
• The backward divided difference
0.975  1.25
f 0.5    0.55 e t 39.7%
0.5
NUMERICAL DIFFERENTIATION
• The centered divided difference
0.25  1.25
f 0.5    1.0 e t 9.6%
0.5
• For h = 0.25

xi  1 0.25 f  xi  1  1.153515625
xi 0.5 f  xi  0.975
xi 1 0.75 f  xi 1   0.686328125
• which can be used to compute the forward divided difference
0.686328125  0.975
f 0.5    1.155 e t 26.5%
0.25
NUMERICAL DIFFERENTIATION
• The backward divided difference
0.975  1.153515625
f 0.5    0.714 e t 21.7%
0.25
• The centered divided difference
0.686328125  1.153515625
f 0.5    0.934 e t 2.4%
0.5
• The following can be deduced from this example:
(i) the centered difference approximation is more accurate than forward
or backward differences for both step sizes.
(ii) halving the step size approximately halves the error of the backward
and forward differences and quarters the error of the centered difference.
NUMERICAL DIFFERENTIATION
Finite Difference Approximations of Higher Derivatives
• Taylor series expansion can be used to derive numerical estimates of
higher derivatives.
• We write a forward Taylor series expansion for f  xi 2  in terms of f  xi  :
f  xi  (12)
f  xi 2   f  xi   f  xi 2h  2

2!
2h   ...
• Equation (9) can be multiplied by 2 and subtracted from Eq. (12) to give:

f  xi 2   2 f  xi 1   f  xi   f  xi  h 2  ...
• which can be solved for
f  xi 2   2 f  xi 1   f  xi  (13)
f  xi   2
 O h 
h
NUMERICAL DIFFERENTIATION
• This relationship is called the second forward finite divided difference.
• Similar manipulations can be employed to derive a backward version:
f  xi   2 f  xi  1   f  xi  2 
f  xi    O h 
h 2
(14)
• and a centered version
f  xi 1   2 f  xi   f  xi  1 
f  xi    O h 
h 2
(15)
• Alternatively the centered difference can be expressed as:
(16)
f  xi 1   f  xi  f  xi   f  xi  1 

f  xi   h h
h
NUMERICAL DIFFERENTIATION
• Thus the second divided difference approximation is a difference of two
first divided differences.
High-Accuracy Differentiation Formulas
• High-accuracy divided-difference formulas can be generated by including
additional terms from the Taylor series expansion.
• Re-call the forward Taylor series expansion can be written up to the second
term as:
f  xi  2
f  xi 1   f  xi   f  xi  h  h  ...
2!

• which can be solved for


f  xi 1   f  xi  f  xi  (17)
f  xi    h  O h 2 
h 2
NUMERICAL DIFFERENTIATION
• We now retain the second-derivative term by substituting the approximation
of the second derivative i.e. Equation to yield:
f  xi 1   f  xi  f  xi 2   2 f  xi 1   f  xi 
f  xi    2
h
h 2h (18)
• Collecting like terms gives:
 f  xi 2   4 f  xi 1   3 f  xi  (19)
f  xi    O h  2

2h
• Inclusion of the second-derivative term has improved the accuracy to
O(h2).
• Similar improved versions can be developed for the backward and
centered formulas as well as for the approximations of the higher
derivatives.
• This is left as an exercise to the reader.
NUMERICAL DIFFERENTIATION

Forward finite divided


difference formulas
NUMERICAL DIFFERENTIATION

Backward finite divided


difference formulae
NUMERICAL DIFFERENTIATION

Centered finite
divided difference
formulae
NUMERICAL DIFFERENTIATION
Example 2
Repeat Example 1 for a step size h = 0.25 and higher accuracy formulae.
Solution
Data required for this problem is:
xi  2 0 f  xi  2  1.25
xi  1 0.25 f  xi  1  1.153515625
xi 0.5 f  xi  0.975
xi 1 0.75 f  xi 1  0.686328125
xi 2 1.0 f  xi 1   0.25
NUMERICAL DIFFERENTIATION
• The forward difference of accuracy O(h2) is computed as
 f  xi 2   4 f  xi 1   3 f  xi 
f  xi  
2h
 0.25  4(0.686328125)  3(0.975)
f 0.5    0.859375 e t 5.82%
2(0.25)

• The backward difference of accuracy O(h2 ) is computed as


3 f  xi   4 f  xi  1   f  xi  2 
f  xi  
2h
3 0.975   4(1.153515625)  1.25
f 0.5    0.878125 e t 3.77%
2(0.25)
NUMERICAL DIFFERENTIATION
• The centered difference of accuracy O(h4 ) is computed as:
 f  xi 2   8 f  xi 1   8 f  xi  1   f  xi  2 
f  xi  
12h
 0.25  8 0.686328125   8 1.153515625   1.2
f 0.5    0.9125 e t 0%
12(0.25)
• As expected, the errors for the forward and backward differences are
considerably more accurate compared to Example 1.
• The centered difference yields a perfect result. This is because the
formulas based on the Taylor series are equivalent to passing polynomials
through the data points.
NUMERICAL DIFFERENTIATION
Derivatives of Unequally Spaced Data
• Approaches discussed to this point are primarily designed to determine the
derivative of a given function.
• For the finite-divided-difference approximations, data had to be evenly
spaced.
• In contrast, empirically derived information—that is, data from
experiments or field studies—is often collected at unequal intervals.
• Such information cannot be analyzed with the techniques discussed to
this point.
• Solution to handle non equi-spaced data is to fit a second-order Lagrange
interpolating polynomial to each set of three adjacent points.
• This polynomial does not require that the points be equispaced.
NUMERICAL DIFFERENTIATION
• The second-order polynomial can be differentiated analytically to give:
2 x  xi  xi 1 2 x  xi  1  xi 1
f  x   f  xi  1   f  xi 
 xi  1  xi  xi  1  xi 1   xi  xi  1  xi  xi 1 
2 x  xi  1  xi (20)
+ f  xi  1 
 xi 1  xi  1  xi 1  xi 
where x is the value at which you want to estimate the derivative
• The above equation has the following advantages:
(i) Can be used to estimate the derivative anywhere within the range
prescribed by the three points.
(ii) The points do not have to be equally spaced.
(iii) Derivative estimate is same accuracy as the centered difference.
NUMERICAL DIFFERENTIATION
Example 3
A temperature gradient can be measured down into the catalytic reactor
as shown in the table.
reactor depth, z 0 1.25 3.75
(cm)
Temperature (o 13.5 12 10
C)
The heat flux at the catalyst –fluid interface can be computed with Fourier’s
law:
dT
q  z 0   kr C
dz z 0

where q = heat flux (W/m2 ), k = coefficient of thermal diffusivity in catalyst


(≅ 3.5 × 10−7 m2/s), ρ = catalyst density (≅ 1800 kg/m3 ), and C = catalyst
specific heat (≅ 840 J/(kg °C)).
NUMERICAL DIFFERENTIATION
A positive value for flux means that heat is transferred from the gas
reactants to the catalyst.
Use numerical differentiation to evaluate the gradient at the catalyst-gas
interface and employ this estimate to determine the heat flux into the
catalyst bed.
Solution
We use Equation 20 :
2(0)  1.25  3.75 2 0   0  3.75
f  x  13.5  12
0  1.250  3.75 1.25  0 1.25  3.75
2 0   0  1.25
+ 10 1.333333 0 C/cm
3.75  0 3.75  1.25
NUMERICAL DIFFERENTIATION
2 o
7 m kg J C
q  3.5 10 1800 3 840 o  133.3333
s m kg C m
2
q 70.56W / m

• Partial derivatives along a single dimension are computed in the same


fashion as ordinary derivatives. This is left as an exercise to the reader.
• Inbuilt MATLAB functions del2, diff and gradient can be used to
perform numerical differentiation of different functions.
NUMERICAL DIFFERENTIATION
Example 4
NUMERICAL INTEGRATION
NUMERICAL INTEGRATION
• The inverse process to differentiation in calculus is integration or
anti-differentiation.
• To integrate means “to bring together, as parts, into a whole; to
unite; to indicate the total amount,
• Mathematically integration is represented as:
b
I  f  x  dx (21)
a

which stands for the integral of the function f(x) with respect to the
independent variable x, evaluated between the limits x = a to x = b
• Integrals are employed by engineers to evaluate the total amount or
quantity of a given physical variable.
NUMERICAL INTEGRATION
• The integral may be evaluated over a line, an area, or a volume.
• Calculation of the volume of a non-isothermal chemical reactor usually
needs the use of numerical integration.
Example 5
Consider the first order reaction A→B in liquid phase, taking place in an
adiabatic plug flow reactor. Pure A enters the reactor, and it is desired to
have the conversion X, at the outlet. The volume of this reactor is given by
: where V is the volume of the reactor, v0, is the
v0 X1 dX inlet volumetric flow rate of A, k, is the rate
V  constant at the temperature T1, Ea, is the
k1 0  Ea  1 1  
1  X exp      activation energy of the reaction, R is the ideal
 R  T1 T   gas constant, T is the temperature of the
reactor where the conversion is X , and T1 , is
a reference temperature.
NUMERICAL INTEGRATION
• The figure below describes the concept of integration.

• For functions lying above the x axis,


the integral expressed by Eq. (21)
corresponds to the area under the
curve of f (x) between x = a and b.
• Most common approaches for
numerical integration are the Newton-
Cotes formulas.
• Based on replacing a complicated
function or tabulated data with a
simple polynomial that is easy to
integrate.
NUMERICAL INTEGRATION
• Three of the most widely used Newton-Cotes formulas are the trapezoidal
rule, Simpson’s 1∕3 rule and Simpson’s 3∕8 rule.
• These formulas are designed for cases where the data to be integrated are
evenly spaced.
NEWTON-COTES INTEGRATION FORMULAS
• The Newton-Cotes formulas are the most common numerical integration
schemes.
• 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
where fn (x) is a polynomial of the form
f n  x  a0  a1 x  ...  an  1 x n 1
 an x n
NUMERICAL INTEGRATION
• where n is the order of the polynomial.

The approximation of an integral by the area under (a) a single straight line and
(b) a single parabola.
NUMERICAL INTEGRATION
• The integral can also be approximated using a series of polynomials
applied piece-wise to the function or data over segments of constant
length.
The approximation of an integral by the
area under three straight-line segments.

• Higher-order polynomials can be


utilized for the same purpose.
• Closed and open forms of the
Newton-Cotes formulas are
available.
• The closed forms are those where the
data points at the beginning and end
of the limits of integration are known.
NUMERICAL INTEGRATION
• The open forms have integration limits that extend beyond the range of the
data.
• Open Newton-Cotes formulas are not generally used for definite
integration.
• They are utilized for evaluating improper integrals and for the
solution of ordinary differential equations.
THE TRAPEZOIDAL RULE
• It corresponds to the case where the polynomial is first-order:
b b
I  f  x  dx  f1  x  dx
a a
where
f b   f a 
f1  x   f a   x  a  (22)
b a
NUMERICAL INTEGRATION
• The area under this straight line is an estimate of the integral of f (x)
between the limits a and b:
b f b   f a  
I   f a    x  a  dx
a
 b a 

• Integration yields:
f a   f b 
I b  a  (23)
2
which is called the trapezoidal rule.
NUMERICAL INTEGRATION
• Therefore, the integral estimate can be represented as:
I width average height (24)
• or
I b  a average height
(25)
• where, for the trapezoidal rule, the

average height is the average of the
function values at the end points, or
[ f(a) + f(b)]∕2.
• All the Newton-Cotes closed
formulas can be expressed in the
general format of Eq. 25 .
• They differ only with respect to the
formulation of the average height.
NUMERICAL INTEGRATION
Error of the Trapezoidal Rule
• When the integral under a straight-line segment is employed to
approximate the integral under a curve, a substantial might be introduced.
• An estimate for the local truncation error of a single application of
the trapezoidal rule is :
1
f x b  a 
3
Et  

12 (26)
where ξ lies somewhere in the interval from a to b.
• Equation indicates that if the function being integrated is linear, the
result from the trapezoidal rule will be exact.
• Otherwise, for functions with second- and higher-order derivatives
(that is, with curvature), some error can occur.
NUMERICAL INTEGRATION
Example 6
Use the trapezoidal rule to numerically integrate:
f  x  0.2  25 x  200 x 2  675 x3  900 x 4  400 x5

Solution
• Exact analytical value of the integral is 1.640533
• The function values f(0) = 0.2 and f(0.8) = 0.232
• Substituting in Eqn. (24) :
0.2  0.232
I 0.8 0.1728
2

• This gives an error,


e t E89.5%
t = 1.640533 − 0.1728 = 1.467733

• Relative error,
NUMERICAL INTEGRATION
• In actual situations, we would have no foreknowledge of the true
value.
• Therefore, an approximate error estimate is required.
• To obtain this estimate, the function’s second derivative over the interval
can be computed by differentiating the original function twice to give:
f  x   400  4050 x  10800 x 2  8000 x3
• The average value of the second derivative can be computed:
0.8
f  x  
 400  4050 x  10800 x 2
 8000 x3  dx
0 0.8  0
• which can be substituted into Eq. (26) to yield:
1
   2.56
3
Ea   60 0.8
12
NUMERICAL INTEGRATION
• Which is of the same order of magnitude and sign as the true error.
Multiple-Application Trapezoidal Rule
• One way to improve the accuracy of the trapezoidal rule is to divide
the integration interval from a to b into a number of segments and
apply the method to each segment.
• The areas of individual segments can then be added to yield the integral
for the entire interval.
• The resulting equations are called multiple-application, or composite,
integration formulas.
NUMERICAL INTEGRATION
There are n + 1 equally spaced base points
(x0 , x1 , x2 , . . . , xn ).

Consequently, there are n segments of


equal width:
b a
h (27)
n

The general format and nomenclature for multiple- application integrals


NUMERICAL INTEGRATION
• If a and b are designated as x0 and xn , respectively, the total integral can
be represented as:
x1 x2 xn
I  f  x dx   f  x dx  ...   f  x dx
x0 x1 xn 1

• Substituting the trapezoidal rule for each integral yields


f  x0   f  x1  f  x1   f  x2  f  xn  1   f  xn 
I h h  ...  h
2 2 2 (28)
• or, grouping terms,
n 1
h  (29)
I   f  x0   2 f  xi   f  xn 
2 i 1 
NUMERICAL INTEGRATION
• or, using Eq. (27) to express Eq. (29) in the general form of Eq. (25):
n 1
f  x0   2 f  xi   f  xn 
(30)
I b  a  i 1
14424431444444444442244444444444
n 3
width
average height

• An error for the multiple-application trapezoidal rule can be obtained


by summing the individual errors for each segment to give:
b  a 
3
n
Et 
12n 3  f x 
i 1
i
(31)
where f″(ξi) is the second derivative at a point ξi located in segment I
• This result can be simplified by estimating the mean or average value
of the second derivative for the entire interval as :
NUMERICAL INTEGRATION
n

 f x  i
f   i 1 (32)
n

• Therefore,  f x i  nf  and Eq. (31) can be rewritten as:

b  a 
3

Ea  f  (33)
12n 2
• Thus, if the number of segments is doubled, the truncation error will
be quartered.
• Note that Eq. (33) gives an approximate error because of the approximate
nature of Eq. (32).
NUMERICAL INTEGRATION
Example 7
Use the two-segment trapezoidal rule to estimate the integral of
f  x  0.2  25 x  200 x 2  675 x3  900 x 4  400 x5 from a = 0 to b = 0.8.
Employ Eq. (33) to estimate the error. Recall that the correct value for the
integral is 1.640533.
Solution
For n =2 (h = 0.4)
f 0  0.2, f 0.4  2.456, f 0.6  0.232
0.2  2 2.456   0.232
I 0.8 1.0688
4
Et 1.640533  1.0688 0.57173, Et 34.9%
0.83
Ea   60  0.64
12 2 
2
NUMERICAL INTEGRATION
SIMPSON’S RULES
• Another way to obtain a more accurate estimate of an integral is to use
higher-order polynomials to connect the points.
• For example, if there is an extra point midway between f(a) and
f(b), the three points can be connected with a parabola (Fig. a).
• If there are two points equally spaced between f(a) and f(b), the four
points can be connected with a third-order polynomial (Fig. b).
• The formulas that result from taking the integrals under these
polynomials are called Simpson’s rules.
NUMERICAL INTEGRATION

(a) Graphical depiction of Simpson’s 1/3 rule: It consists of taking the area under
a parabola connecting three points. (b) Graphical depiction of Simpson’s 3/8 rule:
It consists of taking the area under a cubic equation connecting four points.
NUMERICAL INTEGRATION
Simpson’s 1/3 Rule
• Simpson’s 1∕3 rule results when a second-order interpolating
polynomial is substituted into Eqn. (21) .
b b
I  f  x  dx  f 2  x  dx
a a

• If a and b are designated as x0 and x2 and f2(x) is represented by a


second-order Lagrange polynomial, the integral becomes
  x  x1  x  x2   x  x0  x  x2  
 f  x0   f  x1 
x2  x0  x1  x0  x2   x1  x0  x1  x2 
I    dx
x0  
 +
 x  x0  x  x1 
f  x2  
  x2  x0  x2  x1  
NUMERICAL INTEGRATION
• After integration and algebraic manipulation, the following formula
results:
h (34)
I   f  x0   4 f  x1   f  x2 
3
where, for this case, h = (b − a)∕2.
• This equation is known as Simpson’s 1∕3 rule.
• The label “1∕3” stems from the fact that h is divided by 3 in Eq. 34
• Simpson’s 1∕3 rule can also be expressed using the format of Eq. (25):
f  x0   4 f  x1   f  x2 
I b  a 
1442443144444444442444444444
6 43 (35)
width
average height
NUMERICAL INTEGRATION
• where a = x0 , b = x2 , and x1 = the point midway between a and
b, which is given by (b +a)∕2.
• It can be shown that a single-segment application of Simpson’s 1∕3 rule
has a truncation error of :
b  a 
5
4 
e t  f x 
2880
• where ξ lies somewhere in the interval from a to b.
• Thus, Simpson’s 1∕3 rule is more accurate than the trapezoidal rule.
Example 8
Use Simpson’s 1/3 rule to integrate
f  x  0.2  25 x  200 x 2  675 x3  900 x 4  400 x5 from a = 0 to b = 0.8.
Recall that the exact value is 1.640533.
NUMERICAL INTEGRATION
• f(0) = 0.2, f(0.4)=2.456, f(0.8)=0.232
• Therefore, Eq. (21.15) can be used to compute:
0.2  4 2.456   0.232
I 0.8  1.367467
6
• which represents an exact error of
Et = 1.640533 − 1.367467 = 0.2730667 εt = 16.6%
• which is approximately five times more accurate than for a single
application of the trapezoidal rule.
0.8
5

Ea   2400   0.2730667
2880
• where −2400 is the average fourth derivative for the interval.
NUMERICAL INTEGRATION
• Simpson’s rule can be improved by dividing the integration interval into a
number of segments of equal width :
b a (36)
h
n
• The total integral can be represented as:
x2 x4 xn
I  f  x  dx  f  x  dx ...   f  x  dx (37)
x0 x2 xn 2

• Substituting Simpson’s 1∕3 rule for the individual integrals yields


f  x0   4 f  x1   f  x2  f  x2   4 f  x3   f  x4 
I 2 h  2h
6 6
f  xn  2   4 f  xn  1   f  xn 
...  2h
6
NUMERICAL INTEGRATION
• or, combining terms and using Eq. (37)
n 1 n 2
f  x0   4  f  xi   2  f x   f x 
j n

I b  a  i 1,3,5 j 2,4,6 (38)


14424431444444444444444444
432444444444444444444
n 43
width
average height

Graphical representation of the multiple


application of Simpson’s 1∕3 rule. Note
that the method can be employed only if
the number of segments is even.
NUMERICAL INTEGRATION
• An error estimate for the multiple-application Simpson’s rule is
b  a 
5
4 
Ea  4
f (39)
180n

• where is the average fourth derivative for the interval.


Example 9
Use multiple-application Simpson’s 1/3 Rule with n = 4 to estimate the
integral of
f  x  0.2  25 x  200 x 2  675 x3  900 x 4  400 x5 from a = 0 to b = 0.8.
• Recall that the exact value is 1.640533.
NUMERICAL INTEGRATION
Solution
• For n = 4 (h = 0.2):
• f(0) = 0.2 f(0.2) = 1.288 f(0.4) = 2.456 f(0.6) = 3.464 f(0.8) = 0.232
0.2  4 1.288  3.464   2 2.456   0.232
I 0.8 1.623467
12
• Et = 1.640533 − 1.623467 = 0.017067 εt = 1.04%
• The estimated
5 error [Eq. (39)] is
0.8 
4 
Ea   2400  0.017067
180 4 

• The multiple-application version of Simpson’s 1∕3 rule yields very accurate


results.
• However it is limited to cases where the values are equi-spaced.
• Further, it is limited to situations where there are an even number of
segments and an odd number of points.
NUMERICAL INTEGRATION
Simpson’s 3/8 Rule
• Simpson’s 3∕8 rule is used in conjunction with the 1∕3 rule to
permit evaluation of both even and odd numbers of segments.
• A third-order Lagrange polynomial can be fit to four points and integrated:
b b
I  f  x  dx  f 3  x  dx
a a

• to yield
3h
I   f  x0   3 f  x1   3 f  x2   f  x3 
8
where h= (b−a)∕3
• This equation is called Simpson’s 3∕8 rule because h is multiplied by 3∕8.
• It is the third Newton-Cotes closed integration formula.
NUMERICAL INTEGRATION
• The 3∕8 rule can also be expressed in the form of Eq. (25):
f  x0   3 f  x1   3 f  x2   f  x3 
I b  a 
1442443144444444444444244444444444444
(40)
8 3
width
average height

• Thus, the two interior points are given weights of three-eighths, whereas the
end points are weighted with one-eighth.
• Simpson’s 3∕8 rule has an error of:
b  a 
5

f   x 
4
Et 
6480 (41)

• Simpson’s 1∕3 rule is usually the method of preference because it attains


third-order accuracy with three points rather than the four points
required for the 3∕8 version.
• However, the 3∕8 rule has utility when the number of segments is odd.
NUMERICAL INTEGRATION
Example 10
(i) Use Simpson’s 3∕8 rule to integrate
f  x  0.2  25 x  200 x 2  675 x3  900 x 4  400 x5 from a = 0 to b = 0.8
(ii) Use it in conjunction with Simpson’s 1∕3 rule to integrate the same
function for five segments.
Solution
(i) A single application of Simpson’s 3∕8 rule requires four equally spaced
points:
f(0) = 0.2, f(0.2667) = 1.432724, f(0.5333) = 3.487177 f(0.8) = 0.232
Using Eq. (21.20),
0.2  3 1.432724  3.487177   0.232
I 0.8 1.519170
8
NUMERICAL INTEGRATION
• Et = 1.640533 − 1.519170 = 0.1213630 εt = 7.4%
0.8
5

Ea   2400  0.1213636
6480

(ii) The data needed for a five-segment application (h = 0.16) is


f(0) = 0.2, f(0.16) = 1.296919, f(0.32) = 1.743393, f(0.48) = 3.186015,
f(0.64) = 3.181929, f(0.80) = 0.232
• The integral for the first two segments is obtained using Simpson’s 1∕3
rule:
0.2  4(1.296919)  1.743393
I 0.32 0.3803237
6
NUMERICAL INTEGRATION
• For the last three segments, the 3∕8 rule can be used to obtain
1.743393  3(3.186015  3.181929)  0.232
I 0.48 1.264754
8
• The total integral is computed by summing the two results:
I = 0.3803237 + 1.264753 = 1.645077
Et = 1.640533 − 1.645077 = −0.00454383 εt = −0.28%
NUMERICAL INTEGRATION
Higher-Order Newton-Cotes Closed Formulas
• A summary of some Newton-Cotes formulae along with their truncation-error
estimates are given in the Table below:

NB: The formulas are presented in the format of Eq. (25)


NUMERICAL INTEGRATION
INTEGRATION WITH UNEQUAL SEGMENTS
• In practice, there are many situations where we must deal with
unequal-sized segments.
• For example, experimentally derived data are often of this type.
• For these cases, one method is to apply the trapezoidal rule to each
segment and sum the results:
f  x0   f  x1  f  x1   f  x2  f  xn  1   f  x n 
I h1  h2  ...  hn
2 2 2
(42)
• where hi = the width of segment i.
Example 11
The information in the table was generated using the same
polynomial employed in Example 6. Use Eq. (42) to determine the
integral for these data. Recall that the correct answer is 1.640533.
NUMERICAL INTEGRATION
• Applying Eq. (42) to the data in the table yields
1.309729  0.2 1.305241  1.309729 0.232  2.363
I 0.12  0.1  ...  0.10
2 2 2
= 0.090584 + 0.130749 + ...  0.12975 = 1.594801
• which represents an absolute percent relative error of εt=2.8%.
• Data for f(x) = 0.2 + 25x −200x2 + 675x3−900x4 +400x5 ,
with unequally spaced values of x.
NUMERICAL INTEGRATION
Example 12
Re-compute the integral for the data in previous table, but use Simpson’s
rules for those segments where they are appropriate.
Solutions
The first segment is evaluated with the trapezoidal rule:
1.309729  0.2
I 0.12 0.09058376
2

Because the next two segments from x = 0.12 to 0.32 are of equal length,
their integral can be computed with Simpson’s 1∕3 rule:
1.743393  4 1.305241 1.309729
I 0.2 0.2758029
6
NUMERICAL INTEGRATION
• The next three segments are also equal and, as such, may be evaluated with
the 3∕8 rule to give I = 0.2726863.
• Similarly, the 1∕3 rule can be applied to the two segments from x = 0.44 to
0.64 to yield I = 0.6684701.
• Finally, the last two segments, which are of unequal length, can be
evaluated with the trapezoidal rule to give values of 0.1663479 and
0.1297500, respectively.
• The area of these individual segments can be summed to yield a total
integral of 1.603641.
• This represents an error of εt=2.2%, which is superior to the result using the
trapezoidal rule in Example 11.
NUMERICAL INTEGRATION
OPEN INTEGRATION FORMULAS
• Open integration formulas have limits that extend beyond the range of the
data.
• Table below summarizes the Newton-Cotes open integration formulas.
The formulas are presented in format of Eq. (25). The step size is given by h
= (b − a)/n.
NUMERICAL INTEGRATION
MULTIPLE INTEGRALS
• Multiple integrals are widely used in engineering.
• For example, a general equation to compute the average of a two
dimensional function can be written as

  f  x, y dx dy
d b

c a (43)
f 
d  c b  a 
• The numerator is called a double integral.
NUMERICAL INTEGRATION

Double integral as the area under the


function surface.

Example 13
Suppose that the temperature of a rectangular heated plate is described
by the following function:
T  x, y  2 xy  2 x  x  2 y  72
2 2
NUMERICAL INTEGRATION
If the plate is 8-m long (x dimension) and 6-m wide (y dimension), compute
the average temperature.
Solution
• Use two-segment applications of the trapezoidal rule in each dimension.
• The temperatures at the necessary x and y values are depicted in
the Figure below

Numerical evaluation of
a double integral using
the two-segment
trapezoidal rule.
NUMERICAL INTEGRATION
• A simple average of these values is 47.33.
• The function can also be evaluated analytically to yield a result of
58.66667.
• To make the same evaluation numerically, the trapezoidal rule is first
implemented along the x dimension for each y value.
• These values are then integrated along the y dimension to give the
final result of 2544.
• Dividing this by the area yields the average temperature as 2544∕(6 ×
8) = 53.
• Applying a single-segment Simpson’s 1∕3 rule in the same fashion an
integral value of 2816 and an average of 58.66667, i.e. exact answer.
END OF MODULE 4

You might also like