Why is $|\mathbf{a}|^{2T}\mathbf{b}=\mathbf{a}^{T}*diag(\mathbf{b})*\mathbf{a}$ true? 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}$.
 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.$$
A: Edit: I'm not sure if I should leave my answer here or remove it.
I now think that the accepted answer is correct.
Origianlly I gave my answer, because I just got confused by the notation $|\mathbf|$ for the element wise absolute value. I thought it's refering to the absolute value of a vector. Apparently it's a common source of confusion: Is there a mathematical operator that will turn a matrix into its absolute values?
My comments
In the question I assume "absolute value" refers to the euclidean norm of the vector. If that's true $|\mathbf{a}|$ should be a scalar and thus $|\mathbf{a}|^{2}$. A transposed scalar is still a scalar, i.e. $|\mathbf{a}|^{2}\mathbf{b} = |\mathbf{a}|^{2T}\mathbf{b}$.
The accepted answer defines ${\bf v} = |{\bf a}|^2$ with ${\bf a} = [a_1, \ldots, a_N]^\top$.
He then concludes, that ${\bf v} = [a_1^2, \ldots, a_N^2]^\top.$ which I don't understand, because since the absolute value (aka euclidean norm) of a vector is a scaler so should be it's square.
Thus we should have
$\mathbf{v} = |\mathbf{a}|^2 = \left( \left( \sum_{i=1}^N a_i^2 \right)^{1/2} \right)^2 = \sum_{i=1}^N a_i^2$
My answer
What follows is my attempt at answering the original question.
As far as I understand the question is:
Given $\mathbf{a} \in \mathbb{R}^N$ and $\mathbf{b} \in \mathbb{R}^N$ we want to show, that
$$|\mathbf{a}|^{2}\mathbf{b} = \mathbf{a}^\top \text{diag}(\mathbf{b}) \mathbf{a}$$
where $\text{diag}(\mathbf{b})$ is the $N\mathsf{\times} N$ diagonal matrix with the elements of $\mathbf{b}$ on the diagonal and $|\mathbf{a}| = \left( \sum_{i=1}^N a_i^2 \right)^{1/2} = \sqrt{\sum_{i=1}^N a_i^2}$ is the euclidean norm of $\mathbf{a}$.
As far as I can tell the statement we're supposed to proof is not true, because the left side of the equation is a vector, i.e. the vector $\mathbf{b}$ scaled by the scalar $|\mathbf{a}|^2$:
$$|\mathbf{a}|^2 \mathbf{b} = \left( \left( \sum_{i=1}^N a_i^2 \right)^{1/2} \right)^2 \mathbf{b} = \left(\sum_{i=1}^N a_i^2 \right) \mathbf{b}$$
while the right side evaluates to a scalar:
$$
\underset{\text{scalar}}{|\mathbf{a}|^2} \underset{N\times 1}{\mathbf{b}} = \underset{1\times N}{\mathbf{a}^\top} \underset{N\times N}{\text{diag}(\mathbf{b})} \underset{N \times 1}{\mathbf{a}}
$$
