Which SVD algorithm implementation is used in MATLAB?

14 次查看(过去 30 天)
Hi,
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?
  4 个评论
Walter Roberson
Walter Roberson 2022-2-22
I am not sure how it is relevant that MKL is copyrighted? LAPACK is copyrighted too, with a modified BSD license.
MKL is probably closed source, but you did not indicate that you needed source access; for everything you have mentioned so far you only need to be able to link against it.

请先登录,再进行评论。

回答(1 个)

Steven Lord
Steven Lord 2022-2-3
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);
format longg
check1 = U*S*V' - A
check1 = 5×5
1.0e+00 * 3.5527136788005e-15 -1.4210854715202e-14 -1.93178806284777e-14 2.48689957516035e-14 1.59872115546023e-14 0 -1.77635683940025e-14 -1.4210854715202e-14 2.48689957516035e-14 1.77635683940025e-14 -3.5527136788005e-15 6.21724893790088e-15 1.77635683940025e-14 7.105427357601e-15 7.105427357601e-15 -3.5527136788005e-15 3.19744231092045e-14 1.77635683940025e-14 -1.77635683940025e-14 -8.43769498715119e-15 5.32907051820075e-15 3.5527136788005e-14 1.4210854715202e-14 -2.17603712826531e-14 -1.95399252334028e-14
U2 = -U;
V2 = -V;
check2 = U2*S*V2' - A
check2 = 5×5
1.0e+00 * 3.5527136788005e-15 -1.4210854715202e-14 -1.93178806284777e-14 2.48689957516035e-14 1.59872115546023e-14 0 -1.77635683940025e-14 -1.4210854715202e-14 2.48689957516035e-14 1.77635683940025e-14 -3.5527136788005e-15 6.21724893790088e-15 1.77635683940025e-14 7.105427357601e-15 7.105427357601e-15 -3.5527136788005e-15 3.19744231092045e-14 1.77635683940025e-14 -1.77635683940025e-14 -8.43769498715119e-15 5.32907051820075e-15 3.5527136788005e-14 1.4210854715202e-14 -2.17603712826531e-14 -1.95399252334028e-14
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.

类别

Help CenterFile Exchange 中查找有关 Linear Algebra 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by