If a matrix `U`

is a function *U(x,y)* that
is evaluated at the points of a square grid, then `4*del2(U)`

is
a finite difference approximation of Laplace's differential operator
applied to *U*,

$$L=\frac{\Delta U}{4}=\frac{1}{4}\left(\frac{{\partial}^{2}U}{\partial {x}^{2}}+\frac{{\partial}^{2}U}{\partial {y}^{2}}\right).$$

For functions of more variables, *U(x,y,z,...)*,
the discrete Laplacian `del2(U)`

calculates second-derivatives
in each dimension,

$$L=\frac{\Delta U}{2N}=\frac{1}{2N}\left(\frac{{\partial}^{2}U}{\partial {x}^{2}}+\frac{{\partial}^{2}U}{\partial {y}^{2}}+\frac{{\partial}^{2}U}{\partial {z}^{2}}+\mathrm{...}\right),$$

where *N* is the number of dimensions in *U* and $$N\ge 2$$.

If the input `U`

is a matrix, the interior
points of `L`

are found by taking the difference
between a point in `U`

and the average of its four
neighbors:

$${L}_{ij}=\left[\frac{\left({u}_{i+1,j}+{u}_{i-1,j}+{u}_{i,j+1}+{u}_{i,j-1}\right)}{4}-{u}_{i,j}\right]\text{\hspace{0.17em}}.$$

Then, `del2`

calculates the values on the edges
of `L`

by linearly extrapolating the second differences
from the interior. This formula is extended for multidimensional `U`

.