Package org.flag4j.linalg
Class Invert
java.lang.Object
org.flag4j.linalg.Invert
This class provides methods for computing the inverse of a matrix. Specialized methods are provided for inverting triangular,
diagonal, and symmetric positive definite matrices.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic CMatrix
Computes the inverse of this matrix.static Matrix
Computes the inverse of this matrix.static CMatrix
Inverts a diagonal matrix.static Matrix
Inverts a diagonal matrix.static CMatrix
invHermPosDef
(CMatrix src) Inverts a hermitian positive definite matrix.static CMatrix
invHermPosDef
(CMatrix src, boolean checkPosDef) Inverts a hermitian positive definite matrix.static Matrix
invSymPosDef
(Matrix src) Inverts a symmetric positive definite matrix.static Matrix
invSymPosDef
(Matrix src, boolean checkPosDef) Inverts a symmetric positive definite matrix.static CMatrix
Inverts a lower triangular matrix.static Matrix
Inverts a lower triangular matrix.static CMatrix
Inverts an upper triangular matrix.static Matrix
Inverts an upper triangular matrix.static boolean
Checks if matrices are inverses of each other.static boolean
Checks if matrices are inverses of each other.static CMatrix
Computes the pseudo-inverse of this matrix.static Matrix
Computes the pseudo-inverse of this matrix.
-
Constructor Details
-
Invert
private Invert()
-
-
Method Details
-
inv
Computes the inverse of this matrix. This is done by computing theLU decomposition
of this matrix, invertingL
using a back-solve algorithm, then solvingU*inv(src)=inv(L)
forinv(src)
.- Parameters:
src
- Matrix to compute inverse of.- Returns:
- The inverse of this matrix.
- Throws:
IllegalArgumentException
- If thesrc
matrix is not square.SingularMatrixException
- If thesrc
matrix is singular (i.e. not invertible).
-
inv
Computes the inverse of this matrix. This is done by computing theLU decomposition
of this matrix, invertingL
using a back-solve algorithm, then solvingU*inv(src)=inv(L)
forinv(src)
.- Parameters:
src
- Matrix to compute inverse of.- Returns:
- The inverse of this matrix.
- Throws:
IllegalArgumentException
- If thesrc
matrix is not square.SingularMatrixException
- If thesrc
matrix is singular (i.e. not invertible).
-
invTriU
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
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
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
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
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
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
Inverts a symmetric positive definite matrix.- Parameters:
src
- Positive definite matrix. It will not be verified ifsrc
is actually symmetric positive definite.- Returns:
- The inverse of the
src
matrix. - Throws:
IllegalArgumentException
- If the matrix is not square.SingularMatrixException
- If thesrc
matrix is singular.- See Also:
-
invSymPosDef
Inverts a symmetric positive definite matrix.- Parameters:
src
- Positive definite matrix.checkPosDef
- Flag indicating if a check should be made to see ifsrc
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 thesrc
matrix is singular.
-
invHermPosDef
Inverts a hermitian positive definite matrix.- Parameters:
src
- Positive definite matrix. It will not be verified ifsrc
is actually hermitian positive definite.- Returns:
- The inverse of the
src
matrix. - Throws:
IllegalArgumentException
- If the matrix is not square.SingularMatrixException
- If thesrc
matrix is singular.- See Also:
-
invHermPosDef
Inverts a hermitian positive definite matrix.- Parameters:
src
- Positive definite matrix.checkPosDef
- Flag indicating if a check should be made to see ifsrc
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 thesrc
matrix is singular.
-
pInv
-
pInv
-
isInv
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. Otherwise, returns false. Otherwise, returns false.
-
isInv
-