2

我想使用 Jama 库将 2 矩阵相乘,但它返回:

A col: 4 row: 4
B col: 1 row: 4
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Matrix dimensions must agree.

我的代码:

double[][] arrA = { {1,0,0,0}, {0, Math.cos(0.34), -Math.sin(0.34), 0}, {0, Math.sin(0.34), Math.cos(0.34), 0}, {0,0,0,1} };
        double[][] arrB = { {x}, {y}, {z}, {1} };
        Matrix A = new Matrix(arrA, 4, 4);
        Matrix B = new Matrix(arrB, 4, 1);
        A.print(1, 1);
        B.print(1, 1);
        System.out.println("A col: " + A.getColumnDimension() + " row: " + A.getRowDimension());
        System.out.println("B col: " + B.getColumnDimension() + " row: " + B.getRowDimension());
        Matrix C = A.arrayTimes(B);
4

2 回答 2

5

你想做A.times(B)矩阵乘法。

arrayTimes是逐个元素的乘法。

于 2011-10-12T15:41:09.453 回答
0

对于 JAMA 的更深入的了解,我真的建议: http: //math.nist.gov/javanumerics/jama/doc/

于 2015-08-18T08:43:53.643 回答