Differentiation-Discrete Functions Mechanical Engineering Majors Authors: Autar Kaw, Sri Harsha Garapati http://numericalmethods.eng.usf.edu Transforming Numerical Methods Education for STEM Undergraduates 4/13/2015 http://numericalmethods.eng.usf.edu 1 Differentiation – ContinuousDiscrete Functions http://numericalmethods.eng.usf.edu Forward Difference Approximation lim f x Δx f x f x Δx 0 Δx For a finite ' Δx' f x x f x f x x 3 http://numericalmethods.eng.usf.edu Graphical Representation Of Forward Difference Approximation f(x) x x+Δx Figure 1 Graphical Representation of forward difference approximation of first derivative. 4 http://numericalmethods.eng.usf.edu Example 1 To find contraction of a steel cylinder immersed in a bath of liquid nitrogen, one needs to know the thermal expansion coefficient data as a function of temperature. This data is given for steel in Table 1. a) Is the rate of change of coefficient of thermal expansion with respect to temperature more at T 80 F than at T 340 F ? b) The data given in Table 1 can be regressed to α a0 a1T a2T2 to get .α 6.0216106 6.2790109 T 1.22151011 T 2. Compare the results with part (a) if you used the regression curve to find the rate of change of the coefficient of thermal expansion with respect to temperature at .T 80 F and at T 340 F . 5 http://numericalmethods.eng.usf.edu Example 1 Cont. Table 1 Coefficient of thermal expansion as a function of temperature. 6 Temperature, T (oF) Coefficient of thermal expansion, α (in/in/oF) 80 6.47 10 40 6.24 10 −40 5.72 10 −120 −200 −280 −340 5.09 106 6 4.30 10 3.33 106 6 2.45 10 6 6 6 http://numericalmethods.eng.usf.edu Example 1 Cont. Solution a) Using the forward divided difference approximation method at T 800 F, d (Ti ) Ti 1 Ti dT T Ti 80 T 40 Ti 1 Ti T 80 40 40 7 http://numericalmethods.eng.usf.edu Example 1 Cont. d (80) 40 80 dT 40 6.24106 6.47 106 40 5.75109 in/in/F2 Using backwards divided difference approximation method at T 3400 F, d (Ti ) Ti Ti 1 dT T 8 Ti 340 T 60 Ti 1 Ti T 340 60 280 http://numericalmethods.eng.usf.edu Example 1 Cont. d (340) 340 280 dT 60 2.45106 3.33106 60 0.14667107 in/in/F2 From the above two results it is clear that the rate of change of coefficient 0 0 of thermal expansion is more at T 80 F than at T 340 F . b) Given α 6.0216106 6.2790109 T 1.22151011T 2 dα 6.279 10 9 2.443 10 11 T dT dα80 6.279109 2.4431011 80 dT 4.3246109 in/in/F2 9 http://numericalmethods.eng.usf.edu Example 1 Cont. dα 340 6.279109 2.4431011 - 340 dT 0.14585107 in/in/F2 Table 2 Summary of change in coefficient of thermal expansion using different approximations. Change in Coefficient of Thermal Expansion, Temperature, Ti 10 d Ti dT Divided Difference Approximation 2nd Order Polynomial Regression 800F 5.75 109 in / in/ o F 2 4.3246109 in / in/ oF 2 3400F 0.14667107 in / in/ oF 2 0.14585107 in / in/ oF 2 http://numericalmethods.eng.usf.edu Direct Fit Polynomials In this method, given ' n 1' data points x0 , y0 , x1 , y1 , x2 , y2 ,, xn , yn one can fit a n th order polynomial given by Pn x a0 a1x an 1xn 1 an xn To find the first derivative, Pnx dPn ( x ) a1 2a 2 x n 1a n 1 x n 2 na n x n 1 dx Similarly other derivatives can be found. 11 http://numericalmethods.eng.usf.edu Example 2-Direct Fit Polynomials To find contraction of a steel cylinder immersed in a bath of liquid nitrogen, one needs to know the thermal expansion coefficient data as a function of temperature. This data is given for steel in Table 3. a) Using the third order polynomial interpolant, find the change in coefficient of thermal expansion at T 80F and T 340F. b) The data given in Table 3 can be regressed to α a0 a1T a2T 2 to get . α 6.0216106 6.2790109 T 1.22151011 T 2 . Compare the results with part (a) if you used the regression curve to find the rate of change of the coefficient of thermal expansion with respect to temperature at T 80F and T 340F . 12 http://numericalmethods.eng.usf.edu Example 2 Cont. Table 3 Coefficient of thermal expansion as a function of temperature. 13 Temperature, T (oF) Coefficient of thermal expansion, α (in/in/oF) 80 6.47 10 40 6.24 10 −40 5.72 10 −120 −200 −280 −340 5.09 106 6 4.30 10 3.33 106 6 2.45 10 6 6 6 http://numericalmethods.eng.usf.edu Example 2-Direct Fit Polynomials cont. Solution For the third order polynomial interpolation (also called cubic interpolation), we choose the coefficient of thermal expansion given by t a0 a1T a2T 2 a3T 3 a) Change in Thermal Expansion Coefficient at 800 F : Since we want to find the rate of change in the thermal expansion 0 coefficient at T 80 F, and we are using a third order polynomial, we need 0 0 to choose the four points closest to T 80 F that also bracket T 80 F to evaluate it. The four points are T0 80 F, T1 40 F, T2 40 F, andT3 120F. To 80, To 6.47106 T1 40, T1 6.24106 T2 40, T2 5.72106 14 T3 120, T3 5.09106 http://numericalmethods.eng.usf.edu Example 2-Direct Fit Polynomials cont. such that 80 6.47 106 a0 a1 80 a2 802 a3 803 40 6.24 106 a0 a1 40 a2 402 a3 403 40 5.72 106 a0 a1 40 a2 402 a3 403 120 5.09 106 a0 a1 120 a2 1202 a3 1203 Writing the four equations in matrix form, we have 1 80 1 40 1 40 1 120 15 512000 a 0 6.47 106 1600 64000 a1 6.24 10 6 1600 64000 a 2 5.72 10 6 14400 1728000 a 3 5.09 10 6 6400 http://numericalmethods.eng.usf.edu Example 2-Direct Fit Polynomials cont. Solving the above four equations gives a0 0.59915105 a1 0.64813108 a2 0.71875 1011 Hence a3 0.11719 1013 T a0 a1T a2T 2 a3T 3 0.59915105 0.64813108 T 0.718751011T 2 0.117191013 T 3 , 120 T 80 16 http://numericalmethods.eng.usf.edu Example 2-Direct Fit Polynomials cont. Figure 2 Graph of coefficient of thermal expansion vs. temperature. 17 http://numericalmethods.eng.usf.edu Example 2-Direct Fit Polynomials cont. The change in coefficient of thermal expansion at T 800F is given by d 80 d (T ) T 80 dT dt Given that T 0.59915 10 5 0.64813 10 8 T 0.71875 10 11T 2 0.11719 10 13 T 3 , 120 T 80 d T d T dT dT d 0.59915105 0.64812108 T 0.718751011T 2 0.117191013 T 3 dt 0.64813108 1.43751011T 0.351571013 T 2 , 120 T 80 d 80 2 0.64813108 1.43751011 80 0.351571013 T 80 dT 5.5563109 in/in/F2 18 http://numericalmethods.eng.usf.edu Example 2-Direct Fit Polynomials cont. b) Change in Thermal Expansion Coefficient at 3400F: Since we want to find the rate of change in the thermal expansion 0 coefficient at T 340 F, and we are using a third order polynomial, we need to choose the four points closest to T 3400F that also bracket to T 3400F evaluate it. The four points are T0 120F, T1 200F, T2 280F, andT3 340F. To 120, To 5.09106 T1 200, T1 4.30106 T2 280, T2 3.33106 T3 340, T3 2.45106 19 http://numericalmethods.eng.usf.edu Example 2-Direct Fit Polynomials cont. Such that 120 5.09 106 a0 a1 120 a2 1202 a3 1203 200 4.30 106 a0 a1 200 a2 2002 a3 2003 280 3.33 106 a0 a1 280 a2 2802 a3 2803 340 2.45 106 a0 a1 340 a2 3402 a3 3403 Writing the four equations in matrix form, we have 1 1 1 1 20 120 14400 1728000 a 0 5.09 106 200 40000 8000000 a1 4.30 10 6 280 78400 21952000 a 2 3.33 10 6 6 340 115600 39304000 a 3 2.45 10 http://numericalmethods.eng.usf.edu Example 2-Direct Fit Polynomials cont. Solving the above four equations gives a0 0.60625 105 a1 0.74881108 a2 0.29018 1011 a3 0.186011013 Hence T a0 a1T a2T 2 a3T 3 0.60625105 0.74881108 T 0.290181011T 2 0.186011013 T 3 , 340 T 120 21 http://numericalmethods.eng.usf.edu Example 2-Direct Fit Polynomials cont. Figure 3 Graph of coefficient of thermal expansion vs. temperature. 22 http://numericalmethods.eng.usf.edu Example 2-Direct Fit Polynomials cont. 0 The change in coefficient of thermal expansion at T 340 F is given by d 340 d (T ) T 340 dT dt Given that T 0.60625105 0.74881108 T 0.290181011T 2 0.186011013 T 3 , 340 T 120 d T d T dt dt d 0.60625105 0.74881108 T 0.290181011T 2 0.186011013 T 3 dT 0.74881108 0.580361011T 0.558041013 T 2 , 340 t 120 23 http://numericalmethods.eng.usf.edu Example 2-Direct Fit Polynomials cont. d 340 2 0.74881108 0.580361011 340 0.558041013 340 dt 0.15905107 in/in/F2 Table 4 Summary of change in coefficient of thermal expansion using different approximations. Temperature, Ti 24 Change in Coefficient of Thermal Expansion, d Ti dT 3rd Order Interpolation 2nd Order Polynomial Regression 800F 5.5563109 in / in/ oF 2 4.3246109 in / in/ oF 2 3400F 0.15905107 in / in/ oF 2 0.14585107 in / in/ oF 2 http://numericalmethods.eng.usf.edu Lagrange Polynomial In this method, given x1, y1 ,, xn , yn , one can fit a n 1th order Lagrangian polynomial given by f n ( x) where ‘ n ’ in n L ( x) f ( x ) i 0 i i f n (x) stands for the n th order polynomial that approximates the function y f (x) given at (n 1) data points as x0 , y0 , x1 , y1 ,......,xn1 , yn1 , xn , yn , and n Li ( x) j 0 j i x xj xi x j Li (x) a weighting function that includes a product of (n 1) terms with terms of ji 25 omitted. http://numericalmethods.eng.usf.edu Lagrange Polynomial Cont. Then to find the first derivative, one can differentiate f n x once, and so on for other derivatives. For example, the second order Lagrange polynomial passing through x0 , y0 , x1, y1 , x2 , y2 f 2 x is x x1 x x2 f x x x0 x x2 f x x x0 x x1 f x x0 x1 x0 x2 0 x1 x0 x1 x2 1 x2 x0 x2 x1 2 Differentiating equation (2) gives 26 http://numericalmethods.eng.usf.edu Lagrange Polynomial Cont. 2 x x0 x2 2 x x0 x1 2 x x1 x2 f 2 x f x0 f x1 f x x0 x1 x0 x2 x1 x0 x1 x2 x2 x0 x2 x1 2 Differentiating again would give the second derivative as f 2x 27 2 x0 x1 x0 x2 f x0 2 x1 x0 x1 x2 f x1 2 x2 x0 x2 x1 f x2 http://numericalmethods.eng.usf.edu Example 3 To find contraction of a steel cylinder immersed in a bath of liquid nitrogen, one needs to know the thermal expansion coefficient data as a function of temperature. This data is given for steel in Table 5. a) Using the second order Lagrange polynomial interpolant, find the change in coefficient of thermal expansion at T 80F and T 340F. b) The data given in Table 5 can be regressed to α a0 a1T a2T 2 to get . α 6.0216106 6.2790109 T 1.22151011 T 2 . Compare the results with part (a) if you used the regression curve to find the rate of change of the coefficient of thermal expansion with respect to temperature at T 80F and T 340F . 28 http://numericalmethods.eng.usf.edu Example 3 Cont. Table 5 Coefficient of thermal expansion as a function of temperature. 29 Temperature, T (oF) Coefficient of thermal expansion, α (in/in/oF) 80 6.47 10 40 6.24 10 −40 5.72 10 −120 −200 −280 −340 5.09 106 6 4.30 10 3.33 106 6 2.45 10 6 6 6 http://numericalmethods.eng.usf.edu Example 3 Cont. Solution For second order Lagrangian interpolation, we choose the coefficient of thermal expansion given by T T1 T T2 T T0 T T2 T T0 T T1 (T0 ) (T1 ) (T2 ) (T ) T T T T T T T T T T T T 2 0 2 1 0 1 0 1 0 1 2 2 a) Change in the thermal expansion coefficient at 80 F : Since we want to find the rate of change in the thermal expansion coefficient at T 80 F and we are using second order Lagrangian interpolation, we need to choose the three points closest to T 80 F that also bracket to T 80 F evaluate it. The three points are T0 80 F, T1 40 F, and T2 40 F. T0 80 F, T0 6.47106 T1 40 F, T1 6.24106 T2 40 F T2 5.72106 30 http://numericalmethods.eng.usf.edu Example 3 Cont. The change in the coefficient of thermal expansion at T given by d 80 d (T ) T 80 dT dT Hence 80F is d T 2T T1 T2 T0 2T T0 T2 T1 2T T0 T1 T2 T0 T1 T0 T2 T1 T0 T1 T2 T2 T0 T2 T1 dT d 80 280 40 40 6.47106 280 80 40 6.24106 80 4080 40 40 8040 40 dT 280 80 40 5.72106 40 80 40 40 2.1567107 2.34107 2.3833108 5.5 109 in/in/F2 31 http://numericalmethods.eng.usf.edu Example 3 Cont. b) Change in the thermal expansion coefficient at 340 F : Since we want to find the rate of change in the thermal expansion coefficient at T 340 F and we are using second order Lagrangian interpolation, we need to choose the three points closest to T 340 F that also bracket to T 340 F evaluate it. The three points are T0 200F, T1 280F, and T2 340F. T0 200F, T0 4.30106 T1 280F, T1 3.33106 T2 340F T2 2.45106 The change in the coefficient of thermal expansion at given by T 340F is d 340 d (T ) T 340 dT dT 32 http://numericalmethods.eng.usf.edu Example 3 Cont. Hence d T 2T T1 T2 T0 2T T0 T2 T1 2T T0 T1 T2 T0 T1 T0 T2 T1 T0 T1 T2 T2 T0 T2 T1 dT d 340 2 340 280 340 4.30106 200 280 200 340 dT 2 340 200 280 3.33106 280 200 280 340 2 340 200 280 2.45106 340 200 340 280 2.3036108 9.7125108 5.8333108 0.15756107 in/in/F2 33 http://numericalmethods.eng.usf.edu Example 3 Cont. Table 6 Summary of change in coefficient of thermal expansion using different approximations. Temperature, Ti 80 340 34 Change in Coefficient of Thermal Expansion, d Ti dT 2nd Order Lagrange Interpolation 5.5 109 in/in/F2 0.15756107 in/in/F2 2nd Order Polynomial Regression 4.3246109 in/in/F2 0.14585107 in/in/F2 http://numericalmethods.eng.usf.edu Additional Resources For all resources on this topic such as digital audiovisual lectures, primers, textbook chapters, multiple-choice tests, worksheets in MATLAB, MATHEMATICA, MathCad and MAPLE, blogs, related physical problems, please visit http://numericalmethods.eng.usf.edu/topics/discrete_02 dif.html THE END http://numericalmethods.eng.usf.edu