Numerical Differentiation

Since the derivative is defined in terms of a limit, just like a limit can be approximated numerically, so too can a derivative. \[\begin{align*} f'(x) &= \lim\limits_{h \to 0} \frac{f(x+h)-f(x)}{h} \\[1em]\qquad \implies \qquad f'(x) &\approx \frac{f(x+h)-f(x)}{h}\text{ for a small value of } h \end{align*} \] This difference quotient is asymmetric, weighted to the right of \(x.\) A symmetric difference quotient provides a better approximation \(f'(x):\) \[ f'(x) \approx \frac{f(x+h)-f(x-h)}{2h}\text{ for a small value of } h \]

Both of these approximations rely on only two points; using more point can provide a better approximation. For example, the points \[ \bigl(x\!-\!2h, f(x\!-\!2h)\bigr) \qquad \bigl(x\!-\!h, f(x\!-\!h)\bigr) \qquad \bigl(x, f(x)\bigr) \qquad \bigl(x\!+\!h, f(x\!+\!h)\bigr) \qquad \bigl(x\!+\!2h, f(x\!+\!2h)\bigr) \] are referred to as a five-point stencil of \(f\) around \(x,\) and advanced calculus techniques (Taylor’s Theorem) provide us the approximation \[ f'(x) \approx \frac{f(x-2h) - 8f(x-h) + 8f(x+h) - f(x+2h)}{12h}\text{ for a small value of } h\,. \]