问题描述
我遗漏了一些明显的东西,但是这里有:
I'm missing something obvious, but here goes:
在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
但在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
特征值与abs(vv) == 1
的位置匹配,但是我不明白的是为什么某些特征向量在MATLAB中是负数,而在R中却不是.差异很大,因为我正尝试移植此MATLAB包(尤其是parabolafit_direct.m
和`parabolafit_directm.m')以及后续算法对值的符号敏感.我检查了一下,由于这些符号差异,MATLAB程序包确实产生了正确的拟合输出(到数据集的抛物线),而我的R端口却没有.
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.
那么,为什么会有所不同,我该怎么做才能修改我的R
代码以获得所需的数据符号?
So, why the difference, and what can I do to modify my R
code to get the desired signs of the data?
我继续研究代码,看看这两个负一个"值是否在下一组方程式中被抵消,但是还没有看到.
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.
推荐答案
大多数重要信息在Andras Deak的评论中.总结一下:众所周知,本征值和本征向量仅在乘积常数之前是唯一的.尽管在这种特殊情况下,R
和MATLAB
碰巧以不同的符号结尾,但是所有随后对本征矢量进行的矩阵运算将产生相同的结果(同样,在符号或常数值之内).
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).
在我的特定情况下,最终结果实质上是:一个答案是a*x -b =0
,另一个是-a*x + b = 0
.
In my particular case, the final result essentially was: one answer was a*x -b =0
and the other was -a*x + b = 0
.
这篇关于R和MATLAB返回不同的特征向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!