cpbco.f 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. *DECK CPBCO
  2. SUBROUTINE CPBCO (ABD, LDA, N, M, RCOND, Z, INFO)
  3. C***BEGIN PROLOGUE CPBCO
  4. C***PURPOSE Factor a complex Hermitian positive definite matrix stored
  5. C in band form and estimate the condition number of the
  6. C matrix.
  7. C***LIBRARY SLATEC (LINPACK)
  8. C***CATEGORY D2D2
  9. C***TYPE COMPLEX (SPBCO-S, DPBCO-D, CPBCO-C)
  10. C***KEYWORDS BANDED, CONDITION NUMBER, LINEAR ALGEBRA, LINPACK,
  11. C MATRIX FACTORIZATION, POSITIVE DEFINITE
  12. C***AUTHOR Moler, C. B., (U. of New Mexico)
  13. C***DESCRIPTION
  14. C
  15. C CPBCO factors a complex Hermitian positive definite matrix
  16. C stored in band form and estimates the condition of the matrix.
  17. C
  18. C If RCOND is not needed, CPBFA is slightly faster.
  19. C To solve A*X = B , follow CPBCO by CPBSL.
  20. C To compute INVERSE(A)*C , follow CPBCO by CPBSL.
  21. C To compute DETERMINANT(A) , follow CPBCO by CPBDI.
  22. C
  23. C On Entry
  24. C
  25. C ABD COMPLEX(LDA, N)
  26. C the matrix to be factored. The columns of the upper
  27. C triangle are stored in the columns of ABD and the
  28. C diagonals of the upper triangle are stored in the
  29. C rows of ABD . See the comments below for details.
  30. C
  31. C LDA INTEGER
  32. C the leading dimension of the array ABD .
  33. C LDA must be .GE. M + 1 .
  34. C
  35. C N INTEGER
  36. C the order of the matrix A .
  37. C
  38. C M INTEGER
  39. C the number of diagonals above the main diagonal.
  40. C 0 .LE. M .LT. N .
  41. C
  42. C On Return
  43. C
  44. C ABD an upper triangular matrix R , stored in band
  45. C form, so that A = CTRANS(R)*R .
  46. C If INFO .NE. 0 , the factorization is not complete.
  47. C
  48. C RCOND REAL
  49. C an estimate of the reciprocal condition of A .
  50. C For the system A*X = B , relative perturbations
  51. C in A and B of size EPSILON may cause
  52. C relative perturbations in X of size EPSILON/RCOND .
  53. C If RCOND is so small that the logical expression
  54. C 1.0 + RCOND .EQ. 1.0
  55. C is true, then A may be singular to working
  56. C precision. In particular, RCOND is zero if
  57. C exact singularity is detected or the estimate
  58. C underflows. If INFO .NE. 0 , RCOND is unchanged.
  59. C
  60. C Z COMPLEX(N)
  61. C a work vector whose contents are usually unimportant.
  62. C If A is singular to working precision, then Z is
  63. C an approximate null vector in the sense that
  64. C NORM(A*Z) = RCOND*NORM(A)*NORM(Z) .
  65. C If INFO .NE. 0 , Z is unchanged.
  66. C
  67. C INFO INTEGER
  68. C = 0 for normal return.
  69. C = K signals an error condition. The leading minor
  70. C of order K is not positive definite.
  71. C
  72. C Band Storage
  73. C
  74. C If A is a Hermitian positive definite band matrix,
  75. C the following program segment will set up the input.
  76. C
  77. C M = (band width above diagonal)
  78. C DO 20 J = 1, N
  79. C I1 = MAX(1, J-M)
  80. C DO 10 I = I1, J
  81. C K = I-J+M+1
  82. C ABD(K,J) = A(I,J)
  83. C 10 CONTINUE
  84. C 20 CONTINUE
  85. C
  86. C This uses M + 1 rows of A , except for the M by M
  87. C upper left triangle, which is ignored.
  88. C
  89. C Example: If the original matrix is
  90. C
  91. C 11 12 13 0 0 0
  92. C 12 22 23 24 0 0
  93. C 13 23 33 34 35 0
  94. C 0 24 34 44 45 46
  95. C 0 0 35 45 55 56
  96. C 0 0 0 46 56 66
  97. C
  98. C then N = 6 , M = 2 and ABD should contain
  99. C
  100. C * * 13 24 35 46
  101. C * 12 23 34 45 56
  102. C 11 22 33 44 55 66
  103. C
  104. C***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.
  105. C Stewart, LINPACK Users' Guide, SIAM, 1979.
  106. C***ROUTINES CALLED CAXPY, CDOTC, CPBFA, CSSCAL, SCASUM
  107. C***REVISION HISTORY (YYMMDD)
  108. C 780814 DATE WRITTEN
  109. C 890531 Changed all specific intrinsics to generic. (WRB)
  110. C 890831 Modified array declarations. (WRB)
  111. C 890831 REVISION DATE from Version 3.2
  112. C 891214 Prologue converted to Version 4.0 format. (BAB)
  113. C 900326 Removed duplicate information from DESCRIPTION section.
  114. C (WRB)
  115. C 920501 Reformatted the REFERENCES section. (WRB)
  116. C***END PROLOGUE CPBCO
  117. INTEGER LDA,N,M,INFO
  118. COMPLEX ABD(LDA,*),Z(*)
  119. REAL RCOND
  120. C
  121. COMPLEX CDOTC,EK,T,WK,WKM
  122. REAL ANORM,S,SCASUM,SM,YNORM
  123. INTEGER I,J,J2,K,KB,KP1,L,LA,LB,LM,MU
  124. COMPLEX ZDUM,ZDUM2,CSIGN1
  125. REAL CABS1
  126. CABS1(ZDUM) = ABS(REAL(ZDUM)) + ABS(AIMAG(ZDUM))
  127. CSIGN1(ZDUM,ZDUM2) = CABS1(ZDUM)*(ZDUM2/CABS1(ZDUM2))
  128. C
  129. C FIND NORM OF A
  130. C
  131. C***FIRST EXECUTABLE STATEMENT CPBCO
  132. DO 30 J = 1, N
  133. L = MIN(J,M+1)
  134. MU = MAX(M+2-J,1)
  135. Z(J) = CMPLX(SCASUM(L,ABD(MU,J),1),0.0E0)
  136. K = J - L
  137. IF (M .LT. MU) GO TO 20
  138. DO 10 I = MU, M
  139. K = K + 1
  140. Z(K) = CMPLX(REAL(Z(K))+CABS1(ABD(I,J)),0.0E0)
  141. 10 CONTINUE
  142. 20 CONTINUE
  143. 30 CONTINUE
  144. ANORM = 0.0E0
  145. DO 40 J = 1, N
  146. ANORM = MAX(ANORM,REAL(Z(J)))
  147. 40 CONTINUE
  148. C
  149. C FACTOR
  150. C
  151. CALL CPBFA(ABD,LDA,N,M,INFO)
  152. IF (INFO .NE. 0) GO TO 180
  153. C
  154. C RCOND = 1/(NORM(A)*(ESTIMATE OF NORM(INVERSE(A)))) .
  155. C ESTIMATE = NORM(Z)/NORM(Y) WHERE A*Z = Y AND A*Y = E .
  156. C THE COMPONENTS OF E ARE CHOSEN TO CAUSE MAXIMUM LOCAL
  157. C GROWTH IN THE ELEMENTS OF W WHERE CTRANS(R)*W = E .
  158. C THE VECTORS ARE FREQUENTLY RESCALED TO AVOID OVERFLOW.
  159. C
  160. C SOLVE CTRANS(R)*W = E
  161. C
  162. EK = (1.0E0,0.0E0)
  163. DO 50 J = 1, N
  164. Z(J) = (0.0E0,0.0E0)
  165. 50 CONTINUE
  166. DO 110 K = 1, N
  167. IF (CABS1(Z(K)) .NE. 0.0E0) EK = CSIGN1(EK,-Z(K))
  168. IF (CABS1(EK-Z(K)) .LE. REAL(ABD(M+1,K))) GO TO 60
  169. S = REAL(ABD(M+1,K))/CABS1(EK-Z(K))
  170. CALL CSSCAL(N,S,Z,1)
  171. EK = CMPLX(S,0.0E0)*EK
  172. 60 CONTINUE
  173. WK = EK - Z(K)
  174. WKM = -EK - Z(K)
  175. S = CABS1(WK)
  176. SM = CABS1(WKM)
  177. WK = WK/ABD(M+1,K)
  178. WKM = WKM/ABD(M+1,K)
  179. KP1 = K + 1
  180. J2 = MIN(K+M,N)
  181. I = M + 1
  182. IF (KP1 .GT. J2) GO TO 100
  183. DO 70 J = KP1, J2
  184. I = I - 1
  185. SM = SM + CABS1(Z(J)+WKM*CONJG(ABD(I,J)))
  186. Z(J) = Z(J) + WK*CONJG(ABD(I,J))
  187. S = S + CABS1(Z(J))
  188. 70 CONTINUE
  189. IF (S .GE. SM) GO TO 90
  190. T = WKM - WK
  191. WK = WKM
  192. I = M + 1
  193. DO 80 J = KP1, J2
  194. I = I - 1
  195. Z(J) = Z(J) + T*CONJG(ABD(I,J))
  196. 80 CONTINUE
  197. 90 CONTINUE
  198. 100 CONTINUE
  199. Z(K) = WK
  200. 110 CONTINUE
  201. S = 1.0E0/SCASUM(N,Z,1)
  202. CALL CSSCAL(N,S,Z,1)
  203. C
  204. C SOLVE R*Y = W
  205. C
  206. DO 130 KB = 1, N
  207. K = N + 1 - KB
  208. IF (CABS1(Z(K)) .LE. REAL(ABD(M+1,K))) GO TO 120
  209. S = REAL(ABD(M+1,K))/CABS1(Z(K))
  210. CALL CSSCAL(N,S,Z,1)
  211. 120 CONTINUE
  212. Z(K) = Z(K)/ABD(M+1,K)
  213. LM = MIN(K-1,M)
  214. LA = M + 1 - LM
  215. LB = K - LM
  216. T = -Z(K)
  217. CALL CAXPY(LM,T,ABD(LA,K),1,Z(LB),1)
  218. 130 CONTINUE
  219. S = 1.0E0/SCASUM(N,Z,1)
  220. CALL CSSCAL(N,S,Z,1)
  221. C
  222. YNORM = 1.0E0
  223. C
  224. C SOLVE CTRANS(R)*V = Y
  225. C
  226. DO 150 K = 1, N
  227. LM = MIN(K-1,M)
  228. LA = M + 1 - LM
  229. LB = K - LM
  230. Z(K) = Z(K) - CDOTC(LM,ABD(LA,K),1,Z(LB),1)
  231. IF (CABS1(Z(K)) .LE. REAL(ABD(M+1,K))) GO TO 140
  232. S = REAL(ABD(M+1,K))/CABS1(Z(K))
  233. CALL CSSCAL(N,S,Z,1)
  234. YNORM = S*YNORM
  235. 140 CONTINUE
  236. Z(K) = Z(K)/ABD(M+1,K)
  237. 150 CONTINUE
  238. S = 1.0E0/SCASUM(N,Z,1)
  239. CALL CSSCAL(N,S,Z,1)
  240. YNORM = S*YNORM
  241. C
  242. C SOLVE R*Z = W
  243. C
  244. DO 170 KB = 1, N
  245. K = N + 1 - KB
  246. IF (CABS1(Z(K)) .LE. REAL(ABD(M+1,K))) GO TO 160
  247. S = REAL(ABD(M+1,K))/CABS1(Z(K))
  248. CALL CSSCAL(N,S,Z,1)
  249. YNORM = S*YNORM
  250. 160 CONTINUE
  251. Z(K) = Z(K)/ABD(M+1,K)
  252. LM = MIN(K-1,M)
  253. LA = M + 1 - LM
  254. LB = K - LM
  255. T = -Z(K)
  256. CALL CAXPY(LM,T,ABD(LA,K),1,Z(LB),1)
  257. 170 CONTINUE
  258. C MAKE ZNORM = 1.0
  259. S = 1.0E0/SCASUM(N,Z,1)
  260. CALL CSSCAL(N,S,Z,1)
  261. YNORM = S*YNORM
  262. C
  263. IF (ANORM .NE. 0.0E0) RCOND = YNORM/ANORM
  264. IF (ANORM .EQ. 0.0E0) RCOND = 0.0E0
  265. 180 CONTINUE
  266. RETURN
  267. END