On Oct 15, 4:12 pm, erikson1970 <leifhi...@gmail.com> wrote:
> Piecewise Function: endpoint gotcha - bug or feature?
> It seems that the piecewise function (which requires overlapping
> endpoints for the specified function intervals) does some unadvertised
> averaging for results for values at the endpoints.
>
> See the sage output from the input below.
>
> Rather than pick one of the function intervals for the result - it
> seems to average the two
>
> Nothing jumped out at me in the documentation on this matter.
>

Naively, I guess it's buyer beware:

sage: Piecewise?
<snip>
We assume that these definitions are consistent (ie, no checking is
done).

But actually, it is in the documentation, but well hidden:

sage: sage.functions.piecewise.PiecewisePolynomial.__call__?
Evaluates self at x0.  Returns the average value of the jump if x0 is
an interior endpoint of one of the intervals of self and the usual
value otherwise.

So it's feature-like.  Still, at the very least the documentation
could be clearer.

> Is there a way to force the piecewise function to use the function
> result from the upper or lower function interval when at an interval
> boundary?

Apparently not at this time (unless one used a Python function, but
that would defeat the purpose of using Piecewise).  The correct
solution to all of this is to rewrite piecewise functions to allow
whatever you want from this standpoint (and fix lots of other things),
which several people have on their to-do list (including me), but it's
also a big project, and filled with design decisions like this.  Do
you catch it (if you can! since checking for equality is non-trivial),
or do this, or what?  I'm not sure.

Hope this helps!

- kcrisman

>
> INPUT:
>
> #This code defines a piecewise function which is -1 below pi/2 and 2
> above pi/2.
> f1(x) = -1
> f2(x) = 2
> fp = Piecewise([[(0,pi/2),f1],[(pi/2,pi),f2]])
> # When pi/2 is put into the function, it averages the two results from
> the adjoining function definitions.
> # just above and just below the interval boundary the results are
> correct.
> dn=0.000001               # some small interval
> for n in [-dn,0,dn]:
>     print "fp(pi/2 + ",n,")= ",fp(pi/2+n)
>
> OUTPUT:
>
> fp(pi/2 +  -1.00000000000000e-6 )=  -1
> fp(pi/2 +  0 )=  1/2
> fp(pi/2 +  1.00000000000000e-6 )=  2
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to