XLPack 7.0
XLPack Numerical Library (C API) Reference Manual
Loading...
Searching...
No Matches

◆ sor()

void sor ( int  n,
void(*)(int, const double[], double[])  matvec,
void(*)(int, const double[], double[])  matsol,
void(*)(int, const double[], double, int, int *)  chkconv,
const double  b[],
double  x[],
int  maxiter,
int *  iter,
double *  res,
int  lwork,
double  work[],
int *  info 
)

Solution of linear system Ax = b using successive over-relaxation (SOR) method

Purpose
This routine solves the linear system Ax = b using successive over-relaxation (SOR) iterative method.
Parameters
[in]nDimension of the matrix. (n >= 0) (If n = 0, returns without computation)
[in]matvecUser supplied subroutine which calculates the matrix and vector product as follows.
void matvec(int n, const double x[], double y[])
{
Compute A*x, and return result in y[].
}
[in]matsolThis routine computes (D/ω + L)^(-1)*b using diagonal and lower tridiagonal parts of matrix A as follows.
void matsol(int n, const double b[], double x[])
{
Compute x = (D/ω + L)^(-1)*b (or solve (D/ω + L)*x = b) and return solution in x.
}
where ω(0 < ω < 2) is the relaxation parameter of SOR method. L and D are the lower triangular part and the diagonal part of the matrix A, respectively.
[in]chkconvUser supplied subroutine which is called on every iteration for the convergence test as follows, where x[] is the current approximate solution, res is the current residual norm norm(b - A*x), and iter is the current number of iterations. This routine can also be used to output the intermediate results.
void chkconv(int n, const double x[], double res, int iter, int *ichk)
{
Set *ichk = 1 if converged. Otherwise, set *ichk = 0.
}
[in]b[]Array b[lb] (lb >= n)
Right hand side vector b.
[in,out]x[]Array x[lx] (lx >= n)
[in] Initial guess of solution.
[out] Obtained approximate solution.
[in]maxiterMaximum number of iterations. (maxiter > 0)
[out]iterFinal number of iterations.
[out]resFinal residual norm norm(b - A*x).
[in]lworkSize of array work[]. (lwork >= 3*n)
[out]work[]Array work[lwork]
Work array.
[out]info= 0: Successful exit.
< 0: The (-info)-th argument is invalid.
= 11: Maximum number of iterations exceeded.