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_matvec (f11xn)

## Purpose

nag_sparse_complex_gen_matvec (f11xn) computes a matrix-vector or conjugate transposed matrix-vector product involving a complex sparse non-Hermitian matrix stored in coordinate storage format.

## Syntax

[y, ifail] = f11xn(trans, a, irow, icol, check, x, 'n', n, 'nnz', nnz)
[y, ifail] = nag_sparse_complex_gen_matvec(trans, a, irow, icol, check, x, 'n', n, 'nnz', nnz)

## Description

nag_sparse_complex_gen_matvec (f11xn) computes either the matrix-vector product y = Ax$y=Ax$, or the conjugate transposed matrix-vector product y = AHx$y={A}^{\mathrm{H}}x$, according to the value of the argument trans, where A$A$ is a complex n$n$ by n$n$ sparse non-Hermitian matrix, of arbitrary sparsity pattern. The matrix A$A$ is stored in coordinate storage (CS) format (see Section [Coordinate storage (CS) format] in the F11 Chapter Introduction). The array a stores all the nonzero elements of A$A$, while arrays irow and icol store the corresponding row and column indices respectively.
It is envisaged that a common use of nag_sparse_complex_gen_matvec (f11xn) will be to compute the matrix-vector product required in the application of nag_sparse_complex_gen_basic_solver (f11bs) to sparse complex linear systems. This is illustrated in Section [Example] in (f11dr).

None.

## Parameters

### Compulsory Input Parameters

1:     trans – string (length ≥ 1)
Specifies whether or not the matrix A$A$ is conjugate transposed.
trans = 'N'${\mathbf{trans}}=\text{'N'}$
y = Ax$y=Ax$ is computed.
trans = 'T'${\mathbf{trans}}=\text{'T'}$
y = AHx$y={A}^{\mathrm{H}}x$ is computed.
Constraint: trans = 'N'${\mathbf{trans}}=\text{'N'}$ or 'T'$\text{'T'}$.
2:     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 in 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.
3:     irow(nnz) – int64int32nag_int array
4:     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 array a.
Constraints:
• 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}}$;
• irow(i1) < irow(i)${\mathbf{irow}}\left(\mathit{i}-1\right)<{\mathbf{irow}}\left(\mathit{i}\right)$ or 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}}$.
5:     check – string (length ≥ 1)
Specifies whether or not the CS representation of the matrix A$A$, values of n, nnz, irow and icol should be checked.
check = 'C'${\mathbf{check}}=\text{'C'}$
Checks are carried on the values of n, nnz, irow and icol.
check = 'N'${\mathbf{check}}=\text{'N'}$
None of these checks are carried out.
Constraint: check = 'C'${\mathbf{check}}=\text{'C'}$ or 'N'$\text{'N'}$.
6:     x(n) – complex array
n, the dimension of the array, must satisfy the constraint n1${\mathbf{n}}\ge 1$.
The vector x$x$.

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the array x.
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}$.

None.

### Output Parameters

1:     y(n) – complex array
The vector y$y$.
2:     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:
ifail = 1${\mathbf{ifail}}=1$
 On entry, trans ≠ 'N'${\mathbf{trans}}\ne \text{'N'}$ or 'T'$\text{'T'}$, or check ≠ 'C'${\mathbf{check}}\ne \text{'C'}$ or 'N'$\text{'N'}$.
ifail = 2${\mathbf{ifail}}=2$
 On entry, n < 1${\mathbf{n}}<1$, or nnz < 1${\mathbf{nnz}}<1$, or nnz > n2${\mathbf{nnz}}>{{\mathbf{n}}}^{2}$.
ifail = 3${\mathbf{ifail}}=3$
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.

## Accuracy

