Solution (source code)

= Solution

Apply <Gaussian elimination> to the supplied nonsymmetric <matrix>,
$$
A=\begin{pmatrix}-2&1&0&1\\2&-2&0&0\\0&1&-2&1\\0&0&2&-2\end{pmatrix}.
$$
The first <pivot element> is $-2$, with <elimination multiplier> $l_{21}=2/(-2)=-1$. Perform $R_2\leftarrow R_2+R_1$, giving
$$
\begin{pmatrix}-2&1&0&1\\0&-1&0&1\\0&1&-2&1\\0&0&2&-2\end{pmatrix}.
$$
The second <pivot element> is $-1$, with <elimination multiplier> $l_{32}=-1$. Perform $R_3\leftarrow R_3+R_2$, then use the third <pivot element> $-2$ and <elimination multiplier> $l_{43}=-1$ to perform $R_4\leftarrow R_4+R_3$. The <LU factorization> is
$$
\boxed{A=LU,\qquad
L=\begin{pmatrix}1&0&0&0\\-1&1&0&0\\0&-1&1&0\\0&0&-1&1\end{pmatrix},\qquad
U=\begin{pmatrix}-2&1&0&1\\0&-1&0&1\\0&0&-2&2\\0&0&0&0\end{pmatrix}.}
$$
Here $L$ is a unit <lower triangular matrix>, hence an <invertible matrix>, and $U$ is an <upper triangular matrix>. No row interchange is needed: all three <pivot elements> used in elimination are nonzero. The final diagonal entry is zero, with an entirely zero last row; there is no further division by it. The three nonzero rows of $U$ are <linearly independent>, so \b[the <matrix rank> is $3$] and $A$ is a <singular matrix>. Direct <matrix multiplication> gives $LU=A$.