LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches

◆ ctbrfs()

subroutine ctbrfs ( character uplo,
character trans,
character diag,
integer n,
integer kd,
integer nrhs,
complex, dimension( ldab, * ) ab,
integer ldab,
complex, dimension( ldb, * ) b,
integer ldb,
complex, dimension( ldx, * ) x,
integer ldx,
real, dimension( * ) ferr,
real, dimension( * ) berr,
complex, dimension( * ) work,
real, dimension( * ) rwork,
integer info )

CTBRFS

Download CTBRFS + dependencies [TGZ] [ZIP] [TXT]

Purpose:
!>
!> CTBRFS provides error bounds and backward error estimates for the
!> solution to a system of linear equations with a triangular band
!> coefficient matrix.
!>
!> The solution matrix X must be computed by CTBTRS or some other
!> means before entering this routine.  CTBRFS does not do iterative
!> refinement because doing so cannot improve the backward error.
!> 
Parameters
[in]UPLO
!>          UPLO is CHARACTER*1
!>          = 'U':  A is upper triangular;
!>          = 'L':  A is lower triangular.
!> 
[in]TRANS
!>          TRANS is CHARACTER*1
!>          Specifies the form of the system of equations:
!>          = 'N':  A * X = B     (No transpose)
!>          = 'T':  A**T * X = B  (Transpose)
!>          = 'C':  A**H * X = B  (Conjugate transpose)
!> 
[in]DIAG
!>          DIAG is CHARACTER*1
!>          = 'N':  A is non-unit triangular;
!>          = 'U':  A is unit triangular.
!> 
[in]N
!>          N is INTEGER
!>          The order of the matrix A.  N >= 0.
!> 
[in]KD
!>          KD is INTEGER
!>          The number of superdiagonals or subdiagonals of the
!>          triangular band matrix A.  KD >= 0.
!> 
[in]NRHS
!>          NRHS is INTEGER
!>          The number of right hand sides, i.e., the number of columns
!>          of the matrices B and X.  NRHS >= 0.
!> 
[in]AB
!>          AB is COMPLEX array, dimension (LDAB,N)
!>          The upper or lower triangular band matrix A, stored in the
!>          first kd+1 rows of the array. The j-th column of A is stored
!>          in the j-th column of the array AB as follows:
!>          if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j;
!>          if UPLO = 'L', AB(1+i-j,j)    = A(i,j) for j<=i<=min(n,j+kd).
!>          If DIAG = 'U', the diagonal elements of A are not referenced
!>          and are assumed to be 1.
!> 
[in]LDAB
!>          LDAB is INTEGER
!>          The leading dimension of the array AB.  LDAB >= KD+1.
!> 
[in]B
!>          B is COMPLEX array, dimension (LDB,NRHS)
!>          The right hand side matrix B.
!> 
[in]LDB
!>          LDB is INTEGER
!>          The leading dimension of the array B.  LDB >= max(1,N).
!> 
[in]X
!>          X is COMPLEX array, dimension (LDX,NRHS)
!>          The solution matrix X.
!> 
[in]LDX
!>          LDX is INTEGER
!>          The leading dimension of the array X.  LDX >= max(1,N).
!> 
[out]FERR
!>          FERR is REAL array, dimension (NRHS)
!>          The estimated forward error bound for each solution vector
!>          X(j) (the j-th column of the solution matrix X).
!>          If XTRUE is the true solution corresponding to X(j), FERR(j)
!>          is an estimated upper bound for the magnitude of the largest
!>          element in (X(j) - XTRUE) divided by the magnitude of the
!>          largest element in X(j).  The estimate is as reliable as
!>          the estimate for RCOND, and is almost always a slight
!>          overestimate of the true error.
!> 
[out]BERR
!>          BERR is REAL array, dimension (NRHS)
!>          The componentwise relative backward error of each solution
!>          vector X(j) (i.e., the smallest relative change in
!>          any element of A or B that makes X(j) an exact solution).
!> 
[out]WORK
!>          WORK is COMPLEX array, dimension (2*N)
!> 
[out]RWORK
!>          RWORK is REAL array, dimension (N)
!> 
[out]INFO
!>          INFO is INTEGER
!>          = 0:  successful exit
!>          < 0:  if INFO = -i, the i-th argument had an illegal value
!> 
Author
Univ. of Tennessee
Univ. of California Berkeley
Univ. of Colorado Denver
NAG Ltd.

