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.

slasv2.f 8.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. *> \brief \b SLASV2 computes the singular value decomposition of a 2-by-2 triangular matrix.
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download SLASV2 + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slasv2.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slasv2.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slasv2.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE SLASV2( F, G, H, SSMIN, SSMAX, SNR, CSR, SNL, CSL )
  22. *
  23. * .. Scalar Arguments ..
  24. * REAL CSL, CSR, F, G, H, SNL, SNR, SSMAX, SSMIN
  25. * ..
  26. *
  27. *
  28. *> \par Purpose:
  29. * =============
  30. *>
  31. *> \verbatim
  32. *>
  33. *> SLASV2 computes the singular value decomposition of a 2-by-2
  34. *> triangular matrix
  35. *> [ F G ]
  36. *> [ 0 H ].
  37. *> On return, abs(SSMAX) is the larger singular value, abs(SSMIN) is the
  38. *> smaller singular value, and (CSL,SNL) and (CSR,SNR) are the left and
  39. *> right singular vectors for abs(SSMAX), giving the decomposition
  40. *>
  41. *> [ CSL SNL ] [ F G ] [ CSR -SNR ] = [ SSMAX 0 ]
  42. *> [-SNL CSL ] [ 0 H ] [ SNR CSR ] [ 0 SSMIN ].
  43. *> \endverbatim
  44. *
  45. * Arguments:
  46. * ==========
  47. *
  48. *> \param[in] F
  49. *> \verbatim
  50. *> F is REAL
  51. *> The (1,1) element of the 2-by-2 matrix.
  52. *> \endverbatim
  53. *>
  54. *> \param[in] G
  55. *> \verbatim
  56. *> G is REAL
  57. *> The (1,2) element of the 2-by-2 matrix.
  58. *> \endverbatim
  59. *>
  60. *> \param[in] H
  61. *> \verbatim
  62. *> H is REAL
  63. *> The (2,2) element of the 2-by-2 matrix.
  64. *> \endverbatim
  65. *>
  66. *> \param[out] SSMIN
  67. *> \verbatim
  68. *> SSMIN is REAL
  69. *> abs(SSMIN) is the smaller singular value.
  70. *> \endverbatim
  71. *>
  72. *> \param[out] SSMAX
  73. *> \verbatim
  74. *> SSMAX is REAL
  75. *> abs(SSMAX) is the larger singular value.
  76. *> \endverbatim
  77. *>
  78. *> \param[out] SNL
  79. *> \verbatim
  80. *> SNL is REAL
  81. *> \endverbatim
  82. *>
  83. *> \param[out] CSL
  84. *> \verbatim
  85. *> CSL is REAL
  86. *> The vector (CSL, SNL) is a unit left singular vector for the
  87. *> singular value abs(SSMAX).
  88. *> \endverbatim
  89. *>
  90. *> \param[out] SNR
  91. *> \verbatim
  92. *> SNR is REAL
  93. *> \endverbatim
  94. *>
  95. *> \param[out] CSR
  96. *> \verbatim
  97. *> CSR is REAL
  98. *> The vector (CSR, SNR) is a unit right singular vector for the
  99. *> singular value abs(SSMAX).
  100. *> \endverbatim
  101. *
  102. * Authors:
  103. * ========
  104. *
  105. *> \author Univ. of Tennessee
  106. *> \author Univ. of California Berkeley
  107. *> \author Univ. of Colorado Denver
  108. *> \author NAG Ltd.
  109. *
  110. *> \ingroup OTHERauxiliary
  111. *
  112. *> \par Further Details:
  113. * =====================
  114. *>
  115. *> \verbatim
  116. *>
  117. *> Any input parameter may be aliased with any output parameter.
  118. *>
  119. *> Barring over/underflow and assuming a guard digit in subtraction, all
  120. *> output quantities are correct to within a few units in the last
  121. *> place (ulps).
  122. *>
  123. *> In IEEE arithmetic, the code works correctly if one matrix element is
  124. *> infinite.
  125. *>
  126. *> Overflow will not occur unless the largest singular value itself
  127. *> overflows or is within a few ulps of overflow.
  128. *>
  129. *> Underflow is harmless if underflow is gradual. Otherwise, results
  130. *> may correspond to a matrix modified by perturbations of size near
  131. *> the underflow threshold.
  132. *> \endverbatim
  133. *>
  134. * =====================================================================
  135. SUBROUTINE SLASV2( F, G, H, SSMIN, SSMAX, SNR, CSR, SNL, CSL )
  136. *
  137. * -- LAPACK auxiliary routine --
  138. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  139. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  140. *
  141. * .. Scalar Arguments ..
  142. REAL CSL, CSR, F, G, H, SNL, SNR, SSMAX, SSMIN
  143. * ..
  144. *
  145. * =====================================================================
  146. *
  147. * .. Parameters ..
  148. REAL ZERO
  149. PARAMETER ( ZERO = 0.0E0 )
  150. REAL HALF
  151. PARAMETER ( HALF = 0.5E0 )
  152. REAL ONE
  153. PARAMETER ( ONE = 1.0E0 )
  154. REAL TWO
  155. PARAMETER ( TWO = 2.0E0 )
  156. REAL FOUR
  157. PARAMETER ( FOUR = 4.0E0 )
  158. * ..
  159. * .. Local Scalars ..
  160. LOGICAL GASMAL, SWAP
  161. INTEGER PMAX
  162. REAL A, CLT, CRT, D, FA, FT, GA, GT, HA, HT, L, M,
  163. $ MM, R, S, SLT, SRT, T, TEMP, TSIGN, TT
  164. * ..
  165. * .. Intrinsic Functions ..
  166. INTRINSIC ABS, SIGN, SQRT
  167. * ..
  168. * .. External Functions ..
  169. REAL SLAMCH
  170. EXTERNAL SLAMCH
  171. * ..
  172. * .. Executable Statements ..
  173. *
  174. FT = F
  175. FA = ABS( FT )
  176. HT = H
  177. HA = ABS( H )
  178. *
  179. * PMAX points to the maximum absolute element of matrix
  180. * PMAX = 1 if F largest in absolute values
  181. * PMAX = 2 if G largest in absolute values
  182. * PMAX = 3 if H largest in absolute values
  183. *
  184. PMAX = 1
  185. SWAP = ( HA.GT.FA )
  186. IF( SWAP ) THEN
  187. PMAX = 3
  188. TEMP = FT
  189. FT = HT
  190. HT = TEMP
  191. TEMP = FA
  192. FA = HA
  193. HA = TEMP
  194. *
  195. * Now FA .ge. HA
  196. *
  197. END IF
  198. GT = G
  199. GA = ABS( GT )
  200. IF( GA.EQ.ZERO ) THEN
  201. *
  202. * Diagonal matrix
  203. *
  204. SSMIN = HA
  205. SSMAX = FA
  206. CLT = ONE
  207. CRT = ONE
  208. SLT = ZERO
  209. SRT = ZERO
  210. ELSE
  211. GASMAL = .TRUE.
  212. IF( GA.GT.FA ) THEN
  213. PMAX = 2
  214. IF( ( FA / GA ).LT.SLAMCH( 'EPS' ) ) THEN
  215. *
  216. * Case of very large GA
  217. *
  218. GASMAL = .FALSE.
  219. SSMAX = GA
  220. IF( HA.GT.ONE ) THEN
  221. SSMIN = FA / ( GA / HA )
  222. ELSE
  223. SSMIN = ( FA / GA )*HA
  224. END IF
  225. CLT = ONE
  226. SLT = HT / GT
  227. SRT = ONE
  228. CRT = FT / GT
  229. END IF
  230. END IF
  231. IF( GASMAL ) THEN
  232. *
  233. * Normal case
  234. *
  235. D = FA - HA
  236. IF( D.EQ.FA ) THEN
  237. *
  238. * Copes with infinite F or H
  239. *
  240. L = ONE
  241. ELSE
  242. L = D / FA
  243. END IF
  244. *
  245. * Note that 0 .le. L .le. 1
  246. *
  247. M = GT / FT
  248. *
  249. * Note that abs(M) .le. 1/macheps
  250. *
  251. T = TWO - L
  252. *
  253. * Note that T .ge. 1
  254. *
  255. MM = M*M
  256. TT = T*T
  257. S = SQRT( TT+MM )
  258. *
  259. * Note that 1 .le. S .le. 1 + 1/macheps
  260. *
  261. IF( L.EQ.ZERO ) THEN
  262. R = ABS( M )
  263. ELSE
  264. R = SQRT( L*L+MM )
  265. END IF
  266. *
  267. * Note that 0 .le. R .le. 1 + 1/macheps
  268. *
  269. A = HALF*( S+R )
  270. *
  271. * Note that 1 .le. A .le. 1 + abs(M)
  272. *
  273. SSMIN = HA / A
  274. SSMAX = FA*A
  275. IF( MM.EQ.ZERO ) THEN
  276. *
  277. * Note that M is very tiny
  278. *
  279. IF( L.EQ.ZERO ) THEN
  280. T = SIGN( TWO, FT )*SIGN( ONE, GT )
  281. ELSE
  282. T = GT / SIGN( D, FT ) + M / T
  283. END IF
  284. ELSE
  285. T = ( M / ( S+T )+M / ( R+L ) )*( ONE+A )
  286. END IF
  287. L = SQRT( T*T+FOUR )
  288. CRT = TWO / L
  289. SRT = T / L
  290. CLT = ( CRT+SRT*M ) / A
  291. SLT = ( HT / FT )*SRT / A
  292. END IF
  293. END IF
  294. IF( SWAP ) THEN
  295. CSL = SRT
  296. SNL = CRT
  297. CSR = SLT
  298. SNR = CLT
  299. ELSE
  300. CSL = CLT
  301. SNL = SLT
  302. CSR = CRT
  303. SNR = SRT
  304. END IF
  305. *
  306. * Correct signs of SSMAX and SSMIN
  307. *
  308. IF( PMAX.EQ.1 )
  309. $ TSIGN = SIGN( ONE, CSR )*SIGN( ONE, CSL )*SIGN( ONE, F )
  310. IF( PMAX.EQ.2 )
  311. $ TSIGN = SIGN( ONE, SNR )*SIGN( ONE, CSL )*SIGN( ONE, G )
  312. IF( PMAX.EQ.3 )
  313. $ TSIGN = SIGN( ONE, SNR )*SIGN( ONE, SNL )*SIGN( ONE, H )
  314. SSMAX = SIGN( SSMAX, TSIGN )
  315. SSMIN = SIGN( SSMIN, TSIGN*SIGN( ONE, F )*SIGN( ONE, H ) )
  316. RETURN
  317. *
  318. * End of SLASV2
  319. *
  320. END