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

◆ zgetsls()

subroutine zgetsls ( character trans,
integer m,
integer n,
integer nrhs,
complex*16, dimension( lda, * ) a,
integer lda,
complex*16, dimension( ldb, * ) b,
integer ldb,
complex*16, dimension( * ) work,
integer lwork,
integer info )

ZGETSLS

Purpose:
!>
!> ZGETSLS solves overdetermined or underdetermined complex 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, and only a rudimentary protection
!> against rank-deficient matrices is provided. This subroutine only detects
!> exact rank-deficiency, where a diagonal element of the triangular factor
!> of A is exactly zero.
!>
!> It is conceivable for one (or more) of the diagonal elements of the triangular
!> factor of A to be subnormally tiny numbers without this subroutine signalling
!> an error. The solutions computed for such almost-rank-deficient matrices may
!> be less accurate due to a loss of numerical precision.
!>
!>
!> 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 = 'C' and m >= n:  find the minimum norm solution of
!>    an undetermined system A**T * X = B.
!>
!> 4. If TRANS = 'C' 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;
!>          = 'C': the linear system involves A**H.
!> 
[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 COMPLEX*16 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 ZGEQR or ZGELQ.
!> 
[in]LDA
!>          LDA is INTEGER
!>          The leading dimension of the array A.  LDA >= max(1,M).
!> 
[in,out]B
!>          B is COMPLEX*16 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 = 'C'.
!>          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 = 'C' and m >= n, rows 1 to M of B contain the
!>          minimum norm solution vectors;
!>          if TRANS = 'C' 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) COMPLEX*16 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. LWORK >= 1.
!>          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 exactly 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 169 of file zgetsls.f.

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