Uploaded by Arnold Lemuel Delizo

Numerical Differentiation & Integration: Lesson Module

advertisement
Lesson 1
Numerical
Differentiation
Lesson 2
Numerical Integration
Module V
NUMERICAL DIFFERENTIATION AND INTEGRATION
ο‚₯
INTRODUCTION
Calculus is the mathematics of change. Because engineers must
continuously deal with systems and processes that change, calculus is an
essential tool of our profession. Standing at the heart of calculus are the
related mathematical concepts of differentiation and integration.
Mathematically, the derivative, which serves as the fundamental
vehicle for differentiation, represents the rate of change of a dependent
variable with respect to an independent variable. The mathematical
definition of the derivative begins with a difference approximation:
𝑓𝑓(π‘₯π‘₯𝑖𝑖 + βˆ†π‘₯π‘₯ ) − 𝑓𝑓 (π‘₯π‘₯𝑖𝑖 )
βˆ†π‘¦π‘¦
=
βˆ†π‘₯π‘₯
βˆ†π‘₯π‘₯
where y and f(x) are alternative representatives for the dependent variable
and x is the independent variable. If Δx is allowed to approach zero, the
difference becomes a derivative
𝑓𝑓(π‘₯π‘₯𝑖𝑖 + βˆ†π‘₯π‘₯ ) − 𝑓𝑓 (π‘₯π‘₯𝑖𝑖 )
𝑑𝑑𝑦𝑦
= lim
βˆ†π‘₯π‘₯
𝑑𝑑𝑑𝑑 βˆ†π‘₯π‘₯→0
where dy/dx [which can also be designated as y’ or f’(xi)] is the first
derivative of y with respect to x evaluated at xi.
The second derivative represents the derivative of the first derivative,
𝑑𝑑 2 𝑦𝑦
𝑑𝑑 𝑑𝑑𝑑𝑑
=
( )
2
𝑑𝑑𝑑𝑑
𝑑𝑑𝑑𝑑 𝑑𝑑𝑑𝑑
Thus, the second derivative tells us how fast the slope is changing. It is
commonly referred to as the curvature, because a high value for the second
derivative means high curvature.
Partial derivatives can be thought of as taking the derivative of the function
at a point with all but one variable held constant. For example, given a
function f that depends on both x and y, the partial derivative of f with
respect to x at an arbitrary point (x, y) is defined as
𝑓𝑓 (π‘₯π‘₯ + βˆ†π‘₯π‘₯, 𝑦𝑦) − 𝑓𝑓 (π‘₯π‘₯, 𝑦𝑦)
πœ•πœ•πœ•πœ•
= 𝑙𝑙𝑙𝑙𝑙𝑙
βˆ†π‘₯π‘₯→0
βˆ†π‘₯π‘₯
πœ•πœ•πœ•πœ•
Similarly, the partial derivative of f with respect to y is defined as
𝑓𝑓 (π‘₯π‘₯, 𝑦𝑦 + βˆ†π‘¦π‘¦) − 𝑓𝑓 (π‘₯π‘₯, 𝑦𝑦)
πœ•πœ•πœ•πœ•
= 𝑙𝑙𝑙𝑙𝑙𝑙
βˆ†π‘¦π‘¦→0
βˆ†π‘¦π‘¦
πœ•πœ•πœ•πœ•
The inverse process to differentiation in calculus
Mathematically, integration is represented by
is
integration.
𝑏𝑏
𝐼𝐼 = οΏ½ 𝑓𝑓 (π‘₯π‘₯ )𝑑𝑑𝑑𝑑
π‘Žπ‘Ž
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. The
function f(x) is referred to as the integrand. The symbol Κƒ is actually a stylized
capital S that is intended to signify the close connection between integration
and summation.
OBJECTIVES
After studying the module, you should be able to:
1. To execute numerical differentiation and integration to a given set of
interpolation points without solving the polynomial.
2. To execute numerical integration to find an approximation for the value of
the definite integral where the function is not explicitly defined.
3. Implement numerical differentiation and integration with the use of
Microsoft Excel.

