def cobweb(mu, walkers=10, steps=7): f = plt.figure() ax = f.add_subplot(111) interval = np.linspace(0.0, 1.0, 100) logmap = Logistic(mu) logmap.plot(ax, interval, lw=2) for x0 in np.random.rand(walkers): logmap.plot_cobweb(ax, x0, steps, lw=2) ax.set_title('Ex 2A: Random init. cond. for mu=%1.3f'%mu) return f
def invariant_density(mu, x0,cycles=1000000,ret_all=False, bins=500): transients = 1000 f = plt.figure() ax = f.add_subplot(111) logmap = Logistic(mu) y0 = logmap.iterate_from(x0, transients) y = logmap.trajectory(y0, cycles) n, bins, patches = ax.hist(y, bins, normed=1) ax.set_xlim(0,1) if ret_all: return f,logmap,n else: return f
import numpy as np import matplotlib.pyplot as plt from maplib import Logistic epsilon = 1e-10 x0 = 0.4 y0 = x0 + epsilon logmap = Logistic(0.9) x = logmap.trajectory(x0, 100) y = logmap.trajectory(y0, 100) ind = np.arange(len(x), dtype=float) # x-y \sim epsilon exp(lambda * t) # log(|x-y|) = log(epsilon) + lambda*t (b=log(epsilon) and m=lambda) d = np.log(abs(x-y)) coeffs = np.polyfit(ind, d, 1) lyap_exp, b = coeffs print 'lyapunov exponent= %1.3f' % lyap_exp print 'log(epsilon)=%1.3f, b = %1.3f' % (np.log(epsilon), b) # now plot the result plt.subplot(211) plt.plot(ind, x, '-r', ind, x, '--g', ) plt.subplot(212) plt.plot(ind, d, ind, np.polyval(coeffs, ind)) plt.show()