我一直在尝试编写分治矩阵乘法算法
有一个问题,当我尝试将矩阵分成四个季度时,它给了我一个错误 ArrayOutOfIndexBound
- 我不确定我对基本情况是否正确,所以你们能帮帮我吗?
我遇到的问题是double[][] a21
public static double[][] divideAndConquer(double[][] a , double[][] b, int dimension){
if (a.length == 1){
double[][] result = new double[1][1];
result[0][0]= a[0][0]*b[0][0];
return result;
}
else {
int m = dimension/2;
double[][] a11 = new double[m][m];
for(int i = 0; i < m ; i++){
for (int j = 0 ; j< m ; j++)
a11[i][j]= a[i][j];
}
double[][] a21 = new double[m][m];
for(int i = m; i < dimension; i++){
for (int j = 0 ; j< m ; j++)
a21[i][j]= a[i][j];
}
double[][] a12 = new double[m][m];
for(int i = 0; i < m ; i++){
for (int j = m ; j< dimension ; j++)
a12[i][j]= a[i][j];
}
double[][] a22 = new double[m][m];
for(int i = m; i < dimension; i++){
for (int j = m; j < dimension; j++)
a21[i][j]= a[i][j];
}
double[][] b11 = new double[m][m];
for(int i = 0; i < m ; i++){
for (int j = 0 ; j< m ; j++)
b11[i][j]= b[i][j];
}
double[][] b12 = new double[m][m];
for(int i = 0; i < m ; i++){
for (int j = m ; j< dimension ; j++)
b12[i][j]= b[i][j];
}
double[][] b21 = new double[m][m];
for(int i = m; i < dimension; i++){
for (int j = 0 ; j< m ; j++)
b21[i][j]= b[i][j];
}
double[][] b22 = new double[m][m];
for(int i = m; i < dimension; i++){
for (int j = m; j < dimension; j++)
b21[i][j]= b[i][j];
}
double[][] x1 = divideAndConquer(a11,b11,m);
double[][] x2 = divideAndConquer(a12,b21,m);
double[][] x3 = divideAndConquer(a11,b12,m);
double[][] x4 = divideAndConquer(a12,b22,m);
double[][] x5 = divideAndConquer(a21,b11,m);
double[][] x6 = divideAndConquer(a22,b21,m);
double[][] x7 = divideAndConquer(a21,b12,m);
double[][] x8 = divideAndConquer(a22,b22,m);
..........................etc