Ask Your Question
0

piecewise function with variable within domains

asked 7 years ago

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

Preview: (hide)

Comments

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

mforets gravatar imagemforets ( 7 years ago )

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 ( 7 years ago )

1 Answer

Sort by » oldest newest most voted
0

answered 7 years ago

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)

my_piecewise(0.2,0.7).plot()
Preview: (hide)
link

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

Stats

Asked: 7 years ago

Seen: 423 times

Last updated: Oct 09 '17