# Dimension of the space of matrices that commute with a diagonal matrix with different entries on the main diagonal

Assume $$A\in M_n(\mathbb{R})$$ which means $$A$$ is an $$n\times n$$ matrix over field of real numbers. Define $$C(A)=\{B\in M_n(\mathbb{R}) \mid AB=BA\}$$. It can be shown that $$C(A)$$ is a vector space over real numbers field. In general, we can show $$\text{dim } C(A)\geq n$$. In a specific case, assume $$A$$ is a diagonal matrix that all entries on main diagonal are pairwise different. In this case, what is $$\text{dim }C(A)$$?

I suspect that dimension of‌ $$C(A)$$ in this case is equal to $$n$$. We know all the diagonal matrices commute with this $$A$$. So we can introduce a basis with elements $$E_1,\dots,E_n$$ which $$E_i$$ is a matrix that its $$(i,i)$$ entry is one and all the other entries are zeros. So the dimension is $$n$$. But I'm not sure it's a correct answer, because maybe there are other matrices that commute with $$A$$ that can't be generated with a linear combination of $$E_1,\dots,E_n$$. Is this basis correct or no?

Please don't use minimal and characteristic polynomials of a matrix. I would be really thankful if you use reasonings as elemtary as I said.

Any help is so much appreciated!

• Direct computation shows that if $A$ is a diagonal matrix with pairwise different elements on the diagonal and $AB=BA$, then $B$ is a diagonal matrix. Commented Nov 6, 2023 at 7:23

## 1 Answer

You are correct in your guess that if $$A$$ is diagonal with distinct diagonal elements, then the linearly independent elements $$E_1,\dots,E_n\in C(A)$$ span $$C(A)$$ (hence constitute a basis of $$C(A)$$).

Indeed, assuming more generally that $$A=\begin{pmatrix} d_1 I_{n_1}& 0 &\dots& 0\\ 0&d_2 I_{n_2}&\dots&0\\ \vdots&\vdots&\ddots&\vdots\\ 0&0&\dots&d_pI_{n_p} \end{pmatrix}$$ where $$d_1,\dots,d_p$$ are pairwise distinct, let us check that $$AB=BA$$ iff $$B$$ is of the form $$\begin{pmatrix} C_1& 0 &\dots& 0\\ 0&C_2&\dots&0\\ \vdots&\vdots&\ddots&\vdots\\ 0&0&\dots&C_p \end{pmatrix}$$ where each $$C_k$$ is an $$n_k\times n_k$$ matrix.

It is clear that every matrix of this form commutes with $$A.$$ Conversely, if $$B\in C(A)$$ then $$B$$ is of this form since for each $$k$$, $$\ker(A-d_kI_n)$$ is closed under $$B.$$