Let
$$ D= \left[\begin{matrix} d_1 & 0 & 0 \\ 0 & d_2 & 0 \\ 0 & 0 & d_3 \\ \end{matrix}\right]$$
and
$$Q=\left[\begin{matrix} q_1 & q_2 & q_3 \\ q_2 & q_4 & q_5\\ q_3 & q_6 & q_7 \\ \end{matrix}\right]$$
Find a symmetric matrix $P$ that satisfies the matrix equation $PD+DP=-Q$.
How can I solve it? Help me solve it.
Using Einstein's summation convention and dropping the $-$ sign which is essentially useless:
$$ q_{ij} = p_{ik} d_{kj} + d_{ik}p_{kj} $$
but $d_{ik} = d_{i}\delta_{ik}$ where $\delta_{ik}$ is 1 if $k=i$, $0$ otherwise so that:
$$ q_{ij} = p_{ij} d_j + d_{i} p_{ij} = p_{ij} (d_i+d_j)$$
and finally $p_{ij} = q_{ij}/(d_i+d_j)$
Small (inefficient but hopefully clear) Julia code to check it:
should give you something < 1e-15