llsia.f 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. *DECK LLSIA
  2. SUBROUTINE LLSIA (A, MDA, M, N, B, MDB, NB, RE, AE, KEY, MODE, NP,
  3. + KRANK, KSURE, RNORM, W, LW, IWORK, LIW, INFO)
  4. C***BEGIN PROLOGUE LLSIA
  5. C***PURPOSE Solve a linear least squares problems by performing a QR
  6. C factorization of the 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 SINGLE 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 LLSIA 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 LLSIA 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 LLSIA(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..
  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 LLSIA. 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..
  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 R1MACH, U11LS, U12LS, XERMSG
  152. C***REVISION HISTORY (YYMMDD)
  153. C 810801 DATE WRITTEN
  154. C 890831 Modified array declarations. (WRB)
  155. C 891009 Removed unreferenced variable. (WRB)
  156. C 891009 REVISION DATE from Version 3.2
  157. C 891214 Prologue converted to Version 4.0 format. (BAB)
  158. C 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)
  159. C 900510 Fixed an error message. (RWC)
  160. C 920501 Reformatted the REFERENCES section. (WRB)
  161. C***END PROLOGUE LLSIA
  162. DIMENSION A(MDA,*),B(MDB,*),RE(*),AE(*),RNORM(*),W(*)
  163. INTEGER IWORK(*)
  164. C
  165. C***FIRST EXECUTABLE STATEMENT LLSIA
  166. IF(INFO.LT.0 .OR. INFO.GT.1) GO TO 514
  167. IT=INFO
  168. INFO=-1
  169. IF(NB.EQ.0 .AND. IT.EQ.1) GO TO 501
  170. IF(M.LT.1) GO TO 502
  171. IF(N.LT.1) GO TO 503
  172. IF(N.GT.M) GO TO 504
  173. IF(MDA.LT.M) GO TO 505
  174. IF(LIW.LT.M+N) GO TO 506
  175. IF(MODE.LT.0 .OR. MODE.GT.3) GO TO 515
  176. IF(NB.EQ.0) GO TO 4
  177. IF(NB.LT.0) GO TO 507
  178. IF(MDB.LT.M) GO TO 508
  179. IF(IT.EQ.0) GO TO 4
  180. GO TO 400
  181. 4 IF(KEY.LT.0.OR.KEY.GT.3) GO TO 509
  182. IF(KEY.EQ.0 .AND. LW.LT.5*N) GO TO 510
  183. IF(KEY.EQ.1 .AND. LW.LT.4*N) GO TO 510
  184. IF(KEY.EQ.2 .AND. LW.LT.4*N) GO TO 510
  185. IF(KEY.EQ.3 .AND. LW.LT.3*N) GO TO 510
  186. IF(NP.LT.0 .OR. NP.GT.N) GO TO 516
  187. C
  188. EPS=10.*R1MACH(4)
  189. N1=1
  190. N2=N1+N
  191. N3=N2+N
  192. N4=N3+N
  193. N5=N4+N
  194. C
  195. IF(KEY.EQ.1) GO TO 100
  196. IF(KEY.EQ.2) GO TO 200
  197. IF(KEY.EQ.3) GO TO 300
  198. C
  199. IF(RE(1).LT.0.0) GO TO 511
  200. IF(RE(1).GT.1.0) GO TO 512
  201. IF(RE(1).LT.EPS) RE(1)=EPS
  202. IF(AE(1).LT.0.0) GO TO 513
  203. DO 20 I=1,N
  204. W(N4-1+I)=RE(1)
  205. W(N5-1+I)=AE(1)
  206. 20 CONTINUE
  207. CALL U11LS(A,MDA,M,N,W(N4),W(N5),MODE,NP,KRANK,KSURE,
  208. 1 W(N1),W(N2),W(N3),IWORK(N1),IWORK(N2))
  209. GO TO 400
  210. C
  211. 100 CONTINUE
  212. IF(AE(1).LT.0.0) GO TO 513
  213. DO 120 I=1,N
  214. IF(RE(I).LT.0.0) GO TO 511
  215. IF(RE(I).GT.1.0) GO TO 512
  216. IF(RE(I).LT.EPS) RE(I)=EPS
  217. W(N4-1+I)=AE(1)
  218. 120 CONTINUE
  219. CALL U11LS(A,MDA,M,N,RE,W(N4),MODE,NP,KRANK,KSURE,
  220. 1 W(N1),W(N2),W(N3),IWORK(N1),IWORK(N2))
  221. GO TO 400
  222. C
  223. 200 CONTINUE
  224. IF(RE(1).LT.0.0) GO TO 511
  225. IF(RE(1).GT.1.0) GO TO 512
  226. IF(RE(1).LT.EPS) RE(1)=EPS
  227. DO 220 I=1,N
  228. W(N4-1+I)=RE(1)
  229. IF(AE(I).LT.0.0) GO TO 513
  230. 220 CONTINUE
  231. CALL U11LS(A,MDA,M,N,W(N4),AE,MODE,NP,KRANK,KSURE,
  232. 1 W(N1),W(N2),W(N3),IWORK(N1),IWORK(N2))
  233. GO TO 400
  234. C
  235. 300 CONTINUE
  236. DO 320 I=1,N
  237. IF(RE(I).LT.0.0) GO TO 511
  238. IF(RE(I).GT.1.0) GO TO 512
  239. IF(RE(I).LT.EPS) RE(I)=EPS
  240. IF(AE(I).LT.0.0) GO TO 513
  241. 320 CONTINUE
  242. CALL U11LS(A,MDA,M,N,RE,AE,MODE,NP,KRANK,KSURE,
  243. 1 W(N1),W(N2),W(N3),IWORK(N1),IWORK(N2))
  244. C
  245. C DETERMINE INFO
  246. C
  247. 400 IF(KRANK.NE.N) GO TO 402
  248. INFO=5
  249. GO TO 410
  250. 402 IF(KRANK.NE.0) GO TO 404
  251. INFO=3
  252. GO TO 410
  253. 404 IF(KRANK.GE.NP) GO TO 406
  254. INFO=4
  255. RETURN
  256. 406 INFO=MODE
  257. IF(MODE.EQ.0) RETURN
  258. 410 IF(NB.EQ.0) RETURN
  259. C
  260. C SOLUTION PHASE
  261. C
  262. N1=1
  263. N2=N1+N
  264. N3=N2+N
  265. IF(INFO.EQ.2) GO TO 420
  266. IF(LW.LT.N2-1) GO TO 510
  267. CALL U12LS(A,MDA,M,N,B,MDB,NB,MODE,KRANK,
  268. 1 RNORM,W(N1),W(N1),IWORK(N1),IWORK(N2))
  269. RETURN
  270. C
  271. 420 IF(LW.LT.N3-1) GO TO 510
  272. CALL U12LS(A,MDA,M,N,B,MDB,NB,MODE,KRANK,
  273. 1 RNORM,W(N1),W(N2),IWORK(N1),IWORK(N2))
  274. RETURN
  275. C
  276. C ERROR MESSAGES
  277. C
  278. 501 CALL XERMSG ('SLATEC', 'LLSIA',
  279. + 'SOLUTION ONLY (INFO=1) BUT NO RIGHT HAND SIDE (NB=0)', 1, 0)
  280. RETURN
  281. 502 CALL XERMSG ('SLATEC', 'LLSIA', 'M.LT.1', 2, 1)
  282. RETURN
  283. 503 CALL XERMSG ('SLATEC', 'LLSIA', 'N.LT.1', 2, 1)
  284. RETURN
  285. 504 CALL XERMSG ('SLATEC', 'LLSIA', 'N.GT.M', 2, 1)
  286. RETURN
  287. 505 CALL XERMSG ('SLATEC', 'LLSIA', 'MDA.LT.M', 2, 1)
  288. RETURN
  289. 506 CALL XERMSG ('SLATEC', 'LLSIA', 'LIW.LT.M+N', 2, 1)
  290. RETURN
  291. 507 CALL XERMSG ('SLATEC', 'LLSIA', 'NB.LT.0', 2, 1)
  292. RETURN
  293. 508 CALL XERMSG ('SLATEC', 'LLSIA', 'MDB.LT.M', 2, 1)
  294. RETURN
  295. 509 CALL XERMSG ('SLATEC', 'LLSIA', 'KEY OUT OF RANGE', 2, 1)
  296. RETURN
  297. 510 CALL XERMSG ('SLATEC', 'LLSIA', 'INSUFFICIENT WORK SPACE', 8, 1)
  298. INFO=-1
  299. RETURN
  300. 511 CALL XERMSG ('SLATEC', 'LLSIA', 'RE(I) .LT. 0', 2, 1)
  301. RETURN
  302. 512 CALL XERMSG ('SLATEC', 'LLSIA', 'RE(I) .GT. 1', 2, 1)
  303. RETURN
  304. 513 CALL XERMSG ('SLATEC', 'LLSIA', 'AE(I) .LT. 0', 2, 1)
  305. RETURN
  306. 514 CALL XERMSG ('SLATEC', 'LLSIA', 'INFO OUT OF RANGE', 2, 1)
  307. RETURN
  308. 515 CALL XERMSG ('SLATEC', 'LLSIA', 'MODE OUT OF RANGE', 2, 1)
  309. RETURN
  310. 516 CALL XERMSG ('SLATEC', 'LLSIA', 'NP OUT OF RANGE', 2, 1)
  311. RETURN
  312. END