我尝试将matlab程序翻译成python,但我找不到python中的(matlab eigs)匹配。 我试过scipy.sparse.linalg,但它们完全不同: MATLAB:
>> up_Cx
up_Cx =
1.0e+03 *
2.1341 2.1341 2.1341
2.1341 2.1341 2.1341
2.1341 2.1341 2.1341
>> [A,D]=eigs(up_Cx)
A =
0.5774 -0.0961 -0.8108
0.5774 -0.6541 0.4886
0.5774 0.7502 0.3222
D =
1.0e+03 *
6.4023 0 0
0 0.0000 0
0 0 0.0000
>>
我在python中尝试过:
>>> H_CX
array([[ 2134.08350667, 2134.08350667, 2134.08350667],
[ 2134.08350667, 2134.08350667, 2134.08350667],
[ 2134.08350667, 2134.08350667, 2134.08350667]])
>>> scipy.sparse.linalg.eigs(H_CX)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.py", line 1238, in eigs
% (k, n - 1))
ValueError: k=6 must be between 1 and ndim(A)-1=2
和k = 1:
>>> H_CX
array([[ 2134.08350667, 2134.08350667, 2134.08350667],
[ 2134.08350667, 2134.08350667, 2134.08350667],
[ 2134.08350667, 2134.08350667, 2134.08350667]])
>>> scipy.sparse.linalg.eigs(H_CX)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.py", line 1238, in eigs
% (k, n - 1))
ValueError: k=6 must be between 1 and ndim(A)-1=2
>>> scipy.sparse.linalg.eigs(H_CX,1)
(array([ 6402.25052002+0.j]), array([[-0.57735027+0.j],
[-0.57735027+0.j],
[-0.57735027+0.j]]))
结果完全不同,我很困惑......