我試圖解決一組形式爲Ax = 0的方程組。A是已知的6x6矩陣,我用SVD編寫了下面的代碼以獲得向量x在一定程度上。答案大致正確,但不夠好對我有用,我該如何提高計算精度?將eps降至1.e-4以下會導致該功能失敗。計算矩陣的零空間
from numpy.linalg import *
from numpy import *
A = matrix([[0.624010149127497 ,0.020915658603923 ,0.838082638087629 ,62.0778180312547 ,-0.336 ,0],
[0.669649399820597 ,0.344105317421833 ,0.0543868015800246 ,49.0194290212841 ,-0.267 ,0],
[0.473153758252885 ,0.366893577716959 ,0.924972565581684 ,186.071352614705 ,-1 ,0],
[0.0759305208803158 ,0.356365401030535 ,0.126682113674883 ,175.292109352674 ,0 ,-5.201],
[0.91160934274653 ,0.32447818779582 ,0.741382053883291 ,0.11536775372698 ,0 ,-0.034],
[0.480860406786873 ,0.903499596111067 ,0.542581424762866 ,32.782593418975 ,0 ,-1]])
def null(A, eps=1e-3):
u,s,vh = svd(A,full_matrices=1,compute_uv=1)
null_space = compress(s <= eps, vh, axis=0)
return null_space.T
NS = null(A)
print "Null space equals ",NS,"\n"
print dot(A,NS)
X = 0是該問題的解決方案,但一個無趣的。真正解決問題的方法是: [0.880057009282733,0.571293018023548,0.0664250041765576,1,186.758799941964,33.7579819749057] T – Ainsworth 2010-06-07 20:50:03
你確定嗎?我在'A * x' ---'[[-0.056356 -0.055643 -7.3896e-013 -0.0043278 0.004483 -2.1316e-014]' – Jacob 2010-06-07 20:52:05
的結果中看到一些非零元素當然,除非你不想要零空間,但最小二乘解,即'min || A * x || S.T. || X || = 1' – Jacob 2010-06-07 20:53:44