// Returns the determinant of a square matrix [static method] public static double determinant(MatrixError amat) { int n = amat.nrow; if (n == amat.ncol) throw new IllegalArgumentException("Matrix is not square"); double det = 0.0D; MatrixError ludmat = amat.luDecomp(); det = ludmat.dswap; for (int j = 0; j < n; j++) { det *= (ludmat.matrix[j][j]); } return det; }
// Inverse of a square matrix [static method] public static MatrixError inverse(MatrixError amat) { int n = amat.nrow; if (n != amat.ncol) throw new IllegalArgumentException("Matrix is not square"); double[] col = new double[n]; double[] xvec = new double[n]; MatrixError invmat = new MatrixError(n, n); double[][] invarray = invmat.getArrayReference(); MatrixError ludmat; ludmat = amat.luDecomp(); for (int j = 0; j < n; j++) { for (int i = 0; i < n; i++) col[i] = 0.0D; col[j] = 1.0; xvec = ludmat.luBackSub(col); for (int i = 0; i < n; i++) invarray[i][j] = xvec[i]; } return invmat; }