# Determine the dimension of a vector space.

Let $A$ be an $n \times n$ diagonal matrix with characteristic polynomial $(x-a)^p(x-b)^q$,where $a$ and $b$ are distinct real numbers. Let $V$ be the real vector space of all $n \times n$ matrices $B$ such that $AB=BA$. Determine the dimension of $V$.

I am getting the answer as $p^2+q^2$.

I first wrote the matrix $A$ as a diagonal matrix with the first $p$ entries along the diagonal as $a$ and the next $q$ entries $b$. Then carry out the multiplication $AB$ and $BA$ and match the entries $(1,1)$ to $(n,n)$. We see that only the $p^2 + q^2$ entries match, the rest must be $0$. Hence, the dimension should be $p^2 + q^2$. Is this the correct answer.

• Why don't you write down explicitly your work? It looks good, though...+1 – DonAntonio Apr 6 '14 at 12:41

Indeed, the dimension is $p^2+q^2$. We can as in the OP suppose without loss of generality that the $p$ first entries of $A$ are $a$ and the $q$ other $b$ (otherwise use permutation matrices).
Then write a matrix $B$ as a block matrix $\pmatrix{B_1&B_2\\ B_3&B_4}$ with $B_1\in\mathcal M_{p\times p}$ and $B_4\in\mathcal M_{q\times q}$. The computation of $AB-BA$ shows, using $a\neq b$, that $B_2=B_3=0$ if and only if $AB=BA$, hence $$V=\left\{\pmatrix{B_1&0\\0&B_2}, B_1\in\mathcal M_{p\times p},B_2\in\mathcal M_{q\times q}\right\}.$$ This space has indeed dimension $p^2+q^2$.