help-gsl
[Top][All Lists]
Advanced

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

[Help-gsl] ODE system (vectorial)


From: Altro
Subject: [Help-gsl] ODE system (vectorial)
Date: Sat, 23 Jul 2011 11:14:42 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110617 Thunderbird/3.1.11

Hi,
I'm trying to integrate an ODE system using odeiv2.
There are 2*n variables, we call them x_i and y_i, where i range from 0 to n.
The system has this form:

x'_i= f( sum_i)
y'_i=g(...x_i, y_i, .... , sum_i)

where

sum_i = y_0 + y_1 + y_2 + ....y_n

I define the system with (second argument is a pointer to the Jacobian matrix, but I do not need it) :

N=2*n;
gsl_odeiv2_system sys = {func, NULL, N, &parameters};

I have some doubt in the definition of argument func.
I implement my functions in this way:

int func (double t, const double *x, double *f, void *params) { //odd index entries of x[] correspond to y_i, while even index entries correspond to x_i
    structype S = *(structype *)params;
    int i, j;
    for (i=0; i<N; i=i+2) {
        S.sum[i/2]=0;
        for (j=0; j<N; j=j+2) {
             S.sum[i/2]=S.sum[i/2] + x[j+1];
        }
f[i] = S.param1 * f(S.sum[i/2]) ; //x'_i= f( sum_i) f[i+1]= S.param2 * x[i] * f(S.sum[i/2]) + S.sum[i/2] * x[i+1]; //y'_i=g(...x_i, y_i, .... , sum_i)
    }
    return GSL_SUCCESS;
}
where
typedef struct {
    double param1;
    double param2;
    double *sum;    //sum is a vector of dimension  n.
} structype;
and
double f(double x)
is an external function.

Is this implementation correct?
I wonder if it is better to implement the system using sum_i as a third variable, so having a system of dimension 3*n...

Regards,

A.



reply via email to

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