LAPACK  3.8.0
LAPACK: Linear Algebra PACKage

◆ stprfs()

subroutine stprfs ( character  UPLO,
character  TRANS,
character  DIAG,
integer  N,
integer  NRHS,
real, dimension( * )  AP,
real, dimension( ldb, * )  B,
integer  LDB,
real, dimension( ldx, * )  X,
integer  LDX,
real, dimension( * )  FERR,
real, dimension( * )  BERR,
real, dimension( * )  WORK,
integer, dimension( * )  IWORK,
integer  INFO 
)

STPRFS

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

Purpose:
 STPRFS provides error bounds and backward error estimates for the
 solution to a system of linear equations with a triangular packed
 coefficient matrix.

 The solution matrix X must be computed by STPTRS or some other
 means before entering this routine.  STPRFS 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 = 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]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]AP
          AP is REAL array, dimension (N*(N+1)/2)
          The upper or lower triangular matrix A, packed columnwise in
          a linear array.  The j-th column of A is stored in the array
          AP as follows:
          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
          if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n.
          If DIAG = 'U', the diagonal elements of A are not referenced
          and are assumed to be 1.
[in]B
          B is REAL 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 REAL 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 REAL array, dimension (3*N)
[out]IWORK
          IWORK is INTEGER 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.
Date
December 2016

Definition at line 177 of file stprfs.f.

