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.Fri, 13 Sep 2013 04:28:54 -0500plot sqrt(sin(x))http://ask.sagemath.org/question/8049/plot-sqrtsinx/is there a way to plot this kind of functions right?
plot(sqrt(sin(x)),(0,10))
verbose 0 (4069: plot.py, generate_plot_points) WARNING: When plotting,
failed to evaluate function at 74 points.
verbose 0 (4069: plot.py, generate_plot_points) Last error message: ''
Sat, 02 Apr 2011 22:55:53 -0500http://ask.sagemath.org/question/8049/plot-sqrtsinx/Answer by kcrisman for <p>is there a way to plot this kind of functions right?</p>
<p>plot(sqrt(sin(x)),(0,10))</p>
<p>verbose 0 (4069: plot.py, generate_plot_points) WARNING: When plotting,
failed to evaluate function at 74 points.
verbose 0 (4069: plot.py, generate_plot_points) Last error message: ''</p>
http://ask.sagemath.org/question/8049/plot-sqrtsinx/?answer=12257#post-id-12257I think that the current best way to deal with your issue is to know ahead of time what the domain is.
sage: plot(sqrt(sin(x)),(x,0,pi))+plot(sqrt(sin(x)),(x,2*pi,3*pi))
Which isn't ideal, but could be enough for you.
However, I agree that the current behavior looks pretty bad, so [Ticket 11123](http://trac.sagemath.org/sage_trac/attachment/ticket/11123/) is now dedicated to this.
As another workaround, you could do
sage: plot(sqrt(sin(x)),(0,10),plot_points=40000)
but even that looks not the greatest, and takes forever.Mon, 04 Apr 2011 04:57:43 -0500http://ask.sagemath.org/question/8049/plot-sqrtsinx/?answer=12257#post-id-12257Comment by kcrisman for <p>I think that the current best way to deal with your issue is to know ahead of time what the domain is. </p>
<pre><code>sage: plot(sqrt(sin(x)),(x,0,pi))+plot(sqrt(sin(x)),(x,2*pi,3*pi))
</code></pre>
<p>Which isn't ideal, but could be enough for you.</p>
<p>However, I agree that the current behavior looks pretty bad, so <a href="http://trac.sagemath.org/sage_trac/attachment/ticket/11123/">Ticket 11123</a> is now dedicated to this.</p>
<p>As another workaround, you could do</p>
<pre><code>sage: plot(sqrt(sin(x)),(0,10),plot_points=40000)
</code></pre>
<p>but even that looks not the greatest, and takes forever.</p>
http://ask.sagemath.org/question/8049/plot-sqrtsinx/?comment=17016#post-id-17016I should point out that [Ticket 13246](http://trac.sagemath.org/ticket/13246) has a patch for this issue, though it's not been included in Sage yet.Fri, 13 Sep 2013 04:28:54 -0500http://ask.sagemath.org/question/8049/plot-sqrtsinx/?comment=17016#post-id-17016Answer by parzan for <p>is there a way to plot this kind of functions right?</p>
<p>plot(sqrt(sin(x)),(0,10))</p>
<p>verbose 0 (4069: plot.py, generate_plot_points) WARNING: When plotting,
failed to evaluate function at 74 points.
verbose 0 (4069: plot.py, generate_plot_points) Last error message: ''</p>
http://ask.sagemath.org/question/8049/plot-sqrtsinx/?answer=12252#post-id-12252If you only want to get rid of the part where sin(x) is negative you can use
maxima.plot2d(sqrt(sin(x)),[x,0,10])
(write this in sage - it has a maxima interface built in).
However, since the values of sqrt(sin(x)) in these places are complex, a possibly better visualization of it is
complex_plot(sqrt(sin(x)), (0, 10), (-1, 1))
This is a strip around the range you are interested in. Here is an explanation of the output, from sage manual:
The magnitude of the output is indicated by the brightness (with zero being black and infinity being white) while the argument is represented by the hue (with red being positive real, and increasing through orange, yellow, ... as the argument increases).
[This page](http://commons.wikimedia.org/wiki/User:Jan_Homann/Mathematics) demonstrates and explains some complex plots.Sat, 02 Apr 2011 23:37:58 -0500http://ask.sagemath.org/question/8049/plot-sqrtsinx/?answer=12252#post-id-12252Comment by Georg Damm for <p>If you only want to get rid of the part where sin(x) is negative you can use</p>
<pre><code>maxima.plot2d(sqrt(sin(x)),[x,0,10])
</code></pre>
<p>(write this in sage - it has a maxima interface built in).</p>
<p>However, since the values of sqrt(sin(x)) in these places are complex, a possibly better visualization of it is</p>
<pre><code>complex_plot(sqrt(sin(x)), (0, 10), (-1, 1))
</code></pre>
<p>This is a strip around the range you are interested in. Here is an explanation of the output, from sage manual:</p>
<p>The magnitude of the output is indicated by the brightness (with zero being black and infinity being white) while the argument is represented by the hue (with red being positive real, and increasing through orange, yellow, ... as the argument increases).</p>
<p><a href="http://commons.wikimedia.org/wiki/User:Jan_Homann/Mathematics">This page</a> demonstrates and explains some complex plots.</p>
http://ask.sagemath.org/question/8049/plot-sqrtsinx/?comment=21917#post-id-21917This is a good workaround - thanks :) But I consider it still a bug - any objections? How can this be used in sagetex?Sun, 03 Apr 2011 02:42:35 -0500http://ask.sagemath.org/question/8049/plot-sqrtsinx/?comment=21917#post-id-21917Comment by parzan for <p>If you only want to get rid of the part where sin(x) is negative you can use</p>
<pre><code>maxima.plot2d(sqrt(sin(x)),[x,0,10])
</code></pre>
<p>(write this in sage - it has a maxima interface built in).</p>
<p>However, since the values of sqrt(sin(x)) in these places are complex, a possibly better visualization of it is</p>
<pre><code>complex_plot(sqrt(sin(x)), (0, 10), (-1, 1))
</code></pre>
<p>This is a strip around the range you are interested in. Here is an explanation of the output, from sage manual:</p>
<p>The magnitude of the output is indicated by the brightness (with zero being black and infinity being white) while the argument is represented by the hue (with red being positive real, and increasing through orange, yellow, ... as the argument increases).</p>
<p><a href="http://commons.wikimedia.org/wiki/User:Jan_Homann/Mathematics">This page</a> demonstrates and explains some complex plots.</p>
http://ask.sagemath.org/question/8049/plot-sqrtsinx/?comment=21893#post-id-21893I agree that detecting the domain of definition is desirable (at least as an option), and since maxima does it it should be possible. I have no experience with sagetex so I can't help there.Tue, 05 Apr 2011 12:59:06 -0500http://ask.sagemath.org/question/8049/plot-sqrtsinx/?comment=21893#post-id-21893