Euclidean norm squared

 

SNRSQ/DNRSQ/SCNRSQ/DZNRSQ

 

INTEGER*8

n, incx

 

REAL*8

s, DZNRSQ

 

COMPLEX*16

x(lenx)

 

s = DZNRSQ(n, x, incx)

Input

n

Number of elements of vector x to be used in the

 

 

calculation. If n ≤ 0, the subprograms do not reference

 

 

x.

 

x

Array of length lenx = (n−1)⋅incx+1 containing the

 

 

n-vector x.

 

incx

Increment for the array x. x is stored forward in array x

 

 

with increment incx; that is, xi is stored in

 

 

x((i−1)⋅incx+1).

 

 

Use incx = 1 if the vector x is stored contiguously in

 

 

array x; that is, if xi is stored in x(i). Refer to “BLAS

 

 

Indexing Conventions” in the introduction to this

 

 

chapter.

Output

s

If n ≤ 0, then s = 0. Otherwise, s is the square of the

 

 

Euclidean norm of x.

Fortran

REAL*4 FUNCTION SNRSQ (N, X,INCX)

Equivalent

REAL*4 X(*)

SNRSQ = 0.0

IF ( N .LE. 0 ) RETURN IX = 1

INCXA = ABS ( INCX ) DO 10 I = 1, N

SNRSQ = SNRSQ + X(IX) ** 2

IX = IX + INCXA 10 CONTINUE

RETURN END

Example Compute the square of the Euclidean norm of the REAL*8 vector x, where xis a vector 10 elements long stored in a one-dimensional array X of dimension 20.

INTEGER*4

N,INCX

REAL*8

S,DNRSQ,X(20)

N =

10

 

INCX = 1

 

S =

DNRSQ (N,X,INCX)

Chapter 2 Basic Vector Operations 111