5

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!

iridium
  • 395

1 Answers1

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