• API
• FAQ
• Tools
• Archive
daily pastebin goal
88%
SHARE
TWEET

# Untitled

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

Top