The LMFIT function does a non-linear least squares fit to a function with an arbitrary number of parameters. LMFIT uses the Levenberg-Marquardt algorithm, which combines the steepest descent and inverse-Hessian function fitting methods. The function may be any non-linear function.
Iterations are performed until three consecutive iterations fail to change the chi square value by more than the specified tolerance amount, or until a maximum number of iterations have been performed. The LMFIT function returns a vector of calculated parameters, which are improvements upon the initial guesses.
The initial guess of the parameter values should be as close to the actual values as possible or the solution may not converge. Test the value of the variable specified by the CONVERGENCE keyword to determine whether the algorithm converged, failed to converge, or encountered a singular matrix.
This routine is written in the IDL language. Its source code can be found in the file
subdirectory of the IDL distribution. LMFIT is based on the routine
described in section 15.5 of
Numerical Recipes in C: The Art of Scientific Computing
(Second Edition), published by Cambridge University Press, and is used by permission.
Set this keyword equal to a vector, with as many elements as A , which contains a zero for each fixed parameter, and a non-zero value for elements of A to fit. If FITA is not specified, all parameters are taken to be non-fixed.
Use this keyword to specify the name of the function to fit. If this keyword is omitted, LMFIT assumes that the IDL procedure
is to be used. If
is not already compiled, IDL compiles the function from the file
, located in the
subdirectory of the IDL distribution.
is designed to fit a quadratic equation.
The function to be fit must be written as an IDL procedure and compiled prior to calling LMFIT. The function must accept a vector X (the independent variables) and a vector A containing the fitted function's parameter values. It must return an A +1-element vector in which the first (zeroth) element is the evaluated function value and the remaining elements are the partial derivatives with respect to each parameter in A .
Set this keyword equal to a vector of fitting weights for Y i . This vector must be the same length as X and Y. For instrumental (Gaussian) weighting (when the measurement errors or standard deviations (s) of Y are known), set WEIGHTS to 1/(s 2 ). For statistical (Poisson) weighting, set WEIGHTS=1/Y. If WEIGHTS is not specified, WEIGHTS i is assumed to be 1.0.