LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
dgglse.f
Go to the documentation of this file.
1*> \brief <b> DGGLSE 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 DGGLSE + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgglse.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgglse.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgglse.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE DGGLSE( 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* DOUBLE PRECISION A( LDA, * ), B( LDB, * ), C( * ), D( * ),
27* $ WORK( * ), X( * )
28* ..
29*
30*
31*> \par Purpose:
32* =============
33*>
34*> \verbatim
35*>
36*> DGGLSE 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 DTRTRS 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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*> DGEQRF, SGERQF, DORMQR and SORMRQ.
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 dgglse( 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 DOUBLE PRECISION A( LDA, * ), B( LDB, * ), C( * ), D( * ),
199 $ WORK( * ), X( * )
200* ..
201*
202* =====================================================================
203*
204* .. Parameters ..
205 DOUBLE PRECISION ONE
206 PARAMETER ( ONE = 1.0d+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 daxpy, dcopy, dgemv, dggrqf, dormqr,
215 $ dormrq,
217* ..
218* .. External Functions ..
219 INTEGER ILAENV
220 EXTERNAL ILAENV
221* ..
222* .. Intrinsic Functions ..
223 INTRINSIC int, max, min
224* ..
225* .. Executable Statements ..
226*
227* Test the input parameters
228*
229 info = 0
230 mn = min( m, n )
231 lquery = ( lwork.EQ.-1 )
232 IF( m.LT.0 ) THEN
233 info = -1
234 ELSE IF( n.LT.0 ) THEN
235 info = -2
236 ELSE IF( p.LT.0 .OR. p.GT.n .OR. p.LT.n-m ) THEN
237 info = -3
238 ELSE IF( lda.LT.max( 1, m ) ) THEN
239 info = -5
240 ELSE IF( ldb.LT.max( 1, p ) ) THEN
241 info = -7
242 END IF
243*
244* Calculate workspace
245*
246 IF( info.EQ.0) THEN
247 IF( n.EQ.0 ) THEN
248 lwkmin = 1
249 lwkopt = 1
250 ELSE
251 nb1 = ilaenv( 1, 'DGEQRF', ' ', m, n, -1, -1 )
252 nb2 = ilaenv( 1, 'DGERQF', ' ', m, n, -1, -1 )
253 nb3 = ilaenv( 1, 'DORMQR', ' ', m, n, p, -1 )
254 nb4 = ilaenv( 1, 'DORMRQ', ' ', m, n, p, -1 )
255 nb = max( nb1, nb2, nb3, nb4 )
256 lwkmin = m + n + p
257 lwkopt = p + mn + max( m, n )*nb
258 END IF
259 work( 1 ) = lwkopt
260*
261 IF( lwork.LT.lwkmin .AND. .NOT.lquery ) THEN
262 info = -12
263 END IF
264 END IF
265*
266 IF( info.NE.0 ) THEN
267 CALL xerbla( 'DGGLSE', -info )
268 RETURN
269 ELSE IF( lquery ) THEN
270 RETURN
271 END IF
272*
273* Quick return if possible
274*
275 IF( n.EQ.0 )
276 $ RETURN
277*
278* Compute the GRQ factorization of matrices B and A:
279*
280* B*Q**T = ( 0 T12 ) P Z**T*A*Q**T = ( R11 R12 ) N-P
281* N-P P ( 0 R22 ) M+P-N
282* N-P P
283*
284* where T12 and R11 are upper triangular, and Q and Z are
285* orthogonal.
286*
287 CALL dggrqf( p, m, n, b, ldb, work, a, lda, work( p+1 ),
288 $ work( p+mn+1 ), lwork-p-mn, info )
289 lopt = int( work( p+mn+1 ) )
290*
291* Update c = Z**T *c = ( c1 ) N-P
292* ( c2 ) M+P-N
293*
294 CALL dormqr( 'Left', 'Transpose', m, 1, mn, a, lda,
295 $ work( p+1 ),
296 $ c, max( 1, m ), work( p+mn+1 ), lwork-p-mn, info )
297 lopt = max( lopt, int( work( p+mn+1 ) ) )
298*
299* Solve T12*x2 = d for x2
300*
301 IF( p.GT.0 ) THEN
302 CALL dtrtrs( 'Upper', 'No transpose', 'Non-unit', p, 1,
303 $ b( 1, n-p+1 ), ldb, d, p, info )
304*
305 IF( info.GT.0 ) THEN
306 info = 1
307 RETURN
308 END IF
309*
310* Put the solution in X
311*
312 CALL dcopy( p, d, 1, x( n-p+1 ), 1 )
313*
314* Update c1
315*
316 CALL dgemv( 'No transpose', n-p, p, -one, a( 1, n-p+1 ),
317 $ lda,
318 $ d, 1, one, c, 1 )
319 END IF
320*
321* Solve R11*x1 = c1 for x1
322*
323 IF( n.GT.p ) THEN
324 CALL dtrtrs( 'Upper', 'No transpose', 'Non-unit', n-p, 1,
325 $ a, lda, c, n-p, info )
326*
327 IF( info.GT.0 ) THEN
328 info = 2
329 RETURN
330 END IF
331*
332* Put the solutions in X
333*
334 CALL dcopy( n-p, c, 1, x, 1 )
335 END IF
336*
337* Compute the residual vector:
338*
339 IF( m.LT.n ) THEN
340 nr = m + p - n
341 IF( nr.GT.0 )
342 $ CALL dgemv( 'No transpose', nr, n-m, -one, a( n-p+1,
343 $ m+1 ),
344 $ lda, d( nr+1 ), 1, one, c( n-p+1 ), 1 )
345 ELSE
346 nr = p
347 END IF
348 IF( nr.GT.0 ) THEN
349 CALL dtrmv( 'Upper', 'No transpose', 'Non unit', nr,
350 $ a( n-p+1, n-p+1 ), lda, d, 1 )
351 CALL daxpy( nr, -one, d, 1, c( n-p+1 ), 1 )
352 END IF
353*
354* Backward transformation x = Q**T*x
355*
356 CALL dormrq( 'Left', 'Transpose', n, 1, p, b, ldb, work( 1 ),
357 $ x,
358 $ n, work( p+mn+1 ), lwork-p-mn, info )
359 work( 1 ) = p + mn + max( lopt, int( work( p+mn+1 ) ) )
360*
361 RETURN
362*
363* End of DGGLSE
364*
365 END
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine daxpy(n, da, dx, incx, dy, incy)
DAXPY
Definition daxpy.f:89
subroutine dcopy(n, dx, incx, dy, incy)
DCOPY
Definition dcopy.f:82
subroutine dgemv(trans, m, n, alpha, a, lda, x, incx, beta, y, incy)
DGEMV
Definition dgemv.f:158
subroutine dgglse(m, n, p, a, lda, b, ldb, c, d, x, work, lwork, info)
DGGLSE solves overdetermined or underdetermined systems for OTHER matrices
Definition dgglse.f:189
subroutine dggrqf(m, p, n, a, lda, taua, b, ldb, taub, work, lwork, info)
DGGRQF
Definition dggrqf.f:212
subroutine dtrmv(uplo, trans, diag, n, a, lda, x, incx)
DTRMV
Definition dtrmv.f:147
subroutine dtrtrs(uplo, trans, diag, n, nrhs, a, lda, b, ldb, info)
DTRTRS
Definition dtrtrs.f:144
subroutine dormqr(side, trans, m, n, k, a, lda, tau, c, ldc, work, lwork, info)
DORMQR
Definition dormqr.f:165
subroutine dormrq(side, trans, m, n, k, a, lda, tau, c, ldc, work, lwork, info)
DORMRQ
Definition dormrq.f:165