numeric-linalg
Educational material on the SciPy implementation of numerical linear algebra algorithms
Name | Size | Mode | |
.. | |||
lapack/SRC/slanv2.f | 8476B | -rw-r--r-- |
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095 096 097 098 099 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
*> \brief \b SLANV2 computes the Schur factorization of a real 2-by-2 nonsymmetric matrix in standard form. * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download SLANV2 + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slanv2.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slanv2.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slanv2.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE SLANV2( A, B, C, D, RT1R, RT1I, RT2R, RT2I, CS, SN ) * * .. Scalar Arguments .. * REAL A, B, C, CS, D, RT1I, RT1R, RT2I, RT2R, SN * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> SLANV2 computes the Schur factorization of a real 2-by-2 nonsymmetric *> matrix in standard form: *> *> [ A B ] = [ CS -SN ] [ AA BB ] [ CS SN ] *> [ C D ] [ SN CS ] [ CC DD ] [-SN CS ] *> *> where either *> 1) CC = 0 so that AA and DD are real eigenvalues of the matrix, or *> 2) AA = DD and BB*CC < 0, so that AA + or - sqrt(BB*CC) are complex *> conjugate eigenvalues. *> \endverbatim * * Arguments: * ========== * *> \param[in,out] A *> \verbatim *> A is REAL *> \endverbatim *> *> \param[in,out] B *> \verbatim *> B is REAL *> \endverbatim *> *> \param[in,out] C *> \verbatim *> C is REAL *> \endverbatim *> *> \param[in,out] D *> \verbatim *> D is REAL *> On entry, the elements of the input matrix. *> On exit, they are overwritten by the elements of the *> standardised Schur form. *> \endverbatim *> *> \param[out] RT1R *> \verbatim *> RT1R is REAL *> \endverbatim *> *> \param[out] RT1I *> \verbatim *> RT1I is REAL *> \endverbatim *> *> \param[out] RT2R *> \verbatim *> RT2R is REAL *> \endverbatim *> *> \param[out] RT2I *> \verbatim *> RT2I is REAL *> The real and imaginary parts of the eigenvalues. If the *> eigenvalues are a complex conjugate pair, RT1I > 0. *> \endverbatim *> *> \param[out] CS *> \verbatim *> CS is REAL *> \endverbatim *> *> \param[out] SN *> \verbatim *> SN is REAL *> Parameters of the rotation matrix. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \ingroup lanv2 * *> \par Further Details: * ===================== *> *> \verbatim *> *> Modified by V. Sima, Research Institute for Informatics, Bucharest, *> Romania, to reduce the risk of cancellation errors, *> when computing real eigenvalues, and to ensure, if possible, that *> abs(RT1R) >= abs(RT2R). *> \endverbatim *> * ===================================================================== SUBROUTINE SLANV2( A, B, C, D, RT1R, RT1I, RT2R, RT2I, CS, SN ) * * -- LAPACK auxiliary routine -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * * .. Scalar Arguments .. REAL A, B, C, CS, D, RT1I, RT1R, RT2I, RT2R, SN * .. * * ===================================================================== * * .. Parameters .. REAL ZERO, HALF, ONE, TWO PARAMETER ( ZERO = 0.0E+0, HALF = 0.5E+0, ONE = 1.0E+0, $ TWO = 2.0E+0 ) REAL MULTPL PARAMETER ( MULTPL = 4.0E+0 ) * .. * .. Local Scalars .. REAL AA, BB, BCMAX, BCMIS, CC, CS1, DD, EPS, P, SAB, $ SAC, SCALE, SIGMA, SN1, TAU, TEMP, Z, SAFMIN, $ SAFMN2, SAFMX2 INTEGER COUNT * .. * .. External Functions .. REAL SLAMCH, SLAPY2 EXTERNAL SLAMCH, SLAPY2 * .. * .. Intrinsic Functions .. INTRINSIC ABS, MAX, MIN, SIGN, SQRT * .. * .. Executable Statements .. * SAFMIN = SLAMCH( 'S' ) EPS = SLAMCH( 'P' ) SAFMN2 = SLAMCH( 'B' )**INT( LOG( SAFMIN / EPS ) / $ LOG( SLAMCH( 'B' ) ) / TWO ) SAFMX2 = ONE / SAFMN2 IF( C.EQ.ZERO ) THEN CS = ONE SN = ZERO * ELSE IF( B.EQ.ZERO ) THEN * * Swap rows and columns * CS = ZERO SN = ONE TEMP = D D = A A = TEMP B = -C C = ZERO * ELSE IF( (A-D).EQ.ZERO .AND. SIGN( ONE, B ).NE. $ SIGN( ONE, C ) ) THEN CS = ONE SN = ZERO * ELSE * TEMP = A - D P = HALF*TEMP BCMAX = MAX( ABS( B ), ABS( C ) ) BCMIS = MIN( ABS( B ), ABS( C ) )*SIGN( ONE, B )*SIGN( ONE, C ) SCALE = MAX( ABS( P ), BCMAX ) Z = ( P / SCALE )*P + ( BCMAX / SCALE )*BCMIS * * If Z is of the order of the machine accuracy, postpone the * decision on the nature of eigenvalues * IF( Z.GE.MULTPL*EPS ) THEN * * Real eigenvalues. Compute A and D. * Z = P + SIGN( SQRT( SCALE )*SQRT( Z ), P ) A = D + Z D = D - ( BCMAX / Z )*BCMIS * * Compute B and the rotation matrix * TAU = SLAPY2( C, Z ) CS = Z / TAU SN = C / TAU B = B - C C = ZERO * ELSE * * Complex eigenvalues, or real (almost) equal eigenvalues. * Make diagonal elements equal. * COUNT = 0 SIGMA = B + C 10 CONTINUE COUNT = COUNT + 1 SCALE = MAX( ABS(TEMP), ABS(SIGMA) ) IF( SCALE.GE.SAFMX2 ) THEN SIGMA = SIGMA * SAFMN2 TEMP = TEMP * SAFMN2 IF (COUNT .LE. 20) $ GOTO 10 END IF IF( SCALE.LE.SAFMN2 ) THEN SIGMA = SIGMA * SAFMX2 TEMP = TEMP * SAFMX2 IF (COUNT .LE. 20) $ GOTO 10 END IF P = HALF*TEMP TAU = SLAPY2( SIGMA, TEMP ) CS = SQRT( HALF*( ONE+ABS( SIGMA ) / TAU ) ) SN = -( P / ( TAU*CS ) )*SIGN( ONE, SIGMA ) * * Compute [ AA BB ] = [ A B ] [ CS -SN ] * [ CC DD ] [ C D ] [ SN CS ] * AA = A*CS + B*SN BB = -A*SN + B*CS CC = C*CS + D*SN DD = -C*SN + D*CS * * Compute [ A B ] = [ CS SN ] [ AA BB ] * [ C D ] [-SN CS ] [ CC DD ] * * Note: Some of the multiplications are wrapped in parentheses to * prevent compilers from using FMA instructions. See * https://github.com/Reference-LAPACK/lapack/issues/1031. * A = AA*CS + CC*SN B = ( BB*CS ) + ( DD*SN ) C = -( AA*SN ) + ( CC*CS ) D = -BB*SN + DD*CS * TEMP = HALF*( A+D ) A = TEMP D = TEMP * IF( C.NE.ZERO ) THEN IF( B.NE.ZERO ) THEN IF( SIGN( ONE, B ).EQ.SIGN( ONE, C ) ) THEN * * Real eigenvalues: reduce to upper triangular form * SAB = SQRT( ABS( B ) ) SAC = SQRT( ABS( C ) ) P = SIGN( SAB*SAC, C ) TAU = ONE / SQRT( ABS( B+C ) ) A = TEMP + P D = TEMP - P B = B - C C = ZERO CS1 = SAB*TAU SN1 = SAC*TAU TEMP = CS*CS1 - SN*SN1 SN = CS*SN1 + SN*CS1 CS = TEMP END IF ELSE B = -C C = ZERO TEMP = CS CS = -SN SN = TEMP END IF END IF END IF * END IF * * Store eigenvalues in (RT1R,RT1I) and (RT2R,RT2I). * RT1R = A RT2R = D IF( C.EQ.ZERO ) THEN RT1I = ZERO RT2I = ZERO ELSE RT1I = SQRT( ABS( B ) )*SQRT( ABS( C ) ) RT2I = -RT1I END IF RETURN * * End of SLANV2 * END