[英]Matrix multiplication using Jama library
I want to multiply 2 matrix using Jama library but it returns: 我想使用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.
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. 您想对矩阵乘法做
A.times(B)
。
arrayTimes
is element by element multiplication. arrayTimes
是逐元素相乘。
有关JAMA的更深层次的想法,我确实建议: http : //math.nist.gov/javanumerics/jama/doc/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.