[Math] If a matrix commutes with all diagonal matrices, must the matrix itself be diagonal

linear algebra

I'm new to stackexchange so feel free to correct my style/format/logic etc.

The question is this: let's say $A$ is a square matrix of size $n$. I would like to show that $AD = DA$, for any diagonal matrix $D$ also of size $n$, if and only if $A$ is also diagonal.

I think I have some of the proof but am not very confident in it.

$\Leftarrow $:
If A is diagonal, it is not too hard to show that $AD = DA$, because multiplying two diagonal matrices just amounts to multiplying the corresponding diagonal entries.

$\Rightarrow$:
(i) $DA$ is found by multiplying each row in A with the corresponding entry along the diagonal in $D$. $AD$ is found by multiplying each column in $A$ with the corresponding entry along the diagonal in $D$. Since $AD = DA$, this product has to be symmetric.

(ii) Now suppose $A$ weren't a diagonal matrix. Then if we make the entries along the diagonal in $D$ all different, $AD$ won't be symmetric anymore (?). This contradicts (i), so we have shown both ways.

Does this work?

[edited]

Best Answer

Here's a geometric formulation. If two matrices $A,D$ commute, then all eigenspaces for $D$ must be $A$-stable (if $v$ is eigenvector for $D$ and eigenvalue $\lambda$, then $DA\cdot v=AD\cdot v=A\cdot\lambda v=\lambda(A\cdot v)$, so $A\cdot v$ is eigenvector for $D$ and eigenvalue $\lambda$ as well). Now for every standard basis vector $e_i$ there is a diagonal matrix $D$ for which $\langle e_i\rangle$ is an eigenspace for $D$, for instance the elementary matrix $D=E_{i,i}$. Since $A$ must commute with all such $D$, it must stabilise every line $\langle e_i\rangle$, and this forces $A$ to be diagonal.

If your field has at least $n$ elements (in particular if it is infinite), you can arrange for a single $D$ to have every line $\langle e_i\rangle$ as eigenspace, and then just commuting with this single $D$ will force being diagonal.