# gsl_fit

### 1.7

This program demonstrates one possilbe way to fit 2D data to a user-supplied model function, using the Gnu Scientific Library (GSL).
The idea behind this project is to create a general extension to the GSL for fitting. It is my test platform for using the GSL in other programs, and as such, it does many things that may not be useful for other applications.
As long as you can express a function, , to be minimized with respect to a set of parameters , then the GSL can fit data using several methods. The function is usually given by

where are the set of data points and errors in , and for a single point , and paramter set , the user-supplied model function returns a single value .

What makes all this possible is the fact that the GSL passes a void pointer to the required functions for evaluation. This means we can store all the data and paramters in a single container struct in memory and pass around pointer to it. So the `gsl_fit_container`

struct contains three other structs, each of which contain the data, the parameters and the model functions, respectivly.
In this example program, the total model function can be a sum of other functions, i.e.

This becomes useful, for example, when the data is a sum of gaussian peaks. Instead of putting all the peaks into one function call, you can write a single general function that evaluates a single gaussian function and call the function `gsl_fit_add_model_*`

as many times as you need.

It is also possible to either fit a single data set, or several data sets to the same set of parameters and functions. For example, parameter may be positive for one data set and negative for the other, but the magnitude should still be the same. Another example may be the case where the same peak may be shifted between two data sets by a exact, fixed amount, but it's width and amplitude are the same.
In these cases, it becomes necessary that when the program calls the user-supplied function for evaluating , additional paramters are passed which indicate which data set and which peak are being calculated.

To use this feature, as you add data sets, they are numbered as you add them, starting from 0. Likewise, as you add functions, they are numbered as you add them.

The method of fitting can be chosen to be one of the following:

- Non-linear least squares
- Multidimensional minimization
- Simulated annealing

For more information on these, see the GSL documentation. It may be possible to add optional GSL extension minimization routines.

All comments and questions are welcome, see my main page for my email address. Feel free to browse these documentation pages.

Generated on Fri Jan 19 14:54:26 2007 for gsl_fit by
1.4.7