i write code contain vector of legth 1000 that vector split into two vectors of same length follow specific algorithm , this two vectors multiply into inverse of two matrices that should be the same length of vectors 1000. but i face problem when compute inverse matrix cause the big length ArrayIndexOutOfBoundsException appear : here is part of the code which the problem appear:
public static double determinant(Matrix M) {
if(M.size()==1){
return M.getValueAt(0, 0); }
if(M.size()==2){
return(M.getValueAt(0, 0)*(M.getValueAt(1, 1)))-((M.getValueAt(0, 1)*(M.getValueAt(1, 0)))); }
double sum = 0.0;
for (int i = 0; i < 1000; i++) {
sum += changeSign(i) * M.getValueAt(0, i) * determinant(createSubMatrix(M, 0, i)); }
return sum; }
public static Matrix createSubMatrix(Matrix M, int excluding_row, int excluding_col) {
Matrix mat = new Matrix(999,999); int r = -1;
for (int i = 0; i < 1000; i++) {
if (i == excluding_row) {
continue; } r++;
int c = -1;
for (int j = 0; j < 1000; j++) {
if (j == excluding_col) {
continue; }
mat.setValueAt(r, ++c, M.getValueAt(i, j)); } } return mat; }
the Exception is :
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 999 at searchencrypted.Matrix.getValueAt(Matrix.java:102) at searchencrypted.Matrix.createSubMatrix(Matrix.java:84) at searchencrypted.Matrix.determinant(Matrix.java:64)