How to solve this Lyapunov like equation AX-XA=B? Now we have a Lyapunov like equation:
$AX-XA=B$
where $A,X,B$ are $n\times n$ square matrices. $A,B$ are given, $X$ is the unknown. In this equation, both $A$ and $B$ are non-singular and non-symmetric. However, this equation cannot be solved using the standard Lyapunov equation solver because the Kronecker product,
$A\otimes I^T-I\otimes A^T$,
of the equation is singular. I have searched online for how to solve this but with no lucky. Any one can help me on solving this Lyapunov alike equation? Thank you very much!
Sincerely,
$Sharp$

Eidt: currently, I have found a unstable solution to this equation:  
first to covert the equation into a large linear equation:
$Gx=b=(A\otimes I^T-I\otimes A^T)\times vecX = vecB$.
As the Kronecker product is singular, normal linear equation solver doesn't fit this problem. Thus I generated the Moore-Penrose pseudoinverse of the matrix $G$ via SVD algorithm. so the linear equation becomes:
$x=pinv(G)\times b$
For some cases, this works fine although some error is a bit large. But for other cases, e.g. matrix $A$ remains the same with $B$ varies, although I can still get one of the solutions, I can have very ridiculous results of $X$. Any one can help me to find a stable solution to this equation? Thank you so much!
 A: The equation $AX-XA=B$ is equivalent to $(I\otimes A-A^T\otimes I)\operatorname{vec}(X)=\operatorname{vec}(B)$ (the difference of Kronecker products is not $A\otimes I^T-I\otimes A^T$). There are either no solutions or infinitely many solutions $X$ when $I\otimes A-A^T\otimes I$ is singular. In the latter case, there is no way to avoid "very ridiculous results of $X$" if you don't specify what kind of results are qualified as normal.
One obvious necessary condition for the equation to be solvable is that $B$ is traceless. Anyway, if you use Moore-Penrose inverse to solve the problem and obtain $\operatorname{vec}(X_0) = (I\otimes A-A^T\otimes I)^+\operatorname{vec}(B)$, then the equation is solvable if and only if $X_0$ is indeed a solution to $AX-XA=B$. In other words, if $AX_0-X_0A\ne B$, no $X$ will satisfy $AX-XA=B$.
Suppose $X_0$ is indeed a solution to $AX-XA=B$. If what you want is a negative stable solution (an $X$ whose eigenvalues over $\mathbb C$ have only negative real parts), note that if $X_0-\alpha I$ is also a solution to the equation for all scalar $\alpha$. So, you can choose any $\alpha>0$ that is large enough, e.g. some $\alpha$ greater than the spectral radius of $X_0$, then $X=X_0-\alpha I$ will be a stable solution.
