ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 20 Sep 2016 14:37:59 -0500How do I plot a function undefined in some areas?http://ask.sagemath.org/question/34850/how-do-i-plot-a-function-undefined-in-some-areas/ I am trying to plot `f(x,z)` which is undefined in some areas. When I try to plot some other function, I can get it to work easily because Sage restricts the plot to the area where the function is real. E.g.:
plot3d(sqrt(1-x^2-y^2), (x,-5,5), (y,-5,5))
The border is a bit weird, but it works. I cannot get a working plot with my code, however. I also tried to wrap the function with a `try ... except` statement but I don't know what to return:
var("x y z")
def wrap(exp, a, b):
try:
return exp(x=a, z=b)
except ValueError:
return None
plot3d(lambda x,y: wrap(f, x, y), (x, -t, t), (y, -t, t)).show(aspect_ratio=1)
My function is `f` and it contains variables `x` and `z`.Sun, 18 Sep 2016 15:02:42 -0500http://ask.sagemath.org/question/34850/how-do-i-plot-a-function-undefined-in-some-areas/Answer by paulmasson for <p>I am trying to plot <code>f(x,z)</code> which is undefined in some areas. When I try to plot some other function, I can get it to work easily because Sage restricts the plot to the area where the function is real. E.g.:</p>
<pre><code>plot3d(sqrt(1-x^2-y^2), (x,-5,5), (y,-5,5))
</code></pre>
<p>The border is a bit weird, but it works. I cannot get a working plot with my code, however. I also tried to wrap the function with a <code>try ... except</code> statement but I don't know what to return:</p>
<pre><code>var("x y z")
def wrap(exp, a, b):
try:
return exp(x=a, z=b)
except ValueError:
return None
plot3d(lambda x,y: wrap(f, x, y), (x, -t, t), (y, -t, t)).show(aspect_ratio=1)
</code></pre>
<p>My function is <code>f</code> and it contains variables <code>x</code> and <code>z</code>.</p>
http://ask.sagemath.org/question/34850/how-do-i-plot-a-function-undefined-in-some-areas/?answer=34872#post-id-34872Try returning `NaN` (not a number).Tue, 20 Sep 2016 14:37:59 -0500http://ask.sagemath.org/question/34850/how-do-i-plot-a-function-undefined-in-some-areas/?answer=34872#post-id-34872