All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mikera.matrixx.algo.Definite Maven / Gradle / Ivy

Go to download

Fast double-precision vector and matrix maths library for Java, supporting N-dimensional numeric arrays.

There is a newer version: 0.67.0
Show newest version
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