绘制 Logistic 映射分叉图

逻辑斯蒂映射:
x k + 1 = r x k ( 1 − x k ) x_{k+1} = rx_k(1-x_k) xk+1=rxk(1xk)

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rcParams
from tqdm.notebook import tqdm

rcParams.update({
   'font.size': 18})
plt.rcParams['figure.figsize'] = [12, 12]

startval = 1
endval = 4
xvals = np.array([[],[]])
n_iter = 1000
n_plot = 100

def logistic(xk,r):
    return r*xk*(1-xk)

for r in tqdm(np.arange(startval,endval,0.00025)):
    x = 0.5
    for i in range(n_iter):
        x = logistic(x,r)
        if i == n_iter-n_plot:
            xss = x
        if i > n_iter-n_plot:
            xvals = np.append(xvals,np.array([[r],[x]]),axis=1)
            if np.abs(x-xss) < 0.001:
                break

plt.plot(xvals[0,:],xvals[1,:],'.',ms=0.1,color='k')
plt.ylim(0,1)
plt.xlim(1,endval)

在这里插入图片描述

局部放大

plt.plot(xvals[0,:],xvals[1,:],'.',ms=0.1,color='k')
plt.ylim(0,1)
plt.xlim(3.45,4)
plt.xlabel('r')
plt.ylabel(' fixed point')

在这里插入图片描述

张贴在2