fitting data to a superellipse
Show older comments
greeting to the MATLAB community,
xdata=
I have two data sets; xdata and ydata and I need to fit a supperellipse to those data with this line of code.
%%%%%%%%%%%%%%%%%%%
a=2;
b=5;
p=2;
xc=3;
yc=1;
t=0:pi/20:2*pi;
xdata=xc+a*cos(t); %example
ydata=yc+b*sin(t); %example
a0 = [10 10 2]; %inintial guess
options = optimset('Display','iter');
c = [xc yc]; %given
%
f = @(aa) (((xdata-c(1)))./aa(1)).^aa(3) + (((ydata-c(2)))./aa(2)).^aa(3) -1; %superellipse Equation
af = lsqnonlin(f, a0, [], [], options);
I used the x&y data of an ellipse with a=2,b=5,xc=3,yc=1
but it returns the following values: af= 9.999999837882097 + 0.000000000000000i 9.999999149008248 + 0.000000000000000i 1.999994717969291 - 0.000007892981223i
which should be colse to 2 5 2
any idea? thanks!

3 Comments
John D'Errico
on 25 Dec 2017
But we don't see your data. There is a very good chance that you have made a very poor choice in how to fit this data, because an ellipse is NOT a function. So best is if you actually attach a .mat file to your question or to a comment. Second best would be to attach a plot of that data.
Saeed
on 25 Dec 2017
Saeed
on 25 Dec 2017
Accepted Answer
More Answers (0)
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!