how to approximate set of point to a given function

조회 수: 7 (최근 30일)
Robert Jones
Robert Jones 2022년 12월 14일
댓글: Jan 2022년 12월 14일
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
Robert Jones
Robert Jones 2022년 12월 14일
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 2022년 12월 14일
"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.

댓글을 달려면 로그인하십시오.

답변 (2개)

Bora Eryilmaz
Bora Eryilmaz 2022년 12월 14일
편집: Bora Eryilmaz 2022년 12월 14일
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 2022년 12월 14일
  댓글 수: 2
Robert Jones
Robert Jones 2022년 12월 14일
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 2022년 12월 14일
"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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Least Squares에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by