Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Lyapunov Exponent (Processing)
/** Lyapunov Exponent
*
* Based on code on pg. 62 of _Chaos in Wonderland_
* by Clifford A. Pickover
*
*/
float calcLyapunovExponent(float a, float b, float c, float d) {
float Lsum = 0;
float n = 0;
float x = 0.1;
float y = 0.1;
float xe = x + 0.000001;
float ye = y;
float xx, yy, xsave, ysave, dLx, dLy, dL2, df, rs, L = 0;
float bigNumber = 2139095039; /* Pickover's algorithm calls
for a long int (1000000000000) here, but I often get NaN returned
when using it in Processing, and I have found that using a
large float returns a value close enough to Pickover's to
be useful. */
for(int i=0; i<10000000; i++) {
xx = sin(y*b) + c*sin(x*b); yy = sin(x*a) + d*sin(y*a);
xsave = xx; ysave = yy; x = xe; y = ye; n++;
xx = sin(y*b) + c*sin(x*b); yy = sin(x*a) + d*sin(y*a);
dLx = xx - xsave; dLy = yy - ysave; dL2 = dLx*dLx + dLy*dLy;
df = bigNumber*dL2; rs = 1/sqrt(df);
xe = xsave + rs*(xx - xsave); ye = ysave + rs*(yy - ysave);
xx = xsave; yy = ysave; Lsum = Lsum + log(df); L = 0.721347*Lsum/n;
x = xx; y = yy;
}
return L;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment