IBM Books

Engineering and Scientific Subroutine Library for AIX Version 3 Release 3: Guide and Reference

ISAMAX, IDAMAX, ICAMAX, and IZAMAX--Position of the First or Last Occurrence of the Vector Element Having the Largest Magnitude

ISAMAX and IDAMAX find the position i of the first or last occurrence of a vector element having the maximum absolute value. ICAMAX and IZAMAX find the position i of the first or last occurrence of a vector element having the largest sum of the absolute values of the real and imaginary parts of the vector elements.

You get the position of the first or last occurrence of an element by specifying positive or negative stride, respectively, for vector x. Regardless of the stride, the position i is always relative to the location specified in the calling sequence for vector x (in argument x).

Table 36. Data Types

x Subprogram
Short-precision real ISAMAX
Long-precision real IDAMAX
Short-precision complex ICAMAX
Long-precision complex IZAMAX

Syntax

Fortran ISAMAX | IDAMAX | ICAMAX | IZAMAX (n, x, incx)
C and C++ isamax | idamax | icamax | izamax (n, x, incx);
PL/I ISAMAX | IDAMAX | ICAMAX | IZAMAX (n, x, incx);

On Entry

n
is the number of elements in vector x. Specified as: a fullword integer; n >= 0.

x
is the vector x of length n. Specified as: a one-dimensional array of (at least) length 1+(n-1)|incx|, containing numbers of the data type indicated in Table 36.

incx
is the stride for vector x. Specified as: a fullword integer. It can have any value.

On Return

Function value
 

is the position i of the element in the array, where:

If incx >= 0, i is the position of the first occurrence.

If incx < 0, i is the position of the last occurrence.

Returned as: a fullword integer; 0 <= i <= n.

Note

Declare the ISAMAX, IDAMAX, ICAMAX, and IZAMAX functions in your program as returning a fullword integer value.

Function

ISAMAX and IDAMAX find the first element xk, where k is defined as the smallest index k, such that:

|xk| = max{|xj| for j = 1, n}

ICAMAX and IZAMAX find the first element xk, where k is defined as the smallest index k, such that:

|ak|+|bk| = max{|aj|+|bj| for j = 1, n}
where xk = (ak, bk)

By specifying a positive or negative stride for vector x, the first or last occurrence, respectively, is found in the array. The position i, returned as the value of the function, is always figured relative to the location specified in the calling sequence for vector x (in argument x). Therefore, depending on the stride specified for incx, i has the following values:

For incx >= 0, i = k
For incx < 0, i = n-k+1

See reference [79]. The result is returned as a function value. If n is 0, then 0 is returned as the value of the function.

Error Conditions

Computational Errors

None

Input-Argument Errors

n < 0

Example 1

This example shows a vector, x, with a stride of 1.

Function Reference and Input
               N   X   INCX
               |   |    |
IMAX = ISAMAX( 9 , X ,  1   )
 
X        =  (1.0, 2.0, 7.0, -8.0, -5.0, -10.0, -9.0, 10.0, 6.0)

Output
IMAX     =  6

Example 2

This example shows a vector, x, with a stride greater than 1.

Function Reference and Input
               N   X   INCX
               |   |    |
IMAX = ISAMAX( 5 , X ,  2   )
 
X        =  (1.0, . , 7.0, . , -5.0, . , -9.0, . , 6.0)

Output
IMAX     =  4

Example 3

This example shows a vector, x, with a stride of 0.

Function Reference and Input
               N   X   INCX
               |   |    |
IMAX = ISAMAX( 9 , X ,  0   )
 
X        =  (1.0, . , . , . , . , . , . , . , .)

Output
IMAX     =  1

Example 4

This example shows a vector, x, with a negative stride. Processing begins at element X(15), which is 2.0.

Function Reference and Input
               N   X   INCX
               |   |    |
IMAX = ISAMAX( 8 , X , -2   )
 
X        =  (3.0, . , 5.0, . , -8.0, . , 6.0, . , 8.0, . ,
             4.0, . , 8.0, . , 2.0)

Output
IMAX     =  7

Example 5

This example shows a vector, x, containing complex numbers and having a stride of 1.

Function Reference and Input
               N   X   INCX
               |   |    |
IMAX = ICAMAX( 5 , X ,  1   )
 
X        =  ((9.0 , 2.0) , (7.0 , -8.0) , (-5.0 , -10.0) , (-4.0 , 10.0),
             (6.0 , 3.0))

Output
IMAX     =  2


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]