Skip to article frontmatterSkip to article content

Convergence of finite differences

All of the finite-difference formulas in the previous section based on equally spaced nodes converge as the node spacing hh decreases to zero. However, note that to discretize a function over an interval [a,b][a,b], we use h=(ba)/nh=(b-a)/n, which implies n=(ba)/h=O(h1)n=(b-a)/h=O(h^{-1}). As h0h\to 0, the total number of nodes needed grows without bound. So we would like to make hh as large as possible while still achieving some acceptable accuracy.

Although we are measuring the truncation error only at x=0x=0, it could be defined for other xx as well. The definition adjusts naturally to use f(0)f''(0) for difference formulas targeting the second derivative.

All of the finite-difference formulas given in Finite differences are convergent.

5.5.1Order of accuracy

Of major interest is the rate at which τf0\tau_f\to 0 in a convergent formula.

Hence the forward-difference formula in Example 5.5.1 has order of accuracy equal to 1; i.e., it is first-order accurate. All else being equal, a higher order of accuracy is preferred, since O(hm)O(h^m) vanishes more quickly for larger values of mm. As a rule, including more function values in a finite-difference formula (i.e., increasing the number of weights in (5.4.1)) increases the order of accuracy, as can be seen in Table 5.4.1 and Table 5.4.2.

Order of accuracy is calculated by expanding τf\tau_f in a Taylor series about h=0h=0 and ignoring all but the leading term.[1]

5.5.2Stability

The truncation error τf(h)\tau_f(h) of a finite-difference formula is dominated by a leading term O(hm)O(h^m) for an integer mm. This error decreases as h0h\to 0. However, we have not yet accounted for the effects of roundoff error. To keep matters as simple as possible, let’s consider the forward difference

δ(h)=f(x+h)f(x)h.\delta(h) = \frac{f(x+h)-f(x)}{h}.

As h0h\to 0, the numerator approaches zero even though the values f(x+h)f(x+h) and f(x)f(x) are not necessarily near zero. This is the recipe for subtractive cancellation error! In fact, finite-difference formulas are inherently ill-conditioned as h0h\to 0. To be precise, recall that the condition number for the problem of computing f(x+h)f(x)f(x+h)-f(x) is

κ(h)=max{f(x+h),f(x)}f(x+h)f(x),\kappa(h) = \frac{ \max\{\,|f(x+h)|,|f(x)|\,\} }{ |f(x+h)-f(x) | },

implying a relative error of size κ(h)ϵmach\kappa(h) \epsilon_\text{mach} in its computation. Hence the numerical value we actually compute for δ is

δ~(h)=f(x+h)f(x)h(1+κ(h)ϵmach)=δ(h)+max{f(x+h),f(x)}f(x+h)f(x)f(x+h)f(x)hϵmach.\begin{align*} \tilde{\delta}(h) &= \frac{f(x+h)-f(x)}{h}\, (1+\kappa(h)\epsilon_\text{mach}) \\ &= \delta(h) + \frac{ \max\{\,|f(x+h)|,|f(x)|\,\} }{ |f(x+h)-f(x) | }\cdot \frac{f(x+h)-f(x)}{h} \cdot \epsilon_\text{mach}.\\ \end{align*}

Hence as h0h\to 0,

δ~(h)δ(h)=max{f(x+h),f(x)}hϵmachf(x)ϵmachh1.\bigl| \tilde{\delta}(h) - \delta(h) \bigr| = \frac{ \max\{\,|f(x+h)|,|f(x)|\,\} }{ h}\,\epsilon_\text{mach} \sim |f(x)|\, \epsilon_\text{mach}\cdot h^{-1}.

Combining the truncation error and the roundoff error leads to

f(x)δ~(h)τf(h)+f(x)ϵmachh1.\bigl| f'(x) - \tilde{\delta}(h) \bigr| \le \bigl| \tau_f(h) \bigr| + \bigl|f(x) \bigr|\, \epsilon_\text{mach} \, h^{-1}.

