1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| import numpy as np import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d as p3d
''' Chen吸引子生成函数 参数为三个初始坐标,三个初始参数,迭代次数 返回三个一维数组(坐标) ''' def Chen(x0,y0,z0,a,b,c,T): h=0.001 x=[] y=[] z=[] for t in range(T): xt=x0+h*(a*(y0-x0)) yt=y0+h*((c-a)*x0-x0*z0+c*y0) zt=z0+h*(x0*y0-b*z0)
x0,y0,z0=xt,yt,zt x.append(x0) y.append(y0) z.append(z0)
return x,y,z
def main(): a=35 b=3 c=28 T=10000 x0=0 y0=1 z0=0 x,y,z=Chen(x0,y0,z0,a,b,c,T) ax=plt.subplot(121,projection="3d") ax.scatter(x,y,z,s=5) ax.set_xlabel('x(t)') ax.set_ylabel('y(t)') ax.set_zlabel('z(t)') ax.set_title('x0={0} y0={1} z0={2}'.format(x0,y0,z0))
ax.grid(False) x0=0 y0=1.001 z0=0 xx,yy,zz=Chen(x0,y0,z0,a,b,c,T) ax=plt.subplot(122,projection="3d") ax.scatter(xx,yy,zz,s=5) ax.set_xlabel('x(t)') ax.set_ylabel('y(t)') ax.set_zlabel('z(t)') ax.set_title('x0={0} y0={1} z0={2}'.format(x0,y0,z0)) ax.grid(False) plt.show()
t=np.arange(0,T) plt.scatter(t,x,s=1) plt.scatter(t,xx,s=1) plt.show()
if __name__=='__main__': main()
|