Next: , Previous: Initializing the Nonlinear Least-Squares Solver, Up: Nonlinear Least-Squares Fitting


37.3 Providing the Function to be Minimized

You must provide n functions of p variables for the minimization algorithms to operate on. In order to allow for arbitrary parameters the functions are defined by the following data types:

— Data Type: gsl_multifit_function

This data type defines a general system of functions with arbitrary parameters.

int (* f) (const gsl_vector * x, void * params, gsl_vector * f)
this function should store the vector result f(x,params) in f for argument x and arbitrary parameters params, returning an appropriate error code if the function cannot be computed.
size_t n
the number of functions, i.e. the number of components of the vector f.
size_t p
the number of independent variables, i.e. the number of components of the vector x.
void * params
a pointer to the arbitrary parameters of the function.

— Data Type: gsl_multifit_function_fdf

This data type defines a general system of functions with arbitrary parameters and the corresponding Jacobian matrix of derivatives,

int (* f) (const gsl_vector * x, void * params, gsl_vector * f)
this function should store the vector result f(x,params) in f for argument x and arbitrary parameters params, returning an appropriate error code if the function cannot be computed.
int (* df) (const gsl_vector * x, void * params, gsl_matrix * J)
this function should store the n-by-p matrix result J_ij = d f_i(x,params) / d x_j in J for argument x and arbitrary parameters params, returning an appropriate error code if the function cannot be computed.
int (* fdf) (const gsl_vector * x, void * params, gsl_vector * f, gsl_matrix * J)
This function should set the values of the f and J as above, for arguments x and arbitrary parameters params. This function provides an optimization of the separate functions for f(x) and J(x)—it is always faster to compute the function and its derivative at the same time.
size_t n
the number of functions, i.e. the number of components of the vector f.
size_t p
the number of independent variables, i.e. the number of components of the vector x.
void * params
a pointer to the arbitrary parameters of the function.

Note that when fitting a non-linear model against experimental data, the data is passed to the functions above using the params argument and the trial best-fit parameters through the x argument.