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.Tue, 17 Dec 2019 23:33:00 +0100How do i plot a piecewise function with functional constraints?https://ask.sagemath.org/question/49060/how-do-i-plot-a-piecewise-function-with-functional-constraints/ I have to plot a function T(x,x) which equals x*y if x*y>0 and x+y otherwise. I have defined the function:
def T(x,y):
if (x*y>0):
return x*y
else:
return x+y
but it does not work.Tue, 17 Dec 2019 15:34:09 +0100https://ask.sagemath.org/question/49060/how-do-i-plot-a-piecewise-function-with-functional-constraints/Answer by eric_g for <p>I have to plot a function T(x,x) which equals x<em>y if x</em>y>0 and x+y otherwise. I have defined the function:</p>
<pre><code>def T(x,y):
if (x*y>0):
return x*y
else:
return x+y
</code></pre>
<p>but it does not work.</p>
https://ask.sagemath.org/question/49060/how-do-i-plot-a-piecewise-function-with-functional-constraints/?answer=49062#post-id-49062To plot a Python function (i.e. a function defined by means of `def`), simply provide the function's name to the plot function. In your case this is `T` and not `T(x, y)`:
plot3d(T, (-2, 2), (-2, 2))
works well with the function `T` that you have defined. Tue, 17 Dec 2019 23:33:00 +0100https://ask.sagemath.org/question/49060/how-do-i-plot-a-piecewise-function-with-functional-constraints/?answer=49062#post-id-49062