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_herm_solve_ilu (f11jq)

## Purpose

nag_sparse_complex_herm_solve_ilu (f11jq) solves a complex sparse Hermitian system of linear equations, represented in symmetric coordinate storage format, using a conjugate gradient or Lanczos method, with incomplete Cholesky preconditioning.

## Syntax

[x, rnorm, itn, ifail] = f11jq(method, nnz, a, irow, icol, ipiv, istr, b, tol, maxitn, x, 'n', n, 'la', la)
[x, rnorm, itn, ifail] = nag_sparse_complex_herm_solve_ilu(method, nnz, a, irow, icol, ipiv, istr, b, tol, maxitn, x, 'n', n, 'la', la)

## Description

nag_sparse_complex_herm_solve_ilu (f11jq) solves a complex sparse Hermitian linear system of equations
 Ax = b, $Ax=b,$
using a preconditioned conjugate gradient method (see Meijerink and Van der Vorst (1977)), or a preconditioned Lanczos method based on the algorithm SYMMLQ (see Paige and Saunders (1975)). The conjugate gradient method is more efficient if A$A$ is positive definite, but may fail to converge for indefinite matrices. In this case the Lanczos method should be used instead. For further details see Barrett et al. (1994).
nag_sparse_complex_herm_solve_ilu (f11jq) uses the incomplete Cholesky factorization determined by nag_sparse_complex_herm_precon_ilu (f11jn) as the preconditioning matrix. A call to nag_sparse_complex_herm_solve_ilu (f11jq) must always be preceded by a call to nag_sparse_complex_herm_precon_ilu (f11jn). Alternative preconditioners for the same storage scheme are available by calling nag_sparse_complex_herm_solve_jacssor (f11js).
The matrix A$A$ and the preconditioning matrix M$M$ are represented in symmetric coordinate storage (SCS) format (see Section [Symmetric coordinate storage (SCS) format] in the F11 Chapter Introduction) in the arrays a, irow and icol, as returned from nag_sparse_complex_herm_precon_ilu (f11jn). The array a holds the nonzero entries in the lower triangular parts of these matrices, while irow and icol hold the corresponding row and column indices.

## References

Barrett R, Berry M, Chan T F, Demmel J, Donato J, Dongarra J, Eijkhout V, Pozo R, Romine C and Van der Vorst H (1994) Templates for the Solution of Linear Systems: Building Blocks for Iterative Methods SIAM, Philadelphia
Meijerink J and Van der Vorst H (1977) An iterative solution method for linear systems of which the coefficient matrix is a symmetric M-matrix Math. Comput. 31 148–162
Paige C C and Saunders M A (1975) Solution of sparse indefinite systems of linear equations SIAM J. Numer. Anal. 12 617–629

## Parameters

### Compulsory Input Parameters

1:     method – string
Specifies the iterative method to be used.
method = 'CG'${\mathbf{method}}=\text{'CG'}$
method = 'SYMMLQ'${\mathbf{method}}=\text{'SYMMLQ'}$
Lanczos method (SYMMLQ).
Constraint: method = 'CG'${\mathbf{method}}=\text{'CG'}$ or 'SYMMLQ'$\text{'SYMMLQ'}$.
2:     nnz – int64int32nag_int scalar
The number of nonzero elements in the lower triangular part of the matrix A$A$. This must be the same value as was supplied in the preceding call to nag_sparse_complex_herm_precon_ilu (f11jn).
Constraint: 1nnzn × (n + 1) / 2$1\le {\mathbf{nnz}}\le {\mathbf{n}}×\left({\mathbf{n}}+1\right)/2$.
3:     a(la) – complex array
la, the dimension of the array, must satisfy the constraint la2 × nnz${\mathbf{la}}\ge 2×{\mathbf{nnz}}$.
The values returned in the array a by a previous call to nag_sparse_complex_herm_precon_ilu (f11jn).
4:     irow(la) – int64int32nag_int array
5:     icol(la) – int64int32nag_int array
6:     ipiv(n) – int64int32nag_int array
7:     istr(n + 1${\mathbf{n}}+1$) – int64int32nag_int array
la, the dimension of the array, must satisfy the constraint la2 × nnz${\mathbf{la}}\ge 2×{\mathbf{nnz}}$.
The values returned in arrays irow, icol, ipiv and istr by a previous call to nag_sparse_complex_herm_precon_ilu (f11jn).
8:     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$.
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 ipiv, b, x. (An error is raised if these dimensions are not equal.)
n$n$, the order of the matrix A$A$. This must be the same value as was supplied in the preceding call to nag_sparse_complex_herm_precon_ilu (f11jn).
Constraint: n1${\mathbf{n}}\ge 1$.
2:     la – int64int32nag_int scalar
Default: The dimension of the arrays a, irow, icol. (An error is raised if these dimensions are not equal.)
The dimension of the arrays a, irow and icol as declared in the (sub)program from which nag_sparse_complex_herm_solve_ilu (f11jq) is called. This must be the same value as was supplied in the preceding call to nag_sparse_complex_herm_precon_ilu (f11jn).
Constraint: la2 × nnz${\mathbf{la}}\ge 2×{\mathbf{nnz}}$.

