Ask Your Question
1

help with simple integration of piecewise function?

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

Neal gravatar image

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

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/Sage-6.3.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/functions/piecewise.py", line 833, in integral
return F(b) - F(a)

File "/Applications/Sage-6.3.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/functions/piecewise.py", 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/Sage-6.3.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/symbolic/callable.py", 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/Sage-6.3.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/symbolic/integration/integral.py", 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
2

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

tmonteil gravatar image

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

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

Stats

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

Seen: 2,240 times

Last updated: Nov 17 '14