Java 如何用jblas求复双矩阵的逆

Java 如何用jblas求复双矩阵的逆,java,matrix,eigenvector,eigenvalue,Java,Matrix,Eigenvector,Eigenvalue,基本上,我想计算一个属于ComplexDoubleMatrix类的矩阵的逆,但是我没有找到像inverse()或inv()这样的函数,有人知道如何计算矩阵的逆吗?先谢谢你 我的最终目标是使用jblas.eigen创建矩阵的特征分解。 现在,我当前的实现是由下面的jama库实现的。为了执行类似的函数,我需要计算Vinverse,这就是为什么我想在jblas中找到一个反函数 public static SimpleEigenDecomposition SimpleEigenDecomposition

基本上,我想计算一个属于ComplexDoubleMatrix类的矩阵的逆,但是我没有找到像inverse()或inv()这样的函数,有人知道如何计算矩阵的逆吗?先谢谢你

我的最终目标是使用jblas.eigen创建矩阵的特征分解。 现在,我当前的实现是由下面的jama库实现的。为了执行类似的函数,我需要计算Vinverse,这就是为什么我想在jblas中找到一个反函数

public static SimpleEigenDecomposition SimpleEigenDecomposition(double [][] rates)
 {
     Matrix ratesMatrix = new Matrix(rates);
     EigenvalueDecomposition ed = new EigenvalueDecomposition(ratesMatrix);
     Matrix V = ed.getV();
     Matrix D =ed.getD();
     Matrix Vinverse = V.inverse();
     Matrix resultMatrix = V.times(D).times(V.inverse());
   //check if result and rates are close enough
     SimpleMatrix trueMatrix = new SimpleMatrix(rates);
     SimpleMatrix calculatedMatrix = new SimpleMatrix(resultMatrix.getArray()) ;
     if(EJMLUtils.isClose(trueMatrix, calculatedMatrix, THRESHOLD))
   {
      return new  SimpleEigenDecomposition(V, D, Vinverse);
   }else{
     throw new RuntimeException();
     }

原因是没有逆运算,因为如果使用Cramer规则进行逆运算,计算成本太高。我最初认为这很奇怪,因为它可能是用高斯-乔登消去法实现的。但奇怪的是,连我都找不到。如果有人在JBLAS中找到它,请在下面进行评论

我可以建议使用pinv()。它使用最小二乘法,作为静态函数出现在org.jblas.Solve

import org.jblas.Solve public static SimpleEigenDecomposition SimpleEigenDecomposition(double [][] rates) { // inside the main function replace this for your implementation of inverse DoubleMatrix Vinverse = Solve.pinv(V); } 导入org.jblas.Solve 公共静态SimpleIgendeComposition SimpleIgendeComposition(双[]费率) { //在main函数中,替换此函数以实现反向 双矩阵V=Solve.pinv(V); }
当矩阵可逆时,租约平方pinv给出与实际逆矩阵相同的输出。

矩阵a的逆矩阵可以通过求解AX=I找到,其中I是单位矩阵,X将是a的逆矩阵。因此,使用jblas我们可以说

DoubleMatrix Vinverse = Solve.solve(A, DoubleMatrix.eye(A.rows));
请注意,我们不能反转非方矩阵。我们可以使用以下方法检查矩阵A是否为正方形:

A.isSquare(); // returns true if it is