SymPy秩不同于NumPy矩阵秩



给定一些SymPy矩阵M

M = Matrix([
[0.000111334436666596, 0.00114870370895408, -0.000328330524152990, 5.61388353859808e-6, -0.000464532588930332, -0.000969955779635878, 1.70579589853818e-5, -5.77891177019884e-6, -0.000186812539472235, -2.37115911398055e-5],
[-0.00105346453420510, 0.000165063406707273, -0.00184449574409890, 0.000658080565333929, 0.00197652092300241, 0.000516180213512589, 9.53823860082390e-5, 0.000189858427211978, -3.80494288487685e-5, 0.000188984043643408],
[-0.00102465075104153, -0.000402915220398109, 0.00123785300884241, -0.00125808154543978, 0.000126618511490838, 0.00185985865307693, 0.000123626008509804, 0.000211557638637554, 0.000407232404255796, 1.89851719447102e-5],
[0.230813497584639, -0.209574389008468, 0.742275067362657, -0.202368828927654, -0.236683258718819, 0.183258819107153, 0.180335891933511, -0.530606389541138, -0.379368598768419, 0.334800403899511],
[-0.00102465075104153, -0.000402915220398109, 0.00123785300884241, -0.00125808154543978, 0.000126618511490838, 0.00185985865307693, 0.000123626008509804, 0.000211557638637554, 0.000407232404255796, 1.89851719447102e-5],
[0.00105346453420510, -0.000165063406707273, 0.00184449574409890, -0.000658080565333929, -0.00197652092300241, -0.000516180213512589, -9.53823860082390e-5, -0.000189858427211978, 3.80494288487685e-5, -0.000188984043643408],
[0.945967255845168, -0.0468645728473480, 0.165423896937049, -0.893045423193559, -0.519428986944650, -0.0463256408085840, -0.0257001217930424, 0.0757328764368606, 0.0541336731317414, -0.0477734271777646],
[-0.0273371493900004, -0.954100482348723, -0.0879282784854250, 0.100704543595514, -0.243312734473589, -0.0217088779350294, 0.900584332231093, 0.616061129532614, 0.0651163853434486, -0.0396603397583054],
[0.0967584768347089, -0.0877680087304911, -0.667679934757176, -0.0848411039101494, -0.0224646387789634, -0.194501966574153, 0.0755161040544943, 0.699388977592066, 0.394125039254254, -0.342798611994521],
[-0.000222668873333193, -0.00229740741790816, 0.000656661048305981, -1.12277670771962e-5, 0.000929065177860663, 0.00193991155927176, -3.41159179707635e-5, 1.15578235403977e-5, 0.000373625078944470, 4.74231822796110e-5]
])

计算了矩阵的SymPyrank()rref()。秩为7rref()结果为:

Matrix([
[1, 0, 0, 0, 0, 0, 0, -5.14556976678473, -3.72094268951566,  3.48581267477014],
[0, 1, 0, 0, 0, 0, 0, -5.52930150663022, -4.02230308325653,  3.79193678096199],
[0, 0, 1, 0, 0, 0, 0,  2.44893308665325,  1.83777402439421, -1.87489784909824],
[0, 0, 0, 1, 0, 0, 0, -7.33732284392352, -5.25036238623229,  4.97256759287563],
[0, 0, 0, 0, 1, 0, 0,  5.48049237370489,  3.90091366576548, -3.83642187384021],
[0, 0, 0, 0, 0, 1, 0, -10.6826798792866, -7.56560803870182,  7.45974067056387],
[0, 0, 0, 0, 0, 0, 1, -3.04726210012149, -2.66388837034592,  2.48327234504403],
[0, 0, 0, 0, 0, 0, 0,                 0,                 0,                 0],
[0, 0, 0, 0, 0, 0, 0,                 0,                 0,                 0],
[0, 0, 0, 0, 0, 0, 0,                 0,                 0,                 0]])

奇怪的是,如果我用NumPyMATLAB计算秩,我得到值6,用MATLAB计算rref,我得到预期结果——最后的4行都为零(而不是只有最后的3(。

有人知道这种差异是从哪里来的吗?为什么我不能用SymPy得到正确的结果?我知道秩6是正确的,因为它是一个存在线性依赖关系的方程组。

看看矩阵的特征值,秩确实是6:

array([ 1.14550481e+00+0.00000000e+00j, -1.82137718e-01+6.83443168e-01j,
-1.82137718e-01-6.83443168e-01j,  2.76223053e-03+0.00000000e+00j,
-3.51138883e-04+8.61508469e-04j, -3.51138883e-04-8.61508469e-04j,
5.21160131e-17+0.00000000e+00j, -2.65160469e-16+0.00000000e+00j,
-2.67753616e-18+9.70937977e-18j, -2.67753616e-18-9.70937977e-18j])

使用我的sympy版本,与numpy返回的秩6相比,我甚至获得了秩8。

但实际上,由于矩阵的大小,Sympy无法求解该矩阵的特征值(可能与SymPy无法计算该矩阵的本征值有关(。

因此,其中一个Sympy试图象征性地求解方程并找到秩(基于不完美的浮点数(,而另一个numpy使用近似(lapackIIRC(来找到特征值。通过具有足够的阈值,numpy找到了合适的秩,但它可以用不同的阈值来表示。CCD_ 21试图基于完美的6秩系统的近似系统来寻找秩,并发现它是秩7或8。由于浮点差,这并不奇怪(例如,Sympy移动到整数,试图找到本征值,而不是停留在浮点领域(。

相关内容

  • 没有找到相关文章

最新更新