LAPACK  3.6.1
LAPACK: Linear Algebra PACKage
zsyequb.f
Go to the documentation of this file.
1 *> \brief \b ZSYEQUB
2 *
3 * =========== DOCUMENTATION ===========
4 *
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
7 *
8 *> \htmlonly
9 *> Download ZSYEQUB + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zsyequb.f">
11 *> [TGZ]</a>
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zsyequb.f">
13 *> [ZIP]</a>
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zsyequb.f">
15 *> [TXT]</a>
16 *> \endhtmlonly
17 *
18 * Definition:
19 * ===========
20 *
21 * SUBROUTINE ZSYEQUB( UPLO, N, A, LDA, S, SCOND, AMAX, WORK, INFO )
22 *
23 * .. Scalar Arguments ..
24 * INTEGER INFO, LDA, N
25 * DOUBLE PRECISION AMAX, SCOND
26 * CHARACTER UPLO
27 * ..
28 * .. Array Arguments ..
29 * COMPLEX*16 A( LDA, * ), WORK( * )
30 * DOUBLE PRECISION S( * )
31 * ..
32 *
33 *
34 *> \par Purpose:
35 * =============
36 *>
37 *> \verbatim
38 *>
39 *> ZSYEQUB computes row and column scalings intended to equilibrate a
40 *> symmetric matrix A and reduce its condition number
41 *> (with respect to the two-norm). S contains the scale factors,
42 *> S(i) = 1/sqrt(A(i,i)), chosen so that the scaled matrix B with
43 *> elements B(i,j) = S(i)*A(i,j)*S(j) has ones on the diagonal. This
44 *> choice of S puts the condition number of B within a factor N of the
45 *> smallest possible condition number over all possible diagonal
46 *> scalings.
47 *> \endverbatim
48 *
49 * Arguments:
50 * ==========
51 *
52 *> \param[in] UPLO
53 *> \verbatim
54 *> UPLO is CHARACTER*1
55 *> Specifies whether the details of the factorization are stored
56 *> as an upper or lower triangular matrix.
57 *> = 'U': Upper triangular, form is A = U*D*U**T;
58 *> = 'L': Lower triangular, form is A = L*D*L**T.
59 *> \endverbatim
60 *>
61 *> \param[in] N
62 *> \verbatim
63 *> N is INTEGER
64 *> The order of the matrix A. N >= 0.
65 *> \endverbatim
66 *>
67 *> \param[in] A
68 *> \verbatim
69 *> A is COMPLEX*16 array, dimension (LDA,N)
70 *> The N-by-N symmetric matrix whose scaling
71 *> factors are to be computed. Only the diagonal elements of A
72 *> are referenced.
73 *> \endverbatim
74 *>
75 *> \param[in] LDA
76 *> \verbatim
77 *> LDA is INTEGER
78 *> The leading dimension of the array A. LDA >= max(1,N).
79 *> \endverbatim
80 *>
81 *> \param[out] S
82 *> \verbatim
83 *> S is DOUBLE PRECISION array, dimension (N)
84 *> If INFO = 0, S contains the scale factors for A.
85 *> \endverbatim
86 *>
87 *> \param[out] SCOND
88 *> \verbatim
89 *> SCOND is DOUBLE PRECISION
90 *> If INFO = 0, S contains the ratio of the smallest S(i) to
91 *> the largest S(i). If SCOND >= 0.1 and AMAX is neither too
92 *> large nor too small, it is not worth scaling by S.
93 *> \endverbatim
94 *>
95 *> \param[out] AMAX
96 *> \verbatim
97 *> AMAX is DOUBLE PRECISION
98 *> Absolute value of largest matrix element. If AMAX is very
99 *> close to overflow or very close to underflow, the matrix
100 *> should be scaled.
101 *> \endverbatim
102 *>
103 *> \param[out] WORK
104 *> \verbatim
105 *> WORK is COMPLEX*16 array, dimension (3*N)
106 *> \endverbatim
107 *>
108 *> \param[out] INFO
109 *> \verbatim
110 *> INFO is INTEGER
111 *> = 0: successful exit
112 *> < 0: if INFO = -i, the i-th argument had an illegal value
113 *> > 0: if INFO = i, the i-th diagonal element is nonpositive.
114 *> \endverbatim
115 *
116 * Authors:
117 * ========
118 *
119 *> \author Univ. of Tennessee
120 *> \author Univ. of California Berkeley
121 *> \author Univ. of Colorado Denver
122 *> \author NAG Ltd.
123 *
124 *> \date November 2011
125 *
126 *> \ingroup complex16SYcomputational
127 *
128 *> \par References:
129 * ================
130 *>
131 *> Livne, O.E. and Golub, G.H., "Scaling by Binormalization", \n
132 *> Numerical Algorithms, vol. 35, no. 1, pp. 97-120, January 2004. \n
133 *> DOI 10.1023/B:NUMA.0000016606.32820.69 \n
134 *> Tech report version: http://ruready.utah.edu/archive/papers/bin.pdf
135 *>
136 * =====================================================================
137  SUBROUTINE zsyequb( UPLO, N, A, LDA, S, SCOND, AMAX, WORK, INFO )
138 *
139 * -- LAPACK computational routine (version 3.4.0) --
140 * -- LAPACK is a software package provided by Univ. of Tennessee, --
141 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
142 * November 2011
143 *
144 * .. Scalar Arguments ..
145  INTEGER INFO, LDA, N
146  DOUBLE PRECISION AMAX, SCOND
147  CHARACTER UPLO
148 * ..
149 * .. Array Arguments ..
150  COMPLEX*16 A( lda, * ), WORK( * )
151  DOUBLE PRECISION S( * )
152 * ..
153 *
154 * =====================================================================
155 *
156 * .. Parameters ..
157  DOUBLE PRECISION ONE, ZERO
158  parameter ( one = 1.0d0, zero = 0.0d0 )
159  INTEGER MAX_ITER
160  parameter ( max_iter = 100 )
161 * ..
162 * .. Local Scalars ..
163  INTEGER I, J, ITER
164  DOUBLE PRECISION AVG, STD, TOL, C0, C1, C2, T, U, SI, D, BASE,
165  $ smin, smax, smlnum, bignum, scale, sumsq
166  LOGICAL UP
167  COMPLEX*16 ZDUM
168 * ..
169 * .. External Functions ..
170  DOUBLE PRECISION DLAMCH
171  LOGICAL LSAME
172  EXTERNAL dlamch, lsame
173 * ..
174 * .. External Subroutines ..
175  EXTERNAL zlassq
176 * ..
177 * .. Intrinsic Functions ..
178  INTRINSIC abs, dble, dimag, int, log, max, min, sqrt
179 * ..
180 * .. Statement Functions ..
181  DOUBLE PRECISION CABS1
182 * ..
183 * Statement Function Definitions
184  cabs1( zdum ) = abs( dble( zdum ) ) + abs( dimag( zdum ) )
185 * ..
186 * .. Executable Statements ..
187 *
188 * Test the input parameters.
189 *
190  info = 0
191  IF ( .NOT. ( lsame( uplo, 'U' ) .OR. lsame( uplo, 'L' ) ) ) THEN
192  info = -1
193  ELSE IF ( n .LT. 0 ) THEN
194  info = -2
195  ELSE IF ( lda .LT. max( 1, n ) ) THEN
196  info = -4
197  END IF
198  IF ( info .NE. 0 ) THEN
199  CALL xerbla( 'ZSYEQUB', -info )
200  RETURN
201  END IF
202 
203  up = lsame( uplo, 'U' )
204  amax = zero
205 *
206 * Quick return if possible.
207 *
208  IF ( n .EQ. 0 ) THEN
209  scond = one
210  RETURN
211  END IF
212 
213  DO i = 1, n
214  s( i ) = zero
215  END DO
216 
217  amax = zero
218  IF ( up ) THEN
219  DO j = 1, n
220  DO i = 1, j-1
221  s( i ) = max( s( i ), cabs1( a( i, j ) ) )
222  s( j ) = max( s( j ), cabs1( a( i, j ) ) )
223  amax = max( amax, cabs1( a( i, j ) ) )
224  END DO
225  s( j ) = max( s( j ), cabs1( a( j, j) ) )
226  amax = max( amax, cabs1( a( j, j ) ) )
227  END DO
228  ELSE
229  DO j = 1, n
230  s( j ) = max( s( j ), cabs1( a( j, j ) ) )
231  amax = max( amax, cabs1( a( j, j ) ) )
232  DO i = j+1, n
233  s( i ) = max( s( i ), cabs1( a( i, j ) ) )
234  s( j ) = max( s( j ), cabs1(a( i, j ) ) )
235  amax = max( amax, cabs1( a( i, j ) ) )
236  END DO
237  END DO
238  END IF
239  DO j = 1, n
240  s( j ) = 1.0d+0 / s( j )
241  END DO
242 
243  tol = one / sqrt( 2.0d0 * n )
244 
245  DO iter = 1, max_iter
246  scale = 0.0d+0
247  sumsq = 0.0d+0
248 * beta = |A|s
249  DO i = 1, n
250  work( i ) = zero
251  END DO
252  IF ( up ) THEN
253  DO j = 1, n
254  DO i = 1, j-1
255  t = cabs1( a( i, j ) )
256  work( i ) = work( i ) + cabs1( a( i, j ) ) * s( j )
257  work( j ) = work( j ) + cabs1( a( i, j ) ) * s( i )
258  END DO
259  work( j ) = work( j ) + cabs1( a( j, j ) ) * s( j )
260  END DO
261  ELSE
262  DO j = 1, n
263  work( j ) = work( j ) + cabs1( a( j, j ) ) * s( j )
264  DO i = j+1, n
265  t = cabs1( a( i, j ) )
266  work( i ) = work( i ) + cabs1( a( i, j ) ) * s( j )
267  work( j ) = work( j ) + cabs1( a( i, j ) ) * s( i )
268  END DO
269  END DO
270  END IF
271 
272 * avg = s^T beta / n
273  avg = 0.0d+0
274  DO i = 1, n
275  avg = avg + s( i )*work( i )
276  END DO
277  avg = avg / n
278 
279  std = 0.0d+0
280  DO i = n+1, 2*n
281  work( i ) = s( i-n ) * work( i-n ) - avg
282  END DO
283  CALL zlassq( n, work( n+1 ), 1, scale, sumsq )
284  std = scale * sqrt( sumsq / n )
285 
286  IF ( std .LT. tol * avg ) GOTO 999
287 
288  DO i = 1, n
289  t = cabs1( a( i, i ) )
290  si = s( i )
291  c2 = ( n-1 ) * t
292  c1 = ( n-2 ) * ( work( i ) - t*si )
293  c0 = -(t*si)*si + 2*work( i )*si - n*avg
294  d = c1*c1 - 4*c0*c2
295 
296  IF ( d .LE. 0 ) THEN
297  info = -1
298  RETURN
299  END IF
300  si = -2*c0 / ( c1 + sqrt( d ) )
301 
302  d = si - s( i )
303  u = zero
304  IF ( up ) THEN
305  DO j = 1, i
306  t = cabs1( a( j, i ) )
307  u = u + s( j )*t
308  work( j ) = work( j ) + d*t
309  END DO
310  DO j = i+1,n
311  t = cabs1( a( i, j ) )
312  u = u + s( j )*t
313  work( j ) = work( j ) + d*t
314  END DO
315  ELSE
316  DO j = 1, i
317  t = cabs1( a( i, j ) )
318  u = u + s( j )*t
319  work( j ) = work( j ) + d*t
320  END DO
321  DO j = i+1,n
322  t = cabs1( a( j, i ) )
323  u = u + s( j )*t
324  work( j ) = work( j ) + d*t
325  END DO
326  END IF
327  avg = avg + ( u + work( i ) ) * d / n
328  s( i ) = si
329  END DO
330  END DO
331 
332  999 CONTINUE
333 
334  smlnum = dlamch( 'SAFEMIN' )
335  bignum = one / smlnum
336  smin = bignum
337  smax = zero
338  t = one / sqrt( avg )
339  base = dlamch( 'B' )
340  u = one / log( base )
341  DO i = 1, n
342  s( i ) = base ** int( u * log( s( i ) * t ) )
343  smin = min( smin, s( i ) )
344  smax = max( smax, s( i ) )
345  END DO
346  scond = max( smin, smlnum ) / min( smax, bignum )
347 *
348  END
subroutine zsyequb(UPLO, N, A, LDA, S, SCOND, AMAX, WORK, INFO)
ZSYEQUB
Definition: zsyequb.f:138
subroutine xerbla(SRNAME, INFO)
XERBLA
Definition: xerbla.f:62
subroutine zlassq(N, X, INCX, SCALE, SUMSQ)
ZLASSQ updates a sum of squares represented in scaled form.
Definition: zlassq.f:108