3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download ZTRSNA + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ztrsna.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ztrsna.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ztrsna.f">
21 * SUBROUTINE ZTRSNA( JOB, HOWMNY, SELECT, N, T, LDT, VL, LDVL, VR,
22 * LDVR, S, SEP, MM, M, WORK, LDWORK, RWORK,
25 * .. Scalar Arguments ..
26 * CHARACTER HOWMNY, JOB
27 * INTEGER INFO, LDT, LDVL, LDVR, LDWORK, M, MM, N
29 * .. Array Arguments ..
31 * DOUBLE PRECISION RWORK( * ), S( * ), SEP( * )
32 * COMPLEX*16 T( LDT, * ), VL( LDVL, * ), VR( LDVR, * ),
42 *> ZTRSNA estimates reciprocal condition numbers for specified
43 *> eigenvalues and/or right eigenvectors of a complex upper triangular
44 *> matrix T (or of any matrix Q*T*Q**H with Q unitary).
53 *> Specifies whether condition numbers are required for
54 *> eigenvalues (S) or eigenvectors (SEP):
55 *> = 'E': for eigenvalues only (S);
56 *> = 'V': for eigenvectors only (SEP);
57 *> = 'B': for both eigenvalues and eigenvectors (S and SEP).
62 *> HOWMNY is CHARACTER*1
63 *> = 'A': compute condition numbers for all eigenpairs;
64 *> = 'S': compute condition numbers for selected eigenpairs
65 *> specified by the array SELECT.
70 *> SELECT is LOGICAL array, dimension (N)
71 *> If HOWMNY = 'S', SELECT specifies the eigenpairs for which
72 *> condition numbers are required. To select condition numbers
73 *> for the j-th eigenpair, SELECT(j) must be set to .TRUE..
74 *> If HOWMNY = 'A', SELECT is not referenced.
80 *> The order of the matrix T. N >= 0.
85 *> T is COMPLEX*16 array, dimension (LDT,N)
86 *> The upper triangular matrix T.
92 *> The leading dimension of the array T. LDT >= max(1,N).
97 *> VL is COMPLEX*16 array, dimension (LDVL,M)
98 *> If JOB = 'E' or 'B', VL must contain left eigenvectors of T
99 *> (or of any Q*T*Q**H with Q unitary), corresponding to the
100 *> eigenpairs specified by HOWMNY and SELECT. The eigenvectors
101 *> must be stored in consecutive columns of VL, as returned by
103 *> If JOB = 'V', VL is not referenced.
109 *> The leading dimension of the array VL.
110 *> LDVL >= 1; and if JOB = 'E' or 'B', LDVL >= N.
115 *> VR is COMPLEX*16 array, dimension (LDVR,M)
116 *> If JOB = 'E' or 'B', VR must contain right eigenvectors of T
117 *> (or of any Q*T*Q**H with Q unitary), corresponding to the
118 *> eigenpairs specified by HOWMNY and SELECT. The eigenvectors
119 *> must be stored in consecutive columns of VR, as returned by
121 *> If JOB = 'V', VR is not referenced.
127 *> The leading dimension of the array VR.
128 *> LDVR >= 1; and if JOB = 'E' or 'B', LDVR >= N.
133 *> S is DOUBLE PRECISION array, dimension (MM)
134 *> If JOB = 'E' or 'B', the reciprocal condition numbers of the
135 *> selected eigenvalues, stored in consecutive elements of the
136 *> array. Thus S(j), SEP(j), and the j-th columns of VL and VR
137 *> all correspond to the same eigenpair (but not in general the
138 *> j-th eigenpair, unless all eigenpairs are selected).
139 *> If JOB = 'V', S is not referenced.
144 *> SEP is DOUBLE PRECISION array, dimension (MM)
145 *> If JOB = 'V' or 'B', the estimated reciprocal condition
146 *> numbers of the selected eigenvectors, stored in consecutive
147 *> elements of the array.
148 *> If JOB = 'E', SEP is not referenced.
154 *> The number of elements in the arrays S (if JOB = 'E' or 'B')
155 *> and/or SEP (if JOB = 'V' or 'B'). MM >= M.
161 *> The number of elements of the arrays S and/or SEP actually
162 *> used to store the estimated condition numbers.
163 *> If HOWMNY = 'A', M is set to N.
168 *> WORK is COMPLEX*16 array, dimension (LDWORK,N+6)
169 *> If JOB = 'E', WORK is not referenced.
175 *> The leading dimension of the array WORK.
176 *> LDWORK >= 1; and if JOB = 'V' or 'B', LDWORK >= N.
181 *> RWORK is DOUBLE PRECISION array, dimension (N)
182 *> If JOB = 'E', RWORK is not referenced.
188 *> = 0: successful exit
189 *> < 0: if INFO = -i, the i-th argument had an illegal value
195 *> \author Univ. of Tennessee
196 *> \author Univ. of California Berkeley
197 *> \author Univ. of Colorado Denver
200 *> \date November 2011
202 *> \ingroup complex16OTHERcomputational
204 *> \par Further Details:
205 * =====================
209 *> The reciprocal of the condition number of an eigenvalue lambda is
212 *> S(lambda) = |v**H*u| / (norm(u)*norm(v))
214 *> where u and v are the right and left eigenvectors of T corresponding
215 *> to lambda; v**H denotes the conjugate transpose of v, and norm(u)
216 *> denotes the Euclidean norm. These reciprocal condition numbers always
217 *> lie between zero (very badly conditioned) and one (very well
218 *> conditioned). If n = 1, S(lambda) is defined to be 1.
220 *> An approximate error bound for a computed eigenvalue W(i) is given by
222 *> EPS * norm(T) / S(i)
224 *> where EPS is the machine precision.
226 *> The reciprocal of the condition number of the right eigenvector u
227 *> corresponding to lambda is defined as follows. Suppose
232 *> Then the reciprocal condition number is
234 *> SEP( lambda, T22 ) = sigma-min( T22 - lambda*I )
236 *> where sigma-min denotes the smallest singular value. We approximate
237 *> the smallest singular value by the reciprocal of an estimate of the
238 *> one-norm of the inverse of T22 - lambda*I. If n = 1, SEP(1) is
239 *> defined to be abs(T(1,1)).
241 *> An approximate error bound for a computed right eigenvector VR(i)
244 *> EPS * norm(T) / SEP(i)
247 * =====================================================================
248 SUBROUTINE ZTRSNA( JOB, HOWMNY, SELECT, N, T, LDT, VL, LDVL, VR,
249 $ LDVR, S, SEP, MM, M, WORK, LDWORK, RWORK,
252 * -- LAPACK computational routine (version 3.4.0) --
253 * -- LAPACK is a software package provided by Univ. of Tennessee, --
254 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
257 * .. Scalar Arguments ..
258 CHARACTER HOWMNY, JOB
259 INTEGER INFO, LDT, LDVL, LDVR, LDWORK, M, MM, N
261 * .. Array Arguments ..
263 DOUBLE PRECISION RWORK( * ), S( * ), SEP( * )
264 COMPLEX*16 T( LDT, * ), VL( LDVL, * ), VR( LDVR, * ),
268 * =====================================================================
271 DOUBLE PRECISION ZERO, ONE
272 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D0+0 )
274 * .. Local Scalars ..
275 LOGICAL SOMCON, WANTBH, WANTS, WANTSP
277 INTEGER I, IERR, IX, J, K, KASE, KS
278 DOUBLE PRECISION BIGNUM, EPS, EST, LNRM, RNRM, SCALE, SMLNUM,
280 COMPLEX*16 CDUM, PROD
284 COMPLEX*16 DUMMY( 1 )
286 * .. External Functions ..
289 DOUBLE PRECISION DLAMCH, DZNRM2
291 EXTERNAL LSAME, IZAMAX, DLAMCH, DZNRM2, ZDOTC
293 * .. External Subroutines ..
294 EXTERNAL XERBLA, ZDRSCL, ZLACN2, ZLACPY, ZLATRS, ZTREXC
296 * .. Intrinsic Functions ..
297 INTRINSIC ABS, DBLE, DIMAG, MAX
299 * .. Statement Functions ..
300 DOUBLE PRECISION CABS1
302 * .. Statement Function definitions ..
303 CABS1( CDUM ) = ABS( DBLE( CDUM ) ) + ABS( DIMAG( CDUM ) )
305 * .. Executable Statements ..
307 * Decode and test the input parameters
309 WANTBH = LSAME( JOB, 'B' )
310 WANTS = LSAME( JOB, 'E' ) .OR. WANTBH
311 WANTSP = LSAME( JOB, 'V' ) .OR. WANTBH
313 SOMCON = LSAME( HOWMNY, 'S' )
315 * Set M to the number of eigenpairs for which condition numbers are
329 IF( .NOT.WANTS .AND. .NOT.WANTSP ) THEN
331 ELSE IF( .NOT.LSAME( HOWMNY, 'A' ) .AND. .NOT.SOMCON ) THEN
333 ELSE IF( N.LT.0 ) THEN
335 ELSE IF( LDT.LT.MAX( 1, N ) ) THEN
337 ELSE IF( LDVL.LT.1 .OR. ( WANTS .AND. LDVL.LT.N ) ) THEN
339 ELSE IF( LDVR.LT.1 .OR. ( WANTS .AND. LDVR.LT.N ) ) THEN
341 ELSE IF( MM.LT.M ) THEN
343 ELSE IF( LDWORK.LT.1 .OR. ( WANTSP .AND. LDWORK.LT.N ) ) THEN
347 CALL XERBLA( 'ZTRSNA', -INFO )
351 * Quick return if possible
358 IF( .NOT.SELECT( 1 ) )
364 $ SEP( 1 ) = ABS( T( 1, 1 ) )
368 * Get machine constants
371 SMLNUM = DLAMCH( 'S' ) / EPS
372 BIGNUM = ONE / SMLNUM
373 CALL DLABAD( SMLNUM, BIGNUM )
379 IF( .NOT.SELECT( K ) )
385 * Compute the reciprocal condition number of the k-th
388 PROD = ZDOTC( N, VR( 1, KS ), 1, VL( 1, KS ), 1 )
389 RNRM = DZNRM2( N, VR( 1, KS ), 1 )
390 LNRM = DZNRM2( N, VL( 1, KS ), 1 )
391 S( KS ) = ABS( PROD ) / ( RNRM*LNRM )
397 * Estimate the reciprocal condition number of the k-th
400 * Copy the matrix T to the array WORK and swap the k-th
401 * diagonal element to the (1,1) position.
403 CALL ZLACPY( 'Full', N, N, T, LDT, WORK, LDWORK )
404 CALL ZTREXC( 'No Q', N, WORK, LDWORK, DUMMY, 1, K, 1, IERR )
406 * Form C = T22 - lambda*I in WORK(2:N,2:N).
409 WORK( I, I ) = WORK( I, I ) - WORK( 1, 1 )
412 * Estimate a lower bound for the 1-norm of inv(C**H). The 1st
413 * and (N+1)th columns of WORK are used to store work vectors.
420 CALL ZLACN2( N-1, WORK( 1, N+1 ), WORK, EST, KASE, ISAVE )
425 * Solve C**H*x = scale*b
427 CALL ZLATRS( 'Upper', 'Conjugate transpose',
428 $ 'Nonunit', NORMIN, N-1, WORK( 2, 2 ),
429 $ LDWORK, WORK, SCALE, RWORK, IERR )
432 * Solve C*x = scale*b
434 CALL ZLATRS( 'Upper', 'No transpose', 'Nonunit',
435 $ NORMIN, N-1, WORK( 2, 2 ), LDWORK, WORK,
436 $ SCALE, RWORK, IERR )
439 IF( SCALE.NE.ONE ) THEN
441 * Multiply by 1/SCALE if doing so will not cause
444 IX = IZAMAX( N-1, WORK, 1 )
445 XNORM = CABS1( WORK( IX, 1 ) )
446 IF( SCALE.LT.XNORM*SMLNUM .OR. SCALE.EQ.ZERO )
448 CALL ZDRSCL( N, SCALE, WORK, 1 )
453 SEP( KS ) = ONE / MAX( EST, SMLNUM )