LAPACK 3.3.0

zlags2.f

Go to the documentation of this file.
00001       SUBROUTINE ZLAGS2( 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       DOUBLE PRECISION   A1, A3, B1, B3, CSQ, CSU, CSV
00012       COMPLEX*16         A2, B2, SNQ, SNU, SNV
00013 *     ..
00014 *
00015 *  Purpose
00016 *  =======
00017 *
00018 *  ZLAGS2 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) DOUBLE PRECISION
00059 *  A2      (input) COMPLEX*16
00060 *  A3      (input) DOUBLE PRECISION
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) DOUBLE PRECISION
00065 *  B2      (input) COMPLEX*16
00066 *  B3      (input) DOUBLE PRECISION
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) DOUBLE PRECISION
00071 *  SNU     (output) COMPLEX*16
00072 *          The desired unitary matrix U.
00073 *
00074 *  CSV     (output) DOUBLE PRECISION
00075 *  SNV     (output) COMPLEX*16
00076 *          The desired unitary matrix V.
00077 *
00078 *  CSQ     (output) DOUBLE PRECISION
00079 *  SNQ     (output) COMPLEX*16
00080 *          The desired unitary matrix Q.
00081 *
00082 *  =====================================================================
00083 *
00084 *     .. Parameters ..
00085       DOUBLE PRECISION   ZERO, ONE
00086       PARAMETER          ( ZERO = 0.0D+0, ONE = 1.0D+0 )
00087 *     ..
00088 *     .. Local Scalars ..
00089       DOUBLE PRECISION   A, AUA11, AUA12, AUA21, AUA22, AVB12, AVB11, 
00090      $                   AVB21, AVB22, CSL, CSR, D, FB, FC, S1, S2, 
00091      $                   SNL, SNR, UA11R, UA22R, VB11R, VB22R
00092       COMPLEX*16         B, C, D1, R, T, UA11, UA12, UA21, UA22, VB11,
00093      $                   VB12, VB21, VB22
00094 *     ..
00095 *     .. External Subroutines ..
00096       EXTERNAL           DLASV2, ZLARTG
00097 *     ..
00098 *     .. Intrinsic Functions ..
00099       INTRINSIC          ABS, DBLE, DCMPLX, DCONJG, DIMAG
00100 *     ..
00101 *     .. Statement Functions ..
00102       DOUBLE PRECISION   ABS1
00103 *     ..
00104 *     .. Statement Function definitions ..
00105       ABS1( T ) = ABS( DBLE( T ) ) + ABS( DIMAG( 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 DLASV2( 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 ZLARTG( -DCMPLX( VB11R ), DCONJG( VB12 ), CSQ, SNQ,
00154      $                      R )
00155             ELSE IF( ( ABS( VB11R )+ABS1( VB12 ) ).EQ.ZERO ) THEN
00156                CALL ZLARTG( -DCMPLX( UA11R ), DCONJG( UA12 ), CSQ, SNQ,
00157      $                      R )
00158             ELSE IF( AUA12 / ( ABS( UA11R )+ABS1( UA12 ) ).LE.AVB12 /
00159      $               ( ABS( VB11R )+ABS1( VB12 ) ) ) THEN
00160                CALL ZLARTG( -DCMPLX( UA11R ), DCONJG( UA12 ), CSQ, SNQ,
00161      $                      R )
00162             ELSE
00163                CALL ZLARTG( -DCMPLX( VB11R ), DCONJG( 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 = -DCONJG( D1 )*SNL*A1
00178             UA22 = -DCONJG( D1 )*SNL*A2 + CSL*A3
00179 *
00180             VB21 = -DCONJG( D1 )*SNR*B1
00181             VB22 = -DCONJG( 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 ZLARTG( -DCONJG( VB21 ), DCONJG( VB22 ), CSQ, SNQ,
00190      $                      R )
00191             ELSE IF( ( ABS1( VB21 )+ABS( VB22 ) ).EQ.ZERO ) THEN
00192                CALL ZLARTG( -DCONJG( UA21 ), DCONJG( UA22 ), CSQ, SNQ,
00193      $                      R )
00194             ELSE IF( AUA22 / ( ABS1( UA21 )+ABS1( UA22 ) ).LE.AVB22 /
00195      $               ( ABS1( VB21 )+ABS1( VB22 ) ) ) THEN
00196                CALL ZLARTG( -DCONJG( UA21 ), DCONJG( UA22 ), CSQ, SNQ,
00197      $                      R )
00198             ELSE
00199                CALL ZLARTG( -DCONJG( VB21 ), DCONJG( VB22 ), CSQ, SNQ,
00200      $                      R )
00201             END IF
00202 *
00203             CSU = SNL
00204             SNU = D1*CSL
00205             CSV = SNR
00206             SNV = D1*CSR
00207 *
00208          END IF
00209 *
00210       ELSE
00211 *
00212 *        Input matrices A and B are lower triangular matrices
00213 *
00214 *        Form matrix C = A*adj(B) = ( a 0 )
00215 *                                   ( c d )
00216 *
00217          A = A1*B3
00218          D = A3*B1
00219          C = A2*B3 - A3*B2
00220          FC = ABS( C )
00221 *
00222 *        Transform complex 2-by-2 matrix C to real matrix by unitary
00223 *        diagonal matrix diag(d1,1).
00224 *
00225          D1 = ONE
00226          IF( FC.NE.ZERO )
00227      $      D1 = C / FC
00228 *
00229 *        The SVD of real 2 by 2 triangular C
00230 *
00231 *         ( CSL -SNL )*( A 0 )*(  CSR  SNR ) = ( R 0 )
00232 *         ( SNL  CSL ) ( C D ) ( -SNR  CSR )   ( 0 T )
00233 *
00234          CALL DLASV2( A, FC, D, S1, S2, SNR, CSR, SNL, CSL )
00235 *
00236          IF( ABS( CSR ).GE.ABS( SNR ) .OR. ABS( CSL ).GE.ABS( SNL ) )
00237      $        THEN
00238 *
00239 *           Compute the (2,1) and (2,2) elements of U'*A and V'*B,
00240 *           and (2,1) element of |U|'*|A| and |V|'*|B|.
00241 *
00242             UA21 = -D1*SNR*A1 + CSR*A2
00243             UA22R = CSR*A3
00244 *
00245             VB21 = -D1*SNL*B1 + CSL*B2
00246             VB22R = CSL*B3
00247 *
00248             AUA21 = ABS( SNR )*ABS( A1 ) + ABS( CSR )*ABS1( A2 )
00249             AVB21 = ABS( SNL )*ABS( B1 ) + ABS( CSL )*ABS1( B2 )
00250 *
00251 *           zero (2,1) elements of U'*A and V'*B.
00252 *
00253             IF( ( ABS1( UA21 )+ABS( UA22R ) ).EQ.ZERO ) THEN
00254                CALL ZLARTG( DCMPLX( VB22R ), VB21, CSQ, SNQ, R )
00255             ELSE IF( ( ABS1( VB21 )+ABS( VB22R ) ).EQ.ZERO ) THEN
00256                CALL ZLARTG( DCMPLX( UA22R ), UA21, CSQ, SNQ, R )
00257             ELSE IF( AUA21 / ( ABS1( UA21 )+ABS( UA22R ) ).LE.AVB21 /
00258      $               ( ABS1( VB21 )+ABS( VB22R ) ) ) THEN
00259                CALL ZLARTG( DCMPLX( UA22R ), UA21, CSQ, SNQ, R )
00260             ELSE
00261                CALL ZLARTG( DCMPLX( VB22R ), VB21, CSQ, SNQ, R )
00262             END IF
00263 *
00264             CSU = CSR
00265             SNU = -DCONJG( D1 )*SNR
00266             CSV = CSL
00267             SNV = -DCONJG( D1 )*SNL
00268 *
00269          ELSE
00270 *
00271 *           Compute the (1,1) and (1,2) elements of U'*A and V'*B,
00272 *           and (1,1) element of |U|'*|A| and |V|'*|B|.
00273 *
00274             UA11 = CSR*A1 + DCONJG( D1 )*SNR*A2
00275             UA12 = DCONJG( D1 )*SNR*A3
00276 *
00277             VB11 = CSL*B1 + DCONJG( D1 )*SNL*B2
00278             VB12 = DCONJG( D1 )*SNL*B3
00279 *
00280             AUA11 = ABS( CSR )*ABS( A1 ) + ABS( SNR )*ABS1( A2 )
00281             AVB11 = ABS( CSL )*ABS( B1 ) + ABS( SNL )*ABS1( B2 )
00282 *
00283 *           zero (1,1) elements of U'*A and V'*B, and then swap.
00284 *
00285             IF( ( ABS1( UA11 )+ABS1( UA12 ) ).EQ.ZERO ) THEN
00286                CALL ZLARTG( VB12, VB11, CSQ, SNQ, R )
00287             ELSE IF( ( ABS1( VB11 )+ABS1( VB12 ) ).EQ.ZERO ) THEN
00288                CALL ZLARTG( UA12, UA11, CSQ, SNQ, R )
00289             ELSE IF( AUA11 / ( ABS1( UA11 )+ABS1( UA12 ) ).LE.AVB11 /
00290      $               ( ABS1( VB11 )+ABS1( VB12 ) ) ) THEN
00291                CALL ZLARTG( UA12, UA11, CSQ, SNQ, R )
00292             ELSE
00293                CALL ZLARTG( VB12, VB11, CSQ, SNQ, R )
00294             END IF
00295 *
00296             CSU = SNR
00297             SNU = DCONJG( D1 )*CSR
00298             CSV = SNL
00299             SNV = DCONJG( D1 )*CSL
00300 *
00301          END IF
00302 *
00303       END IF
00304 *
00305       RETURN
00306 *
00307 *     End of ZLAGS2
00308 *
00309       END
 All Files Functions