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.

zgesvx.f 21 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. *> \brief <b> ZGESVX computes the solution to system of linear equations A * X = B for GE matrices</b>
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download ZGESVX + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zgesvx.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zgesvx.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zgesvx.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE ZGESVX( FACT, TRANS, N, NRHS, A, LDA, AF, LDAF, IPIV,
  22. * EQUED, R, C, B, LDB, X, LDX, RCOND, FERR, BERR,
  23. * WORK, RWORK, INFO )
  24. *
  25. * .. Scalar Arguments ..
  26. * CHARACTER EQUED, FACT, TRANS
  27. * INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS
  28. * DOUBLE PRECISION RCOND
  29. * ..
  30. * .. Array Arguments ..
  31. * INTEGER IPIV( * )
  32. * DOUBLE PRECISION BERR( * ), C( * ), FERR( * ), R( * ),
  33. * $ RWORK( * )
  34. * COMPLEX*16 A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
  35. * $ WORK( * ), X( LDX, * )
  36. * ..
  37. *
  38. *
  39. *> \par Purpose:
  40. * =============
  41. *>
  42. *> \verbatim
  43. *>
  44. *> ZGESVX uses the LU factorization to compute the solution to a complex
  45. *> system of linear equations
  46. *> A * X = B,
  47. *> where A is an N-by-N matrix and X and B are N-by-NRHS matrices.
  48. *>
  49. *> Error bounds on the solution and a condition estimate are also
  50. *> provided.
  51. *> \endverbatim
  52. *
  53. *> \par Description:
  54. * =================
  55. *>
  56. *> \verbatim
  57. *>
  58. *> The following steps are performed:
  59. *>
  60. *> 1. If FACT = 'E', real scaling factors are computed to equilibrate
  61. *> the system:
  62. *> TRANS = 'N': diag(R)*A*diag(C) *inv(diag(C))*X = diag(R)*B
  63. *> TRANS = 'T': (diag(R)*A*diag(C))**T *inv(diag(R))*X = diag(C)*B
  64. *> TRANS = 'C': (diag(R)*A*diag(C))**H *inv(diag(R))*X = diag(C)*B
  65. *> Whether or not the system will be equilibrated depends on the
  66. *> scaling of the matrix A, but if equilibration is used, A is
  67. *> overwritten by diag(R)*A*diag(C) and B by diag(R)*B (if TRANS='N')
  68. *> or diag(C)*B (if TRANS = 'T' or 'C').
  69. *>
  70. *> 2. If FACT = 'N' or 'E', the LU decomposition is used to factor the
  71. *> matrix A (after equilibration if FACT = 'E') as
  72. *> A = P * L * U,
  73. *> where P is a permutation matrix, L is a unit lower triangular
  74. *> matrix, and U is upper triangular.
  75. *>
  76. *> 3. If some U(i,i)=0, so that U is exactly singular, then the routine
  77. *> returns with INFO = i. Otherwise, the factored form of A is used
  78. *> to estimate the condition number of the matrix A. If the
  79. *> reciprocal of the condition number is less than machine precision,
  80. *> INFO = N+1 is returned as a warning, but the routine still goes on
  81. *> to solve for X and compute error bounds as described below.
  82. *>
  83. *> 4. The system of equations is solved for X using the factored form
  84. *> of A.
  85. *>
  86. *> 5. Iterative refinement is applied to improve the computed solution
  87. *> matrix and calculate error bounds and backward error estimates
  88. *> for it.
  89. *>
  90. *> 6. If equilibration was used, the matrix X is premultiplied by
  91. *> diag(C) (if TRANS = 'N') or diag(R) (if TRANS = 'T' or 'C') so
  92. *> that it solves the original system before equilibration.
  93. *> \endverbatim
  94. *
  95. * Arguments:
  96. * ==========
  97. *
  98. *> \param[in] FACT
  99. *> \verbatim
  100. *> FACT is CHARACTER*1
  101. *> Specifies whether or not the factored form of the matrix A is
  102. *> supplied on entry, and if not, whether the matrix A should be
  103. *> equilibrated before it is factored.
  104. *> = 'F': On entry, AF and IPIV contain the factored form of A.
  105. *> If EQUED is not 'N', the matrix A has been
  106. *> equilibrated with scaling factors given by R and C.
  107. *> A, AF, and IPIV are not modified.
  108. *> = 'N': The matrix A will be copied to AF and factored.
  109. *> = 'E': The matrix A will be equilibrated if necessary, then
  110. *> copied to AF and factored.
  111. *> \endverbatim
  112. *>
  113. *> \param[in] TRANS
  114. *> \verbatim
  115. *> TRANS is CHARACTER*1
  116. *> Specifies the form of the system of equations:
  117. *> = 'N': A * X = B (No transpose)
  118. *> = 'T': A**T * X = B (Transpose)
  119. *> = 'C': A**H * X = B (Conjugate transpose)
  120. *> \endverbatim
  121. *>
  122. *> \param[in] N
  123. *> \verbatim
  124. *> N is INTEGER
  125. *> The number of linear equations, i.e., the order of the
  126. *> matrix A. N >= 0.
  127. *> \endverbatim
  128. *>
  129. *> \param[in] NRHS
  130. *> \verbatim
  131. *> NRHS is INTEGER
  132. *> The number of right hand sides, i.e., the number of columns
  133. *> of the matrices B and X. NRHS >= 0.
  134. *> \endverbatim
  135. *>
  136. *> \param[in,out] A
  137. *> \verbatim
  138. *> A is COMPLEX*16 array, dimension (LDA,N)
  139. *> On entry, the N-by-N matrix A. If FACT = 'F' and EQUED is
  140. *> not 'N', then A must have been equilibrated by the scaling
  141. *> factors in R and/or C. A is not modified if FACT = 'F' or
  142. *> 'N', or if FACT = 'E' and EQUED = 'N' on exit.
  143. *>
  144. *> On exit, if EQUED .ne. 'N', A is scaled as follows:
  145. *> EQUED = 'R': A := diag(R) * A
  146. *> EQUED = 'C': A := A * diag(C)
  147. *> EQUED = 'B': A := diag(R) * A * diag(C).
  148. *> \endverbatim
  149. *>
  150. *> \param[in] LDA
  151. *> \verbatim
  152. *> LDA is INTEGER
  153. *> The leading dimension of the array A. LDA >= max(1,N).
  154. *> \endverbatim
  155. *>
  156. *> \param[in,out] AF
  157. *> \verbatim
  158. *> AF is COMPLEX*16 array, dimension (LDAF,N)
  159. *> If FACT = 'F', then AF is an input argument and on entry
  160. *> contains the factors L and U from the factorization
  161. *> A = P*L*U as computed by ZGETRF. If EQUED .ne. 'N', then
  162. *> AF is the factored form of the equilibrated matrix A.
  163. *>
  164. *> If FACT = 'N', then AF is an output argument and on exit
  165. *> returns the factors L and U from the factorization A = P*L*U
  166. *> of the original matrix A.
  167. *>
  168. *> If FACT = 'E', then AF is an output argument and on exit
  169. *> returns the factors L and U from the factorization A = P*L*U
  170. *> of the equilibrated matrix A (see the description of A for
  171. *> the form of the equilibrated matrix).
  172. *> \endverbatim
  173. *>
  174. *> \param[in] LDAF
  175. *> \verbatim
  176. *> LDAF is INTEGER
  177. *> The leading dimension of the array AF. LDAF >= max(1,N).
  178. *> \endverbatim
  179. *>
  180. *> \param[in,out] IPIV
  181. *> \verbatim
  182. *> IPIV is INTEGER array, dimension (N)
  183. *> If FACT = 'F', then IPIV is an input argument and on entry
  184. *> contains the pivot indices from the factorization A = P*L*U
  185. *> as computed by ZGETRF; row i of the matrix was interchanged
  186. *> with row IPIV(i).
  187. *>
  188. *> If FACT = 'N', then IPIV is an output argument and on exit
  189. *> contains the pivot indices from the factorization A = P*L*U
  190. *> of the original matrix A.
  191. *>
  192. *> If FACT = 'E', then IPIV is an output argument and on exit
  193. *> contains the pivot indices from the factorization A = P*L*U
  194. *> of the equilibrated matrix A.
  195. *> \endverbatim
  196. *>
  197. *> \param[in,out] EQUED
  198. *> \verbatim
  199. *> EQUED is CHARACTER*1
  200. *> Specifies the form of equilibration that was done.
  201. *> = 'N': No equilibration (always true if FACT = 'N').
  202. *> = 'R': Row equilibration, i.e., A has been premultiplied by
  203. *> diag(R).
  204. *> = 'C': Column equilibration, i.e., A has been postmultiplied
  205. *> by diag(C).
  206. *> = 'B': Both row and column equilibration, i.e., A has been
  207. *> replaced by diag(R) * A * diag(C).
  208. *> EQUED is an input argument if FACT = 'F'; otherwise, it is an
  209. *> output argument.
  210. *> \endverbatim
  211. *>
  212. *> \param[in,out] R
  213. *> \verbatim
  214. *> R is DOUBLE PRECISION array, dimension (N)
  215. *> The row scale factors for A. If EQUED = 'R' or 'B', A is
  216. *> multiplied on the left by diag(R); if EQUED = 'N' or 'C', R
  217. *> is not accessed. R is an input argument if FACT = 'F';
  218. *> otherwise, R is an output argument. If FACT = 'F' and
  219. *> EQUED = 'R' or 'B', each element of R must be positive.
  220. *> \endverbatim
  221. *>
  222. *> \param[in,out] C
  223. *> \verbatim
  224. *> C is DOUBLE PRECISION array, dimension (N)
  225. *> The column scale factors for A. If EQUED = 'C' or 'B', A is
  226. *> multiplied on the right by diag(C); if EQUED = 'N' or 'R', C
  227. *> is not accessed. C is an input argument if FACT = 'F';
  228. *> otherwise, C is an output argument. If FACT = 'F' and
  229. *> EQUED = 'C' or 'B', each element of C must be positive.
  230. *> \endverbatim
  231. *>
  232. *> \param[in,out] B
  233. *> \verbatim
  234. *> B is COMPLEX*16 array, dimension (LDB,NRHS)
  235. *> On entry, the N-by-NRHS right hand side matrix B.
  236. *> On exit,
  237. *> if EQUED = 'N', B is not modified;
  238. *> if TRANS = 'N' and EQUED = 'R' or 'B', B is overwritten by
  239. *> diag(R)*B;
  240. *> if TRANS = 'T' or 'C' and EQUED = 'C' or 'B', B is
  241. *> overwritten by diag(C)*B.
  242. *> \endverbatim
  243. *>
  244. *> \param[in] LDB
  245. *> \verbatim
  246. *> LDB is INTEGER
  247. *> The leading dimension of the array B. LDB >= max(1,N).
  248. *> \endverbatim
  249. *>
  250. *> \param[out] X
  251. *> \verbatim
  252. *> X is COMPLEX*16 array, dimension (LDX,NRHS)
  253. *> If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X
  254. *> to the original system of equations. Note that A and B are
  255. *> modified on exit if EQUED .ne. 'N', and the solution to the
  256. *> equilibrated system is inv(diag(C))*X if TRANS = 'N' and
  257. *> EQUED = 'C' or 'B', or inv(diag(R))*X if TRANS = 'T' or 'C'
  258. *> and EQUED = 'R' or 'B'.
  259. *> \endverbatim
  260. *>
  261. *> \param[in] LDX
  262. *> \verbatim
  263. *> LDX is INTEGER
  264. *> The leading dimension of the array X. LDX >= max(1,N).
  265. *> \endverbatim
  266. *>
  267. *> \param[out] RCOND
  268. *> \verbatim
  269. *> RCOND is DOUBLE PRECISION
  270. *> The estimate of the reciprocal condition number of the matrix
  271. *> A after equilibration (if done). If RCOND is less than the
  272. *> machine precision (in particular, if RCOND = 0), the matrix
  273. *> is singular to working precision. This condition is
  274. *> indicated by a return code of INFO > 0.
  275. *> \endverbatim
  276. *>
  277. *> \param[out] FERR
  278. *> \verbatim
  279. *> FERR is DOUBLE PRECISION array, dimension (NRHS)
  280. *> The estimated forward error bound for each solution vector
  281. *> X(j) (the j-th column of the solution matrix X).
  282. *> If XTRUE is the true solution corresponding to X(j), FERR(j)
  283. *> is an estimated upper bound for the magnitude of the largest
  284. *> element in (X(j) - XTRUE) divided by the magnitude of the
  285. *> largest element in X(j). The estimate is as reliable as
  286. *> the estimate for RCOND, and is almost always a slight
  287. *> overestimate of the true error.
  288. *> \endverbatim
  289. *>
  290. *> \param[out] BERR
  291. *> \verbatim
  292. *> BERR is DOUBLE PRECISION array, dimension (NRHS)
  293. *> The componentwise relative backward error of each solution
  294. *> vector X(j) (i.e., the smallest relative change in
  295. *> any element of A or B that makes X(j) an exact solution).
  296. *> \endverbatim
  297. *>
  298. *> \param[out] WORK
  299. *> \verbatim
  300. *> WORK is COMPLEX*16 array, dimension (2*N)
  301. *> \endverbatim
  302. *>
  303. *> \param[out] RWORK
  304. *> \verbatim
  305. *> RWORK is DOUBLE PRECISION array, dimension (2*N)
  306. *> On exit, RWORK(1) contains the reciprocal pivot growth
  307. *> factor norm(A)/norm(U). The "max absolute element" norm is
  308. *> used. If RWORK(1) is much less than 1, then the stability
  309. *> of the LU factorization of the (equilibrated) matrix A
  310. *> could be poor. This also means that the solution X, condition
  311. *> estimator RCOND, and forward error bound FERR could be
  312. *> unreliable. If factorization fails with 0<INFO<=N, then
  313. *> RWORK(1) contains the reciprocal pivot growth factor for the
  314. *> leading INFO columns of A.
  315. *> \endverbatim
  316. *>
  317. *> \param[out] INFO
  318. *> \verbatim
  319. *> INFO is INTEGER
  320. *> = 0: successful exit
  321. *> < 0: if INFO = -i, the i-th argument had an illegal value
  322. *> > 0: if INFO = i, and i is
  323. *> <= N: U(i,i) is exactly zero. The factorization has
  324. *> been completed, but the factor U is exactly
  325. *> singular, so the solution and error bounds
  326. *> could not be computed. RCOND = 0 is returned.
  327. *> = N+1: U is nonsingular, but RCOND is less than machine
  328. *> precision, meaning that the matrix is singular
  329. *> to working precision. Nevertheless, the
  330. *> solution and error bounds are computed because
  331. *> there are a number of situations where the
  332. *> computed solution can be more accurate than the
  333. *> value of RCOND would suggest.
  334. *> \endverbatim
  335. *
  336. * Authors:
  337. * ========
  338. *
  339. *> \author Univ. of Tennessee
  340. *> \author Univ. of California Berkeley
  341. *> \author Univ. of Colorado Denver
  342. *> \author NAG Ltd.
  343. *
  344. *> \ingroup complex16GEsolve
  345. *
  346. * =====================================================================
  347. SUBROUTINE ZGESVX( FACT, TRANS, N, NRHS, A, LDA, AF, LDAF, IPIV,
  348. $ EQUED, R, C, B, LDB, X, LDX, RCOND, FERR, BERR,
  349. $ WORK, RWORK, INFO )
  350. *
  351. * -- LAPACK driver routine --
  352. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  353. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  354. *
  355. * .. Scalar Arguments ..
  356. CHARACTER EQUED, FACT, TRANS
  357. INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS
  358. DOUBLE PRECISION RCOND
  359. * ..
  360. * .. Array Arguments ..
  361. INTEGER IPIV( * )
  362. DOUBLE PRECISION BERR( * ), C( * ), FERR( * ), R( * ),
  363. $ RWORK( * )
  364. COMPLEX*16 A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
  365. $ WORK( * ), X( LDX, * )
  366. * ..
  367. *
  368. * =====================================================================
  369. *
  370. * .. Parameters ..
  371. DOUBLE PRECISION ZERO, ONE
  372. PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
  373. * ..
  374. * .. Local Scalars ..
  375. LOGICAL COLEQU, EQUIL, NOFACT, NOTRAN, ROWEQU
  376. CHARACTER NORM
  377. INTEGER I, INFEQU, J
  378. DOUBLE PRECISION AMAX, ANORM, BIGNUM, COLCND, RCMAX, RCMIN,
  379. $ ROWCND, RPVGRW, SMLNUM
  380. * ..
  381. * .. External Functions ..
  382. LOGICAL LSAME
  383. DOUBLE PRECISION DLAMCH, ZLANGE, ZLANTR
  384. EXTERNAL LSAME, DLAMCH, ZLANGE, ZLANTR
  385. * ..
  386. * .. External Subroutines ..
  387. EXTERNAL XERBLA, ZGECON, ZGEEQU, ZGERFS, ZGETRF, ZGETRS,
  388. $ ZLACPY, ZLAQGE
  389. * ..
  390. * .. Intrinsic Functions ..
  391. INTRINSIC MAX, MIN
  392. * ..
  393. * .. Executable Statements ..
  394. *
  395. INFO = 0
  396. NOFACT = LSAME( FACT, 'N' )
  397. EQUIL = LSAME( FACT, 'E' )
  398. NOTRAN = LSAME( TRANS, 'N' )
  399. IF( NOFACT .OR. EQUIL ) THEN
  400. EQUED = 'N'
  401. ROWEQU = .FALSE.
  402. COLEQU = .FALSE.
  403. ELSE
  404. ROWEQU = LSAME( EQUED, 'R' ) .OR. LSAME( EQUED, 'B' )
  405. COLEQU = LSAME( EQUED, 'C' ) .OR. LSAME( EQUED, 'B' )
  406. SMLNUM = DLAMCH( 'Safe minimum' )
  407. BIGNUM = ONE / SMLNUM
  408. END IF
  409. *
  410. * Test the input parameters.
  411. *
  412. IF( .NOT.NOFACT .AND. .NOT.EQUIL .AND. .NOT.LSAME( FACT, 'F' ) )
  413. $ THEN
  414. INFO = -1
  415. ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT.
  416. $ LSAME( TRANS, 'C' ) ) THEN
  417. INFO = -2
  418. ELSE IF( N.LT.0 ) THEN
  419. INFO = -3
  420. ELSE IF( NRHS.LT.0 ) THEN
  421. INFO = -4
  422. ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
  423. INFO = -6
  424. ELSE IF( LDAF.LT.MAX( 1, N ) ) THEN
  425. INFO = -8
  426. ELSE IF( LSAME( FACT, 'F' ) .AND. .NOT.
  427. $ ( ROWEQU .OR. COLEQU .OR. LSAME( EQUED, 'N' ) ) ) THEN
  428. INFO = -10
  429. ELSE
  430. IF( ROWEQU ) THEN
  431. RCMIN = BIGNUM
  432. RCMAX = ZERO
  433. DO 10 J = 1, N
  434. RCMIN = MIN( RCMIN, R( J ) )
  435. RCMAX = MAX( RCMAX, R( J ) )
  436. 10 CONTINUE
  437. IF( RCMIN.LE.ZERO ) THEN
  438. INFO = -11
  439. ELSE IF( N.GT.0 ) THEN
  440. ROWCND = MAX( RCMIN, SMLNUM ) / MIN( RCMAX, BIGNUM )
  441. ELSE
  442. ROWCND = ONE
  443. END IF
  444. END IF
  445. IF( COLEQU .AND. INFO.EQ.0 ) THEN
  446. RCMIN = BIGNUM
  447. RCMAX = ZERO
  448. DO 20 J = 1, N
  449. RCMIN = MIN( RCMIN, C( J ) )
  450. RCMAX = MAX( RCMAX, C( J ) )
  451. 20 CONTINUE
  452. IF( RCMIN.LE.ZERO ) THEN
  453. INFO = -12
  454. ELSE IF( N.GT.0 ) THEN
  455. COLCND = MAX( RCMIN, SMLNUM ) / MIN( RCMAX, BIGNUM )
  456. ELSE
  457. COLCND = ONE
  458. END IF
  459. END IF
  460. IF( INFO.EQ.0 ) THEN
  461. IF( LDB.LT.MAX( 1, N ) ) THEN
  462. INFO = -14
  463. ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
  464. INFO = -16
  465. END IF
  466. END IF
  467. END IF
  468. *
  469. IF( INFO.NE.0 ) THEN
  470. CALL XERBLA( 'ZGESVX', -INFO )
  471. RETURN
  472. END IF
  473. *
  474. IF( EQUIL ) THEN
  475. *
  476. * Compute row and column scalings to equilibrate the matrix A.
  477. *
  478. CALL ZGEEQU( N, N, A, LDA, R, C, ROWCND, COLCND, AMAX, INFEQU )
  479. IF( INFEQU.EQ.0 ) THEN
  480. *
  481. * Equilibrate the matrix.
  482. *
  483. CALL ZLAQGE( N, N, A, LDA, R, C, ROWCND, COLCND, AMAX,
  484. $ EQUED )
  485. ROWEQU = LSAME( EQUED, 'R' ) .OR. LSAME( EQUED, 'B' )
  486. COLEQU = LSAME( EQUED, 'C' ) .OR. LSAME( EQUED, 'B' )
  487. END IF
  488. END IF
  489. *
  490. * Scale the right hand side.
  491. *
  492. IF( NOTRAN ) THEN
  493. IF( ROWEQU ) THEN
  494. DO 40 J = 1, NRHS
  495. DO 30 I = 1, N
  496. B( I, J ) = R( I )*B( I, J )
  497. 30 CONTINUE
  498. 40 CONTINUE
  499. END IF
  500. ELSE IF( COLEQU ) THEN
  501. DO 60 J = 1, NRHS
  502. DO 50 I = 1, N
  503. B( I, J ) = C( I )*B( I, J )
  504. 50 CONTINUE
  505. 60 CONTINUE
  506. END IF
  507. *
  508. IF( NOFACT .OR. EQUIL ) THEN
  509. *
  510. * Compute the LU factorization of A.
  511. *
  512. CALL ZLACPY( 'Full', N, N, A, LDA, AF, LDAF )
  513. CALL ZGETRF( N, N, AF, LDAF, IPIV, INFO )
  514. *
  515. * Return if INFO is non-zero.
  516. *
  517. IF( INFO.GT.0 ) THEN
  518. *
  519. * Compute the reciprocal pivot growth factor of the
  520. * leading rank-deficient INFO columns of A.
  521. *
  522. RPVGRW = ZLANTR( 'M', 'U', 'N', INFO, INFO, AF, LDAF,
  523. $ RWORK )
  524. IF( RPVGRW.EQ.ZERO ) THEN
  525. RPVGRW = ONE
  526. ELSE
  527. RPVGRW = ZLANGE( 'M', N, INFO, A, LDA, RWORK ) /
  528. $ RPVGRW
  529. END IF
  530. RWORK( 1 ) = RPVGRW
  531. RCOND = ZERO
  532. RETURN
  533. END IF
  534. END IF
  535. *
  536. * Compute the norm of the matrix A and the
  537. * reciprocal pivot growth factor RPVGRW.
  538. *
  539. IF( NOTRAN ) THEN
  540. NORM = '1'
  541. ELSE
  542. NORM = 'I'
  543. END IF
  544. ANORM = ZLANGE( NORM, N, N, A, LDA, RWORK )
  545. RPVGRW = ZLANTR( 'M', 'U', 'N', N, N, AF, LDAF, RWORK )
  546. IF( RPVGRW.EQ.ZERO ) THEN
  547. RPVGRW = ONE
  548. ELSE
  549. RPVGRW = ZLANGE( 'M', N, N, A, LDA, RWORK ) / RPVGRW
  550. END IF
  551. *
  552. * Compute the reciprocal of the condition number of A.
  553. *
  554. CALL ZGECON( NORM, N, AF, LDAF, ANORM, RCOND, WORK, RWORK, INFO )
  555. *
  556. * Compute the solution matrix X.
  557. *
  558. CALL ZLACPY( 'Full', N, NRHS, B, LDB, X, LDX )
  559. CALL ZGETRS( TRANS, N, NRHS, AF, LDAF, IPIV, X, LDX, INFO )
  560. *
  561. * Use iterative refinement to improve the computed solution and
  562. * compute error bounds and backward error estimates for it.
  563. *
  564. CALL ZGERFS( TRANS, N, NRHS, A, LDA, AF, LDAF, IPIV, B, LDB, X,
  565. $ LDX, FERR, BERR, WORK, RWORK, INFO )
  566. *
  567. * Transform the solution matrix X to a solution of the original
  568. * system.
  569. *
  570. IF( NOTRAN ) THEN
  571. IF( COLEQU ) THEN
  572. DO 80 J = 1, NRHS
  573. DO 70 I = 1, N
  574. X( I, J ) = C( I )*X( I, J )
  575. 70 CONTINUE
  576. 80 CONTINUE
  577. DO 90 J = 1, NRHS
  578. FERR( J ) = FERR( J ) / COLCND
  579. 90 CONTINUE
  580. END IF
  581. ELSE IF( ROWEQU ) THEN
  582. DO 110 J = 1, NRHS
  583. DO 100 I = 1, N
  584. X( I, J ) = R( I )*X( I, J )
  585. 100 CONTINUE
  586. 110 CONTINUE
  587. DO 120 J = 1, NRHS
  588. FERR( J ) = FERR( J ) / ROWCND
  589. 120 CONTINUE
  590. END IF
  591. *
  592. * Set INFO = N+1 if the matrix is singular to working precision.
  593. *
  594. IF( RCOND.LT.DLAMCH( 'Epsilon' ) )
  595. $ INFO = N + 1
  596. *
  597. RWORK( 1 ) = RPVGRW
  598. RETURN
  599. *
  600. * End of ZGESVX
  601. *
  602. END