MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / LUDecompose

Function LUDecompose

arithmetic_analysis/lu_decomposition.py:4–24  ·  view source on GitHub ↗
(table)

Source from the content-addressed store, hash-verified

2import numpy
3
4def LUDecompose (table):
5 # Table that contains our data
6 # Table has to be a square array so we need to check first
7 rows,columns=numpy.shape(table)
8 L=numpy.zeros((rows,columns))
9 U=numpy.zeros((rows,columns))
10 if rows!=columns:
11 return []
12 for i in range (columns):
13 for j in range(i-1):
14 sum=0
15 for k in range (j-1):
16 sum+=L[i][k]*U[k][j]
17 L[i][j]=(table[i][j]-sum)/U[j][j]
18 L[i][i]=1
19 for j in range(i-1,columns):
20 sum1=0
21 for k in range(i-1):
22 sum1+=L[i][k]*U[k][j]
23 U[i][j]=table[i][j]-sum1
24 return L,U
25
26if __name__ == "__main__":
27 matrix =numpy.array([[2,-2,1],

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected