Ask Your Question
0

unaccurate plot of a circle

asked 2013-03-19 13:39:36 +0100

mathematicboy gravatar image

updated 2015-01-14 14:26:18 +0100

FrédéricC gravatar image

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 flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted
2

answered 2013-03-19 15:27:50 +0100

calc314 gravatar image

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))
edit flag offensive delete link more

Comments

Yes, implicit plotting is the way to go.

kcrisman gravatar imagekcrisman ( 2013-03-19 16:14:16 +0100 )edit
1

answered 2013-03-19 20:48:41 +0100

mathematicboy gravatar image

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

edit flag offensive delete link more
0

answered 2013-03-19 15:42:16 +0100

ndomes gravatar image

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)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-03-19 13:39:36 +0100

Seen: 589 times

Last updated: Mar 19 '13