TITLE: When will $AB=BA$?
QUESTION [20 upvotes]: Given two square matrices $A,B$ with same dimension, what conditions will lead to this result? Or what result will this condition lead to? I thought this is a quite simple question, but I can find little information about it. Thanks.

REPLY [2 votes]: There is actually a sufficient and necessary condition for $M_n(\mathbb{C})$:

Let $J$ be the Jordan canonical form of a complex matrix $A$, i.e.,
  $$
A=PJP^{-1}=P\mathrm{diag}(J_1,\cdots,J_s)P^{-1}
$$
  where
  $$
J_i=\lambda_iI+N_i=\left(\begin{matrix}
\lambda_i & & &\\
1 & \ddots & & \\
& \ddots & \ddots & \\
& & 1 & \lambda_i
\end{matrix}\right).
$$
  Then the matrices commutable with $A$ have the form of
  $$
B=PB_1P^{-1}=P(B_{ij})P^{-1}
$$
  where $B_1=(B_{ij})$ has the same blocking as $J$, and
  $$
B_{ij}=\begin{cases}
0 &\mbox{if } \lambda_i\ne\lambda_j\\
\mbox{a }\unicode{x201C}\mbox{lower-triangle-layered matrix''} & \mbox{if } \lambda_i=\lambda_j
\end{cases}
$$

The reference is my textbook of linear algebra, though not in English. Here is an example in the book:

The main part in the proof is to compare the corresponding entries in both sides of the equation $N_iB_{ij}=B_{ij}N_j$ when $\lambda_i=\lambda_j$.