This project has moved. For the latest updates, please go here.

The result of SVD of Math.Net seems different from Matlab

Nov 6, 2014 at 9:38 AM
Edited Nov 6, 2014 at 9:39 AM
Hi, I tried to move some of my code from matlab to C#, but got a problem.

I have a matrix as
  H =

  -65.2236  -17.8837  -22.4864
  -29.5138  -17.3710   -6.4183
  -13.1218   87.7046  -22.1451
If I find the SVD (USV' = H) with Matlab, I got
U =

    0.1879    0.8883    0.4191
    0.1904    0.3857   -0.9028
   -0.9636    0.2494   -0.0967

S =

   92.6983         0         0
         0   77.7989         0
         0         0    1.6234

V =

   -0.0564   -0.9331    0.3552
   -0.9836   -0.0092   -0.1802
    0.1714   -0.3595   -0.9172
While from Math.Net with H.Svd(true), I got
U = 

 0.187853  -0.888287   0.419114
 0.190403  -0.385682  -0.902771
-0.963565  -0.249389  -0.096681

W = 

92.6983        0        0
      0  77.7989        0
      0        0  1.62345

VT = 

-0.0564014   -0.983579   0.171439
  0.933081  0.00916406   0.359549
  0.355216   -0.180245  -0.917242
Do anyone have idea which one is correct?

Thank you
Coordinator
Nov 6, 2014 at 5:43 PM
Both seem to be correct. Only the singular values are uniquely determined in an SVD, and only if they are ordered the same way. U and V are related, but not uniquely determined.

Note that with Math.NET Numerics, VT is already transposed (hence the T suffix), so H = UWVT. Once you transpose VT back to get V, the only difference between the two solutions is the negation of the middle column of both U and VT.

See How unique (on non-unique) are U and V in Singular Value Decomposition (SVD)? for some details on why this is allowed.

Thanks,
Christoph
Marked as answer by cdrnet on 11/14/2014 at 2:34 AM