B8 - 2D boundary value problem
- most of the formulation is a natural extension of a 1D problem:
- a square grid with equal spacing,
- considering a vanishing lapalican of a scalar:
- on a square grid, the second derivatives are evaluated separately in each direction
- assuming
, the finite difference is:
- thinking in terms of
matrices, when in physical space - elements of the right matrix have 5 coefficients each

image: B Hnat, lecture notes
- just as for a 1D problem, writing a matrix equation, where linear algebra based solvers can be applied for numerical solutions
- so a column vector for
must be constructed - taking
in and in , giving grid points, equations and unknowns - mapping each unknown to a column index and each equation to a row index
- a single index is needed to number points on a 2D grid
- this is called row-major indexing scheme, which is standard in C
- a single memory block is allocated by malloc

image: B Hnat, lecture notes
- the matrix is tridiagonal, that can be symbolically drawn as:


image: B Hnat, lecture notes
- each rectangle is either all zeros, a diagonal matrix, or a banded matrix
- for periodic boundary conditions, there will be nonzero values in the corners
- this is tackled using the same folding approach as in 1D