DISL2
This function computes the Euclidean (2-norm) distance between two points.
Function Return Value
DISL2 — Euclidean (2-norm) distance between the points X and Y. (Output)
Required Arguments
X — Vector of length max(N * ∣INCX∣, 1). (Input)
Y — Vector of length max(N * ∣INCY∣, 1). (Input)
Optional Arguments
N — Length of the vectors X and Y. (Input)
Default: N = SIZE (X,1).
INCX — Displacement between elements of X. (Input)
The I-th element of X is X(1 + (I ‑ 1) * INCX) if INCX is greater than or equal to zero, or X(1 + (I ‑ N) * INCX) if INCX is less than zero.
Default: INCX = 1.
INCY — Displacement between elements of Y. (Input)
The I-th element of Y is Y(1 + (I ‑ 1) * INCY) if INCY is greater than or equal to zero, or Y(1 + (I ‑ N) * INCY) if INCY is less than zero.
Default: INCY = 1.
FORTRAN 90 Interface
Generic: DISL2 (X, Y [, …])
Specific: The specific interface names are S_DISL2 and D_DISL2.
FORTRAN 77 Interface
Single: DISL2(N, X, INCX, Y, INCY)
Double: The double precision function name is DDISL2.
Description
The function DISL2 computes the Euclidean (2-norm) distance between two points x and y. The Euclidean distance is defined to be
Example
Compute the Euclidean (2-norm) distance between two vectors of length 4.
USE DISL2_INT
USE UMACH_INT
IMPLICIT NONE
! Declare variables
INTEGER INCX, INCY, N
PARAMETER (N=4)
!
INTEGER NOUT
REAL VAL, X(N), Y(N)
!
! Set values for X and Y
! X = ( 1.0 -1.0 0.0 2.0 )
!
! Y = ( 4.0 2.0 1.0 -3.0 )
!
DATA X/1.0, -1.0, 0.0, 2.0/
DATA Y/4.0, 2.0, 1.0, -3.0/
! Compute L2 distance
VAL = DISL2(X,Y)
! Print results
CALL UMACH (2, NOUT)
WRITE (NOUT,*) ' The 2-norm distance is ', VAL
END
The 2-norm distance is 6.63325