# Solving a linear matrix equation with both left and right multiplication of unknown

I would like to solve a matrix equation of the form $$\mathbf{A} \mathbf{X} + \mathbf{X} \mathbf{A}^T = \mathbf{B}$$

where $$\mathbf{A}$$ and $$\mathbf{B}$$ are known $$n \times n$$ matrices, and $$\mathbf{X}$$ is an unknown $$n \times n$$ matrix.

1. Is there a general way to isolate $$\mathbf X$$ in this expression?
2. Is there a solution for various special cases, such as (1) the case where $$\mathbf{A}$$ and $$\mathbf{B}$$ are real, or (2) when $$\mathbf{B}$$ is real and diagonal?

My intuition is that the case where $$\mathbf{A}$$ and $$\mathbf{B}$$ are both real may be solved using the SVD of $$\mathbf{A}$$. Is there at least a way to compute an approximate solution for X using the pseudoinverse?

• Bartels Stewart algorithm. – copper.hat May 26 at 0:44
• incredible, thank you so much---I had not heard of the Sylvester equation but that looks like it's exactly it – wil3 May 26 at 0:56
• As far as isolating $X$ goes, we can write $$(I \otimes A + A \otimes I)\operatorname{vec}(X) = \operatorname{vec}(B),$$ where $I$ denotes an $n \times n$ matrix, $\otimes$ denotes a Kronecker product, and vec refers to the vectorization operator. – Omnomnomnom May 26 at 2:09

The Bartel Stewart algo. works only when the function $$f:X\mapsto AX+XA^T$$ is one to one.
Let $$spectrum(A)=(\lambda_i)_i$$. Since $$spectrum(f)=\{\lambda_i+\lambda_j;i,j\}$$, B.S. works iff for every $$i,j$$, $$\lambda_i+\lambda_j\not= 0$$. Note that if the previous condition is not fufilled, then the equation may have no solutions; for example, take
$$A=diag(1,-1),B=\begin{pmatrix}0&0\\1&0\end{pmatrix}$$.
More precisely, for this value of $$A$$, the equation $$AX+XA^T=B$$ has no solutions except for rare values ​​of $$B$$.