KTH framework for Nek5000 toolboxes; testing version  0.0.1
dlasv2.f
Go to the documentation of this file.
1  SUBROUTINE dlasv2( F, G, H, SSMIN, SSMAX, SNR, CSR, SNL, CSL )
2 *
3 * -- LAPACK auxiliary routine (version 3.0) --
4 * Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
5 * Courant Institute, Argonne National Lab, and Rice University
6 * October 31, 1992
7 *
8 * .. Scalar Arguments ..
9  DOUBLE PRECISION CSL, CSR, F, G, H, SNL, SNR, SSMAX, SSMIN
10 * ..
11 *
12 * Purpose
13 * =======
14 *
15 * DLASV2 computes the singular value decomposition of a 2-by-2
16 * triangular matrix
17 * [ F G ]
18 * [ 0 H ].
19 * On return, abs(SSMAX) is the larger singular value, abs(SSMIN) is the
20 * smaller singular value, and (CSL,SNL) and (CSR,SNR) are the left and
21 * right singular vectors for abs(SSMAX), giving the decomposition
22 *
23 * [ CSL SNL ] [ F G ] [ CSR -SNR ] = [ SSMAX 0 ]
24 * [-SNL CSL ] [ 0 H ] [ SNR CSR ] [ 0 SSMIN ].
25 *
26 * Arguments
27 * =========
28 *
29 * F (input) DOUBLE PRECISION
30 * The (1,1) element of the 2-by-2 matrix.
31 *
32 * G (input) DOUBLE PRECISION
33 * The (1,2) element of the 2-by-2 matrix.
34 *
35 * H (input) DOUBLE PRECISION
36 * The (2,2) element of the 2-by-2 matrix.
37 *
38 * SSMIN (output) DOUBLE PRECISION
39 * abs(SSMIN) is the smaller singular value.
40 *
41 * SSMAX (output) DOUBLE PRECISION
42 * abs(SSMAX) is the larger singular value.
43 *
44 * SNL (output) DOUBLE PRECISION
45 * CSL (output) DOUBLE PRECISION
46 * The vector (CSL, SNL) is a unit left singular vector for the
47 * singular value abs(SSMAX).
48 *
49 * SNR (output) DOUBLE PRECISION
50 * CSR (output) DOUBLE PRECISION
51 * The vector (CSR, SNR) is a unit right singular vector for the
52 * singular value abs(SSMAX).
53 *
54 * Further Details
55 * ===============
56 *
57 * Any input parameter may be aliased with any output parameter.
58 *
59 * Barring over/underflow and assuming a guard digit in subtraction, all
60 * output quantities are correct to within a few units in the last
61 * place (ulps).
62 *
63 * In IEEE arithmetic, the code works correctly if one matrix element is
64 * infinite.
65 *
66 * Overflow will not occur unless the largest singular value itself
67 * overflows or is within a few ulps of overflow. (On machines with
68 * partial overflow, like the Cray, overflow may occur if the largest
69 * singular value is within a factor of 2 of overflow.)
70 *
71 * Underflow is harmless if underflow is gradual. Otherwise, results
72 * may correspond to a matrix modified by perturbations of size near
73 * the underflow threshold.
74 *
75 * =====================================================================
76 *
77 * .. Parameters ..
78  DOUBLE PRECISION ZERO
79  parameter( zero = 0.0d0 )
80  DOUBLE PRECISION HALF
81  parameter( half = 0.5d0 )
82  DOUBLE PRECISION ONE
83  parameter( one = 1.0d0 )
84  DOUBLE PRECISION TWO
85  parameter( two = 2.0d0 )
86  DOUBLE PRECISION FOUR
87  parameter( four = 4.0d0 )
88 * ..
89 * .. Local Scalars ..
90  LOGICAL GASMAL, SWAP
91  INTEGER PMAX
92  DOUBLE PRECISION A, CLT, CRT, D, FA, FT, GA, GT, HA, HT, L, M,
93  $ MM, R, S, SLT, SRT, T, TEMP, TSIGN, TT
94 * ..
95 * .. Intrinsic Functions ..
96  INTRINSIC abs, sign, sqrt
97 * ..
98 * .. External Functions ..
99  DOUBLE PRECISION DLAMCH
100  EXTERNAL dlamch
101 * ..
102 * .. Executable Statements ..
103 *
104  ft = f
105  fa = abs( ft )
106  ht = h
107  ha = abs( h )
108 *
109 * PMAX points to the maximum absolute element of matrix
110 * PMAX = 1 if F largest in absolute values
111 * PMAX = 2 if G largest in absolute values
112 * PMAX = 3 if H largest in absolute values
113 *
114  pmax = 1
115  swap = ( ha.GT.fa )
116  IF( swap ) THEN
117  pmax = 3
118  temp = ft
119  ft = ht
120  ht = temp
121  temp = fa
122  fa = ha
123  ha = temp
124 *
125 * Now FA .ge. HA
126 *
127  END IF
128  gt = g
129  ga = abs( gt )
130  IF( ga.EQ.zero ) THEN
131 *
132 * Diagonal matrix
133 *
134  ssmin = ha
135  ssmax = fa
136  clt = one
137  crt = one
138  slt = zero
139  srt = zero
140  ELSE
141  gasmal = .true.
142  IF( ga.GT.fa ) THEN
143  pmax = 2
144  IF( ( fa / ga ).LT.dlamch( 'EPS' ) ) THEN
145 *
146 * Case of very large GA
147 *
148  gasmal = .false.
149  ssmax = ga
150  IF( ha.GT.one ) THEN
151  ssmin = fa / ( ga / ha )
152  ELSE
153  ssmin = ( fa / ga )*ha
154  END IF
155  clt = one
156  slt = ht / gt
157  srt = one
158  crt = ft / gt
159  END IF
160  END IF
161  IF( gasmal ) THEN
162 *
163 * Normal case
164 *
165  d = fa - ha
166  IF( d.EQ.fa ) THEN
167 *
168 * Copes with infinite F or H
169 *
170  l = one
171  ELSE
172  l = d / fa
173  END IF
174 *
175 * Note that 0 .le. L .le. 1
176 *
177  m = gt / ft
178 *
179 * Note that abs(M) .le. 1/macheps
180 *
181  t = two - l
182 *
183 * Note that T .ge. 1
184 *
185  mm = m*m
186  tt = t*t
187  s = sqrt( tt+mm )
188 *
189 * Note that 1 .le. S .le. 1 + 1/macheps
190 *
191  IF( l.EQ.zero ) THEN
192  r = abs( m )
193  ELSE
194  r = sqrt( l*l+mm )
195  END IF
196 *
197 * Note that 0 .le. R .le. 1 + 1/macheps
198 *
199  a = half*( s+r )
200 *
201 * Note that 1 .le. A .le. 1 + abs(M)
202 *
203  ssmin = ha / a
204  ssmax = fa*a
205  IF( mm.EQ.zero ) THEN
206 *
207 * Note that M is very tiny
208 *
209  IF( l.EQ.zero ) THEN
210  t = sign( two, ft )*sign( one, gt )
211  ELSE
212  t = gt / sign( d, ft ) + m / t
213  END IF
214  ELSE
215  t = ( m / ( s+t )+m / ( r+l ) )*( one+a )
216  END IF
217  l = sqrt( t*t+four )
218  crt = two / l
219  srt = t / l
220  clt = ( crt+srt*m ) / a
221  slt = ( ht / ft )*srt / a
222  END IF
223  END IF
224  IF( swap ) THEN
225  csl = srt
226  snl = crt
227  csr = slt
228  snr = clt
229  ELSE
230  csl = clt
231  snl = slt
232  csr = crt
233  snr = srt
234  END IF
235 *
236 * Correct signs of SSMAX and SSMIN
237 *
238  IF( pmax.EQ.1 )
239  $ tsign = sign( one, csr )*sign( one, csl )*sign( one, f )
240  IF( pmax.EQ.2 )
241  $ tsign = sign( one, snr )*sign( one, csl )*sign( one, g )
242  IF( pmax.EQ.3 )
243  $ tsign = sign( one, snr )*sign( one, snl )*sign( one, h )
244  ssmax = sign( ssmax, tsign )
245  ssmin = sign( ssmin, tsign*sign( one, f )*sign( one, h ) )
246  RETURN
247 *
248 * End of DLASV2
249 *
250  END
subroutine dlasv2(F, G, H, SSMIN, SSMAX, SNR, CSR, SNL, CSL)
Definition: dlasv2.f:2