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

◆ cptrfs()

subroutine cptrfs ( character uplo,
integer n,
integer nrhs,
real, dimension( * ) d,
complex, dimension( * ) e,
real, dimension( * ) df,
complex, dimension( * ) ef,
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 )

CPTRFS

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

Purpose:
!>
!> CPTRFS improves the computed solution to a system of linear
!> equations when the coefficient matrix is Hermitian positive definite
!> and tridiagonal, and provides error bounds and backward error
!> estimates for the solution.
!> 
Parameters
[in]UPLO
!>          UPLO is CHARACTER*1
!>          Specifies whether the superdiagonal or the subdiagonal of the
!>          tridiagonal matrix A is stored and the form of the
!>          factorization:
!>          = 'U':  E is the superdiagonal of A, and A = U**H*D*U;
!>          = 'L':  E is the subdiagonal of A, and A = L*D*L**H.
!>          (The two forms are equivalent if A is real.)
!> 
[in]N
!>          N is INTEGER
!>          The order of the matrix A.  N >= 0.
!> 
[in]NRHS
!>          NRHS is INTEGER
!>          The number of right hand sides, i.e., the number of columns
!>          of the matrix B.  NRHS >= 0.
!> 
[in]D
!>          D is REAL array, dimension (N)
!>          The n real diagonal elements of the tridiagonal matrix A.
!> 
[in]E
!>          E is COMPLEX array, dimension (N-1)
!>          The (n-1) off-diagonal elements of the tridiagonal matrix A
!>          (see UPLO).
!> 
[in]DF
!>          DF is REAL array, dimension (N)
!>          The n diagonal elements of the diagonal matrix D from
!>          the factorization computed by CPTTRF.
!> 
[in]EF
!>          EF is COMPLEX array, dimension (N-1)
!>          The (n-1) off-diagonal elements of the unit bidiagonal
!>          factor U or L from the factorization computed by CPTTRF
!>          (see UPLO).
!> 
[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,out]X
!>          X is COMPLEX array, dimension (LDX,NRHS)
!>          On entry, the solution matrix X, as computed by CPTTRS.
!>          On exit, the improved 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 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).
!> 
[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 (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
!> 
Internal Parameters:
!>  ITMAX is the maximum number of steps of iterative refinement.
!> 
Author
Univ. of Tennessee
Univ. of California Berkeley
Univ. of Colorado Denver
NAG Ltd.

Definition at line 179 of file cptrfs.f.

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 REAL BERR( * ), D( * ), DF( * ), FERR( * ),
192 $ RWORK( * )
193 COMPLEX B( LDB, * ), E( * ), EF( * ), WORK( * ),
194 $ X( LDX, * )
195* ..
196*
197* =====================================================================
198*
199* .. Parameters ..
200 INTEGER ITMAX
201 parameter( itmax = 5 )
202 REAL ZERO
203 parameter( zero = 0.0e+0 )
204 REAL ONE
205 parameter( one = 1.0e+0 )
206 REAL TWO
207 parameter( two = 2.0e+0 )
208 REAL THREE
209 parameter( three = 3.0e+0 )
210* ..
211* .. Local Scalars ..
212 LOGICAL UPPER
213 INTEGER COUNT, I, IX, J, NZ
214 REAL EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN
215 COMPLEX BI, CX, DX, EX, ZDUM
216* ..
217* .. External Functions ..
218 LOGICAL LSAME
219 INTEGER ISAMAX
220 REAL SLAMCH
221 EXTERNAL lsame, isamax, slamch
222* ..
223* .. External Subroutines ..
224 EXTERNAL caxpy, cpttrs, xerbla
225* ..
226* .. Intrinsic Functions ..
227 INTRINSIC abs, aimag, cmplx, conjg, max, real
228* ..
229* .. Statement Functions ..
230 REAL CABS1
231* ..
232* .. Statement Function definitions ..
233 cabs1( zdum ) = abs( real( zdum ) ) + abs( aimag( 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( 'CPTRFS', -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 = slamch( 'Epsilon' )
271 safmin = slamch( 'Safe minimum' )
272 safe1 = real( 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 = conjg( 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 = conjg( 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 = conjg( 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 = conjg( 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 cpttrs( uplo, n, 1, df, ef, work, n, info )
384 CALL caxpy( n, cmplx( 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 ) ) + real( nz )*
411 $ eps*rwork( i )
412 ELSE
413 rwork( i ) = cabs1( work( i ) ) + real( nz )*
414 $ eps*rwork( i ) + safe1
415 END IF
416 60 CONTINUE
417 ix = isamax( n, rwork, 1 )
418 ferr( j ) = rwork( ix )
419*
420* Estimate the norm of inv(A).
421*
422* Solve M(A) * x = e, where M(A) = (m(i,j)) is given by
423*
424* m(i,j) = abs(A(i,j)), i = j,
425* m(i,j) = -abs(A(i,j)), i .ne. j,
426*
427* and e = [ 1, 1, ..., 1 ]**T. Note M(A) = M(L)*D*M(L)**H.
428*
429* Solve M(L) * x = e.
430*
431 rwork( 1 ) = one
432 DO 70 i = 2, n
433 rwork( i ) = one + rwork( i-1 )*abs( ef( i-1 ) )
434 70 CONTINUE
435*
436* Solve D * M(L)**H * x = b.
437*
438 rwork( n ) = rwork( n ) / df( n )
439 DO 80 i = n - 1, 1, -1
440 rwork( i ) = rwork( i ) / df( i ) +
441 $ rwork( i+1 )*abs( ef( i ) )
442 80 CONTINUE
443*
444* Compute norm(inv(A)) = max(x(i)), 1<=i<=n.
445*
446 ix = isamax( n, rwork, 1 )
447 ferr( j ) = ferr( j )*abs( rwork( ix ) )
448*
449* Normalize error.
450*
451 lstres = zero
452 DO 90 i = 1, n
453 lstres = max( lstres, abs( x( i, j ) ) )
454 90 CONTINUE
455 IF( lstres.NE.zero )
456 $ ferr( j ) = ferr( j ) / lstres
457*
458 100 CONTINUE
459*
460 RETURN
461*
462* End of CPTRFS
463*
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine caxpy(n, ca, cx, incx, cy, incy)
CAXPY
Definition caxpy.f:88
integer function isamax(n, sx, incx)
ISAMAX
Definition isamax.f:71
real function slamch(cmach)
SLAMCH
Definition slamch.f:68
logical function lsame(ca, cb)
LSAME
Definition lsame.f:48
subroutine cpttrs(uplo, n, nrhs, d, e, b, ldb, info)
CPTTRS
Definition cpttrs.f:119
Here is the call graph for this function:
Here is the caller graph for this function: