Closed aosidnf closed 1 year ago
It works for me with SymPy v1.1.8
and Julia v1.8.5
using SymPy, LinearAlgebra
As=Sym["a" "b"; "c" "d"];
ξs=eigvecs(As);
λs=eigvals(As);
ξs*Diagonal(λs)*inv(ξs) - As .|> simplify # gives a 2x2 zero matrix
I am on the same version of SymPy and Julia. this zip contains a nix shell and project.toml which produces the issue for me. https://files.catbox.moe/7vkg5s.zip
Can you try a different shell?
The order is inherited from the python code https://github.com/JuliaPy/SymPy.jl/blob/afaca4a9e0951322dc907402388d1ef5651015b7/src/matrix.jl#L85. We could sort before returning, but you could also sort before using. If you want to put in a PR, it would be welcome.
@jverzani Why sorting? Do eigvals
and eigvecs
not have the same ordering?
I’m assuming that the eigenvals are sorted differently in sympy than Julia. If so, perhaps adjusting that would make things more in line. I’m not sure it would work with symbolic values though.
i tried other versions of sympy and python (the version in nixos 22.05, and the latest 1.11 in master) and had the same issue.
I think sympy simply doesn't guarantee the ordering will be consistent.
It seems sympy.ordered()
will do the job, I'll make a PR later.
Specifically, the ordering is inconsistent such that it makes the common diagonalization behavior not work:
but for a matrix of Syms,