LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
cgglse.f
Go to the documentation of this file.
1*> \brief <b> CGGLSE solves overdetermined or underdetermined systems for OTHER matrices</b>
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download CGGLSE + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgglse.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgglse.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgglse.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE CGGLSE( M, N, P, A, LDA, B, LDB, C, D, X, WORK, LWORK,
20* INFO )
21*
22* .. Scalar Arguments ..
23* INTEGER INFO, LDA, LDB, LWORK, M, N, P
24* ..
25* .. Array Arguments ..
26* COMPLEX A( LDA, * ), B( LDB, * ), C( * ), D( * ),
27* $ WORK( * ), X( * )
28* ..
29*
30*
31*> \par Purpose:
32* =============
33*>
34*> \verbatim
35*>
36*> CGGLSE solves the linear equality-constrained least squares (LSE)
37*> problem:
38*>
39*> minimize || c - A*x ||_2 subject to B*x = d
40*>
41*> where A is an M-by-N matrix, B is a P-by-N matrix, c is a given
42*> M-vector, and d is a given P-vector. It is assumed that
43*> P <= N <= M+P, and
44*>
45*> rank(B) = P and rank( (A) ) = N.
46*> ( (B) )
47*>
48*> These conditions ensure that the LSE problem has a unique solution,
49*> which is obtained using a generalized RQ factorization of the
50*> matrices (B, A) given by
51*>
52*> B = (0 R)*Q, A = Z*T*Q.
53*>
54*> Callers of this subroutine should note that the singularity/rank-deficiency checks
55*> implemented in this subroutine are rudimentary. The CTRTRS subroutine called by this
56*> subroutine only signals a failure due to singularity if the problem is exactly singular.
57*>
58*> It is conceivable for one (or more) of the factors involved in the generalized RQ
59*> factorization of the pair (B, A) to be subnormally close to singularity without this
60*> subroutine signalling an error. The solutions computed for such almost-rank-deficient
61*> problems may be less accurate due to a loss of numerical precision.
62*>
63*> \endverbatim
64*
65* Arguments:
66* ==========
67*
68*> \param[in] M
69*> \verbatim
70*> M is INTEGER
71*> The number of rows of the matrix A. M >= 0.
72*> \endverbatim
73*>
74*> \param[in] N
75*> \verbatim
76*> N is INTEGER
77*> The number of columns of the matrices A and B. N >= 0.
78*> \endverbatim
79*>
80*> \param[in] P
81*> \verbatim
82*> P is INTEGER
83*> The number of rows of the matrix B. 0 <= P <= N <= M+P.
84*> \endverbatim
85*>
86*> \param[in,out] A
87*> \verbatim
88*> A is COMPLEX array, dimension (LDA,N)
89*> On entry, the M-by-N matrix A.
90*> On exit, the elements on and above the diagonal of the array
91*> contain the min(M,N)-by-N upper trapezoidal matrix T.
92*> \endverbatim
93*>
94*> \param[in] LDA
95*> \verbatim
96*> LDA is INTEGER
97*> The leading dimension of the array A. LDA >= max(1,M).
98*> \endverbatim
99*>
100*> \param[in,out] B
101*> \verbatim
102*> B is COMPLEX array, dimension (LDB,N)
103*> On entry, the P-by-N matrix B.
104*> On exit, the upper triangle of the subarray B(1:P,N-P+1:N)
105*> contains the P-by-P upper triangular matrix R.
106*> \endverbatim
107*>
108*> \param[in] LDB
109*> \verbatim
110*> LDB is INTEGER
111*> The leading dimension of the array B. LDB >= max(1,P).
112*> \endverbatim
113*>
114*> \param[in,out] C
115*> \verbatim
116*> C is COMPLEX array, dimension (M)
117*> On entry, C contains the right hand side vector for the
118*> least squares part of the LSE problem.
119*> On exit, the residual sum of squares for the solution
120*> is given by the sum of squares of elements N-P+1 to M of
121*> vector C.
122*> \endverbatim
123*>
124*> \param[in,out] D
125*> \verbatim
126*> D is COMPLEX array, dimension (P)
127*> On entry, D contains the right hand side vector for the
128*> constrained equation.
129*> On exit, D is destroyed.
130*> \endverbatim
131*>
132*> \param[out] X
133*> \verbatim
134*> X is COMPLEX array, dimension (N)
135*> On exit, X is the solution of the LSE problem.
136*> \endverbatim
137*>
138*> \param[out] WORK
139*> \verbatim
140*> WORK is COMPLEX array, dimension (MAX(1,LWORK))
141*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
142*> \endverbatim
143*>
144*> \param[in] LWORK
145*> \verbatim
146*> LWORK is INTEGER
147*> The dimension of the array WORK. LWORK >= max(1,M+N+P).
148*> For optimum performance LWORK >= P+min(M,N)+max(M,N)*NB,
149*> where NB is an upper bound for the optimal blocksizes for
150*> CGEQRF, CGERQF, CUNMQR and CUNMRQ.
151*>
152*> If LWORK = -1, then a workspace query is assumed; the routine
153*> only calculates the optimal size of the WORK array, returns
154*> this value as the first entry of the WORK array, and no error
155*> message related to LWORK is issued by XERBLA.
156*> \endverbatim
157*>
158*> \param[out] INFO
159*> \verbatim
160*> INFO is INTEGER
161*> = 0: successful exit.
162*> < 0: if INFO = -i, the i-th argument had an illegal value.
163*> = 1: the upper triangular factor R associated with B in the
164*> generalized RQ factorization of the pair (B, A) is exactly
165*> singular, so that rank(B) < P; the least squares
166*> solution could not be computed.
167*> = 2: the (N-P) by (N-P) part of the upper trapezoidal factor
168*> T associated with A in the generalized RQ factorization
169*> of the pair (B, A) is exactly singular, so that
170*> rank( (A) ) < N; the least squares solution could not
171*> ( (B) )
172*> be computed.
173*> \endverbatim
174*
175* Authors:
176* ========
177*
178*> \author Univ. of Tennessee
179*> \author Univ. of California Berkeley
180*> \author Univ. of Colorado Denver
181*> \author NAG Ltd.
182*
183*> \ingroup gglse
184*
185* =====================================================================
186 SUBROUTINE cgglse( M, N, P, A, LDA, B, LDB, C, D, X, WORK,
187 $ LWORK,
188 $ INFO )
189*
190* -- LAPACK driver routine --
191* -- LAPACK is a software package provided by Univ. of Tennessee, --
192* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
193*
194* .. Scalar Arguments ..
195 INTEGER INFO, LDA, LDB, LWORK, M, N, P
196* ..
197* .. Array Arguments ..
198 COMPLEX A( LDA, * ), B( LDB, * ), C( * ), D( * ),
199 $ WORK( * ), X( * )
200* ..
201*
202* =====================================================================
203*
204* .. Parameters ..
205 COMPLEX CONE
206 PARAMETER ( CONE = ( 1.0e+0, 0.0e+0 ) )
207* ..
208* .. Local Scalars ..
209 LOGICAL LQUERY
210 INTEGER LOPT, LWKMIN, LWKOPT, MN, NB, NB1, NB2, NB3,
211 $ nb4, nr
212* ..
213* .. External Subroutines ..
214 EXTERNAL caxpy, ccopy, cgemv, cggrqf, ctrmv,
215 $ ctrtrs,
217* ..
218* .. External Functions ..
219 INTEGER ILAENV
220 REAL SROUNDUP_LWORK
221 EXTERNAL ilaenv, sroundup_lwork
222* ..
223* .. Intrinsic Functions ..
224 INTRINSIC int, max, min
225* ..
226* .. Executable Statements ..
227*
228* Test the input parameters
229*
230 info = 0
231 mn = min( m, n )
232 lquery = ( lwork.EQ.-1 )
233 IF( m.LT.0 ) THEN
234 info = -1
235 ELSE IF( n.LT.0 ) THEN
236 info = -2
237 ELSE IF( p.LT.0 .OR. p.GT.n .OR. p.LT.n-m ) THEN
238 info = -3
239 ELSE IF( lda.LT.max( 1, m ) ) THEN
240 info = -5
241 ELSE IF( ldb.LT.max( 1, p ) ) THEN
242 info = -7
243 END IF
244*
245* Calculate workspace
246*
247 IF( info.EQ.0) THEN
248 IF( n.EQ.0 ) THEN
249 lwkmin = 1
250 lwkopt = 1
251 ELSE
252 nb1 = ilaenv( 1, 'CGEQRF', ' ', m, n, -1, -1 )
253 nb2 = ilaenv( 1, 'CGERQF', ' ', m, n, -1, -1 )
254 nb3 = ilaenv( 1, 'CUNMQR', ' ', m, n, p, -1 )
255 nb4 = ilaenv( 1, 'CUNMRQ', ' ', m, n, p, -1 )
256 nb = max( nb1, nb2, nb3, nb4 )
257 lwkmin = m + n + p
258 lwkopt = p + mn + max( m, n )*nb
259 END IF
260 work( 1 ) = sroundup_lwork(lwkopt)
261*
262 IF( lwork.LT.lwkmin .AND. .NOT.lquery ) THEN
263 info = -12
264 END IF
265 END IF
266*
267 IF( info.NE.0 ) THEN
268 CALL xerbla( 'CGGLSE', -info )
269 RETURN
270 ELSE IF( lquery ) THEN
271 RETURN
272 END IF
273*
274* Quick return if possible
275*
276 IF( n.EQ.0 )
277 $ RETURN
278*
279* Compute the GRQ factorization of matrices B and A:
280*
281* B*Q**H = ( 0 T12 ) P Z**H*A*Q**H = ( R11 R12 ) N-P
282* N-P P ( 0 R22 ) M+P-N
283* N-P P
284*
285* where T12 and R11 are upper triangular, and Q and Z are
286* unitary.
287*
288 CALL cggrqf( p, m, n, b, ldb, work, a, lda, work( p+1 ),
289 $ work( p+mn+1 ), lwork-p-mn, info )
290 lopt = int( work( p+mn+1 ) )
291*
292* Update c = Z**H *c = ( c1 ) N-P
293* ( c2 ) M+P-N
294*
295 CALL cunmqr( 'Left', 'Conjugate Transpose', m, 1, mn, a, lda,
296 $ work( p+1 ), c, max( 1, m ), work( p+mn+1 ),
297 $ lwork-p-mn, info )
298 lopt = max( lopt, int( work( p+mn+1 ) ) )
299*
300* Solve T12*x2 = d for x2
301*
302 IF( p.GT.0 ) THEN
303 CALL ctrtrs( 'Upper', 'No transpose', 'Non-unit', p, 1,
304 $ b( 1, n-p+1 ), ldb, d, p, info )
305*
306 IF( info.GT.0 ) THEN
307 info = 1
308 RETURN
309 END IF
310*
311* Put the solution in X
312*
313 CALL ccopy( p, d, 1, x( n-p+1 ), 1 )
314*
315* Update c1
316*
317 CALL cgemv( 'No transpose', n-p, p, -cone, a( 1, n-p+1 ),
318 $ lda,
319 $ d, 1, cone, c, 1 )
320 END IF
321*
322* Solve R11*x1 = c1 for x1
323*
324 IF( n.GT.p ) THEN
325 CALL ctrtrs( 'Upper', 'No transpose', 'Non-unit', n-p, 1,
326 $ a, lda, c, n-p, info )
327*
328 IF( info.GT.0 ) THEN
329 info = 2
330 RETURN
331 END IF
332*
333* Put the solutions in X
334*
335 CALL ccopy( n-p, c, 1, x, 1 )
336 END IF
337*
338* Compute the residual vector:
339*
340 IF( m.LT.n ) THEN
341 nr = m + p - n
342 IF( nr.GT.0 )
343 $ CALL cgemv( 'No transpose', nr, n-m, -cone, a( n-p+1,
344 $ m+1 ),
345 $ lda, d( nr+1 ), 1, cone, c( n-p+1 ), 1 )
346 ELSE
347 nr = p
348 END IF
349 IF( nr.GT.0 ) THEN
350 CALL ctrmv( 'Upper', 'No transpose', 'Non unit', nr,
351 $ a( n-p+1, n-p+1 ), lda, d, 1 )
352 CALL caxpy( nr, -cone, d, 1, c( n-p+1 ), 1 )
353 END IF
354*
355* Backward transformation x = Q**H*x
356*
357 CALL cunmrq( 'Left', 'Conjugate Transpose', n, 1, p, b, ldb,
358 $ work( 1 ), x, n, work( p+mn+1 ), lwork-p-mn, info )
359 work( 1 ) = cmplx( p + mn + max( lopt, int( work( p+mn+1 ) ) ) )
360*
361 RETURN
362*
363* End of CGGLSE
364*
365 END
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine caxpy(n, ca, cx, incx, cy, incy)
CAXPY
Definition caxpy.f:88
subroutine ccopy(n, cx, incx, cy, incy)
CCOPY
Definition ccopy.f:81
subroutine cgemv(trans, m, n, alpha, a, lda, x, incx, beta, y, incy)
CGEMV
Definition cgemv.f:160
subroutine cgglse(m, n, p, a, lda, b, ldb, c, d, x, work, lwork, info)
CGGLSE solves overdetermined or underdetermined systems for OTHER matrices
Definition cgglse.f:189
subroutine cggrqf(m, p, n, a, lda, taua, b, ldb, taub, work, lwork, info)
CGGRQF
Definition cggrqf.f:212
subroutine ctrmv(uplo, trans, diag, n, a, lda, x, incx)
CTRMV
Definition ctrmv.f:147
subroutine ctrtrs(uplo, trans, diag, n, nrhs, a, lda, b, ldb, info)
CTRTRS
Definition ctrtrs.f:144
subroutine cunmqr(side, trans, m, n, k, a, lda, tau, c, ldc, work, lwork, info)
CUNMQR
Definition cunmqr.f:166
subroutine cunmrq(side, trans, m, n, k, a, lda, tau, c, ldc, work, lwork, info)
CUNMRQ
Definition cunmrq.f:166