/*This function will return the determinant of any two dimensional matrix. For this particular function a two dimensional double matrix needs to be passed as arguments - Avishek Ghosh*/
public double determinant(double[][] mat) {
double result = 0;
if(mat.length 2) {
result = mat[0][0] * mat[1][1] - mat[0][1] * mat[1][0];
return result;
}
for(int i = 0; i < mat[0].length; i++) {
double temp[][] = new double[mat.length - 1][mat[0].length - 1];
for(int j = 1; j < mat.length; j++) {
System.arraycopy(mat[j], 0, temp[j-1], 0, i);
System.arraycopy(mat[j], i+1, temp[j-1], i, mat[0].length-i-1);
}
result += mat[0][i] * Math.pow(-1, i) * determinant(temp);
}
return result;
}
Chat with our AI personalities
The determinant function is only defined for an nxn (i.e. square) matrix. So by definition of the determinant it would not exist for a 2x3 matrix.
1
0 or 1
No.
A single math equation does not have a determinant. A system of equations (3x3 , 4x4, etc.) will have a determinant. You can find a determinant of a system by converting the system into a corresponding matrix and finding its determinant.