This is the mail archive of the gsl-discuss@sourceware.cygnus.com mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

core



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..."

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]