Start by estimating an approximate solution. The circle centre is just the mean value of X and Y and the radius the mean distance of points from the centre. Have two functions that compute the first and second derivatives of RMS wrt. to X,Y,R. These functions compute numerical derivatives using get_rms Use these to estimate a better a solution and iterate. Again, a bit of theory may help:-
is a function of the parameters . At minimum:-
In simple cases, the problem can be solved analytically. For example the fitting of a set of points (xi,yi) to the curve:-
Then
and
So
These are just a set of linear simultaneous equations in which can be solved exactly.
Sometimes the problem is not so simple; either can only be calculated numerically or it is not linear in . In such cases an iterative numerical approach can be used. The first step is to find some approximate solution and then to determine the first and second derivatives of (numerically if necessary) at that point to find a better solution.Suppose is an approximate solution, we seek a better solution
and assume that it is not too far away, so that we can write
If is the minimum, then
so
i.e.
Hence can be evaluated to find . The process can be repeated to further improve the solution until convergence is reached.