python-3.x 费根鲍姆逻辑斯蒂Map

cbjzeqam  于 2023-03-13  发布在  Python
关注(0)|答案(1)|浏览(124)

我有麻烦,以绘制费根鲍姆逻辑Map,我做了这个代码:

def logistic_map(r,x = 1./2,n = 1000):
   
    for i in range(n):
        x = i*x*(1-x)
    return x
r = np.arange(1,4,0.01)
x = np.zeros(len(r))

for i in r:
    x += logistic_map(i)
plt.plot(r,x,"k.")
plt.xlabel("r")
plt.ylabel("x")

有人能告诉我这段代码哪里出错了吗,因为我在画(r,x)的时候,把形状画错了。

wvt8vs2t

wvt8vs2t1#

#!/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt

filename = "plot.png"

plotlist = []

for r in np.arange(2.8, 4, 0.0001):
    x = 0.1
    print(r)
    for i in range(150):
        x = r*x*(1 - x)
        if i >= 100:
            plotlist.append((r, x))

r, x = zip(*plotlist)
plt.scatter(r, x, 0.002, marker='o', cmap='hsv', alpha=0.1)
plt.xlim(2.8, 4)
plt.savefig(filename, dpi = 1200)

# https://github.com/void4main/bifurcation-diagram

相关问题