Ma · Mathematics

What Is the 9-Point Finite-Difference Stencil for the Laplacian?

Published By the 9to5Science editorial team

At a glance

  1. 1. Set the grid spacing

    Assume a uniform square grid with spacing h in both coordinate directions.

  2. 2. Place the neighbors

    Use the center point, its four horizontal and vertical neighbors, and its four diagonal neighbors.

  3. 3. Apply the weights

    Weight the center by minus twenty, axial neighbors by four, and diagonal neighbors by one; divide by six h squared.

  4. 4. Check the accuracy

    The formula is second-order accurate and has a rotationally symmetric leading error term.

For a smooth function u(x,y)u(x,y) sampled on a uniform square grid of spacing hh, the standard 9-point stencil approximates the two-dimensional Laplacian, Δu=uxx+uyy\Delta u=u_{xx}+u_{yy}. It uses the grid point itself, four neighbors sharing an edge with it, and four diagonal neighbors.

The formula is useful when you want a compact discrete Laplacian with a more directionally balanced error than the familiar 5-point stencil. It is still a second-order approximation, not a fourth-order one.

The 9-point formula

Write ui,j=u(xi,yj)u_{i,j}=u(x_i,y_j), where neighboring grid points are separated by hh in each coordinate. Then

Δh(9)ui,j=16h2[4(ui+1,j+ui−1,j+ui,j+1+ui,j−1)+ui+1,j+1+ui+1,j−1+ui−1,j+1+ui−1,j−1−20ui,j].\Delta_h^{(9)}u_{i,j}=\frac{1}{6h^2}\left[4\left(u_{i+1,j}+u_{i-1,j}+u_{i,j+1}+u_{i,j-1}\right)+u_{i+1,j+1}+u_{i+1,j-1}+u_{i-1,j+1}+u_{i-1,j-1}-20u_{i,j}\right].

The corresponding weights are arranged as

16h2[1414−204141].\frac{1}{6h^2} \begin{bmatrix} 1 & 4 & 1\\ 4 & -20 & 4\\ 1 & 4 & 1 \end{bmatrix}.

The center coefficient is negative because the Laplacian measures curvature: for a function with a local minimum, the discrete value is typically positive. If your equation uses the negative Laplacian, −Δu-\Delta u, reverse all the signs.

Why these coefficients work

Taylor-expand the values at the neighboring points around (xi,yj)(x_i,y_j). The sum of the four axial values contributes 4u+h2Δu4u+h^2\Delta u to the first relevant terms; the sum of the four diagonal values contributes 4u+2h2Δu4u+2h^2\Delta u. Therefore, multiplying the axial sum by 4 and adding the diagonal sum gives 20u+6h2Δu20u+6h^2\Delta u at leading order. Subtracting 20u20u cancels the constant term, and division by 6h26h^2 leaves the Laplacian.

Keeping the next nonzero Taylor terms gives

Δh(9)u=Δu+h212Δ2u+O(h4),\Delta_h^{(9)}u=\Delta u+\frac{h^2}{12}\Delta^2u+O(h^4),

for a sufficiently smooth function. Here Δ2u=Δ(Δu)=uxxxx+2uxxyy+uyyyy\Delta^2u=\Delta(\Delta u)=u_{xxxx}+2u_{xxyy}+u_{yyyy}. The leading error is thus rotationally symmetric: it involves the same combination of fourth derivatives as applying the Laplacian twice. This is the main accuracy advantage over the standard 5-point stencil, whose leading error depends separately on uxxxxu_{xxxx} and uyyyyu_{yyyy}.

The formula is second-order accurate because its leading error is proportional to h2h^2. The symmetry does not make it fourth-order accurate.

Worked example

Take u(x,y)=x2+y2u(x,y)=x^2+y^2 and evaluate the stencil at the origin. The exact Laplacian is Δu=2+2=4\Delta u=2+2=4. At the origin the center value is 0, every axial neighbor has value h2h^2, and every diagonal neighbor has value 2h22h^2. Substitution gives

Δh(9)u(0,0)=4(4h2)+4(2h2)−20(0)6h2=24h26h2=4.\Delta_h^{(9)}u(0,0)=\frac{4(4h^2)+4(2h^2)-20(0)}{6h^2}=\frac{24h^2}{6h^2}=4.

So the stencil reproduces the exact Laplacian for this quadratic function. This check also confirms the denominator and the distinction between the axial and diagonal weights.

Relation to the 5-point stencil

The common 5-point formula uses only the center and four axial neighbors:

Δh(5)ui,j=ui+1,j+ui−1,j+ui,j+1+ui,j−1−4ui,jh2.\Delta_h^{(5)}u_{i,j}=\frac{u_{i+1,j}+u_{i-1,j}+u_{i,j+1}+u_{i,j-1}-4u_{i,j}}{h^2}.

Both formulas are second-order accurate. The 9-point formula incorporates diagonal information and has a more isotropic leading truncation error, which can be helpful when the solution or geometry has no preferred grid direction. The best choice still depends on the equation, boundary treatment, and desired discrete properties.

Common mistakes

  • Using the 5-point denominator: the 9-point weights shown here require division by 6h26h^2, not h2h^2.
  • Giving diagonal and axial neighbors the same weight: axial neighbors have coefficient 4; diagonals have coefficient 1.
  • Calling it fourth-order accurate: the displayed approximation has an O(h2)O(h^2) error. Some higher-order Poisson schemes use wider or modified stencils, or combine a discrete Laplacian with a correspondingly weighted right-hand side; those are different formulas.
  • Applying square-grid weights to unequal spacings: this expression assumes the same spacing in both directions. A rectangular grid needs adjusted coefficients or a separately derived stencil.
  • Forgetting boundary values: near a domain boundary, some neighbors may lie outside the domain. Their values must be supplied or handled through an appropriate boundary-condition or ghost-point treatment; the interior stencil alone does not specify that treatment.

References

  1. Randall J. LeVeque, Finite Difference Methods for Ordinary and Partial Differential Equations
  2. John C. Strikwerda, Finite Difference Schemes and Partial Differential Equations

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.