Skip to content

Instantly share code, notes, and snippets.

@yoavram
Created March 14, 2016 06:11
Show Gist options
  • Save yoavram/a59bc3b40a4db81a1f78 to your computer and use it in GitHub Desktop.
Save yoavram/a59bc3b40a4db81a1f78 to your computer and use it in GitHub Desktop.
Simulate the Lorentz system using NumPy and SciPy
import matplotlib.pyplot as plt
import numpy as np
from scipy.integrate import odeint
import seaborn as sns
def dvdt(v, t, alpha, rho, beta):
x, y, z = v
return alpha * (y - x), x * (rho - z) - y, x * y - beta * z
alpha = 10
rho = 28
beta = 8/3
t = np.linspace(0, 4, 1000)
v0 = [1, 1, 1]
v = odeint(dvdt, v0, t, (alpha, rho, beta))
fig, ax = plt.subplots(4, 1, sharex=False, sharey=False, figsize=(10, 20))
ax[0].plot(t, v[:, 0])
ax[0].plot(t, v[:, 1])
ax[0].plot(t, v[:, 2])
ax[0].set(xlabel='Time', ylabel='Displacement')
ax[1].plot(v[:,0], v[:,1])
ax[1].set(xlabel='Displacement in x', ylabel='Displacement in y')
ax[2].plot(v[:,1], v[:,2])
ax[2].set(xlabel='Displacement in y', ylabel='Displacement in z')
ax[3].plot(v[:,0], v[:,2])
ax[3].set(xlabel='Displacement in x', ylabel='Displacement in z')
sns.despine()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment