Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_sparse_complex_gen_solve_jacssor (f11ds)

## Purpose

nag_sparse_complex_gen_solve_jacssor (f11ds) solves a complex sparse non-Hermitian system of linear equations, represented in coordinate storage format, using a restarted generalized minimal residual (RGMRES), conjugate gradient squared (CGS), stabilized bi-conjugate gradient (Bi-CGSTAB), or transpose-free quasi-minimal residual (TFQMR) method, without preconditioning, with Jacobi, or with SSOR preconditioning.

## Syntax

[x, rnorm, itn, ifail] = f11ds(method, precon, a, irow, icol, omega, b, m, tol, maxitn, x, 'n', n, 'nnz', nnz)
[x, rnorm, itn, ifail] = nag_sparse_complex_gen_solve_jacssor(method, precon, a, irow, icol, omega, b, m, tol, maxitn, x, 'n', n, 'nnz', nnz)

## Description

nag_sparse_complex_gen_solve_jacssor (f11ds) solves a complex sparse non-Hermitian system of linear equations:
 Ax = b, $Ax=b,$
using an RGMRES (see Saad and Schultz (1986)), CGS (see Sonneveld (1989)), Bi-CGSTAB($\ell$) (see Van der Vorst (1989) and Sleijpen and Fokkema (1993)), or TFQMR (see Freund and Nachtigal (1991) and Freund (1993)) method.
nag_sparse_complex_gen_solve_jacssor (f11ds) allows the following choices for the preconditioner:
• – no preconditioning;
• – Jacobi preconditioning (see Young (1971));
• – symmetric successive-over-relaxation (SSOR) preconditioning (see Young (1971)).
For incomplete LU$LU$ (ILU) preconditioning see nag_sparse_complex_gen_solve_ilu (f11dq).
The matrix A$A$ is represented in coordinate storage (CS) format (see Section [Coordinate storage (CS) format] in the F11 Chapter Introduction) in the arrays a, irow and icol. The array a holds the nonzero entries in the matrix, while irow and icol hold the corresponding row and column indices.
nag_sparse_complex_gen_solve_jacssor (f11ds) is a Black Box function which calls nag_sparse_complex_gen_basic_setup (f11br), nag_sparse_complex_gen_basic_solver (f11bs) and nag_sparse_complex_gen_basic_diag (f11bt). If you wish to use an alternative storage scheme, preconditioner, or termination criterion, or require additional diagnostic information, you should call these underlying functions directly.

## References

Freund R W (1993) A transpose-free quasi-minimal residual algorithm for non-Hermitian linear systems SIAM J. Sci. Comput. 14 470–482
Freund R W and Nachtigal N (1991) QMR: a Quasi-Minimal Residual Method for Non-Hermitian Linear Systems Numer. Math. 60 315–339
Saad Y and Schultz M (1986) GMRES: a generalized minimal residual algorithm for solving nonsymmetric linear systems SIAM J. Sci. Statist. Comput. 7 856–869
Sleijpen G L G and Fokkema D R (1993) BiCGSTAB()$\left(\ell \right)$ for linear equations involving matrices with complex spectrum ETNA 1 11–32
Sonneveld P (1989) CGS, a fast Lanczos-type solver for nonsymmetric linear systems SIAM J. Sci. Statist. Comput. 10 36–52
Van der Vorst H (1989) Bi-CGSTAB, a fast and smoothly converging variant of Bi-CG for the solution of nonsymmetric linear systems SIAM J. Sci. Statist. Comput. 13 631–644
Young D (1971) Iterative Solution of Large Linear Systems Academic Press, New York

## Parameters

### Compulsory Input Parameters

