You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

slanv2.f 8.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. *> \brief \b SLANV2 computes the Schur factorization of a real 2-by-2 nonsymmetric matrix in standard form.
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download SLANV2 + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slanv2.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slanv2.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slanv2.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE SLANV2( A, B, C, D, RT1R, RT1I, RT2R, RT2I, CS, SN )
  22. *
  23. * .. Scalar Arguments ..
  24. * REAL A, B, C, CS, D, RT1I, RT1R, RT2I, RT2R, SN
  25. * ..
  26. *
  27. *
  28. *> \par Purpose:
  29. * =============
  30. *>
  31. *> \verbatim
  32. *>
  33. *> SLANV2 computes the Schur factorization of a real 2-by-2 nonsymmetric
  34. *> matrix in standard form:
  35. *>
  36. *> [ A B ] = [ CS -SN ] [ AA BB ] [ CS SN ]
  37. *> [ C D ] [ SN CS ] [ CC DD ] [-SN CS ]
  38. *>
  39. *> where either
  40. *> 1) CC = 0 so that AA and DD are real eigenvalues of the matrix, or
  41. *> 2) AA = DD and BB*CC < 0, so that AA + or - sqrt(BB*CC) are complex
  42. *> conjugate eigenvalues.
  43. *> \endverbatim
  44. *
  45. * Arguments:
  46. * ==========
  47. *
  48. *> \param[in,out] A
  49. *> \verbatim
  50. *> A is REAL
  51. *> \endverbatim
  52. *>
  53. *> \param[in,out] B
  54. *> \verbatim
  55. *> B is REAL
  56. *> \endverbatim
  57. *>
  58. *> \param[in,out] C
  59. *> \verbatim
  60. *> C is REAL
  61. *> \endverbatim
  62. *>
  63. *> \param[in,out] D
  64. *> \verbatim
  65. *> D is REAL
  66. *> On entry, the elements of the input matrix.
  67. *> On exit, they are overwritten by the elements of the
  68. *> standardised Schur form.
  69. *> \endverbatim
  70. *>
  71. *> \param[out] RT1R
  72. *> \verbatim
  73. *> RT1R is REAL
  74. *> \endverbatim
  75. *>
  76. *> \param[out] RT1I
  77. *> \verbatim
  78. *> RT1I is REAL
  79. *> \endverbatim
  80. *>
  81. *> \param[out] RT2R
  82. *> \verbatim
  83. *> RT2R is REAL
  84. *> \endverbatim
  85. *>
  86. *> \param[out] RT2I
  87. *> \verbatim
  88. *> RT2I is REAL
  89. *> The real and imaginary parts of the eigenvalues. If the
  90. *> eigenvalues are a complex conjugate pair, RT1I > 0.
  91. *> \endverbatim
  92. *>
  93. *> \param[out] CS
  94. *> \verbatim
  95. *> CS is REAL
  96. *> \endverbatim
  97. *>
  98. *> \param[out] SN
  99. *> \verbatim
  100. *> SN is REAL
  101. *> Parameters of the rotation matrix.
  102. *> \endverbatim
  103. *
  104. * Authors:
  105. * ========
  106. *
  107. *> \author Univ. of Tennessee
  108. *> \author Univ. of California Berkeley
  109. *> \author Univ. of Colorado Denver
  110. *> \author NAG Ltd.
  111. *
  112. *> \ingroup realOTHERauxiliary
  113. *
  114. *> \par Further Details:
  115. * =====================
  116. *>
  117. *> \verbatim
  118. *>
  119. *> Modified by V. Sima, Research Institute for Informatics, Bucharest,
  120. *> Romania, to reduce the risk of cancellation errors,
  121. *> when computing real eigenvalues, and to ensure, if possible, that
  122. *> abs(RT1R) >= abs(RT2R).
  123. *> \endverbatim
  124. *>
  125. * =====================================================================
  126. SUBROUTINE SLANV2( A, B, C, D, RT1R, RT1I, RT2R, RT2I, CS, SN )
  127. *
  128. * -- LAPACK auxiliary routine --
  129. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  130. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  131. *
  132. * .. Scalar Arguments ..
  133. REAL A, B, C, CS, D, RT1I, RT1R, RT2I, RT2R, SN
  134. * ..
  135. *
  136. * =====================================================================
  137. *
  138. * .. Parameters ..
  139. REAL ZERO, HALF, ONE, TWO
  140. PARAMETER ( ZERO = 0.0E+0, HALF = 0.5E+0, ONE = 1.0E+0,
  141. $ TWO = 2.0E+0 )
  142. REAL MULTPL
  143. PARAMETER ( MULTPL = 4.0E+0 )
  144. * ..
  145. * .. Local Scalars ..
  146. REAL AA, BB, BCMAX, BCMIS, CC, CS1, DD, EPS, P, SAB,
  147. $ SAC, SCALE, SIGMA, SN1, TAU, TEMP, Z, SAFMIN,
  148. $ SAFMN2, SAFMX2
  149. INTEGER COUNT
  150. * ..
  151. * .. External Functions ..
  152. REAL SLAMCH, SLAPY2
  153. EXTERNAL SLAMCH, SLAPY2
  154. * ..
  155. * .. Intrinsic Functions ..
  156. INTRINSIC ABS, MAX, MIN, SIGN, SQRT
  157. * ..
  158. * .. Executable Statements ..
  159. *
  160. SAFMIN = SLAMCH( 'S' )
  161. EPS = SLAMCH( 'P' )
  162. SAFMN2 = SLAMCH( 'B' )**INT( LOG( SAFMIN / EPS ) /
  163. $ LOG( SLAMCH( 'B' ) ) / TWO )
  164. SAFMX2 = ONE / SAFMN2
  165. IF( C.EQ.ZERO ) THEN
  166. CS = ONE
  167. SN = ZERO
  168. *
  169. ELSE IF( B.EQ.ZERO ) THEN
  170. *
  171. * Swap rows and columns
  172. *
  173. CS = ZERO
  174. SN = ONE
  175. TEMP = D
  176. D = A
  177. A = TEMP
  178. B = -C
  179. C = ZERO
  180. *
  181. ELSE IF( (A-D).EQ.ZERO .AND. SIGN( ONE, B ).NE.
  182. $ SIGN( ONE, C ) ) THEN
  183. CS = ONE
  184. SN = ZERO
  185. *
  186. ELSE
  187. *
  188. TEMP = A - D
  189. P = HALF*TEMP
  190. BCMAX = MAX( ABS( B ), ABS( C ) )
  191. BCMIS = MIN( ABS( B ), ABS( C ) )*SIGN( ONE, B )*SIGN( ONE, C )
  192. SCALE = MAX( ABS( P ), BCMAX )
  193. Z = ( P / SCALE )*P + ( BCMAX / SCALE )*BCMIS
  194. *
  195. * If Z is of the order of the machine accuracy, postpone the
  196. * decision on the nature of eigenvalues
  197. *
  198. IF( Z.GE.MULTPL*EPS ) THEN
  199. *
  200. * Real eigenvalues. Compute A and D.
  201. *
  202. Z = P + SIGN( SQRT( SCALE )*SQRT( Z ), P )
  203. A = D + Z
  204. D = D - ( BCMAX / Z )*BCMIS
  205. *
  206. * Compute B and the rotation matrix
  207. *
  208. TAU = SLAPY2( C, Z )
  209. CS = Z / TAU
  210. SN = C / TAU
  211. B = B - C
  212. C = ZERO
  213. *
  214. ELSE
  215. *
  216. * Complex eigenvalues, or real (almost) equal eigenvalues.
  217. * Make diagonal elements equal.
  218. *
  219. COUNT = 0
  220. SIGMA = B + C
  221. 10 CONTINUE
  222. COUNT = COUNT + 1
  223. SCALE = MAX( ABS(TEMP), ABS(SIGMA) )
  224. IF( SCALE.GE.SAFMX2 ) THEN
  225. SIGMA = SIGMA * SAFMN2
  226. TEMP = TEMP * SAFMN2
  227. IF (COUNT .LE. 20)
  228. $ GOTO 10
  229. END IF
  230. IF( SCALE.LE.SAFMN2 ) THEN
  231. SIGMA = SIGMA * SAFMX2
  232. TEMP = TEMP * SAFMX2
  233. IF (COUNT .LE. 20)
  234. $ GOTO 10
  235. END IF
  236. P = HALF*TEMP
  237. TAU = SLAPY2( SIGMA, TEMP )
  238. CS = SQRT( HALF*( ONE+ABS( SIGMA ) / TAU ) )
  239. SN = -( P / ( TAU*CS ) )*SIGN( ONE, SIGMA )
  240. *
  241. * Compute [ AA BB ] = [ A B ] [ CS -SN ]
  242. * [ CC DD ] [ C D ] [ SN CS ]
  243. *
  244. AA = A*CS + B*SN
  245. BB = -A*SN + B*CS
  246. CC = C*CS + D*SN
  247. DD = -C*SN + D*CS
  248. *
  249. * Compute [ A B ] = [ CS SN ] [ AA BB ]
  250. * [ C D ] [-SN CS ] [ CC DD ]
  251. *
  252. A = AA*CS + CC*SN
  253. B = BB*CS + DD*SN
  254. C = -AA*SN + CC*CS
  255. D = -BB*SN + DD*CS
  256. *
  257. TEMP = HALF*( A+D )
  258. A = TEMP
  259. D = TEMP
  260. *
  261. IF( C.NE.ZERO ) THEN
  262. IF( B.NE.ZERO ) THEN
  263. IF( SIGN( ONE, B ).EQ.SIGN( ONE, C ) ) THEN
  264. *
  265. * Real eigenvalues: reduce to upper triangular form
  266. *
  267. SAB = SQRT( ABS( B ) )
  268. SAC = SQRT( ABS( C ) )
  269. P = SIGN( SAB*SAC, C )
  270. TAU = ONE / SQRT( ABS( B+C ) )
  271. A = TEMP + P
  272. D = TEMP - P
  273. B = B - C
  274. C = ZERO
  275. CS1 = SAB*TAU
  276. SN1 = SAC*TAU
  277. TEMP = CS*CS1 - SN*SN1
  278. SN = CS*SN1 + SN*CS1
  279. CS = TEMP
  280. END IF
  281. ELSE
  282. B = -C
  283. C = ZERO
  284. TEMP = CS
  285. CS = -SN
  286. SN = TEMP
  287. END IF
  288. END IF
  289. END IF
  290. *
  291. END IF
  292. *
  293. * Store eigenvalues in (RT1R,RT1I) and (RT2R,RT2I).
  294. *
  295. RT1R = A
  296. RT2R = D
  297. IF( C.EQ.ZERO ) THEN
  298. RT1I = ZERO
  299. RT2I = ZERO
  300. ELSE
  301. RT1I = SQRT( ABS( B ) )*SQRT( ABS( C ) )
  302. RT2I = -RT1I
  303. END IF
  304. RETURN
  305. *
  306. * End of SLANV2
  307. *
  308. END