dqrfac.f 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. *DECK DQRFAC
  2. SUBROUTINE DQRFAC (M, N, A, LDA, PIVOT, IPVT, LIPVT, SIGMA,
  3. + ACNORM, WA)
  4. C***BEGIN PROLOGUE DQRFAC
  5. C***SUBSIDIARY
  6. C***PURPOSE Subsidiary to DNLS1, DNLS1E, DNSQ and DNSQE
  7. C***LIBRARY SLATEC
  8. C***TYPE DOUBLE PRECISION (QRFAC-S, DQRFAC-D)
  9. C***AUTHOR (UNKNOWN)
  10. C***DESCRIPTION
  11. C
  12. C **** Double Precision version of QRFAC ****
  13. C
  14. C This subroutine uses Householder transformations with column
  15. C pivoting (optional) to compute a QR factorization of the
  16. C M by N matrix A. That is, DQRFAC determines an orthogonal
  17. C matrix Q, a permutation matrix P, and an upper trapezoidal
  18. C matrix R with diagonal elements of nonincreasing magnitude,
  19. C such that A*P = Q*R. The Householder transformation for
  20. C column K, K = 1,2,...,MIN(M,N), is of the form
  21. C
  22. C T
  23. C I - (1/U(K))*U*U
  24. C
  25. C where U has zeros in the first K-1 positions. The form of
  26. C this transformation and the method of pivoting first
  27. C appeared in the corresponding LINPACK subroutine.
  28. C
  29. C The subroutine statement is
  30. C
  31. C SUBROUTINE DQRFAC(M,N,A,LDA,PIVOT,IPVT,LIPVT,SIGMA,ACNORM,WA)
  32. C
  33. C where
  34. C
  35. C M is a positive integer input variable set to the number
  36. C of rows of A.
  37. C
  38. C N is a positive integer input variable set to the number
  39. C of columns of A.
  40. C
  41. C A is an M by N array. On input A contains the matrix for
  42. C which the QR factorization is to be computed. On output
  43. C the strict upper trapezoidal part of A contains the strict
  44. C upper trapezoidal part of R, and the lower trapezoidal
  45. C part of A contains a factored form of Q (the non-trivial
  46. C elements of the U vectors described above).
  47. C
  48. C LDA is a positive integer input variable not less than M
  49. C which specifies the leading dimension of the array A.
  50. C
  51. C PIVOT is a logical input variable. If pivot is set .TRUE.,
  52. C then column pivoting is enforced. If pivot is set .FALSE.,
  53. C then no column pivoting is done.
  54. C
  55. C IPVT is an integer output array of length LIPVT. IPVT
  56. C defines the permutation matrix P such that A*P = Q*R.
  57. C Column J of P is column IPVT(J) of the identity matrix.
  58. C If pivot is .FALSE., IPVT is not referenced.
  59. C
  60. C LIPVT is a positive integer input variable. If PIVOT is
  61. C .FALSE., then LIPVT may be as small as 1. If PIVOT is
  62. C .TRUE., then LIPVT must be at least N.
  63. C
  64. C SIGMA is an output array of length N which contains the
  65. C diagonal elements of R.
  66. C
  67. C ACNORM is an output array of length N which contains the
  68. C norms of the corresponding columns of the input matrix A.
  69. C If this information is not needed, then ACNORM can coincide
  70. C with SIGMA.
  71. C
  72. C WA is a work array of length N. If pivot is .FALSE., then WA
  73. C can coincide with SIGMA.
  74. C
  75. C***SEE ALSO DNLS1, DNLS1E, DNSQ, DNSQE
  76. C***ROUTINES CALLED D1MACH, DENORM
  77. C***REVISION HISTORY (YYMMDD)
  78. C 800301 DATE WRITTEN
  79. C 890531 Changed all specific intrinsics to generic. (WRB)
  80. C 890831 Modified array declarations. (WRB)
  81. C 891214 Prologue converted to Version 4.0 format. (BAB)
  82. C 900326 Removed duplicate information from DESCRIPTION section.
  83. C (WRB)
  84. C 900328 Added TYPE section. (WRB)
  85. C***END PROLOGUE DQRFAC
  86. INTEGER M,N,LDA,LIPVT
  87. INTEGER IPVT(*)
  88. LOGICAL PIVOT
  89. SAVE ONE, P05, ZERO
  90. DOUBLE PRECISION A(LDA,*),SIGMA(*),ACNORM(*),WA(*)
  91. INTEGER I,J,JP1,K,KMAX,MINMN
  92. DOUBLE PRECISION AJNORM,EPSMCH,ONE,P05,SUM,TEMP,ZERO
  93. DOUBLE PRECISION D1MACH,DENORM
  94. DATA ONE,P05,ZERO /1.0D0,5.0D-2,0.0D0/
  95. C***FIRST EXECUTABLE STATEMENT DQRFAC
  96. EPSMCH = D1MACH(4)
  97. C
  98. C COMPUTE THE INITIAL COLUMN NORMS AND INITIALIZE SEVERAL ARRAYS.
  99. C
  100. DO 10 J = 1, N
  101. ACNORM(J) = DENORM(M,A(1,J))
  102. SIGMA(J) = ACNORM(J)
  103. WA(J) = SIGMA(J)
  104. IF (PIVOT) IPVT(J) = J
  105. 10 CONTINUE
  106. C
  107. C REDUCE A TO R WITH HOUSEHOLDER TRANSFORMATIONS.
  108. C
  109. MINMN = MIN(M,N)
  110. DO 110 J = 1, MINMN
  111. IF (.NOT.PIVOT) GO TO 40
  112. C
  113. C BRING THE COLUMN OF LARGEST NORM INTO THE PIVOT POSITION.
  114. C
  115. KMAX = J
  116. DO 20 K = J, N
  117. IF (SIGMA(K) .GT. SIGMA(KMAX)) KMAX = K
  118. 20 CONTINUE
  119. IF (KMAX .EQ. J) GO TO 40
  120. DO 30 I = 1, M
  121. TEMP = A(I,J)
  122. A(I,J) = A(I,KMAX)
  123. A(I,KMAX) = TEMP
  124. 30 CONTINUE
  125. SIGMA(KMAX) = SIGMA(J)
  126. WA(KMAX) = WA(J)
  127. K = IPVT(J)
  128. IPVT(J) = IPVT(KMAX)
  129. IPVT(KMAX) = K
  130. 40 CONTINUE
  131. C
  132. C COMPUTE THE HOUSEHOLDER TRANSFORMATION TO REDUCE THE
  133. C J-TH COLUMN OF A TO A MULTIPLE OF THE J-TH UNIT VECTOR.
  134. C
  135. AJNORM = DENORM(M-J+1,A(J,J))
  136. IF (AJNORM .EQ. ZERO) GO TO 100
  137. IF (A(J,J) .LT. ZERO) AJNORM = -AJNORM
  138. DO 50 I = J, M
  139. A(I,J) = A(I,J)/AJNORM
  140. 50 CONTINUE
  141. A(J,J) = A(J,J) + ONE
  142. C
  143. C APPLY THE TRANSFORMATION TO THE REMAINING COLUMNS
  144. C AND UPDATE THE NORMS.
  145. C
  146. JP1 = J + 1
  147. IF (N .LT. JP1) GO TO 100
  148. DO 90 K = JP1, N
  149. SUM = ZERO
  150. DO 60 I = J, M
  151. SUM = SUM + A(I,J)*A(I,K)
  152. 60 CONTINUE
  153. TEMP = SUM/A(J,J)
  154. DO 70 I = J, M
  155. A(I,K) = A(I,K) - TEMP*A(I,J)
  156. 70 CONTINUE
  157. IF (.NOT.PIVOT .OR. SIGMA(K) .EQ. ZERO) GO TO 80
  158. TEMP = A(J,K)/SIGMA(K)
  159. SIGMA(K) = SIGMA(K)*SQRT(MAX(ZERO,ONE-TEMP**2))
  160. IF (P05*(SIGMA(K)/WA(K))**2 .GT. EPSMCH) GO TO 80
  161. SIGMA(K) = DENORM(M-J,A(JP1,K))
  162. WA(K) = SIGMA(K)
  163. 80 CONTINUE
  164. 90 CONTINUE
  165. 100 CONTINUE
  166. SIGMA(J) = -AJNORM
  167. 110 CONTINUE
  168. RETURN
  169. C
  170. C LAST CARD OF SUBROUTINE DQRFAC.
  171. C
  172. END