forked from denizdonmez/numethods
Update numethods/solvers.py
This commit is contained in:
@@ -64,7 +64,7 @@ class LUDecomposition:
|
|||||||
|
|
||||||
|
|
||||||
class GaussJordan:
|
class GaussJordan:
|
||||||
"""Gauss–Jordan 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("Gauss–Jordan 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:
|
||||||
"""Gauss–Seidel 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("Gauss–Seidel 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):
|
||||||
|
Reference in New Issue
Block a user