LAPACK 3.3.0
|
00001 SUBROUTINE CLAGS2( UPPER, A1, A2, A3, B1, B2, B3, CSU, SNU, CSV, 00002 $ SNV, CSQ, SNQ ) 00003 * 00004 * -- LAPACK auxiliary routine (version 3.2) -- 00005 * -- LAPACK is a software package provided by Univ. of Tennessee, -- 00006 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- 00007 * November 2006 00008 * 00009 * .. Scalar Arguments .. 00010 LOGICAL UPPER 00011 REAL A1, A3, B1, B3, CSQ, CSU, CSV 00012 COMPLEX A2, B2, SNQ, SNU, SNV 00013 * .. 00014 * 00015 * Purpose 00016 * ======= 00017 * 00018 * CLAGS2 computes 2-by-2 unitary matrices U, V and Q, such 00019 * that if ( UPPER ) then 00020 * 00021 * U'*A*Q = U'*( A1 A2 )*Q = ( x 0 ) 00022 * ( 0 A3 ) ( x x ) 00023 * and 00024 * V'*B*Q = V'*( B1 B2 )*Q = ( x 0 ) 00025 * ( 0 B3 ) ( x x ) 00026 * 00027 * or if ( .NOT.UPPER ) then 00028 * 00029 * U'*A*Q = U'*( A1 0 )*Q = ( x x ) 00030 * ( A2 A3 ) ( 0 x ) 00031 * and 00032 * V'*B*Q = V'*( B1 0 )*Q = ( x x ) 00033 * ( B2 B3 ) ( 0 x ) 00034 * where 00035 * 00036 * U = ( CSU SNU ), V = ( CSV SNV ), 00037 * ( -CONJG(SNU) CSU ) ( -CONJG(SNV) CSV ) 00038 * 00039 * Q = ( CSQ SNQ ) 00040 * ( -CONJG(SNQ) CSQ ) 00041 * 00042 * Z' denotes the conjugate transpose of Z. 00043 * 00044 * The rows of the transformed A and B are parallel. Moreover, if the 00045 * input 2-by-2 matrix A is not zero, then the transformed (1,1) entry 00046 * of A is not zero. If the input matrices A and B are both not zero, 00047 * then the transformed (2,2) element of B is not zero, except when the 00048 * first rows of input A and B are parallel and the second rows are 00049 * zero. 00050 * 00051 * Arguments 00052 * ========= 00053 * 00054 * UPPER (input) LOGICAL 00055 * = .TRUE.: the input matrices A and B are upper triangular. 00056 * = .FALSE.: the input matrices A and B are lower triangular. 00057 * 00058 * A1 (input) REAL 00059 * A2 (input) COMPLEX 00060 * A3 (input) REAL 00061 * On entry, A1, A2 and A3 are elements of the input 2-by-2 00062 * upper (lower) triangular matrix A. 00063 * 00064 * B1 (input) REAL 00065 * B2 (input) COMPLEX 00066 * B3 (input) REAL 00067 * On entry, B1, B2 and B3 are elements of the input 2-by-2 00068 * upper (lower) triangular matrix B. 00069 * 00070 * CSU (output) REAL 00071 * SNU (output) COMPLEX 00072 * The desired unitary matrix U. 00073 * 00074 * CSV (output) REAL 00075 * SNV (output) COMPLEX 00076 * The desired unitary matrix V. 00077 * 00078 * CSQ (output) REAL 00079 * SNQ (output) COMPLEX 00080 * The desired unitary matrix Q. 00081 * 00082 * ===================================================================== 00083 * 00084 * .. Parameters .. 00085 REAL ZERO, ONE 00086 PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 ) 00087 * .. 00088 * .. Local Scalars .. 00089 REAL A, AUA11, AUA12, AUA21, AUA22, AVB11, AVB12, 00090 $ AVB21, AVB22, CSL, CSR, D, FB, FC, S1, S2, SNL, 00091 $ SNR, UA11R, UA22R, VB11R, VB22R 00092 COMPLEX B, C, D1, R, T, UA11, UA12, UA21, UA22, VB11, 00093 $ VB12, VB21, VB22 00094 * .. 00095 * .. External Subroutines .. 00096 EXTERNAL CLARTG, SLASV2 00097 * .. 00098 * .. Intrinsic Functions .. 00099 INTRINSIC ABS, AIMAG, CMPLX, CONJG, REAL 00100 * .. 00101 * .. Statement Functions .. 00102 REAL ABS1 00103 * .. 00104 * .. Statement Function definitions .. 00105 ABS1( T ) = ABS( REAL( T ) ) + ABS( AIMAG( T ) ) 00106 * .. 00107 * .. Executable Statements .. 00108 * 00109 IF( UPPER ) THEN 00110 * 00111 * Input matrices A and B are upper triangular matrices 00112 * 00113 * Form matrix C = A*adj(B) = ( a b ) 00114 * ( 0 d ) 00115 * 00116 A = A1*B3 00117 D = A3*B1 00118 B = A2*B1 - A1*B2 00119 FB = ABS( B ) 00120 * 00121 * Transform complex 2-by-2 matrix C to real matrix by unitary 00122 * diagonal matrix diag(1,D1). 00123 * 00124 D1 = ONE 00125 IF( FB.NE.ZERO ) 00126 $ D1 = B / FB 00127 * 00128 * The SVD of real 2 by 2 triangular C 00129 * 00130 * ( CSL -SNL )*( A B )*( CSR SNR ) = ( R 0 ) 00131 * ( SNL CSL ) ( 0 D ) ( -SNR CSR ) ( 0 T ) 00132 * 00133 CALL SLASV2( A, FB, D, S1, S2, SNR, CSR, SNL, CSL ) 00134 * 00135 IF( ABS( CSL ).GE.ABS( SNL ) .OR. ABS( CSR ).GE.ABS( SNR ) ) 00136 $ THEN 00137 * 00138 * Compute the (1,1) and (1,2) elements of U'*A and V'*B, 00139 * and (1,2) element of |U|'*|A| and |V|'*|B|. 00140 * 00141 UA11R = CSL*A1 00142 UA12 = CSL*A2 + D1*SNL*A3 00143 * 00144 VB11R = CSR*B1 00145 VB12 = CSR*B2 + D1*SNR*B3 00146 * 00147 AUA12 = ABS( CSL )*ABS1( A2 ) + ABS( SNL )*ABS( A3 ) 00148 AVB12 = ABS( CSR )*ABS1( B2 ) + ABS( SNR )*ABS( B3 ) 00149 * 00150 * zero (1,2) elements of U'*A and V'*B 00151 * 00152 IF( ( ABS( UA11R )+ABS1( UA12 ) ).EQ.ZERO ) THEN 00153 CALL CLARTG( -CMPLX( VB11R ), CONJG( VB12 ), CSQ, SNQ, 00154 $ R ) 00155 ELSE IF( ( ABS( VB11R )+ABS1( VB12 ) ).EQ.ZERO ) THEN 00156 CALL CLARTG( -CMPLX( UA11R ), CONJG( UA12 ), CSQ, SNQ, 00157 $ R ) 00158 ELSE IF( AUA12 / ( ABS( UA11R )+ABS1( UA12 ) ).LE.AVB12 / 00159 $ ( ABS( VB11R )+ABS1( VB12 ) ) ) THEN 00160 CALL CLARTG( -CMPLX( UA11R ), CONJG( UA12 ), CSQ, SNQ, 00161 $ R ) 00162 ELSE 00163 CALL CLARTG( -CMPLX( VB11R ), CONJG( VB12 ), CSQ, SNQ, 00164 $ R ) 00165 END IF 00166 * 00167 CSU = CSL 00168 SNU = -D1*SNL 00169 CSV = CSR 00170 SNV = -D1*SNR 00171 * 00172 ELSE 00173 * 00174 * Compute the (2,1) and (2,2) elements of U'*A and V'*B, 00175 * and (2,2) element of |U|'*|A| and |V|'*|B|. 00176 * 00177 UA21 = -CONJG( D1 )*SNL*A1 00178 UA22 = -CONJG( D1 )*SNL*A2 + CSL*A3 00179 * 00180 VB21 = -CONJG( D1 )*SNR*B1 00181 VB22 = -CONJG( D1 )*SNR*B2 + CSR*B3 00182 * 00183 AUA22 = ABS( SNL )*ABS1( A2 ) + ABS( CSL )*ABS( A3 ) 00184 AVB22 = ABS( SNR )*ABS1( B2 ) + ABS( CSR )*ABS( B3 ) 00185 * 00186 * zero (2,2) elements of U'*A and V'*B, and then swap. 00187 * 00188 IF( ( ABS1( UA21 )+ABS1( UA22 ) ).EQ.ZERO ) THEN 00189 CALL CLARTG( -CONJG( VB21 ), CONJG( VB22 ), CSQ, SNQ, R ) 00190 ELSE IF( ( ABS1( VB21 )+ABS( VB22 ) ).EQ.ZERO ) THEN 00191 CALL CLARTG( -CONJG( UA21 ), CONJG( UA22 ), CSQ, SNQ, R ) 00192 ELSE IF( AUA22 / ( ABS1( UA21 )+ABS1( UA22 ) ).LE.AVB22 / 00193 $ ( ABS1( VB21 )+ABS1( VB22 ) ) ) THEN 00194 CALL CLARTG( -CONJG( UA21 ), CONJG( UA22 ), CSQ, SNQ, R ) 00195 ELSE 00196 CALL CLARTG( -CONJG( VB21 ), CONJG( VB22 ), CSQ, SNQ, R ) 00197 END IF 00198 * 00199 CSU = SNL 00200 SNU = D1*CSL 00201 CSV = SNR 00202 SNV = D1*CSR 00203 * 00204 END IF 00205 * 00206 ELSE 00207 * 00208 * Input matrices A and B are lower triangular matrices 00209 * 00210 * Form matrix C = A*adj(B) = ( a 0 ) 00211 * ( c d ) 00212 * 00213 A = A1*B3 00214 D = A3*B1 00215 C = A2*B3 - A3*B2 00216 FC = ABS( C ) 00217 * 00218 * Transform complex 2-by-2 matrix C to real matrix by unitary 00219 * diagonal matrix diag(d1,1). 00220 * 00221 D1 = ONE 00222 IF( FC.NE.ZERO ) 00223 $ D1 = C / FC 00224 * 00225 * The SVD of real 2 by 2 triangular C 00226 * 00227 * ( CSL -SNL )*( A 0 )*( CSR SNR ) = ( R 0 ) 00228 * ( SNL CSL ) ( C D ) ( -SNR CSR ) ( 0 T ) 00229 * 00230 CALL SLASV2( A, FC, D, S1, S2, SNR, CSR, SNL, CSL ) 00231 * 00232 IF( ABS( CSR ).GE.ABS( SNR ) .OR. ABS( CSL ).GE.ABS( SNL ) ) 00233 $ THEN 00234 * 00235 * Compute the (2,1) and (2,2) elements of U'*A and V'*B, 00236 * and (2,1) element of |U|'*|A| and |V|'*|B|. 00237 * 00238 UA21 = -D1*SNR*A1 + CSR*A2 00239 UA22R = CSR*A3 00240 * 00241 VB21 = -D1*SNL*B1 + CSL*B2 00242 VB22R = CSL*B3 00243 * 00244 AUA21 = ABS( SNR )*ABS( A1 ) + ABS( CSR )*ABS1( A2 ) 00245 AVB21 = ABS( SNL )*ABS( B1 ) + ABS( CSL )*ABS1( B2 ) 00246 * 00247 * zero (2,1) elements of U'*A and V'*B. 00248 * 00249 IF( ( ABS1( UA21 )+ABS( UA22R ) ).EQ.ZERO ) THEN 00250 CALL CLARTG( CMPLX( VB22R ), VB21, CSQ, SNQ, R ) 00251 ELSE IF( ( ABS1( VB21 )+ABS( VB22R ) ).EQ.ZERO ) THEN 00252 CALL CLARTG( CMPLX( UA22R ), UA21, CSQ, SNQ, R ) 00253 ELSE IF( AUA21 / ( ABS1( UA21 )+ABS( UA22R ) ).LE.AVB21 / 00254 $ ( ABS1( VB21 )+ABS( VB22R ) ) ) THEN 00255 CALL CLARTG( CMPLX( UA22R ), UA21, CSQ, SNQ, R ) 00256 ELSE 00257 CALL CLARTG( CMPLX( VB22R ), VB21, CSQ, SNQ, R ) 00258 END IF 00259 * 00260 CSU = CSR 00261 SNU = -CONJG( D1 )*SNR 00262 CSV = CSL 00263 SNV = -CONJG( D1 )*SNL 00264 * 00265 ELSE 00266 * 00267 * Compute the (1,1) and (1,2) elements of U'*A and V'*B, 00268 * and (1,1) element of |U|'*|A| and |V|'*|B|. 00269 * 00270 UA11 = CSR*A1 + CONJG( D1 )*SNR*A2 00271 UA12 = CONJG( D1 )*SNR*A3 00272 * 00273 VB11 = CSL*B1 + CONJG( D1 )*SNL*B2 00274 VB12 = CONJG( D1 )*SNL*B3 00275 * 00276 AUA11 = ABS( CSR )*ABS( A1 ) + ABS( SNR )*ABS1( A2 ) 00277 AVB11 = ABS( CSL )*ABS( B1 ) + ABS( SNL )*ABS1( B2 ) 00278 * 00279 * zero (1,1) elements of U'*A and V'*B, and then swap. 00280 * 00281 IF( ( ABS1( UA11 )+ABS1( UA12 ) ).EQ.ZERO ) THEN 00282 CALL CLARTG( VB12, VB11, CSQ, SNQ, R ) 00283 ELSE IF( ( ABS1( VB11 )+ABS1( VB12 ) ).EQ.ZERO ) THEN 00284 CALL CLARTG( UA12, UA11, CSQ, SNQ, R ) 00285 ELSE IF( AUA11 / ( ABS1( UA11 )+ABS1( UA12 ) ).LE.AVB11 / 00286 $ ( ABS1( VB11 )+ABS1( VB12 ) ) ) THEN 00287 CALL CLARTG( UA12, UA11, CSQ, SNQ, R ) 00288 ELSE 00289 CALL CLARTG( VB12, VB11, CSQ, SNQ, R ) 00290 END IF 00291 * 00292 CSU = SNR 00293 SNU = CONJG( D1 )*CSR 00294 CSV = SNL 00295 SNV = CONJG( D1 )*CSL 00296 * 00297 END IF 00298 * 00299 END IF 00300 * 00301 RETURN 00302 * 00303 * End of CLAGS2 00304 * 00305 END