work lwork

### 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 ≠ 'CG'${\mathbf{method}}\ne \text{'CG'}$ or 'SYMMLQ'$\text{'SYMMLQ'}$, or n < 1${\mathbf{n}}<1$, or nnz < 1${\mathbf{nnz}}<1$, or nnz > n × (n + 1) / 2${\mathbf{nnz}}>{\mathbf{n}}×\left({\mathbf{n}}+1\right)/2$, or la too small, or tol ≥ 1.0${\mathbf{tol}}\ge 1.0$, or maxitn < 1${\mathbf{maxitn}}<1$, or lwork too small.
ifail = 2${\mathbf{ifail}}=2$
On entry, the SCS representation of A$A$ is invalid. Further details are given in the error message. Check that the call to nag_sparse_complex_herm_solve_ilu (f11jq) has been preceded by a valid call to nag_sparse_complex_herm_precon_ilu (f11jn), and that the arrays a, irow, and icol have not been corrupted between the two calls.
ifail = 3${\mathbf{ifail}}=3$
On entry, the SCS representation of M$M$ is invalid. Further details are given in the error message. Check that the call to nag_sparse_complex_herm_solve_ilu (f11jq) has been preceded by a valid call to nag_sparse_complex_herm_precon_ilu (f11jn), and that the arrays a, irow, icol, ipiv and istr have not been corrupted between the two calls.
W ifail = 4${\mathbf{ifail}}=4$
The required accuracy could not be obtained. However, a reasonable accuracy has been obtained and further iterations could not improve the result.
ifail = 5${\mathbf{ifail}}=5$
Required accuracy not obtained in maxitn iterations.
ifail = 6${\mathbf{ifail}}=6$
The preconditioner appears not to be positive definite.
ifail = 7${\mathbf{ifail}}=7$
The matrix of the coefficients appears not to be positive definite (conjugate gradient method only).
ifail = 8${\mathbf{ifail}}=8$
A serious error has occurred in an internal call to an auxiliary function. 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_herm_solve_ilu (f11jq) for each iteration is roughly proportional to the value of nnzc returned from the preceding call to nag_sparse_complex_herm_precon_ilu (f11jn). One iteration with the Lanczos method (SYMMLQ) requires a slightly larger number of operations than one iteration with the conjugate gradient method.
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 matrix of the coefficients A = M1A$\stackrel{-}{A}={M}^{-1}A$.

## Example

