Télécharger dqrsl.eso

Retour à la liste

Numérotation des lignes :

dqrsl
  1. C DQRSL SOURCE PV090527 23/02/07 11:58:38 11592
  2. subroutine dqrsl ( a, lda, n, k,qraux,y,qy,qty,b,rsd,ab,job,info)
  3.  
  4. c*****************************************************************************80
  5. c
  6. c! DQRSL computes transformations, projections, and least squares solutions.
  7. c
  8. c Discussion:
  9. c
  10. c DQRSL requires the output of DQRDC.
  11. c
  12. c For K .le. min(N,P), let AK be the matrix
  13. c
  14. c AK = ( A(JPVT(1)), A(JPVT(2)), ..., A(JPVT(K)) )
  15. c
  16. c formed from columns JPVT(1), ..., JPVT(K) of the original
  17. c N by P matrix A that was input to DQRDC. If no pivoting was
  18. c done, AK consists of the first K columns of A in their
  19. c original order. DQRDC produces a factored orthogonal matrix Q
  20. c and an upper triangular matrix R such that
  21. c
  22. c AK = Q * (R)
  23. c (0)
  24. c
  25. c This information is contained in coded form in the arrays
  26. c A and QRAUX.
  27. c
  28. c The parameters QY, QTY, B, RSD, and AB are not referenced
  29. c if their computation is not requested and in this case
  30. c can be replaced by dummy variables in the calling program.
  31. c To save storage, the user may in some cases use the same
  32. c array for different parameters in the calling sequence. A
  33. c frequently occuring example is when one wishes to compute
  34. c any of B, RSD, or AB and does not need Y or QTY. In this
  35. c case one may identify Y, QTY, and one of B, RSD, or AB, while
  36. c providing separate arrays for anything else that is to be
  37. c computed.
  38. c
  39. c Thus the calling sequence
  40. c
  41. c call dqrsl ( a, lda, n, k, qraux, y, dum, y, b, y, dum, 110, info )
  42. c
  43. c will result in the computation of B and RSD, with RSD
  44. c overwriting Y. More generally, each item in the following
  45. c list contains groups of permissible identifications for
  46. c a single calling sequence.
  47. c
  48. c 1. (Y,QTY,B) (RSD) (AB) (QY)
  49. c
  50. c 2. (Y,QTY,RSD) (B) (AB) (QY)
  51. c
  52. c 3. (Y,QTY,AB) (B) (RSD) (QY)
  53. c
  54. c 4. (Y,QY) (QTY,B) (RSD) (AB)
  55. c
  56. c 5. (Y,QY) (QTY,RSD) (B) (AB)
  57. c
  58. c 6. (Y,QY) (QTY,AB) (B) (RSD)
  59. c
  60. c In any group the value returned in the array allocated to
  61. c the group corresponds to the last member of the group.
  62. c
  63. c Modified:
  64. c
  65. c 15 April 2012
  66. c
  67. c Author:
  68. c
  69. c Jack Dongarra, Cleve Moler, Jim Bunch, Pete Stewart
  70. c
  71. c Reference:
  72. c
  73. c Jack Dongarra, Cleve Moler, Jim Bunch, Pete Stewart,
  74. c LINPACK User's Guide,
  75. c SIAM, 1979,
  76. c ISBN13: 978-0-898711-72-1,
  77. c LC: QA214.L56.
  78. c
  79. c Parameters:
  80. c
  81. c Input, real*8 A(LDA,P), contains the output of DQRDC.
  82. c
  83. c Input, integer LDA, the leading dimension of the array A.
  84. c
  85. c Input, integer N, the number of rows of the matrix AK. It
  86. c must have the same value as N in DQRDC.
  87. c
  88. c Input, integer K, the number of columns of the matrix AK. K
  89. c must not be greater than min(N,P), where P is the same as in the
  90. c calling sequence to DQRDC.
  91. c
  92. c Input, real*8 QRAUX(P), the auxiliary output from DQRDC.
  93. c
  94. c Input, real*8 Y(N), a vector to be manipulated by DQRSL.
  95. c
  96. c Output, real*8 QY(N), contains Q * Y, if requested.
  97. c
  98. c Output, real*8 QTY(N), contains Q' * Y, if requested.
  99. c
  100. c Output, real*8 B(K), the solution of the least squares problem
  101. c minimize norm2 ( Y - AK * B),
  102. c if its computation has been requested. Note that if pivoting was
  103. c requested in DQRDC, the J-th component of B will be associated with
  104. c column JPVT(J) of the original matrix A that was input into DQRDC.
  105. c
  106. c Output, real*8 RSD(N), the least squares residual Y - AK * B,
  107. c if its computation has been requested. RSD is also the orthogonal
  108. c projection of Y onto the orthogonal complement of the column space
  109. c of AK.
  110. c
  111. c Output, real*8 AB(N), the least squares approximation Ak * B,
  112. c if its computation has been requested. AB is also the orthogonal
  113. c projection of Y onto the column space of A.
  114. c
  115. c Input, integer JOB, specifies what is to be computed. JOB has
  116. c the decimal expansion ABCDE, with the following meaning:
  117. c
  118. c if A /= 0, compute QY.
  119. c if B /= 0, compute QTY.
  120. c if C /= 0, compute QTY and B.
  121. c if D /= 0, compute QTY and RSD.
  122. c if E /= 0, compute QTY and AB.
  123. c
  124. c Note that a request to compute B, RSD, or AB automatically triggers
  125. c the computation of QTY, for which an array must be provided in the
  126. c calling sequence.
  127. c
  128. c Output, integer INFO, is zero unless the computation of B has
  129. c been requested and R is exactly singular. In this case, INFO is the
  130. c index of the first zero diagonal element of R, and B is left unaltered.
  131.  
  132. implicit real*8 (a-h,o-z)
  133. implicit integer (i-n)
  134.  
  135. integer k
  136. integer lda
  137. integer n
  138.  
  139. real*8 a(lda,*)
  140. real*8 ab(n)
  141. real*8 b(k)
  142. logical cab
  143. logical cb
  144. logical cqty
  145. logical cqy
  146. logical cr
  147. integer info
  148. integer j
  149. integer jj
  150. integer job
  151. integer ju
  152. integer kp1
  153. real*8 qraux(*)
  154. real*8 qty(n)
  155. real*8 qy(n)
  156. real*8 rsd(n)
  157. real*8 ddot
  158. real*8 t
  159. real*8 temp
  160. real*8 y(n)
  161.  
  162. c set info flag.
  163.  
  164. info = 0
  165.  
  166. c Determine what is to be computed.
  167.  
  168. cqy = job / 10000 /= 0
  169. cqty = mod ( job, 10000 ) /= 0
  170. cb = mod ( job, 1000 ) / 100 /= 0
  171. cr = mod ( job, 100 ) / 10 /= 0
  172. cab = mod ( job, 10 ) /= 0
  173.  
  174. ju = min ( k, n-1 )
  175.  
  176. c Special action when N = 1.
  177.  
  178. if ( ju .eq. 0 ) then
  179.  
  180. if ( cqy ) then
  181. qy(1) = y(1)
  182. end if
  183.  
  184. if ( cqty ) then
  185. qty(1) = y(1)
  186. end if
  187.  
  188. if ( cab ) then
  189. ab(1) = y(1)
  190. end if
  191.  
  192. if ( cb ) then
  193.  
  194. if ( a(1,1) .eq. 0.0D+00 ) then
  195. info = 1
  196. else
  197. b(1) = y(1) / a(1,1)
  198. end if
  199.  
  200. end if
  201.  
  202. if ( cr ) then
  203. rsd(1) = 0.0D+00
  204. end if
  205.  
  206. return
  207.  
  208. end if
  209.  
  210. c Set up to compute QY or QTY.
  211.  
  212. if ( cqy ) then
  213. qy(1:n) = y(1:n)
  214. end if
  215.  
  216. if ( cqty ) then
  217. qty(1:n) = y(1:n)
  218. end if
  219.  
  220. c Compute QY.
  221.  
  222. if ( cqy ) then
  223.  
  224. do jj = 1, ju
  225.  
  226. j = ju - jj + 1
  227.  
  228. if ( qraux(j) /= 0.0D+00 ) then
  229. temp = a(j,j)
  230. a(j,j) = qraux(j)
  231. t = - ddot ( n-j+1, a(j,j), 1, qy(j), 1 ) / a(j,j)
  232. call daxpy ( n-j+1, t, a(j,j), 1, qy(j), 1 )
  233. a(j,j) = temp
  234. end if
  235.  
  236. end do
  237.  
  238. end if
  239.  
  240. c Compute Q'*Y.
  241.  
  242. if ( cqty ) then
  243.  
  244. do j = 1, ju
  245. if ( qraux(j) /= 0.0D+00 ) then
  246. temp = a(j,j)
  247. a(j,j) = qraux(j)
  248. t = - ddot ( n-j+1, a(j,j), 1, qty(j), 1 ) / a(j,j)
  249. call daxpy ( n-j+1, t, a(j,j), 1, qty(j), 1 )
  250. a(j,j) = temp
  251. end if
  252. end do
  253.  
  254. end if
  255.  
  256. c Set up to compute B, RSD, or AB.
  257.  
  258. if ( cb ) then
  259. b(1:k) = qty(1:k)
  260. end if
  261.  
  262. kp1 = k + 1
  263.  
  264. if ( cab ) then
  265. ab(1:k) = qty(1:k)
  266. end if
  267.  
  268. if ( cr .and. (k .lt. n) ) then
  269. rsd(k+1:n) = qty(k+1:n)
  270. end if
  271.  
  272. if ( cab .and. (k+1 .le. n) ) then
  273. ab(k+1:n) = 0.0D+00
  274. end if
  275.  
  276. if ( cr ) then
  277. rsd(1:k) = 0.0D+00
  278. end if
  279.  
  280. c Compute B.
  281.  
  282. if ( cb ) then
  283.  
  284. do jj = 1, k
  285.  
  286. j = k - jj + 1
  287.  
  288. if ( a(j,j) .eq. 0.0D+00 ) then
  289. info = j
  290. c exit
  291. go to 10
  292. end if
  293.  
  294. b(j) = b(j)/a(j,j)
  295.  
  296. if ( j /= 1 ) then
  297. t = -b(j)
  298. call daxpy ( j-1, t, a(1,j), 1, b, 1 )
  299. end if
  300.  
  301. end do
  302. 10 continue
  303. end if
  304.  
  305. if ( cr .or. cab ) then
  306.  
  307. c Compute RSD or AB as required.
  308.  
  309. do jj = 1, ju
  310.  
  311. j = ju - jj + 1
  312.  
  313. if ( qraux(j) /= 0.0D+00 ) then
  314.  
  315. temp = a(j,j)
  316. a(j,j) = qraux(j)
  317.  
  318. if ( cr ) then
  319. t = - ddot ( n-j+1, a(j,j), 1, rsd(j), 1 ) / a(j,j)
  320. call daxpy ( n-j+1, t, a(j,j), 1, rsd(j), 1 )
  321. end if
  322.  
  323. if ( cab ) then
  324. t = - ddot ( n-j+1, a(j,j), 1, ab(j), 1 ) / a(j,j)
  325. call daxpy ( n-j+1, t, a(j,j), 1, ab(j), 1 )
  326. end if
  327.  
  328. a(j,j) = temp
  329.  
  330. end if
  331.  
  332. end do
  333.  
  334. end if
  335.  
  336. return
  337. end
  338.  
  339.  
  340.  
  341.  

© Cast3M 2003 - Tous droits réservés.
Mentions légales