DIRECTIONS/ MODULE ORGANIZER
There are two lessons in the module. Read each lesson carefully then
answer the exercises/activities to find out how much you have benefited from
it. Work on these exercises carefully and submit your output to your
instructor.
In case you encounter difficulty, discuss this with your instructor during
the face-to-face meeting.
Lesson 1

Numerical Differentiation
Numerical differentiation is a method of approximating the derivative of a
function f at particular value x. Often, particularly in physics and engineering,
a function may be too complicated to merit the work necessary to find the
exact derivative, or the function itself is unknown, and all that is available
are some points x and the function evaluated at those points. Numerical
differentiation, of which finite differences is just one approach, allows one
to avoid these complications by approximating the derivative.
High-accuracy divided-difference formulas can be generated by including
additional terms from the Taylor series expansion. For example, the forward
Taylor series expansion can be written
𝑓𝑓"(π‘₯π‘₯𝑖𝑖 ) 2
𝑓𝑓 (π‘₯π‘₯𝑖𝑖+1 ) = 𝑓𝑓(π‘₯π‘₯𝑖𝑖 ) + 𝑓𝑓 ′(π‘₯π‘₯𝑖𝑖 )β„Ž +
β„Ž +β‹―
2
Which can be solved for
𝑓𝑓′(π‘₯π‘₯𝑖𝑖 ) =
𝑓𝑓 (π‘₯π‘₯𝑖𝑖+1 ) − 𝑓𝑓 (π‘₯π‘₯𝑖𝑖 ) 𝑓𝑓"(π‘₯π‘₯𝑖𝑖 )
−
β„Ž + 𝑂𝑂(β„Ž2 )
β„Ž
2
truncating this result by excluding the second- and higher-derivative terms
and were thus left with a final result of
𝑓𝑓(π‘₯π‘₯𝑖𝑖+1 ) − 𝑓𝑓 (π‘₯π‘₯𝑖𝑖 )
+ 𝑂𝑂(β„Ž2 )
𝑓𝑓′(π‘₯π‘₯𝑖𝑖 ) =
β„Ž
In contrast to this approach, we now retain the second-derivative term by
substituting the following approximation of the second derivative
𝑓𝑓"(π‘₯π‘₯𝑖𝑖 ) =
To yield
𝑓𝑓′(π‘₯π‘₯𝑖𝑖 ) =
𝑓𝑓 (π‘₯π‘₯𝑖𝑖+2 ) − 2𝑓𝑓 (π‘₯π‘₯𝑖𝑖+1 ) + 𝑓𝑓(π‘₯π‘₯𝑖𝑖 )
+ 𝑂𝑂(β„Ž)
β„Ž2
𝑓𝑓 (π‘₯π‘₯𝑖𝑖+1 ) − 𝑓𝑓(π‘₯π‘₯𝑖𝑖 ) 𝑓𝑓 (π‘₯π‘₯𝑖𝑖+2 ) − 2𝑓𝑓 (π‘₯π‘₯𝑖𝑖+1 ) + 𝑓𝑓(π‘₯π‘₯𝑖𝑖 )
−
β„Ž + 𝑂𝑂(β„Ž2 )
β„Ž
2β„Ž2
Or by collecting terms,
𝑓𝑓 ′(π‘₯π‘₯𝑖𝑖 ) =
−𝑓𝑓(π‘₯π‘₯𝑖𝑖+2 ) + 4𝑓𝑓 (π‘₯π‘₯𝑖𝑖+1 ) − 3𝑓𝑓(π‘₯π‘₯𝑖𝑖 )
+ 𝑂𝑂(β„Ž2 )
2β„Ž
Notice that inclusion of the second-derivative term has improved the accuracy
to 𝑂𝑂(β„Ž2 ). Similar improved versions can be developed for the backward and
centered formulas as well as for the approximations of the higher derivatives.
Forward finite-divided-difference formula
First Derivative
𝑓𝑓 (π‘₯π‘₯𝑖𝑖+1 ) − 𝑓𝑓(π‘₯π‘₯𝑖𝑖 )
𝑓𝑓 ′ (π‘₯π‘₯𝑖𝑖 ) =
β„Ž
(
)
−𝑓𝑓 π‘₯π‘₯𝑖𝑖+2 + 4 𝑓𝑓 (π‘₯π‘₯𝑖𝑖+1 ) − 3𝑓𝑓(π‘₯π‘₯𝑖𝑖 )
𝑓𝑓 ′ (π‘₯π‘₯𝑖𝑖 ) =
2β„Ž
Second Derivative
𝑓𝑓(π‘₯π‘₯𝑖𝑖+2 ) − 2𝑓𝑓(π‘₯π‘₯𝑖𝑖+1 ) + 𝑓𝑓(π‘₯π‘₯𝑖𝑖 )
𝑓𝑓"(π‘₯π‘₯𝑖𝑖 ) =
β„Ž2
−𝑓𝑓 (π‘₯π‘₯𝑖𝑖+3 ) + 4𝑓𝑓 (π‘₯π‘₯𝑖𝑖+2 ) − 5𝑓𝑓 (π‘₯π‘₯𝑖𝑖+1 ) + 2𝑓𝑓(π‘₯π‘₯𝑖𝑖 )
𝑓𝑓"(π‘₯π‘₯𝑖𝑖 ) =
β„Ž2
Backward finite-divided-difference formula
First Derivative
𝑓𝑓 (π‘₯π‘₯𝑖𝑖 ) − 𝑓𝑓(π‘₯π‘₯𝑖𝑖−1 )
𝑓𝑓 ′ (π‘₯π‘₯𝑖𝑖 ) =
β„Ž
(
)
(
3𝑓𝑓
π‘₯π‘₯
−
4
𝑓𝑓
π‘₯π‘₯
𝑖𝑖
𝑖𝑖−1 ) + 𝑓𝑓(π‘₯π‘₯𝑖𝑖−2 )
𝑓𝑓 ′(π‘₯π‘₯𝑖𝑖 ) =
2β„Ž
Second Derivative
𝑓𝑓(π‘₯π‘₯𝑖𝑖 ) − 2𝑓𝑓(π‘₯π‘₯𝑖𝑖−1 ) + 𝑓𝑓(π‘₯π‘₯𝑖𝑖−2 )
𝑓𝑓"(π‘₯π‘₯𝑖𝑖 ) =
β„Ž2
2𝑓𝑓 (π‘₯π‘₯𝑖𝑖 ) + 5𝑓𝑓 (π‘₯π‘₯𝑖𝑖−1 ) + 4𝑓𝑓 (π‘₯π‘₯𝑖𝑖−2 ) − 𝑓𝑓(π‘₯π‘₯𝑖𝑖−3 )
𝑓𝑓"(π‘₯π‘₯𝑖𝑖 ) =
β„Ž2
Centered finite-divided-difference formula
First Derivative
𝑓𝑓 (π‘₯π‘₯𝑖𝑖+1 ) − 𝑓𝑓(π‘₯π‘₯𝑖𝑖−1 )
𝑓𝑓 ′(π‘₯π‘₯𝑖𝑖 ) =
2β„Ž
(
)
(
−𝑓𝑓
π‘₯π‘₯
+
8
𝑓𝑓
π‘₯π‘₯
𝑖𝑖+2
𝑖𝑖+1 ) − 8𝑓𝑓 (π‘₯π‘₯𝑖𝑖−1 ) + 𝑓𝑓(π‘₯π‘₯𝑖𝑖−2 )
𝑓𝑓 ′(π‘₯π‘₯𝑖𝑖 ) =
12β„Ž
Second Derivative
𝑓𝑓(π‘₯π‘₯𝑖𝑖+1 ) − 2𝑓𝑓(π‘₯π‘₯𝑖𝑖 ) + 𝑓𝑓(π‘₯π‘₯𝑖𝑖−1 )
𝑓𝑓"(π‘₯π‘₯𝑖𝑖 ) =
β„Ž2
𝑓𝑓"(π‘₯π‘₯𝑖𝑖 )
−𝑓𝑓(π‘₯π‘₯𝑖𝑖+2 ) + 16𝑓𝑓 (π‘₯π‘₯𝑖𝑖+1 ) − 30𝑓𝑓 (π‘₯π‘₯𝑖𝑖 ) + 16𝑓𝑓(π‘₯π‘₯𝑖𝑖−1 ) − 𝑓𝑓 (π‘₯π‘₯𝑖𝑖−2 )
=
12β„Ž2
Error
𝑂𝑂(β„Ž)
𝑂𝑂(β„Ž2 )
𝑂𝑂(β„Ž)
𝑂𝑂(β„Ž2 )
Error
𝑂𝑂(β„Ž)
𝑂𝑂(β„Ž2 )
𝑂𝑂(β„Ž)
𝑂𝑂(β„Ž2 )
Error
𝑂𝑂(β„Ž2 )
𝑂𝑂(β„Ž4 )
𝑂𝑂(β„Ž2 )
𝑂𝑂(β„Ž4 )
Example:
Estimate the Derivative of
𝑓𝑓 (π‘₯π‘₯ ) = −0.1 π‘₯π‘₯ 4 − 0.15 π‘₯π‘₯ 3 − 0.5 π‘₯π‘₯ 2 − 0.25 π‘₯π‘₯ + 1.2
At x= 0.5 using finite divided difference and a step size of h= 0.25. Also find
the Ι›t
Solution: The data needed are
𝑓𝑓(π‘₯π‘₯𝑖𝑖−2 ) = 1.2
π‘₯π‘₯𝑖𝑖−2 = 0
𝑓𝑓 (π‘₯π‘₯𝑖𝑖−2 ) = 1.1035156
π‘₯π‘₯𝑖𝑖−1 = 0.25
π‘₯π‘₯𝑖𝑖 = 0.5
π‘₯π‘₯𝑖𝑖+1 = 0.75
π‘₯π‘₯𝑖𝑖+2 = 1
𝑓𝑓(π‘₯π‘₯𝑖𝑖 ) = 0.925
𝑓𝑓 (π‘₯π‘₯𝑖𝑖+1 ) = 0.6363281
𝑓𝑓 (π‘₯π‘₯𝑖𝑖+2 ) = 0.2
The forward difference of accuracy O(h2) is computed as
By calculus, the true value is -0.9125
−0.2 + 4(0.6363281) − 3(0.925)
= −0.859375
𝑓𝑓 ′(0.5) =
2(0.25)
The backward difference of accuracy O(h2) is computed as
𝑓𝑓 ′(0.5) =
3(0.925) − 4(1.1035156) + 1.2
= −0.878125
2(0.25)
The centered difference of accuracy O(h4) is computed as
𝑓𝑓 ′(0.5) =
πœ€πœ€π‘‘π‘‘ = 5.82%
πœ€πœ€π‘‘π‘‘ = 3.77%
−0.2 + 8(0.6363281) − 8(1.1035156) + 1.2
= −0.9125
12(0.25)
= 0%
πœ€πœ€π‘‘π‘‘
Learning Activity
1. Compute forward and backward difference approximations 𝑂𝑂(β„Ž)
and 𝑂𝑂(β„Ž2 ), and central difference approximations of 𝑂𝑂(β„Ž2 ) and
𝑂𝑂(β„Ž4 ), for the first derivative of
At
π‘₯π‘₯ = 25
β„Ž= 2
𝑦𝑦 = log π‘₯π‘₯
Estimate the true percent relative error for each πœ€πœ€π‘‘π‘‘ approximation.
2. Use centered difference approximations to estimate the first and
second derivatives of
𝑦𝑦 = 𝑒𝑒 π‘₯π‘₯
At
π‘₯π‘₯ = 2
β„Ž = 0.1
Employ both 𝑂𝑂(β„Ž2 ) and 𝑂𝑂(β„Ž4 ), formulas for your estimates.
Lesson 2

