Find all symmetric matrices $X=X^{T}$ such that 
\begin{align}
XDX^{T}=-D \quad (1)
\end{align}
where $D\ne 0$ is a real diagonal matrix. 


For example, $X=iI$ satisfies $(1)$. Can you get a necessary and sufficient characterization for such matrices $X$? Thanks a lot. 



quadratic matrix equation
Since $XD^2=XD(-XDX)=-XDXDX=(-XDX)DX=D^2X$, the matrices $X$ and $D^2$ commute. W.L.O.G we can assume that entries of $D$ which have the same absolute value are consecutive (multiply with a permutation matrix). It follows that $X$ has block diagonal form where each absolute value corresponds to a block. The block corresponding to the value $0$ (if it exists) is an arbitrary symmetric matrix. Let $Y$ be the block of $X$ with absolute value $a\neq 0$ and let $p$ be the number of diagonal entries which are equal to $a$ and $q$ the number of diagonal entries of $D$ which are equal to $-a$. Then $YI\_{p,q}Y=-I\_{p,q}$ where $I\_{p,q}=diag(\underbrace{1,\dots,1}\_{p},\underbrace{-1,\dots,-1}\_{q})$. Since $Y$ is symmetric there exist a Autonne–Takagi factorization $Y=V^TMV$ with unitary $V$ and diagonal $M=diag(m\_1,\dots m\_{p+q})$ with $m\_i\geq 0$. Therefore $V^TMVI\_{p,q}V^TMV=-I\_{p,q}$ and hence $M(VI\_{p,q}V^T)M=-conj(VI\_{p,q}V^T)$. Hence it follows that $VI\_{p,q}V^T=iZ$ where $Z$ is a real symmetric matrix. Furthermore if $Z\_{j,k}\neq 0$ we have $m\_jm\_k=1$. On the other hand every matrix consisting of blocks $Y=V^TMV$ satisfying the conditions above will by construction be a solution.


