gpt4 book ai didi

java - 使用 Jama 库的矩阵乘法

转载 作者:行者123 更新时间:2023-11-30 07:30:37 24 4
gpt4 key购买 nike

我想使用 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);

最佳答案

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

arrayTimes是逐个元素相乘。

关于java - 使用 Jama 库的矩阵乘法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7742671/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com