scidavis  2.3.0
About: SciDAVis is a free application for Scientific Data Analysis and Visualization (a fork off of QtiPlot).
  Fossies Dox: scidavis-2.3.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

exp_saturation.c
Go to the documentation of this file.
1 
10 
33 #include <gsl/gsl_vector.h>
34 #include <gsl/gsl_matrix.h>
35 #include <math.h>
36 
37 struct data {
38  size_t n;
39  size_t p;
40  double * X;
41  double * Y;
42  double * sigma;
43 };
44 
45 char * name() { return "ExponentialSaturation"; }
46 
47 char * function() { return "b1*(1-exp(-b2*x))"; }
48 
49 char * parameters() { return "b1,b2"; }
50 
51 double function_eval(double x, double * params)
52 {
53  return params[0]*(1-exp(-params[1]*x));
54 }
55 
56 int function_f(const gsl_vector * params, void * void_data, gsl_vector * f)
57 {
58  struct data * d = (struct data*) void_data;
59  double b1 = gsl_vector_get(params, 0);
60  double b2 = gsl_vector_get(params, 1);
61  size_t i;
62  for (i=0; i<d->n; i++)
63  gsl_vector_set(f, i, (b1*(1-exp(-b2*d->X[i])) - d->Y[i])/d->sigma[i]);
64  return GSL_SUCCESS;
65 }
66 
67 int function_df(const gsl_vector * params, void * void_data, gsl_matrix *J)
68 {
69  struct data * d = (struct data*) void_data;
70  double b1 = gsl_vector_get(params, 0);
71  double b2 = gsl_vector_get(params, 1);
72  size_t i;
73  for (i=0; i<d->n; i++) {
74  double x = d->X[i];
75  gsl_matrix_set(J, i, 0, (1-exp(-b2*x)));
76  gsl_matrix_set(J, i, 1, b1*x*exp(-b2*x));
77  }
78  return GSL_SUCCESS;
79 }
80 
81 int function_fdf(const gsl_vector * params, void * void_data, gsl_vector * f, gsl_matrix * J)
82 {
83  function_f(params, void_data, f);
84  function_df(params, void_data, J);
85  return GSL_SUCCESS;
86 }
87 
88 double function_d(const gsl_vector * params, void * void_data)
89 {
90  struct data * d = (struct data*) void_data;
91  gsl_vector * f = gsl_vector_alloc(d->n);
92  double result = 0;
93  size_t i;
94 
95  function_f(params, void_data, f);
96  for (i=0; i<d->n; i++)
97  result += pow(gsl_vector_get(f, i), 2);
98 
99  gsl_vector_free(f);
100  return result;
101 }
102 
function_f
int function_f(const gsl_vector *params, void *void_data, gsl_vector *f)
Definition: exp_saturation.c:56
data
Definition: exp_saturation.c:37
function_eval
double function_eval(double x, double *params)
Definition: exp_saturation.c:51
function_d
double function_d(const gsl_vector *params, void *void_data)
Definition: exp_saturation.c:88
parameters
char * parameters()
Definition: exp_saturation.c:49
function_fdf
int function_fdf(const gsl_vector *params, void *void_data, gsl_vector *f, gsl_matrix *J)
Definition: exp_saturation.c:81
name
char * name()
Definition: exp_saturation.c:45
data::X
double * X
Definition: exp_saturation.c:40
data::p
size_t p
Definition: exp_saturation.c:39
data::sigma
double * sigma
Definition: exp_saturation.c:42
data::Y
double * Y
Definition: exp_saturation.c:41
data::n
size_t n
Definition: exp_saturation.c:38
function_df
int function_df(const gsl_vector *params, void *void_data, gsl_matrix *J)
Definition: exp_saturation.c:67