Week 6 Bifurcations and Chaos

Logistic Equation

Bunny Growth on Magical Island $$ X_{n+1} = rX_n$$

On a non-magical island $$X_{n+1} = rX_n(1-X_n)$$

In [1]:
import matplotlib.pyplot as plt
import numpy as np
import Pythonic_files as pf

%config InlineBackend.figure_format='retina'
In [16]:
plt.figure(figsize=(13,5))

r0=3.1

X_0=0.2
Steps=100
Max_x=1.1
X_old=X_0

for t in range(0,Steps):
    X_new=r0*X_old*(1-X_old)
    plt.plot(X_old,X_new,".",c='r',alpha=0.3)
    pf.Cobweb(X_old,X_new,'g',0.2)
    
    X_old=X_new
    Max_x=max(Max_x,X_new)
    
X=np.linspace(0,Max_x,100)
Y=r0*X*(1-X)
plt.plot(X,Y,c='b',alpha=0.5)

plt.plot(X,X,c='r',alpha=0.4)
plt.ylim(0,Max_x)
Out[16]:
(0.0, 1.1)
In [13]:
def log_func(x,r):
    return r*x*(1-x)

What happens when we vary $r$

In [19]:
for R in np.linspace(2,3.5,10):
    plt.figure(figsize=(13,5))

    r0=R

    X_0=0.2
    Steps=100
    Max_x=1.1
    X_old=X_0

    for t in range(0,Steps):
        X_new=log_func(X_old,r0)
        plt.plot(X_old,X_new,".",c='r',alpha=0.3)
        pf.Cobweb(X_old,X_new,'g',0.2)
    
        X_old=X_new
        Max_x=max(Max_x,X_new)
    
    X=np.linspace(0,Max_x,100)
    Y=log_func(X,r0)
    plt.plot(X,Y,c='b',alpha=0.5)

    plt.plot(X,X,c='r',alpha=0.4)
    plt.ylim(0,Max_x)
    plt.title('Parameter_value is r = '+str(R))
In [20]:
for R in np.linspace(2.95,3.6,10):
    plt.figure(figsize=(13,5))

    r0=R

    X_0=0.2
    Steps=100
    Max_x=1.1
    X_old=X_0

    for t in range(0,Steps):
        X_new=log_func(X_old,r0)
        plt.plot(X_old,X_new,".",c='r',alpha=0.3)
        pf.Cobweb(X_old,X_new,'g',0.2)
    
        X_old=X_new
        Max_x=max(Max_x,X_new)
    
    X=np.linspace(0,Max_x,100)
    Y=log_func(X,r0)
    plt.plot(X,Y,c='b',alpha=0.5)

    plt.plot(X,X,c='r',alpha=0.4)
    plt.ylim(0,Max_x)
    plt.title('Parameter_value is r = '+str(R))
In [33]:
r=3.21

X=np.linspace(0,Max_x,100)
Y=log_func(X,r)
YY=log_func(log_func(X,r),r)
plt.plot(X,Y,c='b',alpha=0.5)
plt.plot(X,YY,c='g',alpha=0.5)

plt.plot(X,X,c='r',alpha=0.4)
plt.ylim(0,Max_x)
plt.title('Parameter_value is r = '+str(r))
plt.show()
In [34]:
for R in np.linspace(2.9,3.4,10):
    plt.figure(figsize=(13,5))

    r0=R

    X_0=0.2
    Steps=100
    Max_x=1.1
    X_old=X_0

    for t in range(0,Steps):
        X_new=log_func(X_old,r0)
        plt.plot(X_old,X_new,".",c='r',alpha=0.3)
        pf.Cobweb(X_old,X_new,'g',0.2)
    
        X_old=X_new
        Max_x=max(Max_x,X_new)
    
    X=np.linspace(0,Max_x,100)
    Y=log_func(X,r0)
    plt.plot(X,Y,c='b',alpha=0.5)
    
    YY=log_func(log_func(X,r0),r0)
    plt.plot(X,YY,c='g',alpha=0.5)
    plt.plot(X,X,c='r',alpha=0.4)
    plt.ylim(0,Max_x)
    plt.title('Parameter_value is r = '+str(R))
