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