"M Srj" wrote in message <jn52gu$9vo$
1...@newscl01ah.mathworks.com>...
- - - - - - - - -
(I was afraid you would ask me that!) The equation
A*x^2 + B*x*y + C*y^2 + D*x + E*y + F = 0
is itself an implicit form of the fitted curve which you are seeking. The most direct way to generate the curve for plotting purposes is to solve either x or y in terms of the other. This will in general lead to solving a quadratic equation which will have either two solutions, no solutions, or at special points one solution.
As an example, let's suppose you decide to solve for y in terms of x in the equation
5*x^2-6*x*y+2*y^2-x+5*y+3=0
Rewrite it as:
2*y^2 + (-6*x+5)*y + (5*x^2-x+3) = 0
By the well-known quadratic equation formula the two solutions would then be:
y1 = (6*x-5+sqrt((6*x-5)^2-4*2*(5*x^2-x+3)))/4 and
y2 = (6*x-5-sqrt((6*x-5)^2-4*2*(5*x^2-x+3)))/4
The quantity inside the square root can be expressed as:
(6*x-5)^2-4*2*(5*x^2-x+3)) = -4*x^2-62^x=1 = -4*(x+13/2)^2+170
which means that
(x+13/2)^2 <= 170/4
-1/2*sqrt(170)-13/2 <= x <= 1/2*sqrt(170)-13/2
In other words what we have here is an ellipse and x must range between
these two numbers. We need to plot both y1 and y2 between these two limits to get the entire ellipse. (Use X for this x to distinguish it from the original data x.)
X = linspace(-1/2*sqrt(170)-13/2+1e-14,1/2*sqrt(170)-13/2-1e-14,500);
y1 = (6*X-5+sqrt((6*X-5).^2-4*2*(5*X.^2-X+3)))/4;
y2 = (6*X-5-sqrt((6*X-5).^2-4*2*(5*X.^2-X+3)))/4;
plot(X,y1,'y-',X,y2,'y-',x,y,'ro') % Plot the ellipse and the data points
axis equal
There are other ways of generating conic section curves which don't require two distinct parts as above but rather use a parameter. I would prefer not going into that now, however.
Roger Stafford