I have the two vectors $X$ and $Q$. I want to calculate the following: $(X-Q)^T(X-Q)$.
This is what I get: $X^TX - X^TQ -Q^TX + Q^TQ $
The solutions state that this can be rewritten as: $X^TX - 2Q^TX + Q^TQ$
I can't see how that could be done, is it possible somehow?
Notice that $X^T Q$ is an $1 \times 1$ matrix, and therefore $X^T Q = (X^T Q)^T = Q^T X$. Inserting this in your solution gives the desired result.