# If $X$ is diagonal with distinct diagonal entries and $XY = YX$ then $Y$ is also diagonal matrix.

If $X$ is diagonal with distinct diagonal entries and $XY = YX$ then $Y$ is also diagonal.

I was trying to prove this.

I tried as follows -

Since we know that $X$ is of distinct diagonal entries which means that distinct eigenvalues implying that $X$ is diagonalizable.

that is $X = P^{-1}XP$ where $P$ is the matrix whose columns are the eigenvectors of $X$.

Now we are given that $XY = YX$ or $X = Y^{-1}XY$ but this is for all $Y$ I guess.

Now for $Y = P$ it is clear that $Y$ is diagonalizable, but for other $Y$ how we can prove that they are diagonalizable?

Eigenvalues aren't needed here. All that needs to be observed is that $XY$ with $X$ diagonal multiplies the rows of $Y$ by the diagonal entries of $X$, and that $YX$ does the same for $Y$'s columns.

The $(i,j)$-entries of $XY$ and $YX$ are $x_{ii}y_{ij}$ and $x_{jj}y_{ij}$ respectively. If $XY=YX$ and $i\ne j$, $x_{ii}\ne x_{jj}$ implies $y_{ij}=0$, so $Y$ is diagonal.

The easiest way to see it is to look at the elements of $XY = YX$:

$$(XY)_{ij} = \sum\limits_{k = 1}^d X_{ik} Y_{kj} = X_{ii} Y_{ij}.$$

On the other hand,

$$(YX)_{ij} = \sum\limits_{k = 1}^d Y_{ik} X_{kj} = Y_{ij} X_{jj}.$$

Therefore,

$$X_{ii} Y_{ij} = X_{jj} Y_{ij}.$$

If $i \neq j$, then $Y_{ij} = 0$, because $X_{ii} \neq X_{jj}$.

Hint If $A = (a_{i, j})_{1\le i,j\le n}$ and $B = (b_{i, j})_{1\le i,j\le n}$ are matrices, then $$AB = \left(\sum_{k} a_{i, k} b_{k,j}\right)_{1\le i,j\le n}$$