Ma · Mathematics

What Is the Approximation Formula for a Higher-Order Derivative?

Published By the 9to5Science editorial team

At a glance

  1. 1. Choose a stencil

    Select function values near the point where you want the derivative; the points and weights form a finite-difference stencil.

  2. 2. Apply the difference formula

    For an nth derivative, the nth forward difference gives a basic approximation after division by the step size raised to n.

  3. 3. Check the error

    The basic forward formula is generally first-order accurate; symmetric or wider stencils can give better accuracy.

  4. 4. Test the result

    Compare estimates at smaller step sizes or against a known derivative to check numerical error.

A higher-order derivative can be estimated from function values near the point of interest using finite differences. The general formula depends on which points you use and how accurate you need the result to be. A simple formula works for any derivative order, while carefully chosen stencils can reduce the approximation error.

The general forward-difference formula

Let f(n)(x)f^{(n)}(x) denote the nnth derivative, and let hh be a nonzero step size. The nnth forward difference is

Δhnf(x)=∑k=0n(−1)n−k(nk)f(x+kh).\Delta_h^n f(x)=\sum_{k=0}^{n}(-1)^{n-k}\binom{n}{k}f(x+kh).

Dividing by hnh^n gives the basic approximation:

f(n)(x)≈1hn∑k=0n(−1)n−k(nk)f(x+kh).f^{(n)}(x)\approx \frac{1}{h^n}\sum_{k=0}^{n}(-1)^{n-k}\binom{n}{k}f(x+kh).

For example, the first few cases are

f′(x)≈f(x+h)−f(x)h,f′′(x)≈f(x+2h)−2f(x+h)+f(x)h2,f′′′(x)≈f(x+3h)−3f(x+2h)+3f(x+h)−f(x)h3.\begin{aligned} f'(x)&\approx \frac{f(x+h)-f(x)}{h},\\ f''(x)&\approx \frac{f(x+2h)-2f(x+h)+f(x)}{h^2},\\ f'''(x)&\approx \frac{f(x+3h)-3f(x+2h)+3f(x+h)-f(x)}{h^3}. \end{aligned}

This comes from applying Taylor expansions to the function values and combining them so that lower-order terms cancel. If the function is sufficiently smooth, the forward formula has an error of order hh as hh approaches zero. Thus, halving hh typically reduces the leading error by about a factor of two, provided rounding error does not become dominant.

A more accurate central formula

The general forward formula is convenient, but it uses points on just one side of xx and is not always the most accurate choice. For the second derivative, a common symmetric stencil is

f′′(x)≈f(x+h)−2f(x)+f(x−h)h2.f''(x)\approx \frac{f(x+h)-2f(x)+f(x-h)}{h^2}.

Taylor expansion about xx shows that its leading error is proportional to h2h^2:

f(x+h)−2f(x)+f(x−h)h2=f′′(x)+h212f(4)(x)+O(h4).\frac{f(x+h)-2f(x)+f(x-h)}{h^2} =f''(x)+\frac{h^2}{12}f^{(4)}(x)+O(h^4).

The notation O(h4)O(h^4) describes terms that, under suitable smoothness assumptions, shrink at least as fast as h4h^4. The central formula is therefore second-order accurate: when hh is halved, its leading truncation error is about one quarter as large.

Worked example: approximate a second derivative

Take f(x)=x4f(x)=x^4 and estimate f′′(1)f''(1) using the central formula with h=0.1h=0.1. The exact derivative is f′′(x)=12x2f''(x)=12x^2, so f′′(1)=12f''(1)=12.

First evaluate the function at the three stencil points:

f(1.1)=1.14=1.4641,f(1)=1,f(0.9)=0.94=0.6561.f(1.1)=1.1^4=1.4641,\qquad f(1)=1,\qquad f(0.9)=0.9^4=0.6561.

Substitute these values:

f′′(1)≈1.4641−2(1)+0.6561(0.1)2=0.12020.01=12.02.\begin{aligned} f''(1)&\approx \frac{1.4641-2(1)+0.6561}{(0.1)^2}\\ &=\frac{0.1202}{0.01}=12.02. \end{aligned}

The estimate is 12.0212.02, compared with the exact value 1212. In this example the error is exactly 0.020.02: since f(4)(x)=24f^{(4)}(x)=24, the leading central-formula error is h2f(4)(1)/12=0.01⋅24/12=0.02h^2f^{(4)}(1)/12=0.01\cdot24/12=0.02.

Choosing a step size and stencil

A smaller hh reduces truncation error, but it does not always improve the computed answer. When hh is extremely small, subtracting nearly equal function values can magnify floating-point rounding error. In practice, try a few reasonable step sizes and look for estimates that stabilize. If the function can be evaluated only at points in one direction—for example, near the boundary of its domain—a forward or backward stencil may be necessary.

For higher accuracy, use more points and choose weights that cancel additional Taylor-series terms. The weights depend on the desired derivative order, accuracy, and point locations; the basic forward formula should not be assumed to have high-order accuracy just because nn is large.

Common mistakes

  • Using the wrong power of hh: For an nnth derivative, the finite-difference numerator is divided by hnh^n, not just by hh.
  • Mixing up stencil formulas: The forward second-difference formula uses xx, x+hx+h, and x+2hx+2h. The central second-difference formula uses x−hx-h, xx, and x+hx+h.
  • Ignoring the error order: The basic forward formula is generally first-order accurate; the standard central second-derivative formula is second-order accurate.
  • Making hh too small: Roundoff and cancellation can outweigh the benefit of reducing truncation error.

References

  1. Numerical Analysis, Richard L. Burden, J. Douglas Faires, and Annette M. Burden

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.