<s>[INST] Find matrices $A$ and $B$ given $AB$ and $BA$ Given that:
$$AB= \left[ {\matrix{
   3 & 1 \cr 
   2 & 1 \cr 

 } } \right]$$
and
$$BA= \left[ {\matrix{
   5 & 3 \cr 
   -2 & -1 \cr 

 } } \right]$$
find $A$ and $B$.
 [/INST] First note that both the products are of full rank and hence $A$ and $B$ are also of full rank. So we would expect one set of solutions with one degree of freedom since if $A$ and $B$ satisfy our equations, so will $kA$ and $\frac{1}{k}B$.
Let $$A = \left[ {\matrix{
   a_1 & a_2 \cr 
   a_3 & a_4 \cr 
 } } \right],B = \left[ {\matrix{
   b_1 & b_2 \cr 
   b_3 & b_4 \cr 
 } } \right]$$
$$AB= \left[ {\matrix{
   3 & 1 \cr 
   2 & 1 \cr
 } } \right], BA= \left[ {\matrix{
   5 & 3 \cr 
   -2 & -1 \cr 
 } } \right]$$
Hence, $$B \left[ {\matrix{
   3 & 1 \cr 
   2 & 1 \cr 
 } } \right] = B(AB) = (BA)B= \left[ {\matrix{
   5 & 3 \cr 
   -2 & -1 \cr 
 } } \right] B$$
\begin{align*}
3b_1 + 2b_2 & = 5b_1 + 3b_3\\
b_1 + b_2 & = 5b_2 + 3b_4\\
3b_3 + 2b_4 & = -2b_1 - b_3\\
b_3 + b_4 & = -2b_2 - b_4
\end{align*}
Rearranging, we get,
\begin{align*}
2b_2 & = 2b_1 + 3b_3\\
b_1 & = 4b_2 + 3b_4\\
2b_1 + 4b_3 + 2b_4 & = 0\\
2b_2 + b_3 + 2b_4 & = 0
\end{align*}
Set $b_2 = k$, and $b_4 = m$, we get $b_1 = 4k+3m$ and $b_3 = -2(k+m)$
Hence, $B = \left[ {\matrix{
   4k+3m & k \cr 
   -2(k+m) & m \cr 
 } } \right]$ where $k,m \neq 0$, $B^{-1} = \frac{1}{3m^2+6mk+2k^2} \left[ {\matrix{
   m & -k \cr 
   2(k+m) & 4k+3m \cr 
 } } \right]$.
Hence, $A = B^{-1} \times \left[ {\matrix{
   5 & 3 \cr 
   -2 & -1 \cr 
 } } \right]$
$A = \frac{1}{3m^2+6mk+2k^2} \left[ {\matrix{
   5m+2k & 3m+k \cr 
   2k+4m & 2k+3m \cr 
 } } \right]$
There are two degrees of freedom.
EDIT
Thanks to Qiang Li for pointing out the other degree of freedom
</s>