-6

I have this equation, which define an ellipse.

7.91x^2 + -0.213xy + 5.46y^2 -0.031x -0.0896y = 1

Of the general form: Ax^2 + Bxy + Cy^2 + Dx +Ey = 1

I am using python 2.7 -- pythonxy

Of course, I tried by trying to solve an array of points x and y but it doesn’t work. I used the approach from this question in the following code, but it does not show the desired ellipse.

import numpy as np
import matplotlib.pyplot as plt

z = -np.linspace(-0.5,+0.5,1000)
x = np.linspace(-0.5,+0.5,1000)


x,z = np.meshgrid(x,z)

Z = -1 + 5.46*z**2
X = 7.91*x**2


plt.contour(x,z,(X+Z),[0])
plt.xlim([-0.6,0.6])
plt.ylim([-0.6,+0.6)
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
Agape Gal'lo
  • 687
  • 4
  • 9
  • 23
  • 1
    `Can you give a script to simply plot it ?` No – gonczor Dec 19 '17 at 11:25
  • Of course, I tried by trying to solve an array of points x and y but it doesn’t work. I am quite surprised by this bad reactions... I think that it's often more comfortable for people to directly see the good answer. Putting, on purpose, a "not working code" seems a non sense to me; may be I am wrong... If you want so, delate this post. And by the way it's not a duplicate. – Agape Gal'lo Dec 19 '17 at 11:38
  • By showing the code you change this question from "please tell me how to draw an ellipse" which has been answered already, into "I'm trying to plot an ellipse in the following manner, but it fails, please help me find the problem with my approach". This latter question is answerable. – ImportanceOfBeingErnest Dec 19 '17 at 12:06
  • Once you understood the answer, you may still simply delete this question because it is unclear which exact problem you were facing, appart from getting it all wrong. Since the basic question of how to draw an ellipse has also already been asked, there is little use for keeping this question alive at all. – ImportanceOfBeingErnest Dec 19 '17 at 12:26
  • I understand your point but your answer solve it in a different way than in the other post... If I get too much bad votes I will delete but I think it's helpful. – Agape Gal'lo Dec 19 '17 at 12:54
  • No, it's exactly the same way as shown in the other question. – ImportanceOfBeingErnest Dec 19 '17 at 12:57

1 Answers1

1

The code you show does not represent the equation of the ellipse. It's a bit hard to tell what exactly you were trying in that code, but the approach here is of course completely the same as in the linked question's answer, namely to calculate the left hand side of the equation with a meshgrid and show the level of the right hand side as a contour line.

import numpy as np
import matplotlib.pyplot as plt

x = -np.linspace(-0.5,+0.5,1000)
y = np.linspace(-0.5,+0.5,1000)


X,Y = np.meshgrid(x,y)

#equation: 7.91x^2 + -0.213xy + 5.46y^2 -0.031x -0.0896y = 1
eqn = 7.91* X**2 -0.213*X*Y + 5.46*Y**2 -0.031*X - 0.0896*Y
Z = 1

plt.contour(X,Y,eqn,[Z])
plt.xlim([-0.6,0.6])
plt.ylim([-0.6,+0.6])
plt.show()

enter image description here

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
  • As I said, this question is not really worth keeping, because it adds nothing to the already existing question, apart from correcting some math in the code. It is hence not useful for anyone else but you. By accepting and upvoting this answer (which I gave only for you to see where your error is), you now cannot delete it any more. – ImportanceOfBeingErnest Dec 19 '17 at 12:55