Update numethods/solvers.py

This commit is contained in:
2025-09-16 11:17:49 +03:00
parent 0c5af0d46e
commit fd7cce037e

View File

@@ -64,7 +64,7 @@ class LUDecomposition:
class GaussJordan: class GaussJordan:
"""GaussJordan elimination.""" """Gauss-Jordan elimination."""
def __init__(self, A: Matrix): def __init__(self, A: Matrix):
if not A.is_square(): if not A.is_square():
@@ -95,7 +95,7 @@ class GaussJordan:
return Vector(row[-1] for row in Ab.data) return Vector(row[-1] for row in Ab.data)
def trace(self): def trace(self):
print("GaussJordan Trace (row reduction steps)") print("Gauss-Jordan Trace (row reduction steps)")
for step, Ab in self.steps: for step, Ab in self.steps:
print(f"\nColumn {step}:") print(f"\nColumn {step}:")
print(f"Augmented matrix = {Ab}") print(f"Augmented matrix = {Ab}")
@@ -146,7 +146,7 @@ class Jacobi:
class GaussSeidel: class GaussSeidel:
"""GaussSeidel iterative method for Ax = b.""" """Gauss-Seidel iterative method for Ax = b."""
def __init__( def __init__(
self, A: Matrix, b: Vector, tol: float = 1e-10, max_iter: int = 10_000 self, A: Matrix, b: Vector, tol: float = 1e-10, max_iter: int = 10_000
@@ -181,7 +181,7 @@ class GaussSeidel:
raise ConvergenceError("Gauss-Seidel did not converge within max_iter") raise ConvergenceError("Gauss-Seidel did not converge within max_iter")
def trace(self): def trace(self):
print("GaussSeidel Iteration Trace") print("Gauss-Seidel Iteration Trace")
print(f"{'iter':>6} | {'residual norm':>14}") print(f"{'iter':>6} | {'residual norm':>14}")
print("-" * 26) print("-" * 26)
for k, res in enumerate(self.history): for k, res in enumerate(self.history):