Numerical Integration
The Trapezoidal Rule is the most convenient method for Numerical
Integration. It approximates the area of the integral by approximating it as
trapezoids by dividing the area into parts. It corresponds to the case where
the polynomial is first order:
𝑏𝑏
𝑏𝑏
𝐼𝐼 = οΏ½ 𝑓𝑓 (π‘₯π‘₯ )𝑑𝑑𝑑𝑑 ≅ οΏ½ 𝑓𝑓1 (π‘₯π‘₯ )𝑑𝑑𝑑𝑑
π‘Žπ‘Ž
π‘Žπ‘Ž
Recall that a straight line can be represented as
𝑏𝑏
𝐼𝐼 = οΏ½ [𝑓𝑓 (π‘Žπ‘Ž) +
π‘Žπ‘Ž
𝑓𝑓 (𝑏𝑏) − 𝑓𝑓 (π‘Žπ‘Ž)
(π‘₯π‘₯ − π‘Žπ‘Ž)𝑑𝑑𝑑𝑑
𝑏𝑏 − π‘Žπ‘Ž
The result of the integration is
𝐼𝐼 = (𝑏𝑏 − π‘Žπ‘Ž)
𝑓𝑓(π‘Žπ‘Ž) + 𝑓𝑓(𝑏𝑏)
2
Which is called the trapezoidal rule.
Graphical Depiction of the Trapezoidal Rule
Single Application of Trapezoidal Rule
Integrate 𝑓𝑓(π‘₯π‘₯ ) = 0.2 + 25π‘₯π‘₯ − 200π‘₯π‘₯ 2 + 675π‘₯π‘₯ 3 − 900π‘₯π‘₯ 4 + 400π‘₯π‘₯ 5
From a=0 to b =0.8
Recall from calculus that the exact value of the integral can be
determined analytically to be 1.640533.
Solution.
𝑓𝑓 (0) = 0.2
𝑓𝑓 (0.8) = 0.232
Substituting to the trapezoidal rule formula:
𝐼𝐼 ≅ (0.8 − 0)
0.2+0.232
2
= 0.1728
Which represents an error of
𝐸𝐸𝑑𝑑 = 1.640533 − 0.1728 = 1.467733
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 as shown in Figure 1. 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.
Figure 1: Illustration of the multiple-application
trapezoidal rule. (a) Two segments, (b) three
segments, (c) four segments, and (d) five segments.
The general format and nomenclature for multipleapplication integrals
Figure 2 shows the general format and nomenclature we will use to
characterize multiple-application integrals. There are 𝑛𝑛 + 1 equally spaced
base points (π‘₯π‘₯0 , π‘₯π‘₯1 , π‘₯π‘₯2 , . . . , π‘₯π‘₯𝑛𝑛 ). Consequently, there are n segments of equal
width:
β„Ž=
𝑏𝑏 − π‘Žπ‘Ž
𝑛𝑛
If a and b are designated as x0 and xn, respectively, the total integral can be
represented as
π‘₯π‘₯1
π‘₯π‘₯2
π‘₯π‘₯𝑛𝑛
𝐼𝐼 = οΏ½ 𝑓𝑓 (π‘₯π‘₯ )𝑑𝑑𝑑𝑑 + οΏ½ 𝑓𝑓(π‘₯π‘₯ )𝑑𝑑𝑑𝑑 + β‹― . + οΏ½
π‘₯π‘₯0
π‘₯π‘₯1
π‘₯π‘₯𝑛𝑛−1
𝑓𝑓(π‘₯π‘₯ )𝑑𝑑𝑑𝑑
Substituting the trapezoidal rule for each integral yields
𝐼𝐼 = β„Ž
𝑓𝑓 (π‘₯π‘₯0 ) + 𝑓𝑓(π‘₯π‘₯1 )
𝑓𝑓 (π‘₯π‘₯1 ) + 𝑓𝑓(π‘₯π‘₯2 )
𝑓𝑓(π‘₯π‘₯𝑛𝑛−1 ) + 𝑓𝑓(π‘₯π‘₯𝑛𝑛 )
+ β„Ž
+ β‹― . +β„Ž
2
2
2
or, grouping terms,
𝑛𝑛−1
β„Ž
𝐼𝐼 = �𝑓𝑓(π‘₯π‘₯)0 + 2 οΏ½ 𝑓𝑓 (π‘₯π‘₯𝑖𝑖 ) + 𝑓𝑓(π‘₯π‘₯𝑛𝑛 )οΏ½
2
Or
𝑖𝑖−1
𝑓𝑓(π‘₯π‘₯0 ) + 2 ∑𝑛𝑛−1
𝑖𝑖−1 𝑓𝑓(π‘₯π‘₯𝑖𝑖 ) + 𝑓𝑓(π‘₯π‘₯𝑛𝑛 )
𝐼𝐼 = (𝑏𝑏 − π‘Žπ‘Ž)
2𝑛𝑛
Example:
1. Use the two-segment trapezoidal rule to estimate the integral of
𝑓𝑓(π‘₯π‘₯ ) = 0.2 + 25π‘₯π‘₯ − 200π‘₯π‘₯ 2 + 675π‘₯π‘₯ 3 − 900π‘₯π‘₯ 4 + 400π‘₯π‘₯ 5
from π‘Žπ‘Ž = 0 to 𝑏𝑏 = 0.8
Solution.
n=2
0.8 − 0
β„Ž=
2
𝑓𝑓 (0) = 0.2
𝑓𝑓(0.4) = 2.456
𝑓𝑓 (0.8) = 0.232
0.2 + 2(2.456) + 0.232
οΏ½ = 1.0688
𝐼𝐼 = 0.8 �
4
πœ€πœ€π‘‘π‘‘ = 1.640533 − 1.0688 = 0.57173
π‘‘π‘‘β„Žπ‘’π‘’π‘’π‘’
πœ€πœ€π‘‘π‘‘ = 34.9%
2. Evaluate:
1
οΏ½ π‘₯π‘₯(π‘₯π‘₯ − 1)2 𝑑𝑑𝑑𝑑
0
Approximating the area as trapezoids. In this example, it will be divided
into 5 parts.
Solving the 𝑓𝑓(π‘₯π‘₯) at each boundary
𝑓𝑓(π‘₯π‘₯) = π‘₯π‘₯(π‘₯π‘₯ − 1)2
𝑓𝑓(0) = (0)(0 − 1) 2 = 0
𝑓𝑓(0.2) = (0.2)(0.2 − 1) 2 = 0.128
𝑓𝑓(0.4) = (0.4)(0.4 − 1) 2 = 0.144
𝑓𝑓(0.6) = (0.6)(0.6 − 1) 2 = 0.096
𝑓𝑓(0.8) = (0.8)(0.8 − 1) 2 = 0.032
𝑓𝑓(1) = (1)(1 − 1) 2 = 0
𝑓𝑓(π‘₯π‘₯0 ) + 2 ∑𝑛𝑛−1
𝑖𝑖−1 𝑓𝑓(π‘₯π‘₯𝑖𝑖 ) + 𝑓𝑓(π‘₯π‘₯𝑛𝑛 )
𝐼𝐼 = (𝑏𝑏 − π‘Žπ‘Ž)
2𝑛𝑛
𝐼𝐼 = (1 − 0)(
0 + 2(0.128 + 0.144 + 0.096 + 0.032) + 0
= 0.08
2(5)
The actual integral is
Thus,
πœ€πœ€π‘‘π‘‘ = 0.0833333 − 0.08 = 0.0033333
π‘‘π‘‘β„Žπ‘’π‘’π‘’π‘’
πœ€πœ€π‘‘π‘‘ = 0.04%
Learning Activity
1. Evaluate the integral:
πœ‹πœ‹
2
οΏ½ (6 + 3𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐 )𝑑𝑑𝑑𝑑
0
a. single application of the trapezoidal rule
b. multiple-application trapezoidal rule, with n = 2 and 4
Also find the percent relative error of both methods.
2. Evaluate the integral:
2
οΏ½ (π‘₯π‘₯ 3 − 6π‘₯π‘₯ 2 + 8π‘₯π‘₯ )𝑑𝑑𝑑𝑑
0
a. single application of the trapezoidal rule
b. Using trapezoidal rule with n=6 and 8
Also find the percent relative error of both methods.

MODULE SUMMARY
Lesson 1 deals with Numerical Differentiation. The methods used to
approximate the first and second derivative of a function are through finite
differences.
Lesson 2 deals with Numerical Integration. The methods used to
approximate the integral of a function is through the use of single application
and the multiple application of the trapezoidal rule.
Congratulations!
Download