There are several problems here, as I expected.
1. An ellipse is not a function. So a sum of squares of residuals does not work well here. Best is to convert to polar coordinates.
2. Are you trying to estimate the center of the ellipse? You have fixed xc and yc, but in any fit to data, you would generally not know the exact center.
3. Most importantly, look carefully at what you are doing. Depending on which side of the center a point lies, the expression (x-xc) may be positive of negative. Then you try to raise the to a non-integer power. For example, what does this evaluate to in MATLAB? TRY IT!
(-1)^2.3
ans =
0.58779 + 0.80902i
It returns a complex result. Any negative number will do that, when raised to a non-integer power.
So again, it is best to convert to polar coordinates. Express your ellipse as a function of angle and distance from the polar origin. Then everything will be positive, and no complex numbers will be generated. I'll look back in again if you need help with that, but I'll get you started.
Assume that the center is not known.
xc0 = mean(x);
yc0 = mean(y);
r = sqrt((x - xc0)^2 + (y - yc0)^2);
th = atan2(y - yc0,x - xc0);
Now, you need to re-write your model in polar coordinates, thus r(th), given parameters for the ellipse.
Best Answer