Apply Givens rotation

SROT/DROT/CROT/CSROT/ZROT/ZDROT

Notes The result is unspecified if incx = 0 or incy = 0 or if x and y overlap such that any element of x shares a memory location with any element of y.

There are no companion subprograms that construct real Givens rotations for CSROT and ZDROT.

VECLIB also contains subprograms that construct and apply modified Givens rotations. They are documented elsewhere in this chapter. The modified Givens subprograms are a little more difficult to use, but are more efficient.

Fortran

SUBROUTINE SROT (N, X,INCX, Y,INCY, C,S)

Equivalent

REAL*4 C,S,TEMP,X(*),Y(*)

 

IF ( N .LE. 0 ) RETURN

 

IF ( C .EQ. 1.0 .AND. S .EQ. 0.0 ) RETURN

 

IX = 1

 

IY = 1

 

IF ( INCX .LT. 0 ) IX = 1 - (N-1) * INCX

 

IF ( INCY .LT. 0 ) IY = 1 - (N-1) * INCY

 

DO 10 I = 1, N

TEMP = C * X(IX) + S * Y(IY) Y(IY) = C * Y(IY) - S * X(IX) X(IX) = TEMP

IX = IX + INCX

IY = IY + INCY 10 CONTINUE

RETURN END

Example 1 Apply a Givens rotation to x and y, vectors 10 elements long stored in one-dimensional arrays X and Y of dimension 20.

INTEGER*4 N,INCX,INCY

REAL*8

X(20),Y(20),C,S

N = 10

 

INCX = 1

 

INCY = 1

 

CALL DROT (N,X,INCX,Y,INCY,C,S)

Example 2 Reduce 10-by-10 matrix a stored in two-dimensional array A of dimension 20-by-21 to upper-triangular form via Givens rotations (compare with “Example 2” on page 126 in the description of SROTM and DROTM).

INTEGER*4 INCA,I,J,N

REAL*8 A(20,21),C,S

INCA = 20

DO 20 I = 1, 9

N = 10 - I

DO 10 J = I+1, 10

CALL DROTG (A(I,I),A(J,I),C,S)

CALL DROT (N,A(I,I+1),INCA,A(J,I+1),INCA,C,S)

10CONTINUE

20CONTINUE

Chapter 2 Basic Vector Operations 117