1:     method – string
Specifies the iterative method to be used.
method = 'RGMRES'${\mathbf{method}}=\text{'RGMRES'}$
Restarted generalized minimum residual method.
method = 'CGS'${\mathbf{method}}=\text{'CGS'}$
method = 'BICGSTAB'${\mathbf{method}}=\text{'BICGSTAB'}$
Bi-conjugate gradient stabilized ($\ell$) method.
method = 'TFQMR'${\mathbf{method}}=\text{'TFQMR'}$
Transpose-free quasi-minimal residual method.
Constraint: method = 'RGMRES'${\mathbf{method}}=\text{'RGMRES'}$, 'CGS'$\text{'CGS'}$, 'BICGSTAB'$\text{'BICGSTAB'}$ or 'TFQMR'$\text{'TFQMR'}$.
2:     precon – string (length ≥ 1)
Specifies the type of preconditioning to be used.
precon = 'N'${\mathbf{precon}}=\text{'N'}$
No preconditioning.
precon = 'J'${\mathbf{precon}}=\text{'J'}$
Jacobi.
precon = 'S'${\mathbf{precon}}=\text{'S'}$
Symmetric successive-over-relaxation (SSOR).
Constraint: precon = 'N'${\mathbf{precon}}=\text{'N'}$, 'J'$\text{'J'}$ or 'S'$\text{'S'}$.
3:     a(nnz) – complex array
nnz, the dimension of the array, must satisfy the constraint 1nnzn2$1\le {\mathbf{nnz}}\le {{\mathbf{n}}}^{2}$.
The nonzero elements of the matrix A$A$, ordered by increasing row index, and by increasing column index within each row. Multiple entries for the same row and column indices are not permitted. The function nag_sparse_complex_gen_sort (f11zn) may be used to order the elements in this way.
4:     irow(nnz) – int64int32nag_int array
5:     icol(nnz) – int64int32nag_int array
nnz, the dimension of the array, must satisfy the constraint 1nnzn2$1\le {\mathbf{nnz}}\le {{\mathbf{n}}}^{2}$.
The row and column indices of the nonzero elements supplied in a.
Constraints:
irow and icol must satisfy the following constraints (which may be imposed by a call to nag_sparse_complex_gen_sort (f11zn)):
• 1irow(i)n$1\le {\mathbf{irow}}\left(\mathit{i}\right)\le {\mathbf{n}}$ and 1icol(i)n$1\le {\mathbf{icol}}\left(\mathit{i}\right)\le {\mathbf{n}}$, for i = 1,2,,nnz$\mathit{i}=1,2,\dots ,{\mathbf{nnz}}$;
• either irow(i1) < irow(i)${\mathbf{irow}}\left(\mathit{i}-1\right)<{\mathbf{irow}}\left(\mathit{i}\right)$ or both irow(i1) = irow(i)${\mathbf{irow}}\left(\mathit{i}-1\right)={\mathbf{irow}}\left(\mathit{i}\right)$ and icol(i1) < icol(i)${\mathbf{icol}}\left(\mathit{i}-1\right)<{\mathbf{icol}}\left(\mathit{i}\right)$, for i = 2,3,,nnz$\mathit{i}=2,3,\dots ,{\mathbf{nnz}}$.
6:     omega – double scalar
If precon = 'S'${\mathbf{precon}}=\text{'S'}$, omega is the relaxation parameter ω$\omega$ to be used in the SSOR method. Otherwise omega need not be initialized and is not referenced.
Constraint: 0.0 < omega < 2.0$0.0<{\mathbf{omega}}<2.0$.
7:     b(n) – complex array
n, the dimension of the array, must satisfy the constraint n1${\mathbf{n}}\ge 1$.
The right-hand side vector b$b$.
8:     m – int64int32nag_int scalar
If method = 'RGMRES'${\mathbf{method}}=\text{'RGMRES'}$, m is the dimension of the restart subspace.
If method = 'BICGSTAB'${\mathbf{method}}=\text{'BICGSTAB'}$, m is the order $\ell$ of the polynomial Bi-CGSTAB method.
Otherwise, m is not referenced.
Constraints:
• if method = 'RGMRES'${\mathbf{method}}=\text{'RGMRES'}$, 0 < mmin (n,50)$0<{\mathbf{m}}\le \mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{n}},50\right)$;
• if method = 'BICGSTAB'${\mathbf{method}}=\text{'BICGSTAB'}$, 0 < mmin (n,10)$0<{\mathbf{m}}\le \mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{n}},10\right)$.
9:     tol – double scalar
The required tolerance. Let xk${x}_{k}$ denote the approximate solution at iteration k$k$, and rk${r}_{k}$ the corresponding residual. The algorithm is considered to have converged at iteration k$k$ if
 ‖rk‖∞ ≤ τ × (‖b‖∞ + ‖A‖∞‖xk‖∞). $‖rk‖∞≤τ×(‖b‖∞+‖A‖∞‖xk‖∞).$
