Finding unknown matrices in a set of simultaneous matrix equations I've come across a thorny problem in my research, which is too complicated and specific to ask here. However, it bears some similarity to the following problem, and understanding how to solve this "toy" version might help me to solve my actual problem.
So, suppose I have three real matrices $X$ $(n\times p)$, $Y$ $(m\times n)$ and $Z$ $(p\times m)$, and I wish to find another three (real) matrices $A$ $(n\times m)$, $B$ $(m\times p)$ and $C$ $(p\times n)$ such that
$$
AB = X\\
BC = Y\\
CA = Z.
$$
How can I find $A$, $B$ and $C$? 
This is effectively $mn+np+pm$ equations in $mn+np+pm$ unknowns, so it seems like it might have a unique solution, but the equations are not linear. We can't assume the matrices are invertible, because in general they're not square. How could such a problem be approached? If there's no analytical solution, hints on how to do solve this sort of thing numerically would be appreciated.

Let $m=n=p$. For generic (cf. definition below in (*)) matrices $X=[x_{i,j}],Y=[y_{i,j}],Z=[z_{i,j}]$ there are exactly $2^n$ complex solutions in $A,B,C$.
Proof:  (*): $(x_{i,j}),(y_{i,j}),(z_{i,j})$ are assumed to be mutually transcendental over $\mathbb{Q}$, the rational numbers field. Then $X,Y,Z$ are invertible and if $B$ is known, then $A,C$ are known too. We have $BZB=YX$ that is equivalent to $(BZ)^2=YXZ$. Moreover $YXZ$ has $n$ distinct non-zero eigenvalues $(\lambda_i)_i$. The eigenvalues of $BZ$ are in the form $(\mu_i)_i$ where $\mu_i^2=\lambda_i$ and $BZ,YXZ$ commute. By the Lagrange interpolation theorem, there are $2^n$ complex solutions in $BZ$ and therefore $2^n$ solutions in $B$ and consequently $2^n$ complex solutions in $A,B,C$.
EDIT: Now, suppose that $m,n,p$ are any integers. We may assume that $m=\inf(m,n,p)$. We obtain, as above, $(BZ)^2=YXZ$ where $YXZ$ is a generic (invertible) $m\times m$ generic matrix. Thus there are $2^m$ solutions in $BZ$ and at most $2^m$ solutions in $B=(BZ)^{-1}YX$. It remains to find $A,C$, that is not difficult, using the pseudo-inverse of each solution in $B$.
