Let $\Gamma$ denote the $n$-by-$n$ matrix which has $1$ in all its entries. Denote $$S := \{A \in \mathcal{M}_n(\mathbb{R}) : A\Gamma = \Gamma A\}$$ Determine the dimension of $S$, and find a basis for $S$.
Simple calculation tells that $S$ consists of all matrices with the sum of each row and column agreeing on a value. This is similar to the case of Magic matrices, so I found a literature for that and conclude that the dimension is $\,n^2 - 2n + 2\,$.
Problem is, how do I find a basis for it?
Exhausting all the possibilities by hand seems undesirable, and I can't think of a way to do it systematically.
First hint: $\Gamma\,$ is symmetric and satisfies $\Gamma^2 =n\,\Gamma$ , so that $\,\frac1n\Gamma\,$ is an orthogonal projector. It is fairly straightforward to see that it projects onto a $1$-dimensional image. Hence $\,\frac1n\Gamma\,$ is similar to $E_{nn}=\left(\begin{smallmatrix} 0 &\ldots &0 \\ \vdots &\ddots &\vdots \\ 0 &\dots &1\end{smallmatrix}\right)$, note that $E_{nn}$ has just one nonzero entry. Similarity means there is some transformation matrix $T$, and $\,TE_{nn}T^{-1}=\frac1n\Gamma\,$ holds. In this context you may consult this .
Consider the commutator map $[\,\cdot\, ,E_{nn}]: \mathcal{M}_n(\mathbb{R})\to\mathcal{M}_n(\mathbb{R}), A\mapsto AE_{nn} -E_{nn}A$, which is linear.
Second hint: $\dim\ker\, [\,\cdot\, ,E_{nn}] = (n-1)^2+1$ may be read off from $$[A,E_{nn}] \;=\; \begin{pmatrix} 0 &\dots &0 &a_{1,n}\\ \vdots &\ddots &\vdots & \vdots\\ 0 &\dots &0 &a_{n-1,n}\\ -a_{n,1} &\dots &-a_{n,n-1} &0\end{pmatrix}$$
First question: How are $S$ and $\,\ker\, [\,\cdot\, ,E_{nn}]\,$ related to each other, in terms of the transformation matrix $T$ ?
Last question: How to systematically deduce from the preceding a basis of $S$ ?