<s>[INST] For matrices, under what conditions can we write $AB = BC$? If $A$ and $B$ are real matrices, when does there exist a matrix $C$ such that $AB = BC$? I understand that there is the case where $A$ and $B$ commute so $AB =BA$, but is there a more general rule (ie. necessary and sufficient conditions)?
Thanks!
 [/INST] One could interpret the question as: given a matrix $B \in M^{m\times n}$, describe the subspace of $A \in M^{m \times m}$ for which there exists $C \in M^{n \times n}$ such that $AB = BC$.
If $B$ has rank $r$ and $P \in \text{GL}_n$ and $Q \in \text{GL}_m$ are such that $B = P \begin{pmatrix}I_r & 0_{r \times n-r} \\ 0_{m-r \times r} & 0_{m-r \times n-r} \end{pmatrix} Q$, then this is equivalent to
$$P^{-1}AP \begin{pmatrix}I_r & 0_{r \times n-r} \\ 0_{m-r \times r} & 0_{m-r \times n-r} \end{pmatrix} = \begin{pmatrix}I_r & 0_{r \times n-r} \\ 0_{m-r \times r} & 0_{m-r \times n-r} \end{pmatrix} QCQ^{-1} \tag{1}$$
Writing $PAP^{-1} = \begin{pmatrix}X_{r \times r} & X_{r \times m-r} \\ X_{m-r \times r} & X_{m-r \times m-r} \end{pmatrix}$ and $QCQ^{-1} = \begin{pmatrix}Z_{r \times r} & Z_{r \times n-r} \\ Z_{n-r \times r} & Z_{n-r \times n-r} \end{pmatrix}$, $(1)$ becomes
$$\begin{pmatrix}X_{r \times r} & 0_{r \times n-r} \\ X_{m-r \times r} & 0_{m-r \times n-r} \end{pmatrix} = \begin{pmatrix}Z_{r \times r} & Z_{r \times n-r} \\ 0_{m-r \times r} & 0_{m-r \times n-r} \end{pmatrix}$$
so that $X_{m-r \times r} = 0$, and this is the only restriction.
Conclusion: The said subspace of $A \in M^{m \times m}$ is
$$P^{-1}\begin{pmatrix}*_{r \times r} & *_{r \times m-r} \\ 0_{m-r \times r} & *_{m-r \times m-r} \end{pmatrix}P$$
It has dimension $m^2-mr+r^2$.
</s>