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.

sgeequb.f 8.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. *> \brief \b SGEEQUB
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download SGEEQUB + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgeequb.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgeequb.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgeequb.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE SGEEQUB( M, N, A, LDA, R, C, ROWCND, COLCND, AMAX,
  22. * INFO )
  23. *
  24. * .. Scalar Arguments ..
  25. * INTEGER INFO, LDA, M, N
  26. * REAL AMAX, COLCND, ROWCND
  27. * ..
  28. * .. Array Arguments ..
  29. * REAL A( LDA, * ), C( * ), R( * )
  30. * ..
  31. *
  32. *
  33. *> \par Purpose:
  34. * =============
  35. *>
  36. *> \verbatim
  37. *>
  38. *> SGEEQUB computes row and column scalings intended to equilibrate an
  39. *> M-by-N matrix A and reduce its condition number. R returns the row
  40. *> scale factors and C the column scale factors, chosen to try to make
  41. *> the largest element in each row and column of the matrix B with
  42. *> elements B(i,j)=R(i)*A(i,j)*C(j) have an absolute value of at most
  43. *> the radix.
  44. *>
  45. *> R(i) and C(j) are restricted to be a power of the radix between
  46. *> SMLNUM = smallest safe number and BIGNUM = largest safe number. Use
  47. *> of these scaling factors is not guaranteed to reduce the condition
  48. *> number of A but works well in practice.
  49. *>
  50. *> This routine differs from SGEEQU by restricting the scaling factors
  51. *> to a power of the radix. Barring over- and underflow, scaling by
  52. *> these factors introduces no additional rounding errors. However, the
  53. *> scaled entries' magnitudes are no longer approximately 1 but lie
  54. *> between sqrt(radix) and 1/sqrt(radix).
  55. *> \endverbatim
  56. *
  57. * Arguments:
  58. * ==========
  59. *
  60. *> \param[in] M
  61. *> \verbatim
  62. *> M is INTEGER
  63. *> The number of rows of the matrix A. M >= 0.
  64. *> \endverbatim
  65. *>
  66. *> \param[in] N
  67. *> \verbatim
  68. *> N is INTEGER
  69. *> The number of columns of the matrix A. N >= 0.
  70. *> \endverbatim
  71. *>
  72. *> \param[in] A
  73. *> \verbatim
  74. *> A is REAL array, dimension (LDA,N)
  75. *> The M-by-N matrix whose equilibration factors are
  76. *> to be computed.
  77. *> \endverbatim
  78. *>
  79. *> \param[in] LDA
  80. *> \verbatim
  81. *> LDA is INTEGER
  82. *> The leading dimension of the array A. LDA >= max(1,M).
  83. *> \endverbatim
  84. *>
  85. *> \param[out] R
  86. *> \verbatim
  87. *> R is REAL array, dimension (M)
  88. *> If INFO = 0 or INFO > M, R contains the row scale factors
  89. *> for A.
  90. *> \endverbatim
  91. *>
  92. *> \param[out] C
  93. *> \verbatim
  94. *> C is REAL array, dimension (N)
  95. *> If INFO = 0, C contains the column scale factors for A.
  96. *> \endverbatim
  97. *>
  98. *> \param[out] ROWCND
  99. *> \verbatim
  100. *> ROWCND is REAL
  101. *> If INFO = 0 or INFO > M, ROWCND contains the ratio of the
  102. *> smallest R(i) to the largest R(i). If ROWCND >= 0.1 and
  103. *> AMAX is neither too large nor too small, it is not worth
  104. *> scaling by R.
  105. *> \endverbatim
  106. *>
  107. *> \param[out] COLCND
  108. *> \verbatim
  109. *> COLCND is REAL
  110. *> If INFO = 0, COLCND contains the ratio of the smallest
  111. *> C(i) to the largest C(i). If COLCND >= 0.1, it is not
  112. *> worth scaling by C.
  113. *> \endverbatim
  114. *>
  115. *> \param[out] AMAX
  116. *> \verbatim
  117. *> AMAX is REAL
  118. *> Absolute value of largest matrix element. If AMAX is very
  119. *> close to overflow or very close to underflow, the matrix
  120. *> should be scaled.
  121. *> \endverbatim
  122. *>
  123. *> \param[out] INFO
  124. *> \verbatim
  125. *> INFO is INTEGER
  126. *> = 0: successful exit
  127. *> < 0: if INFO = -i, the i-th argument had an illegal value
  128. *> > 0: if INFO = i, and i is
  129. *> <= M: the i-th row of A is exactly zero
  130. *> > M: the (i-M)-th column of A is exactly zero
  131. *> \endverbatim
  132. *
  133. * Authors:
  134. * ========
  135. *
  136. *> \author Univ. of Tennessee
  137. *> \author Univ. of California Berkeley
  138. *> \author Univ. of Colorado Denver
  139. *> \author NAG Ltd.
  140. *
  141. *> \ingroup realGEcomputational
  142. *
  143. * =====================================================================
  144. SUBROUTINE SGEEQUB( M, N, A, LDA, R, C, ROWCND, COLCND, AMAX,
  145. $ INFO )
  146. *
  147. * -- LAPACK computational routine --
  148. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  149. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  150. *
  151. * .. Scalar Arguments ..
  152. INTEGER INFO, LDA, M, N
  153. REAL AMAX, COLCND, ROWCND
  154. * ..
  155. * .. Array Arguments ..
  156. REAL A( LDA, * ), C( * ), R( * )
  157. * ..
  158. *
  159. * =====================================================================
  160. *
  161. * .. Parameters ..
  162. REAL ONE, ZERO
  163. PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 )
  164. * ..
  165. * .. Local Scalars ..
  166. INTEGER I, J
  167. REAL BIGNUM, RCMAX, RCMIN, SMLNUM, RADIX, LOGRDX
  168. * ..
  169. * .. External Functions ..
  170. REAL SLAMCH
  171. EXTERNAL SLAMCH
  172. * ..
  173. * .. External Subroutines ..
  174. EXTERNAL XERBLA
  175. * ..
  176. * .. Intrinsic Functions ..
  177. INTRINSIC ABS, MAX, MIN, LOG
  178. * ..
  179. * .. Executable Statements ..
  180. *
  181. * Test the input parameters.
  182. *
  183. INFO = 0
  184. IF( M.LT.0 ) THEN
  185. INFO = -1
  186. ELSE IF( N.LT.0 ) THEN
  187. INFO = -2
  188. ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
  189. INFO = -4
  190. END IF
  191. IF( INFO.NE.0 ) THEN
  192. CALL XERBLA( 'SGEEQUB', -INFO )
  193. RETURN
  194. END IF
  195. *
  196. * Quick return if possible.
  197. *
  198. IF( M.EQ.0 .OR. N.EQ.0 ) THEN
  199. ROWCND = ONE
  200. COLCND = ONE
  201. AMAX = ZERO
  202. RETURN
  203. END IF
  204. *
  205. * Get machine constants. Assume SMLNUM is a power of the radix.
  206. *
  207. SMLNUM = SLAMCH( 'S' )
  208. BIGNUM = ONE / SMLNUM
  209. RADIX = SLAMCH( 'B' )
  210. LOGRDX = LOG( RADIX )
  211. *
  212. * Compute row scale factors.
  213. *
  214. DO 10 I = 1, M
  215. R( I ) = ZERO
  216. 10 CONTINUE
  217. *
  218. * Find the maximum element in each row.
  219. *
  220. DO 30 J = 1, N
  221. DO 20 I = 1, M
  222. R( I ) = MAX( R( I ), ABS( A( I, J ) ) )
  223. 20 CONTINUE
  224. 30 CONTINUE
  225. DO I = 1, M
  226. IF( R( I ).GT.ZERO ) THEN
  227. R( I ) = RADIX**INT( LOG( R( I ) ) / LOGRDX )
  228. END IF
  229. END DO
  230. *
  231. * Find the maximum and minimum scale factors.
  232. *
  233. RCMIN = BIGNUM
  234. RCMAX = ZERO
  235. DO 40 I = 1, M
  236. RCMAX = MAX( RCMAX, R( I ) )
  237. RCMIN = MIN( RCMIN, R( I ) )
  238. 40 CONTINUE
  239. AMAX = RCMAX
  240. *
  241. IF( RCMIN.EQ.ZERO ) THEN
  242. *
  243. * Find the first zero scale factor and return an error code.
  244. *
  245. DO 50 I = 1, M
  246. IF( R( I ).EQ.ZERO ) THEN
  247. INFO = I
  248. RETURN
  249. END IF
  250. 50 CONTINUE
  251. ELSE
  252. *
  253. * Invert the scale factors.
  254. *
  255. DO 60 I = 1, M
  256. R( I ) = ONE / MIN( MAX( R( I ), SMLNUM ), BIGNUM )
  257. 60 CONTINUE
  258. *
  259. * Compute ROWCND = min(R(I)) / max(R(I)).
  260. *
  261. ROWCND = MAX( RCMIN, SMLNUM ) / MIN( RCMAX, BIGNUM )
  262. END IF
  263. *
  264. * Compute column scale factors
  265. *
  266. DO 70 J = 1, N
  267. C( J ) = ZERO
  268. 70 CONTINUE
  269. *
  270. * Find the maximum element in each column,
  271. * assuming the row scaling computed above.
  272. *
  273. DO 90 J = 1, N
  274. DO 80 I = 1, M
  275. C( J ) = MAX( C( J ), ABS( A( I, J ) )*R( I ) )
  276. 80 CONTINUE
  277. IF( C( J ).GT.ZERO ) THEN
  278. C( J ) = RADIX**INT( LOG( C( J ) ) / LOGRDX )
  279. END IF
  280. 90 CONTINUE
  281. *
  282. * Find the maximum and minimum scale factors.
  283. *
  284. RCMIN = BIGNUM
  285. RCMAX = ZERO
  286. DO 100 J = 1, N
  287. RCMIN = MIN( RCMIN, C( J ) )
  288. RCMAX = MAX( RCMAX, C( J ) )
  289. 100 CONTINUE
  290. *
  291. IF( RCMIN.EQ.ZERO ) THEN
  292. *
  293. * Find the first zero scale factor and return an error code.
  294. *
  295. DO 110 J = 1, N
  296. IF( C( J ).EQ.ZERO ) THEN
  297. INFO = M + J
  298. RETURN
  299. END IF
  300. 110 CONTINUE
  301. ELSE
  302. *
  303. * Invert the scale factors.
  304. *
  305. DO 120 J = 1, N
  306. C( J ) = ONE / MIN( MAX( C( J ), SMLNUM ), BIGNUM )
  307. 120 CONTINUE
  308. *
  309. * Compute COLCND = min(C(J)) / max(C(J)).
  310. *
  311. COLCND = MAX( RCMIN, SMLNUM ) / MIN( RCMAX, BIGNUM )
  312. END IF
  313. *
  314. RETURN
  315. *
  316. * End of SGEEQUB
  317. *
  318. END