Class MatrixPropertyUtils
- java.lang.Object
-
- dev.nm.algebra.linear.matrix.doubles.MatrixPropertyUtils
-
public final class MatrixPropertyUtils extends Object
These are the boolean operators that take matrices or vectors and check if they satisfy a certain property.
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static booleanareAllSparse(Matrix... matrices)Checks if all matrices are SparseMatrix.static booleanareAllSparse(Vector... vectors)Checks if all vectors are SparseVector.static booleanareEqual(Matrix A1, Matrix A2, double epsilon)Checks the equality of two matrices up to a precision.static booleanareEqual(Vector v1, Vector v2, double epsilon)Checks if two vectors are equal, i.e., v1 - v2 is a zero vector, up to a precision.static booleanareOrthogonal(Vector[] v, double epsilon)Checks if a set of vectors are orthogonal, i.e., for any v1, v2 in v, v1 ∙ v2 == 0.static booleanareOrthogonal(Vector v1, Vector v2, double epsilon)Checks if two vectors are orthogonal, i.e., v1 ∙ v2 == 0.static booleanareOrthogonormal(Vector[] v, double epsilon)Checks if a set of vectors are orthogonormal.static booleanareOrthogonormal(Vector v1, Vector v2, double epsilon)Checks if two vectors are orthogonormal.static doubleconditionNumber(Matrix A)Computes the condition number of a given matrix A.static booleanisDiagonal(Matrix A, double epsilon)Checks if a square matrix is a diagonal matrix, up to a precision.static booleanisIdempotent(Matrix A, double epsilon)Checks if a matrix is idempotent.static booleanisIdentity(Matrix A, double epsilon)Checks if a matrix is an identity matrix, up to a precision.static booleanisLowerBidiagonal(Matrix A, double epsilon)Checks if a matrix is lower bidiagonal, up to a precision.static booleanisLowerTriangular(Matrix A, double epsilon)Checks if a matrix is lower triangular, up to a precision.static booleanisMagicSquare(Matrix A)Deprecated.Not supported yet.static booleanisNaN(Vector v)Checks if a vector contains anyNaNentry.static booleanisOrthogonal(Matrix A, double epsilon)Checks if a matrix is orthogonal, up to a precision.static booleanisPositiveDefinite(Matrix A, double epsilon)Checks if a square matrix is positive definite; the matrix needs not be symmetric.static booleanisPositiveSemiDefinite(Matrix A, double epsilon)Checks if a square matrix is positive definite, up to a precision.static booleanisQuasiTriangular(Matrix A, double epsilon)Checks if a matrix is quasi (upper) triangular, up to a precision.static booleanisReducedRowEchelonForm(Matrix A, double epsilon)Checks if a matrix is in the reduced row echelon form, up to a precision.static booleanisRowEchelonForm(Matrix A, double epsilon)Checks if a matrix is in the row echelon form, up to a precision.static booleanisScalar(Matrix A, double epsilon)Deprecated.Not supported yet.static booleanisSingular(Matrix A, double epsilon)Checks if a square matrix is singular, i.e, having no inverse, up to a precision.static booleanisSkewSymmetric(Matrix A, double epsilon)Checks if a matrix is skew symmetric.static booleanisSymmetric(Matrix A, double epsilon)Checks if a matrix is symmetric.static booleanisSymmetricPositiveDefinite(Matrix A, double epsilon)Checks if a square matrix is symmetric and positive definite.static booleanisTridiagonal(Matrix A, double epsilon)Checks if a matrix is tridiagonal, up to a precision.static booleanisUpperBidiagonal(Matrix A, double epsilon)Checks if a matrix is upper bidiagonal, up to a precision.static booleanisUpperTriangular(Matrix A, double epsilon)Checks if a matrix is upper triangular, up to a precision.static booleanisZero(Vector v, double epsilon)Checks if a vector is a zero vector, i.e., all its entries are 0, up to a precision.static voidthrowIfInvalidIndex(Vector v, int index)Checks if an index is a valid index.static voidthrowIfNotEqualSize(Vector v1, Vector v2)Checks if the input vectors have the same size.
-
-
-
Method Detail
-
isSymmetric
public static boolean isSymmetric(Matrix A, double epsilon)
Checks if a matrix is symmetric.- Parameters:
A- a matrixepsilon- a precision parameter: when a number |x| ≤ ε, it is considered 0- Returns:
trueifA.t() == A
-
isSkewSymmetric
public static boolean isSkewSymmetric(Matrix A, double epsilon)
Checks if a matrix is skew symmetric.- Parameters:
A- a matrixepsilon- a precision parameter: when a number |x| ≤ ε, it is considered 0- Returns:
trueifA.t() == -A
-
isIdempotent
public static boolean isIdempotent(Matrix A, double epsilon)
Checks if a matrix is idempotent.- Parameters:
A- a matrixepsilon- a precision parameter: when a number |x| ≤ ε, it is considered 0- Returns:
trueifA = A*A or A = A2
-
isOrthogonal
public static boolean isOrthogonal(Matrix A, double epsilon)
Checks if a matrix is orthogonal, up to a precision.- Parameters:
A- a matrixepsilon- a precision parameter: when a number |x| ≤ ε, it is considered 0- Returns:
trueifAA' = 1
-
isMagicSquare
@Deprecated public static boolean isMagicSquare(Matrix A)
Deprecated.Not supported yet.Checks if a matrix is a magic square. Not yet implemented.- Parameters:
A- a matrix- Returns:
trueif A is a square matrix having distinct positive integers, arranged such that the sums of the numbers in any rows, columns, or diagonals are equal
-
isSingular
public static boolean isSingular(Matrix A, double epsilon)
Checks if a square matrix is singular, i.e, having no inverse, up to a precision.- Parameters:
A- a matrixepsilon- a precision parameter: when a number |x| ≤ ε, it is considered 0- Returns:
trueif A-1 does not exist
-
isDiagonal
public static boolean isDiagonal(Matrix A, double epsilon)
Checks if a square matrix is a diagonal matrix, up to a precision.- Parameters:
A- a matrixepsilon- a precision parameter: when a number |x| ≤ ε, it is considered 0- Returns:
trueif A is square and Aij=0, for all i != j.
-
isIdentity
public static boolean isIdentity(Matrix A, double epsilon)
Checks if a matrix is an identity matrix, up to a precision.- Parameters:
A- a matrixepsilon- a precision parameter: when a number |x| ≤ ε, it is considered 0- Returns:
trueif A is square, and Aij=0 for all i != j, and Aij=1, for all i == j.
-
isUpperTriangular
public static boolean isUpperTriangular(Matrix A, double epsilon)
Checks if a matrix is upper triangular, up to a precision.- Parameters:
A- a matrixepsilon- a precision parameter: when a number |x| ≤ ε, it is considered 0- Returns:
trueif the matrix is upper triangular
-
isLowerTriangular
public static boolean isLowerTriangular(Matrix A, double epsilon)
Checks if a matrix is lower triangular, up to a precision.- Parameters:
A- a matrixepsilon- a precision parameter: when a number |x| ≤ ε, it is considered 0- Returns:
trueif the matrix is lower triangular
-
isQuasiTriangular
public static boolean isQuasiTriangular(Matrix A, double epsilon)
Checks if a matrix is quasi (upper) triangular, up to a precision.A quasi triangular matrix is upper Hessenberg with no two consecutive non-zero elements on the first subdiagonal.
- Parameters:
A- a matrixepsilon- a precision parameter: when a number |x| ≤ ε, it is considered 0- Returns:
trueif the matrix is quasi (upper) triangular
-
isUpperBidiagonal
public static boolean isUpperBidiagonal(Matrix A, double epsilon)
Checks if a matrix is upper bidiagonal, up to a precision.- Parameters:
A- a matrixepsilon- a precision parameter: when a number |x| ≤ ε, it is considered 0- Returns:
trueif the matrix is upper bidiagonal
-
isLowerBidiagonal
public static boolean isLowerBidiagonal(Matrix A, double epsilon)
Checks if a matrix is lower bidiagonal, up to a precision.- Parameters:
A- a matrixepsilon- a precision parameter: when a number |x| ≤ ε, it is considered 0- Returns:
trueif the matrix is lower bidiagonal
-
isTridiagonal
public static boolean isTridiagonal(Matrix A, double epsilon)
Checks if a matrix is tridiagonal, up to a precision.- Parameters:
A- a matrixepsilon- a precision parameter: when a number |x| ≤ ε, it is considered 0- Returns:
trueif the matrix is tridiagonal
-
isRowEchelonForm
public static boolean isRowEchelonForm(Matrix A, double epsilon)
Checks if a matrix is in the row echelon form, up to a precision.- Parameters:
A- a matrixepsilon- a precision parameter: when a number |x| ≤ ε, it is considered 0- Returns:
trueif the matrix is in row echelon form- See Also:
- Wikipedia: Row echelon form
-
isReducedRowEchelonForm
public static boolean isReducedRowEchelonForm(Matrix A, double epsilon)
Checks if a matrix is in the reduced row echelon form, up to a precision.- Parameters:
A- a matrixepsilon- a precision parameter: when a number |x| ≤ ε, it is considered 0- Returns:
trueif the matrix is in reduced row echelon form- See Also:
- Wikipedia: Row echelon form
-
isScalar
@Deprecated public static boolean isScalar(Matrix A, double epsilon)
Deprecated.Not supported yet.Checks if a square matrix is a scalar matrix, up to a precision.- Parameters:
A- a matrix- Returns:
trueif A is diagonal and, aij=c, for all i == j, c is a constant.
-
isSymmetricPositiveDefinite
public static boolean isSymmetricPositiveDefinite(Matrix A, double epsilon)
Checks if a square matrix is symmetric and positive definite.- Parameters:
A- a matrixepsilon- a precision parameter: when a number |x| ≤ ε, it is considered 0- Returns:
trueif A is symmetric, and z'Mz > 0, for all non-zero real vectors z.- See Also:
- Wikipedia: Positive-definite matrix
-
isPositiveDefinite
public static boolean isPositiveDefinite(Matrix A, double epsilon)
Checks if a square matrix is positive definite; the matrix needs not be symmetric. A real matrix A is positive definite if the symmetric part Asymmetric = 1/2 * (A + A') is symmetric positive definite.- Parameters:
A- a matrixepsilon- a precision parameter: when a number |x| ≤ ε, it is considered 0- Returns:
trueif A satisfies z'Mz > 0, for all non-zero real vectors z.- See Also:
- Wikipedia: Positive-definite matrix
-
isPositiveSemiDefinite
public static boolean isPositiveSemiDefinite(Matrix A, double epsilon)
Checks if a square matrix is positive definite, up to a precision.- Parameters:
A- a matrixepsilon- a precision parameter: when a number |x| ≤ ε, it is considered 0- Returns:
trueif A satisfies z'Mz > 0, for all non-zero real vectors z.- See Also:
- Wikipedia: Negative-definite, semidefinite and indefinite matrices
-
isZero
public static boolean isZero(Vector v, double epsilon)
Checks if a vector is a zero vector, i.e., all its entries are 0, up to a precision.- Parameters:
v- a vectorepsilon- a precision parameter: when a number |x| ≤ ε, it is considered 0- Returns:
trueif v is a zero vector
-
areEqual
public static boolean areEqual(Matrix A1, Matrix A2, double epsilon)
Checks the equality of two matrices up to a precision. Two matrices are equal if- the dimensions are the same;
- all entries are equal
- Parameters:
A1- a matrixA2- a matrixepsilon- a precision parameter: when a number |x| ≤ ε, it is considered 0- Returns:
trueif all entries are equal, entry by entry
-
areEqual
public static boolean areEqual(Vector v1, Vector v2, double epsilon)
Checks if two vectors are equal, i.e., v1 - v2 is a zero vector, up to a precision.- Parameters:
v1- a vectorv2- a vectorepsilon- a precision parameter: when a number |x| ≤ ε, it is considered 0- Returns:
trueif all entries are equal, entry by entry
-
areOrthogonal
public static boolean areOrthogonal(Vector v1, Vector v2, double epsilon)
Checks if two vectors are orthogonal, i.e., v1 ∙ v2 == 0.- Parameters:
v1- a vectorv2- a vectorepsilon- a precision parameter: when a number |x| ≤ ε, it is considered 0- Returns:
truethe two vectors are orthogonal
-
areOrthogonal
public static boolean areOrthogonal(Vector[] v, double epsilon)
Checks if a set of vectors are orthogonal, i.e., for any v1, v2 in v, v1 ∙ v2 == 0.- Parameters:
v- a set of vectorsepsilon- a precision parameter: when a number |x| ≤ ε, it is considered 0- Returns:
trueif any two vectors are orthogonal
-
areOrthogonormal
public static boolean areOrthogonormal(Vector v1, Vector v2, double epsilon)
Checks if two vectors are orthogonormal. Two vectors are orthogonormal if- {v1, v2} are orthogonal;
- |v1| = |v2| = 1.
- Parameters:
v1- a vectorv2- a vectorepsilon- a precision parameter: when a number |x| ≤ ε, it is considered 0- Returns:
trueif the two vectors are orthogonormal
-
areOrthogonormal
public static boolean areOrthogonormal(Vector[] v, double epsilon)
Checks if a set of vectors are orthogonormal.- Parameters:
v- a set of vectorsepsilon- a precision parameter: when a number |x| ≤ ε, it is considered 0- Returns:
trueif any two vectors are orthogonormal
-
areAllSparse
public static boolean areAllSparse(Matrix... matrices)
Checks if all matrices are SparseMatrix.- Parameters:
matrices-- Returns:
trueif and only if all matrices are SparseMatrix
-
areAllSparse
public static boolean areAllSparse(Vector... vectors)
Checks if all vectors are SparseVector.- Parameters:
vectors-- Returns:
trueif and only if all matrices are SparseVector
-
throwIfNotEqualSize
public static void throwIfNotEqualSize(Vector v1, Vector v2)
Checks if the input vectors have the same size.- Parameters:
v1- a vectorv2- a vector- Throws:
VectorSizeMismatch- if sizes do not match
-
throwIfInvalidIndex
public static void throwIfInvalidIndex(Vector v, int index)
Checks if an index is a valid index.- Parameters:
v- a vectorindex- a vector index- Throws:
VectorAccessException- if the index is invalid
-
isNaN
public static boolean isNaN(Vector v)
Checks if a vector contains anyNaNentry.- Parameters:
v- a vector- Returns:
trueif there is at least oneNaNentry.
-
conditionNumber
public static double conditionNumber(Matrix A)
Computes the condition number of a given matrix A. The condition number is computed as the maximal singular value of A divided by the minimal singular value of A. If the condition number is large, A is ill-conditioned. Practically, such a matrix is almost singular, and the computation of its inverse, or solution of a linear system of equations is prone to large numerical errors. A matrix that is not invertible has condition number equal to infinity.- Parameters:
A- the matrix- Returns:
- the condition number of A
- See Also:
- Wikipedia: Condition number
-
-