Question: Convert Vector to diagonal Matrix

I am looking for a more eligent way to convert a Vector to a Diagonal Matrix.

restart

 

 

with(LinearAlgebra):

 

V:=Vector[column](3, [0.5863730366, 0.1171249270, 0.2965020364])

Vector(3, {(1) = .5863730366, (2) = .1171249270, (3) = .2965020364})

(1)

Vm:=Matrix(3,[[V[1],0,0],[0,V[2],0],[0,0,V[3]]])

Matrix(3, 3, {(1, 1) = .5863730366, (1, 2) = 0, (1, 3) = 0, (2, 1) = 0, (2, 2) = .1171249270, (2, 3) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = .2965020364})

(2)

Vm1:=Matrix(3,3):

for i to 3 do
Vm1[i,i]:=V[i];
end do:

Vm1

Matrix(3, 3, {(1, 1) = .5863730366, (1, 2) = 0, (1, 3) = 0, (2, 1) = 0, (2, 2) = .1171249270, (2, 3) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = .2965020364})

(3)
 

 

Download 2024-12-26_Q_Diagonal_Matrix_from_Vector.mw

Please Wait...