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$.
 A: 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
A: Since $AB$ and $BA$ are both defined, we know that $A$ and $B$ are both $2x2$ matrices.  
Let:
$A= \left[ {\matrix{
   x_1 & x_2 \cr 
   x_3 & x_4 \cr 

 } } \right]$  
$B= \left[ {\matrix{
   y_1 & y_2 \cr 
   y_3 & y_4 \cr 

 } } \right]$
Then we get the following equations :  
From $AB$:
$x_1y_1+x_2y_3=3$
$x_1y_2+x_2y_4=1$
$x_3y_1+x_4y_3=2$
$x_3y_3+x_4y_4=1$  
From $BA$:
$y_1x_1+y_2x_3=5$
$y_1x_2+y_2x_4=3$
$y_3x_1+y_4x_3=-2$
$y_3x_2+y_3x_4=-1$  
Then we have eight equations in 8 unknowns, and it should be possible to find A and B.  
