Class Eigen

java.lang.Object
org.flag4j.linalg.Eigen

public final class Eigen extends Object
This class provides several methods useful for computing eigenvalues and eigenvectors.
  • Method Details

    • get2x2EigenValues

      public static CVector get2x2EigenValues(Matrix src)
      Computes the eigenvalues of a 2x2 matrix explicitly.
      Parameters:
      src - The 2x2 matrix to compute the eigenvalues of.
      Returns:
      A complex vector containing the eigenvalues of the 2x2 src matrix.
    • get2x2EigenValues

      public static Complex128[] get2x2EigenValues(double a11, double a12, double a21, double a22)
      Computes the eigenvalues of a 2x2 matrix explicitly.
      Parameters:
      a11 - First entry in matrix (at index (0, 0)).
      a12 - Second entry in matrix (at index (0, 1)).
      a21 - Third entry in matrix (at index (1, 0)).
      a22 - Fourth entry in matrix (at index (1, 1)).
      Returns:
      A complex array containing the eigenvalues of the 2x2 src matrix.
    • get2x2EigenValues

      public static CVector get2x2EigenValues(CMatrix src)
      Computes the eigenvalues of a 2x2 matrix explicitly.
      Parameters:
      src - The 2x2 matrix to compute the eigenvalues of.
      Returns:
      A complex vector containing the eigenvalues of the 2x2 src matrix.
    • get2x2EigenValues

      public static Complex128[] get2x2EigenValues(Complex128 a11, Complex128 a12, Complex128 a21, Complex128 a22)
      Computes the eigenvalues of a 2-by-2 complex matrix (assumed to be row major).
      Parameters:
      a11 - The first entry in the 2-by-2 complex matrix
      a12 - The second entry in the 2-by-2 complex matrix
      a21 - The third entry in the 2-by-2 complex matrix
      a22 - The fourth entry in the 2-by-2 complex matrix
      Returns:
      An array containing the eigenvalues of the specified 2-by-2 complex matrix. Eigenvalues will be repeated per their multiplicity.
    • getEigenValues

      public static CVector getEigenValues(Matrix src)
      Computes the eigenvalues of a square real dense matrix. For reproducibility see getEigenValues(Matrix, long). If the algorithm fails to converge within the default maximum number of iterations, getEigenValues(Matrix, long, int) can be used to specify a larger number of iterations to attempt.
      Parameters:
      src - The matrix to compute the eigenvalues of.
      Returns:
      The eigenvalues of the src matrix.
      See Also:
    • getEigenValues

      public static CVector getEigenValues(Matrix src, long seed)
      Computes the eigenvalues of a square real dense matrix. If the algorithm fails to converge within the default maximum number of iterations, getEigenValues(Matrix, long, int) can be used to specify a larger number of iterations to attempt.
      Parameters:
      src - The matrix to compute the eigenvalues of.
      seed - Seed for random shifts used in computing the eigenvalues.
      Returns:
      The eigenvalues of the src matrix.
      See Also:
    • getEigenValues

      public static CVector getEigenValues(Matrix src, long seed, int maxIterationFactor)
      Computes the eigenvalues of a square real dense matrix.
      Parameters:
      src - The matrix to compute the eigenvalues of.
      seed - Seed for random shifts used in computing the eigenvalues.
      maxIterationFactor - maximum iteration factor for use in computing the total maximum number of iterations to run the QR algorithm for during eigenvalue computation. The maximum number of iterations will be computed as:
            maxIteration = maxIterationFactor * src.numRows;
      Returns:
      The eigenvalues of the src matrix.
      See Also:
    • getEigenValues

      public static CVector getEigenValues(CMatrix src)
      Computes the eigenvalues of a square complex dense matrix. For reproducibility see getEigenValues(CMatrix, long).
      Parameters:
      src - The matrix to compute the eigenvalues of.
      Returns:
      The eigenvalues of the src matrix.
      See Also:
    • getEigenValues

      public static CVector getEigenValues(CMatrix src, long seed)
      Computes the eigenvalues of a square complex dense matrix.
      Parameters:
      src - The matrix to compute the eigenvalues of.
      seed - Seed for random shifts used in computing the eigenvalues. This allows for reproducibility despite randomness in the eigenvalue computation algorithm.
      Returns:
      The eigenvalues of the src matrix.
      See Also:
    • getEigenValues

      public static CVector getEigenValues(CMatrix src, long seed, int maxIterationFactor)
      Computes the eigenvalues of a square complex dense matrix.
      Parameters:
      src - The matrix to compute the eigenvalues of.
      seed - Seed for random shifts used in computing the eigenvalues.
      maxIterationFactor - maximum iteration factor for use in computing the total maximum number of iterations to run the QR algorithm for during eigenvalue computation. The maximum number of iterations will be computed as:
            maxIteration = maxIterationFactor * src.numRows;
      Returns:
      The eigenvalues of the src matrix.
      See Also:
    • getEigenVectors

      public static CMatrix getEigenVectors(Matrix src)
      Computes the eigenvectors of a square real dense matrix.
      Parameters:
      src - The matrix to compute the eigenvectors of.
      Returns:
      A matrix containing the eigenvectors of src as its columns.
      See Also:
    • getEigenVectors

      public static CMatrix getEigenVectors(Matrix src, long seed)
      Computes the eigenvectors of a square real dense matrix. This method accepts a seed for the random number generator involved in the algorithm for computing the eigenvalues. This allows for reproducibility between calls.
      Parameters:
      src - The matrix to compute the eigenvectors of.
      seed - Seed for random shifts used in the algorithm to compute the eigenvalues of.
      Returns:
      A matrix containing the eigenvectors of src as its columns.
      See Also:
    • getEigenVectors

      public static CMatrix getEigenVectors(Matrix src, long seed, int maxIterationFactor)
      Computes the eigenvectors of a square real dense matrix. This method accepts a seed for the random number generator involved in the algorithm for computing the eigenvalues. This allows for reproducibility between calls.
      Parameters:
      src - The matrix to compute the eigenvectors of.
      seed - Seed for random shifts used in the algorithm to compute the eigenvalues of.
      maxIterationFactor - maximum iteration factor for use in computing the total maximum number of iterations to run the QR algorithm for during eigenvalue computation. The maximum number of iterations will be computed as:
            maxIteration = maxIterationFactor * src.numRows;
      Returns:
      A matrix containing the eigenvectors of src as its columns.
      See Also:
    • getEigenVectors

      public static CMatrix getEigenVectors(CMatrix src)
      Computes the eigenvectors of a square real dense matrix.
      Parameters:
      src - The matrix to compute the eigenvectors of.
      Returns:
      A matrix containing the eigenvectors of src as its columns.
      See Also:
    • getEigenVectors

      public static CMatrix getEigenVectors(CMatrix src, long seed)
      Computes the eigenvectors of a square real dense matrix. This method accepts a seed for the random number generator involved in the algorithm for computing the eigenvalues. This allows for reproducibility between calls.
      Parameters:
      src - The matrix to compute the eigenvectors of.
      seed - Seed for random shifts used in the algorithm to compute the eigenvalues of.
      Returns:
      A matrix containing the eigenvectors of src as its columns.
      See Also:
    • getEigenVectors

      public static CMatrix getEigenVectors(CMatrix src, long seed, int maxIterationFactor)
      Computes the eigenvectors of a square real dense matrix. This method accepts a seed for the random number generator involved in the algorithm for computing the eigenvalues. This allows for reproducibility between calls.
      Parameters:
      src - The matrix to compute the eigenvectors of.
      seed - Seed for random shifts used in the algorithm to compute the eigenvalues of.
      maxIterationFactor - maximum iteration factor for use in computing the total maximum number of iterations to run the QR algorithm for during eigenvalue computation. The maximum number of iterations will be computed as:
            maxIteration = maxIterationFactor * src.numRows;
      Returns:
      A matrix containing the eigenvectors of src as its columns.
      See Also:
    • getEigenVectorsTriu

      public static Matrix getEigenVectorsTriu(Matrix T)
      Computes the eigenvectors of an upper triangular matrix.
      Parameters:
      T - The upper triangular matrix to compute the eigenvectors of.
      Returns:
      A matrix containing the eigenvectors of T as its columns.
    • getEigenVectorsTriu

      public static CMatrix getEigenVectorsTriu(CMatrix T)
      Computes the eigenvectors of an upper triangular matrix.
      Parameters:
      T - The upper triangular matrix to compute the eigenvectors of.
      Returns:
      A matrix containing the eigenvectors of T as its columns.
    • getEigenPairs

      public static CMatrix[] getEigenPairs(Matrix src)

      Computes the eigenvalues and eigenvectors of a square complex matrix.

      This method calculates the eigenvalues and eigenvectors of the given complex matrix src. The eigenvalues are returned as a single-row matrix, while the eigenvectors are returned as a matrix where each column corresponds to an eigenvector of the input matrix.

      Random number generation is used internally during the computation to apply random shifts, which enhance numerical stability and improve convergence. Because of this, repeated calls to this method with the same matrix may produce slightly different results.

      If reproducible results are required (e.g., for testing purposes), use the overloaded method getEigenPairs(CMatrix, long) that accepts a seed for the random number generator.

      Parameters:
      src - The input matrix for which to compute the eigenvalues and eigenvectors. This matrix must be square (src.numRows == src.numCols).
      Returns:
      An array containing two matrices:
      1. The first matrix is a 1-by-src.numCols matrix containing the eigenvalues of src.
      2. The second matrix is an src.numRows-by-src.numCols matrix, where each column is an eigenvector corresponding to an eigenvalue in the first matrix.
      Throws:
      IllegalArgumentException - if the input matrix src is not square (e.g. src.numRows != src.numCols).
      See Also:
    • getEigenPairs

      public static CMatrix[] getEigenPairs(Matrix src, long seed)

      Computes the eigenvalues and eigenvectors of a square real matrix.

      This method calculates the eigenvalues and eigenvectors of the given real matrix src. The eigenvalues are collected and returned as a single-row matrix, while the eigenvectors are collected as the columns of matrix.

      The computation uses a random shift algorithm to enhance numerical stability and improve convergence. By providing a seed, the random shifts can be made deterministic, ensuring reproducible results for the same input matrix. For most applications, specifying a seed is optional and generally not required.

      Parameters:
      src - The input matrix for which to compute the eigenvalues and eigenvectors. This matrix must be square (src.numRows == src.numCols).
      seed - A seed value for random shifts used in the algorithm. Providing a seed ensures that the results are reproducible when the same matrix is used as input. If reproducibility is not a concern, this value can be omitted or set to any arbitrary number.
      Returns:
      An array containing two matrices:
      1. The first matrix is a 1-by-src.numCols matrix containing the eigenvalues of src.
      2. The second matrix is an src.numRows-by-src.numCols matrix, where each column is an eigenvector corresponding to an eigenvalue in the first matrix.
      Throws:
      IllegalArgumentException - if the input matrix src is not square (e.g. src.numRows != src.numCols).
      See Also:
    • getEigenPairs

      public static CMatrix[] getEigenPairs(CMatrix src)

      Computes the eigenvalues and eigenvectors of a square real matrix.

      This method calculates the eigenvalues and eigenvectors of the given real matrix src. The eigenvalues are returned as a single-row matrix, while the eigenvectors are returned as a matrix where each column corresponds to an eigenvector of the input matrix.

      Random number generation is used internally during the computation to apply random shifts, which enhance numerical stability and improve convergence. Because of this, repeated calls to this method with the same matrix may produce slightly different results.

      If reproducible results are required (e.g., for testing purposes), use the overloaded method getEigenPairs(CMatrix, long) that accepts a seed for the random number generator.

      Parameters:
      src - The input matrix for which to compute the eigenvalues and eigenvectors. This matrix must be square (src.numRows == src.numCols).
      Returns:
      An array containing two matrices:
      1. The first matrix is a 1-by-src.numCols matrix containing the eigenvalues of src.
      2. The second matrix is an src.numRows-by-src.numCols matrix, where each column is an eigenvector corresponding to an eigenvalue in the first matrix.
      Throws:
      IllegalArgumentException - if the input matrix src is not square (e.g. src.numRows != src.numCols).
      See Also:
    • getEigenPairs

      public static CMatrix[] getEigenPairs(CMatrix src, long seed)

      Computes the eigenvalues and eigenvectors of a square complex matrix.

      This method calculates the eigenvalues and eigenvectors of the given complex matrix src. The eigenvalues are collected and returned as a single-row matrix, while the eigenvectors are collected as the columns of matrix.

      The computation uses a random shift algorithm to enhance numerical stability and improve convergence. By providing a seed, the random shifts can be made deterministic, ensuring reproducible results for the same input matrix. For most applications, specifying a seed is optional and generally not required.

      Parameters:
      src - The input matrix for which to compute the eigenvalues and eigenvectors. This matrix must be square (src.numRows == src.numCols).
      seed - A seed value for random shifts used in the algorithm. Providing a seed ensures that the results are reproducible when the same matrix is used as input. If reproducibility is not a concern, this value can be omitted or set to any arbitrary number.
      Returns:
      An array containing two matrices:
      1. The first matrix is a 1-by-src.numCols matrix containing the eigenvalues of src.
      2. The second matrix is an src.numRows-by-src.numCols matrix, where each column is an eigenvector corresponding to an eigenvalue in the first matrix.
      Throws:
      IllegalArgumentException - if the input matrix src is not square (e.g. src.numRows != src.numCols).
      See Also: