cchdc.f 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. *DECK CCHDC
  2. SUBROUTINE CCHDC (A, LDA, P, WORK, JPVT, JOB, INFO)
  3. C***BEGIN PROLOGUE CCHDC
  4. C***PURPOSE Compute the Cholesky decomposition of a positive definite
  5. C matrix. A pivoting option allows the user to estimate the
  6. C condition number of a positive definite matrix or determine
  7. C the rank of a positive semidefinite matrix.
  8. C***LIBRARY SLATEC (LINPACK)
  9. C***CATEGORY D2D1B
  10. C***TYPE COMPLEX (SCHDC-S, DCHDC-D, CCHDC-C)
  11. C***KEYWORDS CHOLESKY DECOMPOSITION, LINEAR ALGEBRA, LINPACK, MATRIX,
  12. C POSITIVE DEFINITE
  13. C***AUTHOR Dongarra, J., (ANL)
  14. C Stewart, G. W., (U. of Maryland)
  15. C***DESCRIPTION
  16. C
  17. C CCHDC computes the Cholesky decomposition of a positive definite
  18. C matrix. A pivoting option allows the user to estimate the
  19. C condition of a positive definite matrix or determine the rank
  20. C of a positive semidefinite matrix.
  21. C
  22. C On Entry
  23. C
  24. C A COMPLEX(LDA,P).
  25. C A contains the matrix whose decomposition is to
  26. C be computed. Only the upper half of A need be stored.
  27. C The lower part of The array A is not referenced.
  28. C
  29. C LDA INTEGER.
  30. C LDA is the leading dimension of the array A.
  31. C
  32. C P INTEGER.
  33. C P is the order of the matrix.
  34. C
  35. C WORK COMPLEX.
  36. C WORK is a work array.
  37. C
  38. C JPVT INTEGER(P).
  39. C JPVT contains integers that control the selection
  40. C of the pivot elements, if pivoting has been requested.
  41. C Each diagonal element A(K,K)
  42. C is placed in one of three classes according to the
  43. C value of JPVT(K)).
  44. C
  45. C If JPVT(K)) .GT. 0, then X(K) is an initial
  46. C element.
  47. C
  48. C If JPVT(K)) .EQ. 0, then X(K) is a free element.
  49. C
  50. C If JPVT(K)) .LT. 0, then X(K) is a final element.
  51. C
  52. C Before the decomposition is computed, initial elements
  53. C are moved by symmetric row and column interchanges to
  54. C the beginning of the array A and final
  55. C elements to the end. Both initial and final elements
  56. C are frozen in place during the computation and only
  57. C free elements are moved. At the K-th stage of the
  58. C reduction, if A(K,K) is occupied by a free element
  59. C it is interchanged with the largest free element
  60. C A(L,L) with L .GE. K. JPVT is not referenced if
  61. C JOB .EQ. 0.
  62. C
  63. C JOB INTEGER.
  64. C JOB is an integer that initiates column pivoting.
  65. C IF JOB .EQ. 0, no pivoting is done.
  66. C IF JOB .NE. 0, pivoting is done.
  67. C
  68. C On Return
  69. C
  70. C A A contains in its upper half the Cholesky factor
  71. C of the matrix A as it has been permuted by pivoting.
  72. C
  73. C JPVT JPVT(J) contains the index of the diagonal element
  74. C of A that was moved into the J-th position,
  75. C provided pivoting was requested.
  76. C
  77. C INFO contains the index of the last positive diagonal
  78. C element of the Cholesky factor.
  79. C
  80. C For positive definite matrices INFO = P is the normal return.
  81. C For pivoting with positive semidefinite matrices INFO will
  82. C in general be less than P. However, INFO may be greater than
  83. C the rank of A, since rounding error can cause an otherwise zero
  84. C element to be positive. Indefinite systems will always cause
  85. C INFO to be less than P.
  86. C
  87. C***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.
  88. C Stewart, LINPACK Users' Guide, SIAM, 1979.
  89. C***ROUTINES CALLED CAXPY, CSWAP
  90. C***REVISION HISTORY (YYMMDD)
  91. C 790319 DATE WRITTEN
  92. C 890831 Modified array declarations. (WRB)
  93. C 890831 REVISION DATE from Version 3.2
  94. C 891214 Prologue converted to Version 4.0 format. (BAB)
  95. C 900326 Removed duplicate information from DESCRIPTION section.
  96. C (WRB)
  97. C 920501 Reformatted the REFERENCES section. (WRB)
  98. C***END PROLOGUE CCHDC
  99. INTEGER LDA,P,JPVT(*),JOB,INFO
  100. COMPLEX A(LDA,*),WORK(*)
  101. C
  102. INTEGER PU,PL,PLP1,J,JP,JT,K,KB,KM1,KP1,L,MAXL
  103. COMPLEX TEMP
  104. REAL MAXDIA
  105. LOGICAL SWAPK,NEGK
  106. C***FIRST EXECUTABLE STATEMENT CCHDC
  107. PL = 1
  108. PU = 0
  109. INFO = P
  110. IF (JOB .EQ. 0) GO TO 160
  111. C
  112. C PIVOTING HAS BEEN REQUESTED. REARRANGE THE
  113. C THE ELEMENTS ACCORDING TO JPVT.
  114. C
  115. DO 70 K = 1, P
  116. SWAPK = JPVT(K) .GT. 0
  117. NEGK = JPVT(K) .LT. 0
  118. JPVT(K) = K
  119. IF (NEGK) JPVT(K) = -JPVT(K)
  120. IF (.NOT.SWAPK) GO TO 60
  121. IF (K .EQ. PL) GO TO 50
  122. CALL CSWAP(PL-1,A(1,K),1,A(1,PL),1)
  123. TEMP = A(K,K)
  124. A(K,K) = A(PL,PL)
  125. A(PL,PL) = TEMP
  126. A(PL,K) = CONJG(A(PL,K))
  127. PLP1 = PL + 1
  128. IF (P .LT. PLP1) GO TO 40
  129. DO 30 J = PLP1, P
  130. IF (J .GE. K) GO TO 10
  131. TEMP = CONJG(A(PL,J))
  132. A(PL,J) = CONJG(A(J,K))
  133. A(J,K) = TEMP
  134. GO TO 20
  135. 10 CONTINUE
  136. IF (J .EQ. K) GO TO 20
  137. TEMP = A(K,J)
  138. A(K,J) = A(PL,J)
  139. A(PL,J) = TEMP
  140. 20 CONTINUE
  141. 30 CONTINUE
  142. 40 CONTINUE
  143. JPVT(K) = JPVT(PL)
  144. JPVT(PL) = K
  145. 50 CONTINUE
  146. PL = PL + 1
  147. 60 CONTINUE
  148. 70 CONTINUE
  149. PU = P
  150. IF (P .LT. PL) GO TO 150
  151. DO 140 KB = PL, P
  152. K = P - KB + PL
  153. IF (JPVT(K) .GE. 0) GO TO 130
  154. JPVT(K) = -JPVT(K)
  155. IF (PU .EQ. K) GO TO 120
  156. CALL CSWAP(K-1,A(1,K),1,A(1,PU),1)
  157. TEMP = A(K,K)
  158. A(K,K) = A(PU,PU)
  159. A(PU,PU) = TEMP
  160. A(K,PU) = CONJG(A(K,PU))
  161. KP1 = K + 1
  162. IF (P .LT. KP1) GO TO 110
  163. DO 100 J = KP1, P
  164. IF (J .GE. PU) GO TO 80
  165. TEMP = CONJG(A(K,J))
  166. A(K,J) = CONJG(A(J,PU))
  167. A(J,PU) = TEMP
  168. GO TO 90
  169. 80 CONTINUE
  170. IF (J .EQ. PU) GO TO 90
  171. TEMP = A(K,J)
  172. A(K,J) = A(PU,J)
  173. A(PU,J) = TEMP
  174. 90 CONTINUE
  175. 100 CONTINUE
  176. 110 CONTINUE
  177. JT = JPVT(K)
  178. JPVT(K) = JPVT(PU)
  179. JPVT(PU) = JT
  180. 120 CONTINUE
  181. PU = PU - 1
  182. 130 CONTINUE
  183. 140 CONTINUE
  184. 150 CONTINUE
  185. 160 CONTINUE
  186. DO 270 K = 1, P
  187. C
  188. C REDUCTION LOOP.
  189. C
  190. MAXDIA = REAL(A(K,K))
  191. KP1 = K + 1
  192. MAXL = K
  193. C
  194. C DETERMINE THE PIVOT ELEMENT.
  195. C
  196. IF (K .LT. PL .OR. K .GE. PU) GO TO 190
  197. DO 180 L = KP1, PU
  198. IF (REAL(A(L,L)) .LE. MAXDIA) GO TO 170
  199. MAXDIA = REAL(A(L,L))
  200. MAXL = L
  201. 170 CONTINUE
  202. 180 CONTINUE
  203. 190 CONTINUE
  204. C
  205. C QUIT IF THE PIVOT ELEMENT IS NOT POSITIVE.
  206. C
  207. IF (MAXDIA .GT. 0.0E0) GO TO 200
  208. INFO = K - 1
  209. GO TO 280
  210. 200 CONTINUE
  211. IF (K .EQ. MAXL) GO TO 210
  212. C
  213. C START THE PIVOTING AND UPDATE JPVT.
  214. C
  215. KM1 = K - 1
  216. CALL CSWAP(KM1,A(1,K),1,A(1,MAXL),1)
  217. A(MAXL,MAXL) = A(K,K)
  218. A(K,K) = CMPLX(MAXDIA,0.0E0)
  219. JP = JPVT(MAXL)
  220. JPVT(MAXL) = JPVT(K)
  221. JPVT(K) = JP
  222. A(K,MAXL) = CONJG(A(K,MAXL))
  223. 210 CONTINUE
  224. C
  225. C REDUCTION STEP. PIVOTING IS CONTAINED ACROSS THE ROWS.
  226. C
  227. WORK(K) = CMPLX(SQRT(REAL(A(K,K))),0.0E0)
  228. A(K,K) = WORK(K)
  229. IF (P .LT. KP1) GO TO 260
  230. DO 250 J = KP1, P
  231. IF (K .EQ. MAXL) GO TO 240
  232. IF (J .GE. MAXL) GO TO 220
  233. TEMP = CONJG(A(K,J))
  234. A(K,J) = CONJG(A(J,MAXL))
  235. A(J,MAXL) = TEMP
  236. GO TO 230
  237. 220 CONTINUE
  238. IF (J .EQ. MAXL) GO TO 230
  239. TEMP = A(K,J)
  240. A(K,J) = A(MAXL,J)
  241. A(MAXL,J) = TEMP
  242. 230 CONTINUE
  243. 240 CONTINUE
  244. A(K,J) = A(K,J)/WORK(K)
  245. WORK(J) = CONJG(A(K,J))
  246. TEMP = -A(K,J)
  247. CALL CAXPY(J-K,TEMP,WORK(KP1),1,A(KP1,J),1)
  248. 250 CONTINUE
  249. 260 CONTINUE
  250. 270 CONTINUE
  251. 280 CONTINUE
  252. RETURN
  253. END