Least square solution of a matrix Determine the least squares solution to the system
$$\begin{pmatrix} 1 & 2 & 1 \\ 1&3&2\\2&5&3\\2&0&1 \\ 3 &1&1\end{pmatrix}\begin{pmatrix}a\\b\\c\end{pmatrix}=\begin{pmatrix}-1\\2\\0\\1\\-2\end{pmatrix}$$
So the previous equation was Ax = B
To find the least square regression we need $(A^tA)^{-1}A^t B = x$ wherein the regression line is $ y=x_i+x_{i+1}+...+x_{n}$
The problem is:
A=
$\begin{pmatrix} 1 & 2 & 1 \\ 1&3&2\\2&5&3\\2&0&1 \\ 3 &1&1\end{pmatrix}$
$A^{t}$ =
$\begin{pmatrix} 1 & 1 & 2&2&3 \\ 2&3&5&0&1\\1&2&3&1&1\end{pmatrix}$
$(A^{t}A)$=$\begin{pmatrix} 6 & 9 & 15&3&6 \\ 9&14&23&4&8\\15&23&38&7&14\\3&4&7&5&7\\6&8&14&7&11\end{pmatrix}$
This is the problem:
$(A^{t}A)^{-1}$ = singular

You have computed $AA^T$, not $A^TA$.  The correct $A^TA$ should be:
$$\left(\begin{array}\\
19 & 18 & 14 \\
18 & 39 & 24 \\
13 & 24 & 16
\end{array}\right)$$
