1 *> \brief <b> CGGLSE solves overdetermined or underdetermined systems for OTHER matrices</b>
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download CGGLSE + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgglse.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgglse.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgglse.f">
21 * SUBROUTINE CGGLSE( M, N, P, A, LDA, B, LDB, C, D, X, WORK, LWORK,
24 * .. Scalar Arguments ..
25 * INTEGER INFO, LDA, LDB, LWORK, M, N, P
27 * .. Array Arguments ..
28 * COMPLEX A( LDA, * ), B( LDB, * ), C( * ), D( * ),
38 *> CGGLSE solves the linear equality-constrained least squares (LSE)
41 *> minimize || c - A*x ||_2 subject to B*x = d
43 *> where A is an M-by-N matrix, B is a P-by-N matrix, c is a given
44 *> M-vector, and d is a given P-vector. It is assumed that
47 *> rank(B) = P and rank( (A) ) = N.
50 *> These conditions ensure that the LSE problem has a unique solution,
51 *> which is obtained using a generalized RQ factorization of the
52 *> matrices (B, A) given by
54 *> B = (0 R)*Q, A = Z*T*Q.
63 *> The number of rows of the matrix A. M >= 0.
69 *> The number of columns of the matrices A and B. N >= 0.
75 *> The number of rows of the matrix B. 0 <= P <= N <= M+P.
80 *> A is COMPLEX array, dimension (LDA,N)
81 *> On entry, the M-by-N matrix A.
82 *> On exit, the elements on and above the diagonal of the array
83 *> contain the min(M,N)-by-N upper trapezoidal matrix T.
89 *> The leading dimension of the array A. LDA >= max(1,M).
94 *> B is COMPLEX array, dimension (LDB,N)
95 *> On entry, the P-by-N matrix B.
96 *> On exit, the upper triangle of the subarray B(1:P,N-P+1:N)
97 *> contains the P-by-P upper triangular matrix R.
103 *> The leading dimension of the array B. LDB >= max(1,P).
108 *> C is COMPLEX array, dimension (M)
109 *> On entry, C contains the right hand side vector for the
110 *> least squares part of the LSE problem.
111 *> On exit, the residual sum of squares for the solution
112 *> is given by the sum of squares of elements N-P+1 to M of
118 *> D is COMPLEX array, dimension (P)
119 *> On entry, D contains the right hand side vector for the
120 *> constrained equation.
121 *> On exit, D is destroyed.
126 *> X is COMPLEX array, dimension (N)
127 *> On exit, X is the solution of the LSE problem.
132 *> WORK is COMPLEX array, dimension (MAX(1,LWORK))
133 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
139 *> The dimension of the array WORK. LWORK >= max(1,M+N+P).
140 *> For optimum performance LWORK >= P+min(M,N)+max(M,N)*NB,
141 *> where NB is an upper bound for the optimal blocksizes for
142 *> CGEQRF, CGERQF, CUNMQR and CUNMRQ.
144 *> If LWORK = -1, then a workspace query is assumed; the routine
145 *> only calculates the optimal size of the WORK array, returns
146 *> this value as the first entry of the WORK array, and no error
147 *> message related to LWORK is issued by XERBLA.
153 *> = 0: successful exit.
154 *> < 0: if INFO = -i, the i-th argument had an illegal value.
155 *> = 1: the upper triangular factor R associated with B in the
156 *> generalized RQ factorization of the pair (B, A) is
157 *> singular, so that rank(B) < P; the least squares
158 *> solution could not be computed.
159 *> = 2: the (N-P) by (N-P) part of the upper trapezoidal factor
160 *> T associated with A in the generalized RQ factorization
161 *> of the pair (B, A) is singular, so that
162 *> rank( (A) ) < N; the least squares solution could not
170 *> \author Univ. of Tennessee
171 *> \author Univ. of California Berkeley
172 *> \author Univ. of Colorado Denver
175 *> \date November 2011
177 *> \ingroup complexOTHERsolve
179 * =====================================================================
180 SUBROUTINE CGGLSE( M, N, P, A, LDA, B, LDB, C, D, X, WORK, LWORK,
183 * -- LAPACK driver routine (version 3.4.0) --
184 * -- LAPACK is a software package provided by Univ. of Tennessee, --
185 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
188 * .. Scalar Arguments ..
189 INTEGER INFO, LDA, LDB, LWORK, M, N, P
191 * .. Array Arguments ..
192 COMPLEX A( LDA, * ), B( LDB, * ), C( * ), D( * ),
196 * =====================================================================
200 PARAMETER ( CONE = ( 1.0E+0, 0.0E+0 ) )
202 * .. Local Scalars ..
204 INTEGER LOPT, LWKMIN, LWKOPT, MN, NB, NB1, NB2, NB3,
207 * .. External Subroutines ..
208 EXTERNAL CAXPY, CCOPY, CGEMV, CGGRQF, CTRMV, CTRTRS,
209 $ CUNMQR, CUNMRQ, XERBLA
211 * .. External Functions ..
215 * .. Intrinsic Functions ..
216 INTRINSIC INT, MAX, MIN
218 * .. Executable Statements ..
220 * Test the input parameters
224 LQUERY = ( LWORK.EQ.-1 )
227 ELSE IF( N.LT.0 ) THEN
229 ELSE IF( P.LT.0 .OR. P.GT.N .OR. P.LT.N-M ) THEN
231 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
233 ELSE IF( LDB.LT.MAX( 1, P ) ) THEN
237 * Calculate workspace
244 NB1 = ILAENV( 1, 'CGEQRF', ' ', M, N, -1, -1 )
245 NB2 = ILAENV( 1, 'CGERQF', ' ', M, N, -1, -1 )
246 NB3 = ILAENV( 1, 'CUNMQR', ' ', M, N, P, -1 )
247 NB4 = ILAENV( 1, 'CUNMRQ', ' ', M, N, P, -1 )
248 NB = MAX( NB1, NB2, NB3, NB4 )
250 LWKOPT = P + MN + MAX( M, N )*NB
254 IF( LWORK.LT.LWKMIN .AND. .NOT.LQUERY ) THEN
260 CALL XERBLA( 'CGGLSE', -INFO )
262 ELSE IF( LQUERY ) THEN
266 * Quick return if possible
271 * Compute the GRQ factorization of matrices B and A:
273 * B*Q**H = ( 0 T12 ) P Z**H*A*Q**H = ( R11 R12 ) N-P
274 * N-P P ( 0 R22 ) M+P-N
277 * where T12 and R11 are upper triangular, and Q and Z are
280 CALL CGGRQF( P, M, N, B, LDB, WORK, A, LDA, WORK( P+1 ),
281 $ WORK( P+MN+1 ), LWORK-P-MN, INFO )
282 LOPT = WORK( P+MN+1 )
284 * Update c = Z**H *c = ( c1 ) N-P
287 CALL CUNMQR( 'Left', 'Conjugate Transpose', M, 1, MN, A, LDA,
288 $ WORK( P+1 ), C, MAX( 1, M ), WORK( P+MN+1 ),
290 LOPT = MAX( LOPT, INT( WORK( P+MN+1 ) ) )
292 * Solve T12*x2 = d for x2
295 CALL CTRTRS( 'Upper', 'No transpose', 'Non-unit', P, 1,
296 $ B( 1, N-P+1 ), LDB, D, P, INFO )
303 * Put the solution in X
305 CALL CCOPY( P, D, 1, X( N-P+1 ), 1 )
309 CALL CGEMV( 'No transpose', N-P, P, -CONE, A( 1, N-P+1 ), LDA,
313 * Solve R11*x1 = c1 for x1
316 CALL CTRTRS( 'Upper', 'No transpose', 'Non-unit', N-P, 1,
317 $ A, LDA, C, N-P, INFO )
324 * Put the solutions in X
326 CALL CCOPY( N-P, C, 1, X, 1 )
329 * Compute the residual vector:
334 $ CALL CGEMV( 'No transpose', NR, N-M, -CONE, A( N-P+1, M+1 ),
335 $ LDA, D( NR+1 ), 1, CONE, C( N-P+1 ), 1 )
340 CALL CTRMV( 'Upper', 'No transpose', 'Non unit', NR,
341 $ A( N-P+1, N-P+1 ), LDA, D, 1 )
342 CALL CAXPY( NR, -CONE, D, 1, C( N-P+1 ), 1 )
345 * Backward transformation x = Q**H*x
347 CALL CUNMRQ( 'Left', 'Conjugate Transpose', N, 1, P, B, LDB,
348 $ WORK( 1 ), X, N, WORK( P+MN+1 ), LWORK-P-MN, INFO )
349 WORK( 1 ) = P + MN + MAX( LOPT, INT( WORK( P+MN+1 ) ) )