# piecewise function with variable within domains

Dear all,

I am trying to define a piecewise function where the domains are parametrized by some variable:

import sage.all as sage
sage.var('x')
sage.var('x0')
sage.var('x1')
sage.assume( 0<x0)
sage.assume(x0<x1)
sage.assume(x1< 1)
sage.piecewise([((0,x0),0), ([x0,x1],1), ((x1,1),1)], var=x)


However, I cannot seem to get it to work:

TypeError: unable to simplify to a real interval approximation


Any idea how to make it work? Thanks!

Martin

edit retag close merge delete

a workaround is to define it as linear combination of heaviside, or step functions. these special functions are documented here.

The constructor

f = sage.piecewise( [ ((0,x0),0), ([x0,x1],1), ((x1,1),2) ], var=x )


crashes because RLF( x0 ) makes no sense. It is generally not a good idea to assume that code written for a special purpose can do the same job for a similar mathematical, possibly more general situation. But let's say the constructor would have instantiated something (now with possibly broken methods).

Which is the application of the above?

Make "it" work for which purpose?

What should be done now with "that f that works" ?

Sort by » oldest newest most voted def my_piecewise(x0,x1):
if 0 < x0 < x1 < 1:
return piecewise([((0,x0),0), ([x0,x1],1), ((x1,1),2)], var=x)

my_piecewise(0.2,0.7).plot()

more