001:       SUBROUTINE DLAEV2( A, B, C, RT1, RT2, CS1, SN1 )
002: *
003: *  -- LAPACK auxiliary routine (version 3.2) --
004: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
005: *     November 2006
006: *
007: *     .. Scalar Arguments ..
008:       DOUBLE PRECISION   A, B, C, CS1, RT1, RT2, SN1
009: *     ..
010: *
011: *  Purpose
012: *  =======
013: *
014: *  DLAEV2 computes the eigendecomposition of a 2-by-2 symmetric matrix
015: *     [  A   B  ]
016: *     [  B   C  ].
017: *  On return, RT1 is the eigenvalue of larger absolute value, RT2 is the
018: *  eigenvalue of smaller absolute value, and (CS1,SN1) is the unit right
019: *  eigenvector for RT1, giving the decomposition
020: *
021: *     [ CS1  SN1 ] [  A   B  ] [ CS1 -SN1 ]  =  [ RT1  0  ]
022: *     [-SN1  CS1 ] [  B   C  ] [ SN1  CS1 ]     [  0  RT2 ].
023: *
024: *  Arguments
025: *  =========
026: *
027: *  A       (input) DOUBLE PRECISION
028: *          The (1,1) element of the 2-by-2 matrix.
029: *
030: *  B       (input) DOUBLE PRECISION
031: *          The (1,2) element and the conjugate of the (2,1) element of
032: *          the 2-by-2 matrix.
033: *
034: *  C       (input) DOUBLE PRECISION
035: *          The (2,2) element of the 2-by-2 matrix.
036: *
037: *  RT1     (output) DOUBLE PRECISION
038: *          The eigenvalue of larger absolute value.
039: *
040: *  RT2     (output) DOUBLE PRECISION
041: *          The eigenvalue of smaller absolute value.
042: *
043: *  CS1     (output) DOUBLE PRECISION
044: *  SN1     (output) DOUBLE PRECISION
045: *          The vector (CS1, SN1) is a unit right eigenvector for RT1.
046: *
047: *  Further Details
048: *  ===============
049: *
050: *  RT1 is accurate to a few ulps barring over/underflow.
051: *
052: *  RT2 may be inaccurate if there is massive cancellation in the
053: *  determinant A*C-B*B; higher precision or correctly rounded or
054: *  correctly truncated arithmetic would be needed to compute RT2
055: *  accurately in all cases.
056: *
057: *  CS1 and SN1 are accurate to a few ulps barring over/underflow.
058: *
059: *  Overflow is possible only if RT1 is within a factor of 5 of overflow.
060: *  Underflow is harmless if the input data is 0 or exceeds
061: *     underflow_threshold / macheps.
062: *
063: * =====================================================================
064: *
065: *     .. Parameters ..
066:       DOUBLE PRECISION   ONE
067:       PARAMETER          ( ONE = 1.0D0 )
068:       DOUBLE PRECISION   TWO
069:       PARAMETER          ( TWO = 2.0D0 )
070:       DOUBLE PRECISION   ZERO
071:       PARAMETER          ( ZERO = 0.0D0 )
072:       DOUBLE PRECISION   HALF
073:       PARAMETER          ( HALF = 0.5D0 )
074: *     ..
075: *     .. Local Scalars ..
076:       INTEGER            SGN1, SGN2
077:       DOUBLE PRECISION   AB, ACMN, ACMX, ACS, ADF, CS, CT, DF, RT, SM,
078:      $                   TB, TN
079: *     ..
080: *     .. Intrinsic Functions ..
081:       INTRINSIC          ABS, SQRT
082: *     ..
083: *     .. Executable Statements ..
084: *
085: *     Compute the eigenvalues
086: *
087:       SM = A + C
088:       DF = A - C
089:       ADF = ABS( DF )
090:       TB = B + B
091:       AB = ABS( TB )
092:       IF( ABS( A ).GT.ABS( C ) ) THEN
093:          ACMX = A
094:          ACMN = C
095:       ELSE
096:          ACMX = C
097:          ACMN = A
098:       END IF
099:       IF( ADF.GT.AB ) THEN
100:          RT = ADF*SQRT( ONE+( AB / ADF )**2 )
101:       ELSE IF( ADF.LT.AB ) THEN
102:          RT = AB*SQRT( ONE+( ADF / AB )**2 )
103:       ELSE
104: *
105: *        Includes case AB=ADF=0
106: *
107:          RT = AB*SQRT( TWO )
108:       END IF
109:       IF( SM.LT.ZERO ) THEN
110:          RT1 = HALF*( SM-RT )
111:          SGN1 = -1
112: *
113: *        Order of execution important.
114: *        To get fully accurate smaller eigenvalue,
115: *        next line needs to be executed in higher precision.
116: *
117:          RT2 = ( ACMX / RT1 )*ACMN - ( B / RT1 )*B
118:       ELSE IF( SM.GT.ZERO ) THEN
119:          RT1 = HALF*( SM+RT )
120:          SGN1 = 1
121: *
122: *        Order of execution important.
123: *        To get fully accurate smaller eigenvalue,
124: *        next line needs to be executed in higher precision.
125: *
126:          RT2 = ( ACMX / RT1 )*ACMN - ( B / RT1 )*B
127:       ELSE
128: *
129: *        Includes case RT1 = RT2 = 0
130: *
131:          RT1 = HALF*RT
132:          RT2 = -HALF*RT
133:          SGN1 = 1
134:       END IF
135: *
136: *     Compute the eigenvector
137: *
138:       IF( DF.GE.ZERO ) THEN
139:          CS = DF + RT
140:          SGN2 = 1
141:       ELSE
142:          CS = DF - RT
143:          SGN2 = -1
144:       END IF
145:       ACS = ABS( CS )
146:       IF( ACS.GT.AB ) THEN
147:          CT = -TB / CS
148:          SN1 = ONE / SQRT( ONE+CT*CT )
149:          CS1 = CT*SN1
150:       ELSE
151:          IF( AB.EQ.ZERO ) THEN
152:             CS1 = ONE
153:             SN1 = ZERO
154:          ELSE
155:             TN = -CS / TB
156:             CS1 = ONE / SQRT( ONE+TN*TN )
157:             SN1 = TN*CS1
158:          END IF
159:       END IF
160:       IF( SGN1.EQ.SGN2 ) THEN
161:          TN = CS1
162:          CS1 = -SN1
163:          SN1 = TN
164:       END IF
165:       RETURN
166: *
167: *     End of DLAEV2
168: *
169:       END
170: