Hi,
I'm having trouble with some piecewise constant functions.
Suppose that I define
f=Piecewise ([([0,1],0),([1,2],x-1)])
Then f.integral() works as expected, but f.derivative() will fail with
TypeError: 'sage.rings.integer.Integer' object is not callable
It seems that Sage does not understand that 0 is the null function,
and treat it as an integer for with a derivative is not meaningful
Then, I've tried defining
f1=Piecewise ([([0,1],ConstantFunction(0)),([1,2],x-1)])
My last try was to cast 0 to the symbolic ring
f2=Piecewise ([([0,1],SR(0)),([1,2],x-1)])
Now f2.integral() works, but f2.derivative() fails with the error message
ValueError: the number of arguments must be less than or equal to 0
Whats the right way to define my function so that both integral and
derivative work ?
The behavior of Sage is annoying ! Any help is
welcome!
sage-6.3-x86_64-Linux/src/bin/sage-ipython:1:
DeprecationWarning: Substitution using function-call syntax and
unnamed arguments is deprecated and will be removed from a future
release of Sage; you can use named arguments instead, like EXPR(x=...,
y=...)
See http://trac.sagemath.org/5930 for details.
#!/usr/bin/env python
Piecewise defined function with 1 parts, [[(1/3, 1/2), x |--> 1]]
A bit annoying message, not?
f3=Piecewise([([0,1],SR(0).function(x)),([1,2],(1-x).function(x))])
Writing something like
SR(0).function(x)
instead of
ConstantFunction(0)
is not what most mathematicians or students would do, I guess. Maybe
there is something to improve here.
f = Piecewise([[(-1,1), sin(x^2)]])
t = f.trapezoid(3)
Piecewise defined function with 3 parts, [[(-1, -1/3), -3/2*(x + 1)*(sin(1) - sin(1/9)) + sin(1)], [(-1/3, 1/3), sin(1/9)], [(1/3, 1), 1/2*(3*x - 1)*(sin(1) - sin(1/9)) + sin(1/9)]]
ValueError: the number of arguments must be less than or equal to 0
Hi,
I believe the solution of Nils using SR(0) is very elegant, but it cannot be applied in every case. For example, when the piecewise is created by another method (trapezoid):
f = Piecewise([[(-1,1), sin(x^2)]])
f = Piecewise([[(-1,1), sin(x^2).function(x)]])
t = f.trapezoid(3)
Here t has a constant part in (-1/3,1/3):
Piecewise defined function with 3 parts, [[(-1, -1/3), -3/2*(x + 1)*(sin(1) - sin(1/9)) + sin(1)], [(-1/3, 1/3), sin(1/9)], [(1/3, 1), 1/2*(3*x - 1)*(sin(1) - sin(1/9)) + sin(1/9)]]
So t(0.1) gives the following error:
ValueError: the number of arguments must be less than or equal to 0