Hello Oscar,

 thank you for the fast answer. I'll test the chop option. Further, I
commented on this idea in "Zero in SymPy #22425".

Regards,

Zoufiné

On Fri, Nov 5, 2021 at 12:22 AM Oscar Benjamin <oscar.j.benja...@gmail.com>
wrote:

> On Thu, 4 Nov 2021 at 23:13, Zoufiné Lauer-Baré <zoufine.b...@gmail.com>
> wrote:
> >
> > Dear all,
>
> Hi and thanks for reporting this.
>
> > I just created an issue in the SymPy github project (Zero in SymPy
> > #22425 opened 2 minutes ago by zolabar). Here goes the content, may be
> someone knows this topic and there are already issues on this.
> >
> > Sometimes SymPy hesitates to return zero... I've encountered this
> problem in three applications. There may be a solution to this already,
> however I haven't seen it yet.
> >
> > Problem 1: Real symmetric Matrices have only real eigenvalues...
> > Problem 2: Analiticity of Möbius transform
> > Problem 3:  Stationary Points of Himmelblau Function
> >
> > Problem 1:
> >
> > A = sym.Matrix(([1, 4, -2],
> > [4, 0, 0],
> > [-2, 0, 3]))
> >
> > should have only real eigenvalues, since it is symmetric, but SymPy
> returns complex eigenvalues with an imaginary part of the orrder
> 10**(-126)...
>
> I'm not sure what the issue here is:
>
> In [42]: A = sym.Matrix(([1, 4, -2],
>     ...: [4, 0, 0],
>     ...: [-2, 0, 3]))
>
> In [43]: nroots(A.charpoly())
> Out[43]: [-3.79943573866291, 2.29524145208425, 5.50419428657866]
>
> In [44]: {e.evalf() for e in A.eigenvals()}
> Out[44]: {-3.79943573866291 + 0.e-20⋅ⅈ, 2.29524145208425 + 0.e-20⋅ⅈ,
> 5.50419428657866 + 0.e-20⋅ⅈ}
>
> The complex parts here show as zero. You can get rid of them
> completely with chop:
>
> In [45]: {e.evalf(chop=True) for e in A.eigenvals()}
> Out[45]: {-3.79943573866291, 2.29524145208425, 5.50419428657866}
>
> The source of the complex part is casus irreducibilis:
> https://en.wikipedia.org/wiki/Casus_irreducibilis
>
> That shows why it is better to compute numerical roots directly from
> the polynomial rather than from a radical expression for the roots.
>
> I don't immediately have time to investigate the other two points
> (copy-pasting the code didn't work).
>
> --
> Oscar
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "sympy" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/sympy/rMAWl_g8z9s/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> sympy+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/CAHVvXxSTY4mUUV5cYVvRc77yKUURGKR%3DCOoBm0ZAhUtgxXkV%2Bg%40mail.gmail.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAPQg10iRONcf_rGpaUGNvcnPRs_Xb1h4HLmDMf_opqQdL3hygQ%40mail.gmail.com.

Reply via email to