Find the values of $a$ and $b$ such that the following matrices are similar 
Find the values of $a$ and $b$ such that the following matrices  are similar.
$$A=\begin{bmatrix} -2& 0 & 0 \\ 2 & a & 2 \\ 3& 1 & 1 \end{bmatrix}, \qquad B=\begin{bmatrix} -1& 0 & 0 \\ 0 & 2 & 0 \\ 0& 0 & b \end{bmatrix}$$

I know that similar matrices must  have the same ranks. Hence, I can take  that value  of $a$ as any real number  and $b \neq 0$. Is  my answer is  true or false? Any hints or solutions will be appreciated. Thank you.

Calculate the characteristic polynomials:
$$\det (A - \lambda I) = (-2-\lambda) \begin{vmatrix}a-2 & 2 \\ 1 & 1-\lambda\end{vmatrix} = (-2-\lambda)(\lambda^2 - \lambda(a+1) + (a-2)) = (-2 - \lambda)\left(\frac{1+a-\sqrt{a^2-2a+9}}2 - \lambda\right)\left(\frac{1+a+\sqrt{a^2-2a+9}}2 - \lambda\right)$$
$$\det (B - \lambda I) = (-1-\lambda)(2 - \lambda)(b - \lambda)$$
If $A$ and $B$ are similar, then the characteristic polynomials are equal so uniqueness of factorization in $\mathbb{C}[\lambda]$ gives $b = -2$ and 
$$\left\{\frac{1+a-\sqrt{a^2-2a+9}}2, \frac{1+a+\sqrt{a^2-2a+9}}2\right\} = \{-1, 2\}$$
for which the only solution is $a = 0$.
On the other hand, if $a = 0, b= 2$ then both $A$ and $B$ diagonalize with distinct eigenvalues $\{-1, 2, -2\}$ so they are similar.
