LAPACK 3.3.1
Linear Algebra PACKage

sggsvd.f

Go to the documentation of this file.
00001       SUBROUTINE SGGSVD( JOBU, JOBV, JOBQ, M, N, P, K, L, A, LDA, B,
00002      $                   LDB, ALPHA, BETA, U, LDU, V, LDV, Q, LDQ, WORK,
00003      $                   IWORK, INFO )
00004 *
00005 *  -- LAPACK driver routine (version 3.3.1) --
00006 *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
00007 *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
00008 *  -- April 2011                                                      --
00009 *
00010 *     .. Scalar Arguments ..
00011       CHARACTER          JOBQ, JOBU, JOBV
00012       INTEGER            INFO, K, L, LDA, LDB, LDQ, LDU, LDV, M, N, P
00013 *     ..
00014 *     .. Array Arguments ..
00015       INTEGER            IWORK( * )
00016       REAL               A( LDA, * ), ALPHA( * ), B( LDB, * ),
00017      $                   BETA( * ), Q( LDQ, * ), U( LDU, * ),
00018      $                   V( LDV, * ), WORK( * )
00019 *     ..
00020 *
00021 *  Purpose
00022 *  =======
00023 *
00024 *  SGGSVD computes the generalized singular value decomposition (GSVD)
00025 *  of an M-by-N real matrix A and P-by-N real matrix B:
00026 *
00027 *        U**T*A*Q = D1*( 0 R ),    V**T*B*Q = D2*( 0 R )
00028 *
00029 *  where U, V and Q are orthogonal matrices.
00030 *  Let K+L = the effective numerical rank of the matrix (A**T,B**T)**T,
00031 *  then R is a K+L-by-K+L nonsingular upper triangular matrix, D1 and
00032 *  D2 are M-by-(K+L) and P-by-(K+L) "diagonal" matrices and of the
00033 *  following structures, respectively:
00034 *
00035 *  If M-K-L >= 0,
00036 *
00037 *                      K  L
00038 *         D1 =     K ( I  0 )
00039 *                  L ( 0  C )
00040 *              M-K-L ( 0  0 )
00041 *
00042 *                    K  L
00043 *         D2 =   L ( 0  S )
00044 *              P-L ( 0  0 )
00045 *
00046 *                  N-K-L  K    L
00047 *    ( 0 R ) = K (  0   R11  R12 )
00048 *              L (  0    0   R22 )
00049 *
00050 *  where
00051 *
00052 *    C = diag( ALPHA(K+1), ... , ALPHA(K+L) ),
00053 *    S = diag( BETA(K+1),  ... , BETA(K+L) ),
00054 *    C**2 + S**2 = I.
00055 *
00056 *    R is stored in A(1:K+L,N-K-L+1:N) on exit.
00057 *
00058 *  If M-K-L < 0,
00059 *
00060 *                    K M-K K+L-M
00061 *         D1 =   K ( I  0    0   )
00062 *              M-K ( 0  C    0   )
00063 *
00064 *                      K M-K K+L-M
00065 *         D2 =   M-K ( 0  S    0  )
00066 *              K+L-M ( 0  0    I  )
00067 *                P-L ( 0  0    0  )
00068 *
00069 *                     N-K-L  K   M-K  K+L-M
00070 *    ( 0 R ) =     K ( 0    R11  R12  R13  )
00071 *                M-K ( 0     0   R22  R23  )
00072 *              K+L-M ( 0     0    0   R33  )
00073 *
00074 *  where
00075 *
00076 *    C = diag( ALPHA(K+1), ... , ALPHA(M) ),
00077 *    S = diag( BETA(K+1),  ... , BETA(M) ),
00078 *    C**2 + S**2 = I.
00079 *
00080 *    (R11 R12 R13 ) is stored in A(1:M, N-K-L+1:N), and R33 is stored
00081 *    ( 0  R22 R23 )
00082 *    in B(M-K+1:L,N+M-K-L+1:N) on exit.
00083 *
00084 *  The routine computes C, S, R, and optionally the orthogonal
00085 *  transformation matrices U, V and Q.
00086 *
00087 *  In particular, if B is an N-by-N nonsingular matrix, then the GSVD of
00088 *  A and B implicitly gives the SVD of A*inv(B):
00089 *                       A*inv(B) = U*(D1*inv(D2))*V**T.
00090 *  If ( A**T,B**T)**T  has orthonormal columns, then the GSVD of A and B is
00091 *  also equal to the CS decomposition of A and B. Furthermore, the GSVD
00092 *  can be used to derive the solution of the eigenvalue problem:
00093 *                       A**T*A x = lambda* B**T*B x.
00094 *  In some literature, the GSVD of A and B is presented in the form
00095 *                   U**T*A*X = ( 0 D1 ),   V**T*B*X = ( 0 D2 )
00096 *  where U and V are orthogonal and X is nonsingular, D1 and D2 are
00097 *  ``diagonal''.  The former GSVD form can be converted to the latter
00098 *  form by taking the nonsingular matrix X as
00099 *
00100 *                       X = Q*( I   0    )
00101 *                             ( 0 inv(R) ).
00102 *
00103 *  Arguments
00104 *  =========
00105 *
00106 *  JOBU    (input) CHARACTER*1
00107 *          = 'U':  Orthogonal matrix U is computed;
00108 *          = 'N':  U is not computed.
00109 *
00110 *  JOBV    (input) CHARACTER*1
00111 *          = 'V':  Orthogonal matrix V is computed;
00112 *          = 'N':  V is not computed.
00113 *
00114 *  JOBQ    (input) CHARACTER*1
00115 *          = 'Q':  Orthogonal matrix Q is computed;
00116 *          = 'N':  Q is not computed.
00117 *
00118 *  M       (input) INTEGER
00119 *          The number of rows of the matrix A.  M >= 0.
00120 *
00121 *  N       (input) INTEGER
00122 *          The number of columns of the matrices A and B.  N >= 0.
00123 *
00124 *  P       (input) INTEGER
00125 *          The number of rows of the matrix B.  P >= 0.
00126 *
00127 *  K       (output) INTEGER
00128 *  L       (output) INTEGER
00129 *          On exit, K and L specify the dimension of the subblocks
00130 *          described in the Purpose section.
00131 *          K + L = effective numerical rank of (A**T,B**T)**T.
00132 *
00133 *  A       (input/output) REAL array, dimension (LDA,N)
00134 *          On entry, the M-by-N matrix A.
00135 *          On exit, A contains the triangular matrix R, or part of R.
00136 *          See Purpose for details.
00137 *
00138 *  LDA     (input) INTEGER
00139 *          The leading dimension of the array A. LDA >= max(1,M).
00140 *
00141 *  B       (input/output) REAL array, dimension (LDB,N)
00142 *          On entry, the P-by-N matrix B.
00143 *          On exit, B contains the triangular matrix R if M-K-L < 0.
00144 *          See Purpose for details.
00145 *
00146 *  LDB     (input) INTEGER
00147 *          The leading dimension of the array B. LDB >= max(1,P).
00148 *
00149 *  ALPHA   (output) REAL array, dimension (N)
00150 *  BETA    (output) REAL array, dimension (N)
00151 *          On exit, ALPHA and BETA contain the generalized singular
00152 *          value pairs of A and B;
00153 *            ALPHA(1:K) = 1,
00154 *            BETA(1:K)  = 0,
00155 *          and if M-K-L >= 0,
00156 *            ALPHA(K+1:K+L) = C,
00157 *            BETA(K+1:K+L)  = S,
00158 *          or if M-K-L < 0,
00159 *            ALPHA(K+1:M)=C, ALPHA(M+1:K+L)=0
00160 *            BETA(K+1:M) =S, BETA(M+1:K+L) =1
00161 *          and
00162 *            ALPHA(K+L+1:N) = 0
00163 *            BETA(K+L+1:N)  = 0
00164 *
00165 *  U       (output) REAL array, dimension (LDU,M)
00166 *          If JOBU = 'U', U contains the M-by-M orthogonal matrix U.
00167 *          If JOBU = 'N', U is not referenced.
00168 *
00169 *  LDU     (input) INTEGER
00170 *          The leading dimension of the array U. LDU >= max(1,M) if
00171 *          JOBU = 'U'; LDU >= 1 otherwise.
00172 *
00173 *  V       (output) REAL array, dimension (LDV,P)
00174 *          If JOBV = 'V', V contains the P-by-P orthogonal matrix V.
00175 *          If JOBV = 'N', V is not referenced.
00176 *
00177 *  LDV     (input) INTEGER
00178 *          The leading dimension of the array V. LDV >= max(1,P) if
00179 *          JOBV = 'V'; LDV >= 1 otherwise.
00180 *
00181 *  Q       (output) REAL array, dimension (LDQ,N)
00182 *          If JOBQ = 'Q', Q contains the N-by-N orthogonal matrix Q.
00183 *          If JOBQ = 'N', Q is not referenced.
00184 *
00185 *  LDQ     (input) INTEGER
00186 *          The leading dimension of the array Q. LDQ >= max(1,N) if
00187 *          JOBQ = 'Q'; LDQ >= 1 otherwise.
00188 *
00189 *  WORK    (workspace) REAL array,
00190 *                      dimension (max(3*N,M,P)+N)
00191 *
00192 *  IWORK   (workspace/output) INTEGER array, dimension (N)
00193 *          On exit, IWORK stores the sorting information. More
00194 *          precisely, the following loop will sort ALPHA
00195 *             for I = K+1, min(M,K+L)
00196 *                 swap ALPHA(I) and ALPHA(IWORK(I))
00197 *             endfor
00198 *          such that ALPHA(1) >= ALPHA(2) >= ... >= ALPHA(N).
00199 *
00200 *  INFO    (output) INTEGER
00201 *          = 0:  successful exit
00202 *          < 0:  if INFO = -i, the i-th argument had an illegal value.
00203 *          > 0:  if INFO = 1, the Jacobi-type procedure failed to
00204 *                converge.  For further details, see subroutine STGSJA.
00205 *
00206 *  Internal Parameters
00207 *  ===================
00208 *
00209 *  TOLA    REAL
00210 *  TOLB    REAL
00211 *          TOLA and TOLB are the thresholds to determine the effective
00212 *          rank of (A**T,B**T)**T. Generally, they are set to
00213 *                   TOLA = MAX(M,N)*norm(A)*MACHEPS,
00214 *                   TOLB = MAX(P,N)*norm(B)*MACHEPS.
00215 *          The size of TOLA and TOLB may affect the size of backward
00216 *          errors of the decomposition.
00217 *
00218 *  Further Details
00219 *  ===============
00220 *
00221 *  2-96 Based on modifications by
00222 *     Ming Gu and Huan Ren, Computer Science Division, University of
00223 *     California at Berkeley, USA
00224 *
00225 *  =====================================================================
00226 *
00227 *     .. Local Scalars ..
00228       LOGICAL            WANTQ, WANTU, WANTV
00229       INTEGER            I, IBND, ISUB, J, NCYCLE
00230       REAL               ANORM, BNORM, SMAX, TEMP, TOLA, TOLB, ULP, UNFL
00231 *     ..
00232 *     .. External Functions ..
00233       LOGICAL            LSAME
00234       REAL               SLAMCH, SLANGE
00235       EXTERNAL           LSAME, SLAMCH, SLANGE
00236 *     ..
00237 *     .. External Subroutines ..
00238       EXTERNAL           SCOPY, SGGSVP, STGSJA, XERBLA
00239 *     ..
00240 *     .. Intrinsic Functions ..
00241       INTRINSIC          MAX, MIN
00242 *     ..
00243 *     .. Executable Statements ..
00244 *
00245 *     Test the input parameters
00246 *
00247       WANTU = LSAME( JOBU, 'U' )
00248       WANTV = LSAME( JOBV, 'V' )
00249       WANTQ = LSAME( JOBQ, 'Q' )
00250 *
00251       INFO = 0
00252       IF( .NOT.( WANTU .OR. LSAME( JOBU, 'N' ) ) ) THEN
00253          INFO = -1
00254       ELSE IF( .NOT.( WANTV .OR. LSAME( JOBV, 'N' ) ) ) THEN
00255          INFO = -2
00256       ELSE IF( .NOT.( WANTQ .OR. LSAME( JOBQ, 'N' ) ) ) THEN
00257          INFO = -3
00258       ELSE IF( M.LT.0 ) THEN
00259          INFO = -4
00260       ELSE IF( N.LT.0 ) THEN
00261          INFO = -5
00262       ELSE IF( P.LT.0 ) THEN
00263          INFO = -6
00264       ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
00265          INFO = -10
00266       ELSE IF( LDB.LT.MAX( 1, P ) ) THEN
00267          INFO = -12
00268       ELSE IF( LDU.LT.1 .OR. ( WANTU .AND. LDU.LT.M ) ) THEN
00269          INFO = -16
00270       ELSE IF( LDV.LT.1 .OR. ( WANTV .AND. LDV.LT.P ) ) THEN
00271          INFO = -18
00272       ELSE IF( LDQ.LT.1 .OR. ( WANTQ .AND. LDQ.LT.N ) ) THEN
00273          INFO = -20
00274       END IF
00275       IF( INFO.NE.0 ) THEN
00276          CALL XERBLA( 'SGGSVD', -INFO )
00277          RETURN
00278       END IF
00279 *
00280 *     Compute the Frobenius norm of matrices A and B
00281 *
00282       ANORM = SLANGE( '1', M, N, A, LDA, WORK )
00283       BNORM = SLANGE( '1', P, N, B, LDB, WORK )
00284 *
00285 *     Get machine precision and set up threshold for determining
00286 *     the effective numerical rank of the matrices A and B.
00287 *
00288       ULP = SLAMCH( 'Precision' )
00289       UNFL = SLAMCH( 'Safe Minimum' )
00290       TOLA = MAX( M, N )*MAX( ANORM, UNFL )*ULP
00291       TOLB = MAX( P, N )*MAX( BNORM, UNFL )*ULP
00292 *
00293 *     Preprocessing
00294 *
00295       CALL SGGSVP( JOBU, JOBV, JOBQ, M, P, N, A, LDA, B, LDB, TOLA,
00296      $             TOLB, K, L, U, LDU, V, LDV, Q, LDQ, IWORK, WORK,
00297      $             WORK( N+1 ), INFO )
00298 *
00299 *     Compute the GSVD of two upper "triangular" matrices
00300 *
00301       CALL STGSJA( JOBU, JOBV, JOBQ, M, P, N, K, L, A, LDA, B, LDB,
00302      $             TOLA, TOLB, ALPHA, BETA, U, LDU, V, LDV, Q, LDQ,
00303      $             WORK, NCYCLE, INFO )
00304 *
00305 *     Sort the singular values and store the pivot indices in IWORK
00306 *     Copy ALPHA to WORK, then sort ALPHA in WORK
00307 *
00308       CALL SCOPY( N, ALPHA, 1, WORK, 1 )
00309       IBND = MIN( L, M-K )
00310       DO 20 I = 1, IBND
00311 *
00312 *        Scan for largest ALPHA(K+I)
00313 *
00314          ISUB = I
00315          SMAX = WORK( K+I )
00316          DO 10 J = I + 1, IBND
00317             TEMP = WORK( K+J )
00318             IF( TEMP.GT.SMAX ) THEN
00319                ISUB = J
00320                SMAX = TEMP
00321             END IF
00322    10    CONTINUE
00323          IF( ISUB.NE.I ) THEN
00324             WORK( K+ISUB ) = WORK( K+I )
00325             WORK( K+I ) = SMAX
00326             IWORK( K+I ) = K + ISUB
00327          ELSE
00328             IWORK( K+I ) = K + I
00329          END IF
00330    20 CONTINUE
00331 *
00332       RETURN
00333 *
00334 *     End of SGGSVD
00335 *
00336       END
 All Files Functions