public class EigenDecomposition
extends java.lang.Object
M V = V Dwhere V is an n X n eigenvector matrix and D is an n X n matrix formed from the eigenvalues.
If M is symmetric, then D will be a diagonal matrix formed from the (real-valued) eigenvalues, and V will be orthogonal.
If M is non-symmetric, then the eigenvalues may also include complex conjugate pairs (a + b i), (a - b i), in which case D will be block-diagonal, with each complex conjugate pair forming a block
[ a b ] [ -b a ]If v1 and v2 are the columns of V corresponding to this block, then the eigenvectors corresponding to (a + b i), (a - b i) are (a v1 - b v2 i) and (b v1 + a v2 i). V is no longer guaranteeed to be orthogonal, and may also be singular. The methods
hqr2 and tlr2 in this class were
 taken from Jama (http://math.nist.gov/javanumerics/jama).| Modifier and Type | Field and Description | 
|---|---|
| static int | DEFAULT_ITERATION_LIMITThe default iteration limit for computing the SVD. | 
| static double | EPS | 
| static int | OMIT_VSpecifies that the eigenvector matrix V should not be computed. | 
| static double | one | 
| static int | SYMMETRICSpecifies that the symmetric part of M, or 1/2 (M+M^T), is to be
 factored. | 
| static double | zero | 
| Constructor and Description | 
|---|
| EigenDecomposition()Creates an uninitialized EigenDecomposition. | 
| EigenDecomposition(Matrix M)Creates a EigenDecomposition and initializes it for the matrix M. | 
| EigenDecomposition(Matrix M,
                  int flags)Creates a EigenDecomposition, sets the computation flags, and
 initializes it for the matrix M. | 
| Modifier and Type | Method and Description | 
|---|---|
| double | condition()Computes the condition number of the original matrix M associated with
 this decomposition. | 
| double | determinant()Computes the determinant of the original matrix M associated with this
 decomposition. | 
| void | factor(Matrix M)Performs an eigen decomposition on the Matrix M. | 
| void | factor(Matrix M,
      int flags)Performs an eigen decomposition on the Matrix M. | 
| static EigenDecomposition | factor(Vector er,
      Vector ei,
      DenseMatrix V,
      Matrix M)Convenience method that creates an EigenDecomposition, factors it for the
 matrix M, and stores the resulting eigenvalues and vectors into the
 corresponding arguments. | 
| void | factorSymmetric(Matrix M)Performs an eigen decomposition on the symmetric part of the Matrix M. | 
| void | factorSymmetric(Matrix M,
               int flags)Performs an eigen decomposition on the symmetric part of the Matrix M. | 
| static EigenDecomposition | factorSymmetric(Vector er,
               DenseMatrix V,
               Matrix M)Convenience method that creates an EigenDecomposition, factors it using a
 symmetric factorization for the matrix M, and stores the resulting
 eigenvalues and vectors into the corresponding arguments. | 
| void | get(Vector e,
   DenseMatrix V) | 
| void | get(Vector er,
   Vector ei,
   DenseMatrix V)Gets the eigenvalues and eigenvectors associated with the decomposition. | 
| void | getD(MatrixNd D)Returns the D matrix associated with this decomposition. | 
| VectorNd | getEigImag()Returns the imaginary parts of the current eigenvalues associated with
 this decomposition. | 
| VectorNd | getEigReal()Returns the real parts of the current eigenvalues associated with this
 decomposition. | 
| int | getIterationLimit()Gets the iteration limit for computations. | 
| double | getMaxAbsEig()Returns the maximum absolute value of all the eigenvalues. | 
| double | getMinAbsEig()Returns the minimum absolute value of all the eigenvalues. | 
| MatrixNd | getV()Returns the current eigenvector matrix V associated with this
 decomposition. | 
| boolean | inverse(MatrixNd MI)Computes the inverse of the original matrix M associated this
 decomposition, and places the result in MI. | 
| static void | main(java.lang.String[] args) | 
| double | norm()Computes the 2-norm of the original matrix M associated with this
 decomposition. | 
| void | setIterationLimit(int lim)Sets the iteration limit for computations. | 
| boolean | solve(MatrixNd X,
     MatrixNd B)Solves the linear equation  M X = B where M is the original matrix associated with this decomposition, and X and B are matrices. | 
| boolean | solve(VectorNd x,
     VectorNd b)Solves the linear equation  M x = b where M is the original matrix associated with this decomposition, and x and b are vectors. | 
| static int | tql2(double[] d,
    double[] e,
    int n,
    MatrixNd V,
    int maxit)Computes the eigenvalues and eigenvectors of a symmetric tridiagonal matrix
 This code was taken from Jama (http://math.nist.gov/javanumerics/jama). | 
| static int | tqli(double[] d,
    double[] e,
    int n,
    MatrixNd Z) | 
| void | tridiag(int n,
       double[] d,
       double[] e,
       double[] buf,
       MatrixNd Z) | 
| void | upperhessen(int n,
           double[] buf,
           MatrixNd Z) | 
public static final double EPS
public static final double zero
public static final double one
public static final int SYMMETRIC
public static final int OMIT_V
public static final int DEFAULT_ITERATION_LIMIT
public EigenDecomposition(Matrix M)
M - matrix to perform the SVD onpublic EigenDecomposition(Matrix M, int flags)
M - matrix to perform the Eigen decomposition onflags - flags associated with computationpublic EigenDecomposition()
public int getIterationLimit()
setIterationLimit(int)public void setIterationLimit(int lim)
lim - iteration limitgetIterationLimit()public void factorSymmetric(Matrix M)
M - matrix to perform the decomposition onpublic void factorSymmetric(Matrix M, int flags)
OMIT_V is set in flags.M - matrix to perform the decomposition onflags - flags to control the decompositionpublic void factor(Matrix M)
factorSymmetric(maspack.matrix.Matrix) should be
 used instead.M - matrix to perform the decomposition onpublic void factor(Matrix M, int flags)
OMIT_V is set in flags.  A symmetric
 decomposition is performed on the symmetric part of M (i.e., 1/2 (M+M^T)
 if SYMMETRIC is set in flags. A symmetric
 decomposition will also be permformed if M is found to be exactly
 symmetric. However, if M is supposed to be symmetric but is
 not exactly so because of round-off error, then either the
 SYMMETRIC flag should be specified or
 factorSymmetric(maspack.matrix.Matrix) should be used instead.M - matrix to perform the decomposition onflags - flags to control the decompositionpublic void get(Vector e, DenseMatrix V)
public void get(Vector er, Vector ei, DenseMatrix V)
er - If not null, returns the real part of the eigenvaluesei - If not null, returns the imaginary part of the eigenvaluesV - If not null, returns the eigenvectorsImproperStateException - if this decomposition is uninitialized, or if V is non-null but V
 was not computedImproperSizeException - if eig or V are not of the proper dimension and cannot be resized.public MatrixNd getV()
null. Subsequent factorizations will cause a different V to
 be created. The returned matrix should not be modified if any subsequent
 calls are to be made which depend on V (including solve and inverse
 methods).ImproperStateException - if this EigenDecomposition is uninitializedpublic VectorNd getEigReal()
ImproperStateException - if this decomposition is uninitializedpublic VectorNd getEigImag()
ImproperStateException - if this decomposition is uninitializedpublic void getD(MatrixNd D)
D - matrix to return D inImproperStateException - if this decomposition is uninitializedImproperSizeException - if D is not n X n and cannot be resizedpublic double getMinAbsEig()
ImproperStateException - if this decomposition is uninitializedpublic double getMaxAbsEig()
ImproperStateException - if this decomposition is uninitializedpublic static EigenDecomposition factor(Vector er, Vector ei, DenseMatrix V, Matrix M)
null, then the eigenvector matrix will not be computed.er - If not null, returns the real part of the eigenvaluesei - If not null, returns the imaginary part of the eigenvaluesV - If not null, returns the eigenvectorsM - matrix to be factoredpublic static EigenDecomposition factorSymmetric(Vector er, DenseMatrix V, Matrix M)
null, then the eigenvector matrix will not
 be computed.er - If not null, returns the (real) eigenvaluesV - If not null, returns the eigenvectorsM - matrix to be factoredpublic double condition()
ImproperStateException - if this decomposition is uninitialized or unsymmetricpublic double norm()
ImproperStateException - if this decomposition is uninitialized or unsymmetricpublic double determinant()
ImproperStateException - if this decomposition is uninitializedpublic boolean solve(VectorNd x, VectorNd b)
x - unknown vector to solve forb - constant vectorImproperStateException - if this decomposition is uninitialized or unsymmetric, or if V was not
 computed.ImproperSizeException - if b does not have a size compatible with M, or if x does not have a size
 compatible with M and cannot be resized.public boolean solve(MatrixNd X, MatrixNd B)
X - unknown matrix to solve forB - constant matrixImproperStateException - if this decomposition is uninitialized or unsymmetric, or if V was not
 computed.ImproperSizeException - if B has a different number of rows than M, or if X has a different number
 of rows than M or a different number of columns than B and cannot be
 resized.public boolean inverse(MatrixNd MI)
MI - matrix in which the inverse is storedImproperStateException - if this decomposition is uninitialized or unsymmetric, or if V was not
 computed.ImproperSizeException - If MI does not have the same size as M and cannot be
 resized.public void tridiag(int n,
                    double[] d,
                    double[] e,
                    double[] buf,
                    MatrixNd Z)
public static int tqli(double[] d,
                       double[] e,
                       int n,
                       MatrixNd Z)
public void upperhessen(int n,
                        double[] buf,
                        MatrixNd Z)
public static int tql2(double[] d,
                       double[] e,
                       int n,
                       MatrixNd V,
                       int maxit)
d - diagonal elements of the matrixe - off-diagonal elements of the matrixn - matrix sizeV - if non-null, used to return the eigenvalues.maxit - iteration limit. If -1, 30*n will be commonly used.public static void main(java.lang.String[] args)