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.
 A: If two matrices are similar, then they have the same characteristic polynomials. The characteristic polynomials of your matrices are$$-x^2+(a-1)x^2+(a+4)x+4-2a\text{ and }-x^3+(b+1)x^2+(-b+2)x-2b$$respectively. They are equal if and only if $a=0$ and $b=-2$. On the other hand, in this case the matrices have three distinct eigenvalues (the same for both). Therefore, they're similar.
A: 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.
A: Clearly (by block upper triangular form) $A$ has an eigenvalue $-2$ regardless of $a$, and $B$ only has such an eigenvalue if $b=-2$; that is therefore a necessary condition for similarity. But then the  matrix $B$ has $3$ distinct eigenvalues, and will be similar to another matrix if and only if that matrix has the same characteristic polynomial as$~B$. For that to happen for$~A$, the bottom-right $2\times2$ block of$~A$ must have characteristic polynomial equal to $(X+1)(X-2)=X^2-X-2$ which means it should have trace$~1$ and determinant$~{-}2$, and this happens if and only if $a=0$. So the matrices are similar if and only if $a=0$ and $b=-2$.
