$A^TA=B^TB$. Is $A=QB$ for some orthogonal $Q$?

Suppose that $A$ and $B$ are two real square matrices and $A^TA=B^TB$. Can we say that $A=QB$ for some orthogonal matrix $Q$?

If they are vectors we have $\|a\|^2=a^Ta=b^Tb=\|b\|^2$, so intuitively clear, since we just have to rotate. But it is hard to picture the matrix case but I have not been able to show.


The answer is yes. In particular, it suffices to show that for every matrix $A$, there exists an orthogonal matrix $U$ such that $$ A = U \sqrt{A^TA} $$ which is to say that each matrix has a polar decomposition.


There is also a nice geometric way to see this.

The geometric interpretation of the singular value decomposition says that a $(n\times n)$-matrix $A$ maps the unit $(n-1)$-sphere in $\mathbb{R}^n$ to a hyperellipsoid. The lengths of the axes of this ellipsoid are the roots of the eigenvalues of $A^T A$.

So if $A^T A = B^T B$, the matrices $A$ and $B$ map the unit $(n-1)$-sphere to congruent hyperellipsoids. Hence $A$ and $B$ must be the same up to an orthogonal matrix, which represents the isometry that maps one hyperellipsoid into the other.