dllsia.f 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. *DECK DLLSIA
  2. SUBROUTINE DLLSIA (A, MDA, M, N, B, MDB, NB, RE, AE, KEY, MODE,
  3. + NP, KRANK, KSURE, RNORM, W, LW, IWORK, LIW, INFO)
  4. C***BEGIN PROLOGUE DLLSIA
  5. C***PURPOSE Solve linear least squares problems by performing a QR
  6. C factorization of the input matrix using Householder
  7. C transformations. Emphasis is put on detecting possible
  8. C rank deficiency.
  9. C***LIBRARY SLATEC
  10. C***CATEGORY D9, D5
  11. C***TYPE DOUBLE PRECISION (LLSIA-S, DLLSIA-D)
  12. C***KEYWORDS LINEAR LEAST SQUARES, QR FACTORIZATION
  13. C***AUTHOR Manteuffel, T. A., (LANL)
  14. C***DESCRIPTION
  15. C
  16. C DLLSIA computes the least squares solution(s) to the problem AX=B
  17. C where A is an M by N matrix with M.GE.N and B is the M by NB
  18. C matrix of right hand sides. User input bounds on the uncertainty
  19. C in the elements of A are used to detect numerical rank deficiency.
  20. C The algorithm employs a row and column pivot strategy to
  21. C minimize the growth of uncertainty and round-off errors.
  22. C
  23. C DLLSIA requires (MDA+6)*N + (MDB+1)*NB + M dimensioned space
  24. C
  25. C ******************************************************************
  26. C * *
  27. C * WARNING - All input arrays are changed on exit. *
  28. C * *
  29. C ******************************************************************
  30. C SUBROUTINE DLLSIA(A,MDA,M,N,B,MDB,NB,RE,AE,KEY,MODE,NP,
  31. C 1 KRANK,KSURE,RNORM,W,LW,IWORK,LIW,INFO)
  32. C
  33. C Input..All TYPE REAL variables are DOUBLE PRECISION
  34. C
  35. C A(,) Linear coefficient matrix of AX=B, with MDA the
  36. C MDA,M,N actual first dimension of A in the calling program.
  37. C M is the row dimension (no. of EQUATIONS of the
  38. C problem) and N the col dimension (no. of UNKNOWNS).
  39. C Must have MDA.GE.M and M.GE.N.
  40. C
  41. C B(,) Right hand side(s), with MDB the actual first
  42. C MDB,NB dimension of B in the calling program. NB is the
  43. C number of M by 1 right hand sides. Must have
  44. C MDB.GE.M. If NB = 0, B is never accessed.
  45. C
  46. C ******************************************************************
  47. C * *
  48. C * Note - Use of RE and AE are what make this *
  49. C * code significantly different from *
  50. C * other linear least squares solvers. *
  51. C * However, the inexperienced user is *
  52. C * advised to set RE=0.,AE=0.,KEY=0. *
  53. C * *
  54. C ******************************************************************
  55. C RE(),AE(),KEY
  56. C RE() RE() is a vector of length N such that RE(I) is
  57. C the maximum relative uncertainty in column I of
  58. C the matrix A. The values of RE() must be between
  59. C 0 and 1. A minimum of 10*machine precision will
  60. C be enforced.
  61. C
  62. C AE() AE() is a vector of length N such that AE(I) is
  63. C the maximum absolute uncertainty in column I of
  64. C the matrix A. The values of AE() must be greater
  65. C than or equal to 0.
  66. C
  67. C KEY For ease of use, RE and AE may be input as either
  68. C vectors or scalars. If a scalar is input, the algo-
  69. C rithm will use that value for each column of A.
  70. C The parameter key indicates whether scalars or
  71. C vectors are being input.
  72. C KEY=0 RE scalar AE scalar
  73. C KEY=1 RE vector AE scalar
  74. C KEY=2 RE scalar AE vector
  75. C KEY=3 RE vector AE vector
  76. C
  77. C MODE The integer mode indicates how the routine
  78. C is to react if rank deficiency is detected.
  79. C If MODE = 0 return immediately, no solution
  80. C 1 compute truncated solution
  81. C 2 compute minimal length solution
  82. C The inexperienced user is advised to set MODE=0
  83. C
  84. C NP The first NP columns of A will not be interchanged
  85. C with other columns even though the pivot strategy
  86. C would suggest otherwise.
  87. C The inexperienced user is advised to set NP=0.
  88. C
  89. C WORK() A real work array dimensioned 5*N. However, if
  90. C RE or AE have been specified as vectors, dimension
  91. C WORK 4*N. If both RE and AE have been specified
  92. C as vectors, dimension WORK 3*N.
  93. C
  94. C LW Actual dimension of WORK
  95. C
  96. C IWORK() Integer work array dimensioned at least N+M.
  97. C
  98. C LIW Actual dimension of IWORK.
  99. C
  100. C INFO Is a flag which provides for the efficient
  101. C solution of subsequent problems involving the
  102. C same A but different B.
  103. C If INFO = 0 original call
  104. C INFO = 1 subsequent calls
  105. C On subsequent calls, the user must supply A, KRANK,
  106. C LW, IWORK, LIW, and the first 2*N locations of WORK
  107. C as output by the original call to DLLSIA. MODE must
  108. C be equal to the value of MODE in the original call.
  109. C If MODE.LT.2, only the first N locations of WORK
  110. C are accessed. AE, RE, KEY, and NP are not accessed.
  111. C
  112. C Output..All TYPE REAL variable are DOUBLE PRECISION
  113. C
  114. C A(,) Contains the upper triangular part of the reduced
  115. C matrix and the transformation information. It togeth
  116. C with the first N elements of WORK (see below)
  117. C completely specify the QR factorization of A.
  118. C
  119. C B(,) Contains the N by NB solution matrix for X.
  120. C
  121. C KRANK,KSURE The numerical rank of A, based upon the relative
  122. C and absolute bounds on uncertainty, is bounded
  123. C above by KRANK and below by KSURE. The algorithm
  124. C returns a solution based on KRANK. KSURE provides
  125. C an indication of the precision of the rank.
  126. C
  127. C RNORM() Contains the Euclidean length of the NB residual
  128. C vectors B(I)-AX(I), I=1,NB.
  129. C
  130. C WORK() The first N locations of WORK contain values
  131. C necessary to reproduce the Householder
  132. C transformation.
  133. C
  134. C IWORK() The first N locations contain the order in
  135. C which the columns of A were used. The next
  136. C M locations contain the order in which the
  137. C rows of A were used.
  138. C
  139. C INFO Flag to indicate status of computation on completion
  140. C -1 Parameter error(s)
  141. C 0 - Rank deficient, no solution
  142. C 1 - Rank deficient, truncated solution
  143. C 2 - Rank deficient, minimal length solution
  144. C 3 - Numerical rank 0, zero solution
  145. C 4 - Rank .LT. NP
  146. C 5 - Full rank
  147. C
  148. C***REFERENCES T. Manteuffel, An interval analysis approach to rank
  149. C determination in linear least squares problems,
  150. C Report SAND80-0655, Sandia Laboratories, June 1980.
  151. C***ROUTINES CALLED D1MACH, DU11LS, DU12LS, XERMSG
  152. C***REVISION HISTORY (YYMMDD)
  153. C 810801 DATE WRITTEN
  154. C 890831 Modified array declarations. (WRB)
  155. C 891006 Cosmetic changes to prologue. (WRB)
  156. C 891009 Removed unreferenced variable. (WRB)
  157. C 891009 REVISION DATE from Version 3.2
  158. C 891214 Prologue converted to Version 4.0 format. (BAB)
  159. C 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)
  160. C 900510 Fixed an error message. (RWC)
  161. C 920501 Reformatted the REFERENCES section. (WRB)
  162. C***END PROLOGUE DLLSIA
  163. IMPLICIT DOUBLE PRECISION (A-H,O-Z)
  164. DOUBLE PRECISION D1MACH
  165. DIMENSION A(MDA,*),B(MDB,*),RE(*),AE(*),RNORM(*),W(*)
  166. INTEGER IWORK(*)
  167. C
  168. C***FIRST EXECUTABLE STATEMENT DLLSIA
  169. IF(INFO.LT.0 .OR. INFO.GT.1) GO TO 514
  170. IT=INFO
  171. INFO=-1
  172. IF(NB.EQ.0 .AND. IT.EQ.1) GO TO 501
  173. IF(M.LT.1) GO TO 502
  174. IF(N.LT.1) GO TO 503
  175. IF(N.GT.M) GO TO 504
  176. IF(MDA.LT.M) GO TO 505
  177. IF(LIW.LT.M+N) GO TO 506
  178. IF(MODE.LT.0 .OR. MODE.GT.3) GO TO 515
  179. IF(NB.EQ.0) GO TO 4
  180. IF(NB.LT.0) GO TO 507
  181. IF(MDB.LT.M) GO TO 508
  182. IF(IT.EQ.0) GO TO 4
  183. GO TO 400
  184. 4 IF(KEY.LT.0.OR.KEY.GT.3) GO TO 509
  185. IF(KEY.EQ.0 .AND. LW.LT.5*N) GO TO 510
  186. IF(KEY.EQ.1 .AND. LW.LT.4*N) GO TO 510
  187. IF(KEY.EQ.2 .AND. LW.LT.4*N) GO TO 510
  188. IF(KEY.EQ.3 .AND. LW.LT.3*N) GO TO 510
  189. IF(NP.LT.0 .OR. NP.GT.N) GO TO 516
  190. C
  191. EPS=10.*D1MACH(3)
  192. N1=1
  193. N2=N1+N
  194. N3=N2+N
  195. N4=N3+N
  196. N5=N4+N
  197. C
  198. IF(KEY.EQ.1) GO TO 100
  199. IF(KEY.EQ.2) GO TO 200
  200. IF(KEY.EQ.3) GO TO 300
  201. C
  202. IF(RE(1).LT.0.0D0) GO TO 511
  203. IF(RE(1).GT.1.0D0) GO TO 512
  204. IF(RE(1).LT.EPS) RE(1)=EPS
  205. IF(AE(1).LT.0.0D0) GO TO 513
  206. DO 20 I=1,N
  207. W(N4-1+I)=RE(1)
  208. W(N5-1+I)=AE(1)
  209. 20 CONTINUE
  210. CALL DU11LS(A,MDA,M,N,W(N4),W(N5),MODE,NP,KRANK,KSURE,
  211. 1 W(N1),W(N2),W(N3),IWORK(N1),IWORK(N2))
  212. GO TO 400
  213. C
  214. 100 CONTINUE
  215. IF(AE(1).LT.0.0D0) GO TO 513
  216. DO 120 I=1,N
  217. IF(RE(I).LT.0.0D0) GO TO 511
  218. IF(RE(I).GT.1.0D0) GO TO 512
  219. IF(RE(I).LT.EPS) RE(I)=EPS
  220. W(N4-1+I)=AE(1)
  221. 120 CONTINUE
  222. CALL DU11LS(A,MDA,M,N,RE,W(N4),MODE,NP,KRANK,KSURE,
  223. 1 W(N1),W(N2),W(N3),IWORK(N1),IWORK(N2))
  224. GO TO 400
  225. C
  226. 200 CONTINUE
  227. IF(RE(1).LT.0.0D0) GO TO 511
  228. IF(RE(1).GT.1.0D0) GO TO 512
  229. IF(RE(1).LT.EPS) RE(1)=EPS
  230. DO 220 I=1,N
  231. W(N4-1+I)=RE(1)
  232. IF(AE(I).LT.0.0D0) GO TO 513
  233. 220 CONTINUE
  234. CALL DU11LS(A,MDA,M,N,W(N4),AE,MODE,NP,KRANK,KSURE,
  235. 1 W(N1),W(N2),W(N3),IWORK(N1),IWORK(N2))
  236. GO TO 400
  237. C
  238. 300 CONTINUE
  239. DO 320 I=1,N
  240. IF(RE(I).LT.0.0D0) GO TO 511
  241. IF(RE(I).GT.1.0D0) GO TO 512
  242. IF(RE(I).LT.EPS) RE(I)=EPS
  243. IF(AE(I).LT.0.0D0) GO TO 513
  244. 320 CONTINUE
  245. CALL DU11LS(A,MDA,M,N,RE,AE,MODE,NP,KRANK,KSURE,
  246. 1 W(N1),W(N2),W(N3),IWORK(N1),IWORK(N2))
  247. C
  248. C DETERMINE INFO
  249. C
  250. 400 IF(KRANK.NE.N) GO TO 402
  251. INFO=5
  252. GO TO 410
  253. 402 IF(KRANK.NE.0) GO TO 404
  254. INFO=3
  255. GO TO 410
  256. 404 IF(KRANK.GE.NP) GO TO 406
  257. INFO=4
  258. RETURN
  259. 406 INFO=MODE
  260. IF(MODE.EQ.0) RETURN
  261. 410 IF(NB.EQ.0) RETURN
  262. C
  263. C SOLUTION PHASE
  264. C
  265. N1=1
  266. N2=N1+N
  267. N3=N2+N
  268. IF(INFO.EQ.2) GO TO 420
  269. IF(LW.LT.N2-1) GO TO 510
  270. CALL DU12LS(A,MDA,M,N,B,MDB,NB,MODE,KRANK,
  271. 1 RNORM,W(N1),W(N1),IWORK(N1),IWORK(N2))
  272. RETURN
  273. C
  274. 420 IF(LW.LT.N3-1) GO TO 510
  275. CALL DU12LS(A,MDA,M,N,B,MDB,NB,MODE,KRANK,
  276. 1 RNORM,W(N1),W(N2),IWORK(N1),IWORK(N2))
  277. RETURN
  278. C
  279. C ERROR MESSAGES
  280. C
  281. 501 CALL XERMSG ('SLATEC', 'DLLSIA',
  282. + 'SOLUTION ONLY (INFO=1) BUT NO RIGHT HAND SIDE (NB=0)', 1, 0)
  283. RETURN
  284. 502 CALL XERMSG ('SLATEC', 'DLLSIA', 'M.LT.1', 2, 1)
  285. RETURN
  286. 503 CALL XERMSG ('SLATEC', 'DLLSIA', 'N.LT.1', 2, 1)
  287. RETURN
  288. 504 CALL XERMSG ('SLATEC', 'DLLSIA', 'N.GT.M', 2, 1)
  289. RETURN
  290. 505 CALL XERMSG ('SLATEC', 'DLLSIA', 'MDA.LT.M', 2, 1)
  291. RETURN
  292. 506 CALL XERMSG ('SLATEC', 'DLLSIA', 'LIW.LT.M+N', 2, 1)
  293. RETURN
  294. 507 CALL XERMSG ('SLATEC', 'DLLSIA', 'NB.LT.0', 2, 1)
  295. RETURN
  296. 508 CALL XERMSG ('SLATEC', 'DLLSIA', 'MDB.LT.M', 2, 1)
  297. RETURN
  298. 509 CALL XERMSG ('SLATEC', 'DLLSIA', 'KEY OUT OF RANGE', 2, 1)
  299. RETURN
  300. 510 CALL XERMSG ('SLATEC', 'DLLSIA', 'INSUFFICIENT WORK SPACE', 8, 1)
  301. INFO=-1
  302. RETURN
  303. 511 CALL XERMSG ('SLATEC', 'DLLSIA', 'RE(I) .LT. 0', 2, 1)
  304. RETURN
  305. 512 CALL XERMSG ('SLATEC', 'DLLSIA', 'RE(I) .GT. 1', 2, 1)
  306. RETURN
  307. 513 CALL XERMSG ('SLATEC', 'DLLSIA', 'AE(I) .LT. 0', 2, 1)
  308. RETURN
  309. 514 CALL XERMSG ('SLATEC', 'DLLSIA', 'INFO OUT OF RANGE', 2, 1)
  310. RETURN
  311. 515 CALL XERMSG ('SLATEC', 'DLLSIA', 'MODE OUT OF RANGE', 2, 1)
  312. RETURN
  313. 516 CALL XERMSG ('SLATEC', 'DLLSIA', 'NP OUT OF RANGE', 2, 1)
  314. RETURN
  315. END