Five-point stencil

From testwiki
Jump to navigation Jump to search

Template:Short description

An illustration of the five-point stencil in one and two dimensions (top, and bottom, respectively).

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 for 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

{x2h,xh,x,x+h,x+2h}.

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:[1]

f(x)f(x+2h)+8f(x+h)8f(xh)+f(x2h)12h

The center point f(x) itself is not involved, only the four neighboring points.

Derivation

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

f(x±h)=f(x)±hf(x)+h22f(x)±h36f(3)(x)+O1±(h4).(E1±).

Evaluating (E1+)(E1) gives us

f(x+h)f(xh)=2hf(x)+h33f(3)(x)+O1(h4).(E1).

The residual term O1(h4) should be of the order of h5 instead of h4 because if the terms of h4 had been written out in (E1+) and (E1−), it can be seen that they would have canceled each other out by Template:Math. 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(x±2h)=f(x)±2hf(x)+4h22!f(x)±8h33!f(3)(x)+O2±(h4).(E2±)

and (E2+)(E2) gives us

f(x+2h)f(x2h)=4hf(x)+8h33f(3)(x)+O2(h5).(E2).

In order to eliminate the terms of ƒ(3)(x), calculate 8 × (E1) − (E2)

8f(x+h)8f(xh)f(x+2h)+f(x2h)=12hf(x)+O(h5)

thus giving the formula as above. Note: the coefficients of f in this formula, (8, -8,-1,1), 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[2]

f(x+2h)+8f(x+h)8f(xh)+f(x2h)12h=f(x)130f(5)(x)h4+O(h5)

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(x) 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

f(x)f(x+2h)+16f(x+h)30f(x)+16f(xh)f(x2h)12h2f(3)(x)f(x+2h)2f(x+h)+2f(xh)f(x2h)2h3f(4)(x)f(x+2h)4f(x+h)+6f(x)4f(xh)+f(x2h)h4

The errors in these approximations are O(hTemplate:I sup), O(hTemplate:I sup) and O(hTemplate:I sup) respectively.[2]

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

j(ξ)=i=0,ijkξxixjxi,

where the interpolation points are

x0=x2h,x1=xh,x2=x,x3=x+h,x4=x+2h.

Then, the quartic polynomial p4(x) interpolating Template:Math at these five points is

p4(x)=j=04f(xj)j(x)

and its derivative is

p4(x)=j=04f(xj)'j(x).

So, the finite difference approximation of Template:Math at the middle point Template:Math is

f(x2)=0(x2)f(x0)+1(x2)f(x1)+2(x2)f(x2)+3(x2)f(x3)+4(x2)f(x4)+O(h4)

Evaluating the derivatives of the five Lagrange polynomials at Template:Math 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 (xy) in the grid is

{(xh,y),(x,y),(x+h,y),(x,yh),(x,y+h)},

forming a pattern that is also called a quincunx. This stencil is often used to approximate the Laplacian of a function of two variables:

2f(x,y)f(xh,y)+f(x+h,y)+f(x,yh)+f(x,y+h)4f(x,y)h2.

The error in this approximation is O(h 2),[3] which may be explained as follows:

From the 3 point stencils for the second derivative of a function with respect to x and y:

2fx2=f(x+Δx,y)+f(xΔx,y)2f(x,y)Δx22f(4)(x,y)4!Δx2+2fy2=f(x,y+Δy)+f(x,yΔy)2f(x,y)Δy22f(4)(x,y)4!Δy2+

If we assume Δx=Δy=h:

2f=2fx2+2fy2=f(x+h,y)+f(xh,y)+f(x,y+h)+f(x,yh)4f(x,y)h24f(4)(x,y)4!h2+=f(x+h,y)+f(xh,y)+f(x,y+h)+f(x,yh)4f(x,y)h2+O(h2)

See also

References

Template:Reflist

  1. Template:Cite book
  2. 2.0 2.1 Abramowitz & Stegun, Table 25.2
  3. Abramowitz & Stegun, 25.3.30