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, ¶meters};
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.
_______________________________________________
Help-gsl mailing list
Help-gsl@gnu.org
https://lists.gnu.org/mailman/listinfo/help-gsl