import numpy as np import matplotlib.pyplot as plt import sys # Question 1 def logistic(x0, r, iter): x = [x0] for i in xrange(iter): x.append(r*x[-1]*(1-x[-1])) return x # Question 2 for i in range(10): x = logistic(np.random.random(), 2.5, 1000) plt.plot(x) plt.savefig('simple.png') plt.close() # Question 3 for i in range(10): x = logistic(np.random.random(), 3.9, 1000) plt.plot(x) plt.savefig('chaotic.png') plt.close() # Question 4 R = [] X = [] for r in np.linspace(2.5, 4, 3000): print >> sys.stderr, r for j in xrange(10): x0 = np.random.random() x1 = logistic(x0, r, 1000)[-1] R.append(r) X.append(x1) plt.plot(R, X, ',') plt.xlabel('r') plt.savefig('logistic.png', dpi=400)