-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindL.py
28 lines (23 loc) · 832 Bytes
/
FindL.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import numpy as np
def gauss_transformation(matrix):
n = len(matrix)
gauss_matrix = np.identity(n)
for i in range(n):
for j in range(i+1, n):
if matrix[i][i] == 0:
return None # Gauss elimination cannot proceed if diagonal element is zero
ratio = matrix[j][i] / matrix[i][i]
for k in range(n):
matrix[j][k] -= ratio * matrix[i][k]
gauss_matrix[j][k] -= ratio * gauss_matrix[i][k]
return gauss_matrix
# Input matrix here:
matrix = [[1, 2, 1],
[3, 8, 1],
[0, 4, 1]]
gauss_matrix = gauss_transformation(matrix)
if gauss_matrix is not None:
print("Gauss Transformation Matrix:")
print(gauss_matrix)
else:
print("Gauss elimination cannot be applied because a diagonal element is zero.")