[sage-support] Re: Derivative of functions ...

2018-11-02 Thread Matthias Koeppe
On Friday, November 2, 2018 at 5:44:34 PM UTC-7, Emmanuel Charpentier wrote:
>
> 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)
> [...] Except for the point 0, for which the piecewise function is not 
> defined :
>
>>
>>
For the half-open interval, one needs to use RealSet constructors:

sage: 
f=piecewise([((-oo,0),x^3),(RealSet.unbounded_above_closed(0),x^2)],var=x)
sage: f
piecewise(x|-->x^3 on (-oo, 0), x|-->x^2 on [0, +oo); x)

-- 
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 sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


[sage-support] Re: Derivative of functions ...

2018-11-02 Thread Emmanuel Charpentier
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)
---
ValueErrorTraceback (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 sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


[sage-support] Re: Derivative of functions ...

2018-10-31 Thread Francesco


Il giorno mercoledì 31 ottobre 2018 10:11:34 UTC+1, Francesco ha scritto:
>
> 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 ?
>

Ok,  the piecewise-defined functions can be written with the sign(x) 
function. The funz(x) can be written as:

funz(x)=(x^2)*(sign(x)+1)/2+(x^3)*(-sign(x)+1)/2

-- 
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 sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.