If matrices $A,B$ similar, find nonsingular $S$ s.t.$B=S^{-1}AS$ Consider the matrices below
$$A=\begin{bmatrix}9&4&5\\-4&0&-3\\-6&-4&-2\end{bmatrix}$$
and
$$B=\begin{bmatrix}2&1&0\\0&2&0\\0&0&3\end{bmatrix}$$
These matrices have the same eigenvalues $\{2,2,-3\}$ and the same Jordan Canonical Form so they are similar. 
In trying to find $S$ s.t. $B=S^{-1}AS$ I set
$$S=\begin{bmatrix}a&b&c\\d&e&f\\g&h&k\end{bmatrix}$$
and then tried to solve the system of 9 equations with 9 unknowns 
$$B=S^{-1}AS\Leftrightarrow SB=AS$$
but Matlab showed it is rank deficient so it provided only the zero solution.
How can I find such matrix $S$?
Is there a systematic way to do that in the general case when both $A,B$ are $n\times n$ matrices?

Since $A$ and $B$ have the same Jordan normal form $J$, there exist invertible matrices $P$ and $Q$ such that
$$P^{-1}AP=J=Q^{-1}BQ\text{.}$$
Then
$$B=(PQ^{-1})^{-1}APQ^{-1}\text{.}$$
