Python 中的 Eig 给出不同的特征值?

Eig in Python giving different Eigenvalues?

所以本质上问题是 Matlab 中的 eig 函数和 Python 给了我不同的东西。我正在从论文中复制数据以确认我的数值方法是正确的(所以我知道答案 - 通过 Matlab 获得)

我已经试过了,还是没有改善。

下面是使用的数据矩阵:

2852    170.380000000000    77.3190000000000    -51.0710000000000   -191.560000000000   105.410000000000    240.950000000000    102.700000000000
2842    169.640000000000    76.6120000000000    -50.3980000000000   -191.310000000000   105.660000000000    240.850000000000    102.960000000000
2838.80000000000    176.950000000000    80.4150000000000    -51.5700000000000   -192.190000000000   104.870000000000    239.700000000000    104.110000000000
2837.40000000000    182.930000000000    88.4070000000000    -54.1410000000000   -194.460000000000   104.230000000000    238.760000000000    105.020000000000
2890.80000000000    167.270000000000    122 -67.7490000000000   -275.150000000000   160.960000000000    248.010000000000    95.9470000000000
2962.10000000000    113.910000000000    177.060000000000    -98.9930000000000   -259.270000000000   80.7860000000000    262.890000000000    80.9180000000000
3013.90000000000    72.9740000000000    225.260000000000    -135.700000000000   -233.520000000000   0.0469300000000000  272.110000000000    71.5160000000000
3026.50000000000    112.420000000000    243.020000000000    -169.460000000000   -218.060000000000   0.0465190000000000  271.250000000000    71.8280000000000
3367.10000000000    -0.310680000000000  479.870000000000    0.494350000000000   -0.603940000000000  -0.147820000000000  282.700000000000    -64.1680000000000  
    import scipy.io as sc
    import math as m
    import numpy as np
    from numpy import diag, power
    from scipy.linalg import expm, sinm, cosm
    import matplotlib.pyplot as plt
    import pandas as pd

    ###########################. Import Data from Excel Sheet. 
    ###################################
    df = pd.read_excel('DataCompanionMatrix.xlsx', header=None)
    data = np.array(df)

    ###########################. FUNCTION DEFINE. 
    #################################################
    m = data.shape[0]
    n = data.shape[1]

    x = data[0:-1,:]
    y = data[-1,:]

    A = np.dot(x,np.transpose(x))
    xx = np.dot(x,np.transpose(y))
    Co_values = np.dot(np.linalg.pinv(A),xx)

    C = np.zeros((n,n))
    for i in range(0,n-1):
        C[i,i-1] = 1

    C[:,n-1] = Co_values

    eigV,eigW = np.linalg.eig(C)
    print(eigV)

数据为9x8矩阵,x为8x8矩阵,y为1x8数组,A为8x8,C为8x8,co为1x8数组。

在 Matlab 中,特征值是复数特征值的 1x8 数组。在 Python 中,我得到一个 1x8 数组,其中填充了 7 个零和 1 个整数。

我希望绘制特征值,它们应该位于单位圆上,这是我在 Matlab 上完成的。

C matrix- matlab and python (both look like this)

Python eigenvalues

Matlab eigenvalues

您在 Python 中创建的数组 C 与您在 MATLAB 中创建的数组不对应。

如果我按如下方式修改您的 Python 代码,我会得到相同的数组 C 和相同的特征值:

C = np.zeros((n,n))
for i in range(0,n-1):
    C[i+1,i] = 1       # This is where the differences are!

C[:,n-1] = Co_values