In my coursebook on linear algebra on some page I see that a diagonal matrix $D$ for a matrix $A$ that can be diagonalized ca be found as follows: $$\tag{1}D=T^TAT$$
But reading further I see that my professor uses the following formulae to finding a diagonal matrix: $$\tag{2}D= T^{-1}AT$$
I have tried to quickly find a diagonal matrix using MATLAB for the following matrix $$ A = \left(\begin{matrix} 2 & 1 & 1\\ 1 & 2 & 1\\ 1 & 1 & 2 \end{matrix}\right) $$ The $T$-matrix is $$ \left(\begin{matrix} -1/\sqrt{2} & -1/\sqrt{6} & 1/\sqrt{3} \\ 0 & 2/\sqrt{6}& 1/\sqrt{3}\\ 1/\sqrt{2} & -1/\sqrt{6} & 1/\sqrt{3} \end{matrix}\right) $$
I have applied both $(1)$ and $(2)$ and received the same result: $$D = \left(\begin{matrix} 1 & 0 & 0 \\ 0 & 1 & 0\\ 0 & 0 & 4 \end{matrix}\right) $$
Are both formulas indeed equivalent? If yes, why would one use $(2)$ when applying $(1)$ is clearly easier (transposing a matrix is undoubtedly easier than finding its inverse)?
A matrix $A$ can be diagonalized as $D=T^TAT$ iff $A$ is symmetric, in which case $T^{-1}=T^T$. But in general, A diagonalizable matrix $A$ can be only written as $D=T^{-1}AT$.