Reputation: 47
I have 3 equations as follows
u'= -a*(u-v)
v'= c*u-v-u*w
w'= -b*w+u*v
a=5.0 b=0.9 and c=8.2
Im trying to use scipy.integrate.odeint solve from t=0 to t=10 My initial conditions are u(0)=0, v(0)=1.0 and w(0)=2.0 I can't many useful notes on scipy.integrate.odeint. So could use some advice on using this module for my problem.
Upvotes: 0
Views: 723
Reputation: 25508
scipy.integrate.odeint takes a function to integrate, initial values for the dependent variables (your u
, v
, an w
) and a grid of time values. Any extra arguments that your function needs (such as a
, b
and c
) are passed as args
.
The function you define should take a vector of values, say, X
, (which you can unpack to u
, v
and w
), the time point they correspond to, and any additional arguments, and should return the first derivatives of X
with respect to time at that time point.
Visualising the Lorenz attractor is a subject of one of the Matplotlib gallery examples.
import numpy as np
from scipy.integrate import odeint
a, b, c = 5, 0.9, 8.2
u0, v0, w0 = 0, 1, 2
def lorenz(X, t, a, b, c):
u, v, w = X
up = -a*(u - v)
vp = c*u - v - u*w
wp = -b*w + u*v
return up, vp, wp
t = np.linspace(0, 100, 10000)
f = odeint(lorenz, (u0, v0, w0), t, args=(a, b, c))
x, y, z = f.T
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot(x, y, z)
ax.set_xlabel("X Axis")
ax.set_ylabel("Y Axis")
ax.set_zlabel("Z Axis")
ax.set_title("Lorenz Attractor")
plt.show()
Upvotes: 1