mikera.matrixx.algo.Definite Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vectorz Show documentation
Show all versions of vectorz Show documentation
Fast double-precision vector and matrix maths library for Java, supporting N-dimensional numeric arrays.
package mikera.matrixx.algo;
import mikera.matrixx.AMatrix;
import mikera.matrixx.decompose.Cholesky;
import mikera.matrixx.decompose.Eigen;
import mikera.matrixx.decompose.IEigenResult;
import mikera.vectorz.Vector2;
public class Definite {
private Definite(){}
/**
* Tests whether a symmetric matrix is positive definite
*
* Results are undefined if the matrix is not symmetric
*
* @param a
* @return
*/
public static boolean isPositiveDefinite(AMatrix a) {
return Cholesky.decompose(a)!=null;
}
/**
* Tests whether a symmetric matrix is positive semi-definite
*
* Results are undefined if the matrix is not symmetric
*
* @param a
* @return
*/
public static boolean isPositiveSemiDefinite(AMatrix a) {
IEigenResult e=Eigen.decomposeSymmetric(a);
if (e==null) return false;
Vector2[] eigenValues=e.getEigenvalues();
for (Vector2 v:eigenValues) {
if (v.x<0) return false;
}
return true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy