You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

strt03.f 8.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. *> \brief \b STRT03
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. * Definition:
  9. * ===========
  10. *
  11. * SUBROUTINE STRT03( UPLO, TRANS, DIAG, N, NRHS, A, LDA, SCALE,
  12. * CNORM, TSCAL, X, LDX, B, LDB, WORK, RESID )
  13. *
  14. * .. Scalar Arguments ..
  15. * CHARACTER DIAG, TRANS, UPLO
  16. * INTEGER LDA, LDB, LDX, N, NRHS
  17. * REAL RESID, SCALE, TSCAL
  18. * ..
  19. * .. Array Arguments ..
  20. * REAL A( LDA, * ), B( LDB, * ), CNORM( * ),
  21. * $ WORK( * ), X( LDX, * )
  22. * ..
  23. *
  24. *
  25. *> \par Purpose:
  26. * =============
  27. *>
  28. *> \verbatim
  29. *>
  30. *> STRT03 computes the residual for the solution to a scaled triangular
  31. *> system of equations A*x = s*b or A'*x = s*b.
  32. *> Here A is a triangular matrix, A' is the transpose of A, s is a
  33. *> scalar, and x and b are N by NRHS matrices. The test ratio is the
  34. *> maximum over the number of right hand sides of
  35. *> norm(s*b - op(A)*x) / ( norm(op(A)) * norm(x) * EPS ),
  36. *> where op(A) denotes A or A' and EPS is the machine epsilon.
  37. *> \endverbatim
  38. *
  39. * Arguments:
  40. * ==========
  41. *
  42. *> \param[in] UPLO
  43. *> \verbatim
  44. *> UPLO is CHARACTER*1
  45. *> Specifies whether the matrix A is upper or lower triangular.
  46. *> = 'U': Upper triangular
  47. *> = 'L': Lower triangular
  48. *> \endverbatim
  49. *>
  50. *> \param[in] TRANS
  51. *> \verbatim
  52. *> TRANS is CHARACTER*1
  53. *> Specifies the operation applied to A.
  54. *> = 'N': A *x = s*b (No transpose)
  55. *> = 'T': A'*x = s*b (Transpose)
  56. *> = 'C': A'*x = s*b (Conjugate transpose = Transpose)
  57. *> \endverbatim
  58. *>
  59. *> \param[in] DIAG
  60. *> \verbatim
  61. *> DIAG is CHARACTER*1
  62. *> Specifies whether or not the matrix A is unit triangular.
  63. *> = 'N': Non-unit triangular
  64. *> = 'U': Unit triangular
  65. *> \endverbatim
  66. *>
  67. *> \param[in] N
  68. *> \verbatim
  69. *> N is INTEGER
  70. *> The order of the matrix A. N >= 0.
  71. *> \endverbatim
  72. *>
  73. *> \param[in] NRHS
  74. *> \verbatim
  75. *> NRHS is INTEGER
  76. *> The number of right hand sides, i.e., the number of columns
  77. *> of the matrices X and B. NRHS >= 0.
  78. *> \endverbatim
  79. *>
  80. *> \param[in] A
  81. *> \verbatim
  82. *> A is REAL array, dimension (LDA,N)
  83. *> The triangular matrix A. If UPLO = 'U', the leading n by n
  84. *> upper triangular part of the array A contains the upper
  85. *> triangular matrix, and the strictly lower triangular part of
  86. *> A is not referenced. If UPLO = 'L', the leading n by n lower
  87. *> triangular part of the array A contains the lower triangular
  88. *> matrix, and the strictly upper triangular part of A is not
  89. *> referenced. If DIAG = 'U', the diagonal elements of A are
  90. *> also not referenced and are assumed to be 1.
  91. *> \endverbatim
  92. *>
  93. *> \param[in] LDA
  94. *> \verbatim
  95. *> LDA is INTEGER
  96. *> The leading dimension of the array A. LDA >= max(1,N).
  97. *> \endverbatim
  98. *>
  99. *> \param[in] SCALE
  100. *> \verbatim
  101. *> SCALE is REAL
  102. *> The scaling factor s used in solving the triangular system.
  103. *> \endverbatim
  104. *>
  105. *> \param[in] CNORM
  106. *> \verbatim
  107. *> CNORM is REAL array, dimension (N)
  108. *> The 1-norms of the columns of A, not counting the diagonal.
  109. *> \endverbatim
  110. *>
  111. *> \param[in] TSCAL
  112. *> \verbatim
  113. *> TSCAL is REAL
  114. *> The scaling factor used in computing the 1-norms in CNORM.
  115. *> CNORM actually contains the column norms of TSCAL*A.
  116. *> \endverbatim
  117. *>
  118. *> \param[in] X
  119. *> \verbatim
  120. *> X is REAL array, dimension (LDX,NRHS)
  121. *> The computed solution vectors for the system of linear
  122. *> equations.
  123. *> \endverbatim
  124. *>
  125. *> \param[in] LDX
  126. *> \verbatim
  127. *> LDX is INTEGER
  128. *> The leading dimension of the array X. LDX >= max(1,N).
  129. *> \endverbatim
  130. *>
  131. *> \param[in] B
  132. *> \verbatim
  133. *> B is REAL array, dimension (LDB,NRHS)
  134. *> The right hand side vectors for the system of linear
  135. *> equations.
  136. *> \endverbatim
  137. *>
  138. *> \param[in] LDB
  139. *> \verbatim
  140. *> LDB is INTEGER
  141. *> The leading dimension of the array B. LDB >= max(1,N).
  142. *> \endverbatim
  143. *>
  144. *> \param[out] WORK
  145. *> \verbatim
  146. *> WORK is REAL array, dimension (N)
  147. *> \endverbatim
  148. *>
  149. *> \param[out] RESID
  150. *> \verbatim
  151. *> RESID is REAL
  152. *> The maximum over the number of right hand sides of
  153. *> norm(op(A)*x - s*b) / ( norm(op(A)) * norm(x) * EPS ).
  154. *> \endverbatim
  155. *
  156. * Authors:
  157. * ========
  158. *
  159. *> \author Univ. of Tennessee
  160. *> \author Univ. of California Berkeley
  161. *> \author Univ. of Colorado Denver
  162. *> \author NAG Ltd.
  163. *
  164. *> \date December 2016
  165. *
  166. *> \ingroup single_lin
  167. *
  168. * =====================================================================
  169. SUBROUTINE STRT03( UPLO, TRANS, DIAG, N, NRHS, A, LDA, SCALE,
  170. $ CNORM, TSCAL, X, LDX, B, LDB, WORK, RESID )
  171. *
  172. * -- LAPACK test routine (version 3.7.0) --
  173. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  174. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  175. * December 2016
  176. *
  177. * .. Scalar Arguments ..
  178. CHARACTER DIAG, TRANS, UPLO
  179. INTEGER LDA, LDB, LDX, N, NRHS
  180. REAL RESID, SCALE, TSCAL
  181. * ..
  182. * .. Array Arguments ..
  183. REAL A( LDA, * ), B( LDB, * ), CNORM( * ),
  184. $ WORK( * ), X( LDX, * )
  185. * ..
  186. *
  187. * =====================================================================
  188. *
  189. * .. Parameters ..
  190. REAL ONE, ZERO
  191. PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 )
  192. * ..
  193. * .. Local Scalars ..
  194. INTEGER IX, J
  195. REAL BIGNUM, EPS, ERR, SMLNUM, TNORM, XNORM, XSCAL
  196. * ..
  197. * .. External Functions ..
  198. LOGICAL LSAME
  199. INTEGER ISAMAX
  200. REAL SLAMCH
  201. EXTERNAL LSAME, ISAMAX, SLAMCH
  202. * ..
  203. * .. External Subroutines ..
  204. EXTERNAL SAXPY, SCOPY, SLABAD, SSCAL, STRMV
  205. * ..
  206. * .. Intrinsic Functions ..
  207. INTRINSIC ABS, MAX, REAL
  208. * ..
  209. * .. Executable Statements ..
  210. *
  211. * Quick exit if N = 0
  212. *
  213. IF( N.LE.0 .OR. NRHS.LE.0 ) THEN
  214. RESID = ZERO
  215. RETURN
  216. END IF
  217. EPS = SLAMCH( 'Epsilon' )
  218. SMLNUM = SLAMCH( 'Safe minimum' )
  219. BIGNUM = ONE / SMLNUM
  220. CALL SLABAD( SMLNUM, BIGNUM )
  221. *
  222. * Compute the norm of the triangular matrix A using the column
  223. * norms already computed by SLATRS.
  224. *
  225. TNORM = ZERO
  226. IF( LSAME( DIAG, 'N' ) ) THEN
  227. DO 10 J = 1, N
  228. TNORM = MAX( TNORM, TSCAL*ABS( A( J, J ) )+CNORM( J ) )
  229. 10 CONTINUE
  230. ELSE
  231. DO 20 J = 1, N
  232. TNORM = MAX( TNORM, TSCAL+CNORM( J ) )
  233. 20 CONTINUE
  234. END IF
  235. *
  236. * Compute the maximum over the number of right hand sides of
  237. * norm(op(A)*x - s*b) / ( norm(op(A)) * norm(x) * EPS ).
  238. *
  239. RESID = ZERO
  240. DO 30 J = 1, NRHS
  241. CALL SCOPY( N, X( 1, J ), 1, WORK, 1 )
  242. IX = ISAMAX( N, WORK, 1 )
  243. XNORM = MAX( ONE, ABS( X( IX, J ) ) )
  244. XSCAL = ( ONE / XNORM ) / REAL( N )
  245. CALL SSCAL( N, XSCAL, WORK, 1 )
  246. CALL STRMV( UPLO, TRANS, DIAG, N, A, LDA, WORK, 1 )
  247. CALL SAXPY( N, -SCALE*XSCAL, B( 1, J ), 1, WORK, 1 )
  248. IX = ISAMAX( N, WORK, 1 )
  249. ERR = TSCAL*ABS( WORK( IX ) )
  250. IX = ISAMAX( N, X( 1, J ), 1 )
  251. XNORM = ABS( X( IX, J ) )
  252. IF( ERR*SMLNUM.LE.XNORM ) THEN
  253. IF( XNORM.GT.ZERO )
  254. $ ERR = ERR / XNORM
  255. ELSE
  256. IF( ERR.GT.ZERO )
  257. $ ERR = ONE / EPS
  258. END IF
  259. IF( ERR*SMLNUM.LE.TNORM ) THEN
  260. IF( TNORM.GT.ZERO )
  261. $ ERR = ERR / TNORM
  262. ELSE
  263. IF( ERR.GT.ZERO )
  264. $ ERR = ONE / EPS
  265. END IF
  266. RESID = MAX( RESID, ERR )
  267. 30 CONTINUE
  268. *
  269. RETURN
  270. *
  271. * End of STRT03
  272. *
  273. END