# 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.

edit retag close merge delete

Sort by » oldest newest most voted

This 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))

more

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.

more I 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)

more