# Matrix equations in mathematica

I need to solve a matrix equation such as $$A=S^{-1}A~S$$ for a given matrix A. Suppose that the matrices are $$3*3$$ and A is diagonal.

A = {{1, 0, 0}, {0, -1/2 + I Sqrt[3]/2, 0}, {0, 0, -1/2 - I Sqrt[3]/2}};
S[a_, b_, c_, d_, e_, f_, g_, h_, k_] := {{a, b, c}, {d, e, f}, {g, h, k}};

Solve[A == Inverse[S] . A . S, {a, b, c, d, e, f, g, h, k}] // MatrixForm

• You write S[a_....] then call it using just S. So need to correct this. But Mathematica finds only trivial solution !Mathematica graphics Commented Feb 6 at 10:49
• Thank you so much, I changed the command as you said and It works. Commented Feb 6 at 11:07
• FindInstance[A . S == S . A, S ∈ Matrices[Dimensions[A], Reals], 20] for 20 random solutions. Commented Feb 6 at 11:26

## 1 Answer

Any diagonal matrix with non-zero entries will solve:

a = {{1, 0, 0}, {0, -1/2 + I  Sqrt[3]/2, 0}, {0,
0, -1/2 - I  Sqrt[3]/2}};
m = Array[s, {3, 3}];
ans = m /. Solve[m . a == a . m, Flatten[m]][[1]];
ans // MatrixForm
test = ans /. {s[1, 1] -> 1, s[2, 2] -> 2, s[3, 3] -> 3};
Inverse[test] . a . test === a


• Thanks, Yeah I got the same answer. Commented Feb 7 at 10:40