Ask Your Question
2

Piecewise, Sage VS Mathematica

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

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?

Thanks

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
1

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

niles gravatar image

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

Will the following suit your needs?

def f(x,a):
    if x <= a:
        return 0
    else:
        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

Stats

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

Seen: 532 times

Last updated: Dec 23 '10