Finite Difference Matrix
Many matrices in scientific computing contain mostly zeros, particularly those arising
from the discretisation of partial differential equations (PDEs). Here we will construct
a sparse matrix using
scipy.sparse
that is derived from the finite difference
discretisation of the Poisson equation. In 1D, Poisson equation isThe central FD approximation of is:
We will discretise at regular points along from 0 to 1, given by
, :
+----+----+----------+----+> x 0 x_1 x_2 ... x_N 1
Using this set of point and the discretised equation, this gives a set of equations
at each interior point on the domain:
where .
To solve these equations we will need additional equations at and , known as
the boundary conditions. For this example we will use at and
(also known as a non-homogenous Dirichlet bc), so that , and , and the equation at becomes:
and the equation at becomes:
We can therefore represent the final equations in matrix form like so:
The relevant sparse matrix here is , given by
As you can see, the number of non-zero elements grows linearly with the size , so a
sparse matrix format is much preferred over a dense matrix holding all elements!
Additional Reading
For more on the Finite Difference Method for solving PDEs:
K. W. Morton and D. F. Mayers. Numerical Solution of Partial Differential Equations: An
Introduction. Cambridge University Press, 2005.