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
| import numpy as np import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d as p3d
''' Rossler吸引子生成函数 参数为三个初始坐标,四个初始参数,迭代次数 返回三个一维数组(坐标) ''' def Rossler(x0,y0,z0,w,p,q,r,T): h=0.01 x=[] y=[] z=[] for t in range(T): xt=x0+h*(-w*y0-z0) yt=y0+h*(w*x0+p*y0) zt=z0+h*(q+z0*(x0-r))
x0,y0,z0=xt,yt,zt x.append(x0) y.append(y0) z.append(z0) return x,y,z
def main(): w=1 p=0.165 q=0.2 r=10 T=20000 x0=1 y0=0 z0=0 x,y,z=Rossler(x0,y0,z0,w,p,q,r,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=1 y0=0 z0=0') ax.grid(False) x0=1 y0=0 z0=0.00001 xx,yy,zz=Rossler(x0,y0,z0,w,p,q,r,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=1 y0=0 z0=0.00001') 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()
|
v1.5.2