Behavior of Elimination Matrices

In [3]:
import numpy as np
In [30]:
n = 4

Let's create some elimination matrices:

In [40]:
M1 = np.eye(n)
M1[1,0] = 0.5
M1
Out[40]:
array([[ 1. ,  0. ,  0. ,  0. ],
       [ 0.5,  1. ,  0. ,  0. ],
       [ 0. ,  0. ,  1. ,  0. ],
       [ 0. ,  0. ,  0. ,  1. ]])
In [41]:
M2 = np.eye(n)
M2[3,0] = 4
M2
Out[41]:
array([[ 1.,  0.,  0.,  0.],
       [ 0.,  1.,  0.,  0.],
       [ 0.,  0.,  1.,  0.],
       [ 4.,  0.,  0.,  1.]])
In [42]:
M3 = np.eye(n)
M3[2,1] = 1.3
M3
Out[42]:
array([[ 1. ,  0. ,  0. ,  0. ],
       [ 0. ,  1. ,  0. ,  0. ],
       [ 0. ,  1.3,  1. ,  0. ],
       [ 0. ,  0. ,  0. ,  1. ]])

Now play around with them:

In [43]:
M1.dot(M2)
Out[43]:
array([[ 1. ,  0. ,  0. ,  0. ],
       [ 0.5,  1. ,  0. ,  0. ],
       [ 0. ,  0. ,  1. ,  0. ],
       [ 4. ,  0. ,  0. ,  1. ]])
In [44]:
M2.dot(M1)
Out[44]:
array([[ 1. ,  0. ,  0. ,  0. ],
       [ 0.5,  1. ,  0. ,  0. ],
       [ 0. ,  0. ,  1. ,  0. ],
       [ 4. ,  0. ,  0. ,  1. ]])
In [45]:
M1.dot(M2).dot(M3)
Out[45]:
array([[ 1. ,  0. ,  0. ,  0. ],
       [ 0.5,  1. ,  0. ,  0. ],
       [ 0. ,  1.3,  1. ,  0. ],
       [ 4. ,  0. ,  0. ,  1. ]])

BUT:

In [47]:
M3.dot(M1).dot(M2)
Out[47]:
array([[ 1.  ,  0.  ,  0.  ,  0.  ],
       [ 0.5 ,  1.  ,  0.  ,  0.  ],
       [ 0.65,  1.3 ,  1.  ,  0.  ],
       [ 4.  ,  0.  ,  0.  ,  1.  ]])