[Top][All Lists]

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

RE: [Help-gsl] (no subject)

From: Earl, Joseph
Subject: RE: [Help-gsl] (no subject)
Date: Fri, 2 Apr 2010 14:12:41 +0100

For the struct, if you are only passing doubles it's simpler to use:

double myStruct[3];
myStruct[0] = param1;
myStruct[1] = param2;
myStruct[2] = param3;

That should work (I think). 3 is the number of elements so, increase it if you 

Joseph Earl

-----Original Message-----
From: address@hidden [mailto:address@hidden On Behalf Of address@hidden
Sent: 01 April 2010 20:52
To: address@hidden
Subject: [Help-gsl] (no subject)

Great.  Don't want to waste anyone's time...

So, I am trying to use the 'qag' numerical subroutine in a program I am
writing and am having problems passing multiple parameters from my main
program into the function that I am trying to integrate.  I was able to do
it with one parameter, as shown on the gsl webpage, and that works ok, but
I can't get it to work with the three I need.

I tried making a structure, as shown below, and it compiles but gives a
bus error when I try to run the code.  Here is an example of what I tried:

#include <gsl/gsl_integration.h>

struct parameters_{
double Epeak;
double alphaband;
double betaband;

double ENEdE(double En, void * params);
const double z=2.77;
const double omega_m=0.3;
const double omega_A=0.7;
const double H0=7.1;

int main() {

double Epeak;
double band1=15.;
double band2=150.;
double alphaband;
double betaband;

gsl_integration_workspace * w = gsl_integration_workspace_alloc (10000);


double k1,k1_err,k2,k2_err,k3,k3_err,lumdist;

gsl_function ENEDE;
ENEDE.function = &ENEdE;

struct parameters_ parameters;

gsl_integration_qag (&ENEDE, band1, band2, 0, 1e-7, 1000, 5, w, &k1,
gsl_integration_qag (&ENEDE, 1/(1+z), 10000/(1+z), 0, 1e-7, 1000, 5, w,
&k2, &k2_err);

gsl_integration_workspace_free (w);

return 0;

double ENEdE(double En, void * params) {

struct parameters_ parameters = *(struct parameters_ *)params;

double Epeak= parameters.Epeak;
double alpha= parameters.alphaband;
double beta= parameters.betaband;
if ((alpha-beta)*Epeak >= En) {
return En*pow(En/100,alpha)*exp(-En/Epeak);
else {

Again, it compiles but it crashes at the call of 'qag'.  Any idea what
might be going wrong? Or is there a better method to pass these
parameters?  In the main program, the values for the variables 'Epeak',
'alphaband' and 'betaband' change every iteration so making them global
variables is out.  Thanks!


Francisco Virgili

> Good Afternoon-
> I had a question about passing some parameters in a program utilizing the
> numerical integration subroutine 'qag'.  Would this be the correct address
> to send that question?  Thank you.
AFAIK, this is the correct place to answer doubts about GSL subroutines. So

> Best,
> Francisco Virgili
> _______________________________________________
> Help-gsl mailing list
> address@hidden

Ivan Pulido
Estudiante de FĂ­sica
Universidad Nacional de Colombia

Help-gsl mailing list

reply via email to

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