00001 SUBROUTINE DSYEQUB( UPLO, N, A, LDA, S, SCOND, AMAX, WORK, INFO )
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 IMPLICIT NONE
00012
00013
00014 INTEGER INFO, LDA, N
00015 DOUBLE PRECISION AMAX, SCOND
00016 CHARACTER UPLO
00017
00018
00019 DOUBLE PRECISION A( LDA, * ), S( * ), WORK( * )
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 DOUBLE PRECISION ONE, ZERO
00086 PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 )
00087 INTEGER MAX_ITER
00088 PARAMETER ( MAX_ITER = 100 )
00089
00090
00091 INTEGER I, J, ITER
00092 DOUBLE PRECISION AVG, STD, TOL, C0, C1, C2, T, U, SI, D, BASE,
00093 $ SMIN, SMAX, SMLNUM, BIGNUM, SCALE, SUMSQ
00094 LOGICAL UP
00095
00096
00097 DOUBLE PRECISION DLAMCH
00098 LOGICAL LSAME
00099 EXTERNAL DLAMCH, LSAME
00100
00101
00102 EXTERNAL DLASSQ
00103
00104
00105 INTRINSIC ABS, INT, LOG, MAX, MIN, SQRT
00106
00107
00108
00109
00110
00111 INFO = 0
00112 IF ( .NOT. ( LSAME( UPLO, 'U' ) .OR. LSAME( UPLO, 'L' ) ) ) THEN
00113 INFO = -1
00114 ELSE IF ( N .LT. 0 ) THEN
00115 INFO = -2
00116 ELSE IF ( LDA .LT. MAX( 1, N ) ) THEN
00117 INFO = -4
00118 END IF
00119 IF ( INFO .NE. 0 ) THEN
00120 CALL XERBLA( 'DSYEQUB', -INFO )
00121 RETURN
00122 END IF
00123
00124 UP = LSAME( UPLO, 'U' )
00125 AMAX = ZERO
00126
00127
00128
00129 IF ( N .EQ. 0 ) THEN
00130 SCOND = ONE
00131 RETURN
00132 END IF
00133
00134 DO I = 1, N
00135 S( I ) = ZERO
00136 END DO
00137
00138 AMAX = ZERO
00139 IF ( UP ) THEN
00140 DO J = 1, N
00141 DO I = 1, J-1
00142 S( I ) = MAX( S( I ), ABS( A( I, J ) ) )
00143 S( J ) = MAX( S( J ), ABS( A( I, J ) ) )
00144 AMAX = MAX( AMAX, ABS( A(I, J) ) )
00145 END DO
00146 S( J ) = MAX( S( J ), ABS( A( J, J ) ) )
00147 AMAX = MAX( AMAX, ABS( A( J, J ) ) )
00148 END DO
00149 ELSE
00150 DO J = 1, N
00151 S( J ) = MAX( S( J ), ABS( A( J, J ) ) )
00152 AMAX = MAX( AMAX, ABS( A( J, J ) ) )
00153 DO I = J+1, N
00154 S( I ) = MAX( S( I ), ABS( A( I, J ) ) )
00155 S( J ) = MAX( S( J ), ABS( A( I, J ) ) )
00156 AMAX = MAX( AMAX, ABS( A( I, J ) ) )
00157 END DO
00158 END DO
00159 END IF
00160 DO J = 1, N
00161 S( J ) = 1.0D+0 / S( J )
00162 END DO
00163
00164 TOL = ONE / SQRT(2.0D0 * N)
00165
00166 DO ITER = 1, MAX_ITER
00167 SCALE = 0.0D+0
00168 SUMSQ = 0.0D+0
00169
00170 DO I = 1, N
00171 WORK(I) = ZERO
00172 END DO
00173 IF ( UP ) THEN
00174 DO J = 1, N
00175 DO I = 1, J-1
00176 T = ABS( A( I, J ) )
00177 WORK( I ) = WORK( I ) + ABS( A( I, J ) ) * S( J )
00178 WORK( J ) = WORK( J ) + ABS( A( I, J ) ) * S( I )
00179 END DO
00180 WORK( J ) = WORK( J ) + ABS( A( J, J ) ) * S( J )
00181 END DO
00182 ELSE
00183 DO J = 1, N
00184 WORK( J ) = WORK( J ) + ABS( A( J, J ) ) * S( J )
00185 DO I = J+1, N
00186 T = ABS( A( I, J ) )
00187 WORK( I ) = WORK( I ) + ABS( A( I, J ) ) * S( J )
00188 WORK( J ) = WORK( J ) + ABS( A( I, J ) ) * S( I )
00189 END DO
00190 END DO
00191 END IF
00192
00193
00194 AVG = 0.0D+0
00195 DO I = 1, N
00196 AVG = AVG + S( I )*WORK( I )
00197 END DO
00198 AVG = AVG / N
00199
00200 STD = 0.0D+0
00201 DO I = 2*N+1, 3*N
00202 WORK( I ) = S( I-2*N ) * WORK( I-2*N ) - AVG
00203 END DO
00204 CALL DLASSQ( N, WORK( 2*N+1 ), 1, SCALE, SUMSQ )
00205 STD = SCALE * SQRT( SUMSQ / N )
00206
00207 IF ( STD .LT. TOL * AVG ) GOTO 999
00208
00209 DO I = 1, N
00210 T = ABS( A( I, I ) )
00211 SI = S( I )
00212 C2 = ( N-1 ) * T
00213 C1 = ( N-2 ) * ( WORK( I ) - T*SI )
00214 C0 = -(T*SI)*SI + 2*WORK( I )*SI - N*AVG
00215 D = C1*C1 - 4*C0*C2
00216
00217 IF ( D .LE. 0 ) THEN
00218 INFO = -1
00219 RETURN
00220 END IF
00221 SI = -2*C0 / ( C1 + SQRT( D ) )
00222
00223 D = SI - S( I )
00224 U = ZERO
00225 IF ( UP ) THEN
00226 DO J = 1, I
00227 T = ABS( A( J, I ) )
00228 U = U + S( J )*T
00229 WORK( J ) = WORK( J ) + D*T
00230 END DO
00231 DO J = I+1,N
00232 T = ABS( A( I, J ) )
00233 U = U + S( J )*T
00234 WORK( J ) = WORK( J ) + D*T
00235 END DO
00236 ELSE
00237 DO J = 1, I
00238 T = ABS( A( I, J ) )
00239 U = U + S( J )*T
00240 WORK( J ) = WORK( J ) + D*T
00241 END DO
00242 DO J = I+1,N
00243 T = ABS( A( J, I ) )
00244 U = U + S( J )*T
00245 WORK( J ) = WORK( J ) + D*T
00246 END DO
00247 END IF
00248
00249 AVG = AVG + ( U + WORK( I ) ) * D / N
00250 S( I ) = SI
00251
00252 END DO
00253
00254 END DO
00255
00256 999 CONTINUE
00257
00258 SMLNUM = DLAMCH( 'SAFEMIN' )
00259 BIGNUM = ONE / SMLNUM
00260 SMIN = BIGNUM
00261 SMAX = ZERO
00262 T = ONE / SQRT(AVG)
00263 BASE = DLAMCH( 'B' )
00264 U = ONE / LOG( BASE )
00265 DO I = 1, N
00266 S( I ) = BASE ** INT( U * LOG( S( I ) * T ) )
00267 SMIN = MIN( SMIN, S( I ) )
00268 SMAX = MAX( SMAX, S( I ) )
00269 END DO
00270 SCOND = MAX( SMIN, SMLNUM ) / MIN( SMAX, BIGNUM )
00271
00272 END