Previous Next Contents Generated Index Doc Set Home



Euclidean Norm of a Vector

The subroutines described in this section compute the l2-norm of the vector x:

Calling Sequence

DL2 = DNRM2 (N, DX, INCX)
SL2 = SNRM2 (N, SX, INCX)
DL2 = DZNRM2 (N, ZX, INCX)
SL2 = SCNRM2 (N, CX, INCX)



double dnrm2(int n, double *dx, int incx)
float snrm2(int n, float *sx, int incx)
double dznrm2(int n, doublecomplex *zx, int incx)
float scnrm2(int n, complex *cx, int incx)

Arguments

N

Number of elements in the vector. N 0.

xX

Input vector X; the size of array X must be at least max(1,N*|INCX|).

INCX

Specifies the storage spacing between successive elements of the vector X. A value of one indicates that the elements of the vector are consecutive in memory. INCX > 0.

If X refers to a two-dimensional array and the value of INCX is equal to the leading dimension of X then the elements of the vector will be a row of X.

If X refers to a two-dimensional array and the value of INCX is equal to the leading dimension of X plus one then the elements of the vector will be a diagonal of X.

Sample Program

 
      PROGRAM TEST
      IMPLICIT NONE
C
      INTEGER           N
      PARAMETER        (N = 4)
C
      DOUBLE PRECISION  TWONRM, X(N)
      INTEGER           INCX
C
      DOUBLE PRECISION  DNRM2
      EXTERNAL          DNRM2
C
C     Initialize the array X to store the vector x shown below.
C
C         1
C     x = 5
C         3
C         1
C
      DATA X / 1.0D0, 5.0D0, 3.0D0, 1.0D0 /
C
      PRINT 1000
      PRINT 1010, X
      INCX = 1
      TWONRM = DNRM2 (N, X, INCX)
      PRINT 1020, TWONRM
C
 1000 FORMAT (1X, 'x:')
 1010 FORMAT (4X, F3.1)
 1020 FORMAT (/1X, 'The L-2 norm of x is ', F3.1)
C
      END
 

Sample Output

 
 x:
    1.0
    5.0
    3.0
    1.0



 The L-2 norm of x is 6.0






Previous Next Contents Generated Index Doc Set Home