Télécharger dgebal.eso

Retour à la liste

Numérotation des lignes :

dgebal
  1. C DGEBAL SOURCE FANDEUR 22/05/02 21:15:04 11359
  2. *> \brief \b DGEBAL
  3. *
  4. * =========== DOCUMENTATION ===========
  5. *
  6. * Online html documentation available at
  7. * http://www.netlib.org/lapack/explore-html/
  8. *
  9. *> \htmlonly
  10. *> Download DGEBAL + dependencies
  11. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgebal.f">
  12. *> [TGZ]</a>
  13. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgebal.f">
  14. *> [ZIP]</a>
  15. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgebal.f">
  16. *> [TXT]</a>
  17. *> \endhtmlonly
  18. *
  19. * Definition:
  20. * ===========
  21. *
  22. * SUBROUTINE DGEBAL( JOB, N, A, LDA, ILO, IHI, SCALE, INFO )
  23. *
  24. * .. Scalar Arguments ..
  25. * CHARACTER JOB
  26. * INTEGER IHI, ILO, INFO, LDA, N
  27. * ..
  28. * .. Array Arguments ..
  29. * REAL*8 A( LDA, * ), SCALE( * )
  30. * ..
  31. *
  32. *
  33. *> \par Purpose:
  34. * =============
  35. *>
  36. *> \verbatim
  37. *>
  38. *> DGEBAL balances a general real matrix A. This involves, first,
  39. *> permuting A by a similarity transformation to isolate eigenvalues
  40. *> in the first 1 to ILO-1 and last IHI+1 to N elements on the
  41. *> diagonal; and second, applying a diagonal similarity transformation
  42. *> to rows and columns ILO to IHI to make the rows and columns as
  43. *> close in norm as possible. Both steps are optional.
  44. *>
  45. *> Balancing may reduce the 1-norm of the matrix, and improve the
  46. *> accuracy of the computed eigenvalues and/or eigenvectors.
  47. *> \endverbatim
  48. *
  49. * Arguments:
  50. * ==========
  51. *
  52. *> \param[in] JOB
  53. *> \verbatim
  54. *> JOB is CHARACTER*1
  55. *> Specifies the operations to be performed on A:
  56. *> = 'N': none: simply set ILO = 1, IHI = N, SCALE(I) = 1.0
  57. *> for i = 1,...,N;
  58. *> = 'P': permute only;
  59. *> = 'S': scale only;
  60. *> = 'B': both permute and scale.
  61. *> \endverbatim
  62. *>
  63. *> \param[in] N
  64. *> \verbatim
  65. *> N is INTEGER
  66. *> The order of the matrix A. N >= 0.
  67. *> \endverbatim
  68. *>
  69. *> \param[in,out] A
  70. *> \verbatim
  71. *> A is REAL*8 array, dimension (LDA,N)
  72. *> On entry, the input matrix A.
  73. *> On exit, A is overwritten by the balanced matrix.
  74. *> If JOB = 'N', A is not referenced.
  75. *> See Further Details.
  76. *> \endverbatim
  77. *>
  78. *> \param[in] LDA
  79. *> \verbatim
  80. *> LDA is INTEGER
  81. *> The leading dimension of the array A. LDA >= max(1,N).
  82. *> \endverbatim
  83. *>
  84. *> \param[out] ILO
  85. *> \verbatim
  86. *> ILO is INTEGER
  87. *> \endverbatim
  88. *> \param[out] IHI
  89. *> \verbatim
  90. *> IHI is INTEGER
  91. *> ILO and IHI are set to integers such that on exit
  92. *> A(i,j) = 0 if i > j and j = 1,...,ILO-1 or I = IHI+1,...,N.
  93. *> If JOB = 'N' or 'S', ILO = 1 and IHI = N.
  94. *> \endverbatim
  95. *>
  96. *> \param[out] SCALE
  97. *> \verbatim
  98. *> SCALE is REAL*8 array, dimension (N)
  99. *> Details of the permutations and scaling factors applied to
  100. *> A. If P(j) is the index of the row and column interchanged
  101. *> with row and column j and D(j) is the scaling factor
  102. *> applied to row and column j, then
  103. *> SCALE(j) = P(j) for j = 1,...,ILO-1
  104. *> = D(j) for j = ILO,...,IHI
  105. *> = P(j) for j = IHI+1,...,N.
  106. *> The order in which the interchanges are made is N to IHI+1,
  107. *> then 1 to ILO-1.
  108. *> \endverbatim
  109. *>
  110. *> \param[out] INFO
  111. *> \verbatim
  112. *> INFO is INTEGER
  113. *> = 0: successful exit.
  114. *> < 0: if INFO = -i, the i-th argument had an illegal value.
  115. *> \endverbatim
  116. *
  117. * Authors:
  118. * ========
  119. *
  120. *> \author Univ. of Tennessee
  121. *> \author Univ. of California Berkeley
  122. *> \author Univ. of Colorado Denver
  123. *> \author NAG Ltd.
  124. *
  125. *> \date June 2017
  126. *
  127. *> \ingroup doubleGEcomputational
  128. *
  129. *> \par Further Details:
  130. * =====================
  131. *>
  132. *> \verbatim
  133. *>
  134. *> The permutations consist of row and column interchanges which put
  135. *> the matrix in the form
  136. *>
  137. *> ( T1 X Y )
  138. *> P A P = ( 0 B Z )
  139. *> ( 0 0 T2 )
  140. *>
  141. *> where T1 and T2 are upper triangular matrices whose eigenvalues lie
  142. *> along the diagonal. The column indices ILO and IHI mark the starting
  143. *> and ending columns of the submatrix B. Balancing consists of applying
  144. *> a diagonal similarity transformation inv(D) * B * D to make the
  145. *> 1-norms of each row of B and its corresponding column nearly equal.
  146. *> The output matrix is
  147. *>
  148. *> ( T1 X*D Y )
  149. *> ( 0 inv(D)*B*D inv(D)*Z ).
  150. *> ( 0 0 T2 )
  151. *>
  152. *> Information about the permutations P and the diagonal matrix D is
  153. *> returned in the vector SCALE.
  154. *>
  155. *> This subroutine is based on the EISPACK routine BALANC.
  156. *>
  157. *> Modified by Tzu-Yi Chen, Computer Science Division, University of
  158. *> California at Berkeley, USA
  159. *> \endverbatim
  160. *>
  161. * =====================================================================
  162. SUBROUTINE DGEBAL( JOB, N, A, LDA, ILO, IHI, SCALE, INFO )
  163. *
  164. * -- LAPACK computational routine (version 3.7.1) --
  165. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  166. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  167. * June 2017
  168.  
  169. IMPLICIT INTEGER(I-N)
  170. IMPLICIT REAL*8(A-H,O-Z)
  171. *
  172. * .. Scalar Arguments ..
  173. CHARACTER JOB
  174. INTEGER IHI, ILO, INFO, LDA, N
  175. * ..
  176. * .. Array Arguments ..
  177. REAL*8 A( LDA, * ), SCALE( * )
  178. * ..
  179. *
  180. * =====================================================================
  181. *
  182. * .. Parameters ..
  183. c ZERO, ONE
  184. PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
  185. REAL*8 SCLFAC
  186. PARAMETER ( SCLFAC = 2.0D+0 )
  187. REAL*8 FACTOR
  188. PARAMETER ( FACTOR = 0.95D+0 )
  189. * ..
  190. * .. Local Scalars ..
  191. LOGICAL NOCONV
  192. INTEGER I, ICA, IEXC, IRA, J, K, L, M
  193. REAL*8 C, CA, F, G, R, RA, S, SFMAX1, SFMAX2, SFMIN1,
  194. $ SFMIN2
  195. * ..
  196. * .. External Functions ..
  197. LOGICAL DISNAN, LSAME
  198. INTEGER IDAMAX
  199. REAL*8 DLAMCH, DNRM2
  200. EXTERNAL DISNAN, LSAME, IDAMAX,
  201. * ..
  202. * .. External Subroutines ..
  203. EXTERNAL DSCAL, DSWAP, XERBLA
  204. * ..
  205. * .. Intrinsic Functions ..
  206. * INTRINSIC ABS, MAX, MIN
  207. * ..
  208. * Test the input parameters
  209. *
  210. INFO = 0
  211. IF( .NOT.LSAME( JOB, 'N' ) .AND.
  212. $ .NOT.LSAME( JOB, 'P' ) .AND.
  213. $ .NOT.LSAME( JOB, 'S' ) .AND.
  214. $ .NOT.LSAME( JOB, 'B' ) ) THEN
  215. INFO = -1
  216. ELSE IF( N.LT.0 ) THEN
  217. INFO = -2
  218. ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
  219. INFO = -4
  220. END IF
  221. IF( INFO.NE.0 ) THEN
  222. CALL XERBLA( 'DGEBAL', -INFO )
  223. RETURN
  224. END IF
  225. *
  226. K = 1
  227. L = N
  228. *
  229. IF( N.EQ.0 )
  230. $ GO TO 210
  231. *
  232. IF( LSAME( JOB, 'N' ) ) THEN
  233. DO 10 I = 1, N
  234. SCALE( I ) = ONE
  235. 10 CONTINUE
  236. GO TO 210
  237. END IF
  238. *
  239. IF( LSAME( JOB, 'S' ) )
  240. $ GO TO 120
  241. *
  242. * Permutation to isolate eigenvalues if possible
  243. *
  244. GO TO 50
  245. *
  246. * Row and column exchange.
  247. *
  248. 20 CONTINUE
  249. SCALE( M ) = J
  250. IF( J.EQ.M )
  251. $ GO TO 30
  252. *
  253. CALL DSWAP( L, A( 1, J ), 1, A( 1, M ), 1 )
  254. CALL DSWAP( N-K+1, A( J, K ), LDA, A( M, K ), LDA )
  255. *
  256. 30 CONTINUE
  257. GO TO ( 40, 80 )IEXC
  258. *
  259. * Search for rows isolating an eigenvalue and push them down.
  260. *
  261. 40 CONTINUE
  262. IF( L.EQ.1 )
  263. $ GO TO 210
  264. L = L - 1
  265. *
  266. 50 CONTINUE
  267. DO 70 J = L, 1, -1
  268. *
  269. DO 60 I = 1, L
  270. IF( I.EQ.J )
  271. $ GO TO 60
  272. IF( A( J, I ).NE.ZERO )
  273. $ GO TO 70
  274. 60 CONTINUE
  275. *
  276. M = L
  277. IEXC = 1
  278. GO TO 20
  279. 70 CONTINUE
  280. *
  281. GO TO 90
  282. *
  283. * Search for columns isolating an eigenvalue and push them left.
  284. *
  285. 80 CONTINUE
  286. K = K + 1
  287. *
  288. 90 CONTINUE
  289. DO 110 J = K, L
  290. *
  291. DO 100 I = K, L
  292. IF( I.EQ.J )
  293. $ GO TO 100
  294. IF( A( I, J ).NE.ZERO )
  295. $ GO TO 110
  296. 100 CONTINUE
  297. *
  298. M = K
  299. IEXC = 2
  300. GO TO 20
  301. 110 CONTINUE
  302. *
  303. 120 CONTINUE
  304. DO 130 I = K, L
  305. SCALE( I ) = ONE
  306. 130 CONTINUE
  307. *
  308. IF( LSAME( JOB, 'P' ) )
  309. $ GO TO 210
  310. *
  311. * Balance the submatrix in rows K to L.
  312. *
  313. * Iterative loop for norm reduction
  314. *
  315. SFMIN1 = DLAMCH( 'S' ) / DLAMCH( 'P' )
  316. SFMAX1 = ONE / SFMIN1
  317. SFMIN2 = SFMIN1*SCLFAC
  318. SFMAX2 = ONE / SFMIN2
  319. *
  320. 140 CONTINUE
  321. NOCONV = .FALSE.
  322. *
  323. DO 200 I = K, L
  324. *
  325. C = DNRM2( L-K+1, A( K, I ), 1 )
  326. R = DNRM2( L-K+1, A( I, K ), LDA )
  327. ICA = IDAMAX( L, A( 1, I ), 1 )
  328. CA = ABS( A( ICA, I ) )
  329. IRA = IDAMAX( N-K+1, A( I, K ), LDA )
  330. RA = ABS( A( I, IRA+K-1 ) )
  331. *
  332. * Guard against zero C or R due to underflow.
  333. *
  334. IF( C.EQ.ZERO .OR. R.EQ.ZERO )
  335. $ GO TO 200
  336. G = R / SCLFAC
  337. F = ONE
  338. S = C + R
  339. 160 CONTINUE
  340. IF( C.GE.G .OR. MAX( F, C, CA ).GE.SFMAX2 .OR.
  341. $ MIN( R, G, RA ).LE.SFMIN2 )GO TO 170
  342. IF( DISNAN( C+F+CA+R+G+RA ) ) THEN
  343. *
  344. * Exit if NaN to avoid infinite loop
  345. *
  346. INFO = -3
  347. CALL XERBLA( 'DGEBAL', -INFO )
  348. RETURN
  349. END IF
  350. F = F*SCLFAC
  351. C = C*SCLFAC
  352. CA = CA*SCLFAC
  353. R = R / SCLFAC
  354. G = G / SCLFAC
  355. RA = RA / SCLFAC
  356. GO TO 160
  357. *
  358. 170 CONTINUE
  359. G = C / SCLFAC
  360. 180 CONTINUE
  361. IF( G.LT.R .OR. MAX( R, RA ).GE.SFMAX2 .OR.
  362. $ MIN( F, C, G, CA ).LE.SFMIN2 )GO TO 190
  363. F = F / SCLFAC
  364. C = C / SCLFAC
  365. G = G / SCLFAC
  366. CA = CA / SCLFAC
  367. R = R*SCLFAC
  368. RA = RA*SCLFAC
  369. GO TO 180
  370. *
  371. * Now balance.
  372. *
  373. 190 CONTINUE
  374. IF( ( C+R ).GE.FACTOR*S )
  375. $ GO TO 200
  376. IF( F.LT.ONE .AND. SCALE( I ).LT.ONE ) THEN
  377. IF( F*SCALE( I ).LE.SFMIN1 )
  378. $ GO TO 200
  379. END IF
  380. IF( F.GT.ONE .AND. SCALE( I ).GT.ONE ) THEN
  381. IF( SCALE( I ).GE.SFMAX1 / F )
  382. $ GO TO 200
  383. END IF
  384. G = ONE / F
  385. SCALE( I ) = SCALE( I )*F
  386. NOCONV = .TRUE.
  387. *
  388. CALL DSCAL( N-K+1, G, A( I, K ), LDA )
  389. CALL DSCAL( L, F, A( 1, I ), 1 )
  390. *
  391. 200 CONTINUE
  392. *
  393. IF( NOCONV )
  394. $ GO TO 140
  395. *
  396. 210 CONTINUE
  397. ILO = K
  398. IHI = L
  399. *
  400. RETURN
  401. *
  402. * End of DGEBAL
  403. *
  404. END
  405.  
  406.  
  407.  

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