I like playing with equations, particularly those dealing with chaos.
There is a simple recurrence relation called the logistic map that is usually pointed to as the archtypal example of chaotic behaviour emerging from a simple non-linear equation.
I wrote a small program to iterate the above formula for different values of r and starting values of x, and I was able to reproduce the bifurication diagram that illustrates the emergence of chaotic behaviour as r increases.
#include <cstdlib> | |
#include <fstream> | |
#include <cmath> | |
#include <ctime> | |
// Prototypes | |
void update(int niter, double mu, double &x); | |
double random_double(); | |
int main(int narg, char *argv[]) { | |
int nr = 1001, nx = 1001, niter = 64; | |
double rmin = 0.0, rmax = 4.0, dr = (rmax - rmin)/static_cast<double>(nr - 1); | |
double xmin = 0.0, xmax = 1.0; | |
double r, x; | |
srand(time(NULL)); | |
std::fstream fs("output.dat", std::fstream::out); | |
for(int i = 0; i < nr; i++) { | |
r = rmin + dr * static_cast<double>(i); | |
for(int j = 0; j < nx; j++) { | |
x = xmin + (xmax - xmin) * random_double(); | |
update(niter, r, x); | |
fs << r << ", " << x << "\n"; | |
} | |
} | |
fs.close(); | |
return 0; | |
} | |
// Update function for single variable x | |
void update(int niter, double r, double &x) { | |
for(int k = 0; k < niter; k++) { | |
x = r*x*(1.0 - x); | |
} | |
} | |
// Random double precision number in the range [0,1) | |
double random_double() { | |
return static_cast<double>(rand())/static_cast<double>(RAND_MAX); | |
} |
I then tried different recurrence relations to see if I could find any other interesting chaotic behaviour, and I found one that appears to display similar behaviour as the logistic map
It produced a symmetrical version of the logistic map, centred on zero:
The two recurrence relations appear to be quite different, but they seem to produce similar chaotic behaviour. This recurrence formula is actually based on Kepler’s equation, and in fact it is possible to solve Kepler’s equation using fixed point iteration after a simple re-arrangement of the equation. Though the figure above does not display solutions to Kepler’s equation, if it did then there would be a major discrepancy between theory and observations.
If you find this interesting, try playing with the code and experiment for yourself. And if you come across an other interesting relations, feel free to share, I’d be curious to know.