Equation (5.5.8) indicates that while the truncation error τ vanishes as hh decreases, the roundoff error actually increases thanks to the subtractive cancellation. At some value of hh the two error contributions will be of roughly equal size. This occurs when

f(x)ϵmachh1Ch,orhKϵmach,\bigl|f(x)\bigr|\, \epsilon_\text{mach}\, h^{-1} \approx C h, \quad \text{or} \quad h \approx K \sqrt{\rule[0.05em]{0mm}{0.4em}\epsilon_\text{mach}},

for a constant KK that depends on xx and ff, but not hh. In summary, for a first-order finite-difference method, the optimum spacing between nodes is proportional to ϵmach1/2\epsilon_\text{mach}^{\,\,1/2}. (This observation explains the choice of δ in Function 4.6.1.)

For a method of truncation order mm, the details of the subtractive cancellation are a bit different, but the conclusion generalizes.

A different statement of the conclusion is that for a first-order formula, at most we can expect accuracy in only about half of the available machine digits. As mm increases, we get ever closer to using the full accuracy available. Higher-order finite-difference methods are both more efficient and less vulnerable to roundoff than low-order methods.

5.5.3Exercises

  1. ⌨ Evaluate the centered second-order finite-difference approximation to f(4π/5)f'(4\pi/5) for f(x)=cos(x3)f(x)=\cos(x^3) and h=21,22,,28h=2^{-1},2^{-2},\ldots,2^{-8}. On a log-log graph, plot the error as a function of hh and compare it graphically to second-order convergence.

  2. ✍ Derive the first two nonzero terms of the Taylor series at h=0h=0 of the truncation error τf(h)\tau_{f}(h) for the formula (5.4.3).

  3. ✍ Calculate the first nonzero term in the Taylor series of the truncation error τf(h)\tau_{f}(h) for the finite-difference formula defined by the second row of Table 5.4.2.

  4. ✍ Calculate the first nonzero term in the Taylor series of the truncation error τf(h)\tau_{f}(h) for the finite-difference formula defined by the third row of Table 5.4.2.

    only - Unknown Directive
  5. ✍ Show that the formula (5.4.12) is second-order accurate.

    only - Unknown Directive
  6. ✍ A different way to derive finite-difference formulas is the method of undetermined coefficients. Starting from (5.4.1),

    f(x)1hk=pqakf(x+kh),f'(x) \approx \frac{1}{h}\sum_{k=-p}^q a_k f(x+kh),

    let each f(x+kh)f(x+k h) be expanded in a series around h=0h=0. When the coefficients of powers of hh are collected, one obtains

    1hk=pqakf(x+kh)=b0h+b1f(x)+b2f(x)h+,\frac{1}{h} \sum_{k=-p}^q a_k f(x+kh) = \frac{b_0}{h} + b_1 f'(x) + b_2 f''(x)h + \cdots,

    where

    bi=k=pqkiak.b_i = \sum_{k=-p}^q k^i a_k.

    In order to make the result as close as possible to f(x)f'(x), we impose the conditions

    b0=0,b1=1,b2=0,b3=0,,bp+q=0.b_0 = 0,\, b_1=1,\, b_2=0,\, b_3=0,\,\ldots,\,b_{p+q}=0.

    This provides a system of linear equations for the weights.

    (a) For p=q=2p=q=2, write out the system of equations for a2a_{-2}, a1a_{-1}, a0a_0, a1a_1, a2a_2.

    (b) Verify that the coefficients from the appropriate row of Table 5.4.1 satisfy the equations you wrote down in part (a).

    (c) Derive the finite-difference formula for p=1p=1, q=2q=2 using the method of undetermined coefficients.

Footnotes
  1. The term truncation error is derived from the idea that the finite-difference formula, being finite, has to truncate the series representation and thus cannot be exactly correct for all functions.