For non-diagonalizable matrices, the dimension of centralizer can be different from $\sum\limits_{j=1}^k d_j^2$ It is known that if a square matrix $A$ is diagonalizable then the subspace
$$C(A)=\{X\in M_{n,n}; AX=XA\}$$
has the dimension $\sum\limits_{j=1}^k d_j^2$, where $d_j$ denotes the geometric multiplicity of the $j$-th eigenvalue. There are several posts on this site related to this fact.1
I suppose that this is no longer true if we do not assume that $A$ is diagonalizable. What are some counterexamples showing that this is no longer true?
1For example, Finding the dimension of $S = \{B \in M_n \,|\, AB = BA\}$, where $A$ is a diagonalizable matrix, To prove that the dimension of $V$ is $d_1^2 + \ldots + d_k^2$, Show $\dim(U) = d_1^2 + d_2^2 + \cdots + d_k^2$, where $U$ is the set of matrices that commute with a diagonalizable matrix $A$, Let $D$ be an $n \times n$ diagonal matrix whose distinct diagonal entries are $d_1,\ldots, d_k$, and where $d_i$ occurs exactly $n_i$ times., Hoffman Exercise, Linear Algebra, Dimension of centralizer of a diagonalizable matrix., The Dimension of Vector Space.
My motivation for asking this is that there are questions about commuting matrices and specifically about this claim for diagonalizable matrices are posted on this site quite often. So it might be useful to have somewhere on this site a counterexample showing that this is no longer true after omitting this condition.
I have also posted in an answer a counterexample which seems relatively simple to me. Naturally, it is still interesting if somebody can provide other answers with different approaches or other useful insights.
 A: If $A$ consists of a single Jordan block of size $n\times n$, i.e., 
$$A=J=
\begin{pmatrix}
  \lambda & 1 & \ldots & \ldots & 0 \\
  0 & \lambda & 1 &  & \vdots \\
  \vdots &  & \ddots & \ddots & 0 \\
  \vdots &  &  & \lambda & 1 \\
  0 & \ldots & \ldots & 0 & \lambda \\
\end{pmatrix},
$$
then we can write it as $J=\lambda I+N$ where
$$N=\begin{pmatrix}
  0 & 1 & \ldots & \ldots & 0 \\
  0 & 0 & 1 &  & \vdots \\
  \vdots &  & \ddots & \ddots & 0 \\
  \vdots &  &  & 0 & 1 \\
  0 & \ldots & \ldots & 0 & 0 \\
\end{pmatrix}.$$
It is clear that $(\lambda I+N)X=X(\lambda I+N)$ is equivalent to $XN=NX$.
And it is also easy to see that $N$ commutes with $I,N,N^2,\dots,N^{n-1}$. These matrices are linearly independent. (Just notice that each of them has ones only on one diagonal, and it is a different diagonal for each power.) 
So the dimension of the subspace $C(A)$ is at least $n$. (In fact, we could show that it is exactly $n$, but this is not really needed to find a counterexample.)
On the other hand, $J$ has only one eigenvalue which has geometric multiplicity equal to one. So in this case we get $\sum\limits_{j=1}^k d_j^2=1$.
To summarize:


*

*$\dim C(A)\ge n$ (in fact, $\dim C(A)=n$)

*$\sum\limits_{j=1}^k d_j^2=1$

*$\dim C(A)\ne \sum\limits_{j=1}^k d_j^2$
