Rev 17601 | Rev 23011 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{eigen}\alias{eigen}\alias{La.eigen}\title{Spectral Decomposition of a Matrix}\usage{eigen(x, symmetric, only.values = FALSE)La.eigen(x, symmetric, only.values = FALSE,method = c("dsyevr", "dsyev"))}\arguments{\item{x}{a matrix whose spectral decomposition is to be computed.}\item{symmetric}{if \code{TRUE}, the matrix is assumed to be symmetric(or Hermitian if complex) and only its lower triangle is used.If \code{symmetric} is not specified, the matrix is inspected forsymmetry.}\item{only.values}{if \code{TRUE}, only the eigenvalues are computedand returned, otherwise both eigenvalues and eigenvectors arereturned.}\item{method}{The LAPACK routine to use in the real symmetric case.}}\description{Function \code{eigen} computes eigenvalues and eigenvectors by providing aninterface to the EISPACK routines \code{RS}, \code{RG}, \code{CH}and \code{CG}.Function \code{La.eigen} uses the LAPACK routines DSYEV/DSYEVR,DGEEV, ZHEEV and ZGEEV.}\details{If \code{symmetric} is unspecified, the code attempts todetermine if the matrix is symmetric up to plausible numericalinaccuracies. It is faster and surer to set the value yourself.\code{La.eigen} is preferred to \code{eigen} for new projects, butits eigenvectors may differ in sign and (in the asymmetric case) innormalization. (They may also differ between methodsand between platforms.)The LAPACK routine DSYEVR is usually substantiallyfaster than DSYEV: see\url{http://www.cs.berkeley.edu/~demmel/DOE2000/Report0100.html}.Most benefits are seen with an optimized BLAS system.Computing the eigenvectors is the slow part for large matrices.Using \code{method="dsyevr"} requires IEEE 754 arithmetic. Shouldthis not be supported on your platform, \code{method="dsyev"} isused, with a warning.}\value{The spectral decomposition of \code{x} is returnedas components of a list.\item{values}{a vector containing the \eqn{p} eigenvalues of \code{x},sorted in \emph{decreasing} order, according to \code{Mod(values)}if they are complex.}\item{vectors}{a \eqn{p\times p}{p * p} matrix whose columns contain theeigenvectors of \code{x}, or \code{NULL} if \code{only.values} is\code{TRUE}.For \code{eigen(, symmetric = FALSE)} the choice of length of theeigenvectors is not defined by LINPACK. In all other cases thevectors are normalized to unit length.Recall that the eigenvectors are only defined up to a constant: evenwhen the length is specified they are still only defined up to ascalar of modulus one (the sign for real matrices).}}\references{Smith, B. T, Boyle, J. M., Dongarra, J. J., Garbow, B. S., Ikebe,Y.,Klema, V., and Moler, C. B. (1976).\emph{Matrix Eigensystems Routines -- EISPACK Guide}.Springer-Verlag Lecture Notes in Computer Science.Anderson. E. and ten others (1999)\emph{LAPACK Users' Guide}. Third Edition. SIAM.\crAvailable on-line at\url{http://www.netlib.org/lapack/lug/lapack_lug.html}.}\seealso{\code{\link{svd}}, a generalization of \code{eigen}; \code{\link{qr}}, and\code{\link{chol}} for related decompositions.To compute the determinant of a matrix, the \code{\link{qr}}decomposition is much more efficient: \code{\link{det}}.\code{\link{capabilities}} to test for IEEE 754 arithmetic.}\examples{eigen(cbind(c(1,-1),c(-1,1)))eigen(cbind(c(1,-1),c(-1,1)), symmetric = FALSE)# same (different algorithm).eigen(cbind(1,c(1,-1)), only.values = TRUE)eigen(cbind(-1,2:1)) # complex valueseigen(print(cbind(c(0,1i), c(-1i,0))))# Hermite ==> real Eigen values## 3 x 3:eigen(cbind( 1,3:1,1:3))eigen(cbind(-1,c(1:2,0),0:2)) # complex valuesMeps <- .Machine$double.epsset.seed(321, kind = "default") # force a particular seedm <- matrix(round(rnorm(25),3), 5,5)sm <- m + t(m) #- symmetric matrixem <- eigen(sm); V <- em$vectprint(lam <- em$values) # ordered DEcreasinglystopifnot(abs(sm \%*\% V - V \%*\% diag(lam)) < 60*Meps,abs(sm - V \%*\% diag(lam) \%*\% t(V)) < 60*Meps)##------- Symmetric = FALSE: -- different to above : ---em <- eigen(sm, symmetric = FALSE); V2 <- em$vectprint(lam2 <- em$values) # ordered decreasingly in ABSolute value !# and V2 is not normalized (where V is):print(i <- rev(order(lam2)))stopifnot(abs(lam - lam2[i]) < 60 * Meps)zapsmall(Diag <- t(V2) \%*\% V2) # orthogonal, but not normalizedprint(norm2V <- colSums(V2 * V2))stopifnot( abs(1- norm2V / diag(Diag)) < 60*Meps)V2n <- sweep(V2,2, STATS= sqrt(norm2V), FUN="/")## V2n are now Normalized EVapply(V2n * V2n, 2, sum)##[1] 1 1 1 1 1## Both are now TRUE:stopifnot(abs(sm \%*\% V2n - V2n \%*\% diag(lam2)) < 60*Meps,abs(sm - V2n \%*\% diag(lam2) \%*\% t(V2n)) < 60*Meps)## Re-ordered as with symmetric:sV <- V2n[,i]slam <- lam2[i]all(abs(sm \%*\% sV - sV \%*\% diag(slam)) < 60*Meps)all(abs(sm - sV \%*\% diag(slam) \%*\% t(sV)) < 60*Meps)## sV *is* now equal to V -- up to sign (+-) and rounding errorsall(abs(c(1 - abs(sV / V))) < 1000*Meps) # TRUE (P ~ 0.95)}\keyword{algebra}\keyword{array}