If $AB=BA$, show that $B$ is diagonalizable.

We were asked to prove the following:

Let $A$ be an $n \times n$ matrix with $n$ distinct real eigenvalues. If $AB=BA$, show that $B$ is diagonalizable.

It was suggested I show that an eigenvector of $A$ is also an eigenvector of $B$. I am both having trouble doing this and failing to see how I would complete the proof after. Any help would be appreciated.

Thanks

-
This is (a weaker version of) part (b) of the following question: math.stackexchange.com/questions/236212/…. It is also a consequence of the statement in this question: math.stackexchange.com/questions/65012/… And this one: math.stackexchange.com/questions/46544/… – Jonas Meyer Jan 24 '13 at 3:30
Hey Jonas, I still don't understand how it is that if $v$ is an eigenvalue of $A$ corresponding to some eigenvalue $\lambda$, that $A(Bv)= \lambda Bv$ implies that $v$ is also an eigenvector of $B$. I was wondering if you could clear that up for me. Thanks. – Ernest Singleton Jan 24 '13 at 4:44

From a comment:

I still don't understand how it is that if $v$ is an eigenvector of $A$ corresponding to some eigenvalue $\lambda$, that $A(Bv)=\lambda Bv$ implies that $v$ is also an eigenvector of $B$.

If we see that this is true, then we will be able to conclude that $B$ is diagonalized by a basis of eigenvectors for $A$.

It is true because the eigenspace of $A$ for the eigenvalue $\lambda$, $\{x:Ax=\lambda x\}$, is one dimensional by the hypothesis that $A$ has $n$ distinct eigenvalues. The equation $A(Bv)=\lambda Bv$ says that $Bv$ is in this space, which is spanned by $v$. Therefore there exists a scalar $c$ such that $Bv=cv$.

-
I understand now. Thank you very much. I just wasn't considering the one dimensionality of the eigenspace. Thank you very much Jonas. – Ernest Singleton Jan 24 '13 at 5:03

So $A$ is diagonalizable with n distinct elements on its main diagonal, $A=diag$ $(a_1,..., a_n)$. Let $B=(b_{ij})$, do the multiplication for both sides of $AB=BA$ and use component-wise correspondence for matrix equality. Now you see the elements off the main diagonal of B must be zero

-