dbndsl.f 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. *DECK DBNDSL
  2. SUBROUTINE DBNDSL (MODE, G, MDG, NB, IP, IR, X, N, RNORM)
  3. C***BEGIN PROLOGUE DBNDSL
  4. C***PURPOSE Solve the least squares problem for a banded matrix using
  5. C sequential accumulation of rows of the data matrix.
  6. C Exactly one right-hand side vector is permitted.
  7. C***LIBRARY SLATEC
  8. C***CATEGORY D9
  9. C***TYPE DOUBLE PRECISION (BNDSOL-S, DBNDSL-D)
  10. C***KEYWORDS BANDED MATRIX, CURVE FITTING, LEAST SQUARES
  11. C***AUTHOR Lawson, C. L., (JPL)
  12. C Hanson, R. J., (SNLA)
  13. C***DESCRIPTION
  14. C
  15. C These subroutines solve the least squares problem Ax = b for
  16. C banded matrices A using sequential accumulation of rows of the
  17. C data matrix. Exactly one right-hand side vector is permitted.
  18. C
  19. C These subroutines are intended for the type of least squares
  20. C systems that arise in applications such as curve or surface
  21. C fitting of data. The least squares equations are accumulated and
  22. C processed using only part of the data. This requires a certain
  23. C user interaction during the solution of Ax = b.
  24. C
  25. C Specifically, suppose the data matrix (A B) is row partitioned
  26. C into Q submatrices. Let (E F) be the T-th one of these
  27. C submatrices where E = (0 C 0). Here the dimension of E is MT by N
  28. C and the dimension of C is MT by NB. The value of NB is the
  29. C bandwidth of A. The dimensions of the leading block of zeros in E
  30. C are MT by JT-1.
  31. C
  32. C The user of the subroutine DBNDAC provides MT,JT,C and F for
  33. C T=1,...,Q. Not all of this data must be supplied at once.
  34. C
  35. C Following the processing of the various blocks (E F), the matrix
  36. C (A B) has been transformed to the form (R D) where R is upper
  37. C triangular and banded with bandwidth NB. The least squares
  38. C system Rx = d is then easily solved using back substitution by
  39. C executing the statement CALL DBNDSL(1,...). The sequence of
  40. C values for JT must be nondecreasing. This may require some
  41. C preliminary interchanges of rows and columns of the matrix A.
  42. C
  43. C The primary reason for these subroutines is that the total
  44. C processing can take place in a working array of dimension MU by
  45. C NB+1. An acceptable value for MU is
  46. C
  47. C MU = MAX(MT + N + 1),
  48. C
  49. C where N is the number of unknowns.
  50. C
  51. C Here the maximum is taken over all values of MT for T=1,...,Q.
  52. C Notice that MT can be taken to be a small as one, showing that
  53. C MU can be as small as N+2. The subprogram DBNDAC processes the
  54. C rows more efficiently if MU is large enough so that each new
  55. C block (C F) has a distinct value of JT.
  56. C
  57. C The four principle parts of these algorithms are obtained by the
  58. C following call statements
  59. C
  60. C CALL DBNDAC(...) Introduce new blocks of data.
  61. C
  62. C CALL DBNDSL(1,...)Compute solution vector and length of
  63. C residual vector.
  64. C
  65. C CALL DBNDSL(2,...)Given any row vector H solve YR = H for the
  66. C row vector Y.
  67. C
  68. C CALL DBNDSL(3,...)Given any column vector W solve RZ = W for
  69. C the column vector Z.
  70. C
  71. C The dots in the above call statements indicate additional
  72. C arguments that will be specified in the following paragraphs.
  73. C
  74. C The user must dimension the array appearing in the call list..
  75. C G(MDG,NB+1)
  76. C
  77. C Description of calling sequence for DBNDAC..
  78. C
  79. C The entire set of parameters for DBNDAC are
  80. C
  81. C Input.. All Type REAL variables are DOUBLE PRECISION
  82. C
  83. C G(*,*) The working array into which the user will
  84. C place the MT by NB+1 block (C F) in rows IR
  85. C through IR+MT-1, columns 1 through NB+1.
  86. C See descriptions of IR and MT below.
  87. C
  88. C MDG The number of rows in the working array
  89. C G(*,*). The value of MDG should be .GE. MU.
  90. C The value of MU is defined in the abstract
  91. C of these subprograms.
  92. C
  93. C NB The bandwidth of the data matrix A.
  94. C
  95. C IP Set by the user to the value 1 before the
  96. C first call to DBNDAC. Its subsequent value
  97. C is controlled by DBNDAC to set up for the
  98. C next call to DBNDAC.
  99. C
  100. C IR Index of the row of G(*,*) where the user is
  101. C the user to the value 1 before the first call
  102. C to DBNDAC. Its subsequent value is controlled
  103. C by DBNDAC. A value of IR .GT. MDG is considered
  104. C an error.
  105. C
  106. C MT,JT Set by the user to indicate respectively the
  107. C number of new rows of data in the block and
  108. C the index of the first nonzero column in that
  109. C set of rows (E F) = (0 C 0 F) being processed.
  110. C Output.. All Type REAL variables are DOUBLE PRECISION
  111. C
  112. C G(*,*) The working array which will contain the
  113. C processed rows of that part of the data
  114. C matrix which has been passed to DBNDAC.
  115. C
  116. C IP,IR The values of these arguments are advanced by
  117. C DBNDAC to be ready for storing and processing
  118. C a new block of data in G(*,*).
  119. C
  120. C Description of calling sequence for DBNDSL..
  121. C
  122. C The user must dimension the arrays appearing in the call list..
  123. C
  124. C G(MDG,NB+1), X(N)
  125. C
  126. C The entire set of parameters for DBNDSL are
  127. C
  128. C Input..
  129. C
  130. C MODE Set by the user to one of the values 1, 2, or
  131. C 3. These values respectively indicate that
  132. C the solution of AX = B, YR = H or RZ = W is
  133. C required.
  134. C
  135. C G(*,*),MDG, These arguments all have the same meaning and
  136. C NB,IP,IR contents as following the last call to DBNDAC.
  137. C
  138. C X(*) With mode=2 or 3 this array contains,
  139. C respectively, the right-side vectors H or W of
  140. C the systems YR = H or RZ = W.
  141. C
  142. C N The number of variables in the solution
  143. C vector. If any of the N diagonal terms are
  144. C zero the subroutine DBNDSL prints an
  145. C appropriate message. This condition is
  146. C considered an error.
  147. C
  148. C Output..
  149. C
  150. C X(*) This array contains the solution vectors X,
  151. C Y or Z of the systems AX = B, YR = H or
  152. C RZ = W depending on the value of MODE=1,
  153. C 2 or 3.
  154. C
  155. C RNORM If MODE=1 RNORM is the Euclidean length of the
  156. C residual vector AX-B. When MODE=2 or 3 RNORM
  157. C is set to zero.
  158. C
  159. C Remarks..
  160. C
  161. C To obtain the upper triangular matrix and transformed right-hand
  162. C side vector D so that the super diagonals of R form the columns
  163. C of G(*,*), execute the following Fortran statements.
  164. C
  165. C NBP1=NB+1
  166. C
  167. C DO 10 J=1, NBP1
  168. C
  169. C 10 G(IR,J) = 0.E0
  170. C
  171. C MT=1
  172. C
  173. C JT=N+1
  174. C
  175. C CALL DBNDAC(G,MDG,NB,IP,IR,MT,JT)
  176. C
  177. C***REFERENCES C. L. Lawson and R. J. Hanson, Solving Least Squares
  178. C Problems, Prentice-Hall, Inc., 1974, Chapter 27.
  179. C***ROUTINES CALLED XERMSG
  180. C***REVISION HISTORY (YYMMDD)
  181. C 790101 DATE WRITTEN
  182. C 890531 Changed all specific intrinsics to generic. (WRB)
  183. C 890831 Modified array declarations. (WRB)
  184. C 891006 Cosmetic changes to prologue. (WRB)
  185. C 891006 REVISION DATE from Version 3.2
  186. C 891214 Prologue converted to Version 4.0 format. (BAB)
  187. C 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)
  188. C 920501 Reformatted the REFERENCES section. (WRB)
  189. C***END PROLOGUE DBNDSL
  190. IMPLICIT DOUBLE PRECISION (A-H,O-Z)
  191. DIMENSION G(MDG,*),X(*)
  192. C***FIRST EXECUTABLE STATEMENT DBNDSL
  193. ZERO=0.D0
  194. C
  195. RNORM=ZERO
  196. GO TO (10,90,50), MODE
  197. C ********************* MODE = 1
  198. C ALG. STEP 26
  199. 10 DO 20 J=1,N
  200. X(J)=G(J,NB+1)
  201. 20 CONTINUE
  202. RSQ=ZERO
  203. NP1=N+1
  204. IRM1=IR-1
  205. IF (NP1.GT.IRM1) GO TO 40
  206. DO 30 J=NP1,IRM1
  207. RSQ=RSQ+G(J,NB+1)**2
  208. 30 CONTINUE
  209. RNORM=SQRT(RSQ)
  210. 40 CONTINUE
  211. C ********************* MODE = 3
  212. C ALG. STEP 27
  213. 50 DO 80 II=1,N
  214. I=N+1-II
  215. C ALG. STEP 28
  216. S=ZERO
  217. L=MAX(0,I-IP)
  218. C ALG. STEP 29
  219. IF (I.EQ.N) GO TO 70
  220. C ALG. STEP 30
  221. IE=MIN(N+1-I,NB)
  222. DO 60 J=2,IE
  223. JG=J+L
  224. IX=I-1+J
  225. S=S+G(I,JG)*X(IX)
  226. 60 CONTINUE
  227. C ALG. STEP 31
  228. 70 IF (G(I,L+1)) 80,130,80
  229. 80 X(I)=(X(I)-S)/G(I,L+1)
  230. C ALG. STEP 32
  231. RETURN
  232. C ********************* MODE = 2
  233. 90 DO 120 J=1,N
  234. S=ZERO
  235. IF (J.EQ.1) GO TO 110
  236. I1=MAX(1,J-NB+1)
  237. I2=J-1
  238. DO 100 I=I1,I2
  239. L=J-I+1+MAX(0,I-IP)
  240. S=S+X(I)*G(I,L)
  241. 100 CONTINUE
  242. 110 L=MAX(0,J-IP)
  243. IF (G(J,L+1)) 120,130,120
  244. 120 X(J)=(X(J)-S)/G(J,L+1)
  245. RETURN
  246. C
  247. 130 CONTINUE
  248. NERR=1
  249. IOPT=2
  250. CALL XERMSG ('SLATEC', 'DBNDSL',
  251. + 'A ZERO DIAGONAL TERM IS IN THE N BY N UPPER TRIANGULAR ' //
  252. + 'MATRIX.', NERR, IOPT)
  253. RETURN
  254. END