Piece-wise functions and plotting
Hi,
I have a piece-wise defined function that I want to plot (and potentially do other symbolic stuff with) and I was wondering how to do this. The problem is that I am defining my function as a Python function:
def F(x,y): if( x <= y ): return x*y return x+y
So I am gluing together two pieces, and I would like to be able to do
(x,y) = var('x,y') contour_plot( F(x,y), (x,0,1), (y,0,1) )
But the problem is that this only plots the second part. This occurs because x <= y evaluates as false (they are variables) and F(x,y) is always evaluated as x+y. In Mathematica there is the Which function that works on symbolic expression to make piece-wise definitions. Is there an equivalent in Sage? Is there another way to do this? If I had a function (say, delta) that just evaluated as 1 if the symbolic expression was true, and 0 if not, I could craft the function as:
F(x,y) = delta( x<=y ) * (x*y) + delta( x>y ) * (x+y)
But as it is, I think there is no way to do this. Is there?
Thanks a lot for your help,
Edgar
See http://trac.sagemath.org/sage_trac/ticket/11225. Unfortunately, no one has had the combination of time, expertise, and interest to update our piecewise functions from their original implementation - but there might be a helpful link for you there.
Yes, for one-dimensional piecewise functions that would work, but for two-dimensional or more, it would not, I am afraid.
Also, I just found out that Sage has the kronecker_delta function, so one could rewrite the above example as a product of two pieces, however, in my case I actually have three pieces and I would still need to find an appropriate transformation to map the pieces to non-overlapping conditions where the delta function would be 1 for exactly one of them. While possible, this is really not elegant. Any other thoughts?