001:       SUBROUTINE SPOEQU( N, A, LDA, S, SCOND, AMAX, INFO )
002: *
003: *  -- LAPACK routine (version 3.2) --
004: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
005: *     November 2006
006: *
007: *     .. Scalar Arguments ..
008:       INTEGER            INFO, LDA, N
009:       REAL               AMAX, SCOND
010: *     ..
011: *     .. Array Arguments ..
012:       REAL               A( LDA, * ), S( * )
013: *     ..
014: *
015: *  Purpose
016: *  =======
017: *
018: *  SPOEQU computes row and column scalings intended to equilibrate a
019: *  symmetric positive definite matrix A and reduce its condition number
020: *  (with respect to the two-norm).  S contains the scale factors,
021: *  S(i) = 1/sqrt(A(i,i)), chosen so that the scaled matrix B with
022: *  elements B(i,j) = S(i)*A(i,j)*S(j) has ones on the diagonal.  This
023: *  choice of S puts the condition number of B within a factor N of the
024: *  smallest possible condition number over all possible diagonal
025: *  scalings.
026: *
027: *  Arguments
028: *  =========
029: *
030: *  N       (input) INTEGER
031: *          The order of the matrix A.  N >= 0.
032: *
033: *  A       (input) REAL array, dimension (LDA,N)
034: *          The N-by-N symmetric positive definite matrix whose scaling
035: *          factors are to be computed.  Only the diagonal elements of A
036: *          are referenced.
037: *
038: *  LDA     (input) INTEGER
039: *          The leading dimension of the array A.  LDA >= max(1,N).
040: *
041: *  S       (output) REAL array, dimension (N)
042: *          If INFO = 0, S contains the scale factors for A.
043: *
044: *  SCOND   (output) REAL
045: *          If INFO = 0, S contains the ratio of the smallest S(i) to
046: *          the largest S(i).  If SCOND >= 0.1 and AMAX is neither too
047: *          large nor too small, it is not worth scaling by S.
048: *
049: *  AMAX    (output) REAL
050: *          Absolute value of largest matrix element.  If AMAX is very
051: *          close to overflow or very close to underflow, the matrix
052: *          should be scaled.
053: *
054: *  INFO    (output) INTEGER
055: *          = 0:  successful exit
056: *          < 0:  if INFO = -i, the i-th argument had an illegal value
057: *          > 0:  if INFO = i, the i-th diagonal element is nonpositive.
058: *
059: *  =====================================================================
060: *
061: *     .. Parameters ..
062:       REAL               ZERO, ONE
063:       PARAMETER          ( ZERO = 0.0E+0, ONE = 1.0E+0 )
064: *     ..
065: *     .. Local Scalars ..
066:       INTEGER            I
067:       REAL               SMIN
068: *     ..
069: *     .. External Subroutines ..
070:       EXTERNAL           XERBLA
071: *     ..
072: *     .. Intrinsic Functions ..
073:       INTRINSIC          MAX, MIN, SQRT
074: *     ..
075: *     .. Executable Statements ..
076: *
077: *     Test the input parameters.
078: *
079:       INFO = 0
080:       IF( N.LT.0 ) THEN
081:          INFO = -1
082:       ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
083:          INFO = -3
084:       END IF
085:       IF( INFO.NE.0 ) THEN
086:          CALL XERBLA( 'SPOEQU', -INFO )
087:          RETURN
088:       END IF
089: *
090: *     Quick return if possible
091: *
092:       IF( N.EQ.0 ) THEN
093:          SCOND = ONE
094:          AMAX = ZERO
095:          RETURN
096:       END IF
097: *
098: *     Find the minimum and maximum diagonal elements.
099: *
100:       S( 1 ) = A( 1, 1 )
101:       SMIN = S( 1 )
102:       AMAX = S( 1 )
103:       DO 10 I = 2, N
104:          S( I ) = A( I, I )
105:          SMIN = MIN( SMIN, S( I ) )
106:          AMAX = MAX( AMAX, S( I ) )
107:    10 CONTINUE
108: *
109:       IF( SMIN.LE.ZERO ) THEN
110: *
111: *        Find the first non-positive diagonal element and return.
112: *
113:          DO 20 I = 1, N
114:             IF( S( I ).LE.ZERO ) THEN
115:                INFO = I
116:                RETURN
117:             END IF
118:    20    CONTINUE
119:       ELSE
120: *
121: *        Set the scale factors to the reciprocals
122: *        of the diagonal elements.
123: *
124:          DO 30 I = 1, N
125:             S( I ) = ONE / SQRT( S( I ) )
126:    30    CONTINUE
127: *
128: *        Compute SCOND = min(S(I)) / max(S(I))
129: *
130:          SCOND = SQRT( SMIN ) / SQRT( AMAX )
131:       END IF
132:       RETURN
133: *
134: *     End of SPOEQU
135: *
136:       END
137: