help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-gsl] converting old least-squares fit code to use gsl instead


From: Jerome BENOIT
Subject: Re: [Help-gsl] converting old least-squares fit code to use gsl instead - fails miserably
Date: Wed, 04 Feb 2009 17:04:21 +0800
User-agent: Mozilla-Thunderbird 2.0.0.19 (X11/20090103)

Hello !

have you try against the example provided in the doc ?

For me, multifit worked against CAS results.

hth,
Jerome

Martin Sperl wrote:
Hi!

I have tried to convert my non-linear least squares sinus-fit code from my university day to use the gsl library (gsl_multifit) instead of Bevingtons curfit code.

Sadly the conversion-code does not to converge to the expected value except for when using a single variable. (Taking the example in the documentation as base and adapting the functions *_f, *_df, *_fdf, as well as the data test data,...)

I have even tried to do just a linear fit (mx+b) usin ggsl_multifit and it does not converge either (see the fit functions below).

Has someone got experience to get me going in the right direction?
Maybe I am missing something obvious...

Thanks,
              Martin

P.s: Here the _f, _df, _fdf functions:
int fit_f(const gsl_vector * x, void *data, gsl_vector * f) {
 double v,phase,tmp,delta;
 int i;
 double sum2=0;
 /* the parameters */
 double p[10];
 for(i=0;i<x->size;i++) {
   p[i]=gsl_vector_get (x, i);
   fprintf(stderr,"fit_f: Parameter%i: %f\n",i,p[i]);    }
 /* now the loop */
 for(i=0;i<50;i++) {
   /* here the function */
   v=p[0]+p[1]*time[i];
   /* and store the delta */
   delta=v-value[i];
   sum2+=delta*delta;
   gsl_vector_set(f,i,v);
 }
 /* and return ok */
 return GSL_SUCCESS;
}

int fit_df (const gsl_vector * x, void *data, gsl_matrix * J) {
 double phase,tmp;
 int i;
 /* the parameters */
 double p[10];
 for(i=0;i<x->size;i++) {
   p[i]=gsl_vector_get (x, i);
 }
 /* now the loop */
 for(i=0;i<50;i++) {
   /* the intercept b */
   gsl_matrix_set (J, i, 0, 1);
   /* the slope m */
   gsl_matrix_set (J, i, 1, p[1]);
 }

 /* and return ok */
 return GSL_SUCCESS;
}

int fit_fdf (const gsl_vector * x, void *data,
        gsl_vector * f, gsl_matrix * J) {
 fit_f (x, data, f);
 fit_df (x, data, J);
 return GSL_SUCCESS;
}



_______________________________________________
Help-gsl mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/help-gsl


--
Jerome BENOIT
jgmbenoit_at_mailsnare_dot_net




reply via email to

[Prev in Thread] Current Thread [Next in Thread]