Skip to content

Instantly share code, notes, and snippets.

@zeimusu
Created December 23, 2014 11:26
Show Gist options
  • Save zeimusu/a647b92be09ab50a0382 to your computer and use it in GitHub Desktop.
Save zeimusu/a647b92be09ab50a0382 to your computer and use it in GitHub Desktop.
Bifurcation diagram for the logistic map n-> r n (n-1). Also called Feigenbaum diagram
import turtle as t
xstart = 3.2
ystart = 0
xend = 4
yend = 1
xstep = 0.5*(xend-xstart)/t.screensize()[0]
convergesteps = 100
plotsteps = 100
t.setworldcoordinates(xstart,ystart,xend,yend)
t.penup()
t.hideturtle()
def logistic(r,n):
return r*n*(1-n)
def plotn(n,x,y=0.5):
"""
plot n points.
If the sequence has converged these will all be in the same
place. Use x for the logistic parameter and y for initial value
"""
t.tracer(0)
for i in range(n):
t.setpos(x,y)
t.dot(1)
y = logistic(x,y)
t.update()
def converge(x,y=0.5,loops=convergesteps):
"""
loop the logistic map to converge to an attractor (orbit, or strange)
return the final value of the sequence to use as an initial value for the
ploting routine.
The problem is the number of loops (100 by default)
is both too big -> the sequence will often have converged before that point
or too small -> at the interesting biurfication points it will take longer
But how to decide when to stop converging and start plotting? For example
just before the 2->4 biurification the sequence will almost enter a 4 loop,
but in two pairs of close values, which become progressively closer
[0, 0.1 1, 1.1 ; 0.02, 0.08 1.02 1.08 ...] eventually convegint to a 2
-orbit. How is the 'puter to recognize this
"""
for i in range(loops):
y = logistic(x,y)
return y
def main():
x=xstart
while x <= xend:
y = converge(x)
plotn(plotsteps,x,y=y)
x += xstep
main()
t.exitonclick()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment