矩阵如何从Apache Commons数学Java库中找到伪逆
根据这一准则。它可以使用ApacheCommons数学库查找伪逆
RealMatrix Swinv = new LUDecomposition(Sw).getSolver().getInverse(); // MATLAB: Swinv = pinv(Sw)
但是即使Sw
是正方形,我也可以得到异常org.apache.commons.math3.linear.SingularMatrixException:
根据文献,这个getInverse()
是伪逆的
Get the pseudo-inverse of the decomposed matrix.
这等于分解矩阵的逆(如果存在这样的逆)
如果不存在这样的逆,则结果具有类似于逆的属性
In particular, in this case, if the decomposed matrix is A, then the system of equations ( A x = b ) may have no solutions, or many. If it has no solutions, then the pseudo-inverse ( A^+ ) gives the "closest" solution ( z = A^+ b ), meaning ( \left \| A z - b \right \|_2 ) is minimized. If there are many solutions, then ( z = A^+ b ) is the smallest solution, meaning ( \left \| z \right \|_2 ) is minimized.
那我在这里该怎么办?我想找到伪逆。但是我仍然得到了一个错误,因为Sw
是单数
# 1 楼答案
所以我不确定你是从哪里得到这个想法的
LUDecomposition
解算器会产生伪逆。事实上,如果你看一下代码,你会发现这只适用于if a solution exists "in exact linear sense"相反,您应该首先创建一个
SingularValueDecomposition
然后得到这个奇异值分解产生的分解解算器
然后你可以: