Title: | Calculate Generalized Eigenvalues, the Generalized Schur Decomposition and the Generalized Singular Value Decomposition of a Matrix Pair with Lapack |
---|---|
Description: | Functions to compute generalized eigenvalues and eigenvectors, the generalized Schur decomposition and the generalized Singular Value Decomposition of a matrix pair, using Lapack routines. |
Authors: | Berend Hasselman [cre, aut], Lapack authors [aut, cph] |
Maintainer: | Berend Hasselman <[email protected]> |
License: | GPL (>= 2) |
Version: | 2.3 |
Built: | 2024-11-01 11:52:04 UTC |
Source: | CRAN |
Functions to compute generalized eigenvalues and eigenvectors, the generalized Schur decomposition and the generalized Singular Value Decomposition of a matrix pair, using Lapack routines.
The geigen package provides functions to compute the generalized eigenvalues of a pair of matrices and optionally provides the generalized eigenvectors. Both numeric and complex matrices are allowed. The package also provides a function for computing the generalized Schur decomposition of a pair of matrices, either numeric or complex. Finally the package provides a function for computing the generalized singular value decomposition for a pair of matrices, either numeric or complex. The package uses routines provided by the Lapack linear algebra package.
Computes generalized eigenvalues and eigenvectors of a pair of matrices.
geigen(A, B, symmetric, only.values=FALSE)
geigen(A, B, symmetric, only.values=FALSE)
A |
left hand side matrix. |
B |
right hand side matrix. |
symmetric |
if |
only.values |
if |
If the argument symmetric
is missing, the function
will try to determine if the matrices are symmetric with the function isSymmetric
from
the base package. It is faster to specify the argument.
Both matrices must be square. This function provides the solution to the generalized eigenvalue problem defined by
If either one of the matrices is complex the other matrix is coerced to be complex.
If the matrices are symmetric then the matrix B
must be positive definite; if it is not
an error message will be issued.
If the matrix B
is known to be symmetric but not positive definite then the argument
symmetric
should be set to FALSE
explicitly.
If the matrix B
is not positive definite when it should be an
error message of the form
Leading minor of order ... of B is not positive definite
will be issued. In that case set the argument symmetric
to FALSE
if not set and try again.
For general matrices the generalized eigenvalues
are calculated as the ratio
where
may be zero or very small leading
to non finite or very large values for the eigenvalues.
Therefore the values for
and
are also included in the return value
of the function.
When both matrices are complex (or coerced to be so) the generalized eigenvalues,
and
are complex.
When both matrices are numeric
may be numeric or complex and
is numeric.
When both matrices are symmetric (or Hermitian) the generalized eigenvalues are numeric and
no components and
are available.
A list containing components
values |
a vector containing the |
vectors |
an |
alpha |
the numerator of the generalized eigenvalues and may be NULL if not applicable. |
beta |
the denominator of the generalized eigenvalues and may be NULL if not applicable. |
geigen
uses the LAPACK routines DGGEV
,
DSYGV
, ZHEGV
and ZGGEV
.
LAPACK is from http://www.netlib.org/lapack.
The complex routines used by the package come from LAPACK 3.8.0.
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.
See the section Generalized Eigenvalue and Singular Value Problems
(http://www.netlib.org/lapack/lug/node33.html).
eigen
A <- matrix(c(14, 10, 12, 10, 12, 13, 12, 13, 14), nrow=3, byrow=TRUE) B <- matrix(c(48, 17, 26, 17, 33, 32, 26, 32, 34), nrow=3, byrow=TRUE) z1 <- geigen(A, B, symmetric=FALSE, only.values=TRUE) z2 <- geigen(A, B, symmetric=FALSE, only.values=FALSE ) z2 # geigen(A, B) z1 <- geigen(A, B, only.values=TRUE) z2 <- geigen(A, B, only.values=FALSE) z1;z2 A.c <- A + 1i B.c <- B + 1i A[upper.tri(A)] <- A[upper.tri(A)] + 1i A[lower.tri(A)] <- Conj(t(A[upper.tri(A)])) B[upper.tri(B)] <- B[upper.tri(B)] + 1i B[lower.tri(B)] <- Conj(t(B[upper.tri(B)])) isSymmetric(A) isSymmetric(B) z1 <- geigen(A, B, only.values=TRUE) z2 <- geigen(A, B, only.values=FALSE) z1;z2
A <- matrix(c(14, 10, 12, 10, 12, 13, 12, 13, 14), nrow=3, byrow=TRUE) B <- matrix(c(48, 17, 26, 17, 33, 32, 26, 32, 34), nrow=3, byrow=TRUE) z1 <- geigen(A, B, symmetric=FALSE, only.values=TRUE) z2 <- geigen(A, B, symmetric=FALSE, only.values=FALSE ) z2 # geigen(A, B) z1 <- geigen(A, B, only.values=TRUE) z2 <- geigen(A, B, only.values=FALSE) z1;z2 A.c <- A + 1i B.c <- B + 1i A[upper.tri(A)] <- A[upper.tri(A)] + 1i A[lower.tri(A)] <- Conj(t(A[upper.tri(A)])) B[upper.tri(B)] <- B[upper.tri(B)] + 1i B[lower.tri(B)] <- Conj(t(B[upper.tri(B)])) isSymmetric(A) isSymmetric(B) z1 <- geigen(A, B, only.values=TRUE) z2 <- geigen(A, B, only.values=FALSE) z1;z2
Computes the generalized eigenvalues from an object constructed with gqz
.
gevalues(x)
gevalues(x)
x |
an object created with |
The function calculates the generalized eigenvalues from elements of the object returned by
the function gqz
.
The generalized eigenvalues are computed from a ratio where the denominator
(the component of the argument) may be zero.
The function attempts to guard against nonsensical complex
NaN
values when dividing by zero
which may happen on some systems.
A vector containing the generalized eigenvalues. The vector is numeric if the imaginary parts of the eigenvalues are all zero and complex otherwise.
geigen
, gqz
# Real matrices # example from NAG: http://www.nag.com/lapack-ex/node116.html # Find the generalized Schur decomposition with the real eigenvalues ordered to come first A <- matrix(c( 3.9, 12.5,-34.5,-0.5, 4.3, 21.5,-47.5, 7.5, 4.3, 21.5,-43.5, 3.5, 4.4, 26.0,-46.0, 6.0), nrow=4, byrow=TRUE) B <- matrix(c( 1.0, 2.0, -3.0, 1.0, 1.0, 3.0, -5.0, 4.0, 1.0, 3.0, -4.0, 3.0, 1.0, 3.0, -4.0, 4.0), nrow=4, byrow=TRUE) z <- gqz(A, B,"R") z # compute the generalized eigenvalues ger <- gevalues(z) ger
# Real matrices # example from NAG: http://www.nag.com/lapack-ex/node116.html # Find the generalized Schur decomposition with the real eigenvalues ordered to come first A <- matrix(c( 3.9, 12.5,-34.5,-0.5, 4.3, 21.5,-47.5, 7.5, 4.3, 21.5,-43.5, 3.5, 4.4, 26.0,-46.0, 6.0), nrow=4, byrow=TRUE) B <- matrix(c( 1.0, 2.0, -3.0, 1.0, 1.0, 3.0, -5.0, 4.0, 1.0, 3.0, -4.0, 3.0, 1.0, 3.0, -4.0, 4.0), nrow=4, byrow=TRUE) z <- gqz(A, B,"R") z # compute the generalized eigenvalues ger <- gevalues(z) ger
Computes the generalized eigenvalues and Schur form of a pair of matrices.
gqz(A, B, sort=c("N","-","+","S","B","R"))
gqz(A, B, sort=c("N","-","+","S","B","R"))
A |
left hand side matrix. |
B |
right hand side matrix. |
sort |
how to sort the generalized eigenvalues. See ‘Details’. |
Both matrices must be square. This function provides the solution to the generalized eigenvalue problem defined by
If either one of the matrices is complex the other matrix is coerced to be complex.
The sort
argument specifies how to order the eigenvalues on the
diagonal of the generalized Schur form, where it is noted that non-finite eigenvalues never
satisfy any ordering condition (even in the case of a complex infinity).
Eigenvalues that are placed in the leading block of the Schur form
satisfy
N
unordered.
-
negative real part.
+
positive real part.
S
absolute value < 1.
B
absolute value > 1.
R
imaginary part identical to 0 with a tolerance of 100*machine_precision as determined by Lapack.
The generalized Schur form for numeric matrices is
The matrices and
are orthogonal. The matrix
is quasi-upper triangular and
the matrix
is upper triangular.
The return value is a list containing the following components
S
generalized Schur form of A.
T
generalized Schur form of B.
sdim
the number of eigenvalues (after sorting) for which the sorting condition is true.
alphar
numerator of the real parts of the eigenvalues (numeric).
alphai
numerator of the imaginary parts of the eigenvalues (numeric).
beta
denominator of the expression for the eigenvalues (numeric).
Q
matrix of left Schur vectors (matrix Q).
Z
matrix of right Schur vectors (matrix Z).
The generalized Schur form for complex matrices is
The matrices and
are unitary and the matrices
and
are upper triangular.
The return value is a list containing the following components
S
generalized Schur form of A.
T
generalized Schur form of B.
sdim
the number of eigenvalues. (after sorting) for which the sorting condition is true.
alpha
numerator of the eigenvalues (complex).
beta
denominator of the eigenvalues (complex).
Q
matrix of left Schur vectors (matrix Q).
Z
matrix of right Schur vectors (matrix Z).
The generalized eigenvalues can be computed by calling function gevalues
.
gqz
uses the LAPACK routines DGGES
and ZGGES
.
LAPACK is from http://www.netlib.org/lapack.
The complex routines used by the package come from LAPACK 3.8.0.
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.
See the section Eigenvalues, Eigenvectors and Generalized Schur Decomposition
(http://www.netlib.org/lapack/lug/node56.html).
geigen
, gevalues
# Real matrices # example from NAG: http://www.nag.com/lapack-ex/node116.html # Find the generalized Schur decomposition with the real eigenvalues ordered to come first A <- matrix(c( 3.9, 12.5,-34.5,-0.5, 4.3, 21.5,-47.5, 7.5, 4.3, 21.5,-43.5, 3.5, 4.4, 26.0,-46.0, 6.0), nrow=4, byrow=TRUE) B <- matrix(c( 1.0, 2.0, -3.0, 1.0, 1.0, 3.0, -5.0, 4.0, 1.0, 3.0, -4.0, 3.0, 1.0, 3.0, -4.0, 4.0), nrow=4, byrow=TRUE) z <- gqz(A, B,"R") z # complexify A <- A+0i B <- B+0i z <- gqz(A, B,"R") z
# Real matrices # example from NAG: http://www.nag.com/lapack-ex/node116.html # Find the generalized Schur decomposition with the real eigenvalues ordered to come first A <- matrix(c( 3.9, 12.5,-34.5,-0.5, 4.3, 21.5,-47.5, 7.5, 4.3, 21.5,-43.5, 3.5, 4.4, 26.0,-46.0, 6.0), nrow=4, byrow=TRUE) B <- matrix(c( 1.0, 2.0, -3.0, 1.0, 1.0, 3.0, -5.0, 4.0, 1.0, 3.0, -4.0, 3.0, 1.0, 3.0, -4.0, 4.0), nrow=4, byrow=TRUE) z <- gqz(A, B,"R") z # complexify A <- A+0i B <- B+0i z <- gqz(A, B,"R") z
Computes the generalized singular value decomposition of a pair of matrices.
gsvd(A,B)
gsvd(A,B)
A |
a matrix with |
B |
a matrix with |
The matrix A is a -by-
matrix and the matrix B is a
-by-
matrix.
This function decomposes both matrices; if either one is complex than the other matrix
is coerced to be complex.
The Generalized Singular Value Decomposition of numeric matrices and
is given as
and
where
an orthogonal matrix.
a orthogonal matrix.
an orthogonal matrix.
an -by-
upper triangular non singular matrix and the matrix
is an
-by-
matrix. The quantity
is the rank of
the matrix
with
.
,
are quasi diagonal matrices and nonnegative and satisfy
.
is an
-by-
matrix and
is a
-by-
matrix.
The Generalized Singular Value Decomposition of complex matrices and
is given as
and
where
an unitary matrix.
a unitary matrix.
an unitary matrix.
an -by-
upper triangular non singular matrix and the matrix
is an
-by-
matrix. The quantity
is the rank of
the matrix
with
.
,
are quasi diagonal matrices and nonnegative and satisfy
.
is an
-by-
matrix and
is a
-by-
matrix.
For details on this decomposition and the structure of the matrices and
see http://www.netlib.org/lapack/lug/node36.html.
The return value is a list containing the following components
A
the upper triangular matrix or a part of .
B
lower part of the triangular matrix if
(see below).
m
number of rows of .
k
. The number of rows of the matrix
is
.
The first
generalized singular values are infinite.
l
effective rank of the input matrix .
The number of finite generalized singular values after the first
infinite ones.
alpha
a numeric vector with length containing
the numerators of the generalized singular values in
the first
entries.
beta
a numeric vector with length containing
the denominators of the generalized singular value in
the first
entries.
U
the matrix .
V
the matrix .
Q
the matrix .
For a detailed description of these items see http://www.netlib.org/lapack/lug/node36.html. Auxiliary functions are provided for extraction and manipulation of the various items.
gsvd
uses the LAPACK routines DGGSVD3
and ZGGSVD3
from Lapack 3.8.0.
LAPACK is from http://www.netlib.org/lapack.
The decomposition is fully explained in http://www.netlib.org/lapack/lug/node36.html.
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.
See the section Generalized Eigenvalue and Singular Value Problems
(http://www.netlib.org/lapack/lug/node33.html) and
the section Generalized Singular Value Decomposition (GSVD)
(http://www.netlib.org/lapack/lug/node36.html).
A <- matrix(c(1,2,3,3,2,1,4,5,6,7,8,8), nrow=2, byrow=TRUE) B <- matrix(1:18,byrow=TRUE, ncol=6) A B z <- gsvd(A,B) z
A <- matrix(c(1,2,3,3,2,1,4,5,6,7,8,8), nrow=2, byrow=TRUE) B <- matrix(1:18,byrow=TRUE, ncol=6) A B z <- gsvd(A,B) z
Returns a component of the object as a matrix
gsvd.R(z) gsvd.oR(z) gsvd.D1(z) gsvd.D2(z)
gsvd.R(z) gsvd.oR(z) gsvd.D1(z) gsvd.D2(z)
z |
an object created with |
gsvd.R
returns the R
matrix implied by the GSVD.
gsvd.oR
returns the matrix implied by the GSVD.
gsvd.D1
returns the matrix D1
implied by the GSVD.
gsvd.D2
returns the matrix D2
implied by the GSVD.
A <- matrix(c(1,2,3,3,2,1,4,5,6,7,8,8), nrow=2, byrow=TRUE) B <- matrix(1:18,byrow=TRUE, ncol=6) A B z <- gsvd(A,B) z R <- gsvd.R(z) oR <- gsvd.oR(z) D1 <- gsvd.D1(z); D2 <- gsvd.D2(z) R;oR D1;D2
A <- matrix(c(1,2,3,3,2,1,4,5,6,7,8,8), nrow=2, byrow=TRUE) B <- matrix(1:18,byrow=TRUE, ncol=6) A B z <- gsvd(A,B) z R <- gsvd.R(z) oR <- gsvd.oR(z) D1 <- gsvd.D1(z); D2 <- gsvd.D2(z) R;oR D1;D2