# A matricial process to assign different values to elements of a diagonal matrix

Consider having vector

$$v = \begin{pmatrix} v_1\\ v_2\\ \vdots\\ v_n \end{pmatrix}$$

Consider the final result:

$$V = \begin{pmatrix} v_1 & 0 & \dots & 0\\ 0 & v_2 & \dots & 0\\ \vdots & \vdots & \ddots & \vdots\\ 0 & 0 & \dots & v_n\\ \end{pmatrix}$$

How to get matrix $V$ operating on $v$ with matricial operations?

Thanks

-
$\sum_i v^Te_i\cdot e_ie_i^T$ with the $i$-th standard basis vector denoted by $e_i$. – martini May 15 '12 at 6:56
What are 'matricial operations'? – copper.hat May 15 '12 at 7:00
I mean just products and sums... – Andry May 15 '12 at 7:02

You can see that the basis vectors must be involved in this conversion, because the result depends on the basis we use. For example, $v=(1,\dots,1)^T$ will produce the identity matrix, but not if we operate in a different basis. This is why there cannot be a natural coordinate-free transformation of $v$ into $V$.
In the formula given by martini, $V=\sum_{i=1}^n (v^T e_i)(e_ie_i^T)$, the product $e_ie_i^T$ is the matrix with $(i,i)$ entry $1$ and other entries $0$. Multiplication by the scalar $v^T e_i = v_i$ turns $1$ into $v_i$. Summation over $i$ completes the construction.
By the way, Matlab has built-in diag(v) for this purpose.