Ask Your Question
1

Symbolic integration with parameter

asked 2024-10-04 21:20:28 +0100

Emm gravatar image

Hello, The following is a bit annoying, even though I can imagine the origin of the bug. Is there a systematic way to avoid this?

t=var('t')
J(kk)=integrate(exp(-2*pi*I*kk*t),t,0,1)

Whereas J(1) returns the correct value (0), J(0) returns a

ValueError: power::eval(): division by zero

and in a longer version:

--------------------------------------------------------------------------- ValueError
Traceback (most recent call last) Cell In[9], line 1 ----> 1 I(Integer(0))

File /private/var/tmp/sage-10.3-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/symbolic/expression.pyx:6187, in sage.symbolic.expression.Expression.__call__ (build/cythonized/sage/symbolic/expression.cpp:78521)() 6185 z^2 + x^y 6186 """ -> 6187 return self._parent._call_element_(self, args, *kwds) 6188 6189 def variables(self):

File /private/var/tmp/sage-10.3-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/symbolic/callable.py:422, in CallableSymbolicExpressionRing_class._call_element_(self, _the_element, *args, kwds) 420 d = dict(zip([repr(_) for _ in self.arguments()], args)) 421 d.update(kwds) --> 422 return SR(_the_element.substitute(d))

File /private/var/tmp/sage-10.3-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/structure/element.pyx:849, in sage.structure.element.Element.substitute (build/cythonized/sage/structure/element.c:15440)() 847 5 848 """ --> 849 return self.subs(args, *kwds) 850 851

File /private/var/tmp/sage-10.3-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/symbolic/expression.pyx:5899, in sage.symbolic.expression.Expression.subs (build/cythonized/sage/symbolic/expression.cpp:76733)() 5897
smap.insert(make_pair((<expression>self.coerce_in(k))._gobj, 5898
(<expression>self.coerce_in(v))._gobj)) -> 5899 res = self._gobj.subs_map(smap, 0) 5900 return new_Expression_from_GEx(self._parent, res) 5901

ValueError: power::eval(): division by zero

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2024-10-04 21:36:30 +0100

You can add the keyword "hold" to integrate. Initial version:

sage: t=var('t')
sage: J(kk)=integrate(exp(-2*pi*I*kk*t),t,0,1)
sage: J(kk)
1/2*I*e^(-2*I*pi*kk)/(pi*kk) - 1/2*I/(pi*kk)

Note that the integral has already been computed. Instead:

sage: t=var('t')
sage: J(kk)=integrate(exp(-2*pi*I*kk*t),t,0,1, hold=True)
sage: J(kk)
integrate(e^(-2*I*pi*kk*t), t, 0, 1)
sage: J(0)
1
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2024-10-04 21:20:28 +0100

Seen: 124 times

Last updated: Oct 04