XLPack 7.0
XLPack Numerical Library (Excel Worksheet Functions) Reference Manual
Loading...
Searching...
No Matches

◆ WDgelsy()

Function WDgelsy ( M As  Long,
N As  Long,
A As  Variant,
B As  Variant,
Optional Nrhs As  Long = 1,
Optional RCond As  Double = 1.0E-15,
Optional Cov As  String = "N" 
)

Solution to overdetermined or underdetermined linear equations Ax = b using a complete orthogonal factorization

Purpose
WDgelsy computes the minimum-norm solution to a real linear least squares problem:
minimize || A * X - B ||
using a complete orthogonal factorization of A. A is an M x N matrix which may be rank-deficient.

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.

The routine first computes a QR factorization with column pivoting:
A * P = Q * [ R11 R12 ]
[ 0 R22 ]
with R11 defined as the largest leading submatrix whose estimated condition number is less than 1/RCond. The order of R11, rank, is the effective rank of A.

Then, R22 is considered to be negligible, and R12 is annihilated by orthogonal transformations from the right, arriving at the complete orthogonal factorization:
A * P = Q * [ T11 0 ] * Z
[ 0 0 ]
The minimum-norm solution is then
X = P * Z^T [ T11^(-1)*Q1^T*B ]
[ 0 ]
where Q1 consists of the first rank columns of Q.
Returns
If M >= N (N+2 x Nrhs (Cov = "N"), N+2 x Nrhs+1 (Cov = "D") or N+2 x Nrhs+N (Cov = "C"))
Columns 1 to NrhsColumn Nrhs+1 (if Cov = "D")Columns Nrhs+1 to Nrhs+N (if Cov = "C")
Rows 1 to NLeast squares solution vector xVariance (diagonal elements of variance-covariance matrix)Variance-covariance matrix
Row N+1Effective rank (column 1)00
Row N+2Return code (column 1)00
If M < N (N+2 x Nrhs)
Columns 1 to Nrhs
Rows 1 to NMinimum norm solution vector x
Row N+1Effective rank (column 1)
Row N+2Return code (column 1)

Return code
= 0: Successful exit.
= i > 0: The i-th diagonal element of the triangular factor of A is zero.
Parameters
[in]MNumber of rows of the matrix A. (M >= 1)
[in]NNumber of columns of the matrix A. (N >= 1)
[in]A(M x N) M x N coefficient matrix A. (May be rank-deficient)
[in]B(M x Nrhs) Right hand side matrix B.
[in]Nrhs(Optional)
Number of columns of right hand side matrix B. (Nrhs >= 1) (default = 1)
[in]RCond(Optional)
RCond is used to determine the effective rank of A, which is defined as the order of the largest leading triangular submatrix R11 in the QR factorization with pivoting of A, whose estimated condition number < 1/RCond. (default = 1.0e-15)
[in]Cov(Optional)
= "N": Do not compute variance-covariance matrix.
= "D": Compute diagonal elements of variance-covariance matrix. (If M >= N)
= "C": Compute variance-covariance matrix. (If M >= N)
(default = "N")
Reference
LAPACK
Example
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 )

WDgelsy