2
$\begingroup$

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)$

$\endgroup$

1 Answer 1

6
$\begingroup$

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]

Mathematica graphics

So we have 9 equations

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

Mathematica graphics

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}]

Mathematica graphics

And since mX is

Mathematica graphics

Then mX should have this form

Mathematica graphics

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.

$\endgroup$
1
  • $\begingroup$ This is what I want. It's perfect. Thanks! $\endgroup$
    – lotus2019
    Commented Sep 8, 2022 at 3:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.