answersLogoWhite

0

/*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;

}

User Avatar

Wiki User

14y ago

Still curious? Ask our experts.

Chat with our AI personalities

DevinDevin
I've poured enough drinks to know that people don't always want advice—they just want to talk.
Chat with Devin
MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine
ProfessorProfessor
I will give you the most educated answer.
Chat with Professor

Add your answer:

Earn +20 pts
Q: Determinant of matrix in java
Write your answer...
Submit
Still have questions?
magnify glass
imp