X03 Chapter Contents
X03 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentX03ABF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

X03ABF calculates the value of a complex scalar product using basic precision or additional precision and adds it to a complex initial value.

## 2  Specification

 SUBROUTINE X03ABF ( A, ISIZEA, B, ISIZEB, N, ISTEPA, ISTEPB, CX, DX, SW, IFAIL)
 INTEGER ISIZEA, ISIZEB, N, ISTEPA, ISTEPB, IFAIL COMPLEX (KIND=nag_wp) A(ISIZEA), B(ISIZEB), CX, DX LOGICAL SW

## 3  Description

X03ABF calculates the scalar product of two complex vectors and adds it to an initial value $c$ to give a correctly rounded result $d$:
 $d=c+∑i=1naibi.$
If $n<1$, $d=c$.
The vector elements ${a}_{i}$ and ${b}_{i}$ are stored in selected elements of the one-dimensional array parameters A and B, which in the subroutine from which X03ABF is called may be identified with parts of possibly multidimensional arrays according to the standard Fortran rules. For example, the vectors may be parts of a row or column of a matrix. See Section 5 for details, and Section 9 for an example.
The products are accumulated in basic precision or additional precision depending on the parameter SW.
This routine has been designed primarily for use as an auxiliary routine by other routines in the NAG Library, especially those in the chapters on Linear Algebra.

None.

## 5  Parameters

1:     A(ISIZEA) – COMPLEX (KIND=nag_wp) arrayInput
On entry: the elements of the first vector.
The $i$th vector element is stored in the array element ${\mathbf{A}}\left(\left(i-1\right)×{\mathbf{ISTEPA}}+1\right)$. In your subroutine from which X03ABF is called, A can be part of a multidimensional array and the actual argument must be the array element containing the first vector element.
2:     ISIZEA – INTEGERInput
On entry: the dimension of the array A as declared in the (sub)program from which X03ABF is called.
The upper bound for ISIZEA is found by multiplying together the dimensions of A as declared in your subroutine from which X03ABF is called, subtracting the starting position and adding $1$.
Constraint: ${\mathbf{ISIZEA}}\ge \left({\mathbf{N}}-1\right)×{\mathbf{ISTEPA}}+1$.
3:     B(ISIZEB) – COMPLEX (KIND=nag_wp) arrayInput
On entry: the elements of the second vector.
The $i$th vector element is stored in the array element ${\mathbf{B}}\left(\left(i-1\right)×{\mathbf{ISTEPB}}+1\right)$. In your subroutine from which X03ABF is called, B can be part of a multidimensional array and the actual argument must be the array element containing the first vector element.
4:     ISIZEB – INTEGERInput
On entry: the dimension of the array B as declared in the (sub)program from which X03ABF is called.
The upper bound for ISIZEB is found by multiplying together the dimensions of B as declared in your subroutine from which X03ABF is called, subtracting the starting position and adding $1$.
Constraint: ${\mathbf{ISIZEB}}\ge \left({\mathbf{N}}-1\right)×{\mathbf{ISTEPB}}+1$.
5:     N – INTEGERInput
On entry: $n$, the number of elements in the scalar product.
6:     ISTEPA – INTEGERInput
On entry: the step length between elements of the first vector in array A.
Constraint: ${\mathbf{ISTEPA}}>0$.
7:     ISTEPB – INTEGERInput
On entry: the step length between elements of the second vector in array B.
Constraint: ${\mathbf{ISTEPB}}>0$.
8:     CX – COMPLEX (KIND=nag_wp)Input
On entry: the initial value $c$.
9:     DX – COMPLEX (KIND=nag_wp)Output
On exit: the result $d$.
10:   SW – LOGICALInput
On entry: the precision to be used in the calculation.
${\mathbf{SW}}=\mathrm{.TRUE.}$
${\mathbf{SW}}=\mathrm{.FALSE.}$
basic precision.
11:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{ISTEPA}}\le 0$, or ${\mathbf{ISTEPB}}\le 0$.
${\mathbf{IFAIL}}=2$
 On entry, ${\mathbf{ISIZEA}}<\left({\mathbf{N}}-1\right)×{\mathbf{ISTEPA}}+1$, or ${\mathbf{ISIZEB}}<\left({\mathbf{N}}-1\right)×{\mathbf{ISTEPB}}+1$.

## 7  Accuracy

If the calculation is in additional precision, the result is correct to full implementation accuracy provided that exceptionally severe cancellation does not occur in the summation. If the calculation is in basic precision, such accuracy cannot be guaranteed.

The time taken by X03ABF is approximately proportional to $n$ and also depends on whether basic precision or additional precision is used.

## 9  Example

This example calculates the scalar product of the second column of the matrix $A$ and the vector ${\mathbf{B}}$, and add it to an initial value of $1+i$, where
 $A= -1 -i 1 -2+3i i 2i -0 -1-i 1-2i , B= i 1-i -i .$

### 9.1  Program Text

Program Text (x03abfe.f90)

### 9.2  Program Data

Program Data (x03abfe.d)

### 9.3  Program Results

Program Results (x03abfe.r)