Writing the <PERSON> equation finite-difference matrix with <PERSON> boundary conditions
I am interested in solving the <PERSON> equation using the finite-difference approach. I would like to better understand how to write the matrix equation with <PERSON> boundary conditions. Would someone review the following, is it correct?
The finite-difference matrix
The <PERSON> equation,
$$ \frac{\partial^2u(x)}{\partial x^2} = d(x) $$
can be approximated by a finite-difference matrix equation,
$$ \frac{1}{(\Delta x)^2} \textbf{M}\bullet \hat u = \hat d $$
where $\textbf{M}$ is an $n \times n$ matrix and $\hat u$ and $\hat d$ are $1 \times n$ (column) vectors,
Adding a <PERSON> boundary condition
A <PERSON> boundary condition enforces a know flux at the boundary (here we apply it at the left-hand side where the boundary is at $x=0$),
$$ \frac{\partial u(x=0)}{\partial x} = \sigma $$ writing this boundary condition as a centred finite-difference,
NB. I originally made an error here, sign error and didn't divide by 2. The following has been corrected. $$ \frac{u_2 - u_0}{2\Delta x} = \sigma $$
Note the introduction of a mesh point outside the original domain ($u_0$). This term can be eliminated by introducing the second equation, $$ \frac{u_0 - 2u_1 + u_2}{(\Delta x)^2} = d_1 $$
The equation arrises from having more information because of the introduction of the new mesh point. 935
It allows us to write the double derivative of the $u_1$ as the boundary in terms of $u_0$ using a centred finite-difference.
The part I'm not sure about
Combining these two equations $u_0$ can be eliminated. To show the working, let's first re-arrange for the unknown,
$$ u_0 = -2\sigma\Delta x + u_2 \ u_0 = (\Delta x)^2 d_1 + 2 u_1 - u_2 $$
Next they are set equal and rearranged into the form,
$$ \frac{u_2 - u_1}{(\Delta x)^2} = \frac{d_1}{2} + \frac{\sigma}{\Delta x} $$
I chose this form because it is the same form as the matrix equation above. Notice that the $u$ terms are divide by $(\Delta x)^2$ both here and in the original equation. Is this the correct approach?
Finally, using this equation as the first row of the matrix,
Some final thoughts,
1. Is this final matrix correct?
2. Could I have used a better approach?
3. Is there a standard way of writing this matrix? 935