LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches

◆ dgglse()

subroutine dgglse ( integer m,
integer n,
integer p,
double precision, dimension( lda, * ) a,
integer lda,
double precision, dimension( ldb, * ) b,
integer ldb,
double precision, dimension( * ) c,
double precision, dimension( * ) d,
double precision, dimension( * ) x,
double precision, dimension( * ) work,
integer lwork,
integer info )

DGGLSE solves overdetermined or underdetermined systems for OTHER matrices

Download DGGLSE + dependencies [TGZ] [ZIP] [TXT]

Purpose:
!>
!> DGGLSE solves the linear equality-constrained least squares (LSE)
!> problem:
!>
!>         minimize || c - A*x ||_2   subject to   B*x = d
!>
!> where A is an M-by-N matrix, B is a P-by-N matrix, c is a given
!> M-vector, and d is a given P-vector. It is assumed that
!> P <= N <= M+P, and
!>
!>          rank(B) = P and  rank( (A) ) = N.
!>                               ( (B) )
!>
!> These conditions ensure that the LSE problem has a unique solution,
!> which is obtained using a generalized RQ factorization of the
!> matrices (B, A) given by
!>
!>    B = (0 R)*Q,   A = Z*T*Q.
!>
!> Callers of this subroutine should note that the singularity/rank-deficiency checks
!> implemented in this subroutine are rudimentary. The DTRTRS subroutine called by this
!> subroutine only signals a failure due to singularity if the problem is exactly singular.
!>
!> It is conceivable for one (or more) of the factors involved in the generalized RQ
!> factorization of the pair (B, A) to be subnormally close to singularity without this
!> subroutine signalling an error. The solutions computed for such almost-rank-deficient
!> problems may be less accurate due to a loss of numerical precision.
!> 
!> 
Parameters
[in]M
!>          M is INTEGER
!>          The number of rows of the matrix A.  M >= 0.
!> 
[in]N
!>          N is INTEGER
!>          The number of columns of the matrices A and B. N >= 0.
!> 
[in]P
!>          P is INTEGER
!>          The number of rows of the matrix B. 0 <= P <= N <= M+P.
!> 
[in,out]A
!>          A is DOUBLE PRECISION array, dimension (LDA,N)
!>          On entry, the M-by-N matrix A.
!>          On exit, the elements on and above the diagonal of the array
!>          contain the min(M,N)-by-N upper trapezoidal matrix T.
!> 
[in]LDA
!>          LDA is INTEGER
!>          The leading dimension of the array A. LDA >= max(1,M).
!> 
[in,out]B
!>          B is DOUBLE PRECISION array, dimension (LDB,N)
!>          On entry, the P-by-N matrix B.
!>          On exit, the upper triangle of the subarray B(1:P,N-P+1:N)
!>          contains the P-by-P upper triangular matrix R.
!> 
[in]LDB
!>          LDB is INTEGER
!>          The leading dimension of the array B. LDB >= max(1,P).
!> 
[in,out]C
!>          C is DOUBLE PRECISION array, dimension (M)
!>          On entry, C contains the right hand side vector for the
!>          least squares part of the LSE problem.
!>          On exit, the residual sum of squares for the solution
!>          is given by the sum of squares of elements N-P+1 to M of
!>          vector C.
!> 
[in,out]D
!>          D is DOUBLE PRECISION array, dimension (P)
!>          On entry, D contains the right hand side vector for the
!>          constrained equation.
!>          On exit, D is destroyed.
!> 
[out]X
!>          X is DOUBLE PRECISION array, dimension (N)
!>          On exit, X is the solution of the LSE problem.
!> 
[out]WORK
!>          WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK))
!>          On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
!> 
[in]LWORK
!>          LWORK is INTEGER
!>          The dimension of the array WORK. LWORK >= max(1,M+N+P).
!>          For optimum performance LWORK >= P+min(M,N)+max(M,N)*NB,
!>          where NB is an upper bound for the optimal blocksizes for
!>          DGEQRF, SGERQF, DORMQR and SORMRQ.
!>
!>          If LWORK = -1, then a workspace query is assumed; the routine
!>          only calculates the optimal size of the WORK array, returns
!>          this value as the first entry of the WORK array, and no error
!>          message related to LWORK is issued by XERBLA.
!> 
[out]INFO
!>          INFO is INTEGER
!>          = 0:  successful exit.
!>          < 0:  if INFO = -i, the i-th argument had an illegal value.
!>          = 1:  the upper triangular factor R associated with B in the
!>                generalized RQ factorization of the pair (B, A) is exactly
!>                singular, so that rank(B) < P; the least squares
!>                solution could not be computed.
!>          = 2:  the (N-P) by (N-P) part of the upper trapezoidal factor
!>                T associated with A in the generalized RQ factorization
!>                of the pair (B, A) is exactly singular, so that
!>                rank( (A) ) < N; the least squares solution could not
!>                    ( (B) )
!>                be computed.
!> 
Author
Univ. of Tennessee
Univ. of California Berkeley
Univ. of Colorado Denver
NAG Ltd.

Definition at line 186 of file dgglse.f.

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*
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 dggrqf(m, p, n, a, lda, taua, b, ldb, taub, work, lwork, info)
DGGRQF
Definition dggrqf.f:212
integer function ilaenv(ispec, name, opts, n1, n2, n3, n4)
ILAENV
Definition ilaenv.f:160
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
Here is the call graph for this function:
Here is the caller graph for this function: