Skip to content

Commit 38d64a9

Browse files
authored
Rename parameters in Gauss-Seidel method
1 parent 2063129 commit 38d64a9

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

maths/numerical_analysis/gauss_seidel_method.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
def gauss_seidel(
2-
a: list[list[float]], b: list[float], tol: float = 1e-10, max_iter: int = 1000
2+
coefficients: list[list[float]], rhs: list[float], tol: float = 1e-10, max_iter: int = 1000
33
) -> list[float]:
44
"""
55
Solve the linear system Ax = b using the Gauss-Seidel iterative method.
66
77
Args:
8-
a (list[list[float]]): Coefficient matrix (n x n)
9-
b (list[float]): Right-hand side vector (n)
8+
coefficients (list[list[float]]): Coefficient matrix (n x n) representing A
9+
rhs (list[float]): Right-hand side vector (n) representing b
1010
tol (float): Convergence tolerance
1111
max_iter (int): Maximum number of iterations
1212
@@ -21,14 +21,14 @@ def gauss_seidel(
2121
2222
Wikipedia : https://en.wikipedia.org/wiki/Gauss%E2%80%93Seidel_method
2323
"""
24-
n = len(a)
24+
n = len(coefficients)
2525
x = [0.0] * n
2626
for _ in range(max_iter):
2727
x_new = x.copy()
2828
for i in range(n):
29-
s1 = sum(a[i][j] * x_new[j] for j in range(i))
30-
s2 = sum(a[i][j] * x[j] for j in range(i + 1, n))
31-
x_new[i] = (b[i] - s1 - s2) / a[i][i]
29+
s1 = sum(coefficients[i][j] * x_new[j] for j in range(i))
30+
s2 = sum(coefficients[i][j] * x[j] for j in range(i + 1, n))
31+
x_new[i] = (rhs[i] - s1 - s2) / coefficients[i][i]
3232
if all(abs(x_new[i] - x[i]) < tol for i in range(n)):
3333
return x_new
3434
x = x_new

0 commit comments

Comments
 (0)