from __future__ import division
import numpy as np
import scipy.linalg as la
n = 5
A = np.random.randn(n, n)
u = np.random.randn(n)
v = np.random.randn(n)
b = np.random.randn(n)
Ahat = A + np.outer(u, v)
LU, piv = la.lu_factor(A)
print LU
print piv
def solveA(b):
return la.lu_solve((LU, piv), b)
la.norm(np.dot(A, solveA(b)) - b)
\[(A+uv^T)^{-1} = A^{-1} - {A^{-1}uv^T A^{-1} \over 1 + v^T A^{-1}u}\]
xhat = la.solve(Ahat, b)
xhat2 = ...
print la.norm(xhat - xhat2)
(Edit this cell to see solution.)
What's the cost of the Sherman-Morrison procedure?