Non-Linear Dynamics Trajectories with Python
by Ritobrata Ghosh
Introduction
In this Notebook, trajectories of the Logistic Map [1] is plotted with Python.
import numpy as np
import matplotlib.pyplot as plt
def logistic_function(parameter: float, initial_value: float) -> float:
return parameter * initial_value * (1 - initial_value)
def logistic_function_trajectory(parameter: float,
float,
initial_value: int) -> np.array:
num_iter: = np.zeros(num_iter)
trajectory 0] = initial_value
trajectory[for i in range(num_iter-1):
+1] = logistic_function(parameter, initial_value)
trajectory[i= trajectory[i+1]
initial_value return np.array(trajectory)
=2.2, initial_value=0.8, num_iter=10) logistic_function_trajectory(parameter
array([0.8 , 0.352 , 0.5018112 , 0.54999278, 0.54450159,
0.54564314, 0.54541675, 0.5454621 , 0.54545303, 0.54545485])
= np.linspace(1, 200, 200)
xs = logistic_function_trajectory(parameter=2.2, initial_value=0.8, num_iter=200) ys
def plot_trajectory(xs, ys, x_label, y_label, title):
=(20,10))
plt.figure(figsize='o', edgecolor='black', c=point_colors * 50);
plt.scatter(xs, ys, marker;
plt.xlabel(x_label);
plt.ylabel(y_label);
plt.title(title); plt.grid()
= ['cyan', 'magenta', 'yellow', 'black'] point_colors
=xs, ys=ys, x_label='$n$', y_label='$x_n$', title='Trajectory') plot_trajectory(xs
\[r = 2\]
= logistic_function_trajectory(parameter=2.0, initial_value=0.2, num_iter=200)
x_n = logistic_function_trajectory(parameter=2.0, initial_value=0.200001, num_iter=200) x_n_hat
= abs(np.subtract(x_n, x_n_hat))
ys = np.linspace(1, 200, 200) xs
=xs, ys=ys, x_label='$n$', y_label='$ x_n - \hat{x_n} $', title='Trajectory for $r = 2$') plot_trajectory(xs
Plotting \(x_n - \hat{x_n}\) vs. \(n\) for \(r=3.4\)
= logistic_function_trajectory(parameter=3.4, initial_value=0.2, num_iter=200)
x_n = logistic_function_trajectory(parameter=3.4, initial_value=0.200001, num_iter=200)
x_n_hat
= abs(np.subtract(x_n, x_n_hat))
ys = np.linspace(1, 200, 200)
xs
=xs, ys=ys, x_label='$n$', y_label='$ x_n - \hat{x_n} $', title='Trajectory for $r = 3.4$') plot_trajectory(xs
We can thus plot the trajectories of the Logistic Map with Python and relevant libraries.
References
- https://en.wikipedia.org/wiki/Logistic_map
- Bradley, Liz: Nonlinear Dynamics: Mathematical and Computational Approaches via Complexity Explorer, Santa Fe Institute
Cite this Notebook:
@ONLINE {,
author = "Ritobrata Ghosh",
title = "Non Linear Dynamics Trajectories with Python",
month = "apr",
year = "2023",
url = "https://www.kaggle.com/truthr/non-linear-dynamics-trajectories-with-python"
}