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