开发者

Matrix multiplication using Jama library

I want to multiply 2 matrix using Jama library but 开发者_如何学运维it returns:

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

My code:

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);


You want to do A.times(B) for matrix multiplication.

arrayTimes is element by element multiplication.


For a deeper idea about JAMA, I really suggest: http://math.nist.gov/javanumerics/jama/doc/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