Let's say I have a generalised linear (system of) equations. What I mean by that is, say I have something like:
$$ \sum_i A_i X B_i = C $$
Where $A_i$ and $B_i$ are matrices and the equation is to be solved for $X$. Is there a closed-form solution (or failing that, least-squares solution)? As an example, let's take the equation $A_1XB_1 + 2aIXI + IXB_3 = C$. The identity matrices are added to be compatible with the notation I defined above.
Using the vectorisation and Kronecker product operations, we can re-write the equation as:
$$ \sum_i (B_i^T \otimes A_i)\mathbf{vec}(X)=\mathbf{vec}(C) $$
from which we can get the (exact or least-squares) solution to this problem using:
$$ \mathbf{vec}(X)=\left( \sum_i (B_i^T \otimes A_i) \right)^\dagger \mathbf{vec}(C) $$
and performing the inverse-vectorise operation. Here $M^\dagger$ denotes the Moore-Penrose psuedoinverse of the matrix $M$.