Created
March 14, 2016 06:11
-
-
Save yoavram/a59bc3b40a4db81a1f78 to your computer and use it in GitHub Desktop.
Simulate the Lorentz system using NumPy and SciPy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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