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

◆ sgglse()

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

SGGLSE solves overdetermined or underdetermined systems for OTHER matrices

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

Purpose:
!>
!> SGGLSE 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 STRTRS 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 REAL 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 REAL 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 REAL 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 REAL 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 REAL array, dimension (N)
!>          On exit, X is the solution of the LSE problem.
!> 
[out]WORK
!>          WORK is REAL 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
!>          SGEQRF, SGERQF, SORMQR 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 sgglse.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 REAL A( LDA, * ), B( LDB, * ), C( * ), D( * ),
199 $ WORK( * ), X( * )
200* ..
201*
202* =====================================================================
203*
204* .. Parameters ..
205 REAL ONE
206 parameter( one = 1.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 saxpy, scopy, sgemv, sggrqf, sormqr,
215 $ sormrq,
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, 'SGEQRF', ' ', m, n, -1, -1 )
253 nb2 = ilaenv( 1, 'SGERQF', ' ', m, n, -1, -1 )
254 nb3 = ilaenv( 1, 'SORMQR', ' ', m, n, p, -1 )
255 nb4 = ilaenv( 1, 'SORMRQ', ' ', 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( 'SGGLSE', -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**T = ( 0 T12 ) P Z**T*A*Q**T = ( 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* orthogonal.
287*
288 CALL sggrqf( 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**T *c = ( c1 ) N-P
293* ( c2 ) M+P-N
294*
295 CALL sormqr( 'Left', 'Transpose', m, 1, mn, a, lda,
296 $ work( p+1 ),
297 $ c, max( 1, m ), work( p+mn+1 ), 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 strtrs( '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 scopy( p, d, 1, x( n-p+1 ), 1 )
314*
315* Update c1
316*
317 CALL sgemv( 'No transpose', n-p, p, -one, a( 1, n-p+1 ),
318 $ lda,
319 $ d, 1, one, c, 1 )
320 END IF
321*
322* Solve R11*x1 = c1 for x1
323*
324 IF( n.GT.p ) THEN
325 CALL strtrs( '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 scopy( 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 sgemv( 'No transpose', nr, n-m, -one, a( n-p+1,
344 $ m+1 ),
345 $ lda, d( nr+1 ), 1, one, c( n-p+1 ), 1 )
346 ELSE
347 nr = p
348 END IF
349 IF( nr.GT.0 ) THEN
350 CALL strmv( 'Upper', 'No transpose', 'Non unit', nr,
351 $ a( n-p+1, n-p+1 ), lda, d, 1 )
352 CALL saxpy( nr, -one, d, 1, c( n-p+1 ), 1 )
353 END IF
354*
355* Backward transformation x = Q**T*x
356*
357 CALL sormrq( 'Left', 'Transpose', n, 1, p, b, ldb, work( 1 ),
358 $ x,
359 $ n, work( p+mn+1 ), lwork-p-mn, info )
360 work( 1 ) = real( p + mn + max( lopt, int( work( p+mn+1 ) ) ) )
361*
362 RETURN
363*
364* End of SGGLSE
365*
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine saxpy(n, sa, sx, incx, sy, incy)
SAXPY
Definition saxpy.f:89
subroutine scopy(n, sx, incx, sy, incy)
SCOPY
Definition scopy.f:82
subroutine sgemv(trans, m, n, alpha, a, lda, x, incx, beta, y, incy)
SGEMV
Definition sgemv.f:158
subroutine sggrqf(m, p, n, a, lda, taua, b, ldb, taub, work, lwork, info)
SGGRQF
Definition sggrqf.f:212
integer function ilaenv(ispec, name, opts, n1, n2, n3, n4)
ILAENV
Definition ilaenv.f:160
real function sroundup_lwork(lwork)
SROUNDUP_LWORK
subroutine strmv(uplo, trans, diag, n, a, lda, x, incx)
STRMV
Definition strmv.f:147
subroutine strtrs(uplo, trans, diag, n, nrhs, a, lda, b, ldb, info)
STRTRS
Definition strtrs.f:144
subroutine sormqr(side, trans, m, n, k, a, lda, tau, c, ldc, work, lwork, info)
SORMQR
Definition sormqr.f:166
subroutine sormrq(side, trans, m, n, k, a, lda, tau, c, ldc, work, lwork, info)
SORMRQ
Definition sormrq.f:166
Here is the call graph for this function:
Here is the caller graph for this function: