sgbco.f 8.8 KB

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