On Jun 7, 9:58 pm, Felipo Bacani <felipo.bac...@gmail.com> wrote:
> Hello.
>
> How do I define a piecewise function that are discontinuous in one point?
> I mean, how do I define a piecewise function f(x) if it is like
>         x    if 0<x<1
> f(x)=2    if x=1
>         2-x if 1<x<2
>
> If I try the command below:
>
> sage: f= Piecewise([ [(0,1), x], [(1,1), 2], [(1,2), 2-x] ])
>
> There's no error, however if I try to calculate f(1), I get:
>

Very sadly, the Piecewise class needs a lot of TLC.  It was
implemented in the prehistory of Sage, in a huge effort by David
Joyner, when there was virtually no symbolic or plotting capability
whatsoever, and hasn't been updated tons since.

You may want to try a Python function instead.

def f(x):
    if x==1:
        return 2
    elif x<1:
        return x
    else:
        return 2-x

This will plot and evaluate correctly.  You can't differentiate it or
integrate it, though.

We would very much welcome help in bringing piecewise functions up to
date, but it will be a big task to integrate them properly with our
symbolics (Pynac).

To devels interested in this topic:

I also just discovered http://maxima-project.org/wiki/index.php?title=Pw.mac
which could be useful to us in this effort - seems relatively
comprehensive, from a respected member of the Maxima community.

- kcrisman

-- 
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