A comprehensive Python implementation of the famous Lorenz equations that demonstrates chaos theory through interactive visualizations and animations.
The Lorenz attractor is a set of chaotic solutions to the Lorenz system of differential equations, discovered by Edward Lorenz in 1963. It's one of the most famous examples of chaos theory and demonstrates how small changes in initial conditions can lead to vastly different outcomes - the so-called "butterfly effect."
The system models simplified atmospheric convection and is described by three coupled differential equations:
dx/dt = σ(y - x)
dy/dt = x(ρ - z) - y
dz/dt = xy - βz
Where:
- σ (sigma) = Prandtl number (ratio of viscosity to thermal diffusivity)
- ρ (rho) = Rayleigh number (ratio of buoyancy to viscous forces)
- β (beta) = Geometric factor (related to aspect ratio of convection cells)
pip install -r requirements.txt
Run the program:
python lorenz_attractor.py
The system uses the 4th-order Runge-Kutta method (RK4) for solving the differential equations:
k1 = h * f(yn, tn)
k2 = h * f(yn + k1/2, tn + h/2)
k3 = h * f(yn + k2/2, tn + h/2)
k4 = h * f(yn + k3, tn + h)
yn+1 = yn + (k1 + 2*k2 + 2*k3 + k4) / 6
This provides 4th-order accuracy and excellent stability for chaotic systems.
- σ = 10.0: Standard Prandtl number
- ρ = 28.0: Rayleigh number (above critical value ~24.74 for chaos)
- β = 8/3 ≈ 2.667: Geometric factor from Lorenz's original paper
- Initial conditions: (1.0, 1.0, 1.0)
- Time step: 0.01 (adjustable)
- Butterfly Effect Animation:
- Compares trajectories starting at (1,1,1) and (1,1,1.001)
- Shows complete trajectory history (no trailing erasure)
- Displays real-time distance between trajectories
- Fast animation with 10ms frame intervals
- Sensitive Dependence on Initial Conditions: Tiny differences (0.001) grow exponentially
- Strange Attractor: Non-periodic, bounded trajectories
- Deterministic Chaos: Predictable equations producing unpredictable behavior
- Fractal Geometry: Self-similar structure at different scales
- ρ < 1: System decays to origin
- 1 < ρ < 24.74: Stable fixed points (periodic)
- ρ > 24.74: Chaotic behavior begins
- ρ = 28: Classic chaotic regime
# Create custom Lorenz system
lorenz = LorenzAttractor(sigma=15.0, rho=35.0, beta=3.0)
# Simulate with different conditions
initial_state = np.array([2.0, 3.0, 4.0])
t, trajectory = lorenz.simulate(initial_state, t_span=100, dt=0.005)
- Decrease
interval
parameter for faster animation - Increase
dt
for larger time steps - Modify frame skipping in animation functions
- Adjust
linewidth
for thicker/thinner lines - Change
alpha
for transparency effects - Modify
markersize
for point sizes - Customize colors and styles
- Memory Usage: Scales with simulation time and time step
- Computation Time: RK4 method provides good accuracy/speed balance
- Animation Performance: Optimized with frame skipping and efficient updates
- Large Simulations: Consider increasing
dt
for very long time spans