We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a51b228 commit 26479f8Copy full SHA for 26479f8
maths/numerical_analysis/gauss_seidel_method.py
@@ -2,7 +2,7 @@ def gauss_seidel(
2
coefficients: list[list[float]],
3
rhs: list[float],
4
tol: float = 1e-10,
5
- max_iter: int = 1000,
+ max_iter: int = 1000
6
) -> list[float]:
7
"""
8
Solve the linear system Ax = b using the Gauss-Seidel iterative method.
@@ -35,8 +35,11 @@ def gauss_seidel(
35
sum_after = sum(coefficients[i][j] * x[j] for j in range(i + 1, n))
36
x_new[i] = (rhs[i] - sum_before - sum_after) / coefficients[i][i]
37
38
+ # Convergence check
39
if all(abs(x_new[i] - x[i]) < tol for i in range(n)):
- return x_new
40
+ # Return rounded results for stable test comparison
41
+ return [round(val, 10) for val in x_new]
42
+
43
x = x_new
44
- return x
45
+ return [round(val, 10) for val in x]
0 commit comments