If tol0.0${\mathbf{tol}}\le 0.0$, τ = max (sqrt(ε),sqrt(n)ε)$\tau =\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(\sqrt{\epsilon },\sqrt{n}\epsilon \right)$ is used, where ε$\epsilon$ is the machine precision. Otherwise τ = max (tol,10ε,sqrt(n)ε)$\tau =\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{tol}},10\epsilon ,\sqrt{n}\epsilon \right)$ is used.
Constraint: tol < 1.0${\mathbf{tol}}<1.0$.
10:   maxitn – int64int32nag_int scalar
The maximum number of iterations allowed.
Constraint: maxitn1${\mathbf{maxitn}}\ge 1$.
11:   x(n) – complex array
n, the dimension of the array, must satisfy the constraint n1${\mathbf{n}}\ge 1$.
An initial approximation to the solution vector x$x$.

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the arrays b, x. (An error is raised if these dimensions are not equal.)
n$n$, the order of the matrix A$A$.
Constraint: n1${\mathbf{n}}\ge 1$.
2:     nnz – int64int32nag_int scalar
Default: The dimension of the arrays a, irow, icol. (An error is raised if these dimensions are not equal.)
The number of nonzero elements in the matrix A$A$.
Constraint: 1nnzn2$1\le {\mathbf{nnz}}\le {{\mathbf{n}}}^{2}$.

work lwork iwork

### Output Parameters

1:     x(n) – complex array
An improved approximation to the solution vector x$x$.
2:     rnorm – double scalar
The final value of the residual norm rk${‖{r}_{k}‖}_{\infty }$, where k$k$ is the output value of itn.
3:     itn – int64int32nag_int scalar
The number of iterations carried out.
4:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

ifail = 1${\mathbf{ifail}}=1$
 On entry, method ≠ 'RGMRES'${\mathbf{method}}\ne \text{'RGMRES'}$, 'CGS'$\text{'CGS'}$, 'BICGSTAB'$\text{'BICGSTAB'}$ or 'TFQMR'$\text{'TFQMR'}$, or precon ≠ 'N'${\mathbf{precon}}\ne \text{'N'}$, 'J'$\text{'J'}$ or 'S'$\text{'S'}$, or n < 1${\mathbf{n}}<1$, or nnz < 1${\mathbf{nnz}}<1$, or nnz > n2${\mathbf{nnz}}>{{\mathbf{n}}}^{2}$, or precon = 'S'${\mathbf{precon}}=\text{'S'}$ and omega lies outside the interval (0.0,2.0)$\left(0.0,2.0\right)$, or m < 1${\mathbf{m}}<1$, or m > min (n,50)${\mathbf{m}}>\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{n}},50\right)$, when method = 'RGMRES'${\mathbf{method}}=\text{'RGMRES'}$, or m > min (n,10)${\mathbf{m}}>\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{n}},10\right)$, when method = 'BICGSTAB'${\mathbf{method}}=\text{'BICGSTAB'}$, or tol ≥ 1.0${\mathbf{tol}}\ge 1.0$, or maxitn < 1${\mathbf{maxitn}}<1$, or lwork is too small.
ifail = 2${\mathbf{ifail}}=2$
On entry, the arrays irow and icol fail to satisfy the following constraints:
• 1irow(i)n$1\le {\mathbf{irow}}\left(i\right)\le {\mathbf{n}}$ and 1icol(i)n$1\le {\mathbf{icol}}\left(i\right)\le {\mathbf{n}}$, for i = 1,2,,nnz$i=1,2,\dots ,{\mathbf{nnz}}$;
• irow(i1) < irow(i)${\mathbf{irow}}\left(i-1\right)<{\mathbf{irow}}\left(i\right)$, or irow(i1) = irow(i)${\mathbf{irow}}\left(i-1\right)={\mathbf{irow}}\left(i\right)$ and icol(i1) < icol(i)${\mathbf{icol}}\left(i-1\right)<{\mathbf{icol}}\left(i\right)$, for i = 2,3,,nnz$i=2,3,\dots ,{\mathbf{nnz}}$.
Therefore a nonzero element has been supplied which does not lie within the matrix A$A$, is out of order, or has duplicate row and column indices. Call nag_sparse_complex_gen_sort (f11zn) to reorder and sum or remove duplicates.
ifail = 3${\mathbf{ifail}}=3$
On entry, the matrix A$A$ has a zero diagonal element. Jacobi and SSOR preconditioners are therefore not appropriate for this problem.
W ifail = 4${\mathbf{ifail}}=4$
The required accuracy could not be obtained. However, a reasonable accuracy may have been obtained, and further iterations could not improve the result. You should check the output value of rnorm for acceptability. This error code usually implies that your problem has been fully and satisfactorily solved to within or close to the accuracy available on your system. Further iterations are unlikely to improve on this situation.
ifail = 5${\mathbf{ifail}}=5$
Required accuracy not obtained in maxitn iterations.
ifail = 6${\mathbf{ifail}}=6$
Algorithmic breakdown. A solution is returned, although it is possible that it is completely inaccurate.
ifail = 7${\mathbf{ifail}}=7$ (nag_sparse_complex_gen_basic_setup (f11br), nag_sparse_complex_gen_basic_solver (f11bs) or nag_sparse_complex_gen_basic_diag (f11bt))
A serious error has occurred in an internal call to one of the specified functions. Check all function calls and array sizes. Seek expert help.

