Ask Your Question

help with simple integration of piecewise function?

asked 2014-11-16 23:35:36 +0200

Neal gravatar image

updated 2014-11-16 23:45:07 +0200

r = var('r')
Piecewise([[(1,2), 1/floor(r)]]).integral(r,1,2)

Gives an error:

Error in lines ... 
AttributeError: 'sage.rings.integer.Integer' object has no attribute 'variables

What am I doing wrong? I note that

Piecewise([[(1,2), 1/floor(r)]]).integral(r)

gives output ``Piecewise defined function with 1 parts, [[(1, 2), r1 |--> integrate(1/floor(r1), r1, 1, r1)]]''.

And that

integrate(1/floor(r1), r1, 1, r1)(2)

gives the same error as the first attempt. Here's the full stacktrace of the error:

EDIT: Thanks. Here's the full stack trace for the error:

File "/Applications/", line 833, in integral
return F(b) - F(a)

File "/Applications/", line 665, in __call__
return self.functions()[n-1](x0)

File "expression.pyx", line 4391, in sage.symbolic.expression.Expression.__call__ (build/cythonized/sage/symbolic/expression.cpp:21933)

File "/Applications/", line 477, in _call_element_
return SR(_the_element.substitute(**d))

File "expression.pyx", line 4242, in sage.symbolic.expression.Expression.substitute (build/cythonized/sage/symbolic/expression.cpp:21183)

File "/Applications/", line 161, in _eval_
if len(x.variables()) == 1:

File "element.pyx", line 344, in sage.structure.element.Element.__getattr__ (build/cythonized/sage/structure/element.c:4022)

File "misc.pyx", line 257, in sage.structure.misc.getattr_from_other_class (build/cythonized/sage/structure/misc.c:1775)
AttributeError: 'sage.rings.integer.Integer' object has no attribute 'variables'
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-11-17 00:50:42 +0200

tmonteil gravatar image

updated 2014-11-17 00:51:18 +0200

The method integral (as any other method) depends on the object it is applied to, so the syntax may not be the same for symbolic functions and piecewise functions. To see how the method integral works for piecewise functions, you can do:

sage: P = Piecewise([[(1,2), 1/floor(r)]])
sage: P.integral?
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


Asked: 2014-11-16 23:35:36 +0200

Seen: 2,201 times

Last updated: Nov 17 '14