-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLyapunovExponent_RubyTranscript.rb
53 lines (48 loc) · 1.11 KB
/
LyapunovExponent_RubyTranscript.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Lyapunov Exponent Calculation (L) re-Written in Ruby from Old C example taken from C.Pickovers Chaos In Wonderland.
a = rrand(-3,0) # a > -3
b = rrand(0,3) # b < 3
c = rrand(0,0.5) # 0.5 < c
d = rrand(0,1.5) # d < 1.5
Lsum = 0
n = 0
x = 0.1
y = 0.1
xe = x + 0.000001
ye = y
(10**7).times do
xx = Math.sin(y*b) + c*Math.sin(x*b)
yy = Math.sin(x*a) + d*Math.sin(y*a)
xsave = xx
ysave = yy
x = xe
y = ye
n+=1
# Re-Iterate for computing Lyapunov Exponent (L)
xx = Math.sin(y*b) + c*Math.sin(x*b)
yy = Math.sin(x*a) + d*Math.sin(y*a)
dLx = xx - xsave
dLy = yy - ysave
dL2 = dLx*dLx + dLy*dLy
df = 1000000000000.*dL2
rs = 1./Math.sqrt(df)
xe = xsave + rs*(xx - xsave)
ye = ysave + rs*(yy - ysave)
xx = xsave
yy = ysave
Lsum = Lsum + Math.log(df)
L = 0.721347*Lsum/n
x = xx
y = yy
# L is the value for the Lyapunov exponent
slep = L
if (slep <= 0)
slep = slep * -1
end
sleep slep
use_random_seed L*1000
with_fx :pan, pan:rrand(-1,1) do
synth :beep, note:(scale (ring :es6,:es7,:es8,:es2).tick(:A),:aeolian).choose + L, sustain: slep*0.125
end
puts(L)
puts(n)
end