I have read several websites trying to explain finite-differential equations, but I haven't been able to find one that explains how it's put into the matrix form.
$f(x) = -\frac{d^2u}{dx^2}$ where $u(0) = 0$ and $u(1) = 0$ becomes
$\begin{bmatrix} 2 & -1 & 0 & 0 & 0 \\ -1 & 2 & -1 & 0 & 0 \\ 0 & -1 & 2 & -1 & 0 \\ 0 & 0 & -1 & 2 & -1 \\ 0 & 0 & 0 & -1 & 2 \end{bmatrix}$
multiplied by one column of values between $u_1$ to $u_5$ is equal to
$h^2\begin{bmatrix} f(h) \\ f(2h) \\ f(3h) \\ f(4h) \\ f(5h) \end{bmatrix}$
Looking at the equation that causes this matrix, it confuses me. The difference equation is -u_{j+1}+2u_j-u_{j-1}=h^2f(jh)
The initial term, when $j=1$, should make it so that the equation is:
u_2+2u_1-u_0$
Would this not cause the first row to become (-1, 2, 0, 0, 0)$ because $u_0 has been defined as 0? I know that my thinking is wrong, since the book tells me so, but I don't understand how the first and last row is determined.
On a related note, how does the matrix equation if the boundaries are changed? For an example, if u_0 = 1$ and $u_1 = 2 on the original equation. Will the answer become
\begin{bmatrix} 2 & 0 & 0 & 0 & 0 \\ -1 & 2 & -1 & 0 & 0 \\ 0 & -1 & 2 & -1 & 0 \\ 0 & 0 & -1 & 2 & -1 \\ 0 & 0 & 0 & -1 & 2 \end{bmatrix}$