|
|
◆ Dgetsls()
| Sub Dgetsls |
( |
Trans As |
String, |
|
|
M As |
Long, |
|
|
N As |
Long, |
|
|
A() As |
Double, |
|
|
B() As |
Double, |
|
|
Info As |
Long, |
|
|
Optional Nrhs As |
Long = 1 |
|
) |
| |
Solution to overdetermined or underdetermined linear equations Ax = b (Full rank) (Tall skinny QR or short wide LQ factorization)
- Purpose
- This routine solves overdetermined or underdetermined real linear systems involving an M x N matrix A, using a tall skinny QR or short wide LQ factorization of A. It is assumed that A has full rank.
The following options are provided:
- If Trans = "N" and M >= N: find the least squares solution of an overdetermined system, i.e., solve the least squares problem
- If Trans = "N" and M < N: find the minimum norm solution of an underdetermined system A * X = B.
- If Trans = "T" and M >= N: find the minimum norm solution of an underdetermined system A^T * X = B.
- 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] | M | Number of rows of the matrix A. (M >= 0) (If M = 0, returns without computation) |
| [in] | N | Number of columns of the matrix A. (N >= 0) (If N = 0, returns without computation) |
| [in,out] | A() | Array A(LA1 - 1, LA2 - 1) (LA1 >= M, LA2 >= N)
[in] M x N matrix A.
[out] A() is overwritten by details of its QR or LQ factorization as returned by Dgeqr or Dgelq. |
| [in,out] | B() | Array B(LB1 - 1, LB2 - 1) (LB1 >= max(M, N), LB2 >= Nrhs) (2D array) or B(LB - 1) (LB >= max(M, N), Nrhs = 1) (1D array)
[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.
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. |
| [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 A() is invalid.
= -5: The argument B() is invalid.
= -7: 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. |
| [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 )
Sub Ex_Dgetsls()
Const M = 4, N = 3
Dim A(M - 1, N - 1) As Double, B(M - 1) As Double, Ci(N - 1) As Double
Dim Info As Long
A(0, 0) = -1.06: A(0, 1) = 0.48: A(0, 2) = -0.04
A(1, 0) = -1.19: A(1, 1) = 0.73: A(1, 2) = -0.24
A(2, 0) = 1.97: A(2, 1) = -0.89: A(2, 2) = 0.56
A(3, 0) = 0.68: A(3, 1) = -0.53: A(3, 2) = 0.08
B(0) = 0.3884: B(1) = 0.112: B(2) = -0.3644: B(3) = -0.0002
Call Dgetsls("N", M, N, A(), B(), Info)
If Info <> 0 Then
Debug.Print "Error in Dgels: Info =", Info
Exit Sub
End If
Debug.Print "X =", B(0), B(1), B(2)
Debug.Print "Var =", Ci(0), Ci(1), Ci(2)
Debug.Print "Info =", Info
End Sub
Function Ci(X As Double, Optional Info As Long) As Double Cosine integral Ci(x)
Sub Dgetsls(Trans As String, M As Long, N As Long, A() As Double, B() As Double, Info As Long, Optional Nrhs As Long=1) Solution to overdetermined or underdetermined linear equations Ax = b (Full rank) (Tall skinny QR or ...
Sub Dgels(Trans As String, M As Long, N As Long, A() As Double, B() As Double, Info As Long, Optional Nrhs As Long=1) Solution to overdetermined or underdetermined linear equations Ax = b (full rank)
Sub Dgecov(Job As Long, N As Long, A() As Double, Ci() As Double, Info As Long) Unscaled covariance matrix of linear least squares problem solved by Dgels
- Example Results
X = -0.820000000000001 -0.94 0.740000000000001
Var = 6.46959967542666 16.7350408218919 18.7177532773229
Info = 0
|