# Plot circle or ellipse with equation?

Given the standard equation of a circle:

x^2 + y^2 + 7x - 2y + 6 = 0 --Simplified-to--> (x+7/2)^2 + (y-1)^2 = 29/4

Standard formula of a circle: (x + (-h))^2 + (y + (-k))^2 = r^2 The center is represented by (h, k); radius by sqrt(r^2).

So my first question is, is there are way I could insert either of the 1st 2 equations and have Sage 5.9 generate the circle?

My second question similarly deals with an ellipse that has the simplified equation:

((x+2)^2)/9 + ((y-1)^2)/25 = 1

Its major axis is: (-2,-4) (-2,6) Minor axis is: (-5,1) (1,1)

Standard form of an ellipse is: ((x - (-h))^2)/b^2 + ((y + (-k))^2)/a^2

Center is determined by analyzing the differences between the x2/x1, y2/y1 coordinates of the major or minor axis (i.e. midpoint formula).

Could I generate an ellipse baed on the simplified equation?

edit retag close merge delete

Sort by » oldest newest most voted

You can use implicit_plot, either by giving a function of two variables (implicit_plot will plot the level set where the function is equal to 0):

sage: var('x,y')
sage: e(x,y) = ((x+2)^2)/9 + ((y-1)^2)/25
sage: implicit_plot(e - 1, (x,-5,1), (y,-4,6))


or by giving an equation in two variables (note the == sign):

sage: var('x,y')
sage: implicit_plot(((x+2)^2)/9 + ((y-1)^2)/25 == 1, (x,-5,1), (y,-4,6))

more

Thanks! As an added bonus I went ahead and plotted the y-axis/x-axis lines. Yax = x Xax = y p2 = implicit_plot(Yax, (x,-10,10), (y,-10,10)) p3 = implicit_plot(Xax, (x,-10,10), (y,-10,10)) p4 = point((-2, 1)) #center of circle

( 2013-07-03 03:40:16 -0600 )edit