Reputation: 21502
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.
Upvotes: 5
Views: 1364
Reputation: 21502
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
.
Upvotes: 1