Télécharger dqrdc.eso

Retour à la liste

Numérotation des lignes :

dqrdc
  1. C DQRDC SOURCE PV090527 23/02/07 11:58:36 11592
  2. subroutine dqrdc ( a, lda, n, p, qraux, jpvt, work, job )
  3.  
  4. c*****************************************************************************80
  5. c
  6. c! DQRDC computes the QR factorization of a real rectangular matrix.
  7. c
  8. c Discussion:
  9. c
  10. c DQRDC uses Householder transformations.
  11. c
  12. c Column pivoting based on the 2-norms of the reduced columns may be
  13. c performed at the user's option.
  14. c
  15. c Reference:
  16. c
  17. c Jack Dongarra, Cleve Moler, Jim Bunch, Pete Stewart,
  18. c LINPACK User's Guide,
  19. c SIAM, 1979,
  20. c ISBN13: 978-0-898711-72-1,
  21. c LC: QA214.L56.
  22. c
  23. c Parameters:
  24. c
  25. c Input/output, real*8 A(LDA,P). On input, the N by P matrix
  26. c whose decomposition is to be computed. On output, A contains in
  27. c its upper triangle the upper triangular matrix R of the QR
  28. c factorization. Below its diagonal A contains information from
  29. c which the orthogonal part of the decomposition can be recovered.
  30. c Note that if pivoting has been requested, the decomposition is not that
  31. c of the original matrix A but that of A with its columns permuted
  32. c as described by JPVT.
  33. c
  34. c Input, integer LDA, the leading dimension of the array A.
  35. c LDA must be at least N.
  36. c
  37. c Input, integer N, the number of rows of the matrix A.
  38. c
  39. c Input, integer P, the number of columns of the matrix A.
  40. c
  41. c Output, real*8 QRAUX(P), contains further information required
  42. c to recover the orthogonal part of the decomposition.
  43. c
  44. c Input/output, integer JPVT(P). On input, JPVT contains
  45. c integers that control the selection of the pivot columns. The K-th
  46. c column A(*,K) of A is placed in one of three classes according to the
  47. c value of JPVT(K).
  48. c .gt. 0, then A(K) is an initial column.
  49. c = 0, then A(K) is a free column.
  50. c .lt. 0, then A(K) is a final column.
  51. c Before the decomposition is computed, initial columns are moved to
  52. c the beginning of the array A and final columns to the end. Both
  53. c initial and final columns are frozen in place during the computation
  54. c and only free columns are moved. At the K-th stage of the
  55. c reduction, if A(*,K) is occupied by a free column it is interchanged
  56. c with the free column of largest reduced norm. JPVT is not referenced
  57. c if JOB .eq. 0. On output, JPVT(K) contains the index of the column of the
  58. c original matrix that has been interchanged into the K-th column, if
  59. c pivoting was requested.
  60. c
  61. c Workspace, real*8 WORK(P). WORK is not referenced if JOB .eq. 0.
  62. c
  63. c Input, integer JOB, initiates column pivoting.
  64. c 0, no pivoting is done.
  65. c nonzero, pivoting is done.
  66. c
  67. implicit real*8 (a-h,o-z)
  68. implicit integer (i-n)
  69.  
  70. integer lda
  71. integer n
  72. integer p
  73.  
  74. real*8 a(lda,p)
  75. integer jpvt(p)
  76. real*8 qraux(p)
  77. real*8 work(p)
  78. integer j
  79. integer job
  80. integer jp
  81. integer l
  82. integer lup
  83. integer maxj
  84. real*8 maxnrm
  85. real*8 nrmxl
  86. integer pl
  87. integer pu
  88. real*8 ddot
  89. real*8 dnrm2
  90. logical swapj
  91. real*8 t
  92. real*8 tt
  93.  
  94. pl = 1
  95. pu = 0
  96.  
  97. c If pivoting is requested, rearrange the columns.
  98.  
  99. if ( job /= 0 ) then
  100.  
  101. do j = 1, p
  102.  
  103. swapj = 0 .lt. jpvt(j)
  104.  
  105. if ( jpvt(j) .lt. 0 ) then
  106. jpvt(j) = - j
  107. else
  108. jpvt(j) = j
  109. end if
  110.  
  111. if ( swapj ) then
  112.  
  113. if ( j /= pl ) then
  114. call dswap ( n, a(1,pl), 1, a(1,j), 1 )
  115. end if
  116.  
  117. jpvt(j) = jpvt(pl)
  118. jpvt(pl) = j
  119. pl = pl + 1
  120.  
  121. end if
  122.  
  123. end do
  124.  
  125. pu = p
  126.  
  127. do j = p, 1, -1
  128.  
  129. if ( jpvt(j) .lt. 0 ) then
  130.  
  131. jpvt(j) = - jpvt(j)
  132.  
  133. if ( j /= pu ) then
  134. call dswap ( n, a(1,pu), 1, a(1,j), 1 )
  135. jp = jpvt(pu)
  136. jpvt(pu) = jpvt(j)
  137. jpvt(j) = jp
  138. end if
  139.  
  140. pu = pu - 1
  141.  
  142. end if
  143.  
  144. end do
  145.  
  146. end if
  147.  
  148. c Compute the norms of the free columns.
  149.  
  150. do j = pl, pu
  151. qraux(j) = dnrm2 ( n, a(1,j), 1 )
  152. end do
  153.  
  154. work(pl:pu) = qraux(pl:pu)
  155.  
  156. c Perform the Householder reduction of A.
  157.  
  158. lup = min ( n, p )
  159.  
  160. do l = 1, lup
  161.  
  162. c Bring the column of largest norm into the pivot position.
  163.  
  164. if ( (pl .le. l) .and. (l .lt. pu) ) then
  165.  
  166. maxnrm = 0.0D+00
  167. maxj = l
  168. do j = l, pu
  169. if ( maxnrm .lt. qraux(j) ) then
  170. maxnrm = qraux(j)
  171. maxj = j
  172. end if
  173. end do
  174.  
  175. if ( maxj /= l ) then
  176. call dswap ( n, a(1,l), 1, a(1,maxj), 1 )
  177. qraux(maxj) = qraux(l)
  178. work(maxj) = work(l)
  179. jp = jpvt(maxj)
  180. jpvt(maxj) = jpvt(l)
  181. jpvt(l) = jp
  182. end if
  183.  
  184. end if
  185.  
  186. c Compute the Householder transformation for column L.
  187.  
  188. qraux(l) = 0.0D+00
  189.  
  190. if ( l /= n ) then
  191.  
  192. nrmxl = dnrm2 ( n-l+1, a(l,l), 1 )
  193.  
  194. if ( nrmxl /= 0.0D+00 ) then
  195.  
  196. if ( a(l,l) /= 0.0D+00 ) then
  197. nrmxl = sign ( nrmxl, a(l,l) )
  198. end if
  199.  
  200. call dscal ( n-l+1, 1.0D+00 / nrmxl, a(l,l), 1 )
  201. a(l,l) = 1.0D+00 + a(l,l)
  202.  
  203. c Apply the transformation to the remaining columns, updating the norms.
  204.  
  205. do j = l + 1, p
  206.  
  207. t = - ddot ( n-l+1, a(l,l), 1, a(l,j), 1 ) / a(l,l)
  208. call daxpy ( n-l+1, t, a(l,l), 1, a(l,j), 1 )
  209.  
  210. if ( (pl .le. j) .and. (j .le. pu) ) then
  211.  
  212. if ( qraux(j) /= 0.0D+00 ) then
  213.  
  214. tt = 1.0D+00 - ( abs ( a(l,j) ) / qraux(j) )**2
  215. tt = max ( tt, 0.0D+00 )
  216. t = tt
  217. tt = 1.0D+00 + 0.05D+00 * tt * (qraux(j)/work(j))**2
  218.  
  219. if ( tt /= 1.0D+00 ) then
  220. qraux(j) = qraux(j) * sqrt ( t )
  221. else
  222. qraux(j) = dnrm2 ( n-l, a(l+1,j), 1 )
  223. work(j) = qraux(j)
  224. end if
  225.  
  226. end if
  227.  
  228. end if
  229.  
  230. end do
  231.  
  232. c Save the transformation.
  233.  
  234. qraux(l) = a(l,l)
  235. a(l,l) = - nrmxl
  236.  
  237. end if
  238.  
  239. end if
  240.  
  241. end do
  242.  
  243. return
  244. end
  245.  
  246.  

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