L = del2(U,h1,...,hN) specifies
the spacing, h1,...,hN, between points in each
corresponding dimension of U. For each dimension,
specify the spacing as a scalar or a vector of coordinates. The number
of spacing inputs must equal the number of dimensions in U.

Calculate and plot the discrete Laplacian of a multivariate function.

Define the x and y domain of the function.

[x,y] = meshgrid(-5:0.25:5,-5:0.25:5);

Define the function
over this domain.

U = 1/3.*(x.^4+y.^4);

Calculate the Laplacian of this function using del2. The spacing between the points in U is equal in all directions, so you can specify a single spacing input, h.

h = 0.25;
L = 4*del2(U,h);

Analytically, the Laplacian of this function is equal to
.

Spacing in each dimension, specified as scalars or vectors.
The number of spacing inputs must be equal to the number of dimensions
in U. Each spacing input defines the spacing between
points in the corresponding dimension of U:

Use a scalar to specify a uniform spacing.

Use a vector to specify a nonuniform spacing. The
coordinate vector gives the position of each point and must have the
same number of elements as the corresponding dimension of U (a
one-to-one match of coordinates and points).

Data Types: single | double Complex Number Support: Yes

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,

For functions of more variables, U(x,y,z,...),
the discrete Laplacian del2(U) calculates second-derivatives
in each dimension,

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:

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.