```function nag_sparse_complex_herm_solve_ilu_example
nz = int64(23);
a = zeros(3*nz, 1);
a(1:nz) = [6 + 0i; -1 + 1i; 6 + 0i; 0 + 1i; 5 + 0i; 5 + 0i; 2 - 2i; ...
4 + 0i; 1 + 1i; 2 + 0i; 6 + 0i; -4 + 3i; 0 + 1i; -1 + 0i; ...
6 + 0i; -1 - 1i; 0 - 1i; 9 + 0i; 1 + 3i; 1 + 2i; -1 + 0i; ...
1 + 4i; 9 + 0i];
irow = zeros(3*nz, 1, 'int64');
irow(1:nz) = [int64(1); 2; 2; 3; 3; 4; 5; 5; 6; 6; 6; 7; 7; 7; 7; 8; 8; 8; ...
9; 9; 9; 9; 9];
icol = zeros(3*nz, 1, 'int64');
icol(1:nz) = [int64(1); 1; 2; 2; 3; 4; 1; 5; 3; 4; 6; 2; 5; 6; 7; 4; 6; 8; ...
1; 5; 6; 8; 9];
ipiv = zeros(9, 1, 'int64');
b = [  8 + 54i;
-10 - 92i;
25 + 27i;
26 - 28i;
54 + 12i;
26 - 22i;
47 + 65i;
71 - 57i;
60 + 70i];
method = 'CG';
lfill = int64(0);
dtol = 0;
mic = 'N';
dscale = 0;
pstrat = 'N';
tol = 1e-06;
maxitn = int64(100);
x = complex(zeros(9, 1));
% Calculate incomplete Cholesky factorization
[a, irow, icol, ipiv, istr, nnzc, npivm, ifail] = ...
nag_sparse_complex_herm_precon_ilu(nz, a, irow, icol, lfill, dtol, mic, ...
dscale, ipiv);

% Solve Ax = b
[x, rnorm, itn, ifail] = ...
nag_sparse_complex_herm_solve_ilu(method, nz, a, irow, icol, ipiv, ...
istr, b, tol, maxitn, x)
```
```

x =

1.0000 + 9.0000i
2.0000 - 8.0000i
3.0000 + 7.0000i
4.0000 - 6.0000i
5.0000 + 5.0000i
6.0000 - 4.0000i
7.0000 + 3.0000i
8.0000 - 2.0000i
9.0000 + 1.0000i

rnorm =

3.1086e-14

itn =

5

ifail =

0

```
```function f11jq_example
nz = int64(23);
a = zeros(3*nz, 1);
a(1:nz) = [6 + 0i; -1 + 1i; 6 + 0i; 0 + 1i; 5 + 0i; 5 + 0i; 2 - 2i; ...
4 + 0i; 1 + 1i; 2 + 0i; 6 + 0i; -4 + 3i; 0 + 1i; -1 + 0i; ...
6 + 0i; -1 - 1i; 0 - 1i; 9 + 0i; 1 + 3i; 1 + 2i; -1 + 0i; ...
1 + 4i; 9 + 0i];
irow = zeros(3*nz, 1, 'int64');
irow(1:nz) = [int64(1); 2; 2; 3; 3; 4; 5; 5; 6; 6; 6; 7; 7; 7; 7; 8; 8; 8; ...
9; 9; 9; 9; 9];
icol = zeros(3*nz, 1, 'int64');
icol(1:nz) = [int64(1); 1; 2; 2; 3; 4; 1; 5; 3; 4; 6; 2; 5; 6; 7; 4; 6; 8; ...
1; 5; 6; 8; 9];
ipiv = zeros(9, 1, 'int64');
b = [ 8 + 54i;
-10 - 92i;
25 + 27i;
26 - 28i;
54 + 12i;
26 - 22i;
47 + 65i;
71 - 57i;
60 + 70i];
method = 'CG';
lfill = int64(0);
dtol = 0;
mic = 'N';
dscale = 0;
pstrat = 'N';
tol = 1e-06;
maxitn = int64(100);
x = complex(zeros(9, 1));
% Calculate incomplete Cholesky factorization
[a, irow, icol, ipiv, istr, nnzc, npivm, ifail] = ...
f11jn(nz, a, irow, icol, lfill, dtol, mic, dscale, ipiv);

% Solve Ax = b
[x, rnorm, itn, ifail] = ...
f11jq(method, nz, a, irow, icol, ipiv, istr, b, tol, maxitn, x)
```
```

x =

1.0000 + 9.0000i
2.0000 - 8.0000i
3.0000 + 7.0000i
4.0000 - 6.0000i
5.0000 + 5.0000i
6.0000 - 4.0000i
7.0000 + 3.0000i
8.0000 - 2.0000i
9.0000 + 1.0000i

rnorm =

1.9540e-14

itn =

5

ifail =

0

```