Logistic Map (2021.01) === ###### tags: `Side Project`, `Python` ## Brief ![](https://i.imgur.com/e8DqhHv.png) ## Result ![](https://i.imgur.com/pRXdExC.png) ![](https://i.imgur.com/6mNsaSz.png) ![](https://i.imgur.com/etp4T2i.png) ## Code ``` import numpy as np import matplotlib.pyplot as plt from numpy.linalg import norm from matplotlib import style import math 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 def fillit(n1,n2,x0,mu): x = x0 # initial x value z = np.linspace(0.0,1.0,n2-n1) # create an array for i in range(0,n1): # do n1 iterations x = logistic(x,mu) for i in range(0,n2-n1): # fill n2-n1 iterations x = logistic(x,mu) z[i] = x return z def cal(res): k=[] for i in range(len(res)): a = int(res[i]*1000) if (i == 0): k.append(a) else: count = 0 for j in range(len(k)): if(k[j] != a): count = count + 0 else: count = count + 1 break if(count == 0): k.append(a) return (len(k)) # plot the iterated logistic map for nmu number of mu values def mkplot(mu_min,nmu): # nmu is number of mu values to use, mu_min range mu_max = 3.6 # maximum mu value muarr = np.linspace(mu_min,mu_max,nmu) n1=100 #specify iteration range n2=200 x0=0.5 # initial x for i in range(nmu-1, 0, -1): mu = muarr[i] y=fillit(n1,n2,x0,mu) # get the array of iterations test = cal(y) ############################### # 收斂成2 # if(test==2): # print(test) # print(y) # print(i) # print("mu = " + str(mu)) # break # 收斂成1 # if(test==1): # print(test) # print(y) # print(i) # print("mu = " + str(mu)) # break ############################### x=y*0.0 + mu plt.plot(x,y,',k',markersize=1) plt.figure() plt.xlabel(r'$\mu$') mu_min=2 plt.axis([mu_min, 3.6, 0, 1.0]) mkplot(mu_min,1000) plt.show() ```