ISAMAX/IDAMAX/IIAMAX/ICAMAX/IZAMAX | Index of maximum of magnitudes |
Fortran Equivalent
INTEGER*4 FUNCTION ISAMAX (N,X,INCX) REAL*4 X(*),TEMP,XMAX
ISAMAX = 1
IF ( N .GT. 1 ) THEN XMAX = ABS ( X(1) ) INCXA = ABS ( INCX ) IX = 1 + INCXA
DO 10 I = 2, N
TEMP = ABS ( X(IX) )
IF ( TEMP .GT. XMAX ) THEN ISAMAX = I
XMAX = TEMP END IF
IX = IX + INCXA
10 CONTINUE
ELSE IF ( N .LT. 1 ) THEN ISAMAX = 0
END IF
RETURN END
Example Locate the largest element of a REAL*8 vector x, where x is a vector 10 elements long stored in a
INTEGER*4 | I,IDAMAX,N,INCX | |
REAL*8 | X(20) | |
N = | 10 |
|
INCX = 1 |
| |
I = | IDAMAX (N,X,INCX) |
42HP MLIB User’s Guide