Optimising 3 variables to produce minimal errors
Show older comments
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
Accepted Answer
More Answers (0)
Categories
Find more on Interpolation of 2-D Selections in 3-D Grids in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!