Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. from numpy import *
  2. from matplotlib import *
  3. from scipy import *
  4. from pylab import *
  5. from mpl_toolkits.mplot3d import *
  6. import scipy as sp
  7.  
  8. #We define a function which is going to be the recursive function.
  9. def tamari(x_t,y_t,z_t,h,a,b,c,d,e,f,g,u,i):
  10. dx_t=x_t+h*((x_t- a*y)*sp.cos(z_t) - b*y_t*sp.sin(z_t))
  11. dy_t=y_t+h*(sp.sin(z_t)*(c*y_t + x_t) + d*y_t*sp.cos(z_t))
  12. dz_t=z_t+h*(e + f*z_t + g*sp.arctan(((1-u)/(1-i))*(x_t*y_t)))
  13. return dx_t,dy_t,dz_t
  14.  
  15. #parametri
  16. a=1.013
  17. b=-0.011
  18. c=0.02
  19. d = 0.96
  20. e = 0
  21. f = 0.01
  22. g = 1
  23. u = 0.05
  24. i = 0.05
  25.  
  26. #Definisco un rapporto incrementale lim h->0 di (t_finale -t_iniziale)/h
  27. t_iniz=0
  28. t_fin=100
  29. h=0.0001
  30. numsteps=int((t_fin-t_iniz)/h)
  31.  
  32. #using this parameters we build the time.
  33. t=linspace(t_iniz,t_fin,numsteps)
  34. #And the vectors for the solutions
  35. x=zeros(numsteps)
  36. y=zeros(numsteps)
  37. z=zeros(numsteps)
  38.  
  39. #We set the initial conditions
  40. x[0]=0
  41. y[0]=0
  42. z[0]=0
  43.  
  44. #Trange in size -1 perchè la prima condizione imposta è quella iniziale
  45. for k in range(x.size-1):
  46. #We use the previous point to generate the new point using the recursion
  47. [x[k+1],y[k+1],z[k+1]]=tamari(x[k],y[k],z[k],t[k+1]-t[k],a,b,c,d,e,f,g,u,i)
  48.  
  49. #Now that we have the solution in vectors t,x,y,z is time to plot them.
  50.  
  51. #We create a figure and 4 axes on it. 3 of the axes are going to be 2D and the fourth one is a 3D plot.
  52.  
  53. fig = figure()
  54. ax1 = fig.add_axes([0.1, 0.7, 0.4, 0.2])
  55. ax2 = fig.add_axes([0.1, 0.4, 0.4, 0.2])
  56. ax3 = fig.add_axes([0.1, 0.1, 0.4, 0.2])
  57. ax4 = fig.add_axes([0.55, 0.25, 0.35, 0.5],projection='3d')
  58.  
  59. #And we add vectors to each plot
  60.  
  61. #grafico x,y,z, attrattore
  62. ax1.plot(t, x,color='green',label='x(t)')
  63. ax1.set_xlabel('t')
  64. ax1.legend()
  65. ax1.axis((t_iniz,t_fin,min(x),max(x)))
  66.  
  67. ax2.plot(t, y,color='orange',label='y(t)')
  68. ax2.set_xlabel('t')
  69. ax2.legend()
  70. ax2.axis((t_iniz,t_fin,min(y),max(y)))
  71.  
  72. ax3.plot(t, z,color='blue',label='z(t)')
  73. ax3.set_xlabel('t')
  74. ax3.legend()
  75. ax3.axis((t_iniz,t_fin,min(z),max(z)))
  76.  
  77. ax4.plot(x, y,z,color='black')
  78. ax4.set_xlabel('x(t)')
  79. ax4.set_ylabel('y(t)')
  80. ax4.set_zlabel('z(t)')
  81. ax4.set_title('Attrattore di Tamari')
  82.  
  83.  
  84. show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement