numgrid

Numbers the points of a two-dimensional grid region.

Category: Other public functions: sparfun

Syntax

G = numgrid(region, n)

Returns an n-by-n matrix that numbers the interior points of the region and has zeros elsewhere.

Description

The numbering says which unknowns a finite-difference method on that region will have, and in which order. Pass G to delsq to get the matching Laplacian. Boundary points are not numbered, because their values are known in a Dirichlet problem.

Input arguments

region
'S' square, 'L' L-shape, 'C' circle, 'D' disk, 'A' annulus or 'H' hexagon.
n
Number of points per side of the enclosing square.

Output arguments

G
Integer matrix. Interior points are numbered 1, 2, ... down the columns; boundary and outside points are 0.

Example

L-shaped region

G = numgrid('L', 6)
Output
G = 6×6

     0     0     0     0     0     0
     0     1     3     5     9     0
     0     2     4     6    10     0
     0     0     0     7    11     0
     0     0     0     8    12     0
     0     0     0     0     0     0

See also

delsq gallery meshgrid spy