Simulating Rössler attractor and the Lorenz attractor
The Lorenz system is chaotic dynamical system described by a set of three coupled ordinary differential equations, and it exhibits unpredictable behavior over time.
Make sure you have the required dependencies installed. You can install them using:
pip install numpy scipy matplotlib
The code is organized into three main functions:
Defines the Lorenz system of differential equations. Parameters: t: Time variable. xyz: Current state vector [x, y, z]. sigma, rho, beta: System parameters. Returns the rate of change of each variable.
Uses SciPy's solve_ivp to numerically solve the Lorenz system. Parameters: sigma, rho, beta: System parameters. initial_conditions: Initial values for [x, y, z]. t_span: Time span for simulation. num_points: Number of points for time discretization. Returns time values and the state trajectory.
Plots the Lorenz attractor in 3D using Matplotlib. Uses a rainbow color map to add visual appeal. Parameters: t: Time values. xyz: State trajectory.
if __name__ == "__main__":
# Set parameters and initial conditions
sigma = 10
rho = 28
beta = 8/3
initial_conditions = [0, 1, 20]
# Simulate Lorenz attractor
t, xyz = simulate_lorenz(sigma, rho, beta, initial_conditions)
# Plot colorful Lorenz attractor
plot_lorenz_attractor(t, xyz)
-
Run the script by executing the following command:
python lorenz_attractor.py
-
The script will simulate the Lorenz attractor and display a 3D plot with rainbow-colored trajectories.
Feel free to experiment with different parameters and initial conditions to observe the impact on the Lorenz attractor's behavior.
The Rössler system is described by three coupled nonlinear differential equations that exhibit chaotic behavior characterized by interesting trajectories in three-dimensional space.
The code consists of three main functions:
-
rossler_attractor(t, xyz, a, b, c):
- Defines the Rössler system of differential equations.
- Parameters:
t
: Time variable.xyz
: Current state vector [x, y, z].a
,b
,c
: System parameters.
- Returns the rate of change of each variable.
-
simulate_rossler_attractor(a, b, c, initial_conditions, t_span, num_points):
- Uses SciPy's
solve_ivp
to numerically solve the Rössler system. - Parameters:
a
,b
,c
: System parameters.initial_conditions
: Initial values for [x, y, z].t_span
: Time span for simulation.num_points
: Number of points for time discretization.
- Returns time values and the state trajectory.
- Uses SciPy's
-
plot_rossler_attractor(t, xyz):
- Plots the Rössler attractor in 3D using Matplotlib.
- Uses a rainbow color map to add visual appeal.
- Parameters:
t
: Time values.xyz
: State trajectory.
- Set the parameters and initial conditions in the
__main__
block. - Run the script.
- The simulation results are displayed in a 3D plot showing the evolution of the Rössler attractor over time.
numpy
: For numerical operations.scipy
: For solving differential equations usingsolve_ivp
.matplotlib
: For creating 3D visualizations.
if __name__ == "__main__":
# Set parameters for the Rössler attractor
a = 0.2
b = 0.2
c = 5.7
# Set initial conditions
initial_conditions = [0.1, 0.0, 0.0]
# Simulate Rössler attractor
t, xyz = simulate_rossler_attractor(a, b, c, initial_conditions)
# Plot colorful Rössler attractor
plot_rossler_attractor(t, xyz)
Feel free to experiment with different parameter values and initial conditions to observe the impact on the Rössler attractor's behavior. Contributions and improvements are welcome!