06-18-2009 09:05 AM
I'm doing an eigenvalue problem and solved it first in MatLab 5.3 before doing the (soft) real-time software in CVI 8.5.1.
I've run into a problem.
In MatLab I do: [U,S,V]=svd(d,0);
In CVI I do: SVD( input, n, 3, U, S, V);
where d = input, both are n by 3. N is a number between 70 and 700.
My problem is the first two columns of the U and V output matrices in CVI are the Matlab values multiplied by -1.
The third columns of U and V are identical in both CVI and Matlab, as are the singular values, S.
This changes the azimuts and elevations of the eigenvectors relative to the original space.
Which is correct? I can't find any linear algebra to explain the issue.
I've verified the input data is identical in both programs.
--wally.
06-18-2009 10:29 AM - edited 06-18-2009 10:37 AM
I'm more confused than ever.
Matlab 2008b V & U outputs match CVI in columns 1&2 but column 3 is now -1 times the CVI results in column 3 for V & U 😞
Multiplying both V & U by -1 between the different versions of Matlab doesn't really change anything, but the CVI result seems inconsistent with either MatLab convention.
--wally.
06-19-2009 04:07 PM
Wally,
Can you post some example matrices? It would be interesting to try the input on a few different versions of CVI on my side and see if the V and U matrices and the S vector are the same as yours, whether in CVI 8.5.1 or in either version of Matlab you tried. If you could post an example input matrix and example outputs, that would be helpful.
06-19-2009 05:06 PM
Well I could, but the question becomes where to post them and in what format?
I think the fundamental answer is the positive direction of the eigen(singlular)vectors is arbitrary and thus depends on the implimentation details.
I was suprised to find Matlab 5.3 and 2008b were different from each other as well and both being different from CVI 8.5.1.
In all cases the numerical values of the U and V outputs are the same, its just the signs on some or all of the columns disagree. Which columns have the signs reversed is data dependent for each SVD routine, occasionally two will agree. Multipling the USV' outputs in all cases recovers the original input matrix to within roundoff error.
--wally.
06-22-2009 04:32 PM
If you'd like to post the matrices, you can just paste them into a response, or create a text file and attach it to a post, or upload a text file to our ftp site at ftp://ftp.ni.com/incoming/.
As you have discovered, the different SVD routines return slightly different results due to using different methods (and it appears that Matlab switched methods between 5.3 and 2008b), but as you mentioned, multiplying the outputs (USV') gets you your original matrix, so all of the routines are "correct" and none is "more correct" than the other. I don't have any more details about our implementation other than what is mentioned in the LabVIEW SVD help here: http://zone.ni.com/reference/en-XX/help/371361E-01/gmath/svd_decomp/ .
06-23-2009 09:23 AM
I don't really see any reason to post a sample data matrix.
The mathematical answer is while the singular values are unique, the singular vectors are only unique to a constant (-1 being a perfectly good constant) so while they define a set of prefered axes, they can't determine which direction along those axes should be "positive". Different implimentations yield different positive directions which fundamentally are arbitrary with resect to positive/negative.
I consider the issue resolved, I was looking to get something from the routine that it can't really do.
--wally.