LAPACK 3.3.0

dggglm.f

Go to the documentation of this file.
00001       SUBROUTINE DGGGLM( N, M, P, A, LDA, B, LDB, D, X, Y, WORK, LWORK,
00002      $                   INFO )
00003 *
00004 *  -- LAPACK driver 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       INTEGER            INFO, LDA, LDB, LWORK, M, N, P
00011 *     ..
00012 *     .. Array Arguments ..
00013       DOUBLE PRECISION   A( LDA, * ), B( LDB, * ), D( * ), WORK( * ),
00014      $                   X( * ), Y( * )
00015 *     ..
00016 *
00017 *  Purpose
00018 *  =======
00019 *
00020 *  DGGGLM solves a general Gauss-Markov linear model (GLM) problem:
00021 *
00022 *          minimize || y ||_2   subject to   d = A*x + B*y
00023 *              x
00024 *
00025 *  where A is an N-by-M matrix, B is an N-by-P matrix, and d is a
00026 *  given N-vector. It is assumed that M <= N <= M+P, and
00027 *
00028 *             rank(A) = M    and    rank( A B ) = N.
00029 *
00030 *  Under these assumptions, the constrained equation is always
00031 *  consistent, and there is a unique solution x and a minimal 2-norm
00032 *  solution y, which is obtained using a generalized QR factorization
00033 *  of the matrices (A, B) given by
00034 *
00035 *     A = Q*(R),   B = Q*T*Z.
00036 *           (0)
00037 *
00038 *  In particular, if matrix B is square nonsingular, then the problem
00039 *  GLM is equivalent to the following weighted linear least squares
00040 *  problem
00041 *
00042 *               minimize || inv(B)*(d-A*x) ||_2
00043 *                   x
00044 *
00045 *  where inv(B) denotes the inverse of B.
00046 *
00047 *  Arguments
00048 *  =========
00049 *
00050 *  N       (input) INTEGER
00051 *          The number of rows of the matrices A and B.  N >= 0.
00052 *
00053 *  M       (input) INTEGER
00054 *          The number of columns of the matrix A.  0 <= M <= N.
00055 *
00056 *  P       (input) INTEGER
00057 *          The number of columns of the matrix B.  P >= N-M.
00058 *
00059 *  A       (input/output) DOUBLE PRECISION array, dimension (LDA,M)
00060 *          On entry, the N-by-M matrix A.
00061 *          On exit, the upper triangular part of the array A contains
00062 *          the M-by-M upper triangular matrix R.
00063 *
00064 *  LDA     (input) INTEGER
00065 *          The leading dimension of the array A. LDA >= max(1,N).
00066 *
00067 *  B       (input/output) DOUBLE PRECISION array, dimension (LDB,P)
00068 *          On entry, the N-by-P matrix B.
00069 *          On exit, if N <= P, the upper triangle of the subarray
00070 *          B(1:N,P-N+1:P) contains the N-by-N upper triangular matrix T;
00071 *          if N > P, the elements on and above the (N-P)th subdiagonal
00072 *          contain the N-by-P upper trapezoidal matrix T.
00073 *
00074 *  LDB     (input) INTEGER
00075 *          The leading dimension of the array B. LDB >= max(1,N).
00076 *
00077 *  D       (input/output) DOUBLE PRECISION array, dimension (N)
00078 *          On entry, D is the left hand side of the GLM equation.
00079 *          On exit, D is destroyed.
00080 *
00081 *  X       (output) DOUBLE PRECISION array, dimension (M)
00082 *  Y       (output) DOUBLE PRECISION array, dimension (P)
00083 *          On exit, X and Y are the solutions of the GLM problem.
00084 *
00085 *  WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
00086 *          On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
00087 *
00088 *  LWORK   (input) INTEGER
00089 *          The dimension of the array WORK. LWORK >= max(1,N+M+P).
00090 *          For optimum performance, LWORK >= M+min(N,P)+max(N,P)*NB,
00091 *          where NB is an upper bound for the optimal blocksizes for
00092 *          DGEQRF, SGERQF, DORMQR and SORMRQ.
00093 *
00094 *          If LWORK = -1, then a workspace query is assumed; the routine
00095 *          only calculates the optimal size of the WORK array, returns
00096 *          this value as the first entry of the WORK array, and no error
00097 *          message related to LWORK is issued by XERBLA.
00098 *
00099 *  INFO    (output) INTEGER
00100 *          = 0:  successful exit.
00101 *          < 0:  if INFO = -i, the i-th argument had an illegal value.
00102 *          = 1:  the upper triangular factor R associated with A in the
00103 *                generalized QR factorization of the pair (A, B) is
00104 *                singular, so that rank(A) < M; the least squares
00105 *                solution could not be computed.
00106 *          = 2:  the bottom (N-M) by (N-M) part of the upper trapezoidal
00107 *                factor T associated with B in the generalized QR
00108 *                factorization of the pair (A, B) is singular, so that
00109 *                rank( A B ) < N; the least squares solution could not
00110 *                be computed.
00111 *
00112 *  ===================================================================
00113 *
00114 *     .. Parameters ..
00115       DOUBLE PRECISION   ZERO, ONE
00116       PARAMETER          ( ZERO = 0.0D+0, ONE = 1.0D+0 )
00117 *     ..
00118 *     .. Local Scalars ..
00119       LOGICAL            LQUERY
00120       INTEGER            I, LOPT, LWKMIN, LWKOPT, NB, NB1, NB2, NB3,
00121      $                   NB4, NP
00122 *     ..
00123 *     .. External Subroutines ..
00124       EXTERNAL           DCOPY, DGEMV, DGGQRF, DORMQR, DORMRQ, DTRTRS,
00125      $                   XERBLA
00126 *     ..
00127 *     .. External Functions ..
00128       INTEGER            ILAENV
00129       EXTERNAL           ILAENV
00130 *     ..
00131 *     .. Intrinsic Functions ..
00132       INTRINSIC          INT, MAX, MIN
00133 *     ..
00134 *     .. Executable Statements ..
00135 *
00136 *     Test the input parameters
00137 *
00138       INFO = 0
00139       NP = MIN( N, P )
00140       LQUERY = ( LWORK.EQ.-1 )
00141       IF( N.LT.0 ) THEN
00142          INFO = -1
00143       ELSE IF( M.LT.0 .OR. M.GT.N ) THEN
00144          INFO = -2
00145       ELSE IF( P.LT.0 .OR. P.LT.N-M ) THEN
00146          INFO = -3
00147       ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
00148          INFO = -5
00149       ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
00150          INFO = -7
00151       END IF
00152 *
00153 *     Calculate workspace
00154 *
00155       IF( INFO.EQ.0) THEN
00156          IF( N.EQ.0 ) THEN
00157             LWKMIN = 1
00158             LWKOPT = 1
00159          ELSE
00160             NB1 = ILAENV( 1, 'DGEQRF', ' ', N, M, -1, -1 )
00161             NB2 = ILAENV( 1, 'DGERQF', ' ', N, M, -1, -1 )
00162             NB3 = ILAENV( 1, 'DORMQR', ' ', N, M, P, -1 )
00163             NB4 = ILAENV( 1, 'DORMRQ', ' ', N, M, P, -1 )
00164             NB = MAX( NB1, NB2, NB3, NB4 )
00165             LWKMIN = M + N + P
00166             LWKOPT = M + NP + MAX( N, P )*NB
00167          END IF
00168          WORK( 1 ) = LWKOPT
00169 *
00170          IF( LWORK.LT.LWKMIN .AND. .NOT.LQUERY ) THEN
00171             INFO = -12
00172          END IF
00173       END IF
00174 *
00175       IF( INFO.NE.0 ) THEN
00176          CALL XERBLA( 'DGGGLM', -INFO )
00177          RETURN
00178       ELSE IF( LQUERY ) THEN
00179          RETURN
00180       END IF
00181 *
00182 *     Quick return if possible
00183 *
00184       IF( N.EQ.0 )
00185      $   RETURN
00186 *
00187 *     Compute the GQR factorization of matrices A and B:
00188 *
00189 *            Q'*A = ( R11 ) M,    Q'*B*Z' = ( T11   T12 ) M
00190 *                   (  0  ) N-M             (  0    T22 ) N-M
00191 *                      M                     M+P-N  N-M
00192 *
00193 *     where R11 and T22 are upper triangular, and Q and Z are
00194 *     orthogonal.
00195 *
00196       CALL DGGQRF( N, M, P, A, LDA, WORK, B, LDB, WORK( M+1 ),
00197      $             WORK( M+NP+1 ), LWORK-M-NP, INFO )
00198       LOPT = WORK( M+NP+1 )
00199 *
00200 *     Update left-hand-side vector d = Q'*d = ( d1 ) M
00201 *                                             ( d2 ) N-M
00202 *
00203       CALL DORMQR( 'Left', 'Transpose', N, 1, M, A, LDA, WORK, D,
00204      $             MAX( 1, N ), WORK( M+NP+1 ), LWORK-M-NP, INFO )
00205       LOPT = MAX( LOPT, INT( WORK( M+NP+1 ) ) )
00206 *
00207 *     Solve T22*y2 = d2 for y2
00208 *
00209       IF( N.GT.M ) THEN
00210          CALL DTRTRS( 'Upper', 'No transpose', 'Non unit', N-M, 1,
00211      $                B( M+1, M+P-N+1 ), LDB, D( M+1 ), N-M, INFO )
00212 *
00213          IF( INFO.GT.0 ) THEN
00214             INFO = 1
00215             RETURN
00216          END IF
00217 *
00218          CALL DCOPY( N-M, D( M+1 ), 1, Y( M+P-N+1 ), 1 )
00219       END IF
00220 *
00221 *     Set y1 = 0
00222 *
00223       DO 10 I = 1, M + P - N
00224          Y( I ) = ZERO
00225    10 CONTINUE
00226 *
00227 *     Update d1 = d1 - T12*y2
00228 *
00229       CALL DGEMV( 'No transpose', M, N-M, -ONE, B( 1, M+P-N+1 ), LDB,
00230      $            Y( M+P-N+1 ), 1, ONE, D, 1 )
00231 *
00232 *     Solve triangular system: R11*x = d1
00233 *
00234       IF( M.GT.0 ) THEN
00235          CALL DTRTRS( 'Upper', 'No Transpose', 'Non unit', M, 1, A, LDA,
00236      $                D, M, INFO )
00237 *
00238          IF( INFO.GT.0 ) THEN
00239             INFO = 2
00240             RETURN
00241          END IF
00242 *
00243 *        Copy D to X
00244 *
00245          CALL DCOPY( M, D, 1, X, 1 )
00246       END IF
00247 *
00248 *     Backward transformation y = Z'*y
00249 *
00250       CALL DORMRQ( 'Left', 'Transpose', P, 1, NP,
00251      $             B( MAX( 1, N-P+1 ), 1 ), LDB, WORK( M+1 ), Y,
00252      $             MAX( 1, P ), WORK( M+NP+1 ), LWORK-M-NP, INFO )
00253       WORK( 1 ) = M + NP + MAX( LOPT, INT( WORK( M+NP+1 ) ) )
00254 *
00255       RETURN
00256 *
00257 *     End of DGGGLM
00258 *
00259       END
 All Files Functions