I have a Vector X X <-rnorm(n)
. I've turned it into a diagonal matrix V <- matrix(diag(abs(X),ncol = n)
. I want to raise this to the power of -1/2. I've tried to use expm::expm
with K <- V %^% (-1/2)
, But when I do this it just gets turned into a diagonal matrix of 1's. When it should be (v_i)^(-1/2). How would I fix this?
Out put:
[1,] 0.08378436 0.0000000 0.000000 0.0000000 0.0000000
[2,] 0.00000000 0.9829437 0.000000 0.0000000 0.0000000
[3,] 0.00000000 0.0000000 1.875067 0.0000000 0.0000000
[4,] 0.00000000 0.0000000 0.000000 0.1861447 0.0000000
[5,] 0.00000000 0.0000000 0.000000 0.0000000 0.6334857
[,1] [,2] [,3] [,4] [,5]
[1,] 1 0 0 0 0
[2,] 0 1 0 0 0
[3,] 0 0 1 0 0
[4,] 0 0 0 1 0
[5,] 0 0 0 0 1