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:

  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 ||.
  1. If TRANS = 'N' and m < n: find the minimum norm solution of an underdetermined system A * X = B.
  2. If TRANS = 'C' and m >= n: find the minimum norm solution of an underdetermined system A**H * X = B.
  3. 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**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 involves A;
  • = 'C': the linear system involves A**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, A is overwritten by details of its QR factorization as returned by CGEQRF;
  • if M < N, A is overwritten by details of its LQ factorization as returned by CGELQF.

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' and m >= n, rows 1 to n 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 the modulus of elements N+1 to M in that column;
  • 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; the residual sum of squares for the solution in each column is given by the sum of squares of the modulus of elements M+1 to N in 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: 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 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:

  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 ||.
  1. If TRANS = 'N' and m < n: find the minimum norm solution of an underdetermined system A * X = B.
  2. If TRANS = 'T' and m >= n: find the minimum norm solution of an underdetermined system A**T * X = B.
  3. 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 πŸ“

TRANS

TRANS is CHARACTER*1

  • = 'N': the linear system involves A;
  • = 'T': the linear system involves A**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, A is overwritten by details of its QR factorization as returned by DGEQRF;
  • if M < N, A is overwritten by details of its LQ factorization as returned by DGELQF.

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 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 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' and m >= n, rows 1 to n 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+1 to M in that column;
  • 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; 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 array B, and its vibe check is LDB >= MAX(1,M,N). Don't fumble this one πŸ’€
  • WORK β€” WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK)). On exit, if INFO = 0, WORK(1) returns the optimal LWORK. It's the little messenger that tells you how much scratch space you actually needed ✨
  • LWORK β€” LWORK is INTEGER. The dimension of the array WORK.

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: 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. No cap, it just tells you the size and dips.
  • INFO β€” INFO is INTEGER, the receipts πŸ“‹
    • = 0: successful exit. slay.
    • < 0: if INFO = -i, the i-th argument had an illegal value. something you passed was lowkey not it.
    • > 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. 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:

  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 ||.
  1. If TRANS = 'N' and m < n: find the minimum norm solution of an underdetermined system A * X = B.
  2. If TRANS = 'T' and m >= n: find the minimum norm solution of an underdetermined system A**T * X = B.
  3. 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. 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 involves A;
    • = 'T': the linear system involves A**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 REAL array, dimension (LDA,N).

On entry, the M-by-N matrix A. On exit:

  • if M >= N, A is overwritten by details of its QR factorization as returned by SGEQRF;
  • if M < N, A is overwritten by details of its LQ factorization as returned by SGELQF.

it goes in as your matrix and comes out as a factorization's whole diary πŸ“–

  • LDA β€” LDA is INTEGER. The leading dimension of the array A. 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' and m >= n, rows 1 to n 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+1 to M in that column;
  • 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; 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 array B. LDB >= MAX(1,M,N).
  • WORK β€” WORK is REAL 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. the classic "just asking, not committing" move πŸ’…
  • 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 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:

  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 underdetermined system A**H * 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**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 involves A;
  • = 'C': the linear system involves A**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, A is overwritten by details of its QR factorization as returned by ZGEQRF;
  • if M < N, A is overwritten by details of its LQ factorization as returned by ZGELQF.

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' and m >= n, rows 1 to n 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 the modulus of elements N+1 to M in that column;
  • 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; the residual sum of squares for the solution in each column is given by the sum of squares of the modulus of elements M+1 to N in 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: 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 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