import numpy as np
import matplotlib.pyplot as plt
The Lorenz Attractor
1 Differential Equation Non Linear Lorenz
Non Linear system of equations of the form
\[ \dot x=\sigma(y-x) \] \[ \dot y=rx-y-xz \] \[ \dot z=xy-bz \]
The environment required to ensure a replica run of this code is detailed at http://www.bunsen.site
def lorenz(x, y, z, s=10, r=28, b=2.667):
"""
Given:
x, y, z: a point of interest in three dimensional space
s, r, b: parameters defining the lorenz attractor
Returns:
x_dot, y_dot, z_dot: values of the lorenz attractor's partial
derivatives at the point x, y, z
"""
= s*(y - x)
x_dot = r*x - y - x*z
y_dot = x*y - b*z
z_dot return x_dot, y_dot, z_dot
= 0.01
dt = 10000
num_steps
# Need one more for the initial values
= np.empty(num_steps + 1)
xs = np.empty(num_steps + 1)
ys = np.empty(num_steps + 1) zs
# Set initial values
0], ys[0], zs[0] = (0., 1., 1.05) xs[
# Step through "time", calculating the partial derivatives at the current point
# and using them to estimate the next point
for i in range(num_steps):
= lorenz(xs[i], ys[i], zs[i])
x_dot, y_dot, z_dot + 1] = xs[i] + (x_dot * dt)
xs[i + 1] = ys[i] + (y_dot * dt)
ys[i + 1] = zs[i] + (z_dot * dt) zs[i
2 Plot
= plt.figure().add_subplot(projection='3d')
ax
=0.5)
ax.plot(xs, ys, zs, lw"X Axis")
ax.set_xlabel("Y Axis")
ax.set_ylabel("Z Axis")
ax.set_zlabel("Lorenz Attractor")
ax.set_title(
plt.show()
```