1

关于Matrix Toolkit Java (MTJ),我有一个非常幼稚的问题:如何Matrix Bdouble[][] A?

因为在库中,Matrix只是一个接口而不是一个

编辑

所以,我认为拥有JAMA和'MTJ'会解决问题,因为JAMA可以直接定义Matrix对象,但它没有奏效。

我的代码是这样的:

导入 java.util.Arrays;进口贾马。; 导入 no.uib.cipr.matrix。;

public class MainCalc extends TurbulentModel {

    public static void main(String[] args){
        //      TurbulentModel A = new TurbulentModel();
        //      A.numberOfPointsAlongX = 4096;
        //      A.numberOfPointsAlongY = 3;
        //      A.numberOfPointsAlongZ = 3;
        //      A.averageHubWindSpeed = 8;
        //      A.durationOfWindFile = 600;
        //      A.hubHeight = 90;
        //      A.turbulentSeedNumber = 1;
        //      A.volumeWidthAlongY = 150;
        //      A.volumeHeightAlongZ = 150; 
        //      float[] pointsYCoord = A.calcPointsYCoord();
        //      float[] pointsZCoord = A.calcPointsZCoord();
        double[][] rr = {{2, -1, 0},{-1, 2, -1},{0, -1, 2}};
        Matrix test = new Matrix(rr);
        LowerTriangPackMatrix test1 = new LowerTriangPackMatrix(test);

       System.exit(0);

    }
}

s但它被解决为JAMA Matrix concept and MTJ'sMatrix`定义之间的明显冲突。

我该如何解决这个问题?

4

1 回答 1

2

您不需要 JAMA 在 MTJ 中创建矩阵。事实上,正如您已经发现的那样,JAMA 会妨碍 MTJ。

在 MTJ 中创建矩阵对象的最简单方法是使用DenseMatrix实​​现Matrix接口的类。它的一个构造函数接受 adouble[][]并创建一个矩阵,其条目是输入数组中给出的那些。例如,

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

还有其他可用的构造函数,但这两种形式似乎最符合您的需求。您应该查阅javadoc(请注意,这不适用于最新版本 1.01,但似乎很接近)以获取更多选项。

我假设您需要为矩阵进行密集存储。如果您有一个稀疏矩阵,那么 MTJ 中还有其他类,您应该使用它们来代替orDenseMatrix类。您将使用哪些稀疏矩阵类取决于所表示的矩阵固有的稀疏类型。CompColMatrixSymmTridiagMatrix

然而,当有疑问时,密集存储方法将适用于所有可能的矩阵。使用稀疏矩阵的好处是速度和存储空间,但仅适用于适当稀疏的矩阵。

于 2014-03-05T23:51:18.497 回答