snbco.f 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. *DECK SNBCO
  2. SUBROUTINE SNBCO (ABE, LDA, N, ML, MU, IPVT, RCOND, Z)
  3. C***BEGIN PROLOGUE SNBCO
  4. C***PURPOSE Factor a band matrix using Gaussian elimination and
  5. C estimate the condition number.
  6. C***LIBRARY SLATEC
  7. C***CATEGORY D2A2
  8. C***TYPE SINGLE PRECISION (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 SNBCO factors a real band matrix by Gaussian
  15. C elimination and estimates the condition of the matrix.
  16. C
  17. C If RCOND is not needed, SNBFA is slightly faster.
  18. C To solve A*X = B , follow SNBCO by SNBSL.
  19. C To compute INVERSE(A)*C , follow SNBCO by SNBSL.
  20. C To compute DETERMINANT(A) , follow SNBCO by SNBDI.
  21. C
  22. C On Entry
  23. C
  24. C ABE REAL(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 REAL(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 SASUM, SAXPY, SDOT, SNBFA, SSCAL
  120. C***REVISION HISTORY (YYMMDD)
  121. C 800723 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 SNBCO
  128. INTEGER LDA,N,ML,MU,IPVT(*)
  129. REAL ABE(LDA,*),Z(*)
  130. REAL RCOND
  131. C
  132. REAL SDOT,EK,T,WK,WKM
  133. REAL ANORM,S,SASUM,SM,YNORM
  134. INTEGER I,INFO,J,JU,K,KB,KP1,L,LDB,LM,LZ,M,ML1,MM,NL,NU
  135. C***FIRST EXECUTABLE STATEMENT SNBCO
  136. ML1=ML+1
  137. LDB = LDA - 1
  138. ANORM = 0.0E0
  139. DO 10 J = 1, N
  140. NU = MIN(MU,J-1)
  141. NL = MIN(ML,N-J)
  142. L = 1 + NU + NL
  143. ANORM = MAX(ANORM,SASUM(L,ABE(J+NL,ML1-NL),LDB))
  144. 10 CONTINUE
  145. C
  146. C FACTOR
  147. C
  148. CALL SNBFA(ABE,LDA,N,ML,MU,IPVT,INFO)
  149. C
  150. C RCOND = 1/(NORM(A)*(ESTIMATE OF NORM(INVERSE(A)))) .
  151. C ESTIMATE = NORM(Z)/NORM(Y) WHERE A*Z = Y AND TRANS(A)*Y = E .
  152. C TRANS(A) IS THE TRANSPOSE OF A . THE COMPONENTS OF E ARE
  153. C CHOSEN TO CAUSE MAXIMUM LOCAL GROWTH IN THE ELEMENTS OF W WHERE
  154. C TRANS(U)*W = E . THE VECTORS ARE FREQUENTLY RESCALED TO AVOID
  155. C OVERFLOW.
  156. C
  157. C SOLVE TRANS(U)*W = E
  158. C
  159. EK = 1.0E0
  160. DO 20 J = 1, N
  161. Z(J) = 0.0E0
  162. 20 CONTINUE
  163. M = ML + MU + 1
  164. JU = 0
  165. DO 100 K = 1, N
  166. IF (Z(K) .NE. 0.0E0) EK = SIGN(EK,-Z(K))
  167. IF (ABS(EK-Z(K)) .LE. ABS(ABE(K,ML1))) GO TO 30
  168. S = ABS(ABE(K,ML1))/ABS(EK-Z(K))
  169. CALL SSCAL(N,S,Z,1)
  170. EK = S*EK
  171. 30 CONTINUE
  172. WK = EK - Z(K)
  173. WKM = -EK - Z(K)
  174. S = ABS(WK)
  175. SM = ABS(WKM)
  176. IF (ABE(K,ML1) .EQ. 0.0E0) GO TO 40
  177. WK = WK/ABE(K,ML1)
  178. WKM = WKM/ABE(K,ML1)
  179. GO TO 50
  180. 40 CONTINUE
  181. WK = 1.0E0
  182. WKM = 1.0E0
  183. 50 CONTINUE
  184. KP1 = K + 1
  185. JU = MIN(MAX(JU,MU+IPVT(K)),N)
  186. MM = ML1
  187. IF (KP1 .GT. JU) GO TO 90
  188. DO 60 I = KP1, JU
  189. MM = MM + 1
  190. SM = SM + ABS(Z(I)+WKM*ABE(K,MM))
  191. Z(I) = Z(I) + WK*ABE(K,MM)
  192. S = S + ABS(Z(I))
  193. 60 CONTINUE
  194. IF (S .GE. SM) GO TO 80
  195. T = WKM -WK
  196. WK = WKM
  197. MM = ML1
  198. DO 70 I = KP1, JU
  199. MM = MM + 1
  200. Z(I) = Z(I) + T*ABE(K,MM)
  201. 70 CONTINUE
  202. 80 CONTINUE
  203. 90 CONTINUE
  204. Z(K) = WK
  205. 100 CONTINUE
  206. S = 1.0E0/SASUM(N,Z,1)
  207. CALL SSCAL(N,S,Z,1)
  208. C
  209. C SOLVE TRANS(L)*Y = W
  210. C
  211. DO 120 KB = 1, N
  212. K = N + 1 - KB
  213. NL = MIN(ML,N-K)
  214. IF (K .LT. N) Z(K) = Z(K) + SDOT(NL,ABE(K+NL,ML1-NL),-LDB,Z(K+1)
  215. 1 ,1)
  216. IF (ABS(Z(K)) .LE. 1.0E0) GO TO 110
  217. S = 1.0E0/ABS(Z(K))
  218. CALL SSCAL(N,S,Z,1)
  219. 110 CONTINUE
  220. L = IPVT(K)
  221. T = Z(L)
  222. Z(L) = Z(K)
  223. Z(K) = T
  224. 120 CONTINUE
  225. S = 1.0E0/SASUM(N,Z,1)
  226. CALL SSCAL(N,S,Z,1)
  227. C
  228. YNORM = 1.0E0
  229. C
  230. C SOLVE L*V = Y
  231. C
  232. DO 140 K = 1, N
  233. L = IPVT(K)
  234. T = Z(L)
  235. Z(L) = Z(K)
  236. Z(K) = T
  237. NL = MIN(ML,N-K)
  238. IF (K .LT. N) CALL SAXPY(NL,T,ABE(K+NL,ML1-NL),-LDB,Z(K+1),1)
  239. IF (ABS(Z(K)) .LE. 1.0E0) GO TO 130
  240. S = 1.0E0/ABS(Z(K))
  241. CALL SSCAL(N,S,Z,1)
  242. YNORM = S*YNORM
  243. 130 CONTINUE
  244. 140 CONTINUE
  245. S = 1.0E0/SASUM(N,Z,1)
  246. CALL SSCAL(N,S,Z,1)
  247. YNORM = S*YNORM
  248. C
  249. C SOLVE U*Z = V
  250. C
  251. DO 160 KB = 1, N
  252. K = N + 1 - KB
  253. IF (ABS(Z(K)) .LE. ABS(ABE(K,ML1))) GO TO 150
  254. S = ABS(ABE(K,ML1))/ABS(Z(K))
  255. CALL SSCAL(N,S,Z,1)
  256. YNORM = S*YNORM
  257. 150 CONTINUE
  258. IF (ABE(K,ML1) .NE. 0.0E0) Z(K) = Z(K)/ABE(K,ML1)
  259. IF (ABE(K,ML1) .EQ. 0.0E0) Z(K) = 1.0E0
  260. LM = MIN(K,M) - 1
  261. LZ = K - LM
  262. T = -Z(K)
  263. CALL SAXPY(LM,T,ABE(K-1,ML+2),-LDB,Z(LZ),1)
  264. 160 CONTINUE
  265. C MAKE ZNORM = 1.0E0
  266. S = 1.0E0/SASUM(N,Z,1)
  267. CALL SSCAL(N,S,Z,1)
  268. YNORM = S*YNORM
  269. C
  270. IF (ANORM .NE. 0.0E0) RCOND = YNORM/ANORM
  271. IF (ANORM .EQ. 0.0E0) RCOND = 0.0E0
  272. RETURN
  273. END