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.

zptrfs.f 15 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. *> \brief \b ZPTRFS
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download ZPTRFS + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zptrfs.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zptrfs.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zptrfs.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE ZPTRFS( UPLO, N, NRHS, D, E, DF, EF, B, LDB, X, LDX,
  22. * FERR, BERR, WORK, RWORK, INFO )
  23. *
  24. * .. Scalar Arguments ..
  25. * CHARACTER UPLO
  26. * INTEGER INFO, LDB, LDX, N, NRHS
  27. * ..
  28. * .. Array Arguments ..
  29. * DOUBLE PRECISION BERR( * ), D( * ), DF( * ), FERR( * ),
  30. * $ RWORK( * )
  31. * COMPLEX*16 B( LDB, * ), E( * ), EF( * ), WORK( * ),
  32. * $ X( LDX, * )
  33. * ..
  34. *
  35. *
  36. *> \par Purpose:
  37. * =============
  38. *>
  39. *> \verbatim
  40. *>
  41. *> ZPTRFS improves the computed solution to a system of linear
  42. *> equations when the coefficient matrix is Hermitian positive definite
  43. *> and tridiagonal, and provides error bounds and backward error
  44. *> estimates for the solution.
  45. *> \endverbatim
  46. *
  47. * Arguments:
  48. * ==========
  49. *
  50. *> \param[in] UPLO
  51. *> \verbatim
  52. *> UPLO is CHARACTER*1
  53. *> Specifies whether the superdiagonal or the subdiagonal of the
  54. *> tridiagonal matrix A is stored and the form of the
  55. *> factorization:
  56. *> = 'U': E is the superdiagonal of A, and A = U**H*D*U;
  57. *> = 'L': E is the subdiagonal of A, and A = L*D*L**H.
  58. *> (The two forms are equivalent if A is real.)
  59. *> \endverbatim
  60. *>
  61. *> \param[in] N
  62. *> \verbatim
  63. *> N is INTEGER
  64. *> The order of the matrix A. N >= 0.
  65. *> \endverbatim
  66. *>
  67. *> \param[in] NRHS
  68. *> \verbatim
  69. *> NRHS is INTEGER
  70. *> The number of right hand sides, i.e., the number of columns
  71. *> of the matrix B. NRHS >= 0.
  72. *> \endverbatim
  73. *>
  74. *> \param[in] D
  75. *> \verbatim
  76. *> D is DOUBLE PRECISION array, dimension (N)
  77. *> The n real diagonal elements of the tridiagonal matrix A.
  78. *> \endverbatim
  79. *>
  80. *> \param[in] E
  81. *> \verbatim
  82. *> E is COMPLEX*16 array, dimension (N-1)
  83. *> The (n-1) off-diagonal elements of the tridiagonal matrix A
  84. *> (see UPLO).
  85. *> \endverbatim
  86. *>
  87. *> \param[in] DF
  88. *> \verbatim
  89. *> DF is DOUBLE PRECISION array, dimension (N)
  90. *> The n diagonal elements of the diagonal matrix D from
  91. *> the factorization computed by ZPTTRF.
  92. *> \endverbatim
  93. *>
  94. *> \param[in] EF
  95. *> \verbatim
  96. *> EF is COMPLEX*16 array, dimension (N-1)
  97. *> The (n-1) off-diagonal elements of the unit bidiagonal
  98. *> factor U or L from the factorization computed by ZPTTRF
  99. *> (see UPLO).
  100. *> \endverbatim
  101. *>
  102. *> \param[in] B
  103. *> \verbatim
  104. *> B is COMPLEX*16 array, dimension (LDB,NRHS)
  105. *> The right hand side matrix B.
  106. *> \endverbatim
  107. *>
  108. *> \param[in] LDB
  109. *> \verbatim
  110. *> LDB is INTEGER
  111. *> The leading dimension of the array B. LDB >= max(1,N).
  112. *> \endverbatim
  113. *>
  114. *> \param[in,out] X
  115. *> \verbatim
  116. *> X is COMPLEX*16 array, dimension (LDX,NRHS)
  117. *> On entry, the solution matrix X, as computed by ZPTTRS.
  118. *> On exit, the improved solution matrix X.
  119. *> \endverbatim
  120. *>
  121. *> \param[in] LDX
  122. *> \verbatim
  123. *> LDX is INTEGER
  124. *> The leading dimension of the array X. LDX >= max(1,N).
  125. *> \endverbatim
  126. *>
  127. *> \param[out] FERR
  128. *> \verbatim
  129. *> FERR is DOUBLE PRECISION array, dimension (NRHS)
  130. *> The forward error bound for each solution vector
  131. *> X(j) (the j-th column of the solution matrix X).
  132. *> If XTRUE is the true solution corresponding to X(j), FERR(j)
  133. *> is an estimated upper bound for the magnitude of the largest
  134. *> element in (X(j) - XTRUE) divided by the magnitude of the
  135. *> largest element in X(j).
  136. *> \endverbatim
  137. *>
  138. *> \param[out] BERR
  139. *> \verbatim
  140. *> BERR is DOUBLE PRECISION array, dimension (NRHS)
  141. *> The componentwise relative backward error of each solution
  142. *> vector X(j) (i.e., the smallest relative change in
  143. *> any element of A or B that makes X(j) an exact solution).
  144. *> \endverbatim
  145. *>
  146. *> \param[out] WORK
  147. *> \verbatim
  148. *> WORK is COMPLEX*16 array, dimension (N)
  149. *> \endverbatim
  150. *>
  151. *> \param[out] RWORK
  152. *> \verbatim
  153. *> RWORK is DOUBLE PRECISION array, dimension (N)
  154. *> \endverbatim
  155. *>
  156. *> \param[out] INFO
  157. *> \verbatim
  158. *> INFO is INTEGER
  159. *> = 0: successful exit
  160. *> < 0: if INFO = -i, the i-th argument had an illegal value
  161. *> \endverbatim
  162. *
  163. *> \par Internal Parameters:
  164. * =========================
  165. *>
  166. *> \verbatim
  167. *> ITMAX is the maximum number of steps of iterative refinement.
  168. *> \endverbatim
  169. *
  170. * Authors:
  171. * ========
  172. *
  173. *> \author Univ. of Tennessee
  174. *> \author Univ. of California Berkeley
  175. *> \author Univ. of Colorado Denver
  176. *> \author NAG Ltd.
  177. *
  178. *> \ingroup complex16PTcomputational
  179. *
  180. * =====================================================================
  181. SUBROUTINE ZPTRFS( UPLO, N, NRHS, D, E, DF, EF, B, LDB, X, LDX,
  182. $ FERR, BERR, WORK, RWORK, INFO )
  183. *
  184. * -- LAPACK computational routine --
  185. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  186. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  187. *
  188. * .. Scalar Arguments ..
  189. CHARACTER UPLO
  190. INTEGER INFO, LDB, LDX, N, NRHS
  191. * ..
  192. * .. Array Arguments ..
  193. DOUBLE PRECISION BERR( * ), D( * ), DF( * ), FERR( * ),
  194. $ RWORK( * )
  195. COMPLEX*16 B( LDB, * ), E( * ), EF( * ), WORK( * ),
  196. $ X( LDX, * )
  197. * ..
  198. *
  199. * =====================================================================
  200. *
  201. * .. Parameters ..
  202. INTEGER ITMAX
  203. PARAMETER ( ITMAX = 5 )
  204. DOUBLE PRECISION ZERO
  205. PARAMETER ( ZERO = 0.0D+0 )
  206. DOUBLE PRECISION ONE
  207. PARAMETER ( ONE = 1.0D+0 )
  208. DOUBLE PRECISION TWO
  209. PARAMETER ( TWO = 2.0D+0 )
  210. DOUBLE PRECISION THREE
  211. PARAMETER ( THREE = 3.0D+0 )
  212. * ..
  213. * .. Local Scalars ..
  214. LOGICAL UPPER
  215. INTEGER COUNT, I, IX, J, NZ
  216. DOUBLE PRECISION EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN
  217. COMPLEX*16 BI, CX, DX, EX, ZDUM
  218. * ..
  219. * .. External Functions ..
  220. LOGICAL LSAME
  221. INTEGER IDAMAX
  222. DOUBLE PRECISION DLAMCH
  223. EXTERNAL LSAME, IDAMAX, DLAMCH
  224. * ..
  225. * .. External Subroutines ..
  226. EXTERNAL XERBLA, ZAXPY, ZPTTRS
  227. * ..
  228. * .. Intrinsic Functions ..
  229. INTRINSIC ABS, DBLE, DCMPLX, DCONJG, DIMAG, MAX
  230. * ..
  231. * .. Statement Functions ..
  232. DOUBLE PRECISION CABS1
  233. * ..
  234. * .. Statement Function definitions ..
  235. CABS1( ZDUM ) = ABS( DBLE( ZDUM ) ) + ABS( DIMAG( ZDUM ) )
  236. * ..
  237. * .. Executable Statements ..
  238. *
  239. * Test the input parameters.
  240. *
  241. INFO = 0
  242. UPPER = LSAME( UPLO, 'U' )
  243. IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
  244. INFO = -1
  245. ELSE IF( N.LT.0 ) THEN
  246. INFO = -2
  247. ELSE IF( NRHS.LT.0 ) THEN
  248. INFO = -3
  249. ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
  250. INFO = -9
  251. ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
  252. INFO = -11
  253. END IF
  254. IF( INFO.NE.0 ) THEN
  255. CALL XERBLA( 'ZPTRFS', -INFO )
  256. RETURN
  257. END IF
  258. *
  259. * Quick return if possible
  260. *
  261. IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
  262. DO 10 J = 1, NRHS
  263. FERR( J ) = ZERO
  264. BERR( J ) = ZERO
  265. 10 CONTINUE
  266. RETURN
  267. END IF
  268. *
  269. * NZ = maximum number of nonzero elements in each row of A, plus 1
  270. *
  271. NZ = 4
  272. EPS = DLAMCH( 'Epsilon' )
  273. SAFMIN = DLAMCH( 'Safe minimum' )
  274. SAFE1 = NZ*SAFMIN
  275. SAFE2 = SAFE1 / EPS
  276. *
  277. * Do for each right hand side
  278. *
  279. DO 100 J = 1, NRHS
  280. *
  281. COUNT = 1
  282. LSTRES = THREE
  283. 20 CONTINUE
  284. *
  285. * Loop until stopping criterion is satisfied.
  286. *
  287. * Compute residual R = B - A * X. Also compute
  288. * abs(A)*abs(x) + abs(b) for use in the backward error bound.
  289. *
  290. IF( UPPER ) THEN
  291. IF( N.EQ.1 ) THEN
  292. BI = B( 1, J )
  293. DX = D( 1 )*X( 1, J )
  294. WORK( 1 ) = BI - DX
  295. RWORK( 1 ) = CABS1( BI ) + CABS1( DX )
  296. ELSE
  297. BI = B( 1, J )
  298. DX = D( 1 )*X( 1, J )
  299. EX = E( 1 )*X( 2, J )
  300. WORK( 1 ) = BI - DX - EX
  301. RWORK( 1 ) = CABS1( BI ) + CABS1( DX ) +
  302. $ CABS1( E( 1 ) )*CABS1( X( 2, J ) )
  303. DO 30 I = 2, N - 1
  304. BI = B( I, J )
  305. CX = DCONJG( E( I-1 ) )*X( I-1, J )
  306. DX = D( I )*X( I, J )
  307. EX = E( I )*X( I+1, J )
  308. WORK( I ) = BI - CX - DX - EX
  309. RWORK( I ) = CABS1( BI ) +
  310. $ CABS1( E( I-1 ) )*CABS1( X( I-1, J ) ) +
  311. $ CABS1( DX ) + CABS1( E( I ) )*
  312. $ CABS1( X( I+1, J ) )
  313. 30 CONTINUE
  314. BI = B( N, J )
  315. CX = DCONJG( E( N-1 ) )*X( N-1, J )
  316. DX = D( N )*X( N, J )
  317. WORK( N ) = BI - CX - DX
  318. RWORK( N ) = CABS1( BI ) + CABS1( E( N-1 ) )*
  319. $ CABS1( X( N-1, J ) ) + CABS1( DX )
  320. END IF
  321. ELSE
  322. IF( N.EQ.1 ) THEN
  323. BI = B( 1, J )
  324. DX = D( 1 )*X( 1, J )
  325. WORK( 1 ) = BI - DX
  326. RWORK( 1 ) = CABS1( BI ) + CABS1( DX )
  327. ELSE
  328. BI = B( 1, J )
  329. DX = D( 1 )*X( 1, J )
  330. EX = DCONJG( E( 1 ) )*X( 2, J )
  331. WORK( 1 ) = BI - DX - EX
  332. RWORK( 1 ) = CABS1( BI ) + CABS1( DX ) +
  333. $ CABS1( E( 1 ) )*CABS1( X( 2, J ) )
  334. DO 40 I = 2, N - 1
  335. BI = B( I, J )
  336. CX = E( I-1 )*X( I-1, J )
  337. DX = D( I )*X( I, J )
  338. EX = DCONJG( E( I ) )*X( I+1, J )
  339. WORK( I ) = BI - CX - DX - EX
  340. RWORK( I ) = CABS1( BI ) +
  341. $ CABS1( E( I-1 ) )*CABS1( X( I-1, J ) ) +
  342. $ CABS1( DX ) + CABS1( E( I ) )*
  343. $ CABS1( X( I+1, J ) )
  344. 40 CONTINUE
  345. BI = B( N, J )
  346. CX = E( N-1 )*X( N-1, J )
  347. DX = D( N )*X( N, J )
  348. WORK( N ) = BI - CX - DX
  349. RWORK( N ) = CABS1( BI ) + CABS1( E( N-1 ) )*
  350. $ CABS1( X( N-1, J ) ) + CABS1( DX )
  351. END IF
  352. END IF
  353. *
  354. * Compute componentwise relative backward error from formula
  355. *
  356. * max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) )
  357. *
  358. * where abs(Z) is the componentwise absolute value of the matrix
  359. * or vector Z. If the i-th component of the denominator is less
  360. * than SAFE2, then SAFE1 is added to the i-th components of the
  361. * numerator and denominator before dividing.
  362. *
  363. S = ZERO
  364. DO 50 I = 1, N
  365. IF( RWORK( I ).GT.SAFE2 ) THEN
  366. S = MAX( S, CABS1( WORK( I ) ) / RWORK( I ) )
  367. ELSE
  368. S = MAX( S, ( CABS1( WORK( I ) )+SAFE1 ) /
  369. $ ( RWORK( I )+SAFE1 ) )
  370. END IF
  371. 50 CONTINUE
  372. BERR( J ) = S
  373. *
  374. * Test stopping criterion. Continue iterating if
  375. * 1) The residual BERR(J) is larger than machine epsilon, and
  376. * 2) BERR(J) decreased by at least a factor of 2 during the
  377. * last iteration, and
  378. * 3) At most ITMAX iterations tried.
  379. *
  380. IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
  381. $ COUNT.LE.ITMAX ) THEN
  382. *
  383. * Update solution and try again.
  384. *
  385. CALL ZPTTRS( UPLO, N, 1, DF, EF, WORK, N, INFO )
  386. CALL ZAXPY( N, DCMPLX( ONE ), WORK, 1, X( 1, J ), 1 )
  387. LSTRES = BERR( J )
  388. COUNT = COUNT + 1
  389. GO TO 20
  390. END IF
  391. *
  392. * Bound error from formula
  393. *
  394. * norm(X - XTRUE) / norm(X) .le. FERR =
  395. * norm( abs(inv(A))*
  396. * ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X)
  397. *
  398. * where
  399. * norm(Z) is the magnitude of the largest component of Z
  400. * inv(A) is the inverse of A
  401. * abs(Z) is the componentwise absolute value of the matrix or
  402. * vector Z
  403. * NZ is the maximum number of nonzeros in any row of A, plus 1
  404. * EPS is machine epsilon
  405. *
  406. * The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B))
  407. * is incremented by SAFE1 if the i-th component of
  408. * abs(A)*abs(X) + abs(B) is less than SAFE2.
  409. *
  410. DO 60 I = 1, N
  411. IF( RWORK( I ).GT.SAFE2 ) THEN
  412. RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I )
  413. ELSE
  414. RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I ) +
  415. $ SAFE1
  416. END IF
  417. 60 CONTINUE
  418. IX = IDAMAX( N, RWORK, 1 )
  419. FERR( J ) = RWORK( IX )
  420. *
  421. * Estimate the norm of inv(A).
  422. *
  423. * Solve M(A) * x = e, where M(A) = (m(i,j)) is given by
  424. *
  425. * m(i,j) = abs(A(i,j)), i = j,
  426. * m(i,j) = -abs(A(i,j)), i .ne. j,
  427. *
  428. * and e = [ 1, 1, ..., 1 ]**T. Note M(A) = M(L)*D*M(L)**H.
  429. *
  430. * Solve M(L) * x = e.
  431. *
  432. RWORK( 1 ) = ONE
  433. DO 70 I = 2, N
  434. RWORK( I ) = ONE + RWORK( I-1 )*ABS( EF( I-1 ) )
  435. 70 CONTINUE
  436. *
  437. * Solve D * M(L)**H * x = b.
  438. *
  439. RWORK( N ) = RWORK( N ) / DF( N )
  440. DO 80 I = N - 1, 1, -1
  441. RWORK( I ) = RWORK( I ) / DF( I ) +
  442. $ RWORK( I+1 )*ABS( EF( I ) )
  443. 80 CONTINUE
  444. *
  445. * Compute norm(inv(A)) = max(x(i)), 1<=i<=n.
  446. *
  447. IX = IDAMAX( N, RWORK, 1 )
  448. FERR( J ) = FERR( J )*ABS( RWORK( IX ) )
  449. *
  450. * Normalize error.
  451. *
  452. LSTRES = ZERO
  453. DO 90 I = 1, N
  454. LSTRES = MAX( LSTRES, ABS( X( I, J ) ) )
  455. 90 CONTINUE
  456. IF( LSTRES.NE.ZERO )
  457. $ FERR( J ) = FERR( J ) / LSTRES
  458. *
  459. 100 CONTINUE
  460. *
  461. RETURN
  462. *
  463. * End of ZPTRFS
  464. *
  465. END