One way to define (something almost the same as) what you want is :
sage: f=piecewise([((-oo,0),x^3),((0,oo),x^2)],var=x)
sage: f
piecewise(x|-->x^3 on (-oo, 0), x|-->x^2 on (0, +oo); x)
An indeed; you can do
sage: plot(f(x),(x,-1,1), figsize=3)
which seems correct. Except for the point 0, for which the piecewise
function is not defined :
sage: f(0)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
...
ValueError: point 0 is not in the domain
You can even get :
sage: integrate(f,x)
piecewise(x|-->1/4*x^4 on (-oo, 0), x|-->1/3*x^3 on (0, +oo); x)
which seems corect (modulo the oint 0, again...)
But :
sage: diff(f,x)
(0, 0)*D[0]piecewise(x|-->x^3 on (-oo, 0), x|-->x^2 on (0, +oo); x) +
D[1]piecewise(x|-->x^3 on (-oo, 0), x|-->x^2 on (0, +oo); x)
sounds sheer nonsense to me...
BTW, piecewise.py, which defines piecewise functions, defines the integral,
but not the derivative...
BUT I might not understand something obvious : the problem might reside
between my chair and my keyboard...
I also ,note that all "method-calling" calls (f.integrate(x),
f(x).integrate(x), etc...) fail with the cryptic for now) message : "TypeError:
__call__() takes exactly 2 arguments (3 given)".
I think that this issue deserves exploration...
Le mercredi 31 octobre 2018 10:11:34 UTC+1, Francesco a écrit :
>
> Hello; I have installed sage 8.4 and I have problem with the derivatives
> ...
> I have defined a function in sage of this type:
>
> x=var('x')
> def funz(x):
> if x >= 0:
> return x^2
> else:
> return x^3
>
> but, when I try to calculate
>
> diff(funz(x),x)
>
> I obtain only
>
> 3x^2
>
> and this is wrong !! Can you help me ?
>
--
You received this message because you are subscribed to the Google Groups
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.