Skip to contents

spectral() is a wrapper around base::eigen() designed for Hermitian matrices, which can handle repeated eigenvalues.

Usage

spectral(S, multiplicity = TRUE, tol = .Machine$double.eps^0.5, ...)

Arguments

S

a Hermitian matrix. Obs: The matrix is always assumed to be Hermitian, and only its lower triangle (diagonal included) is used.

multiplicity

if TRUE (default), tries to infer eigenvalue multiplicity. If set to FALSE, each eigenvalue is considered unique with multiplicity one.

tol

two eigenvalues x, y are considered equal if abs(x-y) < tol. Defaults to tol=.Machine$double.eps^0.5.

...

further arguments passed on to base::eigen()

Value

The spectral decomposition of S is returned as a list with components

eigvals

vector containing the unique eigenvalues of S in decreasing order.

multiplicity

multiplicities of the eigenvalues in eigvals.

eigvectors

a nrow(S) x nrow(S) unitary matrix whose columns are eigenvectors ordered according to eigvals. Note that there may be more eigenvectors than eigenvalues if multiplicity=TRUE, however eigenvectors of the same eigenspace are next to each other.

The Spectral Theorem ensures the eigenvalues of S are real and that the vector space admits an orthonormal basis consisting of eigenvectors of S. Thus, if s <- spectral(S), and V <- s$eigvectors; lam <- s$eigvals, then

$$S = V \Lambda V^{*}$$

where \(\Lambda =\ \)diag(rep(lam, times=s$multiplicity))

Examples

spectral(matrix(c(0,1,0,1,0,1,0,1,0), nrow=3))
#> $eigvals
#> [1]  1.414214e+00  1.554312e-15 -1.414214e+00
#> 
#> $multiplicity
#> [1] 1 1 1
#> 
#> $eigvectors
#>           [,1]          [,2]       [,3]
#> [1,] 0.5000000 -7.071068e-01 -0.5000000
#> [2,] 0.7071068 -9.420555e-16  0.7071068
#> [3,] 0.5000000  7.071068e-01 -0.5000000
#> 
#> attr(,"class")
#> [1] "spectral"

# Use "tol" to set the tolerance for numerical equality
spectral(matrix(c(0,1,0,1,0,1,0,1,0), nrow=3), tol=10e-5)
#> $eigvals
#> [1]  1.414214e+00  1.554312e-15 -1.414214e+00
#> 
#> $multiplicity
#> [1] 1 1 1
#> 
#> $eigvectors
#>           [,1]          [,2]       [,3]
#> [1,] 0.5000000 -7.071068e-01 -0.5000000
#> [2,] 0.7071068 -9.420555e-16  0.7071068
#> [3,] 0.5000000  7.071068e-01 -0.5000000
#> 
#> attr(,"class")
#> [1] "spectral"

# Use "multiplicity=FALSE" to force each eigenvalue to be considered unique
spectral(matrix(c(0,1,0,1,0,1,0,1,0), nrow=3), multiplicity = FALSE)
#> $eigvals
#> [1]  1.414214e+00  1.554312e-15 -1.414214e+00
#> 
#> $multiplicity
#> [1] 1 1 1
#> 
#> $eigvectors
#>           [,1]          [,2]       [,3]
#> [1,] 0.5000000 -7.071068e-01 -0.5000000
#> [2,] 0.7071068 -9.420555e-16  0.7071068
#> [3,] 0.5000000  7.071068e-01 -0.5000000
#> 
#> attr(,"class")
#> [1] "spectral"