schdc.f 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. *DECK SCHDC
  2. SUBROUTINE SCHDC (A, LDA, P, WORK, JPVT, JOB, INFO)
  3. C***BEGIN PROLOGUE SCHDC
  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 D2B1B
  10. C***TYPE SINGLE PRECISION (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 SCHDC 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 REAL(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 REAL.
  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 SAXPY, SSWAP
  90. C***REVISION HISTORY (YYMMDD)
  91. C 790319 DATE WRITTEN
  92. C 890313 REVISION DATE from Version 3.2
  93. C 891214 Prologue converted to Version 4.0 format. (BAB)
  94. C 900326 Removed duplicate information from DESCRIPTION section.
  95. C (WRB)
  96. C 920501 Reformatted the REFERENCES section. (WRB)
  97. C***END PROLOGUE SCHDC
  98. INTEGER LDA,P,JPVT(*),JOB,INFO
  99. REAL A(LDA,*),WORK(*)
  100. C
  101. INTEGER PU,PL,PLP1,J,JP,JT,K,KB,KM1,KP1,L,MAXL
  102. REAL TEMP
  103. REAL MAXDIA
  104. LOGICAL SWAPK,NEGK
  105. C***FIRST EXECUTABLE STATEMENT SCHDC
  106. PL = 1
  107. PU = 0
  108. INFO = P
  109. IF (JOB .EQ. 0) GO TO 160
  110. C
  111. C PIVOTING HAS BEEN REQUESTED. REARRANGE THE
  112. C THE ELEMENTS ACCORDING TO JPVT.
  113. C
  114. DO 70 K = 1, P
  115. SWAPK = JPVT(K) .GT. 0
  116. NEGK = JPVT(K) .LT. 0
  117. JPVT(K) = K
  118. IF (NEGK) JPVT(K) = -JPVT(K)
  119. IF (.NOT.SWAPK) GO TO 60
  120. IF (K .EQ. PL) GO TO 50
  121. CALL SSWAP(PL-1,A(1,K),1,A(1,PL),1)
  122. TEMP = A(K,K)
  123. A(K,K) = A(PL,PL)
  124. A(PL,PL) = TEMP
  125. PLP1 = PL + 1
  126. IF (P .LT. PLP1) GO TO 40
  127. DO 30 J = PLP1, P
  128. IF (J .GE. K) GO TO 10
  129. TEMP = A(PL,J)
  130. A(PL,J) = A(J,K)
  131. A(J,K) = TEMP
  132. GO TO 20
  133. 10 CONTINUE
  134. IF (J .EQ. K) GO TO 20
  135. TEMP = A(K,J)
  136. A(K,J) = A(PL,J)
  137. A(PL,J) = TEMP
  138. 20 CONTINUE
  139. 30 CONTINUE
  140. 40 CONTINUE
  141. JPVT(K) = JPVT(PL)
  142. JPVT(PL) = K
  143. 50 CONTINUE
  144. PL = PL + 1
  145. 60 CONTINUE
  146. 70 CONTINUE
  147. PU = P
  148. IF (P .LT. PL) GO TO 150
  149. DO 140 KB = PL, P
  150. K = P - KB + PL
  151. IF (JPVT(K) .GE. 0) GO TO 130
  152. JPVT(K) = -JPVT(K)
  153. IF (PU .EQ. K) GO TO 120
  154. CALL SSWAP(K-1,A(1,K),1,A(1,PU),1)
  155. TEMP = A(K,K)
  156. A(K,K) = A(PU,PU)
  157. A(PU,PU) = TEMP
  158. KP1 = K + 1
  159. IF (P .LT. KP1) GO TO 110
  160. DO 100 J = KP1, P
  161. IF (J .GE. PU) GO TO 80
  162. TEMP = A(K,J)
  163. A(K,J) = A(J,PU)
  164. A(J,PU) = TEMP
  165. GO TO 90
  166. 80 CONTINUE
  167. IF (J .EQ. PU) GO TO 90
  168. TEMP = A(K,J)
  169. A(K,J) = A(PU,J)
  170. A(PU,J) = TEMP
  171. 90 CONTINUE
  172. 100 CONTINUE
  173. 110 CONTINUE
  174. JT = JPVT(K)
  175. JPVT(K) = JPVT(PU)
  176. JPVT(PU) = JT
  177. 120 CONTINUE
  178. PU = PU - 1
  179. 130 CONTINUE
  180. 140 CONTINUE
  181. 150 CONTINUE
  182. 160 CONTINUE
  183. DO 270 K = 1, P
  184. C
  185. C REDUCTION LOOP.
  186. C
  187. MAXDIA = A(K,K)
  188. KP1 = K + 1
  189. MAXL = K
  190. C
  191. C DETERMINE THE PIVOT ELEMENT.
  192. C
  193. IF (K .LT. PL .OR. K .GE. PU) GO TO 190
  194. DO 180 L = KP1, PU
  195. IF (A(L,L) .LE. MAXDIA) GO TO 170
  196. MAXDIA = A(L,L)
  197. MAXL = L
  198. 170 CONTINUE
  199. 180 CONTINUE
  200. 190 CONTINUE
  201. C
  202. C QUIT IF THE PIVOT ELEMENT IS NOT POSITIVE.
  203. C
  204. IF (MAXDIA .GT. 0.0E0) GO TO 200
  205. INFO = K - 1
  206. GO TO 280
  207. 200 CONTINUE
  208. IF (K .EQ. MAXL) GO TO 210
  209. C
  210. C START THE PIVOTING AND UPDATE JPVT.
  211. C
  212. KM1 = K - 1
  213. CALL SSWAP(KM1,A(1,K),1,A(1,MAXL),1)
  214. A(MAXL,MAXL) = A(K,K)
  215. A(K,K) = MAXDIA
  216. JP = JPVT(MAXL)
  217. JPVT(MAXL) = JPVT(K)
  218. JPVT(K) = JP
  219. 210 CONTINUE
  220. C
  221. C REDUCTION STEP. PIVOTING IS CONTAINED ACROSS THE ROWS.
  222. C
  223. WORK(K) = SQRT(A(K,K))
  224. A(K,K) = WORK(K)
  225. IF (P .LT. KP1) GO TO 260
  226. DO 250 J = KP1, P
  227. IF (K .EQ. MAXL) GO TO 240
  228. IF (J .GE. MAXL) GO TO 220
  229. TEMP = A(K,J)
  230. A(K,J) = A(J,MAXL)
  231. A(J,MAXL) = TEMP
  232. GO TO 230
  233. 220 CONTINUE
  234. IF (J .EQ. MAXL) GO TO 230
  235. TEMP = A(K,J)
  236. A(K,J) = A(MAXL,J)
  237. A(MAXL,J) = TEMP
  238. 230 CONTINUE
  239. 240 CONTINUE
  240. A(K,J) = A(K,J)/WORK(K)
  241. WORK(J) = A(K,J)
  242. TEMP = -A(K,J)
  243. CALL SAXPY(J-K,TEMP,WORK(KP1),1,A(KP1,J),1)
  244. 250 CONTINUE
  245. 260 CONTINUE
  246. 270 CONTINUE
  247. 280 CONTINUE
  248. RETURN
  249. END