Why pivoting is a good idea

In [15]:
#keep
import numpy as np
import numpy.linalg as la
In [43]:
#keep

A = np.array([
    [1e-20, 1],
    [1, 1],
])

Now find an elimination matrix and go to town:

In [44]:
#keep
U = A.copy()
In [45]:
M = np.eye(2)
M[1,0] = -A[1,0]/A[0,0]
In [46]:
#keep
U = M.dot(U)
U
Out[46]:
array([[  1.00000000e-20,   1.00000000e+00],
       [  0.00000000e+00,  -1.00000000e+20]])
In [47]:
#keep
M
Out[47]:
array([[  1.00000000e+00,   0.00000000e+00],
       [ -1.00000000e+20,   1.00000000e+00]])

Now define L:

In [48]:
L = la.inv(M)
In [49]:
L.dot(U) - A
Out[49]:
array([[ 0.,  0.],
       [ 0., -1.]])
  • Problem?
  • Is the lower right hand entry of U correct?
  • Now try with pivoting.