# Solving a matrix equation $AX=XB$ in a CAS

I have the following computational problem. Let $N$ be a positive integer and $A\in \mathbb{C}^{2N\times 2N}$, $X\in \mathbb{C}^{2N\times 4}$ and $B\in \mathbb{C}^{4\times 4}$. I want to solve the following equation for the matrix $X$ $$A\cdot X= X\cdot B.$$ I found the following paper online (http://www.jstor.org/stable/2099652) but I haven't been able to implement it in Maple or Magma and I don't know what I should be looking for. Does someone know if it is implemented somewhere already?

-
Looks kinda like a Sylvester equation. SylvesterSolve in Maple. – Calle May 18 '11 at 17:54

This is a Sylvester equation, $AX-XB = 0$. This can be solved in Maple by SylvesterSolve and in Matlab by lyap and in Mathematica by LyapunovSolve.
In general, you can get $X$ in a vectorized form by solving $$((I_4 \otimes A) - (B^T \otimes I_{2n})) \operatorname{vec} X = 0$$ for example by Gaussian elimination. $\otimes$ is the Kronecker product and $\operatorname{vec} X$ is the columns of $X$ put on top of each other in a vector.
Hello @Calle I have a question with respect to this, how should be the solution if i have to solve $AXH+AXH-BH=0$?, in my case all matrices are square and A,B,H are constant matrices, as well I need X matrix. – Gina Torres Oct 10 '13 at 10:29