This is the mail archive of the gsl-discuss@sources.redhat.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]
Other format: [Raw text]

Monte Carlo Integration


Hi,

I am trying to use parameters in 'gsl_monte_miser' but couldn't get it
worked so far. For reasons of simplicityI used the example program given in the
manual (which worked) and just tried to add parameters to compute the following
integral:

  I = \int_0^pi \int_0^pi \int_0^pi  1/(a * pi^3) * (1/(1 - b * cos x * cos
y * cos z))  dx dy dz

I only tried 'miser' ( the routine I want to use in my actual program - but
the other routines should work in the same manner). So my program looks as
follows:


#include <stdlib.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_monte.h>
#include <gsl/gsl_monte_miser.h>

struct mc_param {double a; double b;};

double g (double *k, size_t dim, void *p)
{
  struct mc_param *fp = (struct mc_param *)p;

  double A = 1.0 / (fp->a * M_PI * M_PI * M_PI);
  return A / (1.0 - fp->b * cos (k[0]) * cos (k[1]) * cos (k[2]));
}

int
main (void)
{
  double res, err;

  double xl[3] = { 0, 0, 0 };
  double xu[3] = { M_PI, M_PI, M_PI };

  const gsl_rng_type *T;
  gsl_rng *r;
  size_t calls = 500000;
  struct mc_param par = {1.0, 2.0};			/* values for parameter */
    
  gsl_monte_function G = { &g, 3, &par};			/* produces ERROR MESSAGE */

  gsl_rng_env_setup();

  T = gsl_rng_default;
  r = gsl_rng_alloc (T);

  {
    gsl_monte_miser_state *s = gsl_monte_miser_alloc (3);
	gsl_monte_miser_integrate (&G, xl, xu, 3, calls, r, s,&res, &err);
    gsl_monte_miser_free (s);

    printf("result: %lf,  error: %lf\n",res,err);
  }
  return 0;
}

It produces the following error messages:

C:\Cwork_local\Ctest1\mc\testmc.c(30) : error C2093: 'params' : cannot be
initialized using address of automatic variable 'par'
        C:\Cwork_local\Ctest1\mc\testmc.c(27) : see declaration of 'par'
C:\Cwork_local\Ctest1\mc\testmc.c(30) : error C2097: illegal initialization
Error executing cl.exe.

As far as I can understand, my command '&par' is not correct. Does anyone
know the correct command?
In case it is important: I am working on a PC, Microsoft 2000 Professional,
Visual C++ 6.0

Thanks a lot
Annett

-- 
+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
Bitte lächeln! Fotogalerie online mit GMX ohne eigene Homepage!


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