我想用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);发布于 2011-10-12 23:41:09
你想做矩阵乘法的A.times(B)。
arrayTimes是元素与元素的乘法。
发布于 2015-08-18 16:43:54
要更深入地了解JAMA,我真的建议:http://math.nist.gov/javanumerics/jama/doc/
https://stackoverflow.com/questions/7742671
复制相似问题