Professional Documents
Culture Documents
(CENG-2084)
Chapter 6
Numerical Differentiation and
Integration
Mastewal S 1 5/22/2020
Numerical 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
by Mastewal S. Chapter 6 2
The graphical definition of a derivative: as Δx approaches
zero in going from (a) to (c), the difference approximation
becomes a derivative.
by Mastewal S. Chapter 6 3
b
I f ( x)dx
a
by Mastewal S. Chapter 6 5
Equal-area differentiation
(a) Centered finite divided differences are used to estimate the derivative for
each interval between the data points.
(b) The derivative estimates are plotted as a bar graph. A smooth curve is
superimposed on this plot to approximate the area under the bar graph. This
is accomplished by drawing the curve so that equal positive and negative
areas are balanced.
𝑑𝑦
(c) Values of can then be read off the smooth curve.
by Mastewal S. 𝑑𝑥 Chapter 6 6
Equal-area differentiation.
(a) Centered finite divided differences
are used to estimate the derivative
for each interval between the data
points.
(b) The derivative estimates are
plotted as a bar graph. A
smooth curve is superimposed
on this plot to approximate the
area under the bar graph. This
is accomplished by drawing the
curve so that equal positive and
negative areas are balanced.
(c) Values of dy/dx can then be
read off the smooth curve.
by Mastewal S. Chapter 6 7
High-Accuracy Differentiation Formulas
• High-accuracy divided-difference formulas can be generated by including additional
terms from the Taylor series expansion.
f ( xi ) 2
f ( xi 1 ) f ( xi ) f ( xi )h h
2
f ( xi 1 ) f ( xi ) f ( xi )
f ( xi ) h
h 2
f ' ( xi 1 ) f ' ( xi ) f ( xi 2 ) 2 f ( xi 1 ) f ( xi )
f ( xi ) O ( h)
h h2
f ( xi 1 ) f ( xi ) f ( xi 2 ) 2 f ( xi 1 ) f ( xi )
f ( xi ) 2
h O ( h 2
)
h 2h
f ( xi 2 ) 4 f ( xi 1 ) 3 f ( xi )
f ( xi ) O( h2 )
2h
• Inclusion of the 2nd derivative term has improved the accuracy to O(h2).
• Similar improved versions can be developed for the backward and centered formulas
by Mastewal S. Chapter 6 8
Forward finite-divided-difference formulas
by Mastewal S. Chapter 6 9
Backward finite-divided-difference formulas
by Mastewal S. Chapter 6 10
Centered finite-divided-difference formulas
First Derivative Error
f ( xi 1 ) f ( xi 1 )
f ( xi ) O(h2)
2h
f ( xi 2 ) 8 f ( xi 1 ) 8 f ( xi 1 ) f ( xi 2 )
f ( xi ) O(h4)
12h
Second Derivative Error
f ( xi 1 ) 2 f ( xi ) f ( xi 1 )
f " ( xi ) O(h2)
h2
f ( xi 2 ) 16 f ( xi 1 ) 30 f ( xi ) 16 f ( xi 1 ) f ( xi 2 )
f " ( xi ) O(h4)
12h 2
by Mastewal S. Chapter 6 11
Derivation of the centered formula for f’’(xi)
f ( xi ) 2
f ( xi 1 ) f ( xi ) f ( xi )h h
2
2( f ( xi 1 ) f ( xi ) f ( xi )h)
f ( xi )
h2
f ( xi 1 ) f ( xi 1 )
2( f ( xi 1 ) f ( xi ) h)
2h
h2
2 f ( xi 1 ) 2 f ( xi ) f ( xi 1 ) f ( xi 1 )
h2
f ( xi 1 ) 2 f ( xi ) f ( xi 1 )
f ( xi )
h2
by Mastewal S. Chapter 6 12
Example
f(x) = -0.1x4 – 0.15x3 – 0.5x2 – 0.25x + 1.2
f’(x) = -0.4x3 – 0.45x2 – x – 0.25
f n ( x) a0 a1 x an1 x n 1 an x n
by Mastewal S. Chapter 6 14
The approximation of an integral by the area under
(a) a single straight line and
(b) a single parabola.
by Mastewal S. Chapter 6 15
The approximation of an integral by the area under
three straight-line segments.
by Mastewal S. Chapter 6 16
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
by Mastewal S. Chapter 6 17
Graphical depiction of the trapezoidal rule
by Mastewal S. Chapter 6 18
Error of the Trapezoidal Rule/
12
where x lies somewhere in the interval from a to b.
by Mastewal S. Chapter 6 19
The 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.
ba
h a x0 b xn
n
x1 x2 xn
by Mastewal S. Chapter 6 20
The general format and nomenclature for multiple-application integrals.
by Mastewal S. Chapter 6 21
Simpson’s Rules
• More accurate estimate of an integral is
obtained if a high-order polynomial is used to
connect the points. The formulas that result
from taking the integrals under such
polynomials are called Simpson’s rules.
by Mastewal S. Chapter 6 22
(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.
by Mastewal S. Chapter 6 23
b b
I f ( x)dx f 2 ( x)dx
a a
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 )
ba
I
h
f ( x0 ) 4 f ( x1 ) f ( x2 ) h
3 2
by Mastewal S. Chapter 6 24