Dot product
Fortran Equivalent
SDOT/DDOT/CDOTC/CDOTU/ZDOTC/ZDOTU
REAL*4 FUNCTION SDOT (N, X,INCX, Y,INCY)
REAL*4 X(*),Y(*)
SDOT = 0.0
IF ( N .LE. 0 ) RETURN
IX = 1
IY = 1
IF ( INCX .LT. 0 ) IX = 1 -
IF ( INCY .LT. 0 ) IY = 1 -
DO 10 I = 1, N
SDOT = SDOT + X(IX) * Y(IY)
IX = IX + INCX
IY = IY + INCY
10CONTINUE RETURN END
Example 1 Compute the REAL*8 dot product
10
s = ∑ xi yi
i = 1
where x and y are vectors 10 elements long stored in
INTEGER*4 N,INCX,INCY
REAL*8 | S,DDOT,X(20),Y(20) | |
N = | 10 |
|
INCX = 1 |
| |
INCY = 1 |
| |
S = | DDOT (N,X,INCX,Y,INCY) |
Example 2 Compute the REAL*8 dot product
10
s = ∑ xi yi
i = 1
where x is the 4th row of a
INTEGER*4 | N | |
REAL*8 | S,DDOT,X(20,21),Y(20) | |
N = | 10 |
|
S = | DDOT (N,X(4,1),20,Y,1) |
Chapter 2 Basic Vector Operations 87