在Matrix Toolkit Java中构造矩阵
关于矩阵工具包Java(MTJ),我有一个非常天真的问题:如何从在Matrix Toolkit Java中构造矩阵,java,mtj,Java,Mtj,关于矩阵工具包Java(MTJ),我有一个非常天真的问题:如何从双[][]a开始构建矩阵B 因为,在库中,矩阵只是一个接口,而不是类 编辑 因此,我认为使用JAMA和'MTJ'可以解决这个问题,因为在JAMA中,可以直接定义矩阵对象,但它不起作用 我的代码是: 导入java.util.array; 输入Jama。; 进口编号uib.cipr.matrix 但它被分解为JAMAsMatrix概念和MTJ的Matrix`定义之间的明显冲突 我该如何解决这个问题?您不需要JAMA在MTJ中创建矩阵。事
双[][]a
开始构建矩阵B
因为,在库中,矩阵
只是一个接口,而不是类
编辑
因此,我认为使用JAMA
和'MTJ'可以解决这个问题,因为在JAMA
中,可以直接定义矩阵
对象,但它不起作用
我的代码是:
导入java.util.array;
输入Jama。;
进口编号uib.cipr.matrix
但它被分解为JAMAs
Matrix概念和MTJ的
Matrix`定义之间的明显冲突
我该如何解决这个问题?您不需要JAMA在MTJ中创建矩阵。事实上,正如你已经发现的那样,JAMA将成为MTJ的绊脚石 在MTJ中创建矩阵对象的最简单方法是使用实现
matrix
接口的DenseMatrix
类。它的一个构造函数接受一个double[][]
,并创建一个矩阵,其条目是输入数组中给定的条目。比如说,
// create array of backing values for an n-by-n matrix
double[][] matValues = new double[n][n];
... // initialize values somehow
// create a matrix from the matValues array with deep-copy semantics
// the matrix A is independent of any changes to the matValues array and vis-versa
Matrix A = new DenseMatrix(matValues);
// create a matrix from the matValues array **without** deep-copy semantics
// the matrix B will reflect any changes made to the matValues array and vis-versa
Matrix B = new DenseMatrix(matValues, false);
还有其他可用的构造函数,但这两种形式似乎最适合您的需要。有关更多选项,请咨询(请注意,这不是最新版本1.01,但似乎很接近)
我假设您需要密集存储。如果您有,那么MTJ中还有其他类,您应该使用它们来代替DenseMatrix
,例如CompColMatrix
或symmtridiagmetrix
类。您将使用哪些稀疏矩阵类取决于所表示矩阵固有的稀疏性类型
然而,当有疑问时,密集存储方法将适用于所有可能的矩阵。使用稀疏矩阵的好处是速度和存储空间,但仅适用于适当稀疏的矩阵。您能给我们看一下API文档吗?看这里,正如我所期望的:
Matrix
类从JAMA
库中递减。
// create array of backing values for an n-by-n matrix
double[][] matValues = new double[n][n];
... // initialize values somehow
// create a matrix from the matValues array with deep-copy semantics
// the matrix A is independent of any changes to the matValues array and vis-versa
Matrix A = new DenseMatrix(matValues);
// create a matrix from the matValues array **without** deep-copy semantics
// the matrix B will reflect any changes made to the matValues array and vis-versa
Matrix B = new DenseMatrix(matValues, false);