Class Invert

java.lang.Object
org.flag4j.linalg.Invert

public final class Invert extends Object
This class provides methods for computing the inverse of a matrix. Specialized methods are provided for inverting triangular, diagonal, and symmetric positive definite matrices.
  • Method Details

    • inv

      public static Matrix inv(Matrix src)
      Computes the inverse of this matrix. This is done by computing the LU decomposition of this matrix, inverting L using a back-solve algorithm, then solving U*inv(src)=inv(L) for inv(src).
      Parameters:
      src - Matrix to compute inverse of.
      Returns:
      The inverse of this matrix.
      Throws:
      IllegalArgumentException - If the src matrix is not square.
      SingularMatrixException - If the src matrix is singular (i.e. not invertible).
    • inv

      public static CMatrix inv(CMatrix src)
      Computes the inverse of this matrix. This is done by computing the LU decomposition of this matrix, inverting L using a back-solve algorithm, then solving U*inv(src)=inv(L) for inv(src).
      Parameters:
      src - Matrix to compute inverse of.
      Returns:
      The inverse of this matrix.
      Throws:
      IllegalArgumentException - If the src matrix is not square.
      SingularMatrixException - If the src matrix is singular (i.e. not invertible).
    • invTriU

      public static Matrix invTriU(Matrix src)
      Inverts an upper triangular matrix. WARNING: this method does not check that the matrix is actually upper triangular.
      Parameters:
      src - Upper triangular matrix to compute the inverse of.
      Returns:
      The inverse of the upper triangular matrix.
      Throws:
      SingularMatrixException - If the matrix is singular (i.e. has at least one zero along the diagonal).
      IllegalArgumentException - If the matrix is not square.
    • invTriL

      public static Matrix invTriL(Matrix src)
      Inverts a lower triangular matrix. WARNING: this method does not check that the matrix is actually lower triangular.
      Parameters:
      src - Lower triangular matrix to compute the inverse of.
      Returns:
      The inverse of the lower triangular matrix.
      Throws:
      SingularMatrixException - If the matrix is singular (i.e. has at least one zero along the diagonal).
      IllegalArgumentException - If the matrix is not square.
    • invDiag

      public static Matrix invDiag(Matrix src)
      Inverts a diagonal matrix. WARNING: this method does not check that the matrix is actually diagonal.
      Parameters:
      src - Diagonal matrix to compute the inverse of.
      Returns:
      The inverse of the diagonal matrix.
      Throws:
      SingularMatrixException - If the matrix is singular (i.e. has at least one zero along the diagonal).
      IllegalArgumentException - If the matrix is not square.
    • invTriU

      public static CMatrix invTriU(CMatrix src)
      Inverts an upper triangular matrix. WARNING: this method does not check that the matrix is actually upper triangular.
      Parameters:
      src - Upper triangular matrix to compute the inverse of.
      Returns:
      The inverse of the upper triangular matrix.
      Throws:
      SingularMatrixException - If the matrix is singular (i.e. has at least one zero along the diagonal).
      IllegalArgumentException - If the matrix is not square.
    • invTriL

      public static CMatrix invTriL(CMatrix src)
      Inverts a lower triangular matrix. WARNING: this method does not check that the matrix is actually lower triangular and will treat it as such even if it is not triangular.
      Parameters:
      src - Lower triangular matrix to compute the inverse of.
      Returns:
      The inverse of the lower triangular matrix.
      Throws:
      SingularMatrixException - If the matrix is singular (i.e. has at least one zero along the diagonal).
      IllegalArgumentException - If the matrix is not square.
    • invDiag

      public static CMatrix invDiag(CMatrix src)
      Inverts a diagonal matrix. WARNING: this method does not check that the matrix is actually diagonal.
      Parameters:
      src - Diagonal matrix to compute the inverse of.
      Returns:
      The inverse of the diagonal matrix.
      Throws:
      SingularMatrixException - If the matrix is singular (i.e. has at least one zero along the diagonal).
      IllegalArgumentException - If the matrix is not square.
    • invSymPosDef

      public static Matrix invSymPosDef(Matrix src)
      Inverts a symmetric positive definite matrix.
      Parameters:
      src - Positive definite matrix. It will not be verified if src is actually symmetric positive definite.
      Returns:
      The inverse of the src matrix.
      Throws:
      IllegalArgumentException - If the matrix is not square.
      SingularMatrixException - If the src matrix is singular.
      See Also:
    • invSymPosDef

      public static Matrix invSymPosDef(Matrix src, boolean checkPosDef)
      Inverts a symmetric positive definite matrix.
      Parameters:
      src - Positive definite matrix.
      checkPosDef - Flag indicating if a check should be made to see if src is actually symmetric positive definite. WARNING: Checking if the matrix is positive definite can be very computationally expensive.
      Returns:
      The inverse of the src matrix.
      Throws:
      IllegalArgumentException - If the matrix is not square.
      SingularMatrixException - If the src matrix is singular.
    • invHermPosDef

      public static CMatrix invHermPosDef(CMatrix src)
      Inverts a Hermitian positive definite matrix.
      Parameters:
      src - Positive definite matrix. It will not be verified if src is actually Hermitian positive definite.
      Returns:
      The inverse of the src matrix.
      Throws:
      IllegalArgumentException - If the matrix is not square.
      SingularMatrixException - If the src matrix is singular.
      See Also:
    • invHermPosDef

      public static CMatrix invHermPosDef(CMatrix src, boolean checkPosDef)
      Inverts a Hermitian positive definite matrix.
      Parameters:
      src - Positive definite matrix.
      checkPosDef - Flag indicating if a check should be made to see if src is actually Hermitian positive definite. WARNING: Checking if the matrix is positive definite can be very computationally expensive.
      Returns:
      The inverse of the src matrix.
      Throws:
      IllegalArgumentException - If the matrix is not square.
      SingularMatrixException - If the src matrix is singular.
    • pInv

      public static Matrix pInv(Matrix src)
      Computes the pseudo-inverse of this matrix. That is, for a matrix A, computes the Moore–Penrose A+ such that the following hold:
      1. AA+A=A.
      2. A+AA+=A+.
      3. AA+ is Hermitian.
      4. A+A is also Hermitian.
      Returns:
      The Moore–Penrose pseudo-inverse of this matrix.
    • pInv

      public static CMatrix pInv(CMatrix src)
      Computes the pseudo-inverse of this matrix. That is, for a matrix A, computes the Moore–Penrose A+ such that the following hold:
      1. AA+ A=A.
      2. A+ AA+ =A+.
      3. AA+ is Hermitian.
      4. A+ A is also Hermitian.
      Returns:
      The Moore–Penrose pseudo-inverse of this matrix.
    • isInv

      public static boolean isInv(Matrix src1, Matrix src2)
      Checks if matrices are inverses of each other. This method rounds values near zero to zero when checking if the two matrices are inverses to account for floating point precision loss.
      Parameters:
      src1 - First matrix.
      src2 - Second matrix.
      Returns:
      true if matrix src2 is an inverse of this matrix; false otherwise. Otherwise, returns false.
    • isInv

      public static boolean isInv(CMatrix src1, CMatrix src2)
      Checks if matrices are inverses of each other.
      Parameters:
      src1 - First matrix.
      src2 - Second matrix.
      Returns:
      true if matrix src2 is an inverse (approximately) of this matrix; false otherwise. Otherwise, returns false.