## Accuracy

On successful termination, the final residual rk = bAxk${r}_{k}=b-A{x}_{k}$, where k = itn$k={\mathbf{itn}}$, satisfies the termination criterion
 ‖rk‖∞ ≤ τ × (‖b‖∞ + ‖A‖∞‖xk‖∞). $‖rk‖∞≤τ×(‖b‖∞+‖A‖∞‖xk‖∞).$
The value of the final residual norm is returned in rnorm.

The time taken by nag_sparse_complex_gen_solve_jacssor (f11ds) for each iteration is roughly proportional to nnz.
The number of iterations required to achieve a prescribed accuracy cannot easily be determined a priori, as it can depend dramatically on the conditioning and spectrum of the preconditioned coefficient matrix A = M1A$\stackrel{-}{A}={M}^{-1}A$, for some preconditioning matrix M$M$.

## Example

```function nag_sparse_complex_gen_solve_jacssor_example
method = 'CGS';
precon = 'N';
a = [ 2 + 3i;
1 - 1i;
-1 + 0i;
0 + 2i;
-2 + 1i;
1 + 0i;
0 - 1i;
5 + 4i;
3 - 1i;
1 + 0i;
-2 + 2i;
-3 + 1i;
0 + 3i;
4 - 2i;
-2 + 0i;
-6 + 1i];
irow = [int64(1); 1; 1; 2; 2; 2; 3; 3; 3; 3; 4; 4; 4; 5; 5; 5];
icol = [int64(1); 2; 4; 2; 3; 5; 1; 3; 4; 5; 1; 4; 5; 2; 3; 5];
omega = 1.05;
b = [ -3 + 3i;
-11 + 5i;
23 + 48i;
-41 + 2i;
-28 - 31i];
m = int64(1);
tol = 1e-10;
maxitn = int64(1000);
x = complex(zeros(5, 1));
[x, rnorm, itn, ifail] = nag_sparse_complex_gen_solve_jacssor(method, ...
precon, a, irow, icol, omega, b, m, tol, maxitn, x);

fprintf('\nConverged in %d iterations\n', itn);
fprintf('Final residual norm = %16.4e\n', rnorm);
fprintf('\n          X\n');
disp(x);
```
```

Converged in 5 iterations
Final residual norm =       1.0905e-10

X
1.0000 + 2.0000i
2.0000 + 3.0000i
3.0000 + 4.0000i
4.0000 + 5.0000i
5.0000 + 6.0000i

```
```function f11ds_example
method = 'CGS';
precon = 'N';
a = [ 2 + 3i;
1 - 1i;
-1 + 0i;
0 + 2i;
-2 + 1i;
1 + 0i;
0 - 1i;
5 + 4i;
3 - 1i;
1 + 0i;
-2 + 2i;
-3 + 1i;
0 + 3i;
4 - 2i;
-2 + 0i;
-6 + 1i];
irow = [int64(1); 1; 1; 2; 2; 2; 3; 3; 3; 3; 4; 4; 4; 5; 5; 5];
icol = [int64(1); 2; 4; 2; 3; 5; 1; 3; 4; 5; 1; 4; 5; 2; 3; 5];
omega = 1.05;
b = [ -3 + 3i;
-11 + 5i;
23 + 48i;
-41 + 2i;
-28 - 31i];
m = int64(1);
tol = 1e-10;
maxitn = int64(1000);
x = complex(zeros(5, 1));
[x, rnorm, itn, ifail] = ...
f11ds(method, precon, a, irow, icol, omega, b, m, tol, maxitn, x);

fprintf('\nConverged in %d iterations\n', itn);
fprintf('Final residual norm = %16.4e\n', rnorm);
fprintf('\n          X\n');
disp(x);
```
```

Converged in 5 iterations
Final residual norm =       1.4052e-10

X
1.0000 + 2.0000i
2.0000 + 3.0000i
3.0000 + 4.0000i
4.0000 + 5.0000i
5.0000 + 6.0000i

```