|This subroutine computes the linear least squares solution for a general |matrix A or its transpose using a QR factorization |without column pivoting, where A is assumed to have full |rank.
|The following options are provided: |
A, B, work | Subroutine |
Long-precision real | DGELS |
Fortran | CALL DGELS (transa, m, n, nrhs, a, lda, b, ldb, work, lwork, info) |
C and C++ | dgels (transa,m, n, nrhs, a, lda, b ,ldb, work, lwork, info); |
PL/I | CALL DGELS (transa,m, n, nrhs, a, lda, b ,ldb, work, lwork, info); |
|If transa = 'N', matrix A is |used.
|If transa = 'T', matrix AT |is used.
|Specified as: a single character; transa = |'N' or 'T'.
|Specified as: a fullword integer; |m >= 0.
|Specified as: a fullword integer; |n >= 0.
|Specified as: a fullword integer; |nrhs >= 0.
|Specified as: an lda by (at least) n array, |containing numbers of the data type indicated in Table 120.
|Specified as: a fullword integer; lda > 0 |and lda >= m.
|If transa = 'N', matrix B has |m rows and nrhs columns.
|If transa = 'T', matrix B has |n rows and nrhs columns.
|Specified as: the ldb by (at least) nrhs array, |containing numbers of the data type indicated in Table 120.
|Specified as: a fullword integer; ldb > 0 |and ldb >= max(m,n).
|If lwork = 0, work is ignored.
|If lwork <> 0, work is the work area used by |this subroutine, where: |
|Specified as: an area of storage containing numbers of data type |indicated in Table 120.
|Specified as: a fullword integer; where: |
|lwork >= max(1, |mn + max(mn, nrhs))
|where mn = min(m, n). |
|Returned as: an lda by (at least) n array, |containing numbers of the data type indicated in Table 120.
|Returned as: an ldb by (at least) nrhs array, |containing numbers of the data type indicated in Table 120.
|If lwork <> 0 and lwork <> -1, |its size is (at least) of length lwork.
|If lwork = -1, its size is (at least) of length |1.
|Returned as: an area of storage, where:
|If lwork >= 1 or lwork = -1, then |work1 is set to the optimal lwork value and |contains numbers of the data type indicated in Table 120. Except for work1, the contents |of work are overwritten on return.
|Returned as: a fullword integer; |info = 0. |
|This subroutine computes the linear least squares solution for a general |matrix A or its transpose using a QR factorization |without column pivoting, where A is assumed to have full |rank.
|The following options are provided: |
|If (m = 0 and n = 0) or |nrhs = 0, then no computation is performed and the subroutine |returns after doing some parameter checking.
|See reference [62].
|lwork = 0 and unable to allocate work space.
|None.
|This example finds the least squares solution of an overdetermined |system; that is, it solves the least squares problem: minimize |||B-AX||. Matrix |A is size 6 × 2 and matrix B is size |6 × 3.
| TRANSA M N NRHS A LDA B LDB WORK LWORK INFO | | | | | | | | | | | | |CALL DGELS ( 'N' , 6 , 2 , 3 , A , 6 , B, 6, WORK, 0, INFO )
|General matrix A of size 6 × 2:
| * * | | .000000000 2.000000000 | | | 2.000000000 -1.000000000 | |A = | 2.000000000 -1.000000000 | | | .000000000 1.500000000 | | | 2.000000000 -1.000000000 | | | 2.000000000 -1.000000000 | | * *
|General matrix B of size 6 × 3:
| * * | | 1.000000000 4.000000000 1.000000000 | | | 1.000000000 1.000000000 2.000000000 | |B = | 1.000000000 -1.000000000 1.000000000 | | | 1.000000000 3.000000000 2.000000000 | | | 1.000000000 1.000000000 1.000000000 | | | 1.000000000 -1.000000000 1.000000000 | | * *
|Output:
|General matrix A is overwritten.
|Solution matrix X overwrites B:
| * * | | .780000000 1.000000000 1.025000000 | | | .560000000 2.000000000 .800000000 | |B = | .042857143 -1.285714286 -.250000000 | | | .185714286 .428571429 1.250000000 | | | .042857143 .714285714 -.250000000 | | | .042857143 -1.285714286 -.250000000 | | * *
|INFO = 0
|This example finds the minimum norm solution of an underdetermined system |ATX = B. |Matrix A is size 6 × 2. On input, matrix |B is size 2 × 1, stored in array b with |leading dimension 6.
| TRANSA M N NRHS A LDA B LDB WORK LWORK INFO | | | | | | | | | | | | |CALL DGELS ( 'T' , 6 , 2 , 1 , A , 6 , B, 6, WORK, 0, INFO )
|General matrix A of size 6 × 2:
| * * | | .000000000 2.000000000 | | | 2.000000000 -1.000000000 | |A = | 2.000000000 -1.000000000 | | | .000000000 1.500000000 | | | 2.000000000 -1.000000000 | | | 2.000000000 -1.000000000 | | * *
|General matrix B of size 2 × 1:
| * * |B = | 1.000000000 | | | 1.000000000 | | | . | | | . | | | . | | | . | | * *
|Output:
|General matrix A is overwritten.
|Solution matrix X overwrites B:
| * * | | .480000000 | | | .125000000 | |B = | .125000000 | | | .360000000 | | | .125000000 | | | .125000000 | | * *
|INFO = 0
|This example finds the minimum norm solution of an underdetermined system |AX = B. Matrix |A is size 3 × 4. On input, matrix B |is size 3 × 4, stored in array b with leading dimension |4.
| TRANSA M N NRHS A LDA B LDB WORK LWORK INFO | | | | | | | | | | | | |CALL DGELS ( 'N' , 3 , 4 , 4 , A , 3 , B, 4, WORK, 0, INFO )
|General matrix A of size 3 × 4:
| * * | | .500000000 .500000000 .500000000 .500000000 | |A = | .500000000 -1.500000000 .500000000 -1.500000000 | | | 1.000000000 1.000000000 .000000000 1.000000000 | | * *
|General matrix B of size 3 × 4:
| * * | | 1.000000000 1.000000000 1.000000000 .000000000 | |B = | 1.000000000 -1.000000000 2.500000000 1.000000000 | | | 1.000000000 1.000000000 3.000000000 .000000000 | | | . . . . | | * *
|Output:
|General matrix A is overwritten.
|Solution matrix X overwrites B:
| * * | | 1.000000000 .000000000 3.500000000 .500000000 | |B = | .000000000 .500000000 -.250000000 -.250000000 | | | 1.000000000 1.000000000 -1.000000000 .000000000 | | | .000000000 .500000000 -.250000000 -.250000000 | | * *
|INFO = 0
|This example finds the least squares solution of an overdetermined |system; that is, it solves the least squares problem: minimize |||B-ATX||. |Matrix A is size 3 × 4. On input, matrix |B is size 4 × 4.
| TRANSA M N NRHS A LDA B LDB WORK LWORK INFO | | | | | | | | | | | | |CALL DGELS ( 'T' , 3 , 4 , 4 , A , 3 , B , 4 , WORK , 0 , INFO )
|General matrix A of size 3 × 4:
| * * | | .500000000 .500000000 .500000000 .500000000 | |A = | .500000000 -1.500000000 .500000000 -1.500000000 | | | 1.207106781 -.500000000 .207106781 -.500000000 | | * *
|General matrix B of size 4 × 4:
| * * | | 1.000000000 1.000000000 1.000000000 .000000000 | |B = | 1.000000000 -1.000000000 2.000000000 2.414213562 | | | 1.000000000 1.000000000 3.000000000 .000000000 | | | 1.000000000 -1.000000000 4.000000000 -.414213562 | | * *
|Output:
|General matrix A is overwritten.
|Solution matrix X overwrites B:
| * * | | 2.000000000 1.000000000 6.121320344 .500000000 | |B = | .000000000 1.000000000 .707106781 -.500000000 | | | .000000000 .000000000 -2.000000000 .000000000 | | | .000000000 .000000000 1.414213562 -2.000000000 | | * *
|INFO = 0