MATLAB: How to determine the general equation of an ellipse using lsqnonlin

ellipse fittinglsqnonlin

Hello.
Given a set of points (xk,yk) how to determine de general equation of an ellipse: P(x,y) = Ax + Bxy + Cy^2 + Dx + Ey + F = 0
I've tried a few methods (direct least square, Kanatani's hypernormalization, Ellipse fitting with sampson distance). However, this time, I am trying to use de lsqnonlin command. The main difficulty is to guarantee that the coefficients really represent an ellipse, i.e., how do I add the condition: B^2-4*A*C<0 to the lsqnonlin ?
Thank you in advance.

Best Answer

You would probably have to use fmincon, rather than lsqnonlin. It can accommodate more general nonlinear constraints like B^2-4*A*C<=0.