XLPack 6.1
Python API Reference Manual
Loading...
Searching...
No Matches

◆ dgels()

def dgels ( trans  ,
,
,
,
,
nrhs  = 1 
)

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

Purpose
dgels 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.
Returns
info (int)
= 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 a is invalid.
= -5: The argument b is invalid.
= -6: The argument nrhs had an illegal value (nrhs < 0)
= 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.
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,out]aNumpy ndarray (2-dimensional, float, m x 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,out]b[][]Numpy ndarray (1 or 2-dimensional, float, max(m, n) or max(m, n) x 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.
[in]nrhs(Optional)
Number of right hand sides, i.e., number of columns of the matrices B and X. (nrhs >= 0) (If nrhs = 0, returns without computation) (default = 1)
Reference
LAPACK
Example Program
Compute the least squares solution of the overdetermined linear equations Ax = b and its variance, where
( -1.06 0.48 -0.04 )
A = ( -1.19 0.73 -0.24 )
( 1.97 -0.89 0.56 )
( 0.68 -0.53 0.08 )
( 0.3884 )
B = ( 0.1120 )
( -0.3644 )
( -0.0002 )
def TestDgels():
m = 4
n = 3
a = np.array([
[-1.06, -1.19, 1.97, 0.68],
[0.48, 0.73, -0.89, -0.53],
[-0.04, -0.24, 0.56, 0.08]])
b = np.array([0.3884, 0.1120, -0.3644, -0.0002])
info = dgels('N', m, n, a, b)
print(b[0:n], info)
if info == 0:
ci = np.empty(n)
info = dgecov(0, n, a, ci)
print(ci, info)
def dgels(trans, m, n, a, b, nrhs=1)
Solution to overdetermined or underdetermined linear equations Ax = b (full rank)
def dgecov(job, n, a, ci)
Unscaled covariance matrix of linear least squares problem solved by dgels
Example Results
>>> TestDgels()
[-0.82 -0.94 0.74] 0
[ 6.46959968 16.73504082 18.71775328] 0