The problem is as in the title. I think the answer is yes.
There is a similar question here: If $AB=BA$ and $AB$ is diagonal are $A$ and $B$ both diagonal?
But the counterexamples are either non-invertible, or $AB=I$.
The problem is as in the title. I think the answer is yes.
There is a similar question here: If $AB=BA$ and $AB$ is diagonal are $A$ and $B$ both diagonal?
But the counterexamples are either non-invertible, or $AB=I$.
If $A$ and $B$ are (invertible) commuting $n \times n$ matrices and $AB$ is diagonal with distinct entries, then $A$ and $B$ are both diagonal. Conversely, $AB$ must of course be diagonal and if it has repeated entries then taking $A$ to be a Jordan block on those entries ("block" if those entries are not consecutive) gives a counterexample.
To see this, note that if $A$ and $B$ commute then $A$ commutes with $AB$, so $A(AB) v = AB (Av)$. Taking $v = e_i$ (the $i$th unit vector) we get $AB(A e_i) = \lambda_i (Ae_i)$ (with $\lambda_i$ the $i$th entry on the diagonal of $AB$). So $Ae_i$ is an eigenvalue of $AB$ with eigenvalue $\lambda$ (or $0$ if $A$ is not assumed to be invertible), and since $AB$ has distinct eigenvalues it must be a multiple of $e_i$. This holds for each $i$, ie $A$ is diagonal.
You can either apply the same argument to $B$, or note that if $AB$ and $A$ are diagonal and $A$ is invertible then so is $B = A^{-1} (AB)$.