This is my method to calculate the inverse of a matrix (key). I used the JAMA lib for the calculation.
public static double[][] inverseKey(int[][] key) {
int n = key.length;
double[][] keyAsDoubleArray = new double[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
keyAsDoubleArray[i][j] = key[i][j];
}
}
Matrix matrix = new Matrix(keyAsDoubleArray);
// Berechne die Inverse der Matrix
Matrix inverseMatrix = matrix.inverse();
double[][] inverseArray = inverseMatrix.getArray();
return inverseArray;
}
There is no error but the result of the calculation is wrong. Result: 0.1587301587301587 0.011337868480725636 -0.2244897959183673 -0.7777777777777777 0.15873015873015872 0.857142857142857 0.5079365079365079 -0.10657596371882086 -0.48979591836734687
This is the matrix I used: int[][] key = {{6,13,20},{24,16, 17}, {1,10,15}};
I think there is maybe a problem in converting the int[][] in a double[][], but it is necessary in my specific case that the parameter of the method is a Integer Array. Have you any ideas to solve this problem?