Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从创建的数据类型转换RealMatrix以在Apache commons中使用?_Java_Matrix - Fatal编程技术网

Java 如何从创建的数据类型转换RealMatrix以在Apache commons中使用?

Java 如何从创建的数据类型转换RealMatrix以在Apache commons中使用?,java,matrix,Java,Matrix,我需要添加一个方法,使用ApacheCommons类CholeskyDecomposition使用getSolver().getInverse()提供的逆运算。当我尝试使用MyMatrix作为数据类型时,它说它需要是RealMatrix类型,但我不确定如何在两者之间转换(我也不知道为什么它需要是自定义数据类型,但它确实需要) cholesky分解使用RealMatrix接口。您应该看到RealMatrix的哪些实现适合您的用例。从你的问题来看,在我看来你可以使用Array2DroArralMat

我需要添加一个方法,使用ApacheCommons类
CholeskyDecomposition
使用
getSolver().getInverse()
提供的逆运算。当我尝试使用
MyMatrix
作为数据类型时,它说它需要是
RealMatrix
类型,但我不确定如何在两者之间转换(我也不知道为什么它需要是自定义数据类型,但它确实需要)


cholesky分解
使用
RealMatrix
接口。您应该看到
RealMatrix
的哪些实现适合您的用例。从你的问题来看,在我看来你可以使用
Array2DroArralMatrix

您可以这样使用它:

public MyMatrix inverseCD(MyMatrix m)
{
  RealMatrix realMatrix = new Array2DRowRealMatrix(m.getMatrix()); // assuming you created a getter method for the `double[][]` variable
  double[][] inversed = new CholeskyDecomposition(realMatrix).getSolver().getInverse()
                       .getData();
  return new MyMatrix(inversed);
}

cholesky分解
使用
RealMatrix
接口。您应该看到
RealMatrix
的哪些实现适合您的用例。从你的问题来看,在我看来你可以使用
Array2DroArralMatrix

您可以这样使用它:

public MyMatrix inverseCD(MyMatrix m)
{
  RealMatrix realMatrix = new Array2DRowRealMatrix(m.getMatrix()); // assuming you created a getter method for the `double[][]` variable
  double[][] inversed = new CholeskyDecomposition(realMatrix).getSolver().getInverse()
                       .getData();
  return new MyMatrix(inversed);
}

那么m是double[][]类型,即使它是MyMatrix类型?这是代码中的一个错误。你只需要在那里发送适当的参数。在你的例子中,
double[][]
那么double[][]类型的m也是如此,即使它是MyMatrix类型的?这是代码中的一个错误。你只需要在那里发送适当的参数。在您的情况下,
double[][]