ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 19 Mar 2013 14:48:41 -0500unaccurate plot of a circlehttps://ask.sagemath.org/question/9924/unaccurate-plot-of-a-circle/Hi!
I want to plot a circle centered at the origin and radius sqrt(2). When I type:
> plot(sqrt(2-x^2),-sqrt(2),sqrt(2),aspect_ratio=1)+plot(-sqrt(2-x^2),-sqrt(2),sqrt(2))
in sage 5.4, the graph obtained is really unaccurated.
However, for the circle of radius sqrt(3) works fine. Does anybody know why?
Of course I know there are several ways to plot a circle, but i want do do like this for showing my pupils some applications of integral calculus.
I think it is important to have a "plot" command working properly, since it is extensively used in teaching.Tue, 19 Mar 2013 07:39:36 -0500https://ask.sagemath.org/question/9924/unaccurate-plot-of-a-circle/Answer by mathematicboy for <p>Hi!</p>
<p>I want to plot a circle centered at the origin and radius sqrt(2). When I type:</p>
<blockquote>
<p>plot(sqrt(2-x^2),-sqrt(2),sqrt(2),aspect_ratio=1)+plot(-sqrt(2-x^2),-sqrt(2),sqrt(2))</p>
</blockquote>
<p>in sage 5.4, the graph obtained is really unaccurated.</p>
<p>However, for the circle of radius sqrt(3) works fine. Does anybody know why?</p>
<p>Of course I know there are several ways to plot a circle, but i want do do like this for showing my pupils some applications of integral calculus.</p>
<p>I think it is important to have a "plot" command working properly, since it is extensively used in teaching.</p>
https://ask.sagemath.org/question/9924/unaccurate-plot-of-a-circle/?answer=14668#post-id-14668Thank you for your answers.
Of course there are several ways to fix it, but my point is that I don't understand why it works with sqrt(3) and don't with sqrt(2). It seems a problem in accuracy. And it leads to a maybe not good algorithm for painting.
I think this kind of simple examples can transmit a poor image of Sage to pupils. Moreover, if you simply google "plot sqrt(2-x^2)" you obtain a more precise graph. And if you use an obsolete software like Mathematica 4.2 you obtain an ugly graph, but precise at extreme points. And maybe in older versions the result is the same, but i can't check it.
My point of view in this question is not to find alternatives to do a simple task when a command is not working properly in comparison to other softwares. Since it is an easy question there are several alternatives, but believe me, not all pupils are able to find them. My purpose is to ask if someone knows why the command is behaving like this and more interesting, if is there any plan to change it.
Sorry for my answer, but my wish is improve Sage.Tue, 19 Mar 2013 14:48:41 -0500https://ask.sagemath.org/question/9924/unaccurate-plot-of-a-circle/?answer=14668#post-id-14668Answer by calc314 for <p>Hi!</p>
<p>I want to plot a circle centered at the origin and radius sqrt(2). When I type:</p>
<blockquote>
<p>plot(sqrt(2-x^2),-sqrt(2),sqrt(2),aspect_ratio=1)+plot(-sqrt(2-x^2),-sqrt(2),sqrt(2))</p>
</blockquote>
<p>in sage 5.4, the graph obtained is really unaccurated.</p>
<p>However, for the circle of radius sqrt(3) works fine. Does anybody know why?</p>
<p>Of course I know there are several ways to plot a circle, but i want do do like this for showing my pupils some applications of integral calculus.</p>
<p>I think it is important to have a "plot" command working properly, since it is extensively used in teaching.</p>
https://ask.sagemath.org/question/9924/unaccurate-plot-of-a-circle/?answer=14665#post-id-14665This is a common numerical problem when plotting as the function approaches a vertical asymptote.
Raising the number of points plotted will make the picture nicer.
var('x y')
plot(sqrt(2-x^2),(x,1,3),plot_points=10000)
Generally, to plot a circle, it might be best to use `implicit_plot`.
var('x y')
implicit_plot(x^2+y^2==2,(x,-2,2),(y,-2,2))
Tue, 19 Mar 2013 09:27:50 -0500https://ask.sagemath.org/question/9924/unaccurate-plot-of-a-circle/?answer=14665#post-id-14665Comment by kcrisman for <p>This is a common numerical problem when plotting as the function approaches a vertical asymptote. </p>
<p>Raising the number of points plotted will make the picture nicer.</p>
<pre><code>var('x y')
plot(sqrt(2-x^2),(x,1,3),plot_points=10000)
</code></pre>
<p>Generally, to plot a circle, it might be best to use <code>implicit_plot</code>.</p>
<pre><code>var('x y')
implicit_plot(x^2+y^2==2,(x,-2,2),(y,-2,2))
</code></pre>
https://ask.sagemath.org/question/9924/unaccurate-plot-of-a-circle/?comment=18048#post-id-18048Yes, implicit plotting is the way to go.Tue, 19 Mar 2013 10:14:16 -0500https://ask.sagemath.org/question/9924/unaccurate-plot-of-a-circle/?comment=18048#post-id-18048Answer by ndomes for <p>Hi!</p>
<p>I want to plot a circle centered at the origin and radius sqrt(2). When I type:</p>
<blockquote>
<p>plot(sqrt(2-x^2),-sqrt(2),sqrt(2),aspect_ratio=1)+plot(-sqrt(2-x^2),-sqrt(2),sqrt(2))</p>
</blockquote>
<p>in sage 5.4, the graph obtained is really unaccurated.</p>
<p>However, for the circle of radius sqrt(3) works fine. Does anybody know why?</p>
<p>Of course I know there are several ways to plot a circle, but i want do do like this for showing my pupils some applications of integral calculus.</p>
<p>I think it is important to have a "plot" command working properly, since it is extensively used in teaching.</p>
https://ask.sagemath.org/question/9924/unaccurate-plot-of-a-circle/?answer=14666#post-id-14666I don't know the reason, but you are right and it is very funny, for example sqrt(17) gives a closed circle, sqrt(19) does not.
Using a numerical approximation seems to create closed circles in any case.
a = sqrt(2).n()
plot(sqrt(a^2-x^2),-a,a,aspect_ratio=1)+plot(-sqrt(a^2-x^2),-a,a)Tue, 19 Mar 2013 09:42:16 -0500https://ask.sagemath.org/question/9924/unaccurate-plot-of-a-circle/?answer=14666#post-id-14666