svdcmp with S sorted


plfreeman
08-07-2006, 08:00 AM
I have added svdcmp to an SVD object class that I wrote. When I test the routine, I do get a valid SVD back but the sigular values are not sorted from largest to smallest.

1) Did I make a coding error when I copied over the routine, or is this the expected behaviour for svdcmp?
2) If this is the expected behaviour, what modifications are needed to efficiently sort S, U, and V?

Phil

plfreeman
08-14-2006, 10:46 AM
I added an int array to the SVD object that stores the permutation order required to sort S from largest to smallest. Internally in the object U, S, and V are stored in the permutation that svdcmp returns. The getters then use the permutation array to return the matrices and matrix entries in the sorted order. The only real speed hit is the sorting algorithm that gets run after svdcmp. Since my problem space is very small (n<10), it's really not a penalty.