In this notebook, you will implement the alternative Gauss Jordan algorithm that overwrites $ A $ in one sweep with the identity matrix and $ B $ with the inverse of the original matrix $ A $.
Be sure to make a copy!!!!
import numpy as np
import laff
import flame
L = np.matrix( ' 1, 0, 0. 0;\
-2, 1, 0, 0;\
1,-3, 1, 0;\
2, 3,-1, 1' )
U = np.matrix( ' 2,-1, 3,-2;\
0,-2, 1,-1;\
0, 0, 1, 2;\
0, 0, 0, 3' )
A = L * U
Aold = np.matrix( np.copy( A ) )
B = np.matrix( np.eye( 4 ) )
print( 'A = ' )
print( A )
print( 'B = ' )
print( B )
Here is the algorithm:
Important: if you make a mistake, rerun ALL cells above the cell in which you were working, and then the one where you are working.
Create the routine
GJ_Inverse_alt
with the Spark webpage for the algorithm
# insert code here
Important: if you make a mistake, rerun ALL cells above the cell in which you were working, and then the one where you are working.
GJ_Inverse_alt( A, B )
print( A )
print( B )
Matrix $ A $ should now be an identity matrix and $ B $ should no longer be an identity matrix.
Check if $ B $ now equals (approximately) the inverse of the original matrix $ A $:
print( Aold * B )