代码之家  ›  专栏  ›  技术社区  ›  Him

辛函数的估计进展

  •  1
  • Him  · 技术社区  · 7 年前

    我已经发布了 sympy 命令解某个方程。已经好几天了,我不知道什么时候能完成。

    我能去吗 同情 记录呼叫的进度, .solvers.solve ? 如果没有,我如何估计最坏的情况下的时间 需要解一组方程吗?

    例如

    import sympy, sympy.solvers
    from sympy import sqrt
    
    a,c,d,e,f,x = tuple(map(sympy.Symbol, 'acdefx'))
    
    # when will this finish?
    print(sympy.solvers.solve(
        3*sqrt((16*a**2*c**2*x**2 + 8*a*c*e*x - 4*a*c*x**2 - 4*c*d*x - 4*c*f + e**2 + (-8*a**2*c*x - 2*a*e + 2*a*x + 2*a*sqrt(16*a**2*c**2*
    x**2 + 8*a*c*e*x - 4*a*c*x**2 - 4*c*d*x - 4*c*f + e**2) + d)**2)**3/(16*a**2*c**2*x**2 + 8*a*c*e*x - 4*a*c*x**2 - 4*c*d*x - 4*c*f + e**2)**3)*(a*(2*c
    *(8*a**2*c*x + 2*a*e - 2*a*x - d) - (4*a*c - 1)*sqrt(16*a**2*c**2*x**2 + 8*a*c*e*x - 4*a*c*x**2 - 4*c*d*x - 4*c*f + e**2))*(-8*a**2*c*x - 2*a*e + 2*a
    *x + 2*a*sqrt(16*a**2*c**2*x**2 + 8*a*c*e*x - 4*a*c*x**2 - 4*c*d*x - 4*c*f + e**2) + d) + c*(8*a**2*c*x + 2*a*e - 2*a*x - d)*sqrt(16*a**2*c**2*x**2 +
     8*a*c*e*x - 4*a*c*x**2 - 4*c*d*x - 4*c*f + e**2))*(16*a**2*c**2*x**2 + 8*a*c*e*x - 4*a*c*x**2 - 4*c*d*x - 4*c*f + e**2)/((a*(4*a*c - 1)*(16*a**2*c**
    2*x**2 + 8*a*c*e*x - 4*a*c*x**2 - 4*c*d*x - 4*c*f + e**2) - c*(8*a**2*c*x + 2*a*e - 2*a*x - d)**2)*(16*a**2*c**2*x**2 + 8*a*c*e*x - 4*a*c*x**2 - 4*c*
    d*x - 4*c*f + e**2 + (-8*a**2*c*x - 2*a*e + 2*a*x + 2*a*sqrt(16*a**2*c**2*x**2 + 8*a*c*e*x - 4*a*c*x**2 - 4*c*d*x - 4*c*f + e**2) + d)**2))
    ,x))
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   user6655984 user6655984    7 年前

    SymPy不提供任何完工时间估算。它的一些算法依赖于以各种方式重写表达式;如果结果表达式变得更复杂而不是更少,则此过程可能永远不会终止。

    在具体的例子中,分解表达式和求解单个因子是有帮助的。

    factors = expr.factor().args
    solve(factors[4], x)   # "4" by trial and error
    

    退货

    [(c*(-2*a*e + d) - sqrt(c*(16*a**2*c**2*f - 4*a*c*d*e - 4*a*c*f + a*e**2 + c*d**2)))/(2*a*c*(4*a*c - 1)),
     (c*(-2*a*e + d) + sqrt(c*(16*a**2*c**2*f - 4*a*c*d*e - 4*a*c*f + a*e**2 + c*d**2)))/(2*a*c*(4*a*c - 1))]