Definition at line 184 of file ctbrfs.f.

186*
187* -- LAPACK computational routine --
188* -- LAPACK is a software package provided by Univ. of Tennessee, --
189* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
190*
191* .. Scalar Arguments ..
192 CHARACTER DIAG, TRANS, UPLO
193 INTEGER INFO, KD, LDAB, LDB, LDX, N, NRHS
194* ..
195* .. Array Arguments ..
196 REAL BERR( * ), FERR( * ), RWORK( * )
197 COMPLEX AB( LDAB, * ), B( LDB, * ), WORK( * ),
198 $ X( LDX, * )
199* ..
200*
201* =====================================================================
202*
203* .. Parameters ..
204 REAL ZERO
205 parameter( zero = 0.0e+0 )
206 COMPLEX ONE
207 parameter( one = ( 1.0e+0, 0.0e+0 ) )
208* ..
209* .. Local Scalars ..
210 LOGICAL NOTRAN, NOUNIT, UPPER
211 CHARACTER TRANSN, TRANST
212 INTEGER I, J, K, KASE, NZ
213 REAL EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
214 COMPLEX ZDUM
215* ..
216* .. Local Arrays ..
217 INTEGER ISAVE( 3 )
218* ..
219* .. External Subroutines ..
220 EXTERNAL caxpy, ccopy, clacn2, ctbmv, ctbsv,
221 $ xerbla
222* ..
223* .. Intrinsic Functions ..
224 INTRINSIC abs, aimag, max, min, real
225* ..
226* .. External Functions ..
227 LOGICAL LSAME
228 REAL SLAMCH
229 EXTERNAL lsame, slamch
230* ..
231* .. Statement Functions ..
232 REAL CABS1
233* ..
234* .. Statement Function definitions ..
235 cabs1( zdum ) = abs( real( zdum ) ) + abs( aimag( zdum ) )
236* ..
237* .. Executable Statements ..
238*
239* Test the input parameters.
240*
241 info = 0
242 upper = lsame( uplo, 'U' )
243 notran = lsame( trans, 'N' )
244 nounit = lsame( diag, 'N' )
245*
246 IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
247 info = -1
248 ELSE IF( .NOT.notran .AND. .NOT.lsame( trans, 'T' ) .AND. .NOT.
249 $ lsame( trans, 'C' ) ) THEN
250 info = -2
251 ELSE IF( .NOT.nounit .AND. .NOT.lsame( diag, 'U' ) ) THEN
252 info = -3
253 ELSE IF( n.LT.0 ) THEN
254 info = -4
255 ELSE IF( kd.LT.0 ) THEN
256 info = -5
257 ELSE IF( nrhs.LT.0 ) THEN
258 info = -6
259 ELSE IF( ldab.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( 'CTBRFS', -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 IF( notran ) THEN
282 transn = 'N'
283 transt = 'C'
284 ELSE
285 transn = 'C'
286 transt = 'N'
287 END IF
288*
289* NZ = maximum number of nonzero elements in each row of A, plus 1
290*
291 nz = kd + 2
292 eps = slamch( 'Epsilon' )
293 safmin = slamch( 'Safe minimum' )
294 safe1 = real( nz )*safmin
295 safe2 = safe1 / eps
296*
297* Do for each right hand side
298*
299 DO 250 j = 1, nrhs
300*
301* Compute residual R = B - op(A) * X,
302* where op(A) = A, A**T, or A**H, depending on TRANS.
303*
304 CALL ccopy( n, x( 1, j ), 1, work, 1 )
305 CALL ctbmv( uplo, trans, diag, n, kd, ab, ldab, work, 1 )
306 CALL caxpy( n, -one, b( 1, j ), 1, work, 1 )
307*
308* Compute componentwise relative backward error from formula
309*
310* max(i) ( abs(R(i)) / ( abs(op(A))*abs(X) + abs(B) )(i) )
311*
312* where abs(Z) is the componentwise absolute value of the matrix
313* or vector Z. If the i-th component of the denominator is less
314* than SAFE2, then SAFE1 is added to the i-th components of the
315* numerator and denominator before dividing.
316*
317 DO 20 i = 1, n
318 rwork( i ) = cabs1( b( i, j ) )
319 20 CONTINUE
320*
321 IF( notran ) THEN
322*
323* Compute abs(A)*abs(X) + abs(B).
324*
325 IF( upper ) THEN
326 IF( nounit ) THEN
327 DO 40 k = 1, n
328 xk = cabs1( x( k, j ) )
329 DO 30 i = max( 1, k-kd ), k
330 rwork( i ) = rwork( i ) +
331 $ cabs1( ab( kd+1+i-k, k ) )*xk
332 30 CONTINUE
333 40 CONTINUE
334 ELSE
335 DO 60 k = 1, n
336 xk = cabs1( x( k, j ) )
337 DO 50 i = max( 1, k-kd ), k - 1
338 rwork( i ) = rwork( i ) +
339 $ cabs1( ab( kd+1+i-k, k ) )*xk
340 50 CONTINUE
341 rwork( k ) = rwork( k ) + xk
342 60 CONTINUE
343 END IF
344 ELSE
345 IF( nounit ) THEN
346 DO 80 k = 1, n
347 xk = cabs1( x( k, j ) )
348 DO 70 i = k, min( n, k+kd )
349 rwork( i ) = rwork( i ) +
350 $ cabs1( ab( 1+i-k, k ) )*xk
351 70 CONTINUE
352 80 CONTINUE
353 ELSE
354 DO 100 k = 1, n
355 xk = cabs1( x( k, j ) )
356 DO 90 i = k + 1, min( n, k+kd )
357 rwork( i ) = rwork( i ) +
358 $ cabs1( ab( 1+i-k, k ) )*xk
359 90 CONTINUE
360 rwork( k ) = rwork( k ) + xk
361 100 CONTINUE
362 END IF
363 END IF
364 ELSE
365*
366* Compute abs(A**H)*abs(X) + abs(B).
367*
368 IF( upper ) THEN
369 IF( nounit ) THEN
370 DO 120 k = 1, n
371 s = zero
372 DO 110 i = max( 1, k-kd ), k
373 s = s + cabs1( ab( kd+1+i-k, k ) )*
374 $ cabs1( x( i, j ) )
375 110 CONTINUE
376 rwork( k ) = rwork( k ) + s
377 120 CONTINUE
378 ELSE
379 DO 140 k = 1, n
380 s = cabs1( x( k, j ) )
381 DO 130 i = max( 1, k-kd ), k - 1
382 s = s + cabs1( ab( kd+1+i-k, k ) )*
383 $ cabs1( x( i, j ) )
384 130 CONTINUE
385 rwork( k ) = rwork( k ) + s
386 140 CONTINUE
387 END IF
388 ELSE
389 IF( nounit ) THEN
390 DO 160 k = 1, n
391 s = zero
392 DO 150 i = k, min( n, k+kd )
393 s = s + cabs1( ab( 1+i-k, k ) )*
394 $ cabs1( x( i, j ) )
395 150 CONTINUE
396 rwork( k ) = rwork( k ) + s
397 160 CONTINUE
398 ELSE
399 DO 180 k = 1, n
400 s = cabs1( x( k, j ) )
401 DO 170 i = k + 1, min( n, k+kd )
402 s = s + cabs1( ab( 1+i-k, k ) )*
403 $ cabs1( x( i, j ) )
404 170 CONTINUE
405 rwork( k ) = rwork( k ) + s
406 180 CONTINUE
407 END IF
408 END IF
409 END IF
410 s = zero
411 DO 190 i = 1, n
412 IF( rwork( i ).GT.safe2 ) THEN
413 s = max( s, cabs1( work( i ) ) / rwork( i ) )
414 ELSE
415 s = max( s, ( cabs1( work( i ) )+safe1 ) /
416 $ ( rwork( i )+safe1 ) )
417 END IF
418 190 CONTINUE
419 berr( j ) = s
420*
421* Bound error from formula
422*
423* norm(X - XTRUE) / norm(X) .le. FERR =
424* norm( abs(inv(op(A)))*
425* ( abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) / norm(X)
426*
427* where
428* norm(Z) is the magnitude of the largest component of Z
429* inv(op(A)) is the inverse of op(A)
430* abs(Z) is the componentwise absolute value of the matrix or
431* vector Z
432* NZ is the maximum number of nonzeros in any row of A, plus 1
433* EPS is machine epsilon
434*
435* The i-th component of abs(R)+NZ*EPS*(abs(op(A))*abs(X)+abs(B))
436* is incremented by SAFE1 if the i-th component of
437* abs(op(A))*abs(X) + abs(B) is less than SAFE2.
438*
439* Use CLACN2 to estimate the infinity-norm of the matrix
440* inv(op(A)) * diag(W),
441* where W = abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) )))
442*
443 DO 200 i = 1, n
444 IF( rwork( i ).GT.safe2 ) THEN
445 rwork( i ) = cabs1( work( i ) ) + real( nz )*
446 $ eps*rwork( i )
447 ELSE
448 rwork( i ) = cabs1( work( i ) ) + real( nz )*
449 $ eps*rwork( i ) + safe1
450 END IF
451 200 CONTINUE
452*
453 kase = 0
454 210 CONTINUE
455 CALL clacn2( n, work( n+1 ), work, ferr( j ), kase, isave )
456 IF( kase.NE.0 ) THEN
457 IF( kase.EQ.1 ) THEN
458*
459* Multiply by diag(W)*inv(op(A)**H).
460*
461 CALL ctbsv( uplo, transt, diag, n, kd, ab, ldab, work,
462 $ 1 )
463 DO 220 i = 1, n
464 work( i ) = rwork( i )*work( i )
465 220 CONTINUE
466 ELSE
467*
468* Multiply by inv(op(A))*diag(W).
469*
470 DO 230 i = 1, n
471 work( i ) = rwork( i )*work( i )
472 230 CONTINUE
473 CALL ctbsv( uplo, transn, diag, n, kd, ab, ldab, work,
474 $ 1 )
475 END IF
476 GO TO 210
477 END IF
478*
479* Normalize error.
480*
481 lstres = zero
482 DO 240 i = 1, n
483 lstres = max( lstres, cabs1( x( i, j ) ) )
484 240 CONTINUE
485 IF( lstres.NE.zero )
486 $ ferr( j ) = ferr( j ) / lstres
487*
488 250 CONTINUE
489*
490 RETURN
491*
492* End of CTBRFS
493*
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 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
real function slamch(cmach)
SLAMCH
Definition slamch.f:68
logical function lsame(ca, cb)
LSAME
Definition lsame.f:48
subroutine ctbmv(uplo, trans, diag, n, k, a, lda, x, incx)
CTBMV
Definition ctbmv.f:186
subroutine ctbsv(uplo, trans, diag, n, k, a, lda, x, incx)
CTBSV
Definition ctbsv.f:189
Here is the call graph for this function:
Here is the caller graph for this function: