217 KiB
217 KiB
In [13]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
def plot_style(figsize=(12, 6), labelsize=20, titlesize=24, ticklabelsize=14, **kwargs):
basic_style = {
'figure.figsize': figsize,
'axes.labelsize': labelsize,
'axes.titlesize': titlesize,
'xtick.labelsize': ticklabelsize,
'ytick.labelsize': ticklabelsize,
}
basic_style.update(kwargs)
return plt.rc_context(rc=basic_style)
In [20]:
def logistic_map(x, r):
return r * x * (1 - x)
def iterate_map(x0, r, n):
xs = [x0]
for _ in range(n):
x_np1 = logistic_map(xs[-1], r)
xs.append(x_np1)
return xs
In [43]:
x = np.linspace(0, 1, 100)
r = 1.5
f_x = logistic_map(x, r)
In [44]:
with plot_style(figsize=(5, 5), titlesize=20):
plt.plot(x, f_x)
plt.plot([0, 1], [0, 1], 'r--', lw=1)
plt.xlim(0, 1)
plt.ylim(0, 1)
plt.xlabel('x')
plt.ylabel('f(x)')
plt.title(f'r = {r}')
In [84]:
r = 1.5
xs_01 = iterate_map(x0=0.1, r=r, n=20)
xs_03 = iterate_map(x0=0.3, r=r, n=20)
xs_05 = iterate_map(x0=0.4, r=r, n=20)
with plot_style(figsize=(5, 5), titlesize=20):
plt.plot(xs_01, lw=3, label=0.1)
plt.plot(xs_03, lw=3, label=0.3)
plt.plot(xs_05, lw=3, label=0.5)
plt.ylim(0, 1)
plt.xticks([0, 5, 10, 15, 20])
plt.xlabel('iteration')
plt.ylabel('x')
plt.title(f'r = {r}')
plt.legend(title='$x_0$ value', fontsize=14, title_fontsize=16, frameon=False)
In [85]:
r = 3.2
xs_01 = iterate_map(x0=0.1, r=r, n=20)
xs_03 = iterate_map(x0=0.3, r=r, n=20)
xs_05 = iterate_map(x0=0.4, r=r, n=20)
with plot_style(figsize=(5, 5), titlesize=20):
plt.plot(xs_01, lw=3, label=0.1)
plt.plot(xs_03, lw=3, label=0.3)
plt.plot(xs_05, lw=3, label=0.5)
plt.ylim(0, 1)
plt.xticks([0, 5, 10, 15, 20])
plt.xlabel('iteration')
plt.ylabel('x')
plt.title(f'r = {r}')
plt.legend(title='$x_0$ value', fontsize=14, title_fontsize=16, frameon=False)
In [86]:
r = 3.9
xs_01 = iterate_map(x0=0.1, r=r, n=20)
xs_03 = iterate_map(x0=0.3, r=r, n=20)
xs_05 = iterate_map(x0=0.4, r=r, n=20)
with plot_style(figsize=(5, 5), titlesize=20):
plt.plot(xs_01, lw=3, label=0.1)
plt.plot(xs_03, lw=3, label=0.3)
plt.plot(xs_05, lw=3, label=0.5)
plt.ylim(0, 1)
plt.xticks([0, 5, 10, 15, 20])
plt.xlabel('iteration')
plt.ylabel('x')
plt.title(f'r = {r}')
plt.legend(title='$x_0$ value', fontsize=14, title_fontsize=16, frameon=False)
In [ ]: