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) ο¬ve 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!