Solve the matrix equation $X = AX^T + B$ for $X$ Consider the matrix equation

\begin{equation}
X=AX^T+B,
\end{equation}

where $X$ is an unknown square matrix. Is it possible to solve it analytically? Moreover, can a general solution be written down in terms of the matrices $A$ and $B$?
 A: Assume $X$ is an $n \times n$ matrix.
If we rewrite the equation as:
$$ X - AX^T = B $$
then we have a system of $n^2$ linear equations in $n^2$ unknowns (the entries of $X$), so in general the existence of solutions $X$ can be computed by standard methods.
A: $\newcommand{\fvo}{1}
\newcommand{\cdf}{\cdot & \cdot & \cdot & \cdot}
\newcommand{\cdt}{\cdot & \cdot & \cdot}
\newcommand{\cdo}{\cdot}
\newcommand{\cdw}{\cdot}
 $
$\newcommand{\vec}{\text{vec}}$
$\newcommand{\lb}{\left(}$
$\newcommand{\rb}{\right)}$
$\newcommand{\unity}{\bf\text{1}}$ Use the superoperator formalism to rewrite
$X=AX^T+B$ as
$$
\vec(X)=\lb\unity\otimes A \rb\vec (X^T) +\vec(B)\\
\vec(X)-\lb\unity\otimes A \rb\vec (X)=\vec(B)\\
\lb \lb\unity\otimes \unity\rb -\lb\unity\otimes A \rb \hat T\rb \vec (X)=\vec(B),\\
$$
where $\hat T $ describes the Transposition Superoperator. For $4\times 4$ matrices this looks like 
\begin{equation}
\widehat T :=
\left(\,
\begin{smallmatrix}
\fvo & \cdt & \cdf & \cdf & \cdf \\
\cdf & \fvo & \cdt & \cdf & \cdf \\
\cdf & \cdf & \fvo & \cdt & \cdf \\
\cdf & \cdf & \cdf & \fvo & \cdt \\
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\cdo & \fvo & \cdw & \cdf & \cdf & \cdf \\
\cdf & \cdo & \fvo & \cdw & \cdf & \cdf \\
\cdf & \cdf & \cdo & \fvo & \cdw & \cdf \\
\cdf & \cdf & \cdf & \cdo & \fvo & \cdw \\
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\cdw & \fvo & \cdo & \cdf & \cdf & \cdf \\
\cdf & \cdw & \fvo & \cdo & \cdf & \cdf \\
\cdf & \cdf & \cdw & \fvo & \cdo & \cdf \\
\cdf & \cdf & \cdf & \cdw & \fvo & \cdo \\
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\cdt & \fvo & \cdf & \cdf & \cdf \\
\cdf & \cdt & \fvo & \cdf & \cdf \\
\cdf & \cdf & \cdt & \fvo & \cdf \\
\cdf & \cdf & \cdf & \cdt & \fvo \\
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\\
\end{smallmatrix}\,
\right)
\end{equation}
 (see for example here eq. $(43)$).
If $\lb \lb\unity\otimes \unity\rb -\lb\unity\otimes A \rb \hat T\rb $ is invertible, you'll get
$$
\vec (X)=\lb \lb\unity\otimes \unity\rb -\lb\unity\otimes A \rb \hat T\rb ^{-1}\vec(B)
$$
Undo $\vec$ and you're done...
