from __future__ import division
import numpy as np
import numpy.linalg as la
A = np.array([
[3, 4, 5],
[2, 3, 1],
[9, 2, 7]
], dtype=np.float64)
A = np.array([
[1e-20, 1],
[1, 1],
])
n = A.shape[0]
elim_matrices = []
W = A
for i in xrange(n-1):
M = np.eye(n)
M[i+1:, i] = -W[i+1:, i]/W[i,i]
elim_matrices.append(M)
W = np.dot(M, W)
print "--------------------------------------"
print "column %d" % i
print "--------------------------------------"
print "elimination mat:"
print M
print "left over:"
print W
L = reduce(np.dot, [la.inv(M) for M in elim_matrices])
U = W
print "L"
print L
print "U"
print U
A_rebuilt = np.dot(L, U)
A_rebuilt
la.norm(A_rebuilt - A)
Why is this a terrible algorithm? What is its cost?