Ask Your Question
2

Piecewise, Sage VS Mathematica

asked 14 years ago

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

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 14 years ago

niles gravatar image

updated 14 years ago

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.

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

Stats

Asked: 14 years ago

Seen: 792 times

Last updated: Dec 23 '10