Author: [Your Name/AI Assistant]
Date: [Current Date]
Let’s take a concrete code example. Assume we have a function that solves ( Ax = b ) using MSOR with red-black ordering.
To convert MSOR to SOR, we unify the relaxation factor and remove the branch.
def sor_solve(A, b, omega, tol=1e-6, max_iter=1000):
n = len(b)
x = np.zeros_like(b)
for _ in range(max_iter):
x_old = x.copy()
for i in range(n):
sigma = np.dot(A[i, :], x) - A[i, i] * x[i]
x[i] = (1 - omega) * x[i] + (omega / A[i, i]) * (b[i] - sigma)
if np.linalg.norm(x - x_old) < tol:
break
return x