daily pastebin goal
86%
SHARE
TWEET

Untitled

a guest Sep 24th, 2018 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import numpy as np
  2.  
  3. A = np.array([[3.0,-0.1,-0.2],[0.1,7.0,-0.3],[0.3,-0.2,10.2]])
  4.  
  5. B = np.array([[7.85],[-19.3],[71.4]])
  6.  
  7.  
  8. ##########################################################################################
  9. aMat = np.hstack([A, B]) # combine matrix A and B to create augmented matrix
  10.  
  11. nRows = len(aMat[:,0]) # get how many rows
  12. nCols = len(aMat[0,:]) # get how many columns
  13.  
  14. #print 'Augmented Matrix'
  15. #print aMat
  16. #print '*****************************************************************************'
  17.  
  18. # forward elimination
  19.  
  20. #Matrix in Python [row,col]
  21.  
  22. #1) keep row0
  23. #2) from row1 ; calculate scale factor c= aMat[1,0]/aMat[0,0]
  24. #3) find new row1 ; row1_new = row1 - c*row0
  25.  
  26. #4) from row2 ; calculate scale factor c=aMat[2,0]/aMat[0,0]
  27. #5) find new row2 ; row2_new = row2 - c*row0
  28.  
  29. #Repeat step in row1 and row2
  30.  
  31.  
  32. for row in range(1,3):
  33.     c = aMat[row,0]/aMat[0,0]
  34.    
  35.     for col in range(4):
  36.         aMat[row,col] =  aMat[row,col]-(aMat[0,col]*c)
  37. print "Step1: "
  38. print aMat
  39.  
  40. #Step2
  41.  
  42. for row in range(2,3):
  43.     c = aMat[row,1]/aMat[1,1]
  44.    
  45.     for col in range(4):
  46.         aMat[row,col] =  aMat[row,col]-(aMat[1,col]*c)
  47. print "Step2: "
  48. print aMat
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top