> Are you aware of the function piecewise(), which seems to do what you
> want?  If there is a problem with using it, what is it?

I wasn't aware of piecewise(), and although it doesn't seem as elegant
or flexible as being able to use Indicator functions in my function
definitions, I think it  should work.  That said, what I actually want
is to define an additively separable function of two variables where
one component is piecewise.  But creating this function with a
piecewise component isn't working.  Here's what happens:

sage: f1(x) = -1
sage: f2(x) = 2
sage: f = Piecewise([[(0,pi/2),f1],[(pi/2,pi),f2]])
sage: f
Piecewise defined function with 2 parts, [[(0, 1/2*pi), x |--> -1],
[(1/2*pi, pi), x |--> 2]]
sage: g(x,y) = y + f(x)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call
last)

/Users/dmckee/.sage/temp/eve/19724/
_Users_dmckee_Documents_work_research_mexbeq_sage_spline_numeric_solutions_sage_188.py
in <module>()

/Applications/sage/local/lib/python2.5/site-packages/sage/functions/
piecewise.pyc in __call__(self, x0)
    605             if endpts[i] < x0 < endpts[i+1]:
    606                 return self.functions()[i](x0)
--> 607         raise ValueError,"Value not defined outside of
domain."
    608
    609     def which_function(self,x0):

ValueError: Value not defined outside of domain.

I must be doing something dumb (again), right?

Thanks again for all your help!

Doug

>
> M. Hampton
>
> On Jul 21, 12:34 pm, Doug <mcke...@gmail.com> wrote:
>
> > I'm trying to do something that seems very simple but isn't working.
> > Hence the post here :)
>
> > I want to define a very simple piecewise linear function.  It's linear
> > with slope alpha up to a knot at c and then it's linear with slope
> > beta.  Here's what I thought might work:
>
> >     f(x) = (x<=c)*alpha*x + (x>c)*(alpha*c + beta*(x-c))
>
> > Putting the inequalities in there caused a big mess.  So I tried
> > defining a Python Indicator function that turns Truth values into 0 or
> > 1, and then I wrapped my relational expressions with it:
>
> >     def Indicator(cond):
> >          if (cond==True):
> >               return 1
> >          else:
> >               return 0
>
> > This didn't work either:
>
> >     sage: foo(x) = Indicator(x>4) ; foo
> >     x |--> 0
>
> > Any other ideas?  I suppose I could in this case define my piecewise
> > function as a Python function, but then I won't be able to do as much
> > with it later (e.g., differentiate it).
>
> > Thx as usual, Doug
--~--~---------~--~----~------------~-------~--~----~
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
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to