LAPACK  3.9.1
LAPACK: Linear Algebra PACKage

◆ dgetsls()

subroutine dgetsls ( character  TRANS,
integer  M,
integer  N,
integer  NRHS,
double precision, dimension( lda, * )  A,
integer  LDA,
double precision, dimension( ldb, * )  B,
integer  LDB,
double precision, dimension( * )  WORK,
integer  LWORK,
integer  INFO 
)

DGETSLS

Purpose:
 DGETSLS solves overdetermined or underdetermined real linear systems
 involving an M-by-N matrix A, using a tall skinny QR or short wide LQ
 factorization of A.  It is assumed that A has full rank.



 The following options are provided:

 1. If TRANS = 'N' and m >= n:  find the least squares solution of
    an overdetermined system, i.e., solve the least squares problem
                 minimize || B - A*X ||.

 2. If TRANS = 'N' and m < n:  find the minimum norm solution of
    an underdetermined system A * X = B.

 3. If TRANS = 'T' and m >= n:  find the minimum norm solution of
    an undetermined system A**T * X = B.

 4. If TRANS = 'T' and m < n:  find the least squares solution of
    an overdetermined system, i.e., solve the least squares problem
                 minimize || B - A**T * X ||.

 Several right hand side vectors b and solution vectors x can be
 handled in a single call; they are stored as the columns of the
 M-by-NRHS right hand side matrix B and the N-by-NRHS solution
 matrix X.
Parameters
[in]TRANS
          TRANS is CHARACTER*1
          = 'N': the linear system involves A;
          = 'T': the linear system involves A**T.
