Use the method of least squares in order to find the best approximation
to a solution for the system
$$3x + y = 1\\
x − y = 2\\
x + 3y = −1$$
My Try:
$$Ax=B$$
$$\begin{bmatrix} 1 & 1 \\ 1 & -1 \\ 1 & 3 \end{bmatrix}\begin{bmatrix} x \\ y \end{bmatrix}=\begin{bmatrix} 1 \\ 2 \\ -1 \end{bmatrix}$$
First I found $A^TA$ and then $A^TB$
$$A^TA=\begin{bmatrix} 1 & 1 & 1 \\ 1 & -1 & 3 \end{bmatrix}\begin{bmatrix} 1 & 1 \\ 1 & -1 \\ 1 & 3 \end{bmatrix}=\begin{bmatrix} 3 & 3 \\ 3 & 11 \end{bmatrix}$$
and
$$A^TB=\begin{bmatrix} 1 & 1 & 1 \\ 1 & -1 & 3 \end{bmatrix}\begin{bmatrix} 1 \\ 2 \\ -1 \end{bmatrix}=\begin{bmatrix} 2 \\ -4 \end{bmatrix}$$
The I used gaussian elimination for $\begin{bmatrix} 3 & 3 & 2 \\ 3 & 11 & -4 \end{bmatrix}$ and got $x=\dfrac{17}{12},y=-\dfrac{3}{4}$.
Is this method of least squares correct?
Best Answer
Yes, the method is correct. It is more common to write it as: $$ x = (A^TA)^{-1}A^TB$$
Your calculations are right, except that you have a typo in the matrix $A$, as pointed out in the comments.