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.
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityI have two matrices. Is there any command to show these two matrices are similar? I searched but I couldn't find anything.
Thank you.
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.
$\endgroup$
Oct 31, 2017 at 12:56
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.
$\endgroup$
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]);
JordanDecomposition[]
. UseSchurDecomposition[]
otherwise. $\endgroup$