# Solving underdetermined Lyapunov equation?

I'm solving the following for $$X$$ with $$A,B$$ singular positive semidefinite matrices.

$$AX + XA = B$$

Because $$A$$, $$B$$ are singular, standard Lyapunov solver fails

However, if I heuristically skip dividing by 0 elements in Matlab implementation of the Lyapunov solver, I get the same answer as the least squares solution to $$(A\otimes I + I\otimes A)\operatorname{vec}X=\operatorname{vec}B$$

Does this appear in the literature, or does someone see a way to prove that this works?

(originally posted on math.SE)

Since $$A$$ is symmetric, it has an eigendecomposition $$A = QDQ^*$$ with $$Q$$ orthogonal. Then $$M = A \otimes I + I\otimes A = (Q\otimes Q)(D\otimes I + I \otimes D)(Q\otimes Q)^*$$ is an eigendecomposition and also a singular value decomposition. The standard formula for the pseudoinverse in terms of the SVD gives $$M^+ = (A \otimes I + I\otimes A)^+ = (Q\otimes Q)(D\otimes I + I \otimes D)^+(Q\otimes Q)^*,$$ where the pseudoinverse in the middle is a diagonal matrix with elements $$\frac{1}{d_i+d_j}$$ if $$d_i+d_j\neq 0$$ or $$0$$ otherwise.
Your implementation computes the minimum-norm least-squares solution $$\operatorname{vec}X = M^+\operatorname{vec} B$$ with this formula, if I am not mistaken.
Note also that in your case the explicit inverse IT can be avoided, since T ($$Q$$ above) is orthogonal.