help-gsl
[Top][All Lists]
Advanced

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

[Help-gsl] (no subject)


From: virgilif
Subject: [Help-gsl] (no subject)
Date: Thu, 1 Apr 2010 12:52:08 -0700
User-agent: SquirrelMail/1.4.19

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<stdio.h>
#include<math.h>
#include<stdlib.h>
#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);

Epeak=180;
alphaband=0.85;
betaband=2.3;

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

gsl_function ENEDE;
ENEDE.function = &ENEdE;

struct parameters_ parameters;
parameters.Epeak=Epeak;
parameters.alphaband=alphaband;
parameters.betaband=betaband;

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

printf("%e\n",k2/k1);
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 {
return
En*pow((alpha-beta)*(Epeak/100),(alpha-beta))*exp(beta-alpha)*pow(En/100,beta);
}
}



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!

Best,

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


> Best,
>
> Francisco Virgili
>
>
>
> _______________________________________________
> Help-gsl mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/help-gsl
>



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







reply via email to

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