public static double[][] multiplyMatrix(double[][] matrix1, double[][] matrix2) {
// As both arrays are square and the same size, the row size represents the row size and column size for both matrices
int dimension = matrix1.length;
double[][] matrix3 = new double[dimension][dimension];
for (int i = 0; i < dimension-1; i++) {
for (int j = 0; j < dimension-1; j++) {
for (int k = 0; k < dimension-1; j++) {
matrix3[i][j] += matrix1[i][k] * matrix2[k][j];
}
}
}
return matrix3;
}
Run Code Online (Sandbox Code Playgroud)
这非常令人沮丧.
你的for循环需要再进行一次迭代.
for (int i = 0; i < dimension-1; i++)
Run Code Online (Sandbox Code Playgroud)
应该
for (int i = 0; i < dimension; i++)
Run Code Online (Sandbox Code Playgroud)
还要以相同的方式更新j和k循环(并且k循环增量j,这看起来像复制/粘贴错误).