I have something like this $$X^T A^T A X - X^T A^T B - B^T A X$$ or $$X^T A^T A X -2 X^T A^T B$$ since X and B are really vectors ($X^TA^TB=B^TAX$).
I’d like to find the X that minimizes the expression. To do that I want to have something like this $$[X-(A^TA)^{-1}A^TB]^T(A^TA)[X-(A^TA)^{-1}A^TB]-B^TA(A^TA)^{-1}A^TB$$ so that the X that minimizes the expression is $(A^TA)^{-1}A^TB$.
My question is: how does all this relate to the technique of completing the squares? How can I show the squares?
To further explain my question, it’s easy to say, if you have $a^2 + 2ab$ just add and subtract $b^2$. But how can I abstract that to matrices?
PS: I assume $A^TA$ is non singular, positive definite.