cnbco.f 8.9 KB

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