I determined the set of all matrices $A$ such that $AB = BA$ for all $B$ in $GL_n(\mathbb R)$ to be the set of $\lambda I$. Now I'm not sure this is true. But quite sure. So I tried to prove it and it seems to work. But I'm not sure my proof is right.
Please can somebody tell me if my proof is right?
I claim that $Z(GL_n(\mathbb R)) = \{\lambda I \mid \lambda \in \mathbb R\}$.
Note that if $D = \lambda I$ and $A$ is any matrix then
$$(DA)_{ij} = \lambda \sum_k \delta_{ik} a_{kj} = \lambda a_{ij}$$
and
$$(AD)_{ij} = \lambda \sum_k \delta_{kj} a_{ik} = \lambda a_{ij}$$
So if $D$ is a diagonal matrix and $A$ any matrix then $AD = DA$.
Now the other direction: $Z(GL_n(\mathbb R)) \subseteq \{\lambda I \mid \lambda \in \mathbb R\}$.
Let $D$ be a matrix that commutes with all matrices: $AD = DA$. Now by contradiction let $D$ be the matrix that is $\lambda$ on the diagonal and zero everywhere else except $D_{i_0j_0=1}$. Then because
$$ (AB)_{ij} = \sum_k a_{ik}b_{kj}$$
and
$$ (BA)_{ij} = \sum_k b_{ik}a_{kj}$$
we have
$$ (AB)_{ij} = \sum_k a_{ik}b_{kj}$$
and then
$$ (DA)_{i_0j_0} = d_{i_0i_0}a_{i_0j_0} + d_{i_0j_0}a_{j_0j_0} = \lambda a_{i_0j_0} + a_{j_0j_0}$$
$$ (AD)_{i_0j_0} = d_{i_0j_0}a_{i_0j_0} + d_{j_0j_0}a_{i_0i_0} = a_{j_0j_0} + \lambda a_{i_0i_0}$$
are not equal.