Python 中的 SymPy:
>>> M = Matrix([[-4, sqrt(2)], [sqrt(2), -5]])
>>> M
Matrix([
[ -4, sqrt(2)],
[sqrt(2), -5]])
>>> dict_eig = M.eigenvals()
>>> dict_eig
{-6: 1, -3: 1}
SymPy.jl( Julia ):
julia> M = sympy.Matrix([[-4, sqrt(2)], [sqrt(2), -5]])
2×2 Array{Sym,2}:
-4.00000000000000 1.41421356237310
1.41421356237310 -5.00000000000000
julia> dict_eig = M.eigenvals()
Dict{Any,Any} with 2 entries:
-9/2 - sqrt(225000000000001400410360361)/10000000000000 => 1
-9/2 + sqrt(225000000000001400410360361)/10000000000000 => 1
结果实际上是正确的,但很奇怪..为什么会这样以及如何获得Python中报告的表单?
最佳答案
您在 python 版本中隐式使用 sympy 的 sqrt 实现。如果直接调用 sympy 的 sqrt,您将得到相同的结果。
julia> M = [[-4 sympy.sqrt(2)]; [sympy.sqrt(2) -5]]
2×2 Array{Sym,2}:
-4 sqrt(2)
sqrt(2) -5
julia> M.eigenvals()
Dict{Any,Any} with 2 entries:
-3 => 1
-6 => 1
关于julia - 与在 python 中使用 SymPy 相比,SymPy.jl 奇怪的特征值报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58276470/