Mathematical expression to form a vector from diagonal elements

I would like to know is there any way to express mathematically (using matrices multiplication, addition, etc.) a vector which is formed from the diagonal elements of a matrix. For example, I have a matrix called $\mathbf{M}$ and I want to create a vector $\mathbf{v}$ such that $\mathbf{v}= \text{diagonal elements of } \mathbf{M} $

Any matrix algebra or operation do that ? Thank you.


Solution 1:

Such an operator using matrix multiplication and addition with the appropriate constant matrices could be done, but you would find that it may be far more convenient to just write the $D(M)$ notation. It would require both left and right multiplication and as many such terms as there are diagonals, then a final overall left or right multiply (resulting in a row or column vector whichever as desired). So quite an inelegant mixup. I will show you.

You can select an element with left and right multiplication: $$ \pmatrix{1 & 0 & 0\\ 0 & 0 & 0\\ 0 & 0 & 0}\pmatrix{a & b & c\\ d & e & f\\ g & h & i}\pmatrix{1 & 0 & 0\\ 0 & 0 & 0\\ 0 & 0 & 0} = \pmatrix{a& 0 & 0\\ 0 & 0 & 0\\ 0 & 0 & 0} $$

Doing that with each diagonal element then summing those up gives a diagonal matrix, and using that diagonal matrix to have a column result looks like this: $$ \pmatrix{a & 0& 0\\ 0& e & 0\\ 0 & 0& i}\pmatrix{1\\ 1\\ 1} =\pmatrix{a\\ e\\ i} $$

Solution 2:

Let $e_i$ be a basis vector of the target n-dimensional vector space. Let $E_{ij}$ be the matrix with 1 in the ij'th position -- a basis "vector" in the space of n by n matrices where we also introduce Frobenius inner product. Then, $$D(M)=\sum_{i=1}^n\langle M,E_{ii}\rangle e_i.$$ It is essentially a projection operator onto the subspace $\{E_{ii}\}$.