I have the following matrix of the 1D LaPlacian with zero Dirichlet BC:
\begin{equation} A=\frac{1}{h^{2}}\left[\begin{array}{cccccc} 2 & -1 & 0 & 0 & \ldots & 0 \\ -1 & 2 & -1 & 0 & \ldots & 0 \\ \vdots & & & & & \vdots \\ 0 & & & & & -1 \\ 0 & 0 & 0 & 0 & -1 & 2 \end{array}\right] \end{equation}
This matrix comes from $D$. Where D is the sparse matrix of the first order derivative backward.
\begin{equation} A=D^{T} D \end{equation}
I know how to construct this matrix $D$ for Dirichlet boundaries, but I have to work with zero Neumann boundaries now, So I matrix $A$ will also be different.
I sketched the sitation on paper.
- $\frac{x_0-x_{-1}}{h} = 0\\$
- $\frac{x_1-x_0}{h}$
- $\frac{x_2-x_1}{h}$
- $\frac{x_N-x_2}{h} = 0 $
With $x_{-1}$ and $x_N$ as imaginary points.
Question: How do I construct the matrix D?
Ter
$D$ is the matrix whose input is the vector of values $(x_0,\dots,x_{N-1})$ and whose output is the vector of backward differences $dx = \frac 1 h(d x_0,\dots,d x_{N-1})$, where $\Delta x_i = \frac 1h(x_i - x_{i-1})$. We have $$ d x_0 = 0, \quad d x_1 = (x_1 - x_0)/h, \dots, \Delta x_{N-1} = (x_{N-1} - x_{N-2})/h. $$ In matrix form, we have $$ \pmatrix{dx_0 \\ dx_1\\ dx_2 \\ \vdots \\ dx_{N-1}} = \frac 1h \pmatrix{0 & 0 & 0&\cdots & 0\\ -1 & 1 &0& \cdots & 0\\ 0 & -1 & 1 & & 0\\ \vdots & & \ddots & \ddots & \vdots\\ 0 & 0 & \cdots & -1 & 1 } \pmatrix{x_0\\ x_1 \\ x_2 \\ \vdots \\ x_{N-1}}. $$ This matrix is exactly the $D$ that we are looking for.