Ask Your Question

Piecewise, Sage VS Mathematica

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

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

niles gravatar image

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

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

Seen: 691 times

Last updated: Dec 23 '10