I have the following equation:

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

where

• $$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.

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

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$$
$$M = B^T P B$$
• 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.