[Python] SymPy unable to find roots of a specific trigonometric polynomial

Discussão em 'Python' iniciado por Stack, Junho 10, 2025.

  1. Stack

    Stack Membro Participativo

    I've been attempting to find the solutions of various trigonometric polynomials, and so far SymPy's solveset has been able to solve them all admirably except for one.

    Given the input trigonometric polynomial, I first evaluate any factor numerically before trying to apply solveset to it, specifically on the interval 0, 2π :

    eqroots = solveset(N(eq), x, domain=Interval(0, 2 * sympy.pi))


    This seems to work for all the expressions I've tried, except this one :

    [​IMG]

    which always sends back the empty set as a result. This function does have roots in the appropriate range, as can be seen from the plot :

    [​IMG]

    and the usual solver of sympy "solve" does find them, albeit in the range it typically checks, giving them as [-1.93950301201116, 1.93950301201116].

    The minimal code for reproduction is

    from sympy import sqrt, sin, cos, Symbol, solveset, N, Interval, pi
    x=Symbol('x')
    expr = sqrt(sqrt(2) + 2)*cos(x)/2 - sqrt(2 - sqrt(2))*cos(2*x)/4 + sqrt(2 - sqrt(2))/4
    eqroots = solveset(N(expr), x, domain=Interval(0, 2 * pi))


    Is there a reason solveset cannot find those roots?

    Continue reading...

Compartilhe esta Página