Ask Your Question
2

Piecewise, Sage VS Mathematica

asked 2010-12-23 14:15:43 +0100

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 14:26:33 +0100

niles gravatar image

updated 2010-12-23 14:30:48 +0100

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 14:15:43 +0100

Seen: 771 times

Last updated: Dec 23 '10