ulsia.f 12 KB

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