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

◆ Zgelsd()

Sub Zgelsd ( M As  Long,
N As  Long,
A() As  Complex,
B() As  Complex,
S() As  Double,
RCond As  Double,
Rank As  Long,
Info As  Long,
Optional Nrhs As  Long = 1 
)

Solution to overdetermined or underdetermined linear equations Ax = b for complex matrices using the singular value decomposition (SVD) (Divide and conquer method)

Purpose
This routine computes the minimum norm solution to a complex linear least squares problem:
minimize 2-norm(| b - A*x |)
using the singular value decomposition (SVD) 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 problem is solved in three steps:
(1) Reduce the coefficient matrix A to bidiagonal form with Householder transformations, reducing the original problem into a "bidiagonal least squares problem" (BLS).
(2) Solve the BLS using a divide and conquer approach.
(3) Apply back all the Householder transformations to solve the original least squares problem.

The effective rank of A is determined by treating as zero those singular values which are less than RCond times the largest singular value.
Parameters
[in]MNumber of rows of the matrix A. (M >= 0) (If M = 0, returns with Rank = 0)
[in]NNumber of columns of the matrix A. (N >= 0) (If N = 0, returns with Rank = 0)
[in,out]A()Array A(LA1 - 1, LA2 - 1) (LA1 >= M, LA2 >= N)
[in] M x N matrix A.
[out] A() has been destroyed.
[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] M x Nrhs right hand side matrix B.
[out] B() is overwritten by the N x Nrhs solution matrix X. If M >= N and Rank = N, the residual sum of squares for the solution in the i-th column is given by the sum of squares of elements N to M-1 in that column.
[out]S()Array S(LS - 1) (LS >= min(M, N))
The singular values of A in decreasing order.
The condition number of A in the 2-norm = S(0)/S(min(M, N)-1).
[in]RCondRCond is used to determine the effective rank of A.
Singular values S(i) <= RCond*S(0) are treated as zero. If RCond < 0, machine precision is used instead.
[out]RankThe effective rank of A, i.e., the number of singular values which are greater than RCond*S(0).
[out]Info= 0: Successful exit
= -1: The argument M had an illegal value (M < 0)
= -2: The argument N had an illegal value (N < 0)
= -3: The argument A() is invalid.
= -4: The argument B() is invalid.
= -5: The argument S() is invalid.
= -9: The argument Nrhs had an illegal value. (Nrhs < 0)
= i > 0: The algorithm for computing the SVD failed to converge; i off-diagonal elements of an intermediate bidiagonal form did not converge to zero.
[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 with Rank = 0) (default = 1)
Reference
LAPACK
Example Program
Compute the least squares solution of the overdetermined linear equations Ax = b and its variance, where
( -0.82+0.83i 0.18-0.94i -0.18-0.12i )
A = ( -0.76-0.24i 0.57-0.16i -0.08-0.27i )
( 1.90+0.26i -0.98+0.54i 0.21+0.28i )
( 0.50-0.30i -0.31+0.37i 0.22+0.19i )
( 1.7126-0.6648i )
B = ( 0.8697+0.7604i )
( -2.1048-1.6171i )
( -0.9297+0.1252i )
Sub Ex_Zgelsd()
Const M = 4, N = 3
Dim A(M - 1, N - 1) As Complex, B(M - 1) As Complex, Ci(N - 1) As Complex
Dim Sigma(N - 1) As Double, RCond As Double, Rank As Long, Info As Long, I As Long
A(0, 0) = Cmplx(-0.82, 0.83): A(0, 1) = Cmplx(0.18, -0.94): A(0, 2) = Cmplx(-0.18, -0.12)
A(1, 0) = Cmplx(-0.76, -0.24): A(1, 1) = Cmplx(0.57, -0.16): A(1, 2) = Cmplx(-0.08, -0.27)
A(2, 0) = Cmplx(1.9, 0.26): A(2, 1) = Cmplx(-0.98, 0.54): A(2, 2) = Cmplx(0.21, 0.28)
A(3, 0) = Cmplx(0.5, -0.3): A(3, 1) = Cmplx(-0.31, 0.37): A(3, 2) = Cmplx(0.22, 0.19)
B(0) = Cmplx(1.7126, -0.6648): B(1) = Cmplx(0.8697, 0.7604)
B(2) = Cmplx(-2.1048, -1.6171): B(3) = Cmplx(-0.9297, 0.1252)
RCond = 0.0001
Call Zgelsd(M, N, A(), B(), Sigma(), RCond, Rank, Info)
If Info <> 0 Then
Debug.Print "Error in Zgelss: Info =", Info
Exit Sub
End If
Debug.Print "X ="
Debug.Print Creal(B(0)), Cimag(B(0)), Creal(B(1)), Cimag(B(1))
Debug.Print Creal(B(2)), Cimag(B(2))
Debug.Print "Rank =", Rank, "Info =", Info
End Sub
Function Cmplx(R As Double, Optional I As Double=0) As Complex
Building complex number
Function Cimag(A As Complex) As Double
Imaginary part of complex number
Function Creal(A As Complex) As Double
Real part of complex number
Function Ci(X As Double, Optional Info As Long) As Double
Cosine integral Ci(x)
Sub Zgelss(M As Long, N As Long, A() As Complex, B() As Complex, S() As Double, RCond As Double, Rank As Long, Info As Long, Optional Nrhs As Long=1)
Solution to overdetermined or underdetermined linear equations Ax = b for complex matrices using the ...
Sub Zgelsd(M As Long, N As Long, A() As Complex, B() As Complex, S() As Double, RCond As Double, Rank As Long, Info As Long, Optional Nrhs As Long=1)
Solution to overdetermined or underdetermined linear equations Ax = b for complex matrices using the ...
Example Results
X =
-0.82 -0.940000000000001 0.740000000000001 0.199999999999998
0.479999999999997 0.209999999999999
Rank = 3 Info = 0