svinoviteran

gaus1

May 21st, 2019
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. import numpy as np
  2. A = np.array([[2.69, 2.47, 2.07],
  3.     [2.73, 2.39, 1.92],
  4.     [2.93, 2.52, 2.02]])
  5. b = np.array([[19.37], [19.43], [20.8]])
  6.  
  7. def Gaus(A, b):
  8.     n = A.shape[0]
  9.     for i in range(n):
  10.         b[i] /= A[i][i]
  11.         A[i] /= A[i][i]
  12.         for j in range(i + 1, n):
  13.             b[j] -= A[j][i] * b[i]
  14.             A[j] -= A[j][i] * A[i]
  15.  
  16.     for i in range(n - 1, -1, -1):
  17.         for j in range(i - 1, -1, -1):
  18.             b[j] -= b[i] * A[j][i]
  19.     return b
  20. ans = Gaus(A.copy(), b.copy())
  21. print(ans)
Advertisement
Add Comment
Please, Sign In to add comment