LF Fortran 95

DOT_PRODUCT Function

Description

The DOT_PRODUCT function returns the dot product of two vectors of type INTEGER, REAL OR COMPLEX.

Syntax

DOT_PRODUCT (vector_a, vector_b)

Arguments

vector_a is an INTENT(IN) rank one array of type INTEGER, REAL, COMPLEX, or LOGICAL.

vector_b is an INTENT(IN) rank one array and must be the same size as vector_a.

If vector_a is a numeric type, vector_b must also be a numeric type.

If vector_a is LOGICAL, vector_b must also be LOGICAL.

Result

If both vector_a and vector_b are REAL or INTEGER, the result is equal to

SUM (vector_a * vector_b) .

If either argument is of type COMPLEX, the result value is

SUM (CONJG (vector_a) * vector_b) .

If one of the arguments is not COMPLEX, it is treated as if it were complex with an imaginary part of zero.

If the arguments are of type LOGICAL, then the result value is

ANY (vector_a .AND. vector_b).

If the arguments are of different numeric types, the result type is taken from the argument with the higher type, where COMPLEX is higher than REAL, and REAL is higher than INTEGER.

The kind of the result is taken from the argument that offers the greatest range.

If the argument arrays size is zero, the result is zero for numeric types, and false for logical types.

Example

integer :: ivec(3)=(/1,2,3/), & jvec(3)=(/4,5,6/) real :: rvec(3)=(/1.,2.,3./) real(kind(1.d0)) :: svec(3)=(/4.d0,5.d0,6.d0/) complex :: pvec(3)=(/(0.,1.),(0.,2.),(0.,3.)/), & qvec(3)=(/(0.,4.),(0.,5.),(0.,6.)/) write(*,*) dot_product(ivec,jvec) ! integer result write(*,*) dot_product(rvec,jvec) ! real result write(*,*) dot_product(rvec,svec) ! D.P. result write(*,*) dot_product(pvec,jvec) ! Complex result write(*,*) dot_product(pvec,svec) ! D.P. complex result write(*,*) dot_product(pvec,qvec) ! Complex result