# How to prove that "A matrix commuted with all n-order matrices must be an n-order scalar matrix." by mma?

Here is my code. The expected results are not obtained.

Clear["Global*"];
mD = {{a, b, c}, {d, e, f}, {g, h, i}};
mX = Array[X, {3, 3}];
sol = Solve[mD . mX == mX . mD, Flatten[mX]];
mX /. Flatten[sol] // MatrixForm


EDIT

The expected result is an n-order scalar matrix (a 3x3 scalar matrix in my example, p is an arbitrary symbolic variable):

$$mX=\left(\begin{array}{lll}p & 0 & 0 \\ 0 & p & 0 \\ 0 & 0 & p\end{array}\right)$$

The expected results are not obtained.

What is the expected result?

If you want to solve mD . mX == mX . mD for mX elements, then you need to do it element by element for the equation mD . mX == mX . mD. This will give 9 equations, since each mD . mX is 3 by 3 matrix.

Clear["Global*"];
mD = {{a, b, c}, {d, e, f}, {g, h, i}};
mX = Array[X, {3, 3}];
ApplySides[MatrixForm, mD . mX == mX . mD]


So we have 9 equations

(eqs = Thread[Flatten /@ (mD . mX == mX . mD)]) // Column


Mathematica says that for these equations to be true for any $$a,b,c,d,e,f,g,h,i$$ then

SolveAlways[eqs, {a, b, c, d, e, f, g, h, i}]


And since mX is

Then mX should have this form

Where n is any value. This means mD . mX == mX . mD is true for any matrix mX of the above form.

I do not know if this is what you meant or something else.

• This is what I want. It's perfect. Thanks! Commented Sep 8, 2022 at 3:11