help-gsl
[Top][All Lists]
Advanced

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

Re: [Help-gsl] Nonlinea fitting with exit info = 27


From: Patrick Alken
Subject: Re: [Help-gsl] Nonlinea fitting with exit info = 27
Date: Tue, 17 Oct 2017 09:09:19 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0

Hello, there are some tips in the Troubleshooting section of the
Nonlinear least squares manual:

http://www.gnu.org/software/gsl/doc/html/nls.html#troubleshooting

In particular, your problem appears to be an error in your Jacobian
matrix. I've attached a modified version of your program where I
switched to the finite difference Jacobian calculation. I also lowered
the solution tolerance to get a more accurate solution. You'll see that
the numerical solution now agrees with your model to about 1e-7,
although the computed parameters are not exactly what you started with.
This could likely be improved further when you find the error in your
Jacobian function (which I have not done).

Here are the differences with your original program:

> diff main.c main.c.orig
> 188,189c188,189
> <   const double xtol = 1.0e-6;
> <   const double gtol = 1.0e-6;
> ---
> >   const double xtol = 1.0e-2;
> >   const double gtol = 1.0e-2;
> 276d275
> < #if 0
> 279,282d277
> < #else
> <   fdf.df = NULL;
> <   fdf.fvv = NULL;
> < #endif
> 295c290
> <   fdf_params.trs = gsl_multifit_nlinear_trs_dogleg;
> ---
> >   fdf_params.trs = gsl_multifit_nlinear_trs_lmaccel;

Note I also switched to the dogleg algorithm - in order to use lmaccel
you need an accurate Jacobian routine and fvv routine.

On 10/16/2017 07:56 PM, Jiawei Zhao Zhao wrote:
> Dear GSL mailing list.
>
>
> I am new to GSL and trying to fit a Non linear function. the function is 
> given below.
>
>
> y = A*( ( b / (x-r0) ) ^ m- B* ( b / (x-r0) ) ^ n)
>
>
> I modified an example of non linear fitting (code attached). The function 
> successfully complied  and first deviation gives correct value.
>
>
> However, when I test with generating data from:
>
>
> A=1, b= 2.5, m=12, n=6, r0=0 and B=1
>
>
> and try to fit it start from
>
>
> A=1, b= 2.4, m=12, n=6, r0=0 and B=1
>
>
> The iteration seems stopped at the first steps with info = 27.
>
>
> Can anyone help me on this?
>
>
> Regards.
>
>
> Jiawei Zhao
>
>

Attachment: main.c
Description: Text Data


reply via email to

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