home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Geek Gadgets 1
/
ADE-1.bin
/
ade-dist
/
octave-1.1.1p1-src.tgz
/
tar.out
/
fsf
/
octave
/
libcruft
/
minpack
/
r1updt.f
< prev
Wrap
Text File
|
1996-09-28
|
6KB
|
208 lines
SUBROUTINE R1UPDT(M,N,S,LS,U,V,W,SING)
INTEGER M,N,LS
LOGICAL SING
DOUBLE PRECISION S(LS),U(M),V(N),W(M)
C **********
C
C SUBROUTINE R1UPDT
C
C GIVEN AN M BY N LOWER TRAPEZOIDAL MATRIX S, AN M-VECTOR U,
C AND AN N-VECTOR V, THE PROBLEM IS TO DETERMINE AN
C ORTHOGONAL MATRIX Q SUCH THAT
C
C T
C (S + U*V )*Q
C
C IS AGAIN LOWER TRAPEZOIDAL.
C
C THIS SUBROUTINE DETERMINES Q AS THE PRODUCT OF 2*(N - 1)
C TRANSFORMATIONS
C
C GV(N-1)*...*GV(1)*GW(1)*...*GW(N-1)
C
C WHERE GV(I), GW(I) ARE GIVENS ROTATIONS IN THE (I,N) PLANE
C WHICH ELIMINATE ELEMENTS IN THE I-TH AND N-TH PLANES,
C RESPECTIVELY. Q ITSELF IS NOT ACCUMULATED, RATHER THE
C INFORMATION TO RECOVER THE GV, GW ROTATIONS IS RETURNED.
C
C THE SUBROUTINE STATEMENT IS
C
C SUBROUTINE R1UPDT(M,N,S,LS,U,V,W,SING)
C
C WHERE
C
C M IS A POSITIVE INTEGER INPUT VARIABLE SET TO THE NUMBER
C OF ROWS OF S.
C
C N IS A POSITIVE INTEGER INPUT VARIABLE SET TO THE NUMBER
C OF COLUMNS OF S. N MUST NOT EXCEED M.
C
C S IS AN ARRAY OF LENGTH LS. ON INPUT S MUST CONTAIN THE LOWER
C TRAPEZOIDAL MATRIX S STORED BY COLUMNS. ON OUTPUT S CONTAINS
C THE LOWER TRAPEZOIDAL MATRIX PRODUCED AS DESCRIBED ABOVE.
C
C LS IS A POSITIVE INTEGER INPUT VARIABLE NOT LESS THAN
C (N*(2*M-N+1))/2.
C
C U IS AN INPUT ARRAY OF LENGTH M WHICH MUST CONTAIN THE
C VECTOR U.
C
C V IS AN ARRAY OF LENGTH N. ON INPUT V MUST CONTAIN THE VECTOR
C V. ON OUTPUT V(I) CONTAINS THE INFORMATION NECESSARY TO
C RECOVER THE GIVENS ROTATION GV(I) DESCRIBED ABOVE.
C
C W IS AN OUTPUT ARRAY OF LENGTH M. W(I) CONTAINS INFORMATION
C NECESSARY TO RECOVER THE GIVENS ROTATION GW(I) DESCRIBED
C ABOVE.
C
C SING IS A LOGICAL OUTPUT VARIABLE. SING IS SET TRUE IF ANY
C OF THE DIAGONAL ELEMENTS OF THE OUTPUT S ARE ZERO. OTHERWISE
C V IS SET FALSE.
C
C SUBPROGRAMS CALLED
C
C MINPACK-SUPPLIED ... DPMPAR
C
C FORTRAN-SUPPLIED ... DABS,DSQRT
C
C MINPACK. VERSION OF DECEMBER 1978.
C BURTON S. GARBOW, KENNETH E. HILLSTROM, JORGE J. MORE,
C JOHN L. NAZARETH
C
C **********
INTEGER I,J,JJ,L,NMJ,NM1
DOUBLE PRECISION COS,COTAN,GIANT,ONE,P5,P25,SIN,TAN,TAU,TEMP,
* ZERO
DOUBLE PRECISION DPMPAR
DATA ONE,P5,P25,ZERO /1.0D0,5.0D-1,2.5D-1,0.0D0/
C
C GIANT IS THE LARGEST MAGNITUDE.
C
GIANT = DPMPAR(3)
C
C INITIALIZE THE DIAGONAL ELEMENT POINTER.
C
JJ = (N*(2*M - N + 1))/2 - (M - N)
C
C MOVE THE NONTRIVIAL PART OF THE LAST COLUMN OF S INTO W.
C
L = JJ
DO 10 I = N, M
W(I) = S(L)
L = L + 1
10 CONTINUE
C
C ROTATE THE VECTOR V INTO A MULTIPLE OF THE N-TH UNIT VECTOR
C IN SUCH A WAY THAT A SPIKE IS INTRODUCED INTO W.
C
NM1 = N - 1
IF (NM1 .LT. 1) GO TO 70
DO 60 NMJ = 1, NM1
J = N - NMJ
JJ = JJ - (M - J + 1)
W(J) = ZERO
IF (V(J) .EQ. ZERO) GO TO 50
C
C DETERMINE A GIVENS ROTATION WHICH ELIMINATES THE
C J-TH ELEMENT OF V.
C
IF (DABS(V(N)) .GE. DABS(V(J))) GO TO 20
COTAN = V(N)/V(J)
SIN = P5/DSQRT(P25+P25*COTAN**2)
COS = SIN*COTAN
TAU = ONE
IF (DABS(COS)*GIANT .GT. ONE) TAU = ONE/COS
GO TO 30
20 CONTINUE
TAN = V(J)/V(N)
COS = P5/DSQRT(P25+P25*TAN**2)
SIN = COS*TAN
TAU = SIN
30 CONTINUE
C
C APPLY THE TRANSFORMATION TO V AND STORE THE INFORMATION
C NECESSARY TO RECOVER THE GIVENS ROTATION.
C
V(N) = SIN*V(J) + COS*V(N)
V(J) = TAU
C
C APPLY THE TRANSFORMATION TO S AND EXTEND THE SPIKE IN W.
C
L = JJ
DO 40 I = J, M
TEMP = COS*S(L) - SIN*W(I)
W(I) = SIN*S(L) + COS*W(I)
S(L) = TEMP
L = L + 1
40 CONTINUE
50 CONTINUE
60 CONTINUE
70 CONTINUE
C
C ADD THE SPIKE FROM THE RANK 1 UPDATE TO W.
C
DO 80 I = 1, M
W(I) = W(I) + V(N)*U(I)
80 CONTINUE
C
C ELIMINATE THE SPIKE.
C
SING = .FALSE.
IF (NM1 .LT. 1) GO TO 140
DO 130 J = 1, NM1
IF (W(J) .EQ. ZERO) GO TO 120
C
C DETERMINE A GIVENS ROTATION WHICH ELIMINATES THE
C J-TH ELEMENT OF THE SPIKE.
C
IF (DABS(S(JJ)) .GE. DABS(W(J))) GO TO 90
COTAN = S(JJ)/W(J)
SIN = P5/DSQRT(P25+P25*COTAN**2)
COS = SIN*COTAN
TAU = ONE
IF (DABS(COS)*GIANT .GT. ONE) TAU = ONE/COS
GO TO 100
90 CONTINUE
TAN = W(J)/S(JJ)
COS = P5/DSQRT(P25+P25*TAN**2)
SIN = COS*TAN
TAU = SIN
100 CONTINUE
C
C APPLY THE TRANSFORMATION TO S AND REDUCE THE SPIKE IN W.
C
L = JJ
DO 110 I = J, M
TEMP = COS*S(L) + SIN*W(I)
W(I) = -SIN*S(L) + COS*W(I)
S(L) = TEMP
L = L + 1
110 CONTINUE
C
C STORE THE INFORMATION NECESSARY TO RECOVER THE
C GIVENS ROTATION.
C
W(J) = TAU
120 CONTINUE
C
C TEST FOR ZERO DIAGONAL ELEMENTS IN THE OUTPUT S.
C
IF (S(JJ) .EQ. ZERO) SING = .TRUE.
JJ = JJ + (M - J + 1)
130 CONTINUE
140 CONTINUE
C
C MOVE W BACK INTO THE LAST COLUMN OF THE OUTPUT S.
C
L = JJ
DO 150 I = N, M
S(L) = W(I)
L = L + 1
150 CONTINUE
IF (S(JJ) .EQ. ZERO) SING = .TRUE.
RETURN
C
C LAST CARD OF SUBROUTINE R1UPDT.
C
END