XLPack 6.1
C/C++ API Reference Manual (Basic module)
Loading...
Searching...
No Matches

◆ _dgels()

void _dgels ( char  trans,
int  m,
int  n,
int  nrhs,
int  lda,
double  a[],
int  ldb,
double  b[],
double  work[],
int  lwork,
int *  info 
)

Solution to overdetermined or underdetermined linear equations Ax = b (Full rank)

Purpose
This routine solves overdetermined or underdetermined real linear systems involving an m x n matrix A, or its transpose, using a QR or 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 underdetermined 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 x nrhs right hand side matrix B and the n x nrhs solution matrix X.
Parameters
[in]trans= 'N': The linear system involves A.
= 'T': The linear system involves A^T.
[in]mNumber of rows of the matrix A. (m >= 0) (If m = 0, returns zero vectors in b[][])
[in]nNumber of columns of the matrix A. (n >= 0) (If n = 0, returns zero vectors in b[][])
[in]nrhsNumber of right hand sides, i.e., number of columns of the matrices B and X. (nrhs >= 0) (If nrhs = 0, returns without computation)
[in]ldaLeading dimension of the two dimensional array a[][]. (lda >= max(1, m))
[in,out]a[][]Array a[la][lda] (la >= n)
[in] m x n matrix A.
[out] m >= n: a[][] is overwritten by details of its QR factorization as returned by dgeqrf.
  m < n: a[][] is overwritten by details of its LQ factorization as returned by dgelqf.
[in]ldbLeading dimension of the two dimensional array b[][]. (ldb >= max(1, m, n))
[in,out]b[][]Array b[lb][ldb] (lb >= nrhs)
[in] Matrix B of right hand side vectors, stored columnwise; B is m x nrhs if trans = 'N', or n x nrhs if trans = 'T'.
[out] If info = 0, b[][] is overwritten by the solution vectors, stored columnwise:
  trans = 'N' and m >= n: Rows 0 to n-1 of b[][] contain the least squares solution vectors; the residual sum of squares for the solution in each column is given by the sum of squares of elements n to m-1 in that column.
  trans = 'N' and m < n: Rows 0 to n-1 of b[][] contain the minimum norm solution vectors.
  trans = 'T' and m >= n: Rows 0 to m-1 of b[][] contain the minimum norm solution vectors.
  trans = 'T' and m < n: Rows 0 to m-1 of b[][] contain the least squares solution vectors; the residual sum of squares for the solution in each column is given by the sum of squares of elements m to n-1 in that column.
[out]work[]Array work[lwork]
Work array.
On exit, if info = 0, work[0] returns the optimal lwork.
[in]lworkThe dimension of the array work[]. (lwork >= max(1, mn + max(mn, nrhs)))
For optimal performance, lwork >= max(1, mn + max(mn, nrhs)*nb), where mn = min(m, n) and nb is the optimum block size.
If lwork = -1, then a workspace query is assumed. The routine only calculates the optimal size of the work[] array, and returns the value in work[0].
[out]info= 0: Successful exit
= -1: The argument trans had an illegal value (trans != 'T' nor 'N')
= -2: The argument m had an illegal value (m < 0)
= -3: The argument n had an illegal value (n < 0)
= -4: The argument nrhs had an illegal value (nrhs < 0)
= -5: The argument lda had an illegal value (lda < max(1, m))
= -7: The argument ldb had an illegal value (ldb < max(1, m, n))
= -10: The argument lwork had an illegal value (lwork too small)
= i > 0: 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.
Reference
LAPACK