为什么Octave和Matlab每次都会产生一组新的特征向量?

时间:2017-10-10 08:00:47

标签: matlab random octave

我观察到Octave和Matlab在多次调用eigs(X,2)时返回不同的特征向量。特征值保持不变,但特征向量发生变化,尽管X没有变化。我怀疑这是因为eigs()代码内部的随机初始化。任何来自随机性的线索?

有没有办法删除随机性(例如用户指定的所有随机数生成的种子)?

我手动将一些代码从Matlab移植到Armadillo C ++库。移植的代码在某个地方有一个bug,但我发现由于特征向量在Matlab / Octave中从调用变为调用而无法搜索它。

例如,当X为:

[  1.00000 + 0.00000i, -0.64125 + 0.00018i,  0.15282 + 0.04350i,  0.01890 - 0.07992i ...
-0.01980 + 0.02993i, -0.01754 + 0.02204i, -0.01306 + 0.03970i,  0.06067 - 0.08188i ...
-0.04754 - 0.00056i,  0.03681 + 0.02123i;
-0.64125 - 0.00018i,  1.00000 + 0.00000i, -0.67099 - 0.00014i,  0.14904 - 0.00153i ...
-0.01074 + 0.01916i,  0.13448 - 0.06437i, -0.16825 + 0.06454i,  0.06730 - 0.03552i ...
 0.04261 + 0.02680i, -0.07457 - 0.01962i;
 0.15282 - 0.04350i, -0.67099 + 0.00014i,  1.00000 + 0.00000i, -0.65949 - 0.00159i ...
 0.20526 - 0.00742i, -0.17609 + 0.06834i,  0.30492 - 0.08507i, -0.18454 + 0.01918i ...
-0.00090 + 0.01579i,  0.01740 + 0.04236i;
 0.01890 + 0.07992i,  0.14904 + 0.00153i, -0.65949 + 0.00159i,  1.00000 + 0.00000i ...
-0.70059 + 0.00211i,  0.25861 - 0.02341i, -0.17782 + 0.01540i,  0.15505 - 0.01596i ...
-0.03466 + 0.04638i,  0.02013 - 0.05730i;
-0.01980 - 0.02993i, -0.01074 - 0.01916i,  0.20526 + 0.00742i, -0.70059 - 0.00211i ...
 1.00000 + 0.00000i, -0.66423 - 0.00025i,  0.14354 + 0.00726i, -0.03537 + 0.05243i ...
 0.05091 - 0.09231i, -0.06596 + 0.01689i;
-0.01754 - 0.02204i,  0.13448 + 0.06437i, -0.17609 - 0.06834i,  0.25861 + 0.02341i ...
-0.66423 + 0.00025i,  1.00000 + 0.00000i, -0.62010 + 0.00556i,  0.17786 - 0.03333i ...
-0.08309 + 0.02039i,  0.13213 + 0.04940i;
-0.01306 - 0.03970i, -0.16825 - 0.06454i,  0.30492 + 0.08507i, -0.17782 - 0.01540i ...
 0.14354 - 0.00726i, -0.62010 - 0.00556i,  1.00000 + 0.00000i, -0.69907 + 0.00052i ...
 0.21059 + 0.01909i, -0.04506 - 0.03867i;
 0.06067 + 0.08188i,  0.06730 + 0.03552i, -0.18454 - 0.01918i,  0.15505 + 0.01596i ...
-0.03537 - 0.05243i,  0.17786 + 0.03333i, -0.69907 - 0.00052i,  1.00000 + 0.00000i ...
-0.64091 - 0.00089i,  0.11982 - 0.00182i;
-0.04754 + 0.00056i,  0.04261 - 0.02680i, -0.00090 - 0.01579i, -0.03466 - 0.04638i ...
 0.05091 + 0.09231i, -0.08309 - 0.02039i,  0.21059 - 0.01909i, -0.64091 + 0.00089i ...
 1.00000 + 0.00000i, -0.66278 + 0.00015i;
 0.03681 - 0.02123i, -0.07457 + 0.01962i,  0.01740 - 0.04236i,  0.02013 + 0.05730i ...
-0.06596 - 0.01689i,  0.13213 - 0.04940i, -0.04506 + 0.03867i,  0.11982 + 0.00182i ...
-0.66278 - 0.00015i,  1.00000 + 0.00000i ];

eigs(X,2)的两次连续调用会返回以下结果:

e =

  -0.338703 + 0.107398i   0.084395 - 0.026833i
   0.396747 - 0.137376i  -0.186949 + 0.174112i
  -0.293466 + 0.143536i   0.295215 - 0.247898i
   0.164756 - 0.083375i  -0.307448 + 0.238361i
  -0.071050 + 0.009354i   0.289069 - 0.204641i
  -0.034409 - 0.001546i  -0.346065 + 0.187859i
   0.170741 + 0.026855i   0.365437 - 0.175989i
  -0.357124 + 0.014893i  -0.308248 + 0.132656i
   0.483759 - 0.103465i   0.215436 - 0.066429i
  -0.366097 + 0.118043i  -0.129626 + 0.041190i

d =

Diagonal Matrix

   2.0926 - 0.0000i                  0
                  0   3.0116 + 0.0000i

e =

  -0.273138 - 0.227266i  -0.059841 + 0.065281i
   0.329691 + 0.259970i   0.075477 - 0.244066i
  -0.279165 - 0.169681i  -0.132650 + 0.361952i
   0.159079 + 0.093755i   0.148006 - 0.359770i
  -0.046203 - 0.054780i  -0.148851 + 0.321376i
  -0.017259 - 0.029808i   0.206637 - 0.335191i
   0.069489 + 0.158256i  -0.229348 + 0.334538i
  -0.205182 - 0.292677i   0.201316 - 0.268489i
   0.348073 + 0.351529i  -0.153785 + 0.164851i
  -0.296879 - 0.244590i   0.091923 - 0.100248i

d =

Diagonal Matrix

   2.0926 - 0.0000i                  0
                  0   3.0116 - 0.0000i

修改:我添加了示例数据并更改了问题。有问题的Matlab函数是 eigs()而不是 eig(),因为我之前使用不正确。

0 个答案:

没有答案