[R] Matrix eigenvectors in R and MatLab

Mikael Niva mikael.niva at ebc.uu.se
Thu Apr 3 16:58:41 CEST 2003


Dear R-listers

Is there anyone who knows why I get different eigenvectors when I run
MatLab and R? I run both programs in Windows Me. Can I make R to produce
the same vectors as MatLab?

#R Matrix
PA9900<-c(11/24 ,10/53 ,0/1 ,0/1 ,29/43 ,1/24 ,27/53 ,0/1 ,0/1 ,13/43
,14/24 ,178/53 ,146/244 ,17/23 ,15/43 ,2/24 ,4/53 ,0/1 ,2/23 ,2/43 ,4/24
,58/53 ,26/244 ,0/1 ,5/43)

#R-syntax
PA9900<-matrix(PA9900,nrow=5,byrow=T)
eigen(PA9900)

#R-output
$values
[1]  1.2352970  0.3901522 -0.2562860  0.2259411  0.1742592

$vectors
            [,1]        [,2]        [,3]      [,4]       [,5]
[1,] -0.67795430 -1.70686496 -0.52613955 -8.675109 -0.8413826
[2,] -0.32621100  0.54611272 -0.21526356 -2.726193 -0.2876643
[3,] -2.83313878 -2.88801964  0.87388189 45.427935  4.5069361
[4,] -0.09857565 -0.33015962  0.09136359 -5.426254 -0.8201206
[5,] -0.68977432  0.01977374  0.61772506  3.751978  0.4348802


%Matlab Matrix
PA9900 =[11/24 10/53 0/1 0/1 29/43 ;1/24 27/53 0/1 0/1 13/43 ;14/24
178/53 146/244 17/23 15/43 ;2/24 4/53 0/1 2/23 2/43 ;4/24 58/53 26/244
0/1 5/43]

%MatLab-syntax
[wmat,dmat]=eig(mat)

%MatLab-output
wmat =

   -0.2250    0.4330   -0.4998   -0.1795   -0.1854
   -0.1083    0.1771    0.1599   -0.0614   -0.0583
   -0.9403   -0.7191   -0.8457    0.9617    0.9708
   -0.0327   -0.0752   -0.0967   -0.1750   -0.1160
   -0.2289   -0.5083    0.0058    0.0928    0.0802


dmat =

    1.2353         0         0         0         0
         0   -0.2563         0         0         0
         0         0    0.3902         0         0
         0         0         0    0.1743         0
         0         0         0         0    0.2259

Yours sincerely, Mikael Niva

********************************************
Mikael Niva
Avd. för Växtekologi, Dept. of Plant Ecology
EvolutionsBiologiskt Centrum, Uppsala Universitet
Villavägen 14
752 36 UPPSALA
E-post Mikael.Niva at EBC.UU.SE
Tel. +46 (0)18 471 28 65
Fax +46 (0)18 55 34 19



More information about the R-help mailing list