This is the mail archive of the
gsl-discuss@sourceware.cygnus.com
mailing list for the GSL project.
Re: core
- To: Rodolphe.Pollet@lct.jussieu.fr (Rodolphe Pollet)
- Subject: Re: core
- From: Brian Gough <bjg@network-theory.co.uk>
- Date: Sat, 26 Jun 1999 20:12:37 +0100 (BST)
- Cc: gsl-discuss@sourceware.cygnus.com
- References: <199906251616.SAA28223@liliput.lct.jussieu.fr>
Hi,
The definition of gsl_function was changed to allow additional
parameters (such as a) to be passed to the function without the use of
static variables. See the latest doc/roots.texi file in CVS for an
example of how to use gsl_function. Also, the line x = NULL is a
problem, since x must point to allocated memory. Try *x = 0 instead.
regards
Brian Gough
Rodolphe Pollet writes:
>
> This is a simple code to test the Brent-Dekker method :
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <gsl_roots.h>
>
> static double a;
> double fun (const double);
>
> double fun (const double x) {
> return pow(x,5./2)-pow(x-2*a,5./2)-5*a/(2*sqrt(2.));
> }
>
> int main (void) {
> double *x;
> double *x0;
> double *x1;
> double rel_eps, abs_eps;
> unsigned int max_iter;
> int find;
> x0 = (double *) malloc (sizeof(double));
> x1 = (double *) malloc (sizeof(double));
> x = (double *) malloc (sizeof(double));
> *x0 = 0.3;
> *x1 = 1;
> x = NULL;
> rel_eps = 0.01;
> abs_eps = 0.001;
> max_iter = 50;
> a = 0.108;
> printf ("f(x0) = %f\n", fun(*x0));
> printf ("f(x1) = %f\n", fun(*x1));
> find = gsl_root_brent(x, fun, x0, x1, rel_eps, abs_eps, max_iter);
> if (find) printf ("Error : return = %d\n", find);
> printf ("x = %f\n", *x);
> exit (0);
> }
>
> gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release) yields
> gcc -ansi -pedantic -Werror -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wtraditional -Wconversion -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Waggregate-return -fshort-enums -fno-common -Wnested-externs -Dinline= -g -04 -c essai.c -o essai.ogcc: unrecognized option `-04'cc1: warnings being treated as errors
> essai.c: In function `main':
> essai.c:31: warning: passing arg 2 of `gsl_root_brent' from incompatible pointer typemake: *** [essai.o] Error 1
>
> If i ignore the warning, at execution occurs a Memory fault (core dumped).
> In the documentation i found
> int gsl_root_brent (double *root, double (* f)(double),
> double *lower_bound, double *upper_bound,
> double rel_epsilon, double abs_epsilon,
> unsigned int max_iterations);
>
> but in the .h the prototype of the function is
> int gsl_root_brent (double *root, const gsl_function * f,
> double *lower_bound, double *upper_bound,
> double rel_epsilon, double abs_epsilon,
> unsigned int max_iterations);
> struct gsl_function_struct
> {
> double (* function) (double x, void * params);
> void * params;
> };
> typedef struct gsl_function_struct gsl_function ;
>
> Can somebody help me to find the mistake ?
> --
> Rodolphe POLLET
> Laboratoire de Chimie Theorique, Case 137, | pollet@lct.jussieu.fr
> Universite Pierre et Marie Curie, T 22-23, | tel: 01.44.27.42.11
> 4, Place Jussieu, 75252 PARIS CEDEX 05, FRANCE| Fax : 44.27.41.17
>
> __ _
> / / (_)__ __ ____ __
> / /__/ / _ \/ // /\ \/ / . . . t h e c h o i c e o f a
> /____/_/_//_/\_,_/ /_/\_\ G N U g e n e r a t i o n . . .
>
> "Ce n'est pas parcequ'ils sont nombreux avoir tort qu'ils ont
> raison..."
>
> "Computers are like air conditioners - they stop working properly when
> you open Windows..."
- References:
- core
- From: Rodolphe.Pollet@lct.jussieu.fr (Rodolphe Pollet)
- core
- From: Rodolphe.Pollet@lct.jussieu.fr (Rodolphe Pollet)