-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.2_CP1.py
More file actions
30 lines (24 loc) · 812 Bytes
/
Copy path2.2_CP1.py
File metadata and controls
30 lines (24 loc) · 812 Bytes
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
29
30
# Create a script to setup LU factorization with no row exchanges allowed. Shut down on zero pivot.
import numpy as np
def gausselim(A, identityM):
# Shape of the matrix in question (3, 4) in our question.
(n, m) = np.shape(A)
# Perform gaussian elimination - algorithm borrowed from Jordan Barry
for j in range(n - 1):
for i in range(j + 1, n):
#Setup L (LU)
multiple = A[i, j] / A[j, j]
identityM[i,j] = multiple
#Gauss elim
A[i, :] = -(A[i, j] / A[j, j]) * A[j, :] + A[i, :]
return A, identityM
def main():
A = np.array([[3, 2, 1], [6, 3, 4], [3, 1, 5]])
n,m=np.shape(A)
M = np.identity(n)
U, L = gausselim(A, M)
print(U)
print("________")
print(L)
if __name__ == "__main__":
main()