Five-point stencil


In numerical analysis, given a square grid in one or two dimensions, the five-point stencil of a point in the grid is a stencil made up of the point itself together with its four "neighbors". It is used to write finite difference approximations to derivatives at grid points. It is an example of numerical differentiation.

In one dimension

In one dimension, if the spacing between points in the grid is h, then the five-point stencil of a point x in the grid is

1D first derivative

The first derivative of a function f of a real variable at a point x can be approximated using a five-point stencil as:
The center point f itself is not involved, only the four neighboring points.

Derivation

This formula can be obtained by writing out the four Taylor series of and at the point, up to terms of h3, evaluating each series at and respectively, and solving this system of four equations to get f ′. Actually, we have at points x + h and xh:
Evaluating gives us
The residual term O1 should be of the order of h5 instead of h4 because if the terms of h4 had been written out in and, it can be seen that they would have canceled each other out by. But for this calculation, it is left like that since the order of error estimation is not treated here.
Similarly, we have
and gives us
In order to eliminate the terms of ƒ, calculate 8 × −
thus giving the formula as above. Note: the coefficients of f in this formula,, represent a specific example of the more general Savitzky–Golay filter.

Error estimate

The error in this approximation is of order h 4. That can be seen from the expansion
which can be obtained by expanding the left-hand side in a Taylor series. Alternatively, apply Richardson extrapolation to the central difference approximation to on grids with spacing 2h and h.

1D higher-order derivatives

The centered difference formulas for five-point stencils approximating second, third, and fourth derivatives are
The errors in these approximations are O, O and O respectively.

Relationship to Lagrange interpolating polynomials

As an alternative to deriving the finite difference weights from the Taylor series, they may be obtained by differentiating the Lagrange polynomials
where the interpolation points are
Then, the quartic polynomial interpolating at these five points is
and its derivative is
So, the finite difference approximation of at the middle point is
Evaluating the derivatives of the five Lagrange polynomials at gives the same weights as above. This method can be more flexible as the extension to a non-uniform grid is quite straightforward.

In two dimensions

In two dimensions, if for example the size of the squares in the grid is h by h, the five point stencil of a point in the grid is
forming a pattern that is also called a quincunx. This stencil is often used to approximate the Laplacian of a function of two variables:
The error in this approximation is O, which may be explained as follows:
From the 3 point stencils for the second derivative of a function with respect to x and y:
If we assume :