How to solve matrix equation $AXH+AHX−BH=0$ How to solve matrix equation $AXH+AHX−BH=0$? All matrices are square, $A$, $B$ known constant matrices and invertible, $H$ can take any value, $X$ represent the solution to be found. 
I have seen about the Sylvester Equation like in this post Solving a matrix equation $AX=XB$ in a CAS, but I'm not sure how to apply it because of the presence of matrix H.
 A: The equation is still linear in $X$, that means that if you consider $X$ a vector, call it $\Xi$ (made up of all the entries of the matrix $X$ in a definite order) you can write it in the form
$$
Q\Xi = W
$$
where $W$ is the vector likewise made of the entries of the matrix $BH$. Now the problem reduces to finding $Q$ and its inverse (you should check if $Q$ is invertible, it is not obvious to me that it will be).
The matrix $Q$ represents the action of $A$ and $H$ over $X$ sometimes acting on the left and sometimes on the right. I you call the right-acting operator $^R$ and the left one $^L$ then in fact you have $Q = A^L \otimes H^R + (AH)^L \otimes {\bf 1}^R$ and you can write the matrix as a tensor product, and then invert it. To simplify matters you could also start multiplying your equation on the left by $A^{-1}$, but the method to solve remains the same.
Your answer is then $\Xi = Q^{-1} W$ which you can map back to $X$ in matrix form.
A: Okay, the equation
$AXH + AHX - BH = 0$
is equivalent to
$A(HX + XH) = BH.$
You say $A$ is invertible, so you can write 
$HX + XH = A^{-1}BH$
which is a Sylvester equation (Wikipedia) and can be solved in CASes by the functions described in the answer to the post you linked, or as
$$(I_n \otimes H + H^T \otimes I_n) \operatorname{vec} X = \operatorname{vec}(A^{-1}BH).$$
If $A$ is not invertible, I would do as anbarief suggest. First solve
$$AY = BH$$
by solving
$$(I_n \otimes A) \operatorname{vec} Y = \operatorname{vec}(BH)$$
and then solving the Sylvester equation $HX + XH = Y$, e.g. through
$$(I_n \otimes H + H^T \otimes I_n) \operatorname{vec} X = \operatorname{vec} Y.$$
Of coure, if $A$ is not invertible, the equation $AY = BH$ have several or no solutions.
A: My idea is that ...
try to solve this equation first : 
$$  A(X_{1}) = BH $$, 
then solve, 
$$    XH+HX = X_{1}      $$ , by writing $XH + HX = H(X + H^{-1}XH) $. Then write the solution $X$ as a matrix that has $H$ for the diagonalization. Maybe it'll work..? 
A: First vectorise the matrix $X$ so that $vec (X) =  (X_{11},X_{12},X_{21},X_{22})^T$, here I chose the ordering of the base as $11 \to 1, 12\to 2, 21\to 3, 22\to 4$ In this basis now compute $Q = H\otimes 1 + 1 \otimes H$ (No transpose anywhere!), in the case of a matrix $2 \times 2$ we obtain $Q$ in the basis we want as:
$$
Q = \left( \begin{array}{cccc}
2H_{11}& H_{21}&H_{12}&0 \\
H_{12}& H_{11}+H_{22}&0&H_{12}\\
H_{21}&0&H_{11}+H_{22}&0 \\
0&H_{21}&0&2H_{22}
\end{array}\right)
$$
Now invert $Q$ and apply the inverse to $vec(BH)$, the result is $vec(X)$, that is the answer you want. I am guessing that what you did before was wrong because you used a transpose in $H$ (which should not be there), but it worked for the simple case you chose because that particular $H$ you wrote is diagonal so $H=H^T$ and they both agree. If you were to deal with a non-symmetric $H$ your answer would come out wrong because $Q$ was wrong. You should use the $Q$ I wrote above, that is a correct expression for $Q$, also valid when $H$ is not diagonal.
