计算 sympy 错误消息中的符号限制

问题描述 投票:0回答:1

我尝试在 sympy 中计算符号限制,但收到错误消息。

import sympy as smp
from sympy import *
n,x=smp.symbols('n x')
limit(simplify(integrate(exp(-x)*exp(-smp.I*n*x),x).args[0][0]),x,smp.oo)

我收到以下错误消息:

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
Cell In[26], line 1
----> 1 limit(exp(-n*x),x,smp.oo)

File ~\anaconda3\Lib\site-packages\sympy\series\limits.py:64, in limit(e, z, z0, dir)
     13 def limit(e, z, z0, dir="+"):
     14     """Computes the limit of ``e(z)`` at the point ``z0``.
     15 
     16     Parameters
   (...)
     61      limit_seq : returns the limit of a sequence.
     62     """
---> 64     return Limit(e, z, z0, dir).doit(deep=False)

File ~\anaconda3\Lib\site-packages\sympy\series\limits.py:375, in Limit.doit(self, **hints)
    372 l = None
    374 try:
--> 375     r = gruntz(e, z, z0, dir)
    376     if r is S.NaN or l is S.NaN:
    377         raise PoleError()

File ~\anaconda3\Lib\site-packages\sympy\series\gruntz.py:732, in gruntz(e, z, z0, dir)
    729     else:
    730         raise NotImplementedError("dir must be '+' or '-'")
--> 732 r = limitinf(e0, z)
    734 # This is a bit of a heuristic for nice results... we always rewrite
    735 # tractable functions in terms of familiar intractable ones.
    736 # It might be nicer to rewrite the exactly to what they were initially,
    737 # but that would take some work to implement.
    738 return r.rewrite('intractable', deep=True)

File ~\anaconda3\Lib\site-packages\sympy\core\cache.py:72, in __cacheit.<locals>.func_wrapper.<locals>.wrapper(*args, **kwargs)
     69 @wraps(func)
     70 def wrapper(*args, **kwargs):
     71     try:
---> 72         retval = cfunc(*args, **kwargs)
     73     except TypeError as e:
     74         if not e.args or not e.args[0].startswith('unhashable type:'):

File ~\anaconda3\Lib\site-packages\sympy\series\gruntz.py:452, in limitinf(e, x)
    450     c0, e0 = mrv_leadterm(e.min, x)
    451 else:
--> 452     c0, e0 = mrv_leadterm(e, x)
    453 sig = sign(e0, x)
    454 if sig == 1:

File ~\anaconda3\Lib\site-packages\sympy\core\cache.py:72, in __cacheit.<locals>.func_wrapper.<locals>.wrapper(*args, **kwargs)
     69 @wraps(func)
     70 def wrapper(*args, **kwargs):
     71     try:
---> 72         retval = cfunc(*args, **kwargs)
     73     except TypeError as e:
     74         if not e.args or not e.args[0].startswith('unhashable type:'):

File ~\anaconda3\Lib\site-packages\sympy\series\gruntz.py:554, in mrv_leadterm(e, x)
    546 #
    547 # The positive dummy, w, is used here so log(w*2) etc. will expand;
    548 # a unique dummy is needed in this algorithm
   (...)
    551 # improved, or just find limits of Re and Im components separately.
    552 #
    553 w = Dummy("w", positive=True)
--> 554 f, logw = rewrite(exps, Omega, x, w)
    555 try:
    556     lt = f.leadterm(w, logx=logw)

File ~\anaconda3\Lib\site-packages\sympy\series\gruntz.py:647, in rewrite(e, Omega, x, wsym)
    645     sig = sign(g.exp, x)
    646     if sig != 1 and sig != -1 and not sig.has(AccumBounds):
--> 647         raise NotImplementedError('Result depends on the sign of %s' % sig)
    648 if sig == 1:
    649     wsym = 1/wsym  # if g goes to oo, substitute 1/w

NotImplementedError: Result depends on the sign of -sign(n)

................................................ ...................................................... ......................

数学结果应该是

0

任何人都可以解释我的输出并解决这个问题吗?

python sympy limit integrate
1个回答
0
投票

感谢您提供证据。这是正确的代码。

import sympy as smp
from sympy import *
x=symbols('x')
n,smp.I=symbols('n i',positive=True)
limit(simplify(integrate(exp(-x)*exp(-smp.I*n*x),x)),x,smp.oo)
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.