Я пытаюсь сделать простой метод умножения матрицы, используя многомерные массивы ([2][2]
). Я новичок в этом, и я просто не могу понять, что я делаю неправильно. Я бы очень признателен за любую помощь в том, чтобы рассказать мне, что это такое. Я бы предпочел не использовать библиотеки или что-то в этом роде, я в основном делаю это, чтобы узнать, как это работает. Большое вам спасибо заранее.
Я объявляю свои arays в основном методе следующим образом:
Double[][] A={{4.00,3.00},{2.00,1.00}};
Double[][] B={{-0.500,1.500},{1.000,-2.0000}};
A * B должен вернуть единичную матрицу. Это не так.
public static Double[][] multiplicar(Double[][] A, Double[][] B){
//the method runs and returns a matrix of the correct dimensions
//(I actually changed the .length function to a specific value to eliminate
//it as a possible issue), but not the correct values
Double[][] C= new Double[2][2];
int i,j;
////I fill the matrix with zeroes, if I don't do this it gives me an error
for(i=0;i<2;i++) {
for(j=0;j<2;j++){
C[i][j]=0.00000;
}
}
///this is where I'm supposed to perform the adding of every element in
//a row of A multiplied by the corresponding element in the
//corresponding column of B, for all columns in B and all rows in A
for(i=0;i<2;i++){
for(j=0;j<2;j++)
C[i][j]+=(A[i][j]*B[j][i]);
}
return C;
}