Which SVD algorithm implementation is used in MATLAB?
32 visualizzazioni (ultimi 30 giorni)
I am comparing singular value decomposition function [U,S,V] = svd(A) to some C implementations of the algorithm. However, I am getting somewhat different results: for example, columns of the output matrix U are mixed-up, or some output values have different sign, etc.
Does anyone know which SVD algorithm implementation is used in MATLAB?
Steven Lord il 3 Feb 2022
Keep in mind that the SVD of a matrix is not unique. Quoting from Wikipedia: "Non-degenerate singular values always have unique left- and right-singular vectors, up to multiplication by a unit-phase factor (for the real case up to a sign). Consequently, if all singular values of a square matrix M are non-degenerate and non-zero, then its singular value decomposition is unique, up to multiplication of a column of U by a unit-phase factor and simultaneous multiplication of the corresponding column of V by the same unit-phase factor."
A = magic(5);
[U, S, V] = svd(A);
check1 = U*S*V' - A
U2 = -U;
V2 = -V;
check2 = U2*S*V2' - A
The elements of check1 and check2 both look sufficiently small as to be close enough to 0 to say both (U, S, V) and (U2, S, V2) satisfy the SVD contract. It's possible the columns of the output U aren't "mixed up" they're just a different (correct) answer (when combined with the corresponding V) than you expected.