Find $n \times n$ matrices $A$ such that $\det A = 0$ and $\text{rank}(AB) = \text{rank}(BA)$ for any $n \times n$ matrix $B$ Find all complex-valued $n \times n$ matrices $A$ such that $\det A = 0$ and $\text{rank}(AB) = \text{rank}(BA)$ for any $n \times n$ complex-valued $B$.
I believe that $A = 0$ is the only answer. 
I have been able to prove that, if $A$ is of rank $r$, then any $r$ lines and any $r$ columns are linearly independent. To see this, note that since $A$ is of rank $r$, then A has $r$ linearly independent columns; say that the indexes of these columns are $i_1, i_2, ..., i_r$. Then by making B equal to a matrix that has 1 in positions $(i_k,i_k)$ and 0 elsewhere, $AB$ basically "selects" $r$ independent columns from $A$ having all other columns equal to 0, so $\text{rank} AB = r$.
Now, $BA$ selects rows $i_1,i_2,..,i_r$ from $A$. If $A$ were to have $r$ rows that were not linearly independent, then there would be an inversible matrix $M$ which would place these rows in positions $i_1,i_2,...,i_r$. Then 
$$\text{rank} (BA) = \text{rank} (BAM) < r,$$
which would contradict our hypothesis. Thus any $r$ rows of $A$ are linearly independent. Running the same argument in reverse, we get that any $r$ lines of $A$ are linearly independent. 
Any ideas about how to proceed? 
 A: Here is a simple way. Suppose $A\ne 0$ and $\det A=0$. Then its null space $N(A)$ and its range $R(A)$ are both nontrivial. So we can pick any nonzero $v\in N(A)$ and $w\in R(A)$. 
Choose any linear map $\mathbf{B}:\mathbb{R}^n\to N(A)\subseteq\mathbb{R}^n$ such that $\mathbf{B}w=v$, and let $B$ be its matrix. Then it is easy to verify that $AB=0$ but $BA\ne 0$. 
A: Another way to do it: assume $\operatorname{rank}A=r$.
Since both conditions (rank and $\det$) are invariant under pre- and postmultiplication of $A$ by an invertible transformation $\color{red}{(*)}$, it is enough to consider $A$ in the form
$$
A=\begin{bmatrix}I_r & 0\\0 & 0\end{bmatrix}.
$$
The rank condition becomes
$$
\operatorname{rank}\left(\begin{bmatrix}I_r & 0\\0 & 0\end{bmatrix}B\right)=
\operatorname{rank}\left(B\begin{bmatrix}I_r & 0\\0 & 0\end{bmatrix}\right).
$$
Now it is easy to find a $B$ that contradicts the equality if $0<r<n$.
P.S. Explaining $\color{red}{(*)}$: let $A=L\Sigma R$ where $L$, $R$ are invertible. Then $\det A=0$ iff $\det\Sigma=0$ and
$$
\operatorname{rank}\Sigma\, RBL=
\operatorname{rank}L\Sigma R\,B=
\operatorname{rank}B\,L\Sigma R=
\operatorname{rank}RBL\,\Sigma.
$$
Take $RBL$ as a new $B$ matrix (arbitrary).
A: Here is a reasoning to show just how difficult it is to have the ranks of $AB$ and $BA$ to be equal for all $B$, or even just for all $B$ of rank$~1$ (in making that limitation, my answer is similar to the one by Eclipse Sun). Such rank$~1$ matrices can be obtained as matrix products $B=CR$ where $C,R$ are nonzero column respectively row matrices (i.e., of size $n\times 1$ respectively $1\times n$). Changing $C$ in this expression can always be obtained (in many ways if $n>1$) by left-multiplication by some invertible matrix, and this therefore does not change the rank of $BA$; in the same way changing $R$ can be obtained by right-multiplication by some invertible matrix, and this therefore does not change the rank of $AB$. It follows that if the ranks of $AB$ and $BA$ are to be equal for all such$~B$, both have to be independent of $B$ altogether.
But then then only possibilities are when both ranks are always$~1$, which happens only for invertible matrices $A$ that were excluded by the hypothesis $\det(A)=0$, or when both ranks are always$~0$ which happens only for $A=0$.
In a bit more detail you can see, in the given situation, that the rank of $AB$ equals that of $AC$, and that the rank of $BA$ equals that of $RA$ (both are in $\{0,1\}$), and this quickly gives the indicates reasoning.
