# User supplied functions

## Detailed Description

I have seperated the model functions into this file. These are examples of functions that are to be supplied by the user.

All functions are the same format: , i.e., for a single point , and paramter set , return the value .

The functions used for fitting single datasets are prefixed by an s, and those for fitting multiple datasets are prefixed by and m.

## Functions

double mgaussian_area (double x, double *a, unsigned int dataset, unsigned int function)
Gaussian area.
double mlorentzian_area (double x, double *a, unsigned int dataset, unsigned int function)
Lorentz area.
double mpearson_area (double x, double *a, unsigned int dataset, unsigned int function)
Pearson area.
double mline (double x, double *a, unsigned int dataset, unsigned int function)
Straight line.
double sgaussian_area (double x, double *a)
Gaussian area.
double slorentzian_area (double x, double *a)
Lorentz area.
double spearson_area (double x, double *a)
Pearson area.
double sline (double x, double *a)
Straight line.

## Function Documentation

 double mgaussian_area ( double x, double * a, unsigned int dataset, unsigned int function )

a[0] = area
a[1] = center
a[2] = standard deviation width


Definition at line 8 of file test_functions.c.

00010 {
00011   double tmp1, tmp2;
00012 /*
00013 **  a[0] = area
00014 **  a[1] = center
00015 **  a[2] = std dev width
00016 */
00017   tmp1 = ((x-a[1])/a[2])*((x-a[1])/a[2]);
00018   tmp2 = a[0] * exp(-tmp1/2.0) / (sqrt(2.0*M_PI) * a[2]);
00019
00020   /*
00021   ** In this example, \c d contains the information about how the different
00022   ** datasets are related:
00023   ** For dataset i, multiply the amplitude of peak number j by d[i][j]
00024   */
00025   tmp2 *= d[dataset][function];
00026   return tmp2;
00027 }


 double mlorentzian_area ( double x, double * a, unsigned int dataset, unsigned int function )

a[0] = area
a[1] = center
a[2] = width


Definition at line 28 of file test_functions.c.

00030 {
00031   double tmp1, tmp2;
00032 /*
00033 **  a[0] = area
00034 **  a[1] = center
00035 **  a[2] = std dev width
00036 */
00037   tmp1 = ((x - a[1]) / a[2]);
00038   tmp2 = a[0] / (M_PI * a[2] * (1.0 + (tmp1*tmp1)));
00039
00040   /*
00041   ** In this example, \c d contains the information about how the different
00042   ** datasets are related:
00043   ** For dataset i, multiply the amplitude of peak number j by d[i][j]
00044   */
00045   tmp2 *= d[dataset][function];
00046   return tmp2;
00047 }


 double mpearson_area ( double x, double * a, unsigned int dataset, unsigned int function )

a[0] = area
a[1] = center
a[2] = width
a[3] = shape ~1 lorenztian, >3 gaussian


Definition at line 48 of file test_functions.c.

00050 {
00051   double tmp1, tmp2, tmp3, tmp4;
00052 /*
00053 **  a[0] = area
00054 **  a[1] = center
00055 **  a[2] = std dev width
00056 **  a[3] = shape ~1 lorenztian, >3 gaussian
00057 */
00058   if ((a[3] < 0.0) || (a[3] >= GSL_SF_GAMMA_XMAX))
00059   {
00060     return 0.0;
00061   }
00062
00063   tmp1 = pow(2.0, (1.0/a[3]))-1.0;
00064   tmp2 = a[0] * a[3] * gsl_sf_gamma(a[3]) * sqrt(tmp1/a[3]);
00065   tmp3 = 1.0+(4.0*((x-a[1])/a[2])*((x-a[1])/a[2])*tmp1);
00066   tmp3 = pow(tmp3, a[3]);
00067   tmp4 = a[2] * sqrt(M_PI*a[3]) * gsl_sf_gamma(a[3]-0.5) * tmp3;
00068   tmp1 = tmp2/tmp4;
00069
00070   /*
00071   ** In this example, \c d contains the information about how the different
00072   ** datasets are related:
00073   ** For dataset i, multiply the amplitude of peak number j by d[i][j]
00074   */
00075   tmp1 *= d[dataset][function];
00076   return tmp1;
00077 }


 double mline ( double x, double * a, unsigned int dataset, unsigned int function )

a[0] = slope
a[1] = intercept


Definition at line 78 of file test_functions.c.

00080 {
00081   double tmp;
00082 /*
00083 **  a[0] = slope
00084 **  a[1] = intercept
00085 */
00086   tmp = a[0] * x + a[1];
00087   return tmp;
00088 }


 double sgaussian_area ( double x, double * a )

a[0] = area
a[1] = center
a[2] = standard deviation width


Definition at line 89 of file test_functions.c.

00090 {
00091   double tmp1, tmp2;
00092 /*
00093 **  a[0] = area
00094 **  a[1] = center
00095 **  a[2] = std dev width
00096 */
00097   tmp1 = ((x-a[1])/a[2])*((x-a[1])/a[2]);
00098   tmp2 = a[0] * exp(-tmp1/2.0) / (sqrt(2.0*M_PI) * a[2]);
00099   return tmp2;
00100 }


 double slorentzian_area ( double x, double * a )

a[0] = area
a[1] = center
a[2] = width


Definition at line 101 of file test_functions.c.

00102 {
00103   double tmp1, tmp2;
00104 /*
00105 **  a[0] = area
00106 **  a[1] = center
00107 **  a[2] = std dev width
00108 */
00109   tmp1 = ((x - a[1]) / a[2]);
00110   tmp2 = a[0] / (M_PI * a[2] * (1.0 + (tmp1*tmp1)));
00111   return tmp2;
00112 }


 double spearson_area ( double x, double * a )

a[0] = area
a[1] = center
a[2] = width
a[3] = shape ~1 lorenztian, >3 gaussian


Definition at line 113 of file test_functions.c.

00114 {
00115   double tmp1, tmp2, tmp3, tmp4;
00116 /*
00117 **  a[0] = area
00118 **  a[1] = center
00119 **  a[2] = std dev width
00120 **  a[3] = shape ~1 lorenztian, >3 gaussian
00121 */
00122   if ((a[3] < 0.0) || (a[3] >= GSL_SF_GAMMA_XMAX))
00123   {
00124     return 0.0;
00125   }
00126
00127   tmp1 = pow(2.0, (1.0/a[3]))-1.0;
00128   tmp2 = a[0] * a[3] * gsl_sf_gamma(a[3]) * sqrt(tmp1/a[3]);
00129   tmp3 = 1.0+(4.0*((x-a[1])/a[2])*((x-a[1])/a[2])*tmp1);
00130   tmp3 = pow(tmp3, a[3]);
00131   tmp4 = a[2] * sqrt(M_PI*a[3]) * gsl_sf_gamma(a[3]-0.5) * tmp3;
00132   tmp1 = tmp2/tmp4;
00133   return tmp1;
00134 }


 double sline ( double x, double * a )

a[0] = slope
a[1] = intercept


Definition at line 135 of file test_functions.c.

00136 {
00137   double tmp;
00138 /*
00139 **  a[0] = slope
00140 **  a[1] = intercept
00141 */
00142   tmp = a[0] * x + a[1];
00143   return tmp;
00144 }


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