hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_sparse_real_gen_matvec (f11xa)

Purpose

nag_sparse_real_gen_matvec (f11xa) computes a matrix-vector or transposed matrix-vector product involving a real sparse nonsymmetric matrix stored in coordinate storage format.

Syntax

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

Description

nag_sparse_real_gen_matvec (f11xa) computes either the matrix-vector product y = Axy=Ax, or the transposed matrix-vector product y = ATxy=ATx, according to the value of the argument trans, where AA is an nn by nn sparse nonsymmetric matrix, of arbitrary sparsity pattern. The matrix AA is stored in coordinate storage (CS) format (see Section [Coordinate storage (CS) format] in the F11 Chapter Introduction). The array a stores all nonzero elements of AA, while arrays irow and icol store the corresponding row and column indices respectively.
It is envisaged that a common use of nag_sparse_real_gen_matvec (f11xa) will be to compute the matrix-vector product required in the application of nag_sparse_real_gen_basic_solver (f11be) to sparse linear systems. An illustration of this usage appears in Section [Example] in (f11dd).

References

None.

Parameters

Compulsory Input Parameters

1:     trans – string (length ≥ 1)
Specifies whether or not the matrix AA is transposed.
trans = 'N'trans='N'
y = Axy=Ax is computed.
trans = 'T'trans='T'
y = ATxy=ATx is computed.
Constraint: trans = 'N'trans='N' or 'T''T'.
2:     a(nnz) – double array
nnz, the dimension of the array, must satisfy the constraint 1nnzn21nnzn2.
The nonzero elements in the matrix AA, 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_real_gen_sort (f11za) 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 1nnzn21nnzn2.
The row and column indices of the nonzero elements supplied in array a.
Constraints:
irow and icol must satisfy the following constraints (which may be imposed by a call to nag_sparse_real_gen_sort (f11za)):
  • 1irow(i)n1irowin and 1icol(i)n1icolin, for i = 1,2,,nnzi=1,2,,nnz;
  • irow(i1) < irow(i)irowi-1<irowi or irow(i1) = irow(i)irowi-1=irowi and icol(i1) < icol(i)icoli-1<icoli, for i = 2,3,,nnzi=2,3,,nnz.
5:     check – string (length ≥ 1)
Specifies whether or not the CS representation of the matrix AA, values of n, nnz, irow and icol should be checked.
check = 'C'check='C'
Checks are carried on the values of n, nnz, irow and icol.
check = 'N'check='N'
None of these checks are carried out.
Constraint: check = 'C'check='C' or 'N''N'.
6:     x(n) – double array
n, the dimension of the array, must satisfy the constraint n1n1.
The vector xx.

Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the array x.
nn, the order of the matrix AA.
Constraint: n1n1.
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 AA.
Constraint: 1nnzn21nnzn2.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     y(n) – double array
The vector yy.
2:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
On entry,trans'N'trans'N' or 'T''T',
orcheck'C'check'C' or 'N''N'.
  ifail = 2ifail=2
On entry,n < 1n<1,
ornnz < 1nnz<1,
ornnz > n2nnz>n2.
  ifail = 3ifail=3
On entry, the arrays irow and icol fail to satisfy the following constraints:
  • 1irow(i)n1irowin and 1icol(i)n1icolin, for i = 1,2,,nnzi=1,2,,nnz;
  • irow(i1) < irow(i)irowi-1<irowi, or irow(i1) = irow(i)irowi-1=irowi and icol(i1) < icol(i)icoli-1<icoli, for i = 2,3,,nnzi=2,3,,nnz.
Therefore a nonzero element has been supplied which does not lie within the matrix AA, is out of order, or has duplicate row and column indices. Call nag_sparse_real_gen_sort (f11za) to reorder and sum or remove duplicates.

Accuracy

The computed vector yy satisfies the error bound: where c(n)c(n) is a modest linear function of nn, and εε is the machine precision

Further Comments

Timing

The time taken for a call to nag_sparse_real_gen_matvec (f11xa) is proportional to nnz.

Use of check

It is expected that a common use of nag_sparse_real_gen_matvec (f11xa) will be to compute the matrix-vector product required in the application of nag_sparse_real_gen_basic_solver (f11be) to sparse linear systems. In this situation nag_sparse_real_gen_matvec (f11xa) is likely to be called many times with the same matrix AA. In the interests of both reliability and efficiency you are recommended to set check = 'C'check='C' for the first of such calls, and to set check = 'N'check='N' for all subsequent calls.

Example

function nag_sparse_real_gen_matvec_example
a = [2; 1; 1; -1; 4; 1; 1; 1; 2; -2; 3];
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];
check = 'C';
x = [0.7; 0.16; 0.52; 0.77; 0.28];

% Calculate matrix-vector product
trans = 'N';
[y, ifail] = nag_sparse_real_gen_matvec(trans, a, irow, icol, check, x);
fprintf('\nMatrix-vector product:\n');
disp(y);

% Calculate transposed matrix-vector product
trans = 'T';
[y, ifail] = nag_sparse_real_gen_matvec(trans, a, irow, icol, check, x);
fprintf('Transposed matrix-vector product:\n');
disp(y);
 

Matrix-vector product:
    1.5600
   -0.2500
    3.6000
    1.3300
    0.5200

Transposed matrix-vector product:
    3.4800
    0.1400
    0.6800
    0.6100
    2.9000


function f11xa_example
a = [2; 1; 1; -1; 4; 1; 1; 1; 2; -2; 3];
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];
check = 'C';
x = [0.7; 0.16; 0.52; 0.77; 0.28];

% Calculate matrix-vector product
trans = 'N';
[y, ifail] = f11xa(trans, a, irow, icol, check, x);
fprintf('\nMatrix-vector product:\n');
disp(y);

% Calculate transposed matrix-vector product
trans = 'T';
[y, ifail] = f11xa(trans, a, irow, icol, check, x);
fprintf('Transposed matrix-vector product:\n');
disp(y);
 

Matrix-vector product:
    1.5600
   -0.2500
    3.6000
    1.3300
    0.5200

Transposed matrix-vector product:
    3.4800
    0.1400
    0.6800
    0.6100
    2.9000



PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013