0
public Matrix<T, A> multiply(Matrix<T, A> right) throws MatrixException {
    Matrix<T, A> temp = new Matrix<T, A>(arithmetics, rowSize, columnSize);



    if (rowSize != right.columnSize)
        throw new MatrixException(
                "Cannot multiply matrices of different sizes");

    for (int i = 0; i < rowSize; i++) {
        for (int j = 0; j < right.columnSize ; j++)
            for(int k = 0; k < right.rowSize ; k++)
            temp.matrix[i][j] = arithmetics.add(temp.matrix[i][j],
         (arithmetics.multiply(matrix[i][k], right.matrix[k][j])));

    return temp;

}}

好吧,所以我正在尝试将 2 个矩阵相乘,但是

Matrix1
0 0 1
1 1 1 

Matrix5
1 2
2 4
3 6

我得到一个答案

Matrix1 multiply Matrix5
3   6   0   
6   12  0   

但应该是

3 6
6 12

因为它矩阵乘法

4

1 回答 1

1

在你的第二行:

Matrix<T, A> temp = new Matrix<T, A>(arithmetics, rowSize, columnSize);

肯定是:

Matrix<T, A> temp = new Matrix<T, A>(arithmetics, rowSize, right.columnSize);
于 2013-07-01T02:47:23.213 回答