dpbco.f 8.5 KB

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