[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  eigen: Spectral Decomposition of a Matrix

##  Description

Computes eigenvalues and eigenvectors of numeric (double, integer, logical) or
complex matrices.

##  Usage

    
    
    eigen(x, symmetric, only.values = FALSE, EISPACK = FALSE)

##  Arguments

x

a numeric or complex matrix whose spectral decomposition is to be computed.
Logical matrices are coerced to numeric.

symmetric

if ` TRUE ` , the matrix is assumed to be symmetric (or Hermitian if complex)
and only its lower triangle (diagonal included) is used. If ` symmetric ` is
not specified, ` [ isSymmetric ](/link/isSymmetric?package=base&version=3.6.2)
(x) ` is used.

only.values

if ` TRUE ` , only the eigenvalues are computed and returned, otherwise both
eigenvalues and eigenvectors are returned.

EISPACK

logical. Defunct and ignored.

##  Value

The spectral decomposition of ` x ` is returned as a list with components

values

    

a vector containing the \\(p\\) eigenvalues of ` x ` , sorted in _decreasing_
order, according to ` Mod(values) ` in the asymmetric case when they might be
complex (even for real matrices). For real asymmetric matrices the vector will
be complex only if complex conjugate pairs of eigenvalues are detected.

vectors

    

either a \\(p\times p\\) matrix whose columns contain the eigenvectors of ` x
` , or ` NULL ` if ` only.values ` is ` TRUE ` . The vectors are normalized to
unit length.

Recall that the eigenvectors are only defined up to a constant: even when the
length is specified they are still only defined up to a scalar of modulus one
(the sign for real matrices).

When only.values is not true, as by default, the result is of S3 class
"eigen".

If r <\- eigen(A), and V <\- r$vectors; lam <\- r$values, then A = V \Lambda
V^{-1}A = V Lmbd V^(-1) (up to numerical fuzz), where \Lambda =Lmbd
=diag(lam).

##  Details

If ` symmetric ` is unspecified, ` [ isSymmetric
](/link/isSymmetric?package=base&version=3.6.2) (x) ` determines if the matrix
is symmetric up to plausible numerical inaccuracies. It is surer and typically
much faster to set the value yourself.

Computing the eigenvectors is the slow part for large matrices.

Computing the eigendecomposition of a matrix is subject to errors on a real-
world computer: the definitive analysis is Wilkinson (1965). All you can hope
for is a solution to a problem suitably close to ` x ` . So even though a real
asymmetric ` x ` may have an algebraic solution with repeated real
eigenvalues, the computed solution may be of a similar matrix with complex
conjugate pairs of eigenvalues.

Unsuccessful results from the underlying LAPACK code will result in an error
giving a positive error code (most often ` 1 ` ): these can only be
interpreted by detailed study of the FORTRAN code.

##  References

Anderson. E. and ten others (1999) _LAPACK Users' Guide_ . Third Edition.
SIAM. Available on-line at [ http://www.netlib.org/lapack/lug/lapack_lug.html
](http://www.netlib.org/lapack/lug/lapack_lug.html) .

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S Language_ .
Wadsworth & Brooks/Cole.

Wilkinson, J. H. (1965) _The Algebraic Eigenvalue Problem._ Clarendon Press,
Oxford.

##  See Also

` [ svd ](/link/svd?package=base&version=3.6.2) ` , a generalization of `
eigen ` ; ` [ qr ](/link/qr?package=base&version=3.6.2) ` , and ` [ chol
](/link/chol?package=base&version=3.6.2) ` for related decompositions.

To compute the determinant of a matrix, the ` [ qr
](/link/qr?package=base&version=3.6.2) ` decomposition is much more efficient:
` [ det ](/link/det?package=base&version=3.6.2) ` .

##  Examples

[ Run this code
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Feigen&utm_source=r-docs&utm_medium=doc