Given a vector $[x_1,x_2,x_3, \dots, x_n]^T$, is it possible to obtain a diagonal matrix,
$ \left[\begin{array}{c c c c c} x_1 & 0 & 0 & \dots & 0\\ 0 & x_2 & 0 & \dots & 0\\ 0 & 0 & x_3 & \dots & 0\\ \vdots & \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & 0 & \dots & x_n\\ \end{array} \right] $
using matrix operations (like multiplication and/or addition with identity matrix etc)? This seems trivial, but I am unable to work it out!
I need to do this for automation of process in Maxima, so that I don't have to manually type in the elements diagonally. Thanks.
EDIT:
I recently found a direct function diag_matrix(x1,x2,x3,...)
in Maxima. Which means that if we have a list [x1, x2, x3]
, we can use apply(diag_matrix, [x1, x2, x3])
. I am not sure if it is introduced in a recent version or it existed before I posted this question.
diag_matrix(x1,x2,x3,...)
in maxima. I am not sure if it is introduced in a recent version or it existed before I posted this question. $\endgroup$