TITLE: Computing the dimension of a vector space of matrices that commute with a given matrix B,
QUESTION [8 upvotes]: This is part $2$ of the question that I am working on.
For part $1$, I showed that the space of $5\times 5$ matrices which commute with a given matrix $B$, with the ground field = $\mathbb R$ , is a vector space.
But how can I compute its dimension?
Thanks,

REPLY [5 votes]: There is a theorem by Frobenius:

Let $A\in {\rm M}(n,F)$ with $F$ a field and let $d_1(\lambda),\ldots,d_s(\lambda)$ be the invariant factors $\neq 1$ of $\lambda-A$, let $N_i=\deg d_i(\lambda)$. Then the dimension of the vector space of matrices that commute with $A$ is $$N=\sum_{j=1}^s (2s-2j+1)n_j$$