how to approximate set of point to a given function

10 visualizaciones (últimos 30 días)
Robert Jones
Robert Jones el 14 de Dic. de 2022
Comentada: Jan el 14 de Dic. de 2022
Hello,
I am have a set of points (about 100 points) that are supposed to represent a rotated ellipse, given by this formula:
(a^2*sin(tr)^2+b^2*cos(tr)^2)*(x-x0)^2+2*(b^2-a^2)*sin(tr)*cos(tr)*(x-x0)*(y-y0)+(a^2+cos(tr)^2+b^2*sin(tr))*(y-y0)^2=a^2*b^2;
where x0,y0 are the coordinates of the center of the ellipse, a and b are the semi axes of the ellipse and tr is the rotation angle.
How would I go about finding the a,b,x0,y0 and tr so the points would be close as possible to the analytical formula.
I tried to use a multi variable minimization routine that minmize the fifference between the data points and the curve, but it seems to complicated and somewhat prone to errors.
I was wondering if there were a simple way to do that in MATLAB.
Thank you
  3 comentarios
Robert Jones
Robert Jones el 14 de Dic. de 2022
what I was thinking to do is set an optimization scheme in which I assume the variables are [a b xo, y0 tr] and the Goal function something like
Goal=0
For i=1:100
Goal=sqrt(sum(YDi-YF)i^2)+Goal
end
where YD is the Y coordinate from the data point set and YF is the Y-coordinate from the formula
The optimization algorithms I used (GA and Newton) did not converge
Jan
Jan el 14 de Dic. de 2022
"The optimization algorithms I used (GA and Newton) did not converge" - Then I assume, they contain a programming error or your initial estimation was too far apart. If you post your code, the readers can check this.

Iniciar sesión para comentar.

Respuestas (2)

Bora Eryilmaz
Bora Eryilmaz el 14 de Dic. de 2022
Editada: Bora Eryilmaz el 14 de Dic. de 2022
This is an optimization problem that can be solved using fminsearch and a least-squares cost function.
% "Unknown" model parameters
r = 3.5;
x0 = 2.8;
y0 = -1.6;
% Set of data points.
th = 0:0.05:2*pi;
x = r * cos(th) + x0;
y = r * sin(th) + y0;
plot(x, y, 'b', x0, y0, 'r+')
grid
axis equal
% Estimate model parameteres [r, x0, y0]
params0 = [0, 0, 0]; % Initial estimates.
params = fminsearch(@(p) costFcn(p,x,y), params0) % Passes data x and y to the function.
params = 1×3
3.5000 2.8000 -1.6000
function cost = costFcn(params, x, y)
% Grid of points. Should generate xh and yh below of the same size as x and y data.
th = 0:0.05:2*pi;
r = params(1);
x0 = params(2);
y0 = params(3);
xh = r * cos(th) + x0;
yh = r * sin(th) + y0;
cost = sum((xh-x).^2 + (yh-y).^2); % Least-squares cost
end

Jan
Jan el 14 de Dic. de 2022
  2 comentarios
Robert Jones
Robert Jones el 14 de Dic. de 2022
Thanks but Matalb fit ellipse just givres a polynomial approximation.
The goal here is not just getting the points but the ellipse properties
Jan
Jan el 14 de Dic. de 2022
"Thanks but Matalb fit ellipse just givres a polynomial approximation." - I've posted links to 6 different approaches (the last one contains 2 methods, a linear and a non-linear fit).
"The goal here is not just getting the points but the ellipse properties" - The shown methods determine the parameters of a ellipse, which fits a given set of points.

Iniciar sesión para comentar.

Categorías

Más información sobre Least Squares en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by