cgbco.f 9.2 KB

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