About


What are finite differences?

Finite difference equations enable you to approximate a derivative using a series of points located in the vicinity of where you want to establish the derivative. By providing the finite difference stencil, a series of coefficients is calculated that approximates that difference.

For example, assume you wish to approximate the 2nd derivate using a five-point stencil centered around the point where you wish to approximate the finite difference. The finite difference stencil would then look like -2,-1,0,1,2.

The set of coefficients that corresponds to this is: -1/12, +1/3, -1/2, +1/3, -1/12.

And the equation that describes it would look like as follows:

\( \frac{\partial^{2} f}{\partial x^{2}} = \frac{ -1f(-2h) +4f(-h) -6f(0) +4f(+h) -1f(+2h)}{12 h^{2}} \)


How are finite difference coefficients calculated?

To calculate the finite difference coefficients, a Taylor approximation is made around each point in the finite difference stencil up to and including the order of the derivative to be approximated. This gives a set of N linear equations with N unknowns, being the finite difference coefficients. Such a set of equations can be solved using a linear algebra package.

This process is best explained using an example. Let us revisit the problem as shown earlier. Assume we wisth to approximate the 2nd derivate using a centered five-point stencil. In other words, we wish to establish the coefficients A-E in the following formula

\( \frac{d^{2}f}{dx^{2}} \approx A f(-2h) + B f(-h) + C f(0) + d f(h) + Ef(2h) \)

For each point in the stencil, we can expand its value using a Taylor expansions which is terminated after the term corresponding to the derivative to be approximated, as shown below

\( \begin{align} f(-2h) &\approx f(0) + \frac{f'(0)}{1!}(-2h) + \frac{f''(0)}{2!}(-2h)^{2}\\ f(-h) &\approx f(0) + \frac{f'(0)}{1!}(-h) + \frac{f''(0)}{2!}(-h)^{2}\\ f(0) &= f(0)\\ f(h) &\approx f(0) + \frac{f'(0)}{1!}(h) + \frac{f''(0)}{2!}(h)^{2}\\ f(2h) &\approx f(0) + \frac{f'(0)}{1!}(2h) + \frac{f''(0)}{2!}(2h)^{2} \end{align} \)

We now seek a set of coefficients A-E by which \( f(0) \) and \( f'(0) \) vanish and only \( f''(0) \) remains. This gives the following matrix-vector equation

\( \left( \begin{matrix} 1 & 1 & 1 & 1 & 1 \\ -2 & -1 & 0 & 1 & 2 \\ 4 & 1 & 0 & 1 & 4 \\ -8 & -1 & 0 & 1 & 8 \\ 16 & 1 & 0 & 1 & 16 \end{matrix} \right) \left( \begin{matrix} A \\ B \\ C \\ D \\ E \end{matrix} \right) = \frac{1}{h^{2}} \left( \begin{matrix} 0 \\ 0 \\ 2 \\ 0 \\ 0 \end{matrix} \right) \)

This system can be solved which gives the following set of coefficients:

\( \begin{align} A &= -\frac{1}{12} \\ B &= \frac{4}{3} \\ C &= \frac{-5}{2} \\ D &= \frac{4}{3} \\ E &= -\frac{1}{12} \end{align} \)

Links