# Five-point stencil

﻿
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 made up of the point itself together with its four "neighbors". It is used to write finite difference approximations to derivatives at grid points.

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

:$\left\{x-2h, x-h, x, x+h, x+2h\right\}.$

First derivative

The first derivative of a function &fnof; of a real variable at a point "x" can be approximated using a five-point stencil as

:$f\text{'}\left(x\right) approx frac\left\{-f\left(x+2 h\right)+8 f\left(x+h\right)-8 f\left(x-h\right)+f\left(x-2h\right)\right\}\left\{12 h\right\}$

Obtaining the formula

This formula can be obtained by writing out the four Taylor series of &fnof;("x" ± "h") and &fnof;("x" ± 2"h") up to terms of "h" 3 (or up to terms of "h" 5 to get an error estimation as well) and solving this system of four equations to get &fnof; &prime;("x"). Actually, we have at points "x" + "h" and "x" − "h":

:$f\left(x pm h\right) = f\left(x\right) pm h f\text{'}\left(x\right) + frac\left\{h^2\right\}\left\{2\right\}f"\left(x\right) pm frac\left\{h^3\right\}\left\{6\right\} f^\left\{\left(3\right)\right\}\left(x\right) + O_\left\{1pm\right\}\left(h^4\right). qquad \left(E_\left\{1pm\right\}\right).$

Evaluating ("E" 1+) − ("E" 1−) gives us

:$f\left(x+h\right) - f\left(x-h\right) = 2hf\text{'}\left(x\right) + frac\left\{h^3\right\}\left\{3\right\}f^\left\{\left(3\right)\right\}\left(x\right) + O_1\left(h^4\right). qquad \left(E_1\right).$

Note that the residual term O1("h" 4) should be of the order of "h" 5 instead of "h" 4 because if the terms of "h" 4 had been written out in ("E" 1+) and ("E" 1−), it can be seen that they would have canceled each other out by &fnof;("x" + "h") − &fnof;("x" − "h"). But for this calculation, it is left like that since the order of error estimation is not treated here (cf below).

Similarly, we have

:$f\left(x pm 2h\right) = f\left(x\right) pm 2h f\text{'}\left(x\right) + 2h^2 f"\left(x\right) pm frac\left\{4h^3\right\}\left\{3\right\} f^\left\{\left(3\right)\right\}\left(x\right) + O_\left\{2pm\right\}\left(h^4\right). qquad \left(E_\left\{2pm\right\}\right)$

: $\left(E_\left\{2+\right\}\right)-\left(E_\left\{2-\right\}\right)$

gives us

:$f\left(x+2h\right) - f\left(x-2h\right) = 4hf\text{'}\left(x\right) + frac\left\{8h^3\right\}\left\{3\right\}f^\left\{\left(3\right)\right\}\left(x\right) + O_2\left(h^4\right). qquad \left(E_2\right).$

In order to eliminate the terms of &fnof; (3)("x"), calculate 8 &times; ("E"1) − ("E"2)

:$8f\left(x+h\right) - 8f\left(x-h\right) - f\left(x+2h\right) + f\left(x-2h\right) = 12h f\text{'}\left(x\right) + O\left(h^4\right) ,$

thus giving the formula as above.

Estimated error

The error in this approximation is of order "h" 4. That can be seen from the expansion

:$frac\left\{-f\left(x+2 h\right)+8 f\left(x+h\right)-8 f\left(x-h\right)+f\left(x-2h\right)\right\}\left\{12 h\right\}=f\text{'}\left(x\right)-frac\left\{1\right\}\left\{30\right\} f^\left\{\left(5\right)\right\}\left(x\right) h^4+O\left(h^5\right)$ Abramowitz & Stegun, Table 25.2]

which can be obtained by expanding the left-hand side in a Taylor series. Alternatively, apply Richardson extrapolation to the central difference approximation to $f\text{'}\left(x\right)$ on grids with spacing 2"h" and "h".

Higher derivatives

The centered difference formulas for five-point stencils approximating second, third, and fourth derivatives are

:

Estimated errors

The errors in these approximations are "O"("h" 4), "O"("h" 2) and "O"("h" 2) 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

:$ell_j\left(xi\right) = prod_\left\{i=0,, i eq j\right\}^\left\{k\right\} frac\left\{xi-x_i\right\}\left\{x_j-x_i\right\},$

where the interpolation points are

:

Then, the quartic polynomial $p_4\left(x\right)$ interpolating &fnof;("x") at these five points is

:

and its derivative is

:

So, the finite difference approximation of &fnof; &prime;("x") at the middle point "x" = "x"2 is

:

Evaluating the derivatives of the five Lagrange polynomials at "x"="x"2 gives the same weights as above. This method can be more flexible as the extension to a non-uniform grid is quite straightforward.

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 ("x", "y") in the grid is

:$\left\{\left(x-h, y\right), \left(x, y\right), \left(x+h, y\right), \left(x, y-h\right), \left(x, y+h\right)\right\}. ,$

This stencil is often used to approximate the Laplacian of a function of two variables:

:$Delta f\left(x,y\right) approx frac\left\{f\left(x-h,y\right) + f\left(x+h,y\right) + f\left(x,y-h\right) + f\left(x,y+h\right) - 4f\left(x,y\right)\right\}\left\{h^2\right\}.$

The error in this approximation is "O"("h" 2). [Abramowitz & Stegun, 25.3.30]

ee also

* Stencil jumping

Notes

References

*. Ninth printing. Table 25.2.

Wikimedia Foundation. 2010.

### Look at other dictionaries:

• Stencil jumping — Stencil jumping, at times called stencil walking, is an algorithm to locate the grid element enclosing a given point for any structured mesh. In simple words, given a point and a structured mesh, this algorithm will help locate the grid element… …   Wikipedia

• Stencil codes — are computer codes that update array elements according to some fixed pattern, called stencils,Sloot, Peter M.A. et al. (May 28, 2002) [http://books.google.com/books?id=qVcLw1UAFUsC pg=PA843 dq=stencil+array sig=g3gYXncOThX56TUBfHE7hnlSxJg#PPA843 …   Wikipedia

• Five Points — may be:Census recognized communities in the U.S.: *Five Points, Alabama *Five Points, Florida *Five Points, North Carolina *Five Points, Ohio *Five Points, PennsylvaniaU.S. and Canadian neighborhoods: *Five Points (Athens), in Athens, Georgia… …   Wikipedia

• Stencil (numerical analysis) — In mathematics, especially the areas of numerical analysis concentrating on the numerical solution of partial differential equations, a stencil is a geometric arrangement of a nodal group that relate to the point of interest by using a numerical… …   Wikipedia

• Point — Point, n. [F. point, and probably also pointe, L. punctum, puncta, fr. pungere, punctum, to prick. See {Pungent}, and cf. {Puncto}, {Puncture}.] 1. That which pricks or pierces; the sharp end of anything, esp. the sharp end of a piercing… …   The Collaborative International Dictionary of English

• Point lace — Point Point, n. [F. point, and probably also pointe, L. punctum, puncta, fr. pungere, punctum, to prick. See {Pungent}, and cf. {Puncto}, {Puncture}.] 1. That which pricks or pierces; the sharp end of anything, esp. the sharp end of a piercing… …   The Collaborative International Dictionary of English

• Point net — Point Point, n. [F. point, and probably also pointe, L. punctum, puncta, fr. pungere, punctum, to prick. See {Pungent}, and cf. {Puncto}, {Puncture}.] 1. That which pricks or pierces; the sharp end of anything, esp. the sharp end of a piercing… …   The Collaborative International Dictionary of English

• Point of concurrence — Point Point, n. [F. point, and probably also pointe, L. punctum, puncta, fr. pungere, punctum, to prick. See {Pungent}, and cf. {Puncto}, {Puncture}.] 1. That which pricks or pierces; the sharp end of anything, esp. the sharp end of a piercing… …   The Collaborative International Dictionary of English

• Point of contrary flexure — Point Point, n. [F. point, and probably also pointe, L. punctum, puncta, fr. pungere, punctum, to prick. See {Pungent}, and cf. {Puncto}, {Puncture}.] 1. That which pricks or pierces; the sharp end of anything, esp. the sharp end of a piercing… …   The Collaborative International Dictionary of English

• Point of order — Point Point, n. [F. point, and probably also pointe, L. punctum, puncta, fr. pungere, punctum, to prick. See {Pungent}, and cf. {Puncto}, {Puncture}.] 1. That which pricks or pierces; the sharp end of anything, esp. the sharp end of a piercing… …   The Collaborative International Dictionary of English