Definition of the model $x_{i+1} = R\cdot x_i(1-x_1)\quad$ and two helper functions
def logi(x,R) :
val = x
while True :
yield val
val = R*val*(1-val)
def firstn(g,n) :
for i in range(n) :
yield g.next()
def lastmfromn(g,m,n) :
for i in range(n) :
val = g.next()
if(i>m) : yield val
Let's look at some time series
R = 2
x0 = 0.1
n = 50
x = list(firstn(logi(x0,R),n))
t = range(len(x))
import matplotlib
from pylab import *
figure(1,(12,6))
matplotlib.pyplot.plot(t,x)
matplotlib.pyplot.ylim(0,1.1)
matplotlib.pyplot.xlabel("time steps")
matplotlib.pyplot.ylabel("population")
xp=int(0.5*n)
yp=x[xp]
matplotlib.pyplot.annotate('R=2 ... limit population: 0.5', color="blue",xy=(xp-0.5, yp),xytext=(0.3*n,0.3),verticalalignment='center',arrowprops=dict(arrowstyle="->"))
R = 3.2
x0 = 0.1
x = list(firstn(logi(x0,R),n))
t = range(len(x))
import matplotlib
matplotlib.pyplot.plot(t,x)
matplotlib.pyplot.ylim(0,1.1)
matplotlib.pyplot.xlabel("time steps")
matplotlib.pyplot.ylabel("population")
xp=int(0.75*n)
yp=x[xp]
matplotlib.pyplot.annotate('R=3.2 ... oscillation 2 solutions', color="green", xy=(xp, yp),xytext=(0.4*n,1),verticalalignment='center',arrowprops=dict(arrowstyle="->"))
R = 3.5
x0 = 0.1
x = list(firstn(logi(x0,R),n))
t = range(len(x))
import matplotlib
matplotlib.pyplot.plot(t,x)
matplotlib.pyplot.ylim(0,1.1)
matplotlib.pyplot.xlabel("time steps")
matplotlib.pyplot.ylabel("population")
yp=x[int(xp)]
matplotlib.pyplot.annotate('R=3.5 ... oscillation 4 solutions', color="red",xy=(xp, yp),xytext=(0.4*n,0.1),verticalalignment='center',arrowprops=dict(arrowstyle="->"))
matplotlib.pyplot.savefig("logiOsz.png")
matplotlib.pyplot.show()
n=100
R = 3.738
x0 = 0.1
x = list(firstn(logi(x0,R),n))
t = range(len(x))
import matplotlib
figure(2,(12,6))
matplotlib.pyplot.plot(t,x,)
matplotlib.pyplot.ylim(0,1.1)
matplotlib.pyplot.xlabel("time steps")
matplotlib.pyplot.ylabel("population")
xp = 0.75
matplotlib.pyplot.annotate('R=3.738, x0=0.1', xy=(xp*n, x[int(xp*n)]),xytext=(0.5*n,1),verticalalignment='center',arrowprops=dict(arrowstyle="->"))
x0 = 0.1001
x = list(firstn(logi(x0,R),n))
t = range(len(x))
import matplotlib
matplotlib.pyplot.plot(t,x,)
matplotlib.pyplot.ylim(0,1.1)
matplotlib.pyplot.xlabel("time steps")
matplotlib.pyplot.ylabel("population")
matplotlib.pyplot.annotate('R=3.738, x0=0.1001', xy=(xp*n, x[int(xp*n)]),xytext=(0.5*n,0.1),verticalalignment='center',arrowprops=dict(arrowstyle="->"))
matplotlib.pyplot.savefig("chaos.png")
matplotlib.pyplot.show()
R = 3.74
x0 = 0.1
x = list(firstn(logi(x0,R),n))
t = range(len(x))
import matplotlib
figure(3,(12,6))
matplotlib.pyplot.plot(t,x,)
matplotlib.pyplot.ylim(0,1.1)
matplotlib.pyplot.xlabel("time steps")
matplotlib.pyplot.ylabel("population")
xp = 0.73
matplotlib.pyplot.annotate('R=3.74, x0=0.1', xy=(xp*n, x[int(xp*n)]),xytext=(0.5*n,1),verticalalignment='center',arrowprops=dict(arrowstyle="->"))
x0 = 0.1001
x = list(firstn(logi(x0,R),n))
t = range(len(x))
import matplotlib
matplotlib.pyplot.plot(t,x,)
matplotlib.pyplot.ylim(0,1.1)
matplotlib.pyplot.xlabel("time steps")
matplotlib.pyplot.ylabel("population")
matplotlib.pyplot.annotate('R=3.738, x0=0.1001', xy=(xp*n, x[int(xp*n)]),xytext=(0.5*n,0.1),verticalalignment='center',arrowprops=dict(arrowstyle="->"))
matplotlib.pyplot.savefig("order.png")
matplotlib.pyplot.show()
Now lets create the bifurcation plot:
rval = []
points = []
m = 1000
from numpy import linspace
for R in linspace(2.8,4,20000) :
myp = list(lastmfromn(logi(0.1,R),m,m+100))
myR = [ R for i in range(size(myp))]
rval+=myR
points+=myp
import matplotlib
figure(10, figsize=(15,12))
matplotlib.pyplot.scatter(rval,points,s=0.001,alpha=0.3)
matplotlib.pyplot.xlabel("R")
matplotlib.pyplot.ylabel("population")
matplotlib.pyplot.xlim(2.8,4)
matplotlib.pyplot.savefig("logisticMap.png")
matplotlib.pyplot.savefig("logisticMap.jpg")
matplotlib.pyplot.show()