[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 matrix A.  N >= 0.
[in]NRHS
          NRHS is INTEGER
          The number of right hand sides, i.e., the number of
          columns of the matrices B and X. NRHS >=0.
[in,out]A
          A is DOUBLE PRECISION array, dimension (LDA,N)
          On entry, the M-by-N matrix A.
          On exit,
          A is overwritten by details of its QR or LQ
          factorization as returned by DGEQR or DGELQ.
[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,NRHS)
          On entry, the matrix B of right hand side vectors, stored
          columnwise; B is M-by-NRHS if TRANS = 'N', or N-by-NRHS
          if TRANS = 'T'.
          On exit, if INFO = 0, B is overwritten by the solution
          vectors, stored columnwise:
          if TRANS = 'N' and m >= n, rows 1 to n of B contain the least
          squares solution vectors.
          if TRANS = 'N' and m < n, rows 1 to N of B contain the
          minimum norm solution vectors;
          if TRANS = 'T' and m >= n, rows 1 to M of B contain the
          minimum norm solution vectors;
          if TRANS = 'T' and m < n, rows 1 to M of B contain the
          least squares solution vectors.
[in]LDB
          LDB is INTEGER
          The leading dimension of the array B. LDB >= MAX(1,M,N).
[out]WORK
          (workspace) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
          On exit, if INFO = 0, WORK(1) contains optimal (or either minimal
          or optimal, if query was assumed) LWORK.
          See LWORK for details.
[in]LWORK
          LWORK is INTEGER
          The dimension of the array WORK.
          If LWORK = -1 or -2, then a workspace query is assumed.
          If LWORK = -1, the routine calculates optimal size of WORK for the
          optimal performance and returns this value in WORK(1).
          If LWORK = -2, the routine calculates minimal size of WORK and 
          returns this value in WORK(1).
[out]INFO
          INFO is INTEGER
          = 0:  successful exit
          < 0:  if INFO = -i, the i-th argument had an illegal value
          > 0:  if INFO =  i, the i-th diagonal element of the
                triangular factor of A is zero, so that A does not have
                full rank; the least squares solution could not be
                computed.
Author
Univ. of Tennessee
Univ. of California Berkeley
Univ. of Colorado Denver
NAG Ltd.

Definition at line 160 of file dgetsls.f.

162 *
163 * -- LAPACK driver routine --
164 * -- LAPACK is a software package provided by Univ. of Tennessee, --
165 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
166 *
167 * .. Scalar Arguments ..
168  CHARACTER TRANS
169  INTEGER INFO, LDA, LDB, LWORK, M, N, NRHS
170 * ..
171 * .. Array Arguments ..
172  DOUBLE PRECISION A( LDA, * ), B( LDB, * ), WORK( * )
173 *
174 * ..
175 *
176 * =====================================================================
177 *
178 * .. Parameters ..
179  DOUBLE PRECISION ZERO, ONE
180  parameter( zero = 0.0d0, one = 1.0d0 )
181 * ..
182 * .. Local Scalars ..
183  LOGICAL LQUERY, TRAN
184  INTEGER I, IASCL, IBSCL, J, MINMN, MAXMN, BROW,
185  $ SCLLEN, MNK, TSZO, TSZM, LWO, LWM, LW1, LW2,
186  $ WSIZEO, WSIZEM, INFO2
187  DOUBLE PRECISION ANRM, BIGNUM, BNRM, SMLNUM, TQ( 5 ), WORKQ( 1 )
188 * ..
189 * .. External Functions ..
190  LOGICAL LSAME
191  INTEGER ILAENV
192  DOUBLE PRECISION DLAMCH, DLANGE
193  EXTERNAL lsame, ilaenv, dlabad, dlamch, dlange
194 * ..
195 * .. External Subroutines ..
196  EXTERNAL dgeqr, dgemqr, dlascl, dlaset,
198 * ..
199 * .. Intrinsic Functions ..
200  INTRINSIC dble, max, min, int
201 * ..
202 * .. Executable Statements ..
203 *
204 * Test the input arguments.
205 *
206  info = 0
207  minmn = min( m, n )
208  maxmn = max( m, n )
209  mnk = max( minmn, nrhs )
210  tran = lsame( trans, 'T' )
211 *
212  lquery = ( lwork.EQ.-1 .OR. lwork.EQ.-2 )
213  IF( .NOT.( lsame( trans, 'N' ) .OR.
214  $ lsame( trans, 'T' ) ) ) THEN
215  info = -1
216  ELSE IF( m.LT.0 ) THEN
217  info = -2
218  ELSE IF( n.LT.0 ) THEN
219  info = -3
220  ELSE IF( nrhs.LT.0 ) THEN
221  info = -4
222  ELSE IF( lda.LT.max( 1, m ) ) THEN
223  info = -6
224  ELSE IF( ldb.LT.max( 1, m, n ) ) THEN
225  info = -8
226  END IF
227 *
228  IF( info.EQ.0 ) THEN
229 *
230 * Determine the block size and minimum LWORK
231 *
232  IF( m.GE.n ) THEN
233  CALL dgeqr( m, n, a, lda, tq, -1, workq, -1, info2 )
234  tszo = int( tq( 1 ) )
235  lwo = int( workq( 1 ) )
236  CALL dgemqr( 'L', trans, m, nrhs, n, a, lda, tq,
237  $ tszo, b, ldb, workq, -1, info2 )
238  lwo = max( lwo, int( workq( 1 ) ) )
239  CALL dgeqr( m, n, a, lda, tq, -2, workq, -2, info2 )
240  tszm = int( tq( 1 ) )
241  lwm = int( workq( 1 ) )
242  CALL dgemqr( 'L', trans, m, nrhs, n, a, lda, tq,
243  $ tszm, b, ldb, workq, -1, info2 )
244  lwm = max( lwm, int( workq( 1 ) ) )
245  wsizeo = tszo + lwo
246  wsizem = tszm + lwm
247  ELSE
248  CALL dgelq( m, n, a, lda, tq, -1, workq, -1, info2 )
249  tszo = int( tq( 1 ) )
250  lwo = int( workq( 1 ) )
251  CALL dgemlq( 'L', trans, n, nrhs, m, a, lda, tq,
252  $ tszo, b, ldb, workq, -1, info2 )
253  lwo = max( lwo, int( workq( 1 ) ) )
254  CALL dgelq( m, n, a, lda, tq, -2, workq, -2, info2 )
255  tszm = int( tq( 1 ) )
256  lwm = int( workq( 1 ) )
257  CALL dgemlq( 'L', trans, n, nrhs, m, a, lda, tq,
258  $ tszm, b, ldb, workq, -1, info2 )
259  lwm = max( lwm, int( workq( 1 ) ) )
260  wsizeo = tszo + lwo
261  wsizem = tszm + lwm
262  END IF
263 *
264  IF( ( lwork.LT.wsizem ).AND.( .NOT.lquery ) ) THEN
265  info = -10
266  END IF
267 *
268  END IF
269 *
270  IF( info.NE.0 ) THEN
271  CALL xerbla( 'DGETSLS', -info )
272  work( 1 ) = dble( wsizeo )
273  RETURN
274  END IF
275  IF( lquery ) THEN
276  IF( lwork.EQ.-1 ) work( 1 ) = real( wsizeo )
277  IF( lwork.EQ.-2 ) work( 1 ) = real( wsizem )
278  RETURN
279  END IF
280  IF( lwork.LT.wsizeo ) THEN
281  lw1 = tszm
282  lw2 = lwm
283  ELSE
284  lw1 = tszo
285  lw2 = lwo
286  END IF
287 *
288 * Quick return if possible
289 *
290  IF( min( m, n, nrhs ).EQ.0 ) THEN
291  CALL dlaset( 'FULL', max( m, n ), nrhs, zero, zero,
292  $ b, ldb )
293  RETURN
294  END IF
295 *
296 * Get machine parameters
297 *
298  smlnum = dlamch( 'S' ) / dlamch( 'P' )
299  bignum = one / smlnum
300  CALL dlabad( smlnum, bignum )
301 *
302 * Scale A, B if max element outside range [SMLNUM,BIGNUM]
303 *
304  anrm = dlange( 'M', m, n, a, lda, work )
305  iascl = 0
306  IF( anrm.GT.zero .AND. anrm.LT.smlnum ) THEN
307 *
308 * Scale matrix norm up to SMLNUM
309 *
310  CALL dlascl( 'G', 0, 0, anrm, smlnum, m, n, a, lda, info )
311  iascl = 1
312  ELSE IF( anrm.GT.bignum ) THEN
313 *
314 * Scale matrix norm down to BIGNUM
315 *
316  CALL dlascl( 'G', 0, 0, anrm, bignum, m, n, a, lda, info )
317  iascl = 2
318  ELSE IF( anrm.EQ.zero ) THEN
319 *
320 * Matrix all zero. Return zero solution.
321 *
322  CALL dlaset( 'F', maxmn, nrhs, zero, zero, b, ldb )
323  GO TO 50
324  END IF
325 *
326  brow = m
327  IF ( tran ) THEN
328  brow = n
329  END IF
330  bnrm = dlange( 'M', brow, nrhs, b, ldb, work )
331  ibscl = 0
332  IF( bnrm.GT.zero .AND. bnrm.LT.smlnum ) THEN
333 *
334 * Scale matrix norm up to SMLNUM
335 *
336  CALL dlascl( 'G', 0, 0, bnrm, smlnum, brow, nrhs, b, ldb,
337  $ info )
338  ibscl = 1
339  ELSE IF( bnrm.GT.bignum ) THEN
340 *
341 * Scale matrix norm down to BIGNUM
342 *
343  CALL dlascl( 'G', 0, 0, bnrm, bignum, brow, nrhs, b, ldb,
344  $ info )
345  ibscl = 2
346  END IF
347 *
348  IF ( m.GE.n ) THEN
349 *
350 * compute QR factorization of A
351 *
352  CALL dgeqr( m, n, a, lda, work( lw2+1 ), lw1,
353  $ work( 1 ), lw2, info )
354  IF ( .NOT.tran ) THEN
355 *
356 * Least-Squares Problem min || A * X - B ||
357 *
358 * B(1:M,1:NRHS) := Q**T * B(1:M,1:NRHS)
359 *
360  CALL dgemqr( 'L' , 'T', m, nrhs, n, a, lda,
361  $ work( lw2+1 ), lw1, b, ldb, work( 1 ), lw2,
362  $ info )
363 *
364 * B(1:N,1:NRHS) := inv(R) * B(1:N,1:NRHS)
365 *
366  CALL dtrtrs( 'U', 'N', 'N', n, nrhs,
367  $ a, lda, b, ldb, info )
368  IF( info.GT.0 ) THEN
369  RETURN
370  END IF
371  scllen = n
372  ELSE
373 *
374 * Overdetermined system of equations A**T * X = B
375 *
376 * B(1:N,1:NRHS) := inv(R**T) * B(1:N,1:NRHS)
377 *
378  CALL dtrtrs( 'U', 'T', 'N', n, nrhs,
379  $ a, lda, b, ldb, info )
380 *
381  IF( info.GT.0 ) THEN
382  RETURN
383  END IF
384 *
385 * B(N+1:M,1:NRHS) = ZERO
386 *
387  DO 20 j = 1, nrhs
388  DO 10 i = n + 1, m
389  b( i, j ) = zero
390  10 CONTINUE
391  20 CONTINUE
392 *
393 * B(1:M,1:NRHS) := Q(1:N,:) * B(1:N,1:NRHS)
394 *
395  CALL dgemqr( 'L', 'N', m, nrhs, n, a, lda,
396  $ work( lw2+1 ), lw1, b, ldb, work( 1 ), lw2,
397  $ info )
398 *
399  scllen = m
400 *
401  END IF
402 *
403  ELSE
404 *
405 * Compute LQ factorization of A
406 *
407  CALL dgelq( m, n, a, lda, work( lw2+1 ), lw1,
408  $ work( 1 ), lw2, info )
409 *
410 * workspace at least M, optimally M*NB.
411 *
412  IF( .NOT.tran ) THEN
413 *
414 * underdetermined system of equations A * X = B
415 *
416 * B(1:M,1:NRHS) := inv(L) * B(1:M,1:NRHS)
417 *
418  CALL dtrtrs( 'L', 'N', 'N', m, nrhs,
419  $ a, lda, b, ldb, info )
420 *
421  IF( info.GT.0 ) THEN
422  RETURN
423  END IF
424 *
425 * B(M+1:N,1:NRHS) = 0
426 *
427  DO 40 j = 1, nrhs
428  DO 30 i = m + 1, n
429  b( i, j ) = zero
430  30 CONTINUE
431  40 CONTINUE
432 *
433 * B(1:N,1:NRHS) := Q(1:N,:)**T * B(1:M,1:NRHS)
434 *
435  CALL dgemlq( 'L', 'T', n, nrhs, m, a, lda,
436  $ work( lw2+1 ), lw1, b, ldb, work( 1 ), lw2,
437  $ info )
438 *
439 * workspace at least NRHS, optimally NRHS*NB
440 *
441  scllen = n
442 *
443  ELSE
444 *
445 * overdetermined system min || A**T * X - B ||
446 *
447 * B(1:N,1:NRHS) := Q * B(1:N,1:NRHS)
448 *
449  CALL dgemlq( 'L', 'N', n, nrhs, m, a, lda,
450  $ work( lw2+1 ), lw1, b, ldb, work( 1 ), lw2,
451  $ info )
452 *
453 * workspace at least NRHS, optimally NRHS*NB
454 *
455 * B(1:M,1:NRHS) := inv(L**T) * B(1:M,1:NRHS)
456 *
457  CALL dtrtrs( 'Lower', 'Transpose', 'Non-unit', m, nrhs,
458  $ a, lda, b, ldb, info )
459 *
460  IF( info.GT.0 ) THEN
461  RETURN
462  END IF
463 *
464  scllen = m
465 *
466  END IF
467 *
468  END IF
469 *
470 * Undo scaling
471 *
472  IF( iascl.EQ.1 ) THEN
473  CALL dlascl( 'G', 0, 0, anrm, smlnum, scllen, nrhs, b, ldb,
474  $ info )
475  ELSE IF( iascl.EQ.2 ) THEN
476  CALL dlascl( 'G', 0, 0, anrm, bignum, scllen, nrhs, b, ldb,
477  $ info )
478  END IF
479  IF( ibscl.EQ.1 ) THEN
480  CALL dlascl( 'G', 0, 0, smlnum, bnrm, scllen, nrhs, b, ldb,
481  $ info )
482  ELSE IF( ibscl.EQ.2 ) THEN
483  CALL dlascl( 'G', 0, 0, bignum, bnrm, scllen, nrhs, b, ldb,
484  $ info )
485  END IF
486 *
487  50 CONTINUE
488  work( 1 ) = dble( tszo + lwo )
489  RETURN
490 *
491 * End of DGETSLS
492 *
subroutine dgelq(M, N, A, LDA, T, TSIZE, WORK, LWORK, INFO)
DGELQ
Definition: dgelq.f:172
subroutine dgemlq(SIDE, TRANS, M, N, K, A, LDA, T, TSIZE, C, LDC, WORK, LWORK, INFO)
DGEMLQ
Definition: dgemlq.f:171
subroutine dgemqr(SIDE, TRANS, M, N, K, A, LDA, T, TSIZE, C, LDC, WORK, LWORK, INFO)
DGEMQR
Definition: dgemqr.f:172
subroutine dgeqr(M, N, A, LDA, T, TSIZE, WORK, LWORK, INFO)
DGEQR
Definition: dgeqr.f:174
double precision function dlamch(CMACH)
DLAMCH
Definition: dlamch.f:69
subroutine dlabad(SMALL, LARGE)
DLABAD
Definition: dlabad.f:74
subroutine dlascl(TYPE, KL, KU, CFROM, CTO, M, N, A, LDA, INFO)
DLASCL multiplies a general rectangular matrix by a real scalar defined as cto/cfrom.
Definition: dlascl.f:143
subroutine dlaset(UPLO, M, N, ALPHA, BETA, A, LDA)
DLASET initializes the off-diagonal elements and the diagonal elements of a matrix to given values.
Definition: dlaset.f:110
integer function ilaenv(ISPEC, NAME, OPTS, N1, N2, N3, N4)
ILAENV
Definition: ilaenv.f:162
subroutine xerbla(SRNAME, INFO)
XERBLA
Definition: xerbla.f:60
logical function lsame(CA, CB)
LSAME
Definition: lsame.f:53
double precision function dlange(NORM, M, N, A, LDA, WORK)
DLANGE returns the value of the 1-norm, Frobenius norm, infinity-norm, or the largest absolute value ...
Definition: dlange.f:114
subroutine dtrtrs(UPLO, TRANS, DIAG, N, NRHS, A, LDA, B, LDB, INFO)
DTRTRS
Definition: dtrtrs.f:140
Here is the call graph for this function:
Here is the caller graph for this function: