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:

sage: f(1)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/home/bacani/<ipython console> in <module>()
/opt/sage-4.6.2-linux-32bit-ubuntu_10.04_lts-i686-Linux-i686-Linux/local/lib/python2.6/site-packages/sage/functions/piecewise.pyc
 
in __call__(self, x0)
    638         for i in range(1,n):
    639             if x0 == endpts[i]:
--> 640                 return (self.functions()[i-1](x0) + 
self.functions()[i](x0))/2
    641         if x0 == endpts[0]:
    642             return self.functions()[0](x0)
TypeError: 'sage.rings.integer.Integer' object is not callable



And if I try to plot the function, I get:

---------------------------------------------------------------------------

ZeroDivisionError                         Traceback (most recent call last)

/home/bacani/<ipython console> in <module>()

/opt/sage-4.6.2-linux-32bit-ubuntu_10.04_lts-i686-Linux-i686-Linux/local/lib/python2.6/site-packages/sage/misc/decorators.pyc
 
in wrapper(*args, **kwds)

    571                     kwds[new_name] = kwds[old_name]

    572                     del kwds[old_name]

--> 573             return func(*args, **kwds)

    574         

    575         return wrapper

/opt/sage-4.6.2-linux-32bit-ubuntu_10.04_lts-i686-Linux-i686-Linux/local/lib/python2.6/site-packages/sage/misc/decorators.pyc
 
in wrapper(*args, **kwds)

    430                 options['__original_opts'] = kwds

    431             options.update(kwds)

--> 432             return func(*args, **options)

    433 

    434         

/opt/sage-4.6.2-linux-32bit-ubuntu_10.04_lts-i686-Linux-i686-Linux/local/lib/python2.6/site-packages/sage/plot/plot.pyc
 
in plot(funcs, *args, **kwds)

   3024 

   3025     if hasattr(funcs, 'plot'):

-> 3026         G = funcs.plot(*args, **original_opts)

   3027     # if we are using the generic plotting method

   3028     else:

/opt/sage-4.6.2-linux-32bit-ubuntu_10.04_lts-i686-Linux-i686-Linux/local/lib/python2.6/site-packages/sage/functions/piecewise.pyc
 
in plot(self, *args, **kwds)

   1000         """

   1001         from sage.plot.all import plot

-> 1002         return sum([plot(f, a, b, *args, **kwds) for (a,b),f in 
self.list()])

   1003  

   1004     def fourier_series_cosine_coefficient(self,n,L):

/opt/sage-4.6.2-linux-32bit-ubuntu_10.04_lts-i686-Linux-i686-Linux/local/lib/python2.6/site-packages/sage/misc/decorators.pyc
 
in wrapper(*args, **kwds)

    571                     kwds[new_name] = kwds[old_name]

    572                     del kwds[old_name]

--> 573             return func(*args, **kwds)

    574         

    575         return wrapper

/opt/sage-4.6.2-linux-32bit-ubuntu_10.04_lts-i686-Linux-i686-Linux/local/lib/python2.6/site-packages/sage/misc/decorators.pyc
 
in wrapper(*args, **kwds)

    430                 options['__original_opts'] = kwds

    431             options.update(kwds)

--> 432             return func(*args, **options)

    433 

    434         

/opt/sage-4.6.2-linux-32bit-ubuntu_10.04_lts-i686-Linux-i686-Linux/local/lib/python2.6/site-packages/sage/plot/plot.pyc
 
in plot(funcs, *args, **kwds)

   3043             xmax = args[1]

   3044             args = args[2:]

-> 3045             G = _plot(funcs, (xmin, xmax), *args, **kwds)

   3046         elif n == 3:

   3047         # if there are three extra args, then pull them out and pass 
them as a tuple

/opt/sage-4.6.2-linux-32bit-ubuntu_10.04_lts-i686-Linux-i686-Linux/local/lib/python2.6/site-packages/sage/plot/plot.pyc
 
in _plot(funcs, xrange, parametric, polar, fill, label, randomize, 
**options)

   3146             exclude = None

   3147     else:

-> 3148         data = generate_plot_points(f, xrange, plot_points, 
adaptive_tolerance, adaptive_recursion, randomize)

   3149  

   3150     if parametric:

/opt/sage-4.6.2-linux-32bit-ubuntu_10.04_lts-i686-Linux-i686-Linux/local/lib/python2.6/site-packages/sage/plot/plot.pyc
 
in generate_plot_points(f, xrange, plot_points, adaptive_tolerance, 
adaptive_recursion, randomize, initial_points)

   4146     ignore, ranges = setup_for_eval_on_grid([], [xrange], 
plot_points)

   4147     xmin, xmax, delta = ranges[0]

-> 4148     data = srange(*ranges[0], include_endpoint=True)

   4149 

   4150     random = current_randstate().python_random().random

/opt/sage-4.6.2-linux-32bit-ubuntu_10.04_lts-i686-Linux-i686-Linux/local/lib/python2.6/site-packages/sage/misc/misc.pyc
 
in srange(start, end, step, universe, check, include_endpoint, 
endpoint_tolerance)

    974             return range(start, end, step)

    975 

--> 976     L = 
list(xsrange(start,end,step,universe,check,include_endpoint,endpoint_tolerance))

    977     return L

    978 

/opt/sage-4.6.2-linux-32bit-ubuntu_10.04_lts-i686-Linux-i686-Linux/local/lib/python2.6/site-packages/sage/misc/misc.pyc
 
in xsrange(start, end, step, universe, check, include_endpoint, 
endpoint_tolerance)

   1061             return xrange(start, end, step)

   1062     

-> 1063     count = (end-start)/step

   1064     if not isinstance(universe, type) and universe.is_exact():

   1065         icount = int(math.ceil(float(count)))

ZeroDivisionError: float division



Any help?
Thanks in advance,
Felipo

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to