<s>[INST] Polar decomposition of a general matrix How can I calculate the polar decomposition for a general matrix? For example for this simple one:
$$
    \begin{pmatrix}
    a & -b  \\
    b & a  \\
    \end{pmatrix}
$$
I know how to calculate it for a matrix with numbers, via eigenvalues, eigenvectors. I have been searching for the answer on the internet for a while but I don't fully understand it.
 [/INST] So first let $A = \begin{pmatrix}a&-b\\b&a\end{pmatrix}=QS$.
Then, we have $A^{T}A=\begin{pmatrix}a&b\\-b&a\end{pmatrix}\begin{pmatrix}a&-b\\b&a\end{pmatrix}=\begin{pmatrix}a^2+b^2&0\\0&a^2+b^2\end{pmatrix}$.
The Eigenvalue(s) of this matrix is $a^2+b^2$, sometimes they're different but not too hard to handle.
The Eigenvectors are $\begin{pmatrix}1\\0 \end{pmatrix}$ and $\begin{pmatrix}0\\1 \end{pmatrix}$.
So then we can write $A^TA=\begin{pmatrix}1&0\\0&1\end{pmatrix}\begin{pmatrix}a^2+b^2&0\\0&a^2+b^2\end{pmatrix}\begin{pmatrix}1&0\\0&1\end{pmatrix}^{-1}$.
The first factor is just the Eigenvectors, the second is a diagonal matrix consisting of each of the corresponding eigenvalues, and the third is the inverse of the first.
We now define a second matrix $S=\begin{pmatrix}1&0\\0&1\end{pmatrix}\begin{pmatrix}\sqrt{a^2+b^2}&0\\0&\sqrt{a^2+b^2}\end{pmatrix}\begin{pmatrix}1&0\\0&1\end{pmatrix}^{-1}$.
The only difference here is that $S$ is constructed using the singular values, which are basically the square roots of the eigenvalues.
We have that $S=\begin{pmatrix}\sqrt{a^2+b^2}&0\\0&\sqrt{a^2+b^2}\end{pmatrix}$.
We also have that $Q=AS^{-1}= \begin{pmatrix}a&-b\\b&a\end{pmatrix}\begin{pmatrix}\sqrt{a^2+b^2}&0\\0&\sqrt{a^2+b^2}\end{pmatrix}^{-1}=\begin{pmatrix}\frac{a}{\sqrt{a^2+b^2}}&-\frac{b}{\sqrt{a^2+b^2}}\\\frac{b}{\sqrt{a^2+b^2}}&\frac{a}{\sqrt{a^2+b^2}}\end{pmatrix}$.
So finally, we have the polar decomposition: $\begin{pmatrix}a&-b\\b&a\end{pmatrix}=\begin{pmatrix}\frac{a}{\sqrt{a^2+b^2}}&-\frac{b}{\sqrt{a^2+b^2}}\\\frac{b}{\sqrt{a^2+b^2}}&\frac{a}{\sqrt{a^2+b^2}}\end{pmatrix}\begin{pmatrix}\sqrt{a^2+b^2}&0\\0&\sqrt{a^2+b^2}\end{pmatrix}$
</s>