Chapter 5 Numerical Differentiation and Integration
Chapter 5 Numerical Differentiation and Integration
NUMERICAL DIFFERENTIATION
& INTEGRATION
CONTENTS:
• INTRODUCTION
• FORWARD DIFFERENCE FORMULA
• CENTRAL DIFFERENCE FORMULA
• NUMERICAL INTEGRATION
• TRAPEZOIDAL RULE
• SIMPSON’S RULE
5.1 Introduction:
Calculus is mathematics of change. Because engineers must
continuously deal with systems and processes that change,
calculus is an essential tool of the engineering profession.
b
I f x dx
a
which stands for the integral of the function f(x) w.r.t. the
independent variable x, evaluated between the limits x = a
to x = b. The function f(x) is referred to as the integrand.
Non-Computer Methods for Differentiation and Integration
The function to be differentiated or integrated will typically be in one of the
following three forms:
1. A simple continuous function such as a polynomial, an exponential, or a
trigonometric function.
2. A complicated continuous function that is difficult or impossible to
differentiate or integrate directly.
3. A tabulated function where the values of x and f(x) are given at a number of
discrete points, as is often the case with experimental or field data.
In the first case, the derivative or integral of a simple function may be
evaluated analytically using calculus.
For the second case, analytical solutions are often impractical, and
sometimes impossible, to obtain. In these instances, as well as in the
third case of discrete data, approximate methods must be employed.
In the non-computer method for determining derivatives from data, the
(x, y) data are tabulated and, for each interval, a simple divided
difference Δy/Δx is employed to estimate the slope.
Then these values are plotted as a stepped curve versus x. Next a smooth
curve is drawn that attempts to approximate the area under the stepped
curve.
That is, it is drawn so that visually, the positive and the negative areas are
balanced. The rates at given values of x can then be read from the curve.
A simple intuitive approach is to plot the function on a grid and count the
number of boxes that approximate the area. This number multiplied by the
area of each box provides a rough estimate of the total area under the curve.
This estimate can be refined, at the expense of additional effort, by
using a finer grid.
Another commonsense approach is to divide the area into vertical
segments, or strips, with a height equal to the function value at the
midpoint of each strip.
The area of the rectangles can be then calculated and summed to
estimate the total area.
In this approach, it is assumed that the value at the midpoint provides
a valid approximation of the average height of the function for each
strip.
As with the grid method, refined estimates are possible by using more
(and thinner) strips to approximate the integral.
5.2 Numerical Differentiation :
An effective tool for Numerical Differentiation is the Taylor series
expansion of f (x) about the point xi. It has the advantage of providing
us with information about the error involved in the approximation.
the following formula for approximating the first derivative, called the first
forward difference, is obtained
f xi 1 f xi f i
f x Oh Oh
h h
f xi 1 f xi 1
f xi
2h
O h2
𝑓 ( 𝑥 )=𝑒− 𝑥 sin ( 𝑥)
Using h=0.1 Using h=0.01
=((0.296657)-(0.318477))/(0.2) =((0.308432)-(0.310648))/(0.02)
=(-0.0218198)/(0.2) =(-0.000221587)/(0.002)
=-0.109099 =-0.110794
Using h=0.001
=((0.309449)-(0.30967))/(0.002)
=(-0.000221587)/(0.02)
=-0.110794
h 2h 2
collecting terms
Fourth Derivative
f xi 4 4 f xi 3 6 f xi 2 4 f xi 1 f xi
f x i
4
h4
2 f xi 5 11 f xi 4 24 f xi 3 26 f xi 2 14 f xi 1 3 f xi
f 4
x i
h4
Look on the handout for
•Backward Finite-divided Difference Formulas
•Centered Finite-divided Difference Formulas
Numerical Integration
5.3 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 x dx
n
a a
The straight line passing through the two points (a, f(a)) and (b, f(b)) is
given by
f b f a
f 1 x f a x a
ba
The area under this straight line is an estimate of the integral of f(x)
between the limits a and b:
f b f a
b
I f a x a dx
a
ba
f a f b
I b a
2
which is called the trapezoidal rule.
Error of the Trapezoidal Rule
1
f b a
3
Et
12
h n 1
I f x 0 2 f xi f x n
2 i 1
or, It can be expressed in the following form,
n 1
f x 0 2 f xi f x n
I b a i 1
2n
An error for the multiple-application trapezoidal rule can be obtained
by summing the individual errors for each segment to give
b a n
Et
12n 3 f
i 1
i
f i
f i 1
n
Therefore f nf
i and Eq. 5.25 can be rewritten as
Ea
b a
3
f
2
12n
Thus, if the number of segment is doubled, the truncation error will
be quartered.
Example Numerically approximate the integral
For m = 4
f x0 4 f x1 f x 2
I b a
6
Where a=x0, b=x2 and x1= the point midway between a and b,
which is given by (b+a)/2.
Et
b a
5
f 4
2880
where ξ lies somewhere in the interval from a to b. Thus,
Simpson's 1/3 rule is more accurate that the trapezoidal rule.
Multiple Application of Simpson's 1/3 Rule
Just as with the trapezoidal rule, Simpson's rule can be
improved by dividing the integration interval into a number of
segments of equal width:
ba
h
n
The total integration can be represented as
x2 x4 xn
f x0 4 f x1 f x 2 f x 2 4 f x 3 f x 4
I 2h 2h ...
6 6
f x n 2 4 f x n 1 f x n
2h
6
combining terms,
n 1 n2
f x 0 4 f x 2 f x f x
i j n
I b a
i 1, 3, 5 j 2, 4, 6
3n
An error estimate for the multiple-application Simpson's rule is
obtained in the same fashion as for the trapezoidal rule by
summing the individual errors for the segments and averaging
the derivative to yield
Ea
ba 5
f 4
4
180n
4
Where f is the average fourth derivative for the interval.
Ea
b a
5
f 4
180n 4
Example Numerically approximate the integral
I b a
i 1, 3, 5 j 2, 4, 6
3n
For m = 2
For m = 4
For m = 8
Simpson's 3/8 Rule
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.
Et
b a
5
f 4
6480
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.
For m = 2
For m = 3