delsq
Discrete Laplacian on a grid, as a sparse matrix.
Category: Other public functions: sparfun
Syntax
L = delsq(G)
Builds the five-point Laplacian for the grid numbered by G, with Dirichlet boundary.
Description
For each interior point, row k of L holds 4 on the diagonal and -1 in the column of every neighbor that is also interior. This is the matrix of the finite-difference approximation of the Laplace operator, scaled by the squared grid spacing. Combined with numgrid it gives test matrices for the Poisson equation on a square, L-shape or disk.
Input arguments
G- Grid numbering from
numgrid: nonzero entries number the interior points, zeros are outside.
Output arguments
L- Sparse matrix with 4 on the diagonal and -1 for each neighbor.
Example
Square grid
G = numgrid('S', 4);
L = full(delsq(G))
Output
L = 4×4
4 -1 -1 0
-1 4 0 -1
-1 0 4 -1
0 -1 -1 4