Frage

I would like to fit the curve bellow with a circle in a certain range with matlab. I want to fit this curve from x=0,1 to x=0,5 and to get the radius of the circle.

Do you have any ideas how to do that with matlab? enter image description here

Thanks in advance

War es hilfreich?

Lösung

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.

Andere Tipps

Besides using the equation for a circle, one could do it manually by calculating the mean center of all points in the (x,y) plane, and then calculating the mean distance between this center and all points.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top