Solving linear matrix equation Given matrices $A, B, C' \in \Bbb R^{2 \times 6}$, where $'$ denotes matrix transposition, and matrix $L \in \Bbb R^{2 \times 2}$, how can one solve the following linear matrix equation in $X \in \Bbb R^{2 \times 2}$?
$$ ACXC'A' - BCXC'B' = L $$
$X$ is a covariance matrix that should be positive definite or semidefinite. Is there any standard solution to ensure getting correct values?
 A: This is just a system of 4 linear equations in the 4 unknown entries of $X$. Just write down those four equations and solve it. For generic $A,B,C$, it will be nonsingular, so there is going to be only one solution $X\in\mathbb{R}^{2\times 2}$. If that matrix is not positive semidefinite, there is little you can do apart from relaxing the problem somehow; for instance you could look for the closest positive semidefinite matrix to the solution, or the positive semidefinite matrix that minimizes the residual. The case in which there are an infinite number of solutions is probably trickier, but I would not start assuming that until you verify that it is the case.
If you want to introduce some notation to formalize the process, you can introduce Kronecker products, but even without them you can just write down the equations and do everything by hand in the $2\times 2$ case.
There is an algorithm by Hammarling to compute solutions to similar matrix equations by computing the Cholesky factor of $X$ directly; this idea ensures automatically that a positive semidefinite $X$ is produced. But

*

*As far as I can see the case of your matrix equation does not appear in the paper (even after giving a better name to $AC$ and $BC$).

*Your equation is not guaranteed to have a positive semidefinite solution $X$, not even when $L$ is positive definite; for instance take $AC=I$ and $BC=2I$.

*This paper and algorithm might be overkill, especially if you have a $2\times 2$ case.

A: I feel like you are drowning in a glass of water.
Putting $AC=U\in M_2$ and $BC=V\in M_2$, we obtain
(*) $UXU^T-VXV^T=L$ in $M_2$.
If $X$ is a symmetric solution of (*), then $L$ too.
For generic $U,V,L$, there is a unique solution; then if, conversely, $L$ is generic symmetric, then the solution $X$ too.
In particular, there are $3$ independent linear relations linking the $3$ unknowns $x_{1,1},x_{1,2},x_{2,2}$ and not $4$.
If you want that your symmetric solution is $\geq 0$, then of course $U,V,L$ must satisfy additional relations so that $x_{1,1}\geq 0,x_{2,2}\geq 0,\det(X)\geq 0$; these conditions are easy to write since (*) is linear wrt $X$.
On the other hand,
The generic (*) admits a $\geq 0$ symmetric solution with probability $\approx 0.21$; for comparison, a random symmetric $2\times 2$ matrix is $\geq 0$ with probability $\approx 0.11$.
