R and MATLAB returning different eigenvectors

半城伤御伤魂 提交于 2019-11-28 08:41:54

问题


I'm missing something obvious, but here goes:

In R,

dput(M)
structure(c(-2.77555756156289e-16, 9.63770703841896e-16, 0, 9.63770703841896e-16, 
10.6543192562307, 4.11228781751498e-14, 0, 4.11228781751498e-14, 
275.591724761168), .Dim = c(3L, 3L), .Dimnames = list(c("", "", 
""), c("", "", "")))

#thus M is

 -2.775558e-16 9.637707e-16 0.000000e+00
  9.637707e-16 1.065432e+01 4.112288e-14
  0.000000e+00 4.112288e-14 2.755917e+02

eig(M)
$values
[1]  2.755917e+02  1.065432e+01 -2.775558e-16

$vectors
             [,1]         [,2] [,3]
[1,] 5.428099e-34 9.045822e-17    1
[2,] 1.552173e-16 1.000000e+00    0
[3,] 1.000000e+00 0.000000e+00    0

But in MATLAB

[vv,ee] = eig(M)
% hand-copied so ignore the precision)
vv = 
   1.0    -0.    -0.
   0      0      -1
   0      -1     0

ee = 
 %diagonals only
0.0    275.59   10.6543

The eigenvalues match up with the locations where abs(vv) == 1 , but the thing I don't understand is why some eigenvectors are negative one in MATLAB but not in R. It makes a big difference, as I'm trying to port this MATLAB package, (in particular, parabolafit_direct.m and `parabolafit_directm.m' ) and the subsequent algorithms are sensitive to the sign of the values. I checked, and the MATLAB package does produce the correct fitted output (parabolic curve to dataset), while my R-port does not, because of these sign differences.

So, why the difference, and what can I do to modify my R code to get the desired signs of the data?

EDIT: I continue to dig into the code to see if these two "negative one" values cancel out in the next set of equations, but haven't seen that yet.


回答1:


Most of the important info is in the comments by Andras Deak. To summarize: as we all (should) know, eigenvalues and eigenvectors are only unique up to a multiplicative constant. While in this particular case R and MATLAB happened to end up with differing signs, all subsequent matrix operations on the eigenvectors will yield the same result (again,to within sign or constant value).

In my particular case, the final result essentially was: one answer was a*x -b =0 and the other was -a*x + b = 0 .



来源:https://stackoverflow.com/questions/34476016/r-and-matlab-returning-different-eigenvectors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!