Fitting data to a limaçon curve

I have data in the form of two column vectors x and y containing the x and y coordinates of measurements. The data forms a limaçon curve that can be described by the equation (x^2+y^2-a*x)^2 = b^2*(x^2+y^2). How can I fit a curve of that type to my data yielding a and b as results?

 Akzeptierte Antwort

Matt J
Matt J am 28 Feb. 2013
Bearbeitet: Matt J am 28 Feb. 2013

0 Stimmen

Here's a poor man's method, assuming you don't have the Optimization or Curve Fit Toolboxes
z=x.^2+y.^2;
%Cheesy initial guess of p=[a,sqrt(b)]
p= [x, sqrt(z)]\z;
p(2)=max(p(2),0); %b must be positive
%Re-optimize
p0=p;
p=fminsearch(@(p) norm( (z-p(1).*x).^2 - z.*p(2).^2 ), p0 );
a=p(1);
b=p(2)^2;

3 Kommentare

Frederik
Frederik am 1 Mär. 2013
I do have the Optimization and Curve Fitting Toolboxes, though, but I had trouble defining fittypes for use with fit(). I also just realized there is a typo in the equation for the limaçon, it should be b^2 on the right hand side.
Then you could use lsqnonlin, for example.Or, here's a modification of my code
z=x.^2+y.^2;
fun=@(p) norm( (z-p(1).*x).^2 - z.*p(2).^2 );
%Cheesy initial guess of p=[a,b]
p1 = [x, sqrt(z)]\z;
p2 = [-x, sqrt(z)]\(-z);
f1=fun(p1);
f2=fun(p2);
p0=p1*(f1<=f2) + p2*(f2<f1);
%Re-optimize
p=fminsearch(fun, p0 );
a=p(1);
b=p(2);
Frederik
Frederik am 1 Mär. 2013
Thanks, it worked out well!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by