Finding out whether two matrices are similar? [duplicate]

$\mathbf{B = P^{^-1} A P} \iff$ ($\mathbf{B}$ is similar to $\mathbf{A}$)

I'm a little confused about matrix similarity. Let's say we have the following matrix $A$:

\begin{bmatrix}2&5\\4&1\end{bmatrix}

Its eigenvalues are $6$ and $-3$. Respective eigenvectors $\left<(5,4)\right>, \left<(-1,1)\right>$.

How do I find out whether its similar to another matrix (B)?

Let's say matrix $B$:

\begin{bmatrix}4&5\\1&4\end{bmatrix}

Trying to actually find the regular $P$ so that the equation would be satisfied seems like way too much calculating.

My idea is to try and diagonalize both of them - and if I end up with same eigenvalues on the diagonal (in whatever order), then they are both similar? (using the transitive property, since similarity is an equivalence).

marked as duplicate by Kamil Jarosz, Pragabhava, user296602, SchrodingersCat, hardmathJan 25 '16 at 18:20

Your idea is correct and you can even use it to find the matrix $P$. Diagonalizing $A$, you will find $P_1$ such that $P_1^{-1} A P = D_1$ where $D_1$ is diagonal and the diagonal entries are the eigenvalues of $A$. Diagonalizing $B$, you will find $P_2$ such that $P_2^{-1} B P_2 = D_2$ with $D_2$ diagonal. If the matrices $A$ and $B$ have the same eigenvalues (counting with multiplicities), then you can arrange that $D_1 = D_2$ and then
$$A = P_1 D_1 P_1^{-1} = P_1 D_2 P_1^{-1} = P_1 P_2^{-1} B P_2 P_1^{-1} = P^{-1} B P$$
where $P = P_2 P_1^{-1}$.
If $A$ and $B$ don't have the same eigenvalues, or $A$ is diagonalizable and $B$ is not or the other way around, then $A$ and $B$ won't be similar. If both $A$ and $B$ are not diagonalizable, you can bring them to a canonical form instead.