# How to check that two matrices are similar?

I have two matrices. Is there any command to show these two matrices are similar? I searched but I couldn't find anything.

Thank you.

• If they're exact or symbolic matrices, check the result of JordanDecomposition[]. Use SchurDecomposition[] otherwise. Commented Oct 31, 2017 at 12:51

You could use the Jordan normal form provided by JordanDecomposition...

n = 15;
a = RandomReal[{-1, 1}, {n, n}];
b = RandomReal[{-1, 1}, {n, n}];
g = RandomReal[{-1, 1}, {n, n}];
c = LinearSolve[g, a].g;
Max[Abs[JordanDecomposition[a][[2]] - JordanDecomposition[b][[2]]]] < 10^-12
Max[Abs[JordanDecomposition[a][[2]] - JordanDecomposition[c][[2]]]] < 10^-12

(* False *)
(* True *)

• JordanDecomposition[] is unreliable in the inexact case if the matrices to be compared are very nearly defective. Compare the results of SchurDecomposition[] instead. Commented Oct 31, 2017 at 12:56
• @J.M. Hm. In my example, a and c are similar but I see no coincidences in the Schur decompositions... Schur decomposition is a normal form only for conjugacy under orthogonal transformations. Commented Oct 31, 2017 at 13:01

You could check if the Eigenvalues of both matrices are the same, and if both matrices are Diagonalizable . To do so you could create two functions that does this and combine them like this:

l[x_, y_] := (If[Length[Eigenvalues[x]] == Length[Eigenvalues[y]], If[Sort[Eigenvalues[x]] == Sort[Eigenvalues[y]], True, False],
False]);
r[x_, y_] := (If[Det[Eigenvectors[x]] != 0 && Det[Eigenvectors[y]] != 0, True,
False]);
AreSimilar[x_, y_] := (If[l[x, y] == True && r[x, y] == True, True, False]);