Java Programming

Algebra

Linear Algebra

# Determinant of matrix in java?

###### Wiki User

###### December 31, 2010 10:33AM

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

}

## Related Questions

###### Asked in Algebra

### What is the minor of determinant?

###### Asked in Abstract Algebra

### What are applications of determinants?

If you think of a matrix as a mapping of one vector to another,
by either rotation or stretching, then the determinant tells you
what size one unit volume is mapped to. This also can tell you if a
matrix has an inverse as at least one dimension in a non-invertible
matrix will be mapped to zero, making the determinant zero.

###### Asked in Rhyming Words

### What rhymes with permanent?

###### Asked in Definitions, Abstract Algebra, Linear Algebra

### What is the determinant of a matrix?

A determinant is defined for square matrices only.
To find the determinant of the matrix you need to:
find all n-tuples of elements of the matrix such that each row
and each column of the matrix is represented.
calculate the product of the elements.
calculate the sign for that term. To see how this is done, see
below.
calculate the sum of the signed products: that is the
determinant.
To calculate the sign for the product of the n-tuple, arrange
the elements in row order. Swap the elements, two at a time, to get
them in column order. If the number of swaps required is even then
the product is assigned a positive sign, and if odd then a negative
sign.