def qr_ls(A, b):
'''
least square using QR (A must be full column rank)
'''
m = A.shape[0]
n = A.shape[1]
if rank(A) < n:
raise Exception('Rank deficient')
A = qr_householder(A)
for j in range(n):
v = np.hstack((1, A[j+1:, j]))
A[j+1:, j] = 0
b[j:] = (np.eye(m - j + 1) - 2 * np.outer(v, v) / la.norm(v, 2)).dot(b[j:])
x_ls = la.solve(A[:n, :n], b[:n])
return x_ls
评论列表
文章目录