00001 #include "expfit.h"
00002
00003
00004
00005
00006
00007 int expb_f (const gsl_vector * x, void *data,
00008 gsl_vector * f)
00009 {
00010 size_t n = ((struct dataF *)data)->n;
00011 double *y = ((struct dataF *)data)->y;
00012 double *t = ((struct dataF *)data)->t;
00013 double *sigma = ((struct dataF *) data)->sigma;
00014
00015 double A0 = gsl_vector_get (x, 0);
00016 double A1 = gsl_vector_get (x, 1);
00017 double A2 = gsl_vector_get (x, 2);
00018 double A3 = gsl_vector_get (x, 3);
00019 double A4 = gsl_vector_get (x, 4);
00020 double A5 = gsl_vector_get (x, 5);
00021
00022 size_t i;
00023
00024 for (i = 0; i < n; i++)
00025 {
00026
00027
00028
00029 double z = (t[i]-A1)/A2;
00030 double Yi = A0 * exp (-z*z/2.) + A3 +A4*t[i] + A5*t[i]*t[i];
00031 gsl_vector_set (f, i, (Yi - y[i])/sigma[i]);
00032 }
00033
00034 return GSL_SUCCESS;
00035 }
00036
00037
00038
00039 int expb_df (const gsl_vector * x, void *data,
00040 gsl_matrix * J)
00041 {
00042 size_t n = ((struct dataF *)data)->n;
00043 double *sigma = ((struct dataF *) data)->sigma;
00044 double *t = ((struct dataF *)data)->t;
00045
00046 double A0 = gsl_vector_get (x, 0);
00047 double A1 = gsl_vector_get (x, 1);
00048 double A2 = gsl_vector_get (x, 2);
00049
00050
00051
00052
00053 size_t i;
00054
00055 for (i = 0; i < n; i++)
00056 {
00057
00058
00059
00060
00061
00062
00063 double s = sigma[i];
00064 double z = (t[i]-A1)/A2;
00065 double e = exp(-z*z/2.);
00066 gsl_matrix_set (J, i, 0, e/s);
00067 gsl_matrix_set (J, i, 1, A0/A2 * z * e/s);
00068 gsl_matrix_set (J, i, 2, A0/A2 * z * z * e/s);
00069 gsl_matrix_set (J, i, 3, 1/s);
00070 gsl_matrix_set (J, i, 4, t[i]/s);
00071 gsl_matrix_set (J, i, 5, t[i] * t[i]/s);
00072
00073 }
00074 return GSL_SUCCESS;
00075 }
00076
00077 int expb_fdf (const gsl_vector * x, void *data,
00078 gsl_vector * f, gsl_matrix * J)
00079 {
00080 expb_f (x, data, f);
00081 expb_df (x, data, J);
00082
00083 return GSL_SUCCESS;
00084 }
00085
00086