1

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?

Betohaku
  • 205
  • 2
  • 6
  • @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). – Betohaku Apr 30 '16 at 17:56
  • 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) – sebhofer Apr 30 '16 at 19:57
  • @sebhofer That's pretty sweet, it's a pity then that this is just a trial equation for something bigger. – Betohaku Apr 30 '16 at 20:14
  • 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! – sebhofer Apr 30 '16 at 20:19

1 Answers1

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

kglr
  • 394,356
  • 18
  • 477
  • 896