CXML

snrsq, dnrsq, scnrsq, dznrsq 


FORMAT

  {S,D}NRSQ (n, x, incx) SCNRSQ (n, x, incx) DZNRSQ (n, x, incx)

Function Value

  sum                 real*4 | real*8
                      The sum of the squares of the elements of the real
                      vector x.
                      The sum of the squares of the absolute value of the
                      elements of the complex vector x.

                      If n<=0, sum returns the value 0.0.

Arguments

  n                   integer*4
                      On entry, the number of elements of the vector x.
                      On exit, n is unchanged.

  x                   real*4 | real*8 | complex*8 | complex*16
                      On entry, a one-dimensional array X of length at least
                      (1+(n-1)*|incx|), containing the elements of the vector
                      x.
                      On exit, x is unchanged.

  incx                integer*4
                      On entry, the increment for the array X.
                      If incx > 0, vector x is stored forward in the array,
                      so that x(i) is stored in location X(1+(i-1)*incx).
                      If incx < 0, vector x is stored backward in the array,
                      so that x(i) is stored in location X(1+(n-i)*|incx|).
                      If incx = 0, only the first element is accessed.
                      On exit, incx is unchanged.

Description

  SNRSQ and DNRSQ compute the sum of squares of the elements of a real
  vector.  SCNRSQ and DZNRSQ compute the sum of squares of the absolute value
  of the elements of a complex vector.

  SNRSQ and DNRSQ compute the total value of the square roots of each element
  in the real vector x: SUM(j=1...n,x(j)**2)

  SCNRSQ and DZNRSQ compute the total value of the square roots of each
  element in the complex vector x, using the absolute value of each element:
  SUM(j=1...n,|x(j)|**2)

  For complex vectors, each element x(j) is a complex number.  In this
  subprogram, the absolute value of a complex number is defined as the square
  root of the sum of the square of the real part and the square of the
  imaginary part: |x(j)| = (a(j)**2 + b(j)**2)**(1/2) = ((real)**2 +
  (imaginary)**2) **(1/2)

  If incx < 0, the result is identical to using |incx|.  If incx = 0, the
  computation is a time-consuming way of setting sum = nx(1)**2.

  Because of efficient coding, rounding errors can cause the final result to
  differ from the result computed by a sequential evaluation of the sum of
  the squares of the elements of the vector. Use these functions to obtain
  the square of the Euclidean norm instead of squaring the result obtained
  from the Level 1 routines SNRM2 and DNRM2. The computation is more
  accurate.

Example

  INTEGER*4 N, INCX
  REAL*4 X(20), SUM
  INCX = 1
  N = 20
  SUM = SNRSQ(N,X,INCX)

  This FORTRAN example shows how to compute the sum of the squares of the
  elements of the vector x.

CXML Home Page

Index of CXML Routines