KTH framework for Nek5000 toolboxes; testing version  0.0.1
dlanv2.f
Go to the documentation of this file.
1  SUBROUTINE dlanv2( A, B, C, D, RT1R, RT1I, RT2R, RT2I, CS, SN )
2 *
3 * -- LAPACK driver routine (version 3.0) --
4 * Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
5 * Courant Institute, Argonne National Lab, and Rice University
6 * June 30, 1999
7 *
8 * .. Scalar Arguments ..
9  DOUBLE PRECISION A, B, C, CS, D, RT1I, RT1R, RT2I, RT2R, SN
10 * ..
11 *
12 * Purpose
13 * =======
14 *
15 * DLANV2 computes the Schur factorization of a real 2-by-2 nonsymmetric
16 * matrix in standard form:
17 *
18 * [ A B ] = [ CS -SN ] [ AA BB ] [ CS SN ]
19 * [ C D ] [ SN CS ] [ CC DD ] [-SN CS ]
20 *
21 * where either
22 * 1) CC = 0 so that AA and DD are real eigenvalues of the matrix, or
23 * 2) AA = DD and BB*CC < 0, so that AA + or - sqrt(BB*CC) are complex
24 * conjugate eigenvalues.
25 *
26 * Arguments
27 * =========
28 *
29 * A (input/output) DOUBLE PRECISION
30 * B (input/output) DOUBLE PRECISION
31 * C (input/output) DOUBLE PRECISION
32 * D (input/output) DOUBLE PRECISION
33 * On entry, the elements of the input matrix.
34 * On exit, they are overwritten by the elements of the
35 * standardised Schur form.
36 *
37 * RT1R (output) DOUBLE PRECISION
38 * RT1I (output) DOUBLE PRECISION
39 * RT2R (output) DOUBLE PRECISION
40 * RT2I (output) DOUBLE PRECISION
41 * The real and imaginary parts of the eigenvalues. If the
42 * eigenvalues are a complex conjugate pair, RT1I > 0.
43 *
44 * CS (output) DOUBLE PRECISION
45 * SN (output) DOUBLE PRECISION
46 * Parameters of the rotation matrix.
47 *
48 * Further Details
49 * ===============
50 *
51 * Modified by V. Sima, Research Institute for Informatics, Bucharest,
52 * Romania, to reduce the risk of cancellation errors,
53 * when computing real eigenvalues, and to ensure, if possible, that
54 * abs(RT1R) >= abs(RT2R).
55 *
56 * =====================================================================
57 *
58 * .. Parameters ..
59  DOUBLE PRECISION ZERO, HALF, ONE
60  parameter( zero = 0.0d+0, half = 0.5d+0, one = 1.0d+0 )
61  DOUBLE PRECISION MULTPL
62  parameter( multpl = 4.0d+0 )
63 * ..
64 * .. Local Scalars ..
65  DOUBLE PRECISION AA, BB, BCMAX, BCMIS, CC, CS1, DD, EPS, P, SAB,
66  $ SAC, SCALE, SIGMA, SN1, TAU, TEMP, Z
67 * ..
68 * .. External Functions ..
69  DOUBLE PRECISION DLAMCH, DLAPY2
70  EXTERNAL dlamch, dlapy2
71 * ..
72 * .. Intrinsic Functions ..
73  INTRINSIC abs, max, min, sign, sqrt
74 * ..
75 * .. Executable Statements ..
76 *
77  eps = dlamch( 'P' )
78  IF( c.EQ.zero ) THEN
79  cs = one
80  sn = zero
81  GO TO 10
82 *
83  ELSE IF( b.EQ.zero ) THEN
84 *
85 * Swap rows and columns
86 *
87  cs = zero
88  sn = one
89  temp = d
90  d = a
91  a = temp
92  b = -c
93  c = zero
94  GO TO 10
95  ELSE IF( ( a-d ).EQ.zero .AND. sign( one, b ).NE.sign( one, c ) )
96  $ THEN
97  cs = one
98  sn = zero
99  GO TO 10
100  ELSE
101 *
102  temp = a - d
103  p = half*temp
104  bcmax = max( abs( b ), abs( c ) )
105  bcmis = min( abs( b ), abs( c ) )*sign( one, b )*sign( one, c )
106  scale = max( abs( p ), bcmax )
107  z = ( p / scale )*p + ( bcmax / scale )*bcmis
108 *
109 * If Z is of the order of the machine accuracy, postpone the
110 * decision on the nature of eigenvalues
111 *
112  IF( z.GE.multpl*eps ) THEN
113 *
114 * Real eigenvalues. Compute A and D.
115 *
116  z = p + sign( sqrt( scale )*sqrt( z ), p )
117  a = d + z
118  d = d - ( bcmax / z )*bcmis
119 *
120 * Compute B and the rotation matrix
121 *
122  tau = dlapy2( c, z )
123  cs = z / tau
124  sn = c / tau
125  b = b - c
126  c = zero
127  ELSE
128 *
129 * Complex eigenvalues, or real (almost) equal eigenvalues.
130 * Make diagonal elements equal.
131 *
132  sigma = b + c
133  tau = dlapy2( sigma, temp )
134  cs = sqrt( half*( one+abs( sigma ) / tau ) )
135  sn = -( p / ( tau*cs ) )*sign( one, sigma )
136 *
137 * Compute [ AA BB ] = [ A B ] [ CS -SN ]
138 * [ CC DD ] [ C D ] [ SN CS ]
139 *
140  aa = a*cs + b*sn
141  bb = -a*sn + b*cs
142  cc = c*cs + d*sn
143  dd = -c*sn + d*cs
144 *
145 * Compute [ A B ] = [ CS SN ] [ AA BB ]
146 * [ C D ] [-SN CS ] [ CC DD ]
147 *
148  a = aa*cs + cc*sn
149  b = bb*cs + dd*sn
150  c = -aa*sn + cc*cs
151  d = -bb*sn + dd*cs
152 *
153  temp = half*( a+d )
154  a = temp
155  d = temp
156 *
157  IF( c.NE.zero ) THEN
158  IF( b.NE.zero ) THEN
159  IF( sign( one, b ).EQ.sign( one, c ) ) THEN
160 *
161 * Real eigenvalues: reduce to upper triangular form
162 *
163  sab = sqrt( abs( b ) )
164  sac = sqrt( abs( c ) )
165  p = sign( sab*sac, c )
166  tau = one / sqrt( abs( b+c ) )
167  a = temp + p
168  d = temp - p
169  b = b - c
170  c = zero
171  cs1 = sab*tau
172  sn1 = sac*tau
173  temp = cs*cs1 - sn*sn1
174  sn = cs*sn1 + sn*cs1
175  cs = temp
176  END IF
177  ELSE
178  b = -c
179  c = zero
180  temp = cs
181  cs = -sn
182  sn = temp
183  END IF
184  END IF
185  END IF
186 *
187  END IF
188 *
189  10 CONTINUE
190 *
191 * Store eigenvalues in (RT1R,RT1I) and (RT2R,RT2I).
192 *
193  rt1r = a
194  rt2r = d
195  IF( c.EQ.zero ) THEN
196  rt1i = zero
197  rt2i = zero
198  ELSE
199  rt1i = sqrt( abs( b ) )*sqrt( abs( c ) )
200  rt2i = -rt1i
201  END IF
202  RETURN
203 *
204 * End of DLANV2
205 *
206  END
subroutine dlanv2(A, B, C, D, RT1R, RT1I, RT2R, RT2I, CS, SN)
Definition: dlanv2.f:2