LAPACK 3.3.0

dsyequb.f

Go to the documentation of this file.
00001       SUBROUTINE DSYEQUB( UPLO, N, A, LDA, S, SCOND, AMAX, WORK, INFO )
00002 *
00003 *     -- LAPACK routine (version 3.2.2)                                 --
00004 *     -- Contributed by James Demmel, Deaglan Halligan, Yozo Hida and --
00005 *     -- Jason Riedy of Univ. of California Berkeley.                 --
00006 *     -- June 2010                                                    --
00007 *
00008 *     -- LAPACK is a software package provided by Univ. of Tennessee, --
00009 *     -- Univ. of California Berkeley and NAG Ltd.                    --
00010 *
00011       IMPLICIT NONE
00012 *     ..
00013 *     .. Scalar Arguments ..
00014       INTEGER            INFO, LDA, N
00015       DOUBLE PRECISION   AMAX, SCOND
00016       CHARACTER          UPLO
00017 *     ..
00018 *     .. Array Arguments ..
00019       DOUBLE PRECISION   A( LDA, * ), S( * ), WORK( * )
00020 *     ..
00021 *
00022 *  Purpose
00023 *  =======
00024 *
00025 *  DSYEQUB computes row and column scalings intended to equilibrate a
00026 *  symmetric matrix A and reduce its condition number
00027 *  (with respect to the two-norm).  S contains the scale factors,
00028 *  S(i) = 1/sqrt(A(i,i)), chosen so that the scaled matrix B with
00029 *  elements B(i,j) = S(i)*A(i,j)*S(j) has ones on the diagonal.  This
00030 *  choice of S puts the condition number of B within a factor N of the
00031 *  smallest possible condition number over all possible diagonal
00032 *  scalings.
00033 *
00034 *  Arguments
00035 *  =========
00036 *
00037 *  UPLO    (input) CHARACTER*1
00038 *          Specifies whether the details of the factorization are stored
00039 *          as an upper or lower triangular matrix.
00040 *          = 'U':  Upper triangular, form is A = U*D*U**T;
00041 *          = 'L':  Lower triangular, form is A = L*D*L**T.
00042 *
00043 *  N       (input) INTEGER
00044 *          The order of the matrix A.  N >= 0.
00045 *
00046 *  A       (input) DOUBLE PRECISION array, dimension (LDA,N)
00047 *          The N-by-N symmetric matrix whose scaling
00048 *          factors are to be computed.  Only the diagonal elements of A
00049 *          are referenced.
00050 *
00051 *  LDA     (input) INTEGER
00052 *          The leading dimension of the array A.  LDA >= max(1,N).
00053 *
00054 *  S       (output) DOUBLE PRECISION array, dimension (N)
00055 *          If INFO = 0, S contains the scale factors for A.
00056 *
00057 *  SCOND   (output) DOUBLE PRECISION
00058 *          If INFO = 0, S contains the ratio of the smallest S(i) to
00059 *          the largest S(i).  If SCOND >= 0.1 and AMAX is neither too
00060 *          large nor too small, it is not worth scaling by S.
00061 *
00062 *  AMAX    (output) DOUBLE PRECISION
00063 *          Absolute value of largest matrix element.  If AMAX is very
00064 *          close to overflow or very close to underflow, the matrix
00065 *          should be scaled.
00066 *
00067 *  WORK    (workspace) DOUBLE PRECISION array, dimension (3*N)
00068 *
00069 *  INFO    (output) INTEGER
00070 *          = 0:  successful exit
00071 *          < 0:  if INFO = -i, the i-th argument had an illegal value
00072 *          > 0:  if INFO = i, the i-th diagonal element is nonpositive.
00073 *
00074 *  Further Details
00075 *  ======= =======
00076 *
00077 *  Reference: Livne, O.E. and Golub, G.H., "Scaling by Binormalization",
00078 *  Numerical Algorithms, vol. 35, no. 1, pp. 97-120, January 2004.
00079 *  DOI 10.1023/B:NUMA.0000016606.32820.69
00080 *  Tech report version: http://ruready.utah.edu/archive/papers/bin.pdf
00081 *
00082 *  =====================================================================
00083 *
00084 *     .. Parameters ..
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 *     .. Local Scalars ..
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 *     .. External Functions ..
00097       DOUBLE PRECISION   DLAMCH
00098       LOGICAL            LSAME
00099       EXTERNAL           DLAMCH, LSAME
00100 *     ..
00101 *     .. External Subroutines ..
00102       EXTERNAL           DLASSQ
00103 *     ..
00104 *     .. Intrinsic Functions ..
00105       INTRINSIC          ABS, INT, LOG, MAX, MIN, SQRT
00106 *     ..
00107 *     .. Executable Statements ..
00108 *
00109 *     Test input parameters.
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 *     Quick return if possible.
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 *       BETA = |A|S
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 *       avg = s^T beta / n
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
 All Files Functions