Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #reduction_to_canonical_form
- from drawing import ShowMatrixElement, ShowTable
- '''
- (1 2) |1 0 0
- (3 4) |0 1 0
- (5 6) |0 0 1
- '''
- def SetToCanon (A: int, N: int, M: int, more: bool) -> None:
- for i in range(M):
- for j in range(M):
- if j == i:
- A[i].append( (more-0.5000)*(-2) )
- else:
- A[i].append(0)
- ShowMatrixElement(A, -1, -1)
- '''-> (int, int)'''
- def ChooseVariables(A: list, B: list, W: list) -> (int, int):
- M = len(A) # количество уравнений/строк
- N = len(A[0]) # количество переменных/столбцов
- '''W = []
- for i in range(N):
- temp_int = 0
- for j in range(M):
- temp_int = temp_int + A[j][i]
- W.append(temp_int)'''
- #print(W) #отладка
- stolbec_number = 0
- for i in range( len(W) ):
- if W[i] < W[stolbec_number]:
- stolbec_number = i
- #print(W[stolbec_number])#отладка
- stroka_number = 0
- for i in range( len(A) ):
- if abs( B[i]/A[i][stolbec_number] ) < abs(B[stroka_number]/A[stroka_number][stolbec_number]) :
- stroka_number = i
- print(A[stroka_number][stolbec_number])#отладка
- return (stroka_number, stolbec_number)
- #def ChangeVariables(A: list, B: list, [stroka_number, stolbec_number] ):
- #def ChangeVariables(A: list, B: list, W: list, stroka_number, stolbec_number, column: list, headers: list):
- def ChangeVariables(A: list, B: list, stroka_number, stolbec_number, column: list, headers: list):
- B[stroka_number] = B[stroka_number]/A[ stroka_number ][ stolbec_number ]*-1
- for j in range( len(A[0]) ):
- if (j != stolbec_number):
- A[ stroka_number ][j] = A[ stroka_number ][j]/A[ stroka_number ][ stolbec_number ]*-1
- A[stroka_number][stolbec_number] = 1/A[ stroka_number ][ stolbec_number ]
- for i in range(len(A)):
- if i == stroka_number:
- continue
- else:
- B[i] += B[stroka_number]*A[i][stolbec_number]
- for j in range(len(A[0])):
- if j != stolbec_number:
- A[i][j] += A[i][stolbec_number]*A[stroka_number][j]
- A[i][stolbec_number] *= A[stroka_number][stolbec_number]
- column[stroka_number], headers[stolbec_number] = headers[stolbec_number], column[stroka_number]
- ShowTable(A, B, column, headers)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement