Manual Reference Pages  - norm2 (3fortran)

NAME

NORM2(3) - [MATHEMATICS] Euclidean vector norm

SYNOPSIS

result = norm2(array, [dim])

         real(kind=KIND) function norm2(array, dim)

real(kind=KIND),intent(in) :: array(..) integer(kind=**),intent(in),optional :: dim

CHARACTERISTICS

o ARRAY shall be an array of type real.
o DIM shall be a scalar of type integer
o The result is of the same type as ARRAY.

DESCRIPTION

NORM2(3) calculates the Euclidean vector norm (L_2 norm or generalized L norm) of ARRAY along dimension DIM.

OPTIONS

o ARRAY : the array of input values for the L_2 norm computations
o DIM : a value in the range from 1 to RANK(ARRAY).

RESULT

If DIM is absent, a scalar with the square root of the sum of squares of the elements of ARRAY is returned.

Otherwise, an array of rank N-1, where N equals the rank of ARRAY, and a shape similar to that of ARRAY with dimension DIM dropped is returned.

Case (i) : The result of NORM2 (X) has a value equal to a processor-dependent approximation to the generalized L norm of X, which is the square root of the sum of the squares of the elements of X. If X has size zero, the result has the value zero.

Case (ii) : The result of NORM2 (X, DIM=DIM) has a value equal to that of NORM2 (X) if X has rank one. Otherwise, the resulting array is reduced in rank with dimension DIM removed, and each remaining elment is the result of NORM2(X) for the values along dimension DIM.

It is recommended that the processor compute the result without undue overflow or underflow.

EXAMPLES

Sample program:

    program demo_norm2
    implicit none
    integer :: i
    real :: x(2,3) = reshape([ &
       1, 2, 3, &
       4, 5, 6  &
       ],shape(x),order=[2,1])

write(*,*) ’input in row-column order’ write(*,*) ’x=’ write(*,’(4x,3f4.0)’)transpose(x) write(*,*) write(*,*) ’norm2(x)=’,norm2(x) write(*,*) ’which is equivalent to’ write(*,*) ’sqrt(sum(x**2))=’,sqrt(sum(x**2)) write(*,*) write(*,*) ’for reference the array squared is’ write(*,*) ’x**2=’ write(*,’(4x,3f4.0)’)transpose(x**2) write(*,*) write(*,*) ’norm2(x,dim=1)=’,norm2(x,dim=1) write(*,*) ’norm2(x,dim=2)=’,norm2(x,dim=2) write(*,*) ’(sqrt(sum(x(:,i)**2)),i=1,3)=’,(sqrt(sum(x(:,i)**2)),i=1,3) write(*,*) ’(sqrt(sum(x(i,:)**2)),i=1,2)=’,(sqrt(sum(x(i,:)**2)),i=1,2)

end program demo_norm2

Results:

     >  input in row-column order
     >  x=
     >       1.  2.  3.
     >       4.  5.  6.
     >
     >  norm2(x)=   9.539392
     >  which is equivalent to
     >  sqrt(sum(x**2))=   9.539392
     >
     >  for reference the array squared is
     >  x**2=
     >       1.  4.  9.
     >      16. 25. 36.
     >
     >  norm2(x,dim=1)=   4.123106       5.385165       6.708204
     >  norm2(x,dim=2)=   3.741657       8.774964
     >  (sqrt(sum(x(:,i)**2)),i=1,3)=   4.123106       5.385165       6.708204
     >  (sqrt(sum(x(i,:)**2)),i=1,2)=   3.741657       8.774964

STANDARD

Fortran 2008

SEE ALSO

PRODUCT(3), SUM(3), HYPOT(3)

Fortran intrinsic descriptions (license: MIT) @urbanjost


Nemo Release 3.1 norm2 (3fortran) November 02, 2024
Generated by manServer 1.08 from 461a4bee-5a29-40b2-b958-9efcac6ea417 using man macros.