Show that Rank $(A)$ = Rank$(A^2)$ $\iff \exists$ B invertible s.t. $A^2= B A$. Given $n \times n$ matrix $A$, not necessarily invertible, what invertible matrix $B$ solves $A^2= B A$?
$B$ should be $A$ but that is what not being said in the claim above. Please help. Thanks in advance.

The equation $A^2=BA$ can be rewritten as
$$(B-A)A=0. \tag{*}$$
Let's define $C=B-A$, that is, $B=A+C$. So what properties does $C$ need to have?
Let's first consider a vector $v$ in the image of $A$, that is, there exists a vector $w$ such that $w=Av$. But then we have $Cv = CAw = 0$ because of $(*)$.
On the other hand, be $v$ a non-zero vector orthogonal to the image of $A$. Then $Bv = Av + Cv = Cv$. But $B$ is invertible, therefore $Bv\ne 0$.
Therefore the kernel of $C$ is exactly the image of $A$.
Finally we have the condition $\operatorname{rank} A=\operatorname{rank} (A^2)$. Clearly $\operatorname{im}(A^2)\subseteq\operatorname{im} A$. Now since the rank is the dimension of the image, and a finite dimensional subspace has the same dimension as the full space only if it is the full space, we get
$$\operatorname{im} A = \operatorname{im}(A^2).$$
This implies that the image and kernel of $A$ intersect only on the zero vector.
Now using all the above, I claim that if $P$ is the orthogonal projection onto the image of $A$, then $C=I-A$ (where $I$ is the identity matrix) gives the desired matrix, which therefore exists.
Proof:

*

*$BA=A^2$:
By definition of $P$, we have $PA=A$. Therefore we have
$$CA = (I-P)A = IA-PA = A-A = 0. \tag{(**)}$$
And therefore we get
$$BA = (A+C)A = A^2 + CA = A^2$$


*$B$ is invertible:
Be $v\ne 0$. Then we have
\begin{align}
Bv &= (A+C)v\\
   &= (P+C)(A+C)v && \text{because $P+C=I$}\\
   &= PAv + CAv + PCv + C^2v \\
   &= Av + CPAv + PCv + C^2v && \text{$PA=A$ by definition of $P$}\\
   &= Av + Cv && \text{$CP=PC=0, C^2=C$}
\end{align}
Now $Av$ clearly lies in the image of $A$, while $Cv$ lies in the kernel of $A$. But as we have seen above, image and kernel of $A$ only intersect in the zero vector, that is, $Av$ and $Cv$ are linearly independent. Therefore $Av+Cv=0$ implies both $Av=0$ and $Cv=0$. But since the kernel of $C$ is the image of $A$, $Cv=0$ implies that $v$ is in the image of $A$, which in turn implies that $Av\ne 0$.
So we see that $v\ne 0$ implies $Bv\ne 0$, therefore $B$ is invertible. $\square$
