I´ve been using this code in C for integration with different equations but today i modified it to integrate the one shown and the .dat file is giving me all the columns full of "-nan". Is it a wrong-coding issue or its just that this equations isnt meant to be solved by this procedure?
Here are both the integration routine and the main code. Thanks
FIRST THE CODE (i chopped it explaining what does each part do, i apologize if its unpleasant at sight)
#include <stdio.h> #include <math.h> #define a -1 PARAMETERS
struct Par{ double mu1, mu2, w1, w2, eps; } aa; EQUATIONS
void ecuaciones(int n, double v[], double dv[], double t){ double x1,y1,x2,y2; x1=v[0]; x2=v[1]; y1=v[2]; y2=v[3]; y1=aa.mu1*x1-aa.w1*y1-(x1*x1+y1*y1)*x1+aa.eps*(x1-x2) ; y2=aa.mu2*x2-aa.w2*y2-(x2*x2+y2*y2)*x2+aa.eps*(x2-x1) ; dv[0]=y1; dv[1]=y2; dv[2]=aa.w1*x1+aa.mu1*y1-y1*(x1*x1+y1*y1)+aa.eps*(y1-y2) ; dv[3]=aa.w2*x2+aa.mu2*y2-y2*(x2*x2+y2*y2)+aa.eps*(y2-y1) ; return; } MAIN
int main(){ int i,j; FILE *ptr; double v[4],t,dt,t_pre,t_max; EXIT
ptr=fopen("NLIAC.dat","w"); dt=0.01; t_max=20; INITIAL CONDITIONS
for (i = 2; i < 6; i++) { v[0]=i; v[1]=6; v[2]=0; v[3]=1; PARAMETERS DEFINITION aa.w1=1; aa.mu1=1; aa.w2=6; aa.mu2=1; aa.eps=0;
t=0.; INTEGRATION COMMAND
while(t<t_max){ rk4(ecuaciones,v,4,t,dt); EXPORT
fprintf(ptr,"%lg\t%lg\t%lg\t%lg\t%lg\n",t,v[0],v[1],v[2],v[3]); t+=dt; }} fprintf(ptr,"\n"); fclose(ptr); return(0); } AND HERE IS THE INTEGRATION ROUTINE (its fine)
void rk4(void deri(int , double [], double [], double ), \ double h[], int n, double t, double dt) { #define naux 26 int i; double k1[naux],k2[naux],k3[naux],k4[naux],h0[naux]; double dt2, dt6; dt2=dt/2.; dt6=dt/6.; for (i = 0 ; i<n; i++) h0[i] = h[i]; deri(n,h0,k1,t); for (i =0 ; i<n ; i++) h0[i]=h[i]+dt2*k1[i]; deri(n,h0,k2,t+dt2); for (i =0 ; i<n ; i++) h0[i]=h[i]+dt2*k2[i]; deri(n,h0,k3,t+dt2); for (i =0 ; i<n ; i++) h0[i]=h[i]+dt*k3[i]; deri(n,h0,k4,t+dt); for (i = 0 ; i<n ; i++) {h0[i]=h[i]+dt*k4[i];}; for (i =0; i<n ; i++) h[i]=h[i]+dt6*(2.*(k2[i]+k3[i])+k1[i]+k4[i]); return; }