From Taylor Expansions to Difference Formulas
A derivative describes the rate at which a function changes at a point. In computation, we may know function values at nearby points but not have a convenient way to evaluate the derivative directly. A finite-difference formula estimates the derivative by combining those sampled values.
The coefficients in such a formula are not arbitrary. Taylor expansions express nearby function values in terms of derivatives at the target point. By choosing coefficients that cancel unwanted Taylor terms, we can isolate the first derivative. This coefficient-matching process derives the forward, backward, and centered formulas and also reveals what assumptions justify their accuracy.
Taylor Matching as a System of Equations
Write samples at offsets \(s_jh\) from the target \(x\) as \(f(x+s_jh)\), where the offsets \(s_j\) and coefficients \(c_j\) are fixed. Consider the combination
Assume for now that \(f\) has enough derivatives near \(x\) for the Taylor expansions and remainders being used. Expanding a sample through degree \(m\) gives
After substituting these expansions into \(D_h f(x)\), the coefficient multiplying \(f^{(k)}(x)\) is \(h^{k-1}\sum_j c_js_j^k/k!\). To make the combination estimate \(f'(x)\), we require the constant term to vanish and the coefficient of \(f'(x)\) to equal one:
Further conditions can cancel higher derivatives. For example, requiring \(\sum_j c_js_j^2=0\) cancels the \(f''(x)\) term. These equations are the Taylor-matching conditions. Once the coefficients are chosen, the remainder terms must still be controlled; their size depends on the smoothness of \(f\).
Deriving the Forward Formula
Use the two samples \(f(x)\) and \(f(x+h)\). Write a candidate formula as \(\bigl(af(x)+bf(x+h)\bigr)/h\). The offsets are \(0\) and \(1\). The constant-term condition is \(a+b=0\), and the first-derivative condition is \(b=1\). Therefore \(a=-1\), giving the forward difference.
To describe its error term explicitly, suppose \(f\) has a bounded fourth derivative in a neighborhood of \(x\). Taylor's theorem then gives
Subtract \(f(x)\) and divide by \(h\):
Thus the forward formula retains a term involving \(f''(x)\), which is generally the leading difference between the estimate and the derivative.
Worked Example: Deriving and Checking a Forward Difference
Derive the two-sample coefficients and use the formula for \(f(t)=t^3\) at \(x=1\) with \(h=0.1\).
Let the estimate be \(\bigl(af(x)+bf(x+h)\bigr)/h\). The Taylor expansion of its numerator begins with \((a+b)f(x)+bhf'(x)\). To cancel the constant term and retain \(f'(x)\), require \(a+b=0\) and \(b=1\). Hence \(b=1\) and \(a=-1\), so the formula is \(\bigl(f(x+h)-f(x)\bigr)/h\).
Here, \(f(1)=1\), \(f(1.1)=1.1^3=1.331\), and \(h=0.1\). Therefore the estimate is \((1.331-1)/0.1=0.331/0.1=3.31\). The exact derivative is \(f'(t)=3t^2\), so \(f'(1)=3\).
For a check, \(f''(1)=6\) and \(f'''(1)=6\). The Taylor expression for the estimate is \(3+(0.1/2)(6)+(0.1^2/6)(6)=3+0.3+0.01=3.31\), matching the direct calculation. Since \(f\) is a cubic polynomial, this Taylor expansion has no further terms.
Deriving the Backward Formula
Now use \(f(x-h)\) and \(f(x)\), writing the candidate as \(\bigl(af(x-h)+bf(x)\bigr)/h\). The offsets are \(-1\) and \(0\). Cancellation of the constant term gives \(a+b=0\); matching the first derivative gives \(-a=1\). Thus \(a=-1\), \(b=1\), and the backward difference is
Under the same assumption that \(f\) has a bounded fourth derivative near \(x\), expand the backward sample:
Subtract this expression from \(f(x)\), then divide by \(h\):
The sign of the term involving \(f''(x)\) is opposite to the one in the forward formula. Both formulas use values on only one side of \(x\), which can be useful when samples are available only on that side.
Worked Example: Deriving and Checking a Backward Difference
Derive the backward coefficients and apply the formula to \(f(t)=t^3\) at \(x=1\) with \(h=0.2\).
For \(\bigl(af(x-h)+bf(x)\bigr)/h\), the conditions are \(a+b=0\) and \(-a=1\). They give \(a=-1\) and \(b=1\), so the estimate is \(\bigl(f(x)-f(x-h)\bigr)/h\).
Calculate \(f(1)=1\) and \(f(0.8)=0.8^3=0.512\). The estimate is \((1-0.512)/0.2=0.488/0.2=2.44\). The exact derivative is \(f'(1)=3\).
Here, \(f''(1)=6\) and \(f'''(1)=6\). The Taylor expression gives \(3-(0.2/2)(6)+(0.2^2/6)(6)=3-0.6+0.04=2.44\). It agrees with the direct calculation; the expansion is exact because \(f\) is cubic.
Deriving the Centered Formula
For a centered formula, use the samples \(f(x-h)\), \(f(x)\), and \(f(x+h)\). Let the numerator be \(af(x-h)+bf(x)+cf(x+h)\). Matching the constant term, the first derivative, and cancellation of the second derivative gives
The last equation gives \(c=-a\). Substitution into \(-a+c=1\) gives \(-2a=1\), so \(a=-1/2\) and \(c=1/2\). Then \(b=0\). The resulting centered formula is
The cancellation of the second-derivative term is why the centered formula has a different expansion from the one-sided formulas. To justify its next remainder precisely, assume \(f\) has a bounded fifth derivative near \(x\). Expand each sample through degree four; each Taylor remainder is then \(O(h^5)\):
Subtract the second expansion from the first. The constant, second-derivative, and fourth-derivative terms cancel. The two \(O(h^5)\) remainders have a difference that is still \(O(h^5)\), so
Dividing by \(2h\) gives
Worked Example: Deriving and Checking the Centered Formula
Use the centered formula to estimate the derivative of \(f(t)=t^5\) at \(x=1\) with \(h=0.2\), and check the result against the Taylor expansion.
The coefficient equations for the numerator \(af(x-h)+bf(x)+cf(x+h)\) are \(a+b+c=0\), \(-a+c=1\), and \(a+c=0\). Solving gives \(a=-1/2\), \(b=0\), and \(c=1/2\). Dividing the numerator by \(h\) gives \(\bigl(f(x+h)-f(x-h)\bigr)/(2h)\).
Evaluate \(f(1.2)=1.2^5=2.48832\) and \(f(0.8)=0.8^5=0.32768\). Their difference is \(2.48832-0.32768=2.16064\), and \(2h=0.4\). Thus the estimate is \(2.16064/0.4=5.4016\). The exact derivative is \(f'(t)=5t^4\), so \(f'(1)=5\).
For a check, \(f'''(t)=60t^2\), so \(f'''(1)=60\); also \(f^{(5)}(t)=120\). The Taylor expansion of the centered estimate for this degree-five polynomial is \(f'(1)+(h^2/6)f'''(1)+(h^4/120)f^{(5)}(1)\). Substitution gives \(5+(0.04/6)(60)+(0.0016/120)(120)=5+0.4+0.0016=5.4016\), as calculated from the samples.
A Remainder Pitfall
Cancellation of displayed Taylor terms does not automatically mean that the remainder terms cancel to a higher order. Each remainder must be justified at the order claimed. For instance, expansions only through the third derivative with separate \(O(h^4)\) remainders justify at most an \(O(h^4)\) remainder after subtraction; they do not by themselves justify \(O(h^5)\).
For a concrete example, let \(f(t)=\max(t,0)^4\) and take \(x=0\). Its value and first three derivatives at zero are all zero. For \(h>0\), \(f(h)=h^4\) and \(f(-h)=0\). Each sample is consistent with a Taylor expansion through degree three with an \(O(h^4)\) remainder, but their difference is \(h^4\), which is not \(O(h^5)\). The centered derivative estimate is \(h^4/(2h)=h^3/2\), not \(O(h^4)\). To obtain the stronger centered remainder above, the proof instead assumes a bounded fifth derivative and expands each sample through degree four with an \(O(h^5)\) remainder before subtracting.
How the Three Formulas Differ
| Formula | Samples used | First displayed correction |
|---|---|---|
| Forward | \(f(x)\), \(f(x+h)\) | \((h/2)f''(x)\) |
| Backward | \(f(x-h)\), \(f(x)\) | \(-(h/2)f''(x)\) |
| Centered | \(f(x-h)\), \(f(x+h)\) | \((h^2/6)f'''(x)\) |
The table summarizes the displayed Taylor expansions under the smoothness assumptions stated above. It emphasizes the role of coefficient matching: the centered formula cancels the second-derivative term, while the one-sided formulas do not. The choice of formula also depends on which sample points are available. Questions about balancing approximation error against rounding effects are a separate issue.
Check Your Understanding
Use the coefficient equations and Taylor expansions to answer these questions.
- For a candidate two-sample formula \(\bigl(af(x)+bf(x+h)\bigr)/h\), which two equations make it estimate \(f'(x)\)?
- Derive the coefficient conditions for the backward formula using samples at \(x-h\) and \(x\).
- Which additional Taylor term does the three-point centered formula cancel that the one-sided formulas generally retain?
- Why does a pair of \(O(h^4)\) Taylor remainders not necessarily have a difference of \(O(h^5)\)?
- What smoothness condition in the centered derivation justifies the \(O(h^4)\) remainder after division by \(2h\)?