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?

 Respuesta aceptada

Matt J
Matt J el 28 de Feb. de 2013
Editada: Matt J el 28 de Feb. de 2013

0 votos

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 comentarios

Frederik
Frederik el 1 de Mzo. de 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.
Matt J
Matt J el 1 de Mzo. de 2013
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 el 1 de Mzo. de 2013
Thanks, it worked out well!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Linear and Nonlinear Regression en Centro de ayuda y File Exchange.

Preguntada:

el 28 de Feb. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by