Reputation: 393
I am trying to convert a matlab code to C. The matlab code uses a singular value decomposition (SVD) of 3x3 matrices that I implemented in C using numerical reciepes. The matlab code works later with the right singular vectors wich are in some cases that I tested different between Matlab and C, either the second and third columns are swapped or some values are the opposites. In some cases the values are identical. Here are some examples:
Expl1: (Identical values without considering round off error)
Matlab:
-0.3939 0.9010 0.1819
0.6583 0.1385 0.7399
0.6414 0.4112 -0.6477
C:
-0.3939 0.9010 0.1819
0.6584 0.1385 0.7398
0.6414 0.4112 -0.6477
Expl2: (swapped 2nd and 3rd columns)
Matlab:
-0.0309 0.1010 0.9944
-0.0073 -0.9949 0.1008
0.9995 -0.0042 0.0315
C:
-0.0309 0.9944 0.1010
-0.0074 0.1008 -0.9949
0.9995 0.0315 -0.0042
Expl3:(opposite values)
Matlab:
-0.1712 -0.8130 -0.5566
-0.8861 -0.1199 0.4476
0.4306 -0.5698 0.6999
C:
-0.1712 0.8130 0.5566
-0.8861 0.1199 -0.4477
0.4307 0.5698 -0.6999
would this difference cause erroneous results?
Upvotes: 2
Views: 610
Reputation: 383
The right singular vectors of a matrix are unique up to multiplication by a unit-phase factor if it has distinct singular values. When considering real singular vectors, this comes down to a change of sign (more information here).
Also, since singular vectors correspond to certain singular values (diagonal entries of Σ), their order can be changed when the position of the singular values on the diagonal of Σ is changed.
Whether these changes cause erroneous results depends heavily on what you intend to do with the right singular vectors later on in you code.
Upvotes: 2