Is my algorithm correct? (Polar decomposition) I cant seem to find my mistake. Consider this matrix $T = $\begin{bmatrix}
       2 & 1 & 1 \\[0.3em]
       -1 & 2 & 0 \\[0.3em]
       0 & 1 & -1
     \end{bmatrix}
I need the polar decomposition of $T$ ($T=AS$, with $A$ orthogonal and $S$ symmetrical). So, here are my steps:


*

*Calculate $T^TT=$\begin{bmatrix}
       5 & 0 & 2 \\[0.3em]
       0 & 6 & 0 \\[0.3em]
       2 & 0 & 2
     \end{bmatrix}

*Calculate eigenvalues of $T^TT$:
$1,6,6$

*Calculate $S=\sqrt{T^TT}=\left[ \begin {array}{ccc} 1&0&2\\ 0&1&0
\\ -2&0&1\end {array} \right]\left[ \begin {array}{ccc} 1&0&0\\ 0&\sqrt{6}&0
\\ 0&0&\sqrt{6}\end {array} \right]\left[ \begin {array}{ccc} \frac{1}{5}&0&-\frac{2}{5}\\ 0&1&0
\\ \frac{2}{5}&0&\frac{1}{5}\end {array} \right]=$\begin{bmatrix}
       \frac{1}{5}+\frac{4}{5}\sqrt{6} & 0 & -\frac{2}{5}+\frac{2}{5}\sqrt{6} \\[0.3em]
       0 & \sqrt{6} & 0 \\[0.3em]
       -\frac{2}{5}+\frac{2}{5}\sqrt{6} & 0 & \frac{4}{5}+\frac{1}{5}\sqrt{6}
     \end{bmatrix}
Now I get a really big matrix for $S^{-1}$ and an even bigger one for $A$. When I put my matrices in the equation $T=AS$ an error occurs.
Can you help me find my mistake(s)?

What you have for $S$ is exactly correct. To make finding $S^{-1}$ easier, normalize your columns of your matrix of eigenvectors, so that $S = QDQ^{T}$, where $Q$ is an orthogonal matrix. Then $S^{-1} = QD^{-1}Q^{T}$ and all of the matrices in that product are easy to calculate.
In particular,
$$Q = \left[\begin{array}{ccc}
1/\sqrt{5} & 0 & 2/\sqrt{5}\\
0 & 1 & 0\\
-2/\sqrt{5} & 0 & 1/\sqrt{5}\end{array}\right].$$
Then
$$S^{-1} = \left[\begin{array}{ccc}
1/\sqrt{5} & 0 & 2/\sqrt{5}\\
0 & 1 & 0\\
-2/\sqrt{5} & 0 & 1/\sqrt{5}\end{array}\right]
\left[\begin{array}{ccc}
1 & 0 & 0\\
0 & 1/\sqrt{6} & 0\\
0 & 0 & 1/\sqrt{6}\end{array}\right]
\left[\begin{array}{ccc}
1/\sqrt{5} & 0 & -2/\sqrt{5}\\
0 & 1 & 0\\
2/\sqrt{5} & 0 & 1/\sqrt{5}\end{array}\right].$$
Multiplying out gives that 
$$S^{-1} = \left[\begin{array}{ccc}
1/5+4/(5\sqrt{6}) & 0 & -2/5+2/(5\sqrt{6})\\
0 & 1/\sqrt{6} & 0\\
-2/5+2/(5\sqrt{6}) & 0 & 4/5+1/(5\sqrt{6})\end{array}\right].$$
Then since $A = TS^{-1}$,
$$A = \left[\begin{array}{ccc}
2 & 1 & 1\\
-1 & 2 & 0\\
0 & 1 & -1\end{array}\right]
\left[\begin{array}{ccc}
1/5+4/(5\sqrt{6}) & 0 & -2/5+2/(5\sqrt{6})\\
0 & 1/\sqrt{6} & 0\\
-2/5+2/(5\sqrt{6}) & 0 & 4/5+1/(5\sqrt{6})\end{array}\right].$$
Multiplying this out gives that 
$$ A = 
\left[\begin{array}{ccc}
2/\sqrt{6} & 1/\sqrt{6} & 1/\sqrt{6}\\
-1/5-4/(5\sqrt{6}) & 2/\sqrt{6} & 2/5-2/(5\sqrt{6})\\
2/5-2/(5\sqrt{6}) & 1/\sqrt{6} & -4/5-1/(5\sqrt{6})\end{array}\right].$$
