Answer the question
In order to leave comments, you need to log in
How to find the determinant of a matrix (two-dimensional array) in Java?
During the writing of the laboratory work, I hit a dead end. There is a two-dimensional array, ala matrix and it is necessary to find its determinant. I know how to find the determinant itself, but I can't figure out how to implement it. By condition, third-party libraries cannot be used.
public class ThirdTask {
public static void main(String[] args) {
int[][] arrayMatrix = {{1,3,5,17,18,11,15,9,23,22}, {2,48,15,19,11,23,22,7,9,1},
{1,2,3,10,22,11,33,8,18,13}, {2,48,15,19,11,23,22,7,9,1},
{1,3,5,17,18,11,15,9,23,22}, {1,2,3,10,22,11,33,8,18,13},
{2,48,15,19,11,23,22,7,9,1}, {3,1,19,27,5,11,20,17,12,8} };
printArray(arrayMatrix);
}
public static void printArray(int[][] arrayMatrix) {
for(int[] value: arrayMatrix) {
for (int x = 0; x < value.length; x++) {
System.out.print(value[x] + "\t");
if (x == value.length - 1) {
System.out.println();
}
}
}
}
}
Answer the question
In order to leave comments, you need to log in
I join the previous speakers, but I want to warn you that the recursive algorithm for expanding in minors has complexity O (n!), And 10! = 3628800. In general, it can slow down if it is important :)
From the point of view of speed, it is better to bring the matrix to a triangular form using the Gaussian method, the determinant in this case is equal to the product of the diagonal elements. Complexity - O(n 3 ).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question