help-gsl
[Top][All Lists]
Advanced

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

[Help-gsl] Suggestion about root finding algorithms


From: Vicent
Subject: [Help-gsl] Suggestion about root finding algorithms
Date: Fri, 15 Jan 2010 14:39:32 +0100

Hello.

I've been using routines for root finding. I am very satisfied with the
results, but I miss one more function that I am trying to explain:

We have the function   gsl_root_fsolver_root   (and its couple for the case
with derivatives) that, for a given instance of a solver (a solver involves
also a problem to be solved / a root to be found), returns the current
estimate of the root. OK.

But the solver object also contains in its structure the value of  f  for
that root estimate (f  being the function we want to find the root for).

I would like to request a function that allows to get also the value of
 f(root)  that it is already contained in the "state" element of the
"solver" element, AT LEAST IN THE CASE OF SOME SOLVERS.

For example, for the case of BRENT'S ALGORITHM, I've managed to recover
 f(root)  without actually having to call the function  f  again.

I put here a piece of my listing, so that I can better explain what I'm
talking about:



*// We have to define this, because (I think that) it is not included*
*// in any GSL header (it does appear at  brent.c  file):*
*
*
*typedef struct {*
*    double a , b , c , d , e ;*
*    double fa , fb , fc ;*
*} brent_state_t ;*
*
*
*[...]*
*
*
*
*
*    // Some code at my solver routine:*
*
*
*    const gsl_root_fsolver_type *T = gsl_root_fsolver_brent ;*
*    gsl_root_fsolver *s = gsl_root_fsolver_alloc(T) ;*
*
*
*    gsl_function F ;*
*
*
*    struct parametros_1 par = { WHATEVER I NEED AS A PARAMETER } ;*
*
*
*    // The struct  parametros_1  has been properly previously defined*
*
*
*    F.function = &fff ;*
*
*
*    // The function  fff  is the one I want to find the root for,*
*    // and has been properly defined (I mean, has the proper structure*
*    // for being assigned as a part of the variable  F).*
*
*
*    F.params = &par ;*
*
*
*
*
*    // I initialize the solver with the function  gsl_root_fsolver_set  and
so on*
*
*
*    [...]*
*
*
*        // NOW I am in a loop, performing iterations of the solver.*
*
*
*        status = gsl_root_fsolver_iterate(s) ;*
*
*
*        // After the iteration, I can get the current estimate for the
root:*
* *
*        my_root = gsl_root_fsolver_root(s) ;*
*
*
*        // ***** NOW, HERE IT COMES MY PROPOSAL ******
*
*
*        // If I want to get the value for  fff(my_root)*
*        // [ actually, fff(my_root, &par) ]*
*        // BUT don't want to call to  fff,  I really don't need to.*
*        // See:*
*
*
*        brent_state_t *estado = (brent_state_t *)s->state ;*
*        *
*        // After each interation, Brent's algorithm returns as a candidate
value for *
*        // the root the field called "b" in the field "state" of the solver
object*
*        // (see line 216 of  brent.c  file). So, the value I am looking for
is "fb".*
*
*
*        fff_my_root = estado->fb ;*
*
*
*        *
*        [...]*


So, what I mean is that it could be interesting adding a field called
"froot", for example, in the struct  gsl_root_fsolver  (that is, the struct
of a solver "s"), and it would be useful for storing the value of  f(root)
 for the current  "root"  (which is already a field in that struct). In that
way, my code above wouldn't be necessary.

What do you thing? I hope I've managed to explain what I wanted to say.

I look forward to your answers.


--
Vicent Giner


reply via email to

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