# Solve symbolic Sylvester-like equation in MATLAB or MAPLE

I'm looking for a way to solve a symbolic Sylvester-like equation in MATLAB or MAPLE (or any other available tool). In particular, I have the following equation,

$$AX+XA=B$$

where, $$A$$ has some parameters in it, e.g.,

$$A=\begin{bmatrix}a+1 & 2\\3 & 1\end{bmatrix}$$

$$B$$ is known and I want to solve for $$X$$ as a function of $$a$$.

• Matlab has now a "sylvester" function uk.mathworks.com/help/matlab/ref/sylvester.html – Jean Marie Mar 11 at 21:41
• Why not use vectorization? – Rodrigo de Azevedo Mar 11 at 21:45
• @JeanMarie Yes, but the input arguments must be numeric arrays. – Mohammad Mar 11 at 21:46
• @RodrigodeAzevedo Can you please describe more? – Mohammad Mar 11 at 21:46
• Vectorization converts the matrix equation into a system of $4$ linear equations in $4$ unknowns, which is easy to solve symbolically. In MATLAB, use kron for the Kronecker product and reshape for the vectorization and un-vectorization. – Rodrigo de Azevedo Mar 11 at 21:48

You could write the Sylvester equation as a linear system: $$$$(I_2 \otimes A + A^T \otimes I_2) \mathrm{vec} X = \mathrm{vec} B$$$$ which you can then solve for $$\mathrm{vec}X$$: \begin{align} \mathrm{vec}X & = (I_2 \otimes A + A^T \otimes I_2)^{-1} \mathrm{vec} B \\ & = \frac{\mathrm{adj} (I_2 \otimes A + A^T \otimes I_2)}{\mathrm{det} (I_2 \otimes A + A^T \otimes I_2)} \mathrm{vec} B \end{align} and finally reshape back to a 2 by 2 matrix.