A C++ implementation of the Successive-Over-Relaxation (SOR) method, specifically optimized for symmetric sparse banded matrices.
-
Memory Efficiency: Instead of storing a full
$NxN$ matrix$(O(N^2))$ , this solver only stores non-zero bands and the diagonal, achieving$O(N*M)$ memory complexity ($N$ - size of the matrix,$M$ - number of bands) -
Numerical Stability: Implements the SOR iterative algorithm with a configurable relaxation parameter (
$\omega$ ) to accelerate convergence. -
Banded Matrix Support: Specifically handles symmetric matrices where non-zero elements appear only within a distance
$M$ from the diagonal. - Scientific Precision: High-precision output in scientific notation.
This solver finds the solution for a system of linear equations
The Successive-Over-Relaxation (SOR) method is an iterative technique. Given a starting vector
where:
-
$\omega$ is the relaxation factor ($0 < \omega < 2$ ). - If
$\omega = 1$ , the method reduces to Gauss-Seidel method. - If
$1 < \omega < 2$ , the method is called "over-relaxation" and can significantly speed up convergence for certain systems.
.
├── include/
│ └── SORSolver.hpp # Class and method declaration
├── src/
│ ├── SORSolver.cpp # SOR algorithm implementation
│ └── main.cpp # Input/Output handling and CLI
├── data/ # Sample input/output files
├── Makefile # Build system configuration
└── README.md
This project uses make and requires a compiler that supports C++17 standard.
Build the project using the provided Makefile:
makeThe program reads data from standard input. You can pipe your data files directly:
./sor_solver < data/file1.inmake testTo remove object files and the executable:
make cleanThis solver expects the following input sequence:
-
N- size of matrix,N- number of bands above or below the diagonal -
Mlines for each band (starting from the furthest from the diagonal) - The main diagonal elements
- The right-hand side vector
$y$ - The initial guess vector
$x^{(0)}$ - The relaxation parameter
$\omega$ - The number of iterations
$L$
To demonstrate the solver, we can use the provided sample data from data/file1.in. This example represents a system with a
7 # N - matrix size
2 # M - number of bands
1 2 1 2 1 # band 2 (furthest from diagonal)
2 -1 3 1 3 -1 # band 1 (next to diagonal)
5 6 7 8 9 10 11 # main diagonal
8 9 11 16 15 14 11 # vector y
2 3 2 3 2 3 2 # initial guess vector x0
1.5 # relaxation factor
1 # number of iterations
This program outputs the solution vector
-1.0000000000e+00
2.5000000000e-01
-7.3214285714e-01
3.1808035714e-01
-2.6432291666e-01
9.2352120535e-01
6.6197874391e-01