You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

sgeqrs.f 4.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. *> \brief \b SGEQRS
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. * Definition:
  9. * ===========
  10. *
  11. * SUBROUTINE SGEQRS( M, N, NRHS, A, LDA, TAU, B, LDB, WORK, LWORK,
  12. * INFO )
  13. *
  14. * .. Scalar Arguments ..
  15. * INTEGER INFO, LDA, LDB, LWORK, M, N, NRHS
  16. * ..
  17. * .. Array Arguments ..
  18. * REAL A( LDA, * ), B( LDB, * ), TAU( * ),
  19. * $ WORK( LWORK )
  20. * ..
  21. *
  22. *
  23. *> \par Purpose:
  24. * =============
  25. *>
  26. *> \verbatim
  27. *>
  28. *> Solve the least squares problem
  29. *> min || A*X - B ||
  30. *> using the QR factorization
  31. *> A = Q*R
  32. *> computed by SGEQRF.
  33. *> \endverbatim
  34. *
  35. * Arguments:
  36. * ==========
  37. *
  38. *> \param[in] M
  39. *> \verbatim
  40. *> M is INTEGER
  41. *> The number of rows of the matrix A. M >= 0.
  42. *> \endverbatim
  43. *>
  44. *> \param[in] N
  45. *> \verbatim
  46. *> N is INTEGER
  47. *> The number of columns of the matrix A. M >= N >= 0.
  48. *> \endverbatim
  49. *>
  50. *> \param[in] NRHS
  51. *> \verbatim
  52. *> NRHS is INTEGER
  53. *> The number of columns of B. NRHS >= 0.
  54. *> \endverbatim
  55. *>
  56. *> \param[in] A
  57. *> \verbatim
  58. *> A is REAL array, dimension (LDA,N)
  59. *> Details of the QR factorization of the original matrix A as
  60. *> returned by SGEQRF.
  61. *> \endverbatim
  62. *>
  63. *> \param[in] LDA
  64. *> \verbatim
  65. *> LDA is INTEGER
  66. *> The leading dimension of the array A. LDA >= M.
  67. *> \endverbatim
  68. *>
  69. *> \param[in] TAU
  70. *> \verbatim
  71. *> TAU is REAL array, dimension (N)
  72. *> Details of the orthogonal matrix Q.
  73. *> \endverbatim
  74. *>
  75. *> \param[in,out] B
  76. *> \verbatim
  77. *> B is REAL array, dimension (LDB,NRHS)
  78. *> On entry, the m-by-nrhs right hand side matrix B.
  79. *> On exit, the n-by-nrhs solution matrix X.
  80. *> \endverbatim
  81. *>
  82. *> \param[in] LDB
  83. *> \verbatim
  84. *> LDB is INTEGER
  85. *> The leading dimension of the array B. LDB >= M.
  86. *> \endverbatim
  87. *>
  88. *> \param[out] WORK
  89. *> \verbatim
  90. *> WORK is REAL array, dimension (LWORK)
  91. *> \endverbatim
  92. *>
  93. *> \param[in] LWORK
  94. *> \verbatim
  95. *> LWORK is INTEGER
  96. *> The length of the array WORK. LWORK must be at least NRHS,
  97. *> and should be at least NRHS*NB, where NB is the block size
  98. *> for this environment.
  99. *> \endverbatim
  100. *>
  101. *> \param[out] INFO
  102. *> \verbatim
  103. *> INFO is INTEGER
  104. *> = 0: successful exit
  105. *> < 0: if INFO = -i, the i-th argument had an illegal value
  106. *> \endverbatim
  107. *
  108. * Authors:
  109. * ========
  110. *
  111. *> \author Univ. of Tennessee
  112. *> \author Univ. of California Berkeley
  113. *> \author Univ. of Colorado Denver
  114. *> \author NAG Ltd.
  115. *
  116. *> \ingroup single_lin
  117. *
  118. * =====================================================================
  119. SUBROUTINE SGEQRS( M, N, NRHS, A, LDA, TAU, B, LDB, WORK, LWORK,
  120. $ INFO )
  121. *
  122. * -- LAPACK test routine --
  123. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  124. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  125. *
  126. * .. Scalar Arguments ..
  127. INTEGER INFO, LDA, LDB, LWORK, M, N, NRHS
  128. * ..
  129. * .. Array Arguments ..
  130. REAL A( LDA, * ), B( LDB, * ), TAU( * ),
  131. $ WORK( LWORK )
  132. * ..
  133. *
  134. * =====================================================================
  135. *
  136. * .. Parameters ..
  137. REAL ONE
  138. PARAMETER ( ONE = 1.0E+0 )
  139. * ..
  140. * .. External Subroutines ..
  141. EXTERNAL SORMQR, STRSM, XERBLA
  142. * ..
  143. * .. Intrinsic Functions ..
  144. INTRINSIC MAX
  145. * ..
  146. * .. Executable Statements ..
  147. *
  148. * Test the input arguments.
  149. *
  150. INFO = 0
  151. IF( M.LT.0 ) THEN
  152. INFO = -1
  153. ELSE IF( N.LT.0 .OR. N.GT.M ) THEN
  154. INFO = -2
  155. ELSE IF( NRHS.LT.0 ) THEN
  156. INFO = -3
  157. ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
  158. INFO = -5
  159. ELSE IF( LDB.LT.MAX( 1, M ) ) THEN
  160. INFO = -8
  161. ELSE IF( LWORK.LT.1 .OR. LWORK.LT.NRHS .AND. M.GT.0 .AND. N.GT.0 )
  162. $ THEN
  163. INFO = -10
  164. END IF
  165. IF( INFO.NE.0 ) THEN
  166. CALL XERBLA( 'SGEQRS', -INFO )
  167. RETURN
  168. END IF
  169. *
  170. * Quick return if possible
  171. *
  172. IF( N.EQ.0 .OR. NRHS.EQ.0 .OR. M.EQ.0 )
  173. $ RETURN
  174. *
  175. * B := Q' * B
  176. *
  177. CALL SORMQR( 'Left', 'Transpose', M, NRHS, N, A, LDA, TAU, B, LDB,
  178. $ WORK, LWORK, INFO )
  179. *
  180. * Solve R*X = B(1:n,:)
  181. *
  182. CALL STRSM( 'Left', 'Upper', 'No transpose', 'Non-unit', N, NRHS,
  183. $ ONE, A, LDA, B, LDB )
  184. *
  185. RETURN
  186. *
  187. * End of SGEQRS
  188. *
  189. END