-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLUlowerhess.py
More file actions
19 lines (16 loc) · 800 Bytes
/
LUlowerhess.py
File metadata and controls
19 lines (16 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import numpy as np
def LUlowerhess(A):
n = len(A)
for i in range(0,n-1):
for j in range(i+1,n):
A[j][i] = A[j][i] / A[i][i]
A[j][i+1] -= A[j][i] * A[i][i+1]
print(A)
return(A)
matA = np.array([[1,2,0],[3,4,7],[6,5,9]],dtype=float) #example input
LUlowerhess(matA)
#Example output: matA = [[1, 2, 0], [[1,0,0], [[1, 2, 0],
# [3, -2, 7], represents [3,1,0], * [0, -2, 7],
# [6,3.5,-15.5]] [6,3.5,1]] [0,0,-15.5]]
# With LU = matA, L would be the unit lower triangular matrix(numbers below diagonal, and diagonal values)
# are supposed to be 1), and U would be the upper triangular matrix, which includes the diagonal values.