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. It is an example for numerical differentiation.
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
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
Obtaining the formula
This formula can be obtained by writing out the four Taylor series of ƒ(x ± h) and ƒ(x ± 2h) 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 ƒ ′(x). Actually, we have at points x + h and x − h:
Evaluating (E 1+) − (E 1−) gives us
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 ƒ(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).