# Write square of vector elements as diagonal matrix

Suppose $x = (x_1,...,x_n)^T$ is some vector in $\mathbb{R}^n$. I want to write the square diagonal matrix $$\begin{bmatrix} x_1^2 & 0 & \cdots & 0 \\ 0 & x_2^2 & \cdots & 0 \\ 0 & 0 & \ddots & 0 \\ 0 & 0 & \cdots & x_n^2 \end{bmatrix}$$

in terms of some matrix/vector operations on $x$. I'm not even sure this is possible but my first though is use somehow use the matrix $xx^T$ because it has the correct diagonal, but then I'm not really sure what to subtract to get rid of the non-diagonal entries. Thanks for the help.

• so we can only use $x$ and $x^T$? or what other things can we use? Jun 15 '17 at 0:53
• Ideally yes only those two. But I'm open to any suggesting you have I just don't want something like $diag(x_1^2,...,x_n^2)$. Jun 15 '17 at 0:59

Here is a possibility for the $2\times2$ case - I think the extension to the $n\times n$ case is fairly obvious: $$\pmatrix{1&0\cr0&0\cr}\pmatrix{x\cr y\cr}\pmatrix{x&y\cr}\pmatrix{1&0\cr0&0\cr}=\pmatrix{x^2&0\cr0&0\cr}$$ and $$\pmatrix{0&0\cr0&1\cr}\pmatrix{x\cr y\cr}\pmatrix{x&y\cr}\pmatrix{0&0\cr0&1\cr}=\pmatrix{0&0\cr0&y^2\cr}$$ and adding these gives the matrix you want.