In many programs you can create diagonal matrix from a vector, like diag function in Matlab and DiagonalMatrix function in Mathematica. I'm wondering whether we can use matrix product (or hadamard product, kronecker product, etc) of a vector and identity matrices to create a diagonal matrix. Thank you!
Asked
Active
Viewed 1,817 times
5
-
4$\left( \mathbf{1} \cdot \mathbf{x}^{\mathrm{T}} \right) \circ \mathbf{I}$? – AnonSubmitter85 Mar 24 '15 at 22:30
1 Answers
6
You can use $$(xe^T) \odot I_n = \mathrm{diag}(x)$$ Where $\odot$ is the hadamard product and $e^T = (1,1,\ldots)\in\mathbb R^n$. The hadamard product basically masks away all off-diagonal elements and $xe^T$ has $x$ as its diagonal.
AlexR
- 24,905