mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-18 16:27:02 +00:00
Fixed bug with incorrect LU decomposition (#2261)
* Fixed Bug #2257 * = Co-authored-by: Svn-Sp <svn-sp@email> Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
parent
473072bd4f
commit
1495382367
|
@ -13,15 +13,15 @@ def LUDecompose(table):
|
|||
if rows != columns:
|
||||
return []
|
||||
for i in range(columns):
|
||||
for j in range(i - 1):
|
||||
for j in range(i):
|
||||
sum = 0
|
||||
for k in range(j - 1):
|
||||
for k in range(j):
|
||||
sum += L[i][k] * U[k][j]
|
||||
L[i][j] = (table[i][j] - sum) / U[j][j]
|
||||
L[i][i] = 1
|
||||
for j in range(i - 1, columns):
|
||||
for j in range(i, columns):
|
||||
sum1 = 0
|
||||
for k in range(i - 1):
|
||||
for k in range(i):
|
||||
sum1 += L[i][k] * U[k][j]
|
||||
U[i][j] = table[i][j] - sum1
|
||||
return L, U
|
||||
|
|
|
@ -27,7 +27,7 @@ def newton(function: RealFunc, derivative: RealFunc, starting_int: int,) -> floa
|
|||
...
|
||||
ZeroDivisionError: Could not find root
|
||||
"""
|
||||
prev_guess float(starting_int)
|
||||
prev_guess = float(starting_int)
|
||||
while True:
|
||||
try:
|
||||
next_guess = prev_guess - function(prev_guess) / derivative(prev_guess)
|
||||
|
|
Loading…
Reference in New Issue
Block a user