I have the following equation:

$$x^T M x = (x \circ b)^T P (x \circ b) $$


  • $x, b \in \mathbb{R}^D$ are vectors
  • $M, P \in \mathbb{R}^{D \times D}$ are matrices
  • $b, P$ are known
  • $\circ$ denotes the element-wise (Hadamard) product)
  • The equation holds for all $x$.

How can I solve this equation for $M$?

If it helps, I know that M and P are both symmetric positive semi-definite matrices.

  • 2
    $\begingroup$ Note that $b \circ x = B x$ where $B$ is diagonal with $B_{ii} = b_i$. $\endgroup$
    – WimC
    Oct 13, 2021 at 4:46
  • $\begingroup$ Thank you! That makes this so much more obvious. Should I delete my question? $\endgroup$ Oct 13, 2021 at 4:50
  • $\begingroup$ @WimC I can delete, or if you want credit for giving a helpful suggestion, you can write an answer and I'll accept. $\endgroup$ Oct 13, 2021 at 4:50
  • $\begingroup$ Better to write your own answer and accept it. That is perfectly fine! $\endgroup$
    – WimC
    Oct 13, 2021 at 5:15

1 Answer 1


As WimC pointed out in the comments above, $x \cdot b$ can be written as $xB$ or $Bx$ where $B=diag(b)$. Consequently:

$$x^T M x = x^T B^T P B x$$

and therefore

$$M = B^T P B$$

  • 1
    $\begingroup$ It is worth noting that this solution is not unique. Let $y$ be any vector which is orthogonal to $x,$ i.e. $\,x^Ty=0,$ then $\;M'=M+yy^T\;$ is also a solution to the equation. $\endgroup$
    – greg
    Oct 16, 2021 at 3:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .