This project implements the Successive Over-Relaxation (SOR) method for solving systems of linear equations of the form
for the
- ω
$∈ (0,2)$ is the relaxation parameter, -
$k$ is the iteration count, -
$a_{ij}$ are elements of the matrix$A$
The relaxation parameter 𝜔 determines the speed of convergence:
- 𝜔
$= 1$ : equivalent to the Gauss-Seidel method - 𝜔
$< 1$ : under-relaxation - 𝜔
$> 1$ : over-relaxation (faster convergence in many cases)
Input format
The program expects input in the following format:
-
$N$ (size of the matrix) and$M$ (number of nonzero bands above or below the diagonal) -
$M$ lines representing the banded structure of matrix$A$ -
$N$ elements of the diagonal od$A$ -
$N$ elements of the right-hand side vector -
$N$ elements of the initial guess vector$x(0)$ - relaxation parameter 𝜔 and the number of iterations
$L$
Example input:
10
1
1 -1 2 1 3 -1 1 2 2
8 9 10 9 8 5 10 9 7 5
7 -8 5 -7 3 -5 7 -5 4 -3
2 1 2 1 2 1 2 1 2 1
1.3
5
Expected output:
9.9940568551471820e-01
-9.0904662229329669e-01
6.0991796223201045e-01
-1.0130102944878934e+00
1.0831324689900357e+00
-1.5137961825745920e+00
6.1540772283026224e-01
-8.7787343355916414e-01
1.1233322463475970e+00
-1.0523066239504728e+00