0% found this document useful (0 votes)
147 views

Java Matrix Determinant

This Java method calculates the determinant of a matrix. It first checks if the matrix is 1x1 and simply returns the value. Otherwise, it iterates through each column, gets the submatrix by removing that column's row and column, calculates the determinant of the submatrix recursively, and adds the signed value to the running total, switching the sign with each iteration. It returns the final determinant value.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
147 views

Java Matrix Determinant

This Java method calculates the determinant of a matrix. It first checks if the matrix is 1x1 and simply returns the value. Otherwise, it iterates through each column, gets the submatrix by removing that column's row and column, calculates the determinant of the submatrix recursively, and adds the signed value to the running total, switching the sign with each iteration. It returns the final determinant value.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

JAVA MATRIX DETERMINANT

public static double determinant(double[][] input) {


int rows = nRows(input);
//number of rows in the matrix
int columns = nColumns(input); //number of columns in the matrix
double determinant = 0;
if ((rows== 1) && (columns == 1)) return input[0][0];
int sign = 1;
for (int column = 0; column < columns; column++) {
double[][] submatrix = getSubmatrix(input, rows, columns,column);
determinant = determinant + sign*input[0]
[column]*determinant(submatrix);
sign*=-1;
}
return determinant;
}

You might also like