fbpx
Wikipedia

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 for numerical differentiation.

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

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 ƒ of a real variable at a point x can be approximated using a five-point stencil as:[1]

 

Notice that the center point ƒ(x) itself is not involved, only the four neighboring points.

Derivation

This formula can be obtained by writing out the four Taylor series of ƒ(x ± h) and ƒ(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 ƒ(x). Actually, we have at points x + h and x − h:

 

Evaluating   gives us

 

Note that 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 ƒ(x + h) − ƒ(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

 

and   gives us

 

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

 

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]

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(h 4), O(h 2) and O(h 2) 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

 

where the interpolation points are

 

Then, the quartic polynomial   interpolating ƒ(x) at these five points is

 

and its derivative is

 

So, the finite difference approximation of ƒ ′(x) at the middle point x = x2 is

 

Evaluating the derivatives of the five Lagrange polynomials at x=x2 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

 

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(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:

 

 

If we assume  :

 

See also

References

  1. ^ Sauer, Timothy (2012). Numerical Analysis. Pearson. p. 250. ISBN 978-0-321-78367-7.
  2. ^ a b Abramowitz & Stegun, Table 25.2
  3. ^ Abramowitz & Stegun, 25.3.30

five, point, stencil, numerical, analysis, given, square, grid, dimensions, five, point, stencil, point, grid, stencil, made, point, itself, together, with, four, neighbors, used, write, finite, difference, approximations, derivatives, grid, points, example, n. 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 An illustration of the five point stencil in one and two dimensions top and bottom respectively Contents 1 In one dimension 1 1 1D first derivative 1 1 1 Derivation 1 1 2 Error estimate 1 2 1D higher order derivatives 1 3 Relationship to Lagrange interpolating polynomials 2 In two dimensions 3 See also 4 ReferencesIn one dimension EditIn 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 x 2 h x h x x h x 2 h displaystyle x 2h x h x x h x 2h 1D first derivative Edit The first derivative of a function ƒ of a real variable at a point x can be approximated using a five point stencil as 1 f x f x 2 h 8 f x h 8 f x h f x 2 h 12 h displaystyle f x approx frac f x 2h 8f x h 8f x h f x 2h 12h Notice that the center point ƒ x itself is not involved only the four neighboring points Derivation Edit This formula can be obtained by writing out the four Taylor series of ƒ x h and ƒ 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 ƒ x Actually we have at points x h and x h f x h f x h f x h 2 2 f x h 3 6 f 3 x O 1 h 4 E 1 displaystyle f x pm h f x pm hf x frac h 2 2 f x pm frac h 3 6 f 3 x O 1 pm h 4 qquad E 1 pm Evaluating E 1 E 1 displaystyle E 1 E 1 gives us f x h f x h 2 h f x h 3 3 f 3 x O 1 h 4 E 1 displaystyle f x h f x h 2hf x frac h 3 3 f 3 x O 1 h 4 qquad E 1 Note that 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 ƒ x h ƒ 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 x 2 h f x 2 h f x 4 h 2 2 f x 8 h 3 3 f 3 x O 2 h 4 E 2 displaystyle f x pm 2h f x pm 2hf x frac 4h 2 2 f x pm frac 8h 3 3 f 3 x O 2 pm h 4 qquad E 2 pm and E 2 E 2 displaystyle E 2 E 2 gives us f x 2 h f x 2 h 4 h f x 8 h 3 3 f 3 x O 2 h 4 E 2 displaystyle f x 2h f x 2h 4hf x frac 8h 3 3 f 3 x O 2 h 4 qquad E 2 In order to eliminate the terms of ƒ 3 x calculate 8 E1 E2 8 f x h 8 f x h f x 2 h f x 2 h 12 h f x O h 4 displaystyle 8f x h 8f x h f x 2h f x 2h 12hf x O h 4 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 Edit The error in this approximation is of order h 4 That can be seen from the expansion f x 2 h 8 f x h 8 f x h f x 2 h 12 h f x 1 30 f 5 x h 4 O h 5 displaystyle frac f x 2h 8f x h 8f x h f x 2h 12h f x frac 1 30 f 5 x h 4 O h 5 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 x displaystyle f x on grids with spacing 2h and h 1D higher order derivatives Edit The centered difference formulas for five point stencils approximating second third and fourth derivatives are f x f x 2 h 16 f x h 30 f x 16 f x h f x 2 h 12 h 2 displaystyle f x approx frac f x 2h 16f x h 30f x 16f x h f x 2h 12h 2 f 3 x f x 2 h 2 f x h 2 f x h f x 2 h 2 h 3 displaystyle f 3 x approx frac f x 2h 2f x h 2f x h f x 2h 2h 3 f 4 x f x 2 h 4 f x h 6 f x 4 f x h f x 2 h h 4 displaystyle f 4 x approx frac f x 2h 4f x h 6f x 4f x h f x 2h h 4 The errors in these approximations are O h 4 O h 2 and O h 2 respectively 2 Relationship to Lagrange interpolating polynomials Edit As an alternative to deriving the finite difference weights from the Taylor series they may be obtained by differentiating the Lagrange polynomials ℓ j 3 i 0 i j k 3 x i x j x i displaystyle ell j xi prod i 0 i neq j k frac xi x i x j x i where the interpolation points are x 0 x 2 h x 1 x h x 2 x x 3 x h x 4 x 2 h displaystyle x 0 x 2h quad x 1 x h quad x 2 x quad x 3 x h quad x 4 x 2h Then the quartic polynomial p 4 x displaystyle p 4 x interpolating ƒ x at these five points is p 4 x j 0 4 f x j ℓ j x displaystyle p 4 x sum limits j 0 4 f x j ell j x and its derivative is p 4 x j 0 4 f x j ℓ j x displaystyle p 4 x sum limits j 0 4 f x j ell j x So the finite difference approximation of ƒ x at the middle point x x2 is f x 2 ℓ 0 x 2 f x 0 ℓ 1 x 2 f x 1 ℓ 2 x 2 f x 2 ℓ 3 x 2 f x 3 ℓ 4 x 2 f x 4 O h 4 displaystyle f x 2 ell 0 x 2 f x 0 ell 1 x 2 f x 1 ell 2 x 2 f x 2 ell 3 x 2 f x 3 ell 4 x 2 f x 4 O h 4 Evaluating the derivatives of the five Lagrange polynomials at x x2 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 EditIn 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 x h y x y x h y x y h x y h displaystyle x h y x y x h y x y h 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 2 f x y f x h y f x h y f x y h f x y h 4 f x y h 2 displaystyle nabla 2 f x y approx frac f x h y f x h y f x y h f x y h 4f x y h 2 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 2 f x 2 f x D x y f x D x y 2 f x y D x 2 2 f 4 x y 4 D x 2 displaystyle begin array l frac partial 2 f partial x 2 frac f left x Delta x y right f left x Delta x y right 2f x y Delta x 2 2 frac f 4 x y 4 Delta x 2 cdots end array 2 f y 2 f x y D y f x y D y 2 f x y D y 2 2 f 4 x y 4 D y 2 displaystyle begin array l frac partial 2 f partial y 2 frac f left x y Delta y right f left x y Delta y right 2f x y Delta y 2 2 frac f 4 x y 4 Delta y 2 cdots end array If we assume D x D y h displaystyle Delta x Delta y h 2 f 2 f x 2 2 f y 2 f x h y f x h y f x y h f x y h 4 f x y h 2 4 f 4 x y 4 h 2 f x h y f x h y f x y h f x y h 4 f x y h 2 O h 2 displaystyle begin array ll nabla 2 f amp frac partial 2 f partial x 2 frac partial 2 f partial y 2 amp frac 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 x y h 2 4 frac f 4 x y 4 h 2 cdots amp frac 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 x y h 2 O left h 2 right end array See also EditStencil jumping Finite difference coefficients Iterative Stencil LoopsReferences Edit Sauer Timothy 2012 Numerical Analysis Pearson p 250 ISBN 978 0 321 78367 7 a b Abramowitz amp Stegun Table 25 2 Abramowitz amp Stegun 25 3 30 Abramowitz Milton Stegun Irene A 1970 Handbook of Mathematical Functions with Formulas Graphs and Mathematical Tables Dover Ninth printing Table 25 2 Retrieved from https en wikipedia org w index php title Five point stencil amp oldid 1122838221, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.