Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- A = np.array([[3.0,-0.1,-0.2],[0.1,7.0,-0.3],[0.3,-0.2,10.2]])
- B = np.array([[7.85],[-19.3],[71.4]])
- ##########################################################################################
- aMat = np.hstack([A, B]) # combine matrix A and B to create augmented matrix
- nRows = len(aMat[:,0]) # get how many rows
- nCols = len(aMat[0,:]) # get how many columns
- #print 'Augmented Matrix'
- #print aMat
- #print '*****************************************************************************'
- # forward elimination
- #Matrix in Python [row,col]
- #1) keep row0
- #2) from row1 ; calculate scale factor c= aMat[1,0]/aMat[0,0]
- #3) find new row1 ; row1_new = row1 - c*row0
- #4) from row2 ; calculate scale factor c=aMat[2,0]/aMat[0,0]
- #5) find new row2 ; row2_new = row2 - c*row0
- #Repeat step in row1 and row2
- for row in range(1,3):
- c = aMat[row,0]/aMat[0,0]
- for col in range(4):
- aMat[row,col] = aMat[row,col]-(aMat[0,col]*c)
- print "Step1: "
- print aMat
- #Step2
- for row in range(2,3):
- c = aMat[row,1]/aMat[1,1]
- for col in range(4):
- aMat[row,col] = aMat[row,col]-(aMat[1,col]*c)
- print "Step2: "
- print aMat
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement