# Behavior of Elimination Matrices¶

In :
import numpy as np

In :
n = 4


Let's create some elimination matrices:

In :
M1 = np.eye(n)
M1[1,0] = 0.5
M1

Out:
array([[ 1. ,  0. ,  0. ,  0. ],
[ 0.5,  1. ,  0. ,  0. ],
[ 0. ,  0. ,  1. ,  0. ],
[ 0. ,  0. ,  0. ,  1. ]])
In :
M2 = np.eye(n)
M2[3,0] = 4
M2

Out:
array([[ 1.,  0.,  0.,  0.],
[ 0.,  1.,  0.,  0.],
[ 0.,  0.,  1.,  0.],
[ 4.,  0.,  0.,  1.]])
In :
M3 = np.eye(n)
M3[2,1] = 1.3
M3

Out:
array([[ 1. ,  0. ,  0. ,  0. ],
[ 0. ,  1. ,  0. ,  0. ],
[ 0. ,  1.3,  1. ,  0. ],
[ 0. ,  0. ,  0. ,  1. ]])

Now play around with them:

In :
M1.dot(M2)

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

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

Out:
array([[ 1. ,  0. ,  0. ,  0. ],
[ 0.5,  1. ,  0. ,  0. ],
[ 0. ,  1.3,  1. ,  0. ],
[ 4. ,  0. ,  0. ,  1. ]])

BUT:

In :
M3.dot(M1).dot(M2)

Out:
array([[ 1.  ,  0.  ,  0.  ,  0.  ],
[ 0.5 ,  1.  ,  0.  ,  0.  ],
[ 0.65,  1.3 ,  1.  ,  0.  ],
[ 4.  ,  0.  ,  0.  ,  1.  ]])