Numerical Differentiation:1* Lecture (II) Chapter 7 Numerical Differentiation:1* Lecture (II) 1* Ref: “Applied Numerical Methods with MATLAB for Engineers and Scientists”, Steven Chapra, 2nd ed., Ch. 19, McGraw Hill, 2008. Dr. Jie Zou PHY 3320
Outline Numerical differentiation (2) High-accuracy differentiation formulas (3) Derivatives of unequally spaced data Dr. Jie Zou PHY 3320
High-accuracy differentiation formulas High-accuracy finite-difference formulas can be generated by including additional terms from the Taylor series expansion. An example: High-accuracy forward-difference formula for the first derivative (see derivation on the next slide) Dr. Jie Zou PHY 3320
Derivation: High-accuracy forward-difference formula for f’(x) Forward Taylor series expansion Solve for f’(x) Substitute the forward-difference approx. of f”(x) High-accuracy forward-difference formula Accuracy improved to O(h2) Dr. Jie Zou PHY 3320
Forward finite-difference formulas Note: Two versions Upper: Basic Lower: High-accuracy Dr. Jie Zou PHY 3320
Backward finite-difference formulas Note: Two versions Upper: Basic Lower: High-accuracy Dr. Jie Zou PHY 3320
Centered finite-difference formulas Note: Two versions Upper: Basic Lower: High-accuracy Dr. Jie Zou PHY 3320
Example Example 19.1 (Ref.): Repeat the computation in Example 4.4 to estimate f’(x) at x = 0.5 with a step size h = 0.25. Employ the high-accuracy formulas for the forward, centered, and backward-difference approximations. f(x) = -0.1x4 – 0.15x3 – 0.5x2 – 0.25x + 1.2 Dr. Jie Zou PHY 3320
Results (Example 19.1) True value: f’(0.5) = -0.9125 h=0.25 Backward O(h2) Centered O(h4) Forward O(h2) Estimate -0.878125 -0.9125 -0.859375 |t| 3.77% 0% 5.82% High-Accuracy formulas h=0.25 Backward O(h) Centered O(h2) Forward O(h) Estimate -0.714 -0.934 -1.155 |t| 21.7% 2.4% 26.5% Basic formulas Dr. Jie Zou PHY 3320
Derivatives of unequally spaced data Experimental data are often measured at unequal intervals. Previous formulas can be used only for equally spaced data. How to deal with unequally spaced data? One method: (i) Fit a Lagrange Interpolating Polynomial to a set of adjacent points that bracket the point at which the derivative needs to be evaluated; (ii) Differentiate the Interpolating Polynomial analytically and evaluate the derivate at the required point. Dr. Jie Zou PHY 3320
Example Example 19.3 (Ref.): As in Fig. 19.6, a temperature gradient can be measured down into the soil. The heat flux at the soil-air interface can be computed with Fourier’s law: where q(x) = heat flux (W/m2), k = coefficient of thermal conductivity for soil [=0.5 W/(m·K)], T = temperature (K), and z = distance measured down from the surface into the soil (m). Note that a positive value of the flux means that heat is transferred from the air to the soil. Use numerical differentiation to evaluate the gradient at the soil-air interface and employ this estimate to determine the heat flux into the ground Answer: f’(0) = -133.333 K/m and q(z = 0) = 66.667 W/m2. Dr. Jie Zou PHY 3320