Hi,
I'm using SVD to solve an AX=B linear system where:
1) rank(A)==rank(x) -> determined system 1 solution
2) rank(A)>rank(x) -> overdetermined system 1 best fit solution
3) rank(A)<rank(x) -> underdetermined system family of solutions
as a reference I'm finding the parameters (a,b,c,d) of a sphere in space, given M number of (X,Y,Z) points, where M>4,M==4,M<4:
'x² + y² + z² + ax + by + cz + d = 0
A-> [Xi,Yi,Zi,1] X->[a,b,c,d] B->[- (xi² + yi² + zi²)] con i=1,..M
I've got a problem when in case rank(A)<rank(x) -> for M=3 only 3(XYZ) points in :
ASVD = A.SingularValueDecomposition
see code below .
But according to SVD theory it should work for this case also (one of the singular value shall be==0). An SVD library in excel I'm using to cross chek the calculations works in all the three situations mentioned above :
Dim Asfera(,) As Double = _
New Double(,) {{-418.746, 310.726, 313.969, 1}, _
{-418.746, 337.451, 229.786, 1}, _
{-305.253, 321.895, 304.895, 1}}
Dim Bsfera() As Double = _
New Double() {-370475.3926, -342022.9957, _
-289756.7461}
Dim SVsfera() As Double = nothing
Dim Xsfera() As Double = NRvb.LLSS(Asfera, Bsfera, SVsfera)
......
......
......
Public Shared Function LLSS(ByVal Ain(,) As Double, _
ByVal Bin() As Double, _
ByRef SingularValues() As Double, _
Optional ByVal RoundZero As Double = 1.0E-20) As Double()
'Linear Least Square Solution A•X = B
Dim TmpMat(,) As Double
Dim A, U As RectangularMatrix
Dim D, D0inv, V As SquareMatrix
Dim B As ColumnVector
Dim ASVD As SingularValueDecomposition
'----------------------------------------------------
LLSS = Nothing
If Ain.Equals(Nothing) Then GoTo ExitLLSS
If Bin.Equals(Nothing) Then GoTo ExitLLSS
'B = A•X
A = New RectangularMatrix(Ain)
B = New ColumnVector(Bin)
ASVD = A.SingularValueDecomposition
.......................
.......................
.......................
ExitLLSS:
Return LLSS
End Function
while if I add a redundant row (a copy of one set of data) to the Asfera and Bsfera matrices it works ! and it returns the last singular value as==0
Dim Asfera(,) As Double = _
New Double(,) {{-418.746, 310.726, 313.969, 1}, _
{-418.746, 337.451, 229.786, 1}, _
{-418.746, 337.451, 229.786, 1}, _
{-305.253, 321.895, 304.895, 1}}
Dim Bsfera() As Double = _
New Double() {-370475.3926, -342022.9957, _
-342022.9957, -289756.7461}