RICHARDSON EXTRAPOLATION Applied Numerical Methods with MATLAB fo

21.3 RICHARDSON EXTRAPOLATION 529 In a similar fashion, Eq. 21.19 can be written for derivatives as D = 4 3 Dh 2 − 1 3 Dh 1 21.20 For centered difference approximations with Oh 2 , the application of this formula will yield a new derivative estimate of Oh 4 . EXAMPLE 21.2 Richardson Extrapolation Problem Statement. Using the same function as in Example 21.1, estimate the first de- rivative at x = 0.5 employing step sizes of h 1 = 0.5 and h 2 = 0.25. Then use Eq. 21.20 to compute an improved estimate with Richardson extrapolation. Recall that the true value is −0.9125. Solution. The first-derivative estimates can be computed with centered differences as D 0.5 = 0.2 − 1.2 1 = −1.0 ε t = −9.6 and D 0.25 = 0.6363281 − 1.103516 0.5 = −0.934375 ε t = −2.4 First Derivative Error f ′ x i = O h 2 f ′ x i = O h 4 Second Derivative f ′′ x i = O h 2 f ′′ x i = O h 4 Third Derivative f ′′′ x i = O h 2 f ′′′ x i = O h 4 Fourth Derivative f ′′′′ x i = O h 2 f ′′′′ x i = O h 4 − f x i+ 3 + 12 f x i+ 2 − 39 f x i+ 1 + 56 f x i − 39 f x i− 1 + 12 f x i− 2 − f x i− 3 6h 4 f x i+ 2 − 4 f x i+ 1 + 6 f x i − 4 f x i− 1 + f x i− 2 h 4 − f x i+ 3 + 8 f x i+ 2 − 13 f x i+ 1 + 13 f x i− 1 − 8 f x i− 2 + f x i− 3 8h 3 f x i+ 2 − 2 f x i+ 1 + 2 f x i− 1 − f x i− 2 2h 3 −f x i+ 2 + 16 f x i+ 1 − 30 f x i + 16 f x i− 1 − f x i− 2 12h 2 f x i+ 1 − 2 f x i + f x i− 1 h 2 − f x i+ 2 + 8 f x i+ 1 − 8 f x i− 1 + f x i− 2 12h f x i+ 1 − f x i− 1 2h FIGURE 21.5 Centered finite-difference formulas: two versions are presented for each derivative. The latter version incorporates more terms of the Taylor series expansion and is, consequently, more accurate. The improved estimate can be determined by applying Eq. 21.20 to give D = 4 3 −0.934375 − 1 3 −1 = −0.9125 which for the present case is exact. The previous example yielded an exact result because the function being analyzed was a fourth-order polynomial. The exact outcome was due to the fact that Richardson extrap- olation is actually equivalent to fitting a higher-order polynomial through the data and then evaluating the derivatives by centered divided differences. Thus, the present case matched the derivative of the fourth-order polynomial precisely. For most other functions, of course, this would not occur, and our derivative estimate would be improved but not exact. Conse- quently, as was the case for the application of Richardson extrapolation, the approach can be applied iteratively using a Romberg algorithm until the result falls below an acceptable error criterion.

21.4 DERIVATIVES OF UNEQUALLY SPACED DATA

The approaches discussed to this point are primarily designed to determine the derivative of a given function. For the finite-difference approximations of Sec. 21.2, the data had to be evenly spaced. For the Richardson extrapolation technique of Sec. 21.3, the data also had to be evenly spaced and generated for successively halved intervals. Such control of data spac- ing is usually available only in cases where we can use a function to generate a table of values. In contrast, empirically derived information—that is, data from experiments or field studies—are often collected at unequal intervals. Such information cannot be analyzed with the techniques discussed to this point. One way to handle nonequispaced data is to fit a Lagrange interpolating polynomial [recall Eq. 17.21] to a set of adjacent points that bracket the location value at which you want to evaluate the derivative. Remember that this polynomial does not require that the points be equispaced. The polynomial can then be differentiated analytically to yield a for- mula that can be used to estimate the derivative. For example, you can fit a second-order Lagrange polynomial to three adjacent points x , y , x 1 , y 1 , and x 2 , y 2 . Differentiating the polynomial yields: f ′ x = f x 2x − x 1 − x 2 x − x 1 x − x 2 + f x 1 2x − x − x 2 x 1 − x x 1 − x 2 + f x 2 2x − x − x 1 x 2 − x x 2 − x 1 21.21 where x is the value at which you want to estimate the derivative. Although this equation is certainly more complicated than the first-derivative approximation from Fig. 21.3 through Fig. 21.5, it has some important advantages. First, it can provide estimates anywhere within the range prescribed by the three points. Second, the points themselves do not have to be equally spaced. Third, the derivative estimate is of the same accuracy as the centered difference [Eq. 4.25]. In fact, for equispaced points, Eq. 21.21 evaluated at x = x 1 re- duces to Eq. 4.25. 21.5 DERIVATIVES AND INTEGRALS FOR DATA WITH ERRORS 531 EXAMPLE 21.3 Differentiating Unequally Spaced Data Problem Statement. As in Fig. 21.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 Table 21.1: qz = 0 = −k d T d z z =0 where qz = heat flux Wm 2 , 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 for 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 em- ploy this estimate to determine the heat flux into the ground. Solution. Equation 21.21 can be used to calculate the derivative at the air-soil interface as f ′ 0 = 13.5 20 − 0.0125 − 0.0375 0 − 0.01250 − 0.0375 + 12 20 − 0 − 0.0375 0.0125 − 00.0125 − 0.0375 + 10 20 − 0 − 0.0125 0.0375 − 00.0375 − 0.0125 = − 1440 + 1440 − 133.333 = −133.333 K m which can be used to compute qz = 0 = −0.5 W m K − 133.333 K m = 66.667 W m 2 z, cm T ⬚C 10 Air Soil 3.75 13.5 12 1.25 FIGURE 21.6 Temperature versus depth into the soil.

21.5 DERIVATIVES AND INTEGRALS FOR DATA WITH ERRORS

Aside from unequal spacing, another problem related to differentiating empirical data is that these data usually include measurement error. A shortcoming of numerical differentia- tion is that it tends to amplify errors in the data.