[Python] finding zeroes in complex polynomial taking forever in sympy, pathological case?

Discussão em 'Python' iniciado por Stack, Julho 21, 2025.

  1. Stack

    Stack Membro Participativo

    I'm new to sympy and python, I should have used R but wanted to try some AI generated code. This seems to work ok for other test polynomials but this eventually generates some symbolic results but appears to hang before plotting. You can see the commented polynomials work in maybe a few minutes. Any ideas? Thanks.

    from __future__ import division
    from sympy import *
    x, y, z, t = symbols('x y z t')
    k, m, n = symbols('k m n', integer=True)
    f, g, h = symbols('f g h', cls=Function)
    init_printing()
    import numpy as np
    import math
    import matplotlib.pyplot as plt
    #delta, delay = symbols("delta delay")
    delta=.04*math.pi
    delay=2.0*math.pi/delta
    print ( delay )
    #complex_solutions = solveset(z**2-1-2*z+delta*delta*(z**delay), z, domain=Complexes)
    #complex_solutions = solveset(z**2-1-2*z+delta*delta*(z**math.floor(delay+.5)), z, domain=Complexes)
    complex_solutions = solveset(z**math.floor(delay+.5)+1-z, z, domain=Complexes)
    #complex_solutions = solveset(z**2-1-2*z+z**10, z, domain=Complexes)
    print ( complex_solutions )
    t = np.linspace(0, 2 * np.pi, 100) # Angle from 0 to 2pi
    x_circle = np.cos(t)
    y_circle = np.sin(t)
    real_parts = [sol.as_real_imag()[0] for sol in complex_solutions]
    imag_parts = [sol.as_real_imag()[1] for sol in complex_solutions]
    plt.figure(figsize=(6,6))
    plt.scatter(real_parts, imag_parts, color='green', marker='o', label='Complex Solutions')
    plt.plot(x_circle, y_circle, 'b--', alpha=0.5, label='Unit Circle Reference')
    plt.xlabel('Real Axis')
    plt.ylabel('Imaginary Axis')
    plt.title('Solutions on Unit Circle')
    plt.gca().set_aspect('equal')
    plt.grid(True)
    plt.legend()
    plt.show()

    Continue reading...

Compartilhe esta Página