Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
3

shift picewise functions

asked 13 years ago

sagefan gravatar image

Suppose I define a piecewise function f for example:

f = Piecewise([[(-infinity,1),1],[(1,+infinity),x]])

How to define the shifted function g with g(x) = f(x-2) for all x?

Or more generally: If h is another function. How to define g=fh in sage?

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
4

answered 12 years ago

rbeezer gravatar image

The following works as expected:

f1(x)=0
f2(x)=exp(-1/(x^2))
f=Piecewise([[(-10,0),f1],[(0,10),f2]])
h(x)=x-2
c = compose(f, h)
plot(c, -8, 12)
Preview: (hide)
link

Comments

Wow, I had no idea that existed. Nice!

kcrisman gravatar imagekcrisman ( 12 years ago )
2

answered 13 years ago

kcrisman gravatar image

To answer your second question:

sage: f(x) = x^2+5
sage: g(x) = 25*sqrt(x+1)
sage: g(f(x))
25*sqrt(x^2 + 6)
sage: f(g(x))
625*x + 630
sage: h(x) = f(g(x))
sage: h
x |--> 625*x + 630

The first one is harder, because Piecewise functions were implemented long before we even had symbolic functions, and hence are missing a lot of functionality. This is a long-standing need, but it takes a certain expertise in both the old and new code, as well as Ginac, to do this.

(To the cognoscenti - sympy seems to have piecewise functions, but I can't find much documentation, just obscure hints that they are there. How powerful are theirs?)

Preview: (hide)
link

Comments

So there is no workaround to compose piecewise-defined functions?

sagefan gravatar imagesagefan ( 13 years ago )

There may be, but I can't think of one offhand. That doesn't mean it doesn't exist, just that I can't think of it right now.

kcrisman gravatar imagekcrisman ( 13 years ago )

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 13 years ago

Seen: 797 times

Last updated: Oct 16 '12