CDE
This commit is contained in:
parent
518da4a923
commit
764da6cbbb
6144 changed files with 83610 additions and 11 deletions
22
Task/Cholesky-decomposition/Python/cholesky-decomposition.py
Normal file
22
Task/Cholesky-decomposition/Python/cholesky-decomposition.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import math, pprint
|
||||
|
||||
def cholesky(A):
|
||||
L = [[0.0] * len(A) for _ in xrange(len(A))]
|
||||
for i in xrange(len(A)):
|
||||
for j in xrange(i+1):
|
||||
s = sum(L[i][k] * L[j][k] for k in xrange(j))
|
||||
L[i][j] = math.sqrt(A[i][i] - s) if (i == j) else \
|
||||
(1.0 / L[j][j] * (A[i][j] - s))
|
||||
return L
|
||||
|
||||
m1 = [[25, 15, -5],
|
||||
[15, 18, 0],
|
||||
[-5, 0, 11]]
|
||||
pprint.pprint(cholesky(m1))
|
||||
print
|
||||
|
||||
m2 = [[18, 22, 54, 42],
|
||||
[22, 70, 86, 62],
|
||||
[54, 86, 174, 134],
|
||||
[42, 62, 134, 106]]
|
||||
pprint.pprint(cholesky(m2))
|
||||
Loading…
Add table
Add a link
Reference in a new issue