spbco.f 8.4 KB

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