ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 23 Dec 2010 14:26:33 +0100Piecewise, Sage VS Mathematicahttps://ask.sagemath.org/question/7830/piecewise-sage-vs-mathematica/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
Thu, 23 Dec 2010 14:15:43 +0100https://ask.sagemath.org/question/7830/piecewise-sage-vs-mathematica/Answer by niles for <p>I´m transitioning from Mathematica to Sage.
But I don´t know the way to write the piecewise function below in Sage:</p>
<p>f(x,a)= 0 ; x<=a</p>
<pre><code> (x-a)^2 ; x>a
</code></pre>
<p>How can I do this?</p>
<p>Thanks</p>
https://ask.sagemath.org/question/7830/piecewise-sage-vs-mathematica/?answer=11891#post-id-11891Will the following suit your needs?
def f(x,a):
if x <= a:
return 0
else:
return (x-a)^2
There is also a [`Piecewise`](http://www.sagemath.org/doc/reference/sage/functions/piecewise.html) class, but it doesn't look like it will work for what you want.Thu, 23 Dec 2010 14:26:33 +0100https://ask.sagemath.org/question/7830/piecewise-sage-vs-mathematica/?answer=11891#post-id-11891