import os
import matplotlib.pyplot as plt
from numpy import linspace
from scipy.integrate import odeint
os.chdir(r'D:\projects\wordpress\ex340')
os.getcwd()
sigma=10.0
b=8/3.0
r=28.0
f = lambda x,t: [sigma*(x[1]-x[0]), r*x[0]-x[1]-x[0]*x[2], x[0]*x[1]-b*x[2]]
t=linspace(0,20,2000)
y0=[5.0,5.0,5.0]
solution=odeint(f,y0,t)
X=solution[:,0]; Y=solution[:,1]; Z=solution[:,2]
plt.subplot(projection='3d')
plt.plot(X,Y,Z)
plt.xlabel('x')
plt.ylabel('y')
plt.savefig("ex340_a.png", dpi=100)
plt.show()
plt.rcParams['figure.figsize'] = (10.0, 5.0)
plt.subplot(121)
plt.plot(t,Z)
plt.xlabel('t')
plt.ylabel('Z')
plt.subplot(122)
plt.plot(Y,Z)
plt.xlabel('Y')
plt.ylabel('Z')
plt.savefig("ex340_b.png", dpi=100)
plt.show()
plt.close()
Like this:
Like Loading...
Related
Recent Comments