code: public static final double calculateDeterminant(double[][] ai, int dim) {
  		double det = 0;
  		if (dim == 1) {
  			det = ai[0][0];
  		} else if (dim == 2) {
  			det = ai[0][0] * ai[1][1] - ai[0][1] * ai[1][0];
  		} else {
  			double ai1[][] = new double[dim - 1][dim - 1];
  			for (int k = 0; k < dim; k++) {
  				for (int i1 = 1; i1 < dim; i1++) {
  					int j = 0;
  					for (int j1 = 0; j1 < dim; j1++) {
  						if (j1 != k) {
  							ai1[i1 - 1][j] = ai[i1][j1];
  							j++;
  						}
  					}
  				}
  				if (k % 2 == 0) {
  					det += ai[0][k] * calculateDeterminant(ai1, dim - 1);
  				} else {
  					det -= ai[0][k] * calculateDeterminant(ai1, dim - 1);
  				}
  			}
  		}
  		return det;
  	}
docs: Brute-force determinant calculation.