# Product of symmetric matrices

Let $A \in \mathbb{R}^{n \times n}$ be symmetric. I am trying to understand under which conditions on $B \in \mathbb{R}^{n \times n}$ the product $AB$ is also symmetric. It is clear that if $B$ is symmetric and commutes with $A$, we have $$(AB)^T = B^TA^T = BA = AB.$$ Do you see whether the result still holds under weaker conditions?

Let $A\in {\mathbb R}^{n\times n}$ a symmetric matrix. Then there exists an orthogonal matrix $Q\in {\mathbb R}^{n\times n}$ such that $A=QDQ^T$ where $D\in {\mathbb R}^{n\times n}$ is a diagonal matrix. Moreover, we may assume that $D=\alpha_1 I_{n_1}\oplus \cdots \alpha_n I_{n_k}$, where $\alpha_i\in {\mathbb R}$ $(i=1, \ldots, k)$ are distinct eigenvalues of $A$ and $n_1+\cdots+n_k=n$.
Assume that $B\in {\mathbb R}^{n\times n}$ is such that $AB$ is symmetric. Then $$AB=(AB)^T=B^TA^T=B^T A.$$ Hence $B$ has to satisfy the condition $$AB=B^TA \tag1.$$ It is obvious that the converse holds as well: if $B\in {\mathbb R}^{n\times n}$ satisfies (1), then $AB$ is symmetric. Note that it follows thata symmetric $B\in {\mathbb R}^{n\times n}$ commutes with $A$ if and only if $AB$ is symmetric. Let us look for non-symmetric $B\in {\mathbb R}^{n\times n}$ satisfying (1).
If we replace $A$ by $QDQ^T$, then (1) read as $$QDQ^TB=B^TQDQ^T$$ which gives $$D(Q^TBQ)=Q^TB^TQD=(Q^TBQ)^TD.$$ It follows that $C\in {\mathbb R}^{n\times n}$ satisfies condition $$DC=C^TD \tag 2$$ if and only if $B=QCQ^T$ satisfies (1). Hence it is enough to consider (2). Write $D$ as a block diagonal matrix $$D=\left( \begin{array}{cccc} \alpha_1 I_{n_1} & 0 & \ldots & 0\\ 0 &\alpha_2 I_{n_2} & \ldots & 0\\ \vdots & \vdots & \ddots & \vdots\\ 0 & 0 & \ldots & \alpha_k I_{n_k} \end{array} \right)$$ and assume that $$C=\left( \begin{array}{cccc} C_{11} & C_{12} & \ldots & C_{1k}\\ C_{21} &C_{22} & \ldots & C_{2k}\\ \vdots & \vdots & \ddots & \vdots\\ C_{k1} & C_{k2} & \ldots & C_{kk} \end{array} \right)$$ satisfies (2). Then one has $$\alpha_i C_{ij}=\alpha_j C_{ji}^{T}. \tag3$$ Let us agree that $\alpha_1=0$ if $0\in \{ \alpha_i;\, 1\leq i\leq k\}$. Then $$C=\left( \begin{array}{cccc} C_{11} & C_{12} & \ldots & C_{1k}\\ \frac{\alpha_1}{\alpha_2}C_{12} &C_{22} & \ldots & C_{2k}\\ \vdots & \vdots & \ddots & \vdots\\ \frac{\alpha_1}{\alpha_k}C_{1k} & \frac{\alpha_2}{\alpha_k}C_{2k} & \ldots & C_{kk} \end{array} \right)$$ where $C_{ij}$ $(1\leq i<j\leq k)$ are arbitrary matrices, $C_{22}, \ldots, C_{kk}$ atre arbitrary symmetric matrices and $$C_{11}\quad \text{is}\quad \left\{ \begin{array}{l} \text{an arbitrary matrix if}\quad \alpha_1=0\\ \text{an arbitrary symmetric matrix if}\quad \alpha_1\ne 0. \end{array} \right.$$