Vectorization of a diagonal matrix

563 Views Asked by At

Is there any representation for the vectorization of a diagonal matrix $\text{vec}(\text{Diag}(x))$?

For example, for two elements $$\text{vec}(\begin{bmatrix} x_1 & 0 \\ 0 &x_2 \end{bmatrix}) = \begin{bmatrix} 1 & 0 \\ 0 & 0 \\ 0 & 0 \\ 0 & 1 \end{bmatrix} \begin{pmatrix} x_1 \\ x_2 \end{pmatrix} \ . $$

In general case, $\text{vec}(\text{Diag}(x)) = A x$, what is the closed form for matrix $A$?

2

There are 2 best solutions below

2
On BEST ANSWER

$A : \Bbb R^n \to \Bbb R^{n^2}$. Let $e_i, i = 1, ..., n$ be the canonical basis vectors of $\Bbb R^n$, and let $f_j, j = 1, ..., n^2$ be the canonical basis vectors of $\Bbb R^{n^2}$

Then $$A = \sum_{i=1}^n f_{ni - n + i}\otimes e_i^T$$

0
On

For $x\in{\mathbb R}^{n}\,$ you can express the matrix $A\in{\mathbb R}^{n^2\times n}\,$ in index notation $$A_{ij} = \begin{cases} {\tt1}\quad{\rm if}\;(i+n=j+nj) \\ {\tt0}\quad{\rm otherwise} \\ \end{cases} $$ This translates verbatim into any language which permits array comprehensions.

For example, to reproduce the matrix in your question, in Julia you could write

n=2; A = [i+n==j+n*j for i=1:n*n, j=1:n] * 1
4×2 Matrix{Int64}:
 1  0
 0  0
 0  0
 0  1