I consider this as a least square minimization problem. You minimize the norm of the vector function, [f1,f2,...fn]
with respect to x0
, y0
, and r
, where fi(x0,y0,r) = (xi-x0)^2 + (yi-y0)^2 - r^2
. Here, xi
and yi
represent your data, and i=1..n
.
Then first you create a vector function
function [ f ] = circle_fun( x0, y0, r, xdata, ydata, n )
f = zeros(n,1);
for i=1:n
f(i) = abs((x0-xdata(i))^2 + (y0-ydata(i))^2 - r^2);
end
end
And use least square minimization function of MATLAB
f = @(inputs) circle_fun(inputs(1),inputs(2),inputs(3), xdata, ydata, n);
v0 = [0.1, 0.1, 0.1];
[v_opt,resnorm] = lsqnonlin(f,v0);
v0
is an initial guess and v_opt
is a solution vector that has x0
, y0
, and r
inside.