我有一个方奇异系统 A 和向量 b,它在 A 的范围空间中。因为 b 在 A 的范围空间中并且 A 是奇异的,所以有无穷多个解。现在我想要的是 Ax=b 的一些解,不一定是最小范数。由于我的系统 A 很大,我想避免基于 svd 的解决方案(寻找伪逆)。我正在考虑简单地进行 LU 分解并将自由变量设置为 0,但是当 A 是单数时,我尝试的所有方法都无法为我提供解决方案。
我试过 scipy.linalg.solve 但这要求系统是非奇异的。我也尝试过 scipy lu_factor 和 lu_solve 但在执行 lu_factor 时它给了我运行时警告说“对角线数 %d 正好为零。奇异矩阵。”。
所以我的问题是 - 是给定 b 在 A 的范围空间中,有一种方法(使用 scipy)使用 LU 分解找到奇异系统的解决方案。非常感谢任何建议。非常感谢。
最佳答案
试试 scipy.linalg.lu()。它计算矩阵的旋转 LU 分解。
import pprint
import scipy
import scipy.linalg # SciPy Linear Algebra Library
A = scipy.array([ [7, 3, -1, 2], [3, 8, 1, -4], [-1, 1, 4, -1], [2, -4, -1, 6] ])
P, L, U = scipy.linalg.lu(A)
print "A:"
pprint.pprint(A)
print "P:"
pprint.pprint(P)
print "L:"
pprint.pprint(L)
print "U:"
pprint.pprint(U)
代码的输出如下:
A:
array([[ 7, 3, -1, 2],
[ 3, 8, 1, -4],
[-1, 1, 4, -1],
[ 2, -4, -1, 6]])
P:
array([[ 1., 0., 0., 0.],
[ 0., 1., 0., 0.],
[ 0., 0., 1., 0.],
[ 0., 0., 0., 1.]])
L:
array([[ 1. , 0. , 0. , 0. ],
[ 0.42857143, 1. , 0. , 0. ],
[-0.14285714, 0.21276596, 1. , 0. ],
[ 0.28571429, -0.72340426, 0.08982036, 1. ]])
U:
array([[ 7. , 3. , -1. , 2. ],
[ 0. , 6.71428571, 1.42857143, -4.85714286],
[ 0. , 0. , 3.55319149, 0.31914894],
[ 0. , 0. , 0. , 1.88622754]])
关于python - 求解平方奇异系统?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46421252/