Sunday, May 29, 2011


/*Life is always simple, if you get going complex, you definitely are not living*/
/*Just see how patterns emerge from total chaos*/
/*enjoy, if you like maths or even drawing*/

#include <stdio.h>



main()

{

float x0, e, r, r1=3.987;

int i, T, n, M=100;

printf("Please enter the value of r(2,4] : ");

scanf("%f",&r);
     
    printf("Please enter the number of time steps : ");

scanf("%d",&T);

float C[T][M];

printf("Please enter the value of x(0) (0,1] : ");

scanf("%f",&x0);

printf("Please enter the value of coupling strength, e : ");

scanf("%f",&e);

C[0][0]=x0;

for (i=1; i<=M-1; ++i)

C[0][i]=r1*C[0][i-1]*(1-C[0][i-1]);

    for (n=1; n<=T-1; ++n)
    {
        C[n][0]= (1-e)*r*C[n-1][0]*(1-C[n-1][0]) + e*(r*C[n-1][M-1]*(1-C[n-1][M-1]) + r*C[n-1][1]*(1-C[n-1][1]))*0.5;
       
        C[n][M-1]= (1-e)*r*C[n-1][M-1]*(1-C[n-1][M-1]) + e*(r*C[n-1][M-2]*(1-C[n-1][M-2]) + r*C[n-1][0]*(1-C[n-1][0]))*0.5;
       
        for(i=1; i<=(M-2); i++)
       
        C[n][i]= (1-e)*r*C[n-1][i]*(1-C[n-1][i]) + e*(r*C[n-1][i-1]*(1-C[n-1][i-1]) + r*C[n-1][i+1]*(1-C[n-1][i+1]))*0.5;
        }
               
FILE *fp;


fp = fopen ("chaos.dat", "w");

int j, k;

for (j=0; j<=T-1; ++j)
{
        fprintf (fp, "\n");
       
        for (k=0; k<=(M-1); ++k)

fprintf (fp, "%f\n", C[j][k]);
    }
   
    fclose(fp);

printf("Now please open Chaos.dat and plot the data in gnuplot using Splot command (Help : google for the command syntax)\n Enjoy the patterns\n");

getch();

}

No comments: