In the problem I am working on I have an expression that looks like
$$B^T\operatorname{diag}(Bx) y$$
where $B$ is a known $m \times n$ matrix, $x$ is an unknown $n \times 1$ vector of variables, and $y$ is a known $m \times 1$ vector, all of real numbers.
The expression above can always be rewritten in the form $Px$ by expanding and collecting like terms, where $P$ is an $n \times n$ matrix. I would like to know how to calculate $P$ using only matrix and vector products.
As an example, take $B = \left( \begin{array}{ccc} -1 & 1 & 0 \\ -1 & 0 & 1\end{array} \right), y = \left( \begin{array}{c} 2 \\ 3\end{array} \right) $.
Then
\begin{align} B^T \operatorname{diag}(Bx) y & = \left( \begin{array}{cc} -1 & -1 \\ 1 & 0 \\ 0 & 1\end{array} \right) \left( \begin{array}{ccc} -x_1 + x_2 & 0\\ 0 & -x_1 + x_3\end{array} \right) \left( \begin{array}{c} 2 \\ 3\end{array} \right) \\[10pt] & = \left( \begin{array}{c} -5x_1 -2x_2 -3x_3 \\ -2x_1 + 2x_2 \\ -3x_1 + 3x_3\end{array} \right) = \left( \begin{array}{cc} -5 & -2 & -3 \\ -2 & 2 & 0 \\ -3 & 0 & 3\end{array} \right) \left( \begin{array}{c} x_1 \\ x_2 \\ x_3\end{array} \right) \end{align}
Therefore $P = \left( \begin{array}{cc} -5 & -2 & -3 \\ -2 & 2 & 0 \\ -3 & 0 & 3\end{array} \right)$
But I do not know how to calculate $P$ as an expression of the other known quantities, $P = F(B,y)$. Thanks.