dulsia.f 12 KB

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