LAPACK  3.4.2
LAPACK: Linear Algebra PACKage
 All Files Functions Groups
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 *> \htmlonly
9 *> Download CGGLSE + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgglse.f">
11 *> [TGZ]</a>
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgglse.f">
13 *> [ZIP]</a>
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgglse.f">
15 *> [TXT]</a>
16 *> \endhtmlonly
17 *
18 * Definition:
19 * ===========
20 *
21 * SUBROUTINE CGGLSE( M, N, P, A, LDA, B, LDB, C, D, X, WORK, LWORK,
22 * INFO )
23 *
24 * .. Scalar Arguments ..
25 * INTEGER INFO, LDA, LDB, LWORK, M, N, P
26 * ..
27 * .. Array Arguments ..
28 * COMPLEX A( LDA, * ), B( LDB, * ), C( * ), D( * ),
29 * $ WORK( * ), X( * )
30 * ..
31 *
32 *
33 *> \par Purpose:
34 * =============
35 *>
36 *> \verbatim
37 *>
38 *> CGGLSE solves the linear equality-constrained least squares (LSE)
39 *> problem:
40 *>
41 *> minimize || c - A*x ||_2 subject to B*x = d
42 *>
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
45 *> P <= N <= M+P, and
46 *>
47 *> rank(B) = P and rank( (A) ) = N.
48 *> ( (B) )
49 *>
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
53 *>
54 *> B = (0 R)*Q, A = Z*T*Q.
55 *> \endverbatim
56 *
57 * Arguments:
58 * ==========
59 *
60 *> \param[in] M
61 *> \verbatim
62 *> M is INTEGER
63 *> The number of rows of the matrix A. M >= 0.
64 *> \endverbatim
65 *>
66 *> \param[in] N
67 *> \verbatim
68 *> N is INTEGER
69 *> The number of columns of the matrices A and B. N >= 0.
70 *> \endverbatim
71 *>
72 *> \param[in] P
73 *> \verbatim
74 *> P is INTEGER
75 *> The number of rows of the matrix B. 0 <= P <= N <= M+P.
76 *> \endverbatim
77 *>
78 *> \param[in,out] A
79 *> \verbatim
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.
84 *> \endverbatim
85 *>
86 *> \param[in] LDA
87 *> \verbatim
88 *> LDA is INTEGER
89 *> The leading dimension of the array A. LDA >= max(1,M).
90 *> \endverbatim
91 *>
92 *> \param[in,out] B
93 *> \verbatim
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.
98 *> \endverbatim
99 *>
100 *> \param[in] LDB
101 *> \verbatim
102 *> LDB is INTEGER
103 *> The leading dimension of the array B. LDB >= max(1,P).
104 *> \endverbatim
105 *>
106 *> \param[in,out] C
107 *> \verbatim
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
113 *> vector C.
114 *> \endverbatim
115 *>
116 *> \param[in,out] D
117 *> \verbatim
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.
122 *> \endverbatim
123 *>
124 *> \param[out] X
125 *> \verbatim
126 *> X is COMPLEX array, dimension (N)
127 *> On exit, X is the solution of the LSE problem.
128 *> \endverbatim
129 *>
130 *> \param[out] WORK
131 *> \verbatim
132 *> WORK is COMPLEX array, dimension (MAX(1,LWORK))
133 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
134 *> \endverbatim
135 *>
136 *> \param[in] LWORK
137 *> \verbatim
138 *> LWORK is INTEGER
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.
143 *>
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.
148 *> \endverbatim
149 *>
150 *> \param[out] INFO
151 *> \verbatim
152 *> INFO is INTEGER
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
163 *> ( (B) )
164 *> be computed.
165 *> \endverbatim
166 *
167 * Authors:
168 * ========
169 *
170 *> \author Univ. of Tennessee
171 *> \author Univ. of California Berkeley
172 *> \author Univ. of Colorado Denver
173 *> \author NAG Ltd.
174 *
175 *> \date November 2011
176 *
177 *> \ingroup complexOTHERsolve
178 *
179 * =====================================================================
180  SUBROUTINE cgglse( M, N, P, A, LDA, B, LDB, C, D, X, WORK, LWORK,
181  $ info )
182 *
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..--
186 * November 2011
187 *
188 * .. Scalar Arguments ..
189  INTEGER info, lda, ldb, lwork, m, n, p
190 * ..
191 * .. Array Arguments ..
192  COMPLEX a( lda, * ), b( ldb, * ), c( * ), d( * ),
193  $ work( * ), x( * )
194 * ..
195 *
196 * =====================================================================
197 *
198 * .. Parameters ..
199  COMPLEX cone
200  parameter( cone = ( 1.0e+0, 0.0e+0 ) )
201 * ..
202 * .. Local Scalars ..
203  LOGICAL lquery
204  INTEGER lopt, lwkmin, lwkopt, mn, nb, nb1, nb2, nb3,
205  $ nb4, nr
206 * ..
207 * .. External Subroutines ..
208  EXTERNAL caxpy, ccopy, cgemv, cggrqf, ctrmv, ctrtrs,
209  $ cunmqr, cunmrq, xerbla
210 * ..
211 * .. External Functions ..
212  INTEGER ilaenv
213  EXTERNAL ilaenv
214 * ..
215 * .. Intrinsic Functions ..
216  INTRINSIC int, max, min
217 * ..
218 * .. Executable Statements ..
219 *
220 * Test the input parameters
221 *
222  info = 0
223  mn = min( m, n )
224  lquery = ( lwork.EQ.-1 )
225  IF( m.LT.0 ) THEN
226  info = -1
227  ELSE IF( n.LT.0 ) THEN
228  info = -2
229  ELSE IF( p.LT.0 .OR. p.GT.n .OR. p.LT.n-m ) THEN
230  info = -3
231  ELSE IF( lda.LT.max( 1, m ) ) THEN
232  info = -5
233  ELSE IF( ldb.LT.max( 1, p ) ) THEN
234  info = -7
235  END IF
236 *
237 * Calculate workspace
238 *
239  IF( info.EQ.0) THEN
240  IF( n.EQ.0 ) THEN
241  lwkmin = 1
242  lwkopt = 1
243  ELSE
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 )
249  lwkmin = m + n + p
250  lwkopt = p + mn + max( m, n )*nb
251  END IF
252  work( 1 ) = lwkopt
253 *
254  IF( lwork.LT.lwkmin .AND. .NOT.lquery ) THEN
255  info = -12
256  END IF
257  END IF
258 *
259  IF( info.NE.0 ) THEN
260  CALL xerbla( 'CGGLSE', -info )
261  return
262  ELSE IF( lquery ) THEN
263  return
264  END IF
265 *
266 * Quick return if possible
267 *
268  IF( n.EQ.0 )
269  $ return
270 *
271 * Compute the GRQ factorization of matrices B and A:
272 *
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
275 * N-P P
276 *
277 * where T12 and R11 are upper triangular, and Q and Z are
278 * unitary.
279 *
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 )
283 *
284 * Update c = Z**H *c = ( c1 ) N-P
285 * ( c2 ) M+P-N
286 *
287  CALL cunmqr( 'Left', 'Conjugate Transpose', m, 1, mn, a, lda,
288  $ work( p+1 ), c, max( 1, m ), work( p+mn+1 ),
289  $ lwork-p-mn, info )
290  lopt = max( lopt, int( work( p+mn+1 ) ) )
291 *
292 * Solve T12*x2 = d for x2
293 *
294  IF( p.GT.0 ) THEN
295  CALL ctrtrs( 'Upper', 'No transpose', 'Non-unit', p, 1,
296  $ b( 1, n-p+1 ), ldb, d, p, info )
297 *
298  IF( info.GT.0 ) THEN
299  info = 1
300  return
301  END IF
302 *
303 * Put the solution in X
304 *
305  CALL ccopy( p, d, 1, x( n-p+1 ), 1 )
306 *
307 * Update c1
308 *
309  CALL cgemv( 'No transpose', n-p, p, -cone, a( 1, n-p+1 ), lda,
310  $ d, 1, cone, c, 1 )
311  END IF
312 *
313 * Solve R11*x1 = c1 for x1
314 *
315  IF( n.GT.p ) THEN
316  CALL ctrtrs( 'Upper', 'No transpose', 'Non-unit', n-p, 1,
317  $ a, lda, c, n-p, info )
318 *
319  IF( info.GT.0 ) THEN
320  info = 2
321  return
322  END IF
323 *
324 * Put the solutions in X
325 *
326  CALL ccopy( n-p, c, 1, x, 1 )
327  END IF
328 *
329 * Compute the residual vector:
330 *
331  IF( m.LT.n ) THEN
332  nr = m + p - n
333  IF( nr.GT.0 )
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 )
336  ELSE
337  nr = p
338  END IF
339  IF( nr.GT.0 ) THEN
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 )
343  END IF
344 *
345 * Backward transformation x = Q**H*x
346 *
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 ) ) )
350 *
351  return
352 *
353 * End of CGGLSE
354 *
355  END