SHARE
TWEET

Untitled

a guest Nov 10th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def main():
  2.     print("Insert the dimension of matrix")
  3.     n = int(input())
  4.    
  5.     print("\nType of input\n")
  6.     print("\t1 - File\n\t2 - Use formula")
  7.     typ = int(input())
  8.    
  9.     A = np.zeros(shape=(n, n), dtype=np.float64)
  10.     b = np.zeros(shape=(n, 1), dtype=np.float64)
  11.     if typ == 1:
  12.         print("\nEnter filename\n")
  13.         filename = input()
  14.         with open(filename) as f:
  15.             for i in range(n):
  16.                 line = list(f.readline().split())
  17.                 for j, elem in enumerate(line[:n]):
  18.                     A[i][j] = np.float64(elem)
  19.                 b[i][0] = np.float64(line[n])
  20.     elif typ == 2:
  21.         print("\nEnter parametr m\n")
  22.         m = np.float64(input())
  23.         for i in range(n):
  24.             for j in range(n):
  25.                 if i == j:
  26.                     A[i][j] = n + m ** 2 + j / m + i / n
  27.                 else:
  28.                     A[i][j] = (i + j) / (m + n)
  29.             b[i][0] = 200 + 50 * i
  30.     print(A)
  31.     print(b)
  32.     print("\nChoose operation\n")
  33.     print("\t1 - Find determinant\n\t2 - Find reverse matrix\n" +
  34.            "\t3 - Find Gauss solution\n\t4 - Find Gauss solution with main element\n" +
  35.            "\t5 - Find condition number")
  36.     operation = int(input())
  37.     for operation in range(1, 6):
  38.         if operation == 1:
  39.             print("detrminate = {0}".format(determinate(A))
  40.         if operation == 2:
  41.             print("reverse(A) = {0}".format(reverse(A)))
  42.         if operation == 3:
  43.             print("X = {0}".format(gauss(A, b)))
  44.         if operation == 4:
  45.             print("X = {0}".format(gauss_main_elem(A, b)))
  46.         if operation == 5:
  47.             print("cond = {0}".format(cond(A)))
  48.         print("check: {0}\n".format(check(A, b, operation)))
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