Ask Your Question

Piecewise, Sage VS Mathematica

asked 2010-12-23 07:15:43 -0600

fgv gravatar image

I´m transitioning from Mathematica to Sage. But I don´t know the way to write the piecewise function below in Sage:

f(x,a)= 0 ; x<=a

      (x-a)^2  ;  x>a

How can I do this?


edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2010-12-23 07:26:33 -0600

niles gravatar image

updated 2010-12-23 07:30:48 -0600

Will the following suit your needs?

def f(x,a):
    if x <= a:
        return 0
        return (x-a)^2

There is also a Piecewise class, but it doesn't look like it will work for what you want.

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


Asked: 2010-12-23 07:15:43 -0600

Seen: 605 times

Last updated: Dec 23 '10