Ask Your Question

piecewise function with variable within domains

asked 2017-10-08 19:30:19 +0100

maaaaaaartin gravatar image

Dear all,

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

import sage.all as sage
sage.assume( 0<x0)
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!


edit retag flag offensive close merge delete


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

mforets gravatar imagemforets ( 2017-10-09 07:21:47 +0100 )edit

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

dan_fulea gravatar imagedan_fulea ( 2017-10-09 23:37:53 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-10-09 12:19:26 +0100

ndomes gravatar image

What's about a python function?

def my_piecewise(x0,x1):
    if 0 < x0 < x1 < 1:
        return piecewise([((0,x0),0), ([x0,x1],1), ((x1,1),2)], var=x)

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-10-08 19:30:19 +0100

Seen: 283 times

Last updated: Oct 09 '17