Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. # | a11 a21 . . . an1 |    | x1 |    | b1 |
  2. # |  .  .   . . .  .  |    |  . |    |  . |
  3. # |  .  .   . . .  .  | \/ |  . | -- |  . |
  4. # |  .  .   . . .  .  | /\ |  . | -- |  . |
  5. # |  .  .   . . .  .  |    |  . |    |  . |
  6. # | a1n a2n . . . ann |    | xn |    | bn |
  7.  
  8. # | a11 a21  . .    .     a'n1  |    | x1 |    | b1 |
  9. # |  0  a'22 . .    .      .    |    |  . |    |  . |
  10. # |  0   0   . .    .      .    | \/ |  . | -- |  . |
  11. # |  0   0   . .    .      .    | /\ |  . | -- |  . |
  12. # |  0   0   . . a'n-1n-1  .    |    |  . |    |  . |
  13. # |  0   0   . .    0     a'nn  |    | xn |    | bn |
  14.  
  15.  
  16. matrix = [[-1,  2,  1],
  17.           [ 1, -3, -2],
  18.           [ 3, -1, -1]]
  19.  
  20. bees = [-1, -1, 4]
  21.  
  22. n = len(matrix)
  23. for row in range(1, n):
  24.     fraction = matrix[row][0] / matrix[0][0]
  25.     bees[row] -= fraction*bees[0]
  26.     for col in range(n):
  27.         matrix[row][col] -= fraction * matrix[0][col]
  28.  
  29. print(matrix)
  30. print(bees)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement