schdd.f 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. *DECK SCHDD
  2. SUBROUTINE SCHDD (R, LDR, P, X, Z, LDZ, NZ, Y, RHO, C, S, INFO)
  3. C***BEGIN PROLOGUE SCHDD
  4. C***PURPOSE Downdate an augmented Cholesky decomposition or the
  5. C triangular factor of an augmented QR decomposition.
  6. C***LIBRARY SLATEC (LINPACK)
  7. C***CATEGORY D7B
  8. C***TYPE SINGLE PRECISION (SCHDD-S, DCHDD-D, CCHDD-C)
  9. C***KEYWORDS CHOLESKY DECOMPOSITION, DOWNDATE, LINEAR ALGEBRA, LINPACK,
  10. C MATRIX
  11. C***AUTHOR Stewart, G. W., (U. of Maryland)
  12. C***DESCRIPTION
  13. C
  14. C SCHDD downdates an augmented Cholesky decomposition or the
  15. C triangular factor of an augmented QR decomposition.
  16. C Specifically, given an upper triangular matrix R of order P, a
  17. C row vector X, a column vector Z, and a scalar Y, SCHDD
  18. C determines an orthogonal matrix U and a scalar ZETA such that
  19. C
  20. C (R Z ) (RR ZZ)
  21. C U * ( ) = ( ) ,
  22. C (0 ZETA) ( X Y)
  23. C
  24. C where RR is upper triangular. If R and Z have been obtained
  25. C from the factorization of a least squares problem, then
  26. C RR and ZZ are the factors corresponding to the problem
  27. C with the observation (X,Y) removed. In this case, if RHO
  28. C is the norm of the residual vector, then the norm of
  29. C the residual vector of the downdated problem is
  30. C SQRT(RHO**2 - ZETA**2). SCHDD will simultaneously downdate
  31. C several triplets (Z,Y,RHO) along with R.
  32. C For a less terse description of what SCHDD does and how
  33. C it may be applied, see the LINPACK guide.
  34. C
  35. C The matrix U is determined as the product U(1)*...*U(P)
  36. C where U(I) is a rotation in the (P+1,I)-plane of the
  37. C form
  38. C
  39. C ( C(I) -S(I) )
  40. C ( ) .
  41. C ( S(I) C(I) )
  42. C
  43. C The rotations are chosen so that C(I) is real.
  44. C
  45. C The user is warned that a given downdating problem may
  46. C be impossible to accomplish or may produce
  47. C inaccurate results. For example, this can happen
  48. C if X is near a vector whose removal will reduce the
  49. C rank of R. Beware.
  50. C
  51. C On Entry
  52. C
  53. C R REAL(LDR,P), where LDR .GE. P.
  54. C R contains the upper triangular matrix
  55. C that is to be downdated. The part of R
  56. C below the diagonal is not referenced.
  57. C
  58. C LDR INTEGER.
  59. C LDR is the leading dimension of the array R.
  60. C
  61. C P INTEGER.
  62. C P is the order of the matrix R.
  63. C
  64. C X REAL(P).
  65. C X contains the row vector that is to
  66. C be removed from R. X is not altered by SCHDD.
  67. C
  68. C Z REAL(LDZ,NZ), where LDZ .GE. P.
  69. C Z is an array of NZ P-vectors which
  70. C are to be downdated along with R.
  71. C
  72. C LDZ INTEGER.
  73. C LDZ is the leading dimension of the array Z.
  74. C
  75. C NZ INTEGER.
  76. C NZ is the number of vectors to be downdated
  77. C NZ may be zero, in which case Z, Y, and RHO
  78. C are not referenced.
  79. C
  80. C Y REAL(NZ).
  81. C Y contains the scalars for the downdating
  82. C of the vectors Z. Y is not altered by SCHDD.
  83. C
  84. C RHO REAL(NZ).
  85. C RHO contains the norms of the residual
  86. C vectors that are to be downdated.
  87. C
  88. C On Return
  89. C
  90. C R
  91. C Z contain the downdated quantities.
  92. C RHO
  93. C
  94. C C REAL(P).
  95. C C contains the cosines of the transforming
  96. C rotations.
  97. C
  98. C S REAL(P).
  99. C S contains the sines of the transforming
  100. C rotations.
  101. C
  102. C INFO INTEGER.
  103. C INFO is set as follows.
  104. C
  105. C INFO = 0 if the entire downdating
  106. C was successful.
  107. C
  108. C INFO =-1 if R could not be downdated.
  109. C In this case, all quantities
  110. C are left unaltered.
  111. C
  112. C INFO = 1 if some RHO could not be
  113. C downdated. The offending RHOs are
  114. C set to -1.
  115. C
  116. C***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.
  117. C Stewart, LINPACK Users' Guide, SIAM, 1979.
  118. C***ROUTINES CALLED SDOT, SNRM2
  119. C***REVISION HISTORY (YYMMDD)
  120. C 780814 DATE WRITTEN
  121. C 890831 Modified array declarations. (WRB)
  122. C 890831 REVISION DATE from Version 3.2
  123. C 891214 Prologue converted to Version 4.0 format. (BAB)
  124. C 900326 Removed duplicate information from DESCRIPTION section.
  125. C (WRB)
  126. C 920501 Reformatted the REFERENCES section. (WRB)
  127. C***END PROLOGUE SCHDD
  128. INTEGER LDR,P,LDZ,NZ,INFO
  129. REAL R(LDR,*),X(*),Z(LDZ,*),Y(*),S(*)
  130. REAL RHO(*),C(*)
  131. C
  132. INTEGER I,II,J
  133. REAL A,ALPHA,AZETA,NORM,SNRM2
  134. REAL SDOT,T,ZETA,B,XX
  135. C
  136. C SOLVE THE SYSTEM TRANS(R)*A = X, PLACING THE RESULT
  137. C IN THE ARRAY S.
  138. C
  139. C***FIRST EXECUTABLE STATEMENT SCHDD
  140. INFO = 0
  141. S(1) = X(1)/R(1,1)
  142. IF (P .LT. 2) GO TO 20
  143. DO 10 J = 2, P
  144. S(J) = X(J) - SDOT(J-1,R(1,J),1,S,1)
  145. S(J) = S(J)/R(J,J)
  146. 10 CONTINUE
  147. 20 CONTINUE
  148. NORM = SNRM2(P,S,1)
  149. IF (NORM .LT. 1.0E0) GO TO 30
  150. INFO = -1
  151. GO TO 120
  152. 30 CONTINUE
  153. ALPHA = SQRT(1.0E0-NORM**2)
  154. C
  155. C DETERMINE THE TRANSFORMATIONS.
  156. C
  157. DO 40 II = 1, P
  158. I = P - II + 1
  159. SCALE = ALPHA + ABS(S(I))
  160. A = ALPHA/SCALE
  161. B = S(I)/SCALE
  162. NORM = SQRT(A**2+B**2)
  163. C(I) = A/NORM
  164. S(I) = B/NORM
  165. ALPHA = SCALE*NORM
  166. 40 CONTINUE
  167. C
  168. C APPLY THE TRANSFORMATIONS TO R.
  169. C
  170. DO 60 J = 1, P
  171. XX = 0.0E0
  172. DO 50 II = 1, J
  173. I = J - II + 1
  174. T = C(I)*XX + S(I)*R(I,J)
  175. R(I,J) = C(I)*R(I,J) - S(I)*XX
  176. XX = T
  177. 50 CONTINUE
  178. 60 CONTINUE
  179. C
  180. C IF REQUIRED, DOWNDATE Z AND RHO.
  181. C
  182. IF (NZ .LT. 1) GO TO 110
  183. DO 100 J = 1, NZ
  184. ZETA = Y(J)
  185. DO 70 I = 1, P
  186. Z(I,J) = (Z(I,J) - S(I)*ZETA)/C(I)
  187. ZETA = C(I)*ZETA - S(I)*Z(I,J)
  188. 70 CONTINUE
  189. AZETA = ABS(ZETA)
  190. IF (AZETA .LE. RHO(J)) GO TO 80
  191. INFO = 1
  192. RHO(J) = -1.0E0
  193. GO TO 90
  194. 80 CONTINUE
  195. RHO(J) = RHO(J)*SQRT(1.0E0-(AZETA/RHO(J))**2)
  196. 90 CONTINUE
  197. 100 CONTINUE
  198. 110 CONTINUE
  199. 120 CONTINUE
  200. RETURN
  201. END