I find an interesting thing. The matrix results of Matlab SVD decomposition ([U,S,V]=svd(aa)) for the same matrix are different from these of Scilab SVD decomposition matrix. S is same in Matlab and Scilab. But some columns in U and V (SVD decomposition vector) will have different sign with those in Matlab. All their SVD decomposition matrix satisfy USV’ - aa close to zero. Do you know how can I get exactly same U and V (Value and sign) as these in Matlab? Hope I can get help from you.
As you may now, the SVD factorization is necessarily non unique (see e.g. linear algebra - How unique are $U$ and $V$ in the singular value decomposition $A=UDV^\dagger$? - Mathematics Stack Exchange). On this small example Matlab and Scilab yield the same result on a given hardware (Mac Mini M1 with Scilab 2024.0.0) but even Scilab does not give the same result on Windows. This is due to the BLAS (Basic Linear Algebra Subsystem), which for Scilab is different on Windows (Intel MKL BLAS) and macOS and Linux (refBLAS):
Here, since A is of rank 2, the columns 3 to 5 of U are not uniquely determined, even though they are mutually orthogonal and orthogonal to the first two columns.
Hi mottelect, thank you for precise your answer with example code. I am wondering about the sign of SVD decomposition vector matrix. We have a large algorithm, SVD decomposition is only part of this algorithm. In Matlab and Octave, we can get the same results, but in Scilab we can not get same result as that in Matlab and Octave. I studied the program step by step and find difference came from SVD decomposition. Can you give some information which SVD algorithm Scilab used in current code?
Your computations cannot depend on the particular sign of a given component of a singular vector, if they do there is a kind of misconception in your code.
However, a unique normalization can always be applied if you want to have constant results across platform and BLAS. For example, an already normalized (verifying \Vert y\Vert_2=1) eigenvector or singular vector y can be replaced by \operatorname{sign}(y_i)y where y_i is the first nonzero component (among y_1,\dots,y_n).