%matplotlib inline
import utils
import box_count
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
samples=50
t, x_t = utils.solve_lorenz(N=samples, t_max=1000)
# Pick a colormap: viridis, plasma, gray, binary, seismic, gnuplot
viridis = cm.get_cmap('viridis', 50)
colors = viridis(np.linspace(0, 1, 50))
plt.figure(figsize=(12, 12))
plt.style.use('bmh')
plt.xlabel('$x$')
plt.ylabel('$z$')
for i in range(1):
x, y, z = x_t[i,:,:].T
plt.plot(x, z, "-")
plt.style.use('bmh')
fig, ax = plt.subplots(figsize=[10, 10])
# zoom-in lower-left corner of inset axes, and its width and height.
# axins = ax.inset_axes([0.675, 0.05, 0.25, 0.25])
axins = ax.inset_axes([0.1, 0.1, 0.3, 0.3])
# sub-region of the original image
x1, x2, y1, y2 = -5, -4.4, 28.4, 29.5
axins.set_xlim(x1, x2)
axins.set_ylim(y1, y2)
axins.set_xticklabels('')
axins.set_yticklabels('')
axins.set_facecolor('white')
rectpatch, connects=ax.indicate_inset_zoom(axins)
connects[0].set_visible(False)
connects[1].set_visible(True)
connects[2].set_visible(False)
connects[3].set_visible(True)
for i in range(samples):
x, y, z = x_t[i,:,:].T
xi, zi = utils.find_zero_crossings(x,y,z)
ax.plot(xi, zi, '.')
axins.plot(xi, zi, '.')
plt.xlabel('$x$')
plt.ylabel('$z$')
Text(0, 0.5, '$z$')
fd = []
for i in range(1, samples+1):
d = box_count.dimension(np.concatenate(x_t[:i,:,:], axis=0))
fd.append(d)
# print(fd)
# plt.style.use('bmh')
# fig, ax = plt.subplots(figsize=(12, 6))
# ax.set_xlabel("Samples")
# ax.set_ylabel("Dimension")
# ax.scatter(range(1, samples+1), fd, c="red")
import numpy as np
from scipy.optimize import curve_fit
import matplotlib.pyplot as plt
def fit_function(xd, a, b, n):
return a * xd ** n / (xd ** n + b)
x = np.arange(1., samples + 1.)
popt, pcov = curve_fit(fit_function, x, fd)
plt.style.use('bmh')
fig, ax = plt.subplots(figsize=(12, 6))
plt.scatter(x, fd)
plt.plot(x, fit_function(x, *popt), 'r-')
plt.show()
# Standard deviation errors on the parameters
sd = np.sqrt(np.diag(pcov))
# Optimal values
print(f"Fitted parameters: a = {popt[0]:.3f} ± {sd[0]:.2f}, b = {popt[1]:.3f}, n = {popt[2]:.3f}")
print(f" {sd}")
Fitted parameters: a = 2.101 ± 0.09, b = 0.134, n = 0.175 [0.09333063 0.04731838 0.0860685 ]