In [35]:
for R in np.linspace(3.4,3.6,3):
    plt.figure(figsize=(13,5))

    r0=R

    X_0=0.2
    Steps=100
    Max_x=1.1
    X_old=X_0

    for t in range(0,Steps):
        X_new=log_func(X_old,r0)
        plt.plot(X_old,X_new,".",c='r',alpha=0.3)
        pf.Cobweb(X_old,X_new,'g',0.2)
    
        X_old=X_new
        Max_x=max(Max_x,X_new)
    
    X=np.linspace(0,Max_x,100)
    Y=log_func(X,r0)
    plt.plot(X,Y,c='b',alpha=0.5)
    
    YY=log_func(log_func(X,r0),r0)
    plt.plot(X,YY,c='g',alpha=0.5)
    plt.plot(X,X,c='r',alpha=0.4)
    plt.ylim(0,Max_x)
    plt.title('Parameter_value is r = '+str(R))
In [41]:
def log_multi_func(x,r,n):
    def mini_func(x,r):
        return r*x*(1-x)
    for count in range(0,n):
        x = mini_func(x,r)
    return x
In [49]:
r=3.5

X=np.linspace(0,Max_x,100)
Y=log_func(X,r)
YY=log_multi_func(X,r,2)
YYY=log_multi_func(X,r,4)

plt.plot(X,Y,c='b',alpha=0.5)
plt.plot(X,YY,c='g',alpha=0.5)
plt.plot(X,YYY,c='y',alpha=0.5)

plt.plot(X,X,c='r',alpha=0.4)
plt.ylim(0,Max_x)
plt.title('Parameter_value is r = '+str(r))
plt.show()
In [51]:
for R in np.linspace(3.5,3.6,1):
    plt.figure(figsize=(13,5))

    r0=R

    X_0=0.2
    Steps=100
    Max_x=1.1
    X_old=X_0

    for t in range(0,Steps):
        X_new=log_func(X_old,r0)
        plt.plot(X_old,X_new,".",c='r',alpha=0.3)
        pf.Cobweb(X_old,X_new,'g',0.2)
    
        X_old=X_new
        Max_x=max(Max_x,X_new)
    
    X=np.linspace(0,Max_x,1000)
    Y=log_func(X,r0)
    plt.plot(X,Y,c='b',alpha=0.5)
    
    YY=log_multi_func(X,r0,4)
    plt.plot(X,YY,c='g',alpha=0.5)
    plt.plot(X,X,c='r',alpha=0.4)
    plt.ylim(0,Max_x)
    plt.title('Parameter_value is r = '+str(R))

Lets look at these periodic solutions for different $r$ values

In [81]:
n = 1000
x0=0.2

R = np.linspace(2,3.65,n)
X = x0*np.ones(n)

YY = log_multi_func(X,R,1000)
In [88]:
for count in range(0,200):
    plt.plot(R,YY,',k',c='b',alpha=0.01)
    YY=log_func(YY,R)
In [93]:
plt.figure(figsize=(13,5))

n = 1000
x0=0.2

R = np.linspace(2,4,n)
X = x0*np.ones(n)

YY = log_multi_func(X,R,5000)


for count in range(0,600):
    plt.plot(R,YY,',k',c='black',alpha=0.1)
    YY=log_func(YY,R)
    
In [94]:
plt.figure(figsize=(13,5))

n = 1000
x0=0.1

R = np.linspace(2,4,n)
X = x0*np.ones(n)

YY = log_multi_func(X,R,5000)


for count in range(0,600):
    plt.plot(R,YY,',k',c='black',alpha=0.1)
    YY=log_func(YY,R)
    
In [97]:
rleft = 3.65
rright = 3.7

plt.figure(figsize=(13,5))

n = 1000
x0=0.1

R = np.linspace(rleft,rright,n)
X = x0*np.ones(n)

YY = log_multi_func(X,R,5000)


for count in range(0,1000):
    plt.plot(R,YY,',k',c='black',alpha=0.1)
    YY=log_func(YY,R)
In [98]:
rleft = 2.6
rright = 4

plt.figure(figsize=(13,5))

n = 1000
x0=0.1

R = np.linspace(rleft,rright,n)
X = x0*np.ones(n)

YY = log_multi_func(X,R,5000)


for count in range(0,1000):
    plt.plot(R,YY,',k',c='black',alpha=0.1)
    YY=log_func(YY,R)
In [ ]: