I haven't been able to work this problem out myself so I'm coming here for some inspiration about this simple problem (as stated in the title):
Why is the following true:
$|\mathbf{a}|^{2T}\mathbf{b}=\mathbf{a}^{T}*diag(\mathbf{b})*\mathbf{a}$
with $\mathbf{a}$ a vector of dimensions $N\times1$, $\mathbf{b}$ also a vector with dimensions $N\times1$, and $diag(\mathbf{b})$ a diagonal matrix with on its diagonal the elements of the vector $\mathbf{b}$. (The $*$-sign is just a sign for normal matrix multiplication.) Also, $|\mathbf{a}|^{2T}$ is the transpose of the square of the absolute values of the vector $\mathbf{a}$.
Let's call ${\bf v} = |{\bf a}|^2$. In particular, if: $${\bf a} = [a_1, \ldots, a_N]^\top,$$ then: $${\bf v} = [a_1^2, \ldots, a_N^2]^\top.$$
Therefore:
$${\bf v}^\top {\bf b} = \sum_{i=1}^N a_i^2 b_i.$$
On the other hand,
$$\text{diag}({\bf b}) {\bf a} = [b_1a_1, \ldots, b_N a_N]^\top,$$
and hence:
$${\bf a}^\top \text{diag}({\bf b}) {\bf a} = \sum_{i=1}^N a_i \cdot (b_ia_i) = \sum_{i=1}^N a_i^2 b_i.$$