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 know for certain that if a matrix $Q$ commutes with a diagonalizable matrix $P$ then $Q$ is also diagonalizable provided $P$ has distinct eigen values.
In here this is not the case.