[Top][All Lists]

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

[Help-gsl] performing several integrations for different parameter value

From: Altro
Subject: [Help-gsl] performing several integrations for different parameter values (gsl_odeiv2)
Date: Tue, 03 Jan 2012 17:15:38 +0100
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20111108 Thunderbird/3.1.16


I have to resolve a system of ODE for 5 values of a parameter (for example "h").
I implemented the following pseudo-code, but something is wrong:

typedef struct {double h; double p; double **J; other parameters } structure;
//store the parameter values in a vector pointed by h
structure S;
//definition of ODE system
gsl_odeiv2_system sys = {func, NULL, dimension, &S};
for (i=0; i<5; i++){
    S.h = h[i];    //assign to S.h one of the  5 values.
    gsl_odeiv2_step * s = gsl_odeiv2_step_alloc(stepper, 4);
    gsl_odeiv2_control * c = gsl_odeiv2_control_y_new (1e-6, 1e-6);
    gsl_odeiv2_evolve * e = gsl_odeiv2_evolve_alloc (4);
    for (j=1; j<=400; j++){
        while (t<t2) {
           //call a function that compute the jabobian at each step
           updatejacobian(S, x);
           //perform a time step
gsl_status = gsl_odeiv2_evolve_apply (e, c, s, &sys, &t, t2, &h, X);
    gsl_odeiv2_evolve_free (e);
    gsl_odeiv2_control_free (c);
    gsl_odeiv2_step_free (s);

updatejacobian (structure S, double *x){
    S.J[0][0] = S.r * sin(x[4*S.p+3]) * (1 - 2*S.h) - 1;

This program should perform 5 integrations of the same set of ODEs varing parameters S.h (I do not write the entire code, of course). The program behave well until i=0, but at the first increment I receive error:

Program received signal SIGSEGV, Segmentation fault.
0x0000000000401537 in updatejacobian (S=..., x=0x6045b0) at file.c:57
57        S.J[0][0] = S.r *sin(x[4*S.p+3]) * (1 - 2*S.h) - 1;

The program works well also setting S.h (e.g. S.h=0.2) and cutting the
cicle for (i=0; i<5; i++).

Do you understand what's wrong?


reply via email to

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