The computed vector y$y$ satisfies the error bound:
• yAxc(n)εAx${‖y-Ax‖}_{\infty }\le c\left(n\right)\epsilon {‖A‖}_{\infty }{‖x‖}_{\infty }$, if trans = 'N'${\mathbf{trans}}=\text{'N'}$, or
• yAHx c(n)ε AH x${‖y-{A}^{\mathrm{H}}x‖}_{\infty }\le c\left(n\right)\epsilon {‖{A}^{\mathrm{H}}‖}_{\infty }{‖x‖}_{\infty }$, if trans = 'T'${\mathbf{trans}}=\text{'T'}$,
where c(n)$c\left(n\right)$ is a modest linear function of n$n$, and ε$\epsilon$ is the machine precision

### Timing

The time taken for a call to nag_sparse_complex_gen_matvec (f11xn) is proportional to nnz.

### Use of check

It is expected that a common use of nag_sparse_complex_gen_matvec (f11xn) will be to compute the matrix-vector product required in the application of nag_sparse_complex_gen_basic_solver (f11bs) to sparse complex linear systems. In this situation nag_sparse_complex_gen_matvec (f11xn) is likely to be called many times with the same matrix A$A$. In the interests of both reliability and efficiency you are recommended to set check = 'C'${\mathbf{check}}=\text{'C'}$ for the first of such calls, and to set check = 'N'${\mathbf{check}}=\text{'N'}$ for all subsequent calls.

## Example

```function nag_sparse_complex_gen_matvec_example
a = [ 2 + 3i;
1 - 4i;
1 + 0i;
-1 - 2i;
4 + 1i;
0 + 1i;
1 + 3i;
0 - 1i;
2 - 6i;
-2 + 0i;
3 + 1i];
irow = [int64(1);1;2;2;3;3;3;4;4;5;5];
icol = [int64(1);2;3;4;1;3;5;4;5;2;5];
x = [ 0.7 + 0.21i;
0.16 - 0.43i;
0.52 + 0.97i;
0.77 + 0i;
0.28 - 0.64i];
% Calculate matrix-vector product
trans = 'N';
check = 'C';
[y, ifail] = nag_sparse_complex_gen_matvec(trans, a, irow, icol, check, x);
fprintf('\nMatrix-vector product\n');
disp(y);

% Calculate conjugate transposed matrix-vector product
trans = 'T';
check = 'N';
[y, ifail] = nag_sparse_complex_gen_matvec(trans, a, irow, icol, check, x);
fprintf('\nConjugate transposed matrix-vector product\n');
disp(y);
```
```

Matrix-vector product
-0.7900 + 1.4500i
-0.2500 - 0.5700i
3.8200 + 2.2600i
-3.2800 - 3.7300i
1.1600 - 0.7800i

Conjugate transposed matrix-vector product
5.0800 + 1.6800i
-0.7000 + 4.2900i
1.1300 - 0.9500i
0.7000 + 1.5200i
5.1700 + 1.8300i

```
```function f11xn_example
a = [ 2 + 3i;
1 - 4i;
1 + 0i;
-1 - 2i;
4 + 1i;
0 + 1i;
1 + 3i;
0 - 1i;
2 - 6i;
-2 + 0i;
3 + 1i];
irow = [int64(1);1;2;2;3;3;3;4;4;5;5];
icol = [int64(1);2;3;4;1;3;5;4;5;2;5];
x = [ 0.7 + 0.21i;
0.16 - 0.43i;
0.52 + 0.97i;
0.77 + 0i;
0.28 - 0.64i];
% Calculate matrix-vector product
trans = 'N';
check = 'C';
[y, ifail] = f11xn(trans, a, irow, icol, check, x);
fprintf('\nMatrix-vector product\n');
disp(y);

% Calculate conjugate transposed matrix-vector product
trans = 'T';
check = 'N';
[y, ifail] = f11xn(trans, a, irow, icol, check, x);
fprintf('\nConjugate transposed matrix-vector product\n');
disp(y);
```
```

Matrix-vector product
-0.7900 + 1.4500i
-0.2500 - 0.5700i
3.8200 + 2.2600i
-3.2800 - 3.7300i
1.1600 - 0.7800i

Conjugate transposed matrix-vector product
5.0800 + 1.6800i
-0.7000 + 4.2900i
1.1300 - 0.9500i
0.7000 + 1.5200i
5.1700 + 1.8300i

```