1
$\begingroup$

The function Solve works fine for scalars:

In[]:= Solve[A x - x B + C == 0, x]
Out[]= {{x -> -(C/(A - B))}}

When using matrices however,

mA = {{1, 0}, {0, 1}};
mB = {{2, 0}, {0, 2}};
mC = {{3, 1}, {0, 3}};

Solve[mA.x - x.mB + mC == 0, x]

Out[]= {}

There is no output, though there should be (x={{3,1},{0,3}}, I guess). The same happens when the matrix multiplication operator "." is replaced with a white space.

How can linear matrix equations like these be solved?

$\endgroup$
4
  • $\begingroup$ @Artes I'm sorry, I don't see how the answer to the linked question could solve a linear system like this (note also that x is multiplied from the left with mA and from the right with mB). $\endgroup$
    – Betohaku
    Apr 30 '16 at 17:56
  • $\begingroup$ You should note that this is a so-called Lyapunov equation and Mathematica has a dedicated function for solving it! (At least for the cases where C is positive definite) $\endgroup$
    – sebhofer
    Apr 30 '16 at 19:57
  • $\begingroup$ @sebhofer That's pretty sweet, it's a pity then that this is just a trial equation for something bigger. $\endgroup$
    – Betohaku
    Apr 30 '16 at 20:14
  • $\begingroup$ Oh, also note that I haven't realized your equation has two distinct matrices A and B so its not a Lyapunov equation. Sorry for the confusion! $\endgroup$
    – sebhofer
    Apr 30 '16 at 20:19
7
$\begingroup$
With[{x = Array[x, Dimensions[mA]]}, Solve[mA .x - x. mB + mC == 0, Flatten@x]]

Mathematica graphics

Or

With[{x = Array[x, Dimensions[mA]]},  x /. Solve[mA .x - x. mB + mC == 0, Flatten@x]]

{{{3, 1}, {0, 3}}}

$\endgroup$

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