gels(3)
π gels(3) π
okay so bestie, welcome to the <gels> page from the <Library Functions Manual> β the manual name is literally right there in the header, and the whole vibe is least squares using QR/LQ. Itβs giving linear algebra but make it fashion. π¦
πΈ NAME πΈ
gels β gels: least squares using QR/LQ
β¨ SYNOPSIS β¨
π Functions π
cgelsβ CGELS solves overdetermined or underdetermined systems for GE matrices
subroutine cgels (trans, m, n, nrhs, a, lda, b, ldb, work, lwork, info)
dgelsβ DGELS solves overdetermined or underdetermined systems for GE matrices
subroutine dgels (trans, m, n, nrhs, a, lda, b, ldb, work, lwork, info)
sgelsβ SGELS solves overdetermined or underdetermined systems for GE matrices
subroutine sgels (trans, m, n, nrhs, a, lda, b, ldb, work, lwork, info)
zgelsβ ZGELS solves overdetermined or underdetermined systems for GE matrices
subroutine zgels (trans, m, n, nrhs, a, lda, b, ldb, work, lwork, info)
π Detailed Description π
This is the big-picture section, bestie. The original page doesnβt put extra prose here β itβs just the heading doing its main character thing before we get into the actual function docs. π
π Function Documentation π
π§ subroutine cgels
subroutine cgels (character trans, integer m, integer n, integer nrhs,
complex, dimension( lda, * ) a, integer lda, complex, dimension( ldb, *
) b, integer ldb, complex, dimension( * ) work, integer lwork, integer
info)
CGELS solves overdetermined or underdetermined systems for GE matrices
π Purpose π
okay so CGELS solves overdetermined or underdetermined complex linear systems involving an M-by-N matrix A, or its conjugate-transpose, using a QR or 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:
- If
TRANS = 'N'andm >= n: find the least squares solution of an overdetermined system, i.e., solve the least squares problem
minimize || B - A*X ||.
- If
TRANS = 'N'andm < n: find the minimum norm solution of an underdetermined systemA * X = B. - If
TRANS = 'C'andm >= n: find the minimum norm solution of an underdetermined systemA**H * X = B. - If
TRANS = 'C'andm < n: find the least squares solution of an overdetermined system, i.e., solve the least squares problem
minimize || B - A**H * 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 π
TRANS
TRANS is CHARACTER*1
= 'N': the linear system involvesA;= 'C': the linear system involvesA**H.
M
M is INTEGER
The number of rows of the matrix A. M >= 0.
N
N is INTEGER
The number of columns of the matrix A. N >= 0.
NRHS
NRHS is INTEGER
The number of right hand sides, i.e., the number of columns of the matrices B and X. NRHS >= 0.
A
A is COMPLEX array, dimension (LDA,N)
On entry, the M-by-N matrix A.
On exit:
- if
M >= N,Ais overwritten by details of its QR factorization as returned byCGEQRF; - if
M < N,Ais overwritten by details of its LQ factorization as returned byCGELQF.
LDA
LDA is INTEGER
The leading dimension of the array A. LDA >= max(1,M).
B
B is COMPLEX 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'andm >= n, rows 1 tonofBcontain the least squares solution vectors; the residual sum of squares for the solution in each column is given by the sum of squares of the modulus of elementsN+1toMin that column; - if
TRANS = 'N'andm < n, rows 1 toNofBcontain the minimum norm solution vectors; - if
TRANS = 'C'andm >= n, rows 1 toMofBcontain the minimum norm solution vectors; - if
TRANS = 'C'andm < n, rows 1 toMofBcontain the least squares solution vectors; the residual sum of squares for the solution in each column is given by the sum of squares of the modulus of elementsM+1toNin that column.
LDB
LDB is INTEGER
The leading dimension of the array B. LDB >= MAX(1,M,N).
WORK
WORK is COMPLEX array, dimension (MAX(1,LWORK))
On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
LWORK
LWORK is INTEGER
The 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, returns this value as the first entry of the WORK array, and no error message related to LWORK is issued by XERBLA.
INFO
INFO is INTEGER
= 0: successful exit< 0: ifINFO = -i, thei-th argument had an illegal value> 0: ifINFO = i, thei-th diagonal element of the triangular factor ofAis exactly zero, so thatAdoes 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 190 of file cgels.f.
π§ subroutine dgels
subroutine dgels (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)
DGELS solves overdetermined or underdetermined systems for GE matrices
π Purpose π
okay so DGELS solves overdetermined or underdetermined real linear systems involving an M-by-N matrix A, or its transpose, using a QR or 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:
- If
TRANS = 'N'andm >= n: find the least squares solution of an overdetermined system, i.e., solve the least squares problem
minimize || B - A*X ||.
- If
TRANS = 'N'andm < n: find the minimum norm solution of an underdetermined systemA * X = B. - If
TRANS = 'T'andm >= n: find the minimum norm solution of an underdetermined systemA**T * X = B. - If
TRANS = 'T'andm < 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 π
TRANS
TRANS is CHARACTER*1
= 'N': the linear system involvesA;= 'T': the linear system involvesA**T.
M
M is INTEGER
The number of rows of the matrix A. M >= 0.
N
N is INTEGER
The number of columns of the matrix A. N >= 0.
NRHS
NRHS is INTEGER
The number of right hand sides, i.e., the number of columns of the matrices B and X. NRHS >=0.
A
A is DOUBLE PRECISION array, dimension (LDA,N)
On entry, the M-by-N matrix A.
On exit:
- if
M >= N,Ais overwritten by details of its QR factorization as returned byDGEQRF; - if
M < N,Ais overwritten by details of its LQ factorization as returned byDGELQF.
LDA
LDA is INTEGER
The leading dimension of the array A. LDA >= max(1,M).
B
B(picking right back up mid-B, iykyk π«Ά) βB is DOUBLE PRECISION array, dimension (LDB,NRHS). On entry, it's the matrixBof right hand side vectors, stored columnwise;Bis M-by-NRHS ifTRANS = 'N', or N-by-NRHS ifTRANS = 'T'.
On exit, if INFO = 0, B gets overwritten by the solution vectors, also stored columnwise, and which rows hold what totally depends on your situation bestie, so buckle up:
- if
TRANS = 'N'andm >= n, rows 1 to n ofBcontain 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+1 to M in that column; - if
TRANS = 'N'andm < n, rows 1 to N ofBcontain the minimum norm solution vectors; - if
TRANS = 'T'andm >= n, rows 1 to M ofBcontain the minimum norm solution vectors; - if
TRANS = 'T'andm < n, rows 1 to M ofBcontain 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+1 to N in that column.
LDBβLDB is INTEGER. It's the leading dimension of the arrayB, and its vibe check isLDB >= MAX(1,M,N). Don't fumble this one πWORKβWORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK)). On exit, ifINFO = 0,WORK(1)returns the optimalLWORK. It's the little messenger that tells you how much scratch space you actually needed β¨LWORKβLWORK is INTEGER. The dimension of the arrayWORK.
The bare minimum is:
LWORK >= max( 1, MN + max( MN, NRHS ) ).
But for optimal performance, you want:
LWORK >= max( 1, MN + max( MN, NRHS )*NB ).
where MN = min(M,N) and NB is the optimum block size. Like, minimum is fine, but optimal is that girl π
And the iconic shortcut: ifLWORK = -1, then a workspace query is assumed; the routine only calculates the optimal size of theWORKarray, returns this value as the first entry of theWORKarray, and no error message related toLWORKis issued byXERBLA. No cap, it just tells you the size and dips.
INFOβINFO is INTEGER, the receipts π= 0: successful exit. slay.< 0: ifINFO = -i, the i-th argument had an illegal value. something you passed was lowkey not it.> 0: ifINFO = i, the i-th diagonal element of the triangular factor ofAis exactly zero, so thatAdoes not have full rank; the least squares solution could not be computed. that's the "bestie the matrix said no" case π
π«Ά Author π«Ά
Univ. of Tennessee
Univ. of California Berkeley
Univ. of Colorado Denver
NAG Ltd.
Definition at line 191 of file dgels.f.
π₯ subroutine sgels π₯
subroutine sgels (character trans, integer m, integer n, integer nrhs, real,
dimension( lda, * ) a, integer lda, real, dimension( ldb, * ) b, integer
ldb, real, dimension( * ) work, integer lwork, integer info)
SGELS solves overdetermined or underdetermined systems for GE matrices β¨
π Purpose π
SGELS solves overdetermined or underdetermined real linear systems involving an M-by-N matrix A, or its transpose, using a QR or 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.
And here's the part you need to hear, bestie π: 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. So like... it didn't fail, but it also didn't thrive. be aware π
The following options are provided:
- If
TRANS = 'N'andm >= n: find the least squares solution of an overdetermined system, i.e., solve the least squares problem
minimize || B - A*X ||.
- If
TRANS = 'N'andm < n: find the minimum norm solution of an underdetermined systemA * X = B. - If
TRANS = 'T'andm >= n: find the minimum norm solution of an underdetermined systemA**T * X = B. - If
TRANS = 'T'andm < 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. One call, so many vectors, we love to see it π
πΈ Parameters πΈ
TRANSβTRANS is CHARACTER*1, and it picks the whole plotline of the routine:= 'N': the linear system involvesA;= 'T': the linear system involvesA**T.
MβM is INTEGER. The number of rows of the matrixA.M >= 0.NβN is INTEGER. The number of columns of the matrixA.N >= 0.NRHSβNRHS is INTEGER. The number of right hand sides, i.e., the number of columns of the matricesBandX.NRHS >=0.AβA is REAL array, dimension (LDA,N).
On entry, the M-by-N matrix A. On exit:
- if
M >= N,Ais overwritten by details of its QR factorization as returned bySGEQRF; - if
M < N,Ais overwritten by details of its LQ factorization as returned bySGELQF.
it goes in as your matrix and comes out as a factorization's whole diary π
LDAβLDA is INTEGER. The leading dimension of the arrayA.LDA >= max(1,M).BβB is REAL 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 β and the cases go like this:
- if
TRANS = 'N'andm >= n, rows 1 to n ofBcontain 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+1 to M in that column; - if
TRANS = 'N'andm < n, rows 1 to N ofBcontain the minimum norm solution vectors; - if
TRANS = 'T'andm >= n, rows 1 to M ofBcontain the minimum norm solution vectors; - if
TRANS = 'T'andm < n, rows 1 to M ofBcontain 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+1 to N in that column.
LDBβLDB is INTEGER. The leading dimension of the arrayB.LDB >= MAX(1,M,N).WORKβWORK is REAL array, dimension (MAX(1,LWORK)). On exit, ifINFO = 0,WORK(1)returns the optimalLWORK.LWORKβLWORK is INTEGER. The dimension of the arrayWORK.
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.
IfLWORK = -1, then a workspace query is assumed; the routine only calculates the optimal size of theWORKarray, returns this value as the first entry of theWORKarray, and no error message related toLWORKis issued byXERBLA. the classic "just asking, not committing" move π
INFOβINFO is INTEGER= 0: successful exit< 0: ifINFO = -i, the i-th argument had an illegal value> 0: ifINFO = i, the i-th diagonal element of the triangular factor ofAis exactly zero, so thatAdoes 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 191 of file sgels.f.
π¦ subroutine zgels π¦
subroutine zgels (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)
ZGELS solves overdetermined or underdetermined systems for GE matrices β and yes bestie, it's the complex*16 one, the whole squad's here π
π Purpose π
okay so this is exactly where our page break lands β ZGELS's purpose section picks up in the next part, and it is lowkey worth the wait β¨
Okay so real talk, ZGELS is the moment: it solves overdetermined or underdetermined complex linear systems with an M-by-N matrix A, or its conjugate-transpose, using a QR or LQ factorization of A. β¨
Bestie, 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:
- If
TRANS = 'N'andm >= n: find the least squares solution of an overdetermined system, i.e., solve the least squares problemminimize || B - A*X ||. π«Ά - If
TRANS = 'N'andm < n: find the minimum norm solution of an underdetermined systemA * X = B. - If
TRANS = 'C'andm >= n: find the minimum norm solution of an underdetermined systemA**H * X = B. - If
TRANS = 'C'andm < n: find the least squares solution of an overdetermined system, i.e., solve the least squares problemminimize || B - A**H * 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 β¨
TRANS
TRANS is CHARACTER*1 π
= 'N': the linear system involvesA;= 'C': the linear system involvesA**H.
M
M is INTEGER β¨ The number of rows of the matrix A. M >= 0.
N
N is INTEGER π The number of columns of the matrix A. N >= 0.
NRHS
NRHS is INTEGER π The number of right hand sides, i.e., the number of columns of the matrices B and X. NRHS >= 0.
A
A is COMPLEX*16 array, dimension (LDA,N) π
On entry, the M-by-N matrix A.
- if
M >= N,Ais overwritten by details of its QR factorization as returned byZGEQRF; - if
M < N,Ais overwritten by details of its LQ factorization as returned byZGELQF.
LDA
LDA is INTEGER The leading dimension of the array A. LDA >= max(1,M).
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'andm >= n, rows1tonofBcontain the least squares solution vectors; the residual sum of squares for the solution in each column is given by the sum of squares of the modulus of elementsN+1toMin that column; - if
TRANS = 'N'andm < n, rows1toNofBcontain the minimum norm solution vectors; - if
TRANS = 'C'andm >= n, rows1toMofBcontain the minimum norm solution vectors; - if
TRANS = 'C'andm < n, rows1toMofBcontain the least squares solution vectors; the residual sum of squares for the solution in each column is given by the sum of squares of the modulus of elementsM+1toNin that column.
LDB
LDB is INTEGER The leading dimension of the array B. LDB >= MAX(1,M,N).
WORK
WORK is COMPLEX*16 array, dimension (MAX(1,LWORK)) β On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
LWORK
LWORK is INTEGER π₯ The 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, returns this value as the first entry of the WORK array, and no error message related to LWORK is issued by XERBLA.
INFO
INFO is INTEGER π
= 0: successful exit< 0: ifINFO = -i, thei-th argument had an illegal value> 0: ifINFO = i, thei-th diagonal element of the triangular factor ofAis exactly zero, so thatAdoes 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 190 of file zgels.f. π
β¨ Author (Doxygen's little auto-note) β¨
Generated automatically by Doxygen for LAPACK from the source code.
Okay bye bestie β this iconic page is from LAPACK, version 3.12.0, and itβs gels(3). Stay slay and keep your matrices full-rank. π
β¨
π¦ where this page comes from
- arch rolling: lapack-doc 3.12.1-2 Β· custom
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms