cqrdc.f 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. *DECK CQRDC
  2. SUBROUTINE CQRDC (X, LDX, N, P, QRAUX, JPVT, WORK, JOB)
  3. C***BEGIN PROLOGUE CQRDC
  4. C***PURPOSE Use Householder transformations to compute the QR
  5. C factorization of an N by P matrix. Column pivoting is a
  6. C users option.
  7. C***LIBRARY SLATEC (LINPACK)
  8. C***CATEGORY D5
  9. C***TYPE COMPLEX (SQRDC-S, DQRDC-D, CQRDC-C)
  10. C***KEYWORDS LINEAR ALGEBRA, LINPACK, MATRIX, ORTHOGONAL TRIANGULAR,
  11. C QR DECOMPOSITION
  12. C***AUTHOR Stewart, G. W., (U. of Maryland)
  13. C***DESCRIPTION
  14. C
  15. C CQRDC uses Householder transformations to compute the QR
  16. C factorization of an N by P matrix X. Column pivoting
  17. C based on the 2-norms of the reduced columns may be
  18. C performed at the users option.
  19. C
  20. C On Entry
  21. C
  22. C X COMPLEX(LDX,P), where LDX .GE. N.
  23. C X contains the matrix whose decomposition is to be
  24. C computed.
  25. C
  26. C LDX INTEGER.
  27. C LDX is the leading dimension of the array X.
  28. C
  29. C N INTEGER.
  30. C N is the number of rows of the matrix X.
  31. C
  32. C P INTEGER.
  33. C P is the number of columns of the matrix X.
  34. C
  35. C JVPT INTEGER(P).
  36. C JVPT contains integers that control the selection
  37. C of the pivot columns. The K-th column X(K) of X
  38. C is placed in one of three classes according to the
  39. C value of JVPT(K).
  40. C
  41. C If JVPT(K) .GT. 0, then X(K) is an initial
  42. C column.
  43. C
  44. C If JVPT(K) .EQ. 0, then X(K) is a free column.
  45. C
  46. C If JVPT(K) .LT. 0, then X(K) is a final column.
  47. C
  48. C Before the decomposition is computed, initial columns
  49. C are moved to the beginning of the array X and final
  50. C columns to the end. Both initial and final columns
  51. C are frozen in place during the computation and only
  52. C free columns are moved. At the K-th stage of the
  53. C reduction, if X(K) is occupied by a free column
  54. C it is interchanged with the free column of largest
  55. C reduced norm. JVPT is not referenced if
  56. C JOB .EQ. 0.
  57. C
  58. C WORK COMPLEX(P).
  59. C WORK is a work array. WORK is not referenced if
  60. C JOB .EQ. 0.
  61. C
  62. C JOB INTEGER.
  63. C JOB is an integer that initiates column pivoting.
  64. C If JOB .EQ. 0, no pivoting is done.
  65. C If JOB .NE. 0, pivoting is done.
  66. C
  67. C On Return
  68. C
  69. C X X contains in its upper triangle the upper
  70. C triangular matrix R of the QR factorization.
  71. C Below its diagonal X contains information from
  72. C which the unitary part of the decomposition
  73. C can be recovered. Note that if pivoting has
  74. C been requested, the decomposition is not that
  75. C of the original matrix X but that of X
  76. C with its columns permuted as described by JVPT.
  77. C
  78. C QRAUX COMPLEX(P).
  79. C QRAUX contains further information required to recover
  80. C the unitary part of the decomposition.
  81. C
  82. C JVPT JVPT(K) contains the index of the column of the
  83. C original matrix that has been interchanged into
  84. C the K-th column, if pivoting was requested.
  85. C
  86. C***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.
  87. C Stewart, LINPACK Users' Guide, SIAM, 1979.
  88. C***ROUTINES CALLED CAXPY, CDOTC, CSCAL, CSWAP, SCNRM2
  89. C***REVISION HISTORY (YYMMDD)
  90. C 780814 DATE WRITTEN
  91. C 890531 Changed all specific intrinsics to generic. (WRB)
  92. C 890831 Modified array declarations. (WRB)
  93. C 890831 REVISION DATE from Version 3.2
  94. C 891214 Prologue converted to Version 4.0 format. (BAB)
  95. C 900326 Removed duplicate information from DESCRIPTION section.
  96. C (WRB)
  97. C 920501 Reformatted the REFERENCES section. (WRB)
  98. C***END PROLOGUE CQRDC
  99. INTEGER LDX,N,P,JOB
  100. INTEGER JPVT(*)
  101. COMPLEX X(LDX,*),QRAUX(*),WORK(*)
  102. C
  103. INTEGER J,JP,L,LP1,LUP,MAXJ,PL,PU
  104. REAL MAXNRM,SCNRM2,TT
  105. COMPLEX CDOTC,NRMXL,T
  106. LOGICAL NEGJ,SWAPJ
  107. COMPLEX CSIGN,ZDUM,ZDUM1,ZDUM2
  108. REAL CABS1
  109. CSIGN(ZDUM1,ZDUM2) = ABS(ZDUM1)*(ZDUM2/ABS(ZDUM2))
  110. CABS1(ZDUM) = ABS(REAL(ZDUM)) + ABS(AIMAG(ZDUM))
  111. C
  112. C***FIRST EXECUTABLE STATEMENT CQRDC
  113. PL = 1
  114. PU = 0
  115. IF (JOB .EQ. 0) GO TO 60
  116. C
  117. C PIVOTING HAS BEEN REQUESTED. REARRANGE THE COLUMNS
  118. C ACCORDING TO JPVT.
  119. C
  120. DO 20 J = 1, P
  121. SWAPJ = JPVT(J) .GT. 0
  122. NEGJ = JPVT(J) .LT. 0
  123. JPVT(J) = J
  124. IF (NEGJ) JPVT(J) = -J
  125. IF (.NOT.SWAPJ) GO TO 10
  126. IF (J .NE. PL) CALL CSWAP(N,X(1,PL),1,X(1,J),1)
  127. JPVT(J) = JPVT(PL)
  128. JPVT(PL) = J
  129. PL = PL + 1
  130. 10 CONTINUE
  131. 20 CONTINUE
  132. PU = P
  133. DO 50 JJ = 1, P
  134. J = P - JJ + 1
  135. IF (JPVT(J) .GE. 0) GO TO 40
  136. JPVT(J) = -JPVT(J)
  137. IF (J .EQ. PU) GO TO 30
  138. CALL CSWAP(N,X(1,PU),1,X(1,J),1)
  139. JP = JPVT(PU)
  140. JPVT(PU) = JPVT(J)
  141. JPVT(J) = JP
  142. 30 CONTINUE
  143. PU = PU - 1
  144. 40 CONTINUE
  145. 50 CONTINUE
  146. 60 CONTINUE
  147. C
  148. C COMPUTE THE NORMS OF THE FREE COLUMNS.
  149. C
  150. IF (PU .LT. PL) GO TO 80
  151. DO 70 J = PL, PU
  152. QRAUX(J) = CMPLX(SCNRM2(N,X(1,J),1),0.0E0)
  153. WORK(J) = QRAUX(J)
  154. 70 CONTINUE
  155. 80 CONTINUE
  156. C
  157. C PERFORM THE HOUSEHOLDER REDUCTION OF X.
  158. C
  159. LUP = MIN(N,P)
  160. DO 200 L = 1, LUP
  161. IF (L .LT. PL .OR. L .GE. PU) GO TO 120
  162. C
  163. C LOCATE THE COLUMN OF LARGEST NORM AND BRING IT
  164. C INTO THE PIVOT POSITION.
  165. C
  166. MAXNRM = 0.0E0
  167. MAXJ = L
  168. DO 100 J = L, PU
  169. IF (REAL(QRAUX(J)) .LE. MAXNRM) GO TO 90
  170. MAXNRM = REAL(QRAUX(J))
  171. MAXJ = J
  172. 90 CONTINUE
  173. 100 CONTINUE
  174. IF (MAXJ .EQ. L) GO TO 110
  175. CALL CSWAP(N,X(1,L),1,X(1,MAXJ),1)
  176. QRAUX(MAXJ) = QRAUX(L)
  177. WORK(MAXJ) = WORK(L)
  178. JP = JPVT(MAXJ)
  179. JPVT(MAXJ) = JPVT(L)
  180. JPVT(L) = JP
  181. 110 CONTINUE
  182. 120 CONTINUE
  183. QRAUX(L) = (0.0E0,0.0E0)
  184. IF (L .EQ. N) GO TO 190
  185. C
  186. C COMPUTE THE HOUSEHOLDER TRANSFORMATION FOR COLUMN L.
  187. C
  188. NRMXL = CMPLX(SCNRM2(N-L+1,X(L,L),1),0.0E0)
  189. IF (CABS1(NRMXL) .EQ. 0.0E0) GO TO 180
  190. IF (CABS1(X(L,L)) .NE. 0.0E0)
  191. 1 NRMXL = CSIGN(NRMXL,X(L,L))
  192. CALL CSCAL(N-L+1,(1.0E0,0.0E0)/NRMXL,X(L,L),1)
  193. X(L,L) = (1.0E0,0.0E0) + X(L,L)
  194. C
  195. C APPLY THE TRANSFORMATION TO THE REMAINING COLUMNS,
  196. C UPDATING THE NORMS.
  197. C
  198. LP1 = L + 1
  199. IF (P .LT. LP1) GO TO 170
  200. DO 160 J = LP1, P
  201. T = -CDOTC(N-L+1,X(L,L),1,X(L,J),1)/X(L,L)
  202. CALL CAXPY(N-L+1,T,X(L,L),1,X(L,J),1)
  203. IF (J .LT. PL .OR. J .GT. PU) GO TO 150
  204. IF (CABS1(QRAUX(J)) .EQ. 0.0E0) GO TO 150
  205. TT = 1.0E0 - (ABS(X(L,J))/REAL(QRAUX(J)))**2
  206. TT = MAX(TT,0.0E0)
  207. T = CMPLX(TT,0.0E0)
  208. TT = 1.0E0
  209. 1 + 0.05E0*TT*(REAL(QRAUX(J))/REAL(WORK(J)))**2
  210. IF (TT .EQ. 1.0E0) GO TO 130
  211. QRAUX(J) = QRAUX(J)*SQRT(T)
  212. GO TO 140
  213. 130 CONTINUE
  214. QRAUX(J) = CMPLX(SCNRM2(N-L,X(L+1,J),1),0.0E0)
  215. WORK(J) = QRAUX(J)
  216. 140 CONTINUE
  217. 150 CONTINUE
  218. 160 CONTINUE
  219. 170 CONTINUE
  220. C
  221. C SAVE THE TRANSFORMATION.
  222. C
  223. QRAUX(L) = X(L,L)
  224. X(L,L) = -NRMXL
  225. 180 CONTINUE
  226. 190 CONTINUE
  227. 200 CONTINUE
  228. RETURN
  229. END