177 *
178 * -- LAPACK computational routine (version 3.7.0) --
179 * -- LAPACK is a software package provided by Univ. of Tennessee, --
180 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
181 * December 2016
182 *
183 * .. Scalar Arguments ..
184  CHARACTER diag, trans, uplo
185  INTEGER info, ldb, ldx, n, nrhs
186 * ..
187 * .. Array Arguments ..
188  INTEGER iwork( * )
189  REAL ap( * ), b( ldb, * ), berr( * ), ferr( * ),
190  $ work( * ), x( ldx, * )
191 * ..
192 *
193 * =====================================================================
194 *
195 * .. Parameters ..
196  REAL zero
197  parameter( zero = 0.0e+0 )
198  REAL one
199  parameter( one = 1.0e+0 )
200 * ..
201 * .. Local Scalars ..
202  LOGICAL notran, nounit, upper
203  CHARACTER transt
204  INTEGER i, j, k, kase, kc, nz
205  REAL eps, lstres, s, safe1, safe2, safmin, xk
206 * ..
207 * .. Local Arrays ..
208  INTEGER isave( 3 )
209 * ..
210 * .. External Subroutines ..
211  EXTERNAL saxpy, scopy, slacn2, stpmv, stpsv, xerbla
212 * ..
213 * .. Intrinsic Functions ..
214  INTRINSIC abs, max
215 * ..
216 * .. External Functions ..
217  LOGICAL lsame
218  REAL slamch
219  EXTERNAL lsame, slamch
220 * ..
221 * .. Executable Statements ..
222 *
223 * Test the input parameters.
224 *
225  info = 0
226  upper = lsame( uplo, 'U' )
227  notran = lsame( trans, 'N' )
228  nounit = lsame( diag, 'N' )
229 *
230  IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
231  info = -1
232  ELSE IF( .NOT.notran .AND. .NOT.lsame( trans, 'T' ) .AND. .NOT.
233  $ lsame( trans, 'C' ) ) THEN
234  info = -2
235  ELSE IF( .NOT.nounit .AND. .NOT.lsame( diag, 'U' ) ) THEN
236  info = -3
237  ELSE IF( n.LT.0 ) THEN
238  info = -4
239  ELSE IF( nrhs.LT.0 ) THEN
240  info = -5
241  ELSE IF( ldb.LT.max( 1, n ) ) THEN
242  info = -8
243  ELSE IF( ldx.LT.max( 1, n ) ) THEN
244  info = -10
245  END IF
246  IF( info.NE.0 ) THEN
247  CALL xerbla( 'STPRFS', -info )
248  RETURN
249  END IF
250 *
251 * Quick return if possible
252 *
253  IF( n.EQ.0 .OR. nrhs.EQ.0 ) THEN
254  DO 10 j = 1, nrhs
255  ferr( j ) = zero
256  berr( j ) = zero
257  10 CONTINUE
258  RETURN
259  END IF
260 *
261  IF( notran ) THEN
262  transt = 'T'
263  ELSE
264  transt = 'N'
265  END IF
266 *
267 * NZ = maximum number of nonzero elements in each row of A, plus 1
268 *
269  nz = n + 1
270  eps = slamch( 'Epsilon' )
271  safmin = slamch( 'Safe minimum' )
272  safe1 = nz*safmin
273  safe2 = safe1 / eps
274 *
275 * Do for each right hand side
276 *
277  DO 250 j = 1, nrhs
278 *
279 * Compute residual R = B - op(A) * X,
280 * where op(A) = A or A**T, depending on TRANS.
281 *
282  CALL scopy( n, x( 1, j ), 1, work( n+1 ), 1 )
283  CALL stpmv( uplo, trans, diag, n, ap, work( n+1 ), 1 )
284  CALL saxpy( n, -one, b( 1, j ), 1, work( n+1 ), 1 )
285 *
286 * Compute componentwise relative backward error from formula
287 *
288 * max(i) ( abs(R(i)) / ( abs(op(A))*abs(X) + abs(B) )(i) )
289 *
290 * where abs(Z) is the componentwise absolute value of the matrix
291 * or vector Z. If the i-th component of the denominator is less
292 * than SAFE2, then SAFE1 is added to the i-th components of the
293 * numerator and denominator before dividing.
294 *
295  DO 20 i = 1, n
296  work( i ) = abs( b( i, j ) )
297  20 CONTINUE
298 *
299  IF( notran ) THEN
300 *
301 * Compute abs(A)*abs(X) + abs(B).
302 *
303  IF( upper ) THEN
304  kc = 1
305  IF( nounit ) THEN
306  DO 40 k = 1, n
307  xk = abs( x( k, j ) )
308  DO 30 i = 1, k
309  work( i ) = work( i ) + abs( ap( kc+i-1 ) )*xk
310  30 CONTINUE
311  kc = kc + k
312  40 CONTINUE
313  ELSE
314  DO 60 k = 1, n
315  xk = abs( x( k, j ) )
316  DO 50 i = 1, k - 1
317  work( i ) = work( i ) + abs( ap( kc+i-1 ) )*xk
318  50 CONTINUE
319  work( k ) = work( k ) + xk
320  kc = kc + k
321  60 CONTINUE
322  END IF
323  ELSE
324  kc = 1
325  IF( nounit ) THEN
326  DO 80 k = 1, n
327  xk = abs( x( k, j ) )
328  DO 70 i = k, n
329  work( i ) = work( i ) + abs( ap( kc+i-k ) )*xk
330  70 CONTINUE
331  kc = kc + n - k + 1
332  80 CONTINUE
333  ELSE
334  DO 100 k = 1, n
335  xk = abs( x( k, j ) )
336  DO 90 i = k + 1, n
337  work( i ) = work( i ) + abs( ap( kc+i-k ) )*xk
338  90 CONTINUE
339  work( k ) = work( k ) + xk
340  kc = kc + n - k + 1
341  100 CONTINUE
342  END IF
343  END IF
344  ELSE
345 *
346 * Compute abs(A**T)*abs(X) + abs(B).
347 *
348  IF( upper ) THEN
349  kc = 1
350  IF( nounit ) THEN
351  DO 120 k = 1, n
352  s = zero
353  DO 110 i = 1, k
354  s = s + abs( ap( kc+i-1 ) )*abs( x( i, j ) )
355  110 CONTINUE
356  work( k ) = work( k ) + s
357  kc = kc + k
358  120 CONTINUE
359  ELSE
360  DO 140 k = 1, n
361  s = abs( x( k, j ) )
362  DO 130 i = 1, k - 1
363  s = s + abs( ap( kc+i-1 ) )*abs( x( i, j ) )
364  130 CONTINUE
365  work( k ) = work( k ) + s
366  kc = kc + k
367  140 CONTINUE
368  END IF
369  ELSE
370  kc = 1
371  IF( nounit ) THEN
372  DO 160 k = 1, n
373  s = zero
374  DO 150 i = k, n
375  s = s + abs( ap( kc+i-k ) )*abs( x( i, j ) )
376  150 CONTINUE
377  work( k ) = work( k ) + s
378  kc = kc + n - k + 1
379  160 CONTINUE
380  ELSE
381  DO 180 k = 1, n
382  s = abs( x( k, j ) )
383  DO 170 i = k + 1, n
384  s = s + abs( ap( kc+i-k ) )*abs( x( i, j ) )
385  170 CONTINUE
386  work( k ) = work( k ) + s
387  kc = kc + n - k + 1
388  180 CONTINUE
389  END IF
390  END IF
391  END IF
392  s = zero
393  DO 190 i = 1, n
394  IF( work( i ).GT.safe2 ) THEN
395  s = max( s, abs( work( n+i ) ) / work( i ) )
396  ELSE
397  s = max( s, ( abs( work( n+i ) )+safe1 ) /
398  $ ( work( i )+safe1 ) )
399  END IF
400  190 CONTINUE
401  berr( j ) = s
402 *
403 * Bound error from formula
404 *
405 * norm(X - XTRUE) / norm(X) .le. FERR =
406 * norm( abs(inv(op(A)))*
407 * ( abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) / norm(X)
408 *
409 * where
410 * norm(Z) is the magnitude of the largest component of Z
411 * inv(op(A)) is the inverse of op(A)
412 * abs(Z) is the componentwise absolute value of the matrix or
413 * vector Z
414 * NZ is the maximum number of nonzeros in any row of A, plus 1
415 * EPS is machine epsilon
416 *
417 * The i-th component of abs(R)+NZ*EPS*(abs(op(A))*abs(X)+abs(B))
418 * is incremented by SAFE1 if the i-th component of
419 * abs(op(A))*abs(X) + abs(B) is less than SAFE2.
420 *
421 * Use SLACN2 to estimate the infinity-norm of the matrix
422 * inv(op(A)) * diag(W),
423 * where W = abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) )))
424 *
425  DO 200 i = 1, n
426  IF( work( i ).GT.safe2 ) THEN
427  work( i ) = abs( work( n+i ) ) + nz*eps*work( i )
428  ELSE
429  work( i ) = abs( work( n+i ) ) + nz*eps*work( i ) + safe1
430  END IF
431  200 CONTINUE
432 *
433  kase = 0
434  210 CONTINUE
435  CALL slacn2( n, work( 2*n+1 ), work( n+1 ), iwork, ferr( j ),
436  $ kase, isave )
437  IF( kase.NE.0 ) THEN
438  IF( kase.EQ.1 ) THEN
439 *
440 * Multiply by diag(W)*inv(op(A)**T).
441 *
442  CALL stpsv( uplo, transt, diag, n, ap, work( n+1 ), 1 )
443  DO 220 i = 1, n
444  work( n+i ) = work( i )*work( n+i )
445  220 CONTINUE
446  ELSE
447 *
448 * Multiply by inv(op(A))*diag(W).
449 *
450  DO 230 i = 1, n
451  work( n+i ) = work( i )*work( n+i )
452  230 CONTINUE
453  CALL stpsv( uplo, trans, diag, n, ap, work( n+1 ), 1 )
454  END IF
455  GO TO 210
456  END IF
457 *
458 * Normalize error.
459 *
460  lstres = zero
461  DO 240 i = 1, n
462  lstres = max( lstres, abs( x( i, j ) ) )
463  240 CONTINUE
464  IF( lstres.NE.zero )
465  $ ferr( j ) = ferr( j ) / lstres
466 *
467  250 CONTINUE
468 *
469  RETURN
470 *
471 * End of STPRFS
472 *
subroutine stpmv(UPLO, TRANS, DIAG, N, AP, X, INCX)
STPMV
Definition: stpmv.f:144
subroutine xerbla(SRNAME, INFO)
XERBLA
Definition: xerbla.f:62
logical function lsame(CA, CB)
LSAME
Definition: lsame.f:55
subroutine saxpy(N, SA, SX, INCX, SY, INCY)
SAXPY
Definition: saxpy.f:91
real function slamch(CMACH)
SLAMCH
Definition: slamch.f:69
subroutine stpsv(UPLO, TRANS, DIAG, N, AP, X, INCX)
STPSV
Definition: stpsv.f:146
subroutine slacn2(N, V, X, ISGN, EST, KASE, ISAVE)
SLACN2 estimates the 1-norm of a square matrix, using reverse communication for evaluating matrix-vec...
Definition: slacn2.f:138
subroutine scopy(N, SX, INCX, SY, INCY)
SCOPY
Definition: scopy.f:84
Here is the call graph for this function:
Here is the caller graph for this function: