Let $A$ and $B$ be $n$ x $n$ matrices Let $A$ be a diagonal matrix with different diagonal entries. If $B$ is a matrix such that $AB=BA$, show that $B$ is also diagonal.
I think the problem use decomposition, but I stuck to prove it

Call $a_{ij}$ and $b_{ij}$ the entries of $A$ and $B$. Then the entry at place $(i,j)$ of $AB=BA$ can be written
$$
\sum_{k=1}^n a_{ik}b_{kj}=\sum_{k=1}^n b_{ik}a_{kj}
$$
Since $A$ is diagonal, the sum on the left hand side is
$$
a_{ii}b_{ij}
$$
and the sum on the right hand side is
$$
b_{ij}a_{jj}
$$
Thus we have
$$
(a_{ii}-a_{jj})b_{ij}=0
$$
and, when $i\ne j$, …
