Solution (source code)

= Solution

An example in dimension four is
$$
\boxed{A=\begin{pmatrix}1&1&0&0\\0&1&0&0\\0&0&1&1\\0&0&0&1\end{pmatrix},\qquad
B=\begin{pmatrix}1&1&0&0\\0&1&0&0\\0&0&1&0\\0&0&0&1\end{pmatrix}.}
$$
Both are invertible, so each has rank four. Both have <characteristic polynomial> $(x-1)^4$, and each has <minimal polynomial> $(x-1)^2$, since its nonzero nilpotent part squares to zero. However $\operatorname{rank}(A-I)=2$ and $\operatorname{rank}(B-I)=1$. If $B=PAP^{-1}$, then $B-I=P(A-I)P^{-1}$, which would preserve these ranks. The contradiction proves that the matrices are \b[not similar], despite all three specified invariants agreeing.