[R] matlab eigs function in R

David Winsemius dwinsemius at comcast.net
Tue Jun 3 16:04:12 CEST 2008


"Jorge Ivan Velez" <jorgeivanvelez at gmail.com> wrote in
news:317737de0806030529t50fdced9r49156de606a0d198 at mail.gmail.com: 

> Dear kayteck,
> 
> Function eigen (see ?eigen) will do what you want.
> 
> HTH,

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.

-- 
David Winsemius


> 
> Jorge
> 
> 
> On Tue, Jun 3, 2008 at 5:42 AM, kayteck_master
> <kayteck_master at o2.pl> wrote: 
> 
>>
>> Hello
>>
>> Does anybody know how one can compute d largest
>> eigenvalues/eigenvectors in R, like in MATLAB eigs function ? eigen
>> function computes all eigenvectors/eigenvalues, and they are
>> slightly different than those generated by matlab eigs.
>>
>> Thanks in advance
>> --

>



More information about the R-help mailing list