Tuesday, October 7, 2025

diag(x)

When using \({\bf diag}(x)\) in a text, there is always the nagging feeling that there must be a nice way to express this in standard matrix algebra (i.e., some combination of identity matrices, all-ones vectors, and standard matrix multiplications). To remind ourselves, the \({\bf diag}(x)\) function creates a diagonal matrix with \(x_i\) as diagonal elements: \[{\bf diag}(x) = \begin{bmatrix} x_1 & & & \\ & x_2 & & \\ & & \ddots & \\ & & & x_n \end{bmatrix} \] Obviously, my intuition is wrong here, as I have never seen such formulation, and \({\bf diag}(x)\) is used all over the place. I have seen some attempts, but they require exotic notation, and, as a result, don't really improve upon straight use of \({\bf diag}(x)\).