I have the following matrix equation
$$AX=B$$
given $8 \times 3$ matrices $A$ and $B$. $X$ is a $3 \times 3$ diagonal matrix whose main diagonal contains the $3$ unknowns.
Whenever I solve for $X$ using least squares $X= (A^TA)^{-1} A^T B$, I get a square matrix that is not diagonal. Any idea on how I can force the least squares solution matrix to be diagonal?