Given this transformation matrix, how do I decompose it into translation, rotation and scale matrices? I have this problem from my Graphics course. Given this transformation matrix:
$$\begin{pmatrix}
-2 &-1&  2\\
-2  &1& -1\\
 0  &0&  1\\
\end{pmatrix}$$
I need to extract translation, rotation and scale matrices.
I've also have the answer (which is $TRS$):
$$T=\begin{pmatrix}
1&0&2\\
0&1&-1\\
0&0&1\end{pmatrix}\\
R=\begin{pmatrix}
1/\sqrt2 & -1/\sqrt2 &0 \\
1/\sqrt2 & 1/\sqrt2 &0 \\
0&0&1
\end{pmatrix}\\
S=\begin{pmatrix}
-2/\sqrt2 & 0 & 0 \\
0 & \sqrt2 & 0 \\
0& 0& 1
\end{pmatrix}
%    1 0  2        1/sqrt(2) -1/sqrt(2) 0         -2/sqrt(2) 0     0
%T = 0 1 -1    R = /1/sqrt(2) 1/sqrt(2) 0     S = 0        sqrt(2) 0
%    0 0  1        0          0         1         0          0     1
$$
I just have no idea (except for the Translation matrix) how I would get to this solution.

It appears you are working with Affine Transformation Matrices, which is also the case in the other answer you referenced, which is standard for working with 2D computer graphics.  The only difference between the matrices here and those in the other answer is that yours use the square form, rather than a rectangular augmented form.
So, using the labels from the other answer, you would have
$$
\left[
\begin{array}{ccc}
a & b & t_x\\
c & d & t_y\\
0 & 0 & 1\end{array}\right]=\left[\begin{array}{ccc}
s_{x}\cos\psi & -s_{x}\sin\psi & t_x\\
s_{y}\sin\psi & s_{y}\cos\psi & t_y\\
0 & 0 & 1\end{array}\right]
$$
The matrices you seek then take the form:
$$
T=\begin{pmatrix}
1 & 0 & t_x \\
0 & 1 & t_y \\
0 & 0 & 1 \end{pmatrix}\\
R=\begin{pmatrix}
\cos{\psi} & -\sin{\psi} &0 \\
\sin{\psi} & \cos{\psi} &0 \\
0 & 0 & 1 \end{pmatrix}\\
S=\begin{pmatrix}
s_x & 0 & 0 \\
0 & s_y & 0 \\
0 & 0 & 1 \end{pmatrix}
$$
If you need help with extracting those values, the other answer has explicit formulae.
