```001:       SUBROUTINE SLASD5( I, D, Z, DELTA, RHO, DSIGMA, WORK )
002: *
003: *  -- LAPACK auxiliary routine (version 3.2) --
004: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
005: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
006: *     November 2006
007: *
008: *     .. Scalar Arguments ..
009:       INTEGER            I
010:       REAL               DSIGMA, RHO
011: *     ..
012: *     .. Array Arguments ..
013:       REAL               D( 2 ), DELTA( 2 ), WORK( 2 ), Z( 2 )
014: *     ..
015: *
016: *  Purpose
017: *  =======
018: *
019: *  This subroutine computes the square root of the I-th eigenvalue
020: *  of a positive symmetric rank-one modification of a 2-by-2 diagonal
021: *  matrix
022: *
023: *             diag( D ) * diag( D ) +  RHO *  Z * transpose(Z) .
024: *
025: *  The diagonal entries in the array D are assumed to satisfy
026: *
027: *             0 <= D(i) < D(j)  for  i < j .
028: *
029: *  We also assume RHO > 0 and that the Euclidean norm of the vector
030: *  Z is one.
031: *
032: *  Arguments
033: *  =========
034: *
035: *  I      (input) INTEGER
036: *         The index of the eigenvalue to be computed.  I = 1 or I = 2.
037: *
038: *  D      (input) REAL array, dimension (2)
039: *         The original eigenvalues.  We assume 0 <= D(1) < D(2).
040: *
041: *  Z      (input) REAL array, dimension (2)
042: *         The components of the updating vector.
043: *
044: *  DELTA  (output) REAL array, dimension (2)
045: *         Contains (D(j) - sigma_I) in its  j-th component.
046: *         The vector DELTA contains the information necessary
047: *         to construct the eigenvectors.
048: *
049: *  RHO    (input) REAL
050: *         The scalar in the symmetric updating formula.
051: *
052: *  DSIGMA (output) REAL
053: *         The computed sigma_I, the I-th updated eigenvalue.
054: *
055: *  WORK   (workspace) REAL array, dimension (2)
056: *         WORK contains (D(j) + sigma_I) in its  j-th component.
057: *
058: *  Further Details
059: *  ===============
060: *
061: *  Based on contributions by
062: *     Ren-Cang Li, Computer Science Division, University of California
063: *     at Berkeley, USA
064: *
065: *  =====================================================================
066: *
067: *     .. Parameters ..
068:       REAL               ZERO, ONE, TWO, THREE, FOUR
069:       PARAMETER          ( ZERO = 0.0E+0, ONE = 1.0E+0, TWO = 2.0E+0,
070:      \$                   THREE = 3.0E+0, FOUR = 4.0E+0 )
071: *     ..
072: *     .. Local Scalars ..
073:       REAL               B, C, DEL, DELSQ, TAU, W
074: *     ..
075: *     .. Intrinsic Functions ..
076:       INTRINSIC          ABS, SQRT
077: *     ..
078: *     .. Executable Statements ..
079: *
080:       DEL = D( 2 ) - D( 1 )
081:       DELSQ = DEL*( D( 2 )+D( 1 ) )
082:       IF( I.EQ.1 ) THEN
083:          W = ONE + FOUR*RHO*( Z( 2 )*Z( 2 ) / ( D( 1 )+THREE*D( 2 ) )-
084:      \$       Z( 1 )*Z( 1 ) / ( THREE*D( 1 )+D( 2 ) ) ) / DEL
085:          IF( W.GT.ZERO ) THEN
086:             B = DELSQ + RHO*( Z( 1 )*Z( 1 )+Z( 2 )*Z( 2 ) )
087:             C = RHO*Z( 1 )*Z( 1 )*DELSQ
088: *
089: *           B > ZERO, always
090: *
091: *           The following TAU is DSIGMA * DSIGMA - D( 1 ) * D( 1 )
092: *
093:             TAU = TWO*C / ( B+SQRT( ABS( B*B-FOUR*C ) ) )
094: *
095: *           The following TAU is DSIGMA - D( 1 )
096: *
097:             TAU = TAU / ( D( 1 )+SQRT( D( 1 )*D( 1 )+TAU ) )
098:             DSIGMA = D( 1 ) + TAU
099:             DELTA( 1 ) = -TAU
100:             DELTA( 2 ) = DEL - TAU
101:             WORK( 1 ) = TWO*D( 1 ) + TAU
102:             WORK( 2 ) = ( D( 1 )+TAU ) + D( 2 )
103: *           DELTA( 1 ) = -Z( 1 ) / TAU
104: *           DELTA( 2 ) = Z( 2 ) / ( DEL-TAU )
105:          ELSE
106:             B = -DELSQ + RHO*( Z( 1 )*Z( 1 )+Z( 2 )*Z( 2 ) )
107:             C = RHO*Z( 2 )*Z( 2 )*DELSQ
108: *
109: *           The following TAU is DSIGMA * DSIGMA - D( 2 ) * D( 2 )
110: *
111:             IF( B.GT.ZERO ) THEN
112:                TAU = -TWO*C / ( B+SQRT( B*B+FOUR*C ) )
113:             ELSE
114:                TAU = ( B-SQRT( B*B+FOUR*C ) ) / TWO
115:             END IF
116: *
117: *           The following TAU is DSIGMA - D( 2 )
118: *
119:             TAU = TAU / ( D( 2 )+SQRT( ABS( D( 2 )*D( 2 )+TAU ) ) )
120:             DSIGMA = D( 2 ) + TAU
121:             DELTA( 1 ) = -( DEL+TAU )
122:             DELTA( 2 ) = -TAU
123:             WORK( 1 ) = D( 1 ) + TAU + D( 2 )
124:             WORK( 2 ) = TWO*D( 2 ) + TAU
125: *           DELTA( 1 ) = -Z( 1 ) / ( DEL+TAU )
126: *           DELTA( 2 ) = -Z( 2 ) / TAU
127:          END IF
128: *        TEMP = SQRT( DELTA( 1 )*DELTA( 1 )+DELTA( 2 )*DELTA( 2 ) )
129: *        DELTA( 1 ) = DELTA( 1 ) / TEMP
130: *        DELTA( 2 ) = DELTA( 2 ) / TEMP
131:       ELSE
132: *
133: *        Now I=2
134: *
135:          B = -DELSQ + RHO*( Z( 1 )*Z( 1 )+Z( 2 )*Z( 2 ) )
136:          C = RHO*Z( 2 )*Z( 2 )*DELSQ
137: *
138: *        The following TAU is DSIGMA * DSIGMA - D( 2 ) * D( 2 )
139: *
140:          IF( B.GT.ZERO ) THEN
141:             TAU = ( B+SQRT( B*B+FOUR*C ) ) / TWO
142:          ELSE
143:             TAU = TWO*C / ( -B+SQRT( B*B+FOUR*C ) )
144:          END IF
145: *
146: *        The following TAU is DSIGMA - D( 2 )
147: *
148:          TAU = TAU / ( D( 2 )+SQRT( D( 2 )*D( 2 )+TAU ) )
149:          DSIGMA = D( 2 ) + TAU
150:          DELTA( 1 ) = -( DEL+TAU )
151:          DELTA( 2 ) = -TAU
152:          WORK( 1 ) = D( 1 ) + TAU + D( 2 )
153:          WORK( 2 ) = TWO*D( 2 ) + TAU
154: *        DELTA( 1 ) = -Z( 1 ) / ( DEL+TAU )
155: *        DELTA( 2 ) = -Z( 2 ) / TAU
156: *        TEMP = SQRT( DELTA( 1 )*DELTA( 1 )+DELTA( 2 )*DELTA( 2 ) )
157: *        DELTA( 1 ) = DELTA( 1 ) / TEMP
158: *        DELTA( 2 ) = DELTA( 2 ) / TEMP
159:       END IF
160:       RETURN
161: *
162: *     End of SLASD5
163: *
164:       END
165: ```