What is the dimension of a certain vector subspace of invariant matrices? $\newcommand{\Sig}{\Sigma}$
Let $\Sig$ be a diagonal matrix with strictly positive entries on the diagonal. Define $V=\{B \in M_n\mid B\Sig +\Sig B^T=\Sig B +B^T \Sig \}$ (where $M_n$ is the vector space of $n \times n$ real matrices).
What is the dimension of $V$? Is there a "nice" basis for it?
Clearly $V$ contains the subspace of the symmetric matrices.
So $\dim V \ge \frac{n(1+n)}{2}$.
Of course the anser depends on $\Sig$. If $\Sig =Id$ then $V=M_n$. 
It seems that the more identical entries, the larger is $V$.
Is $\dim V$ only dependent on the number of different entries of $\Sig$? If so, what is the functional dependence?
 A: Since $V$ contains the subspace of symmetric matrices, we can write $B$ as the sum of a symmetric matrix and an antisymmetric matrix that's also in $V$. Antisymmetric matrices $A$ in $V$ fulfil $A\Sigma-\Sigma A=\Sigma A-A\Sigma$ and thus $A\Sigma=\Sigma A$, that is, they commute with $\Sigma$. That means an entry $A_{ij}$ can be non-zero iff $\Sigma_{ii}=\Sigma_{jj}$. Thus, if $\Sigma$ has multiplicities $l_i$ (that is, $l_i$ identical elements $\sigma_i$ on the diagonal), the dimension of $V$ is
$$
\frac{n(n+1)}2+\sum_i\frac{l_i(l_i-1)}2\;.
$$
A basis is given by the canonical basis of the symmetric matrices together with those elements of the canonical basis of the antisymmetric matrices that correspond to rows and columns with equal diagonal elements in $\Sigma$.
A: Let $\lambda_1, \dots, \lambda_n$ be the diagonal entries of $\Sigma$; note that $\Sigma$ is invertible, and the diagonal entries of $\Sigma$ are $\lambda_1^{-1}, \dots, \lambda_n^{-1}$. Now, we can rewrite your condition on $B$ as $B-B^T = \Sigma^{-1}(B-B^T)\Sigma$.
Let $B \in M_n$. For $1 \leq i,j \leq n$, let $c_{i,j}$ be the $(i,j)$ entry of $B-B^T$. Then, the $(i,j)$ entry of $\Sigma^{-1}(B-B^T)\Sigma$ is $\lambda_i^{-1}\lambda_j c_{i,j}$. So $B$ satisfies the above equation (i.e., $B \in V$) if and only if either $\lambda_i = \lambda_j$, or $c_{i,j} = 0$.
Since $\Sigma$ is fixed, $B \in V$ is equivalent to the constraint that $c_{i,j} = 0$ for all $i,j$ such that $\lambda_i \neq \lambda_j$. In other words, for all such $i,j$, $b_{i,j} = b_{j,i}$, where $b_{i,j}$ represents the $(i,j)$ entry of $B$.
So if we let $S := \{(i,j) : \lambda_i \neq \lambda_j\}$, then a basis for $V$ would be $\{E_{i,j} + E_{j,i} : (i,j) \in S\} \cup \{E_{i,j} : (i,j) \notin S\}$, where $E_{i,j}$ denotes the matrix whose $(i,j)$ entry is 1, and whose other entries are 0. Note that the left part of this union contains $|S|/2$ elements, since each $(i,j)$ and $(j,i)$ in $S$ contributes the same matrix. So $\dim V = |S|/2 + (n^2-|S|)$.
Note that $|S|$ (and hence $\dim V$) depends not only on the number of different entries of $\Sigma$, but how many of each there are; for instance, if its entries are $1,2,2,2$, then $|S| = 6$, but if its entries are $1,1,2,2$, then $|S| = 8$.
