我在R中执行以下操作:
> m = matrix(c(0.563291, -0.478813, 0.574175,
+ 0.160779, -0.03407, 0.381922,
+ 0.0677914, 0.870361, -0.88602), 3, 3)
> mt = t(m)
> mt
[1,] 0.5632910 -0.478813 0.574175
[2,] 0.1607790 -0.034070 0.381922
[3,] 0.0677914 0.870361 -0.886020
> e<-eigen(mt)
> e
$values
[1] -1.1583554 0.5215205 0.2800359
$vectors
[1,] -0.3684057 0.8245987 -0.1255897
[2,] -0.2513624 0.4625355 -0.7915182
[3,] 0.8950387 0.3257267 -0.5981021
在eigen3中使用以下c ++代码:
std::cout << "=========" << std::endl;
std::cout << A << std::endl;
EigenSolver<MatrixXd> es(A);
std::cout << "evals: " << std::endl;
std::cout << es.eigenvalues();
std::cout << std::endl << "evecs: " << std::endl;
std::cout << es.eigenvectors() << std::endl;
std::cout << "=========" << std::endl;
我得到以下值:
=========
0.563291 -0.478813 0.574175
0.160779 -0.03407 0.381922
0.0677914 0.870361 -0.88602
evals:
(0.521521,0)
(0.280036,0)
(-1.15836,0)
evecs:
(-0.824599,0) (0.125591,0) (-0.368406,0)
(-0.462535,0) (0.791518,0) (-0.251362,0)
(-0.325726,0) (0.598102,0) (0.895039,0)
=========
为什么eigen3中的顺序与R中的顺序不同?我正在寻找特征版本来存储和打印最高特征值和相应的特征向量&#34;格式,它似乎做了,但为什么R在特征向量中的差异似乎是将矢量打印为colum-vectors而不是行向量,值乘以-1乘以?
如果我取R的evs输出和Eigen的evs输出并且如果它们相等则相互乘以它我应该得到Identity Matrix I,不是吗?
> v = matrix(c(-0.3684057, 0.8245987, -0.1255897,
+ -0.2513624, 0.4625355, -0.7915182,
+ 0.8950387, 0.3257267, -0.5981021), nrow = 3, ncol = 3)
> v
[,1] [,2] [,3]
[1,] -0.3684057 -0.2513624 0.8950387
[2,] 0.8245987 0.4625355 0.3257267
[3,] -0.1255897 -0.7915182 -0.5981021
> u = matrix(c(-0.824599, 0.125591, -0.368406,
+ -0.462535, 0.791518, -0.251362,
+ -0.325726, 0.598102, 0.895039), nrow = 3, ncol = 3)
> u
[,1] [,2] [,3]
[1,] -0.824599 -0.462535 -0.325726
[2,] 0.125591 0.791518 0.598102
[3,] -0.368406 -0.251362 0.895039
> c = u*v
> c
[,1] [,2] [,3]
[1,] 0.3037870 0.1162639 -0.2915374
[2,] 0.1035622 0.3661052 0.1948178
[3,] 0.0462680 0.1989576 -0.5353247
> u = t(u)
> u
[,1] [,2] [,3]
[1,] -0.824599 0.125591 -0.368406
[2,] -0.462535 0.791518 -0.251362
[3,] -0.325726 0.598102 0.895039
> c = u*v
> c
[,1] [,2] [,3]
[1,] 0.30378697 -0.03156886 -0.32973763
[2,] -0.38140576 0.36610517 -0.08187531
[3,] 0.04090783 -0.47340862 -0.53532471
>
答案 0 :(得分:1)
你可以对它们进行排序。
对于R,文档说
Value:
The spectral decomposition of ‘x’ is returned as components of a
list with components
values: a vector containing the p eigenvalues of ‘x’, sorted in
_decreasing_ order, according to ‘Mod(values)’ in the
asymmetric case when they might be complex (even for real
matrices). For real asymmetric matrices the vector will be
complex only if complex conjugate pairs of eigenvalues are
detected.
没有什么要求对值进行排序,这样做只是一种惯例。
(矢量符号的相关问题也是准FAQ。)