#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Cobweb plot Created on Mon Aug 24 08:43:32 2020 @author: sal """ # scientific libraries import numpy as np import matplotlib.pyplot as plt # parameters and initial conditions x0 = 0.123 # initial state n = 7 # number of iterations # transformation l = 3.333 def map(x,l): return l * x * (1-x) # logistic map l=lambda # cobweb arrays X, Y = [x0] , [x0] xn = x0 for i in range(0,n): yn = map(xn,l) # f(xn) X.append(xn) , Y.append(yn) # (xn, f(xn)) X.append(yn) , Y.append(yn) # (f(xn), f(xn)) xn = yn # picture plt.figure() plt.title('Cobweb plot of the map $f(x)=$' + str(round(l,3)) +'$\cdot x (1-x)$') #plt.xlabel('x') #plt.ylabel('f(x)') xmin, xmax = 0.0 , 1.0 ymin, ymax = 0.0 , 1.0 plt.axis([xmin,xmax,ymin,ymax]) plt.axis('equal') x = np.arange(xmin, xmax, 0.01) plt.scatter(x0, x0, c='lightblue', s=40, label='$x(0)=$' + str(x0)) # initial state plt.plot(x,x, 'pink') # diagonal plt.plot(x,map(x,l), 'r') # graph of the tranformation plt.plot(X,Y,'lightblue') # cobweb plot plt.scatter(Y[2*n], Y[2*n], c='C0', s=40, label='$x($' + str(n) + '$) \simeq $' + str(round(xn,3)) ) # final state plt.legend()