# [R] How to compute eigenvectors and eigenvalues?

John Fox jfox at mcmaster.ca
Mon Nov 14 13:57:49 CET 2011

```Dear Arnau,

In this and a subsequent message, you seem to incorrectly infer that the two
equal eigenvalues of the matrix imply that it's singular. The rank of the
matrix is equal to the number of *nonzero* eigenvalues, here 3, and so the
matrix is nonsingular. That two eigenvalues are equal simply implies that
the corresponding eigenvectors span a subspace of dimension 2; the 2
corresponding eigenvectors reported by R are (within rounding error) a basis
for this subspace.

I hope this helps,
John

--------------------------------
John Fox
Senator William McMaster
Professor of Social Statistics
Department of Sociology
McMaster University
http://socserv.mcmaster.ca/jfox

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Arnau Mir
> Sent: November-14-11 5:53 AM
> To: r-help at r-project.org
> Subject: [R] How to compute eigenvectors and eigenvalues?
>
> Hello.
>
> Consider the following matrix:
>
> mp <- matrix(c(0,1/4,1/4,3/4,0,1/4,1/4,3/4,1/2),3,3,byrow=T)
>
> > mp
>      [,1] [,2] [,3]
> [1,] 0.00 0.25 0.25
> [2,] 0.75 0.00 0.25
> [3,] 0.25 0.75 0.50
>
>
> The eigenvectors of the previous matrix are 1, 0.25 and 0.25 and it is
> not a diagonalizable matrix.
>
> When you try to find the eigenvalues and eigenvectors with R, R
> responses:
>
> > eigen(mp)
>
> \$values
>   1.00 -0.25 -0.25
>
> \$vectors
>           [,1]          [,2]          [,3]
> [1,] 0.3207501  1.068531e-08 -1.068531e-08 [2,] 0.4490502 -7.071068e-01
> -7.071068e-01 [3,] 0.8339504  7.071068e-01  7.071068e-01
>
> The eigenvalues are correct but the eigenvectors aren't. Moreover, if
> you try to compute the inverse of the matrix of eigenvectors, R is not
> aware that this matrix is singular:
>
>
> > solve(eigen(mp)\$vectors)
>               [,1]          [,2]          [,3]
> [1,]  6.235383e-01  6.235383e-01  6.235383e-01 [2,]  3.743456e+07 -
> 9.358641e+06 -9.358640e+06 [3,] -3.743456e+07  9.358640e+06
> 9.358641e+06
>
>
> My question is: how can I fix it?
>
>
>
> Arnau.
>
> ------------------------------------------------------------
> Arnau Mir Torres
> Edifici A. Turmeda
> Campus UIB
> Ctra. Valldemossa, km. 7,5
> 07122 Palma de Mca.
> tel: (+34) 971172987
> fax: (+34) 971173003
> email: arnau.mir at uib.es
> URL: http://dmi.uib.es/~arnau
> ------------------------------------------------------------
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help