plot periodic orbits and iterations for the logistic map¶

#

In [1]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
In [27]:
# logistic map is f(x) = mu*x*(1-x)  with mu in (0,4)
def logistic(x,mu):
        y = mu*x*(1.0-x)
        return y

# fill an array with iteration n1 to n2 of the logistic map starting with x0
# and with parameter mu
# run n1 iterations, discard, then run n2 iterations
def fillit(n1,n2,x0,mu):
        x = x0  # initial x value
        z = np.linspace(0.0,1.0,n2)  # create an array
        for i in range(0,n1):   # do n1 iterations
                x = logistic(x,mu)

        for i in range(0,n2):   # fill n2 iterations
                x = logistic(x,mu)
                z[i] = x

        return z  # returning the array of iterates


# plot the iterated logistic map for nmu number of mu values
# ax is the plotting axis
def mkplot(mu_min,nmu,ax):  # nmu is number of mu values to use, mu_min range
        mu_max = 4.0  # maximum mu value
        muarr = np.linspace(mu_min,mu_max,nmu)
        n1=100  #specify iteration range
        n2=100
        x0=0.5  # initial condition x
        for i in range(0,nmu):
                mu = muarr[i]
                y=fillit(n1,n2,x0,mu)  # get the array of iterations
                x=y*0.0 + mu   # dummy x value is all mu
                #ax.scatter(x,y,s=0.1,alpha=0.5,color='blue')   # k, plot small points
                ax.plot(x,y,'b.',alpha=0.5,ms=0.5)   # plot small points
In [28]:
fig,ax = plt.subplots(1,1,figsize=(3,3),dpi=300)
ax.set_xlabel(r'$\mu$',fontsize=20)
mu_min=2.9
ax.set_xlim([mu_min, 4.0])
ax.set_ylim([ 0, 1.0])
# this makes the plot!
mkplot(mu_min,1000,ax)
In [ ]: