LAPACK  3.4.2
LAPACK: Linear Algebra PACKage
 All Files Functions Groups
csyequb.f
Go to the documentation of this file.
1 *> \brief \b CSYEQUB
2 *
3 * =========== DOCUMENTATION ===========
4 *
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
7 *
8 *> \htmlonly
9 *> Download CSYEQUB + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/csyequb.f">
11 *> [TGZ]</a>
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/csyequb.f">
13 *> [ZIP]</a>
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/csyequb.f">
15 *> [TXT]</a>
16 *> \endhtmlonly
17 *
18 * Definition:
19 * ===========
20 *
21 * SUBROUTINE CSYEQUB( UPLO, N, A, LDA, S, SCOND, AMAX, WORK, INFO )
22 *
23 * .. Scalar Arguments ..
24 * INTEGER INFO, LDA, N
25 * REAL AMAX, SCOND
26 * CHARACTER UPLO
27 * ..
28 * .. Array Arguments ..
29 * COMPLEX A( LDA, * ), WORK( * )
30 * REAL S( * )
31 * ..
32 *
33 *
34 *> \par Purpose:
35 * =============
36 *>
37 *> \verbatim
38 *>
39 *> CSYEQUB 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 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 REAL 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 REAL
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 REAL
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 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 complexSYcomputational
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 csyequb( 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  REAL amax, scond
147  CHARACTER uplo
148 * ..
149 * .. Array Arguments ..
150  COMPLEX a( lda, * ), work( * )
151  REAL s( * )
152 * ..
153 *
154 * =====================================================================
155 *
156 * .. Parameters ..
157  REAL one, zero
158  parameter( one = 1.0e0, zero = 0.0e0 )
159  INTEGER max_iter
160  parameter( max_iter = 100 )
161 * ..
162 * .. Local Scalars ..
163  INTEGER i, j, iter
164  REAL avg, std, tol, c0, c1, c2, t, u, si, d, base,
165  $ smin, smax, smlnum, bignum, scale, sumsq
166  LOGICAL up
167  COMPLEX zdum
168 * ..
169 * .. External Functions ..
170  REAL slamch
171  LOGICAL lsame
172  EXTERNAL lsame, slamch
173 * ..
174 * .. External Subroutines ..
175  EXTERNAL classq
176 * ..
177 * .. Intrinsic Functions ..
178  INTRINSIC abs, aimag, int, log, max, min, REAL, sqrt
179 * ..
180 * .. Statement Functions ..
181  REAL cabs1
182 * ..
183 * Statement Function Definitions
184  cabs1( zdum ) = abs( REAL( ZDUM ) ) + abs( aimag( 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( 'CSYEQUB', -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.0 / s( j )
241  END DO
242 
243  tol = one / sqrt( 2.0e0 * n )
244 
245  DO iter = 1, max_iter
246  scale = 0.0
247  sumsq = 0.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.0
274  DO i = 1, n
275  avg = avg + s( i )*work( i )
276  END DO
277  avg = avg / n
278 
279  std = 0.0
280  DO i = n+1, 2*n
281  work( i ) = s( i-n ) * work( i-n ) - avg
282  END DO
283  CALL classq( 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 = slamch( 'SAFEMIN' )
335  bignum = one / smlnum
336  smin = bignum
337  smax = zero
338  t = one / sqrt( avg )
339  base = slamch( '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