/* * logistic map * * record x_n+1 vs x_n * useful for studying return maps and period doubling behavior * * by N Giordano -- July 2006 * * usage: logistic_map3 mu [x_0] [n_max] * mu = control parameter (should be between 0 and 4) x_0 = initial value of x (optional) n_max = number of iterations (optional) * * write results to standard output */ #include #include double atof(); double mu; double x_new,x_old; int n_max; main(argc,argv) int argc; char* argv[]; { int seed; int i; /* initialize parameters */ if(argc <=1) { fprintf(stderr,"usage map mu [x_0] [n_max]\n"); exit(0); } mu = atof(argv[1]); x_new = 0; if(argc >= 3) { x_old = atof(argv[2]); } else { x_old = 0.314159; } if(argc >= 4) { n_max = atoi(argv[3]); } else { n_max = 100; } /* do the actual calculation here */ printf("%g\t%g\n",x_old,x_new); for(i = 1; i < n_max; i++) { x_new = mu * x_old * (1.0 - x_old); printf("%g\t%g\n",x_old,x_new); x_old = x_new; printf("%g\t%g\n",x_old,x_new); } }