简体   繁体   English

为什么SymPy不集成此功能?

[英]Why doesn't SymPy integrate this function?

I have the following: 我有以下几点:

x,x1,x2,t=symbols('x x1 x2 t')
f=t*x1*x2*(x-t)**(-0.5)
integrate(f,t)

I can integrate with respect to x , x1 and x2 , but when I try to integrate with respect to t (which is what I want) I get the following error 我可以针对xx1x2进行积分,但是当我尝试针对t进行积分(这是我想要的)时,出现以下错误

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/sympy/integrals/integrals.py", line 1295, in integrate
    risch=risch, manual=manual)
  File "/usr/local/lib/python2.7/dist-packages/sympy/integrals/integrals.py", line 486, in doit
    conds=conds)
  File "/usr/local/lib/python2.7/dist-packages/sympy/integrals/integrals.py", line 908, in _eval_integral
    h = meijerint_indefinite(g, x)
  File "/usr/local/lib/python2.7/dist-packages/sympy/integrals/meijerint.py", line 1612, in meijerint_indefinite
    res = _meijerint_indefinite_1(f.subs(x, x + a), x)
  File "/usr/local/lib/python2.7/dist-packages/sympy/integrals/meijerint.py", line 1677, in _meijerint_indefinite_1
    r = hyperexpand(r.subs(t, a*x**b), place=place)
  File "/usr/local/lib/python2.7/dist-packages/sympy/simplify/hyperexpand.py", line 2473, in hyperexpand
    return f.replace(hyper, do_replace).replace(meijerg, do_meijer)
  File "/usr/local/lib/python2.7/dist-packages/sympy/core/basic.py", line 1408, in replace
    rv = bottom_up(self, rec_replace, atoms=True)
  File "/usr/local/lib/python2.7/dist-packages/sympy/simplify/simplify.py", line 999, in bottom_up
    rv = F(rv)
  File "/usr/local/lib/python2.7/dist-packages/sympy/core/basic.py", line 1393, in rec_replace
    new = _value(expr, result)
  File "/usr/local/lib/python2.7/dist-packages/sympy/core/basic.py", line 1336, in <lambda>
    _value = lambda expr, result: value(*expr.args)
  File "/usr/local/lib/python2.7/dist-packages/sympy/simplify/hyperexpand.py", line 2470, in do_meijer
    allow_hyper, rewrite=rewrite, place=place)
  File "/usr/local/lib/python2.7/dist-packages/sympy/simplify/hyperexpand.py", line 2355, in _meijergexpand
    t, 1/z0)
  File "/usr/local/lib/python2.7/dist-packages/sympy/simplify/hyperexpand.py", line 2281, in do_slater
    t, premult, bh, rewrite=None)
  File "/usr/local/lib/python2.7/dist-packages/sympy/simplify/hyperexpand.py", line 2038, in _hyperexpand
    ops += devise_plan(func, formula.func, z0)
  File "/usr/local/lib/python2.7/dist-packages/sympy/simplify/hyperexpand.py", line 1615, in devise_plan
    raise ValueError('Non-suitable parameters.')
ValueError: Non-suitable parameters.

What does this error mean? 这个错误是什么意思?

Many of SymPy's routines struggle to handle floating point numbers, especially in exponents. SymPy的许多例程都难以处理浮点数,尤其是在指数中。 Use rational numbers whenever possible. 尽可能使用有理数。 More discussion in common gotchas and pitfalls . 有关常见陷阱和陷阱的更多讨论。

>>> x,x1,x2,t=symbols('x x1 x2 t')
>>> f=t*x1*x2*(x-t)**(-Rational('0.5'))
>>> integrate(f,t).simplify()
Piecewise((2*sqrt(x)*x1*x2*(-I*t**2*sqrt((t - x)/x) - I*t*x*sqrt((t - x)/x) + 2*t*x + 2*I*x**2*sqrt((t - x)/x) - 2*x**2)/(3*(t - x)), Abs(t/x) > 1), (2*sqrt(x)*x1*x2*(-t**2*sqrt((-t + x)/x) - t*x*sqrt((-t + x)/x) + 2*t*x + 2*x**2*sqrt((-t + x)/x) - 2*x**2)/(3*(t - x)), True))

Not the nicest answer, but it's an answer. 不是最好的答案,但这是一个答案。 If you know that x and t are, say, positive, it might help in simplification to declare it as such from the beginning. 如果您知道x和t是正数,那么从一开始就声明它为x可能有助于简化。 There are also two cases depending on Abs(t/x) being greater than 1 or not. 根据Abs(t/x)是否大于1,也有两种情况。

Ways to create the rational exponent 1/2: 创建有理指数1/2的方法:

  • Rational(1, 2)
  • Rational('0.5')
  • S(1)/2
  • or just use sqrt function, which has the same effect. 或仅使用sqrt函数,其效果相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM