0

I am attempting to fit a circle to some data. This requires numerically solving a set of three non-linear simultaneous equations (see the Full Least Squares Method of this document).

To me it seems that the NEWTON function provided by IDL is fit for solving this problem. NEWTON requires the name of a function that will compute the values of the equation system for particular values of the independent variables:

FUNCTION newtfunction,X
    RETURN, [Some function of X, Some other function of X]
END

While this works fine, it requires that all parameters of the equation system (in this case the set of data points) is hard coded in the newtfunction. This is fine if there is only one data set to solve for, however I have many thousands of data sets, and defining a new function for each by hand is not an option.

Is there a way around this? Is it possible to define functions programmatically in IDL, or even just pass in the data set in some other manner?

diestl
  • 2,020
  • 4
  • 23
  • 37
  • Typically in these cases you define a model function that takes a set of parameters and actual data points. For instance, assume your function is Y = A*X + B. Then the model function (in your case, newtfunction) will take an array of X values and then an array of parameter values, say, param = [A, B]. You then provide the fitting routine with the function name and initial guesses and then let it go. – honeste_vivere Oct 26 '14 at 18:54
  • You may want to take a look at Craig Markwardt's [webpage](http://www.physics.wisc.edu/~craigm/idl/) which has several routines that are better than the Newton method (e.g., Levenberg–Marquardt algorithm). – honeste_vivere Oct 26 '14 at 18:56
  • Neither of these comments really address my question. The newtfunction by definition is only allowed to take a single parameter. If have since found a different way to fit a circle to data, however that is the topic of a different question/answer. – diestl Oct 27 '14 at 15:42

2 Answers2

0

I am not an expert on this matter, but if I were to solve this problem I would do the following. Instead of solving a system of 3 non-linear equations to find the three unknowns (i.e. xc, yc and r), I would use an optimization routine to converge to a solution by starting with an initial guess. For this steepest descent, conjugate gradient, or any other multivariate optimization method can be used.

I just quickly derived the least square equation for your problem as (please check before use):

F = (sum_{i=1}^{N} (xc^2 - 2 xi xc + xi^2 + yc^2 - 2 yi yc + yi^2 - r^2)^2)

Calculating the gradient for this function is fairly easy, since it is just a summation, and therefore writing a steepest descent code would be trivial, to calculate xc, yc and r.

I hope it helps.

Sourabh Bhat
  • 1,793
  • 16
  • 21
0

It's usual to use a COMMON block in these types of functions to pass in other parameters, cached values, etc. that are not part of the calling signature of the numeric routine.

mgalloy
  • 2,356
  • 1
  • 12
  • 10