Skip to content
Prev 145984 / 398500 Next

matlab eigs function in R

"Jorge Ivan Velez" <jorgeivanvelez at gmail.com> wrote in
news:317737de0806030529t50fdced9r49156de606a0d198 at mail.gmail.com:
He had looked, but since eigen returns both eigenvalues and 
eigenvectors, and does so in a list, perhaps he needs advice about how 
to extract his values from the list structure.

x <- matrix(c(1:5, (1:5)^2, (1:5)^(1/2), 0,0,0,1,0, 0,0,0,0,1),5, 5)

str(eigen(x))
#List of 2
# $ values : cplx [1:5] 7.43+0i 1.00+0i 1.00+0i ...
# $ vectors: cplx [1:5, 1:5] 0.0699+0i 0.1600+0i 0.2894+0i ...

d <- 3

eigen(x)$values[1:d]

[1] 7.431675+0i 1.000000+0i 1.000000+0i

#no need to sort since eigen does that by default.

Not sure we can help him out regarding the "slight difference" btwn 
Matlab values and R values due to the unnecessary vagueness of his 
concern.