Optimising 3 variables to produce minimal errors

Hi,
I have 10 circles (with center x,y and radii coordinates) that I need to generate a new optimal ideal circle from, that minimizes its distance from each of the original 10 circles. The new circle has ideal or optimized center and radius coordinates of ix, iy and ir. The algorithm involves adding up all the error differences this new circle has from the 10 non-optimal ones and optimizing ir, ix, and iy to minimize this error. See code below for my function:
*function F = minfunc(I,Xc,Yc)
dsum=0;
for i = 1:10
dsum = dsum + (I(1) - sqrt((Xc(i) - I(2))^2 + (Yc(i) - I(3))^2))^2;
end
F = I;
end*
where I(1) is the optimal radius, I(2) & I(3) are the optimal X and Y coordinates for the new circle. Please see attached picture of what I'm tryin to do.
I have my main MATLAB code as shown below:
*x0 = [0.5 1 3]; // Initial guestimate
fun = @(I) minfunc(I, Xc, Yc);
I_min = fminsearch(fun,x0);
ir = I_min(1);
ix = I_min(2);
iy = I_min(3);
*
Xc is an array with 10 x-center coords for the 10 non-optimal circles (values ranging from 0.8 to 1.1). Yc is an array with 10 y-center coords for the 10 non-optimal circles (values ranging from 3.0 to 3.3).
When I run the code, I get the following errors:
*Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Error in fminsearch (line 200)
fv(:,1) = funfcn(x,varargin{:});*
I've been stumped for hours on how to resolve this problem and get the correct answers for ir, ix, and iy. I even tried using fsolve but got another bunch of errors, so I abandoned it.
Any help would be greatly appreciated.
Thanks, David

 채택된 답변

Star Strider
Star Strider 2017년 12월 4일

0 개 추천

I would change ‘minfunc’ to define:
F = dsum;
You might find that more applicable to your problem if you want to minimise the distances.

댓글 수: 2

OMG...that did it! Thank you, Star!
As always, my pleasure!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

질문:

2017년 12월 4일

댓글:

2017년 12월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by