-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracer_de_mode
160 lines (134 loc) · 6.88 KB
/
tracer_de_mode
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#-utf-8
import numpy as np
from scipy.optimize import curve_fit
from matplotlib import pyplot as plt
from matplotlib.mlab import frange
import numpy, scipy, pylab, random
#cste = float(input("Entrer la constante de rappel des ressorts: "))
cste=6.8
#nombre = float(input("Entrer le nombre de masse dans le système: "))
nombre=5
#masse = float(input("Entrer la masse moyenne: "))
masse=0.4115
mode = float(input("Entrer le mode: "))
chaine = input("Entrer le type de chaine (H:homogène, I:inhomogène) :")
#a = float(input("Entrer la distance a entre deux masses: "))
a=0.3875
L = 6*a
k = (mode*np.pi)/((nombre+1)*a)
w = 2*np.sqrt(cste/masse)*np.sin(k*a/2)
gamma = k*nombre*a
print("L vaut: ", L)
print("Gamma vaut :", gamma)
print("k vaut:" ,k)
print("Omega vaut", w)
# définition des tableaux numpy contenant les données en x et en y
x = np.linspace(0,L,1000)
y = 0.3*np.sin(mode*np.pi*x/L)
xn = frange(0, L, a)
yn = 0*xn
y2 = 0.3*np.sin(mode*2*np.pi*x/L)
y3 = 0.3*np.sin(mode*3*np.pi*x/L)
y4 = 0.3*np.sin(mode*4*np.pi*x/L)
y5 = 0.3*np.sin(mode*5*np.pi*x/L)
arrow = {'facecolor':'black', 'shrink':0.05, 'width':1, 'headwidth':5}
arrow2 = {'facecolor':'white', 'edgecolor':'green','shrink':0.05, 'width':1, 'headwidth':5}
if (chaine == 'H' or chaine == 'h' ) :
fig, axes = plt.subplots(nrows=5, figsize=(20/2.54, 15/2.54), sharex= True, sharey = True)
axes[0].plot(x,y)
axes[0].plot(xn,yn,'ro')
axes[0].set_ylabel( r'$m=1$' )
axes[0].annotate('', xy=(0.395,-0.25), xytext=(0.38,-0.25),arrowprops=arrow)
axes[0].annotate('', xy=(0.85,-0.25), xytext=(0.7,-0.25),arrowprops=arrow)
axes[0].annotate('', xy=(1.325,-0.25), xytext=(1,-0.25),arrowprops=arrow)
axes[0].annotate('', xy=(1.625,-0.25), xytext=(1.475,-0.25),arrowprops=arrow)
axes[0].annotate('', xy=(1.945,-0.25), xytext=(1.93,-0.25),arrowprops=arrow)
axes[1].plot(x,y2,'r')
axes[1].plot(xn,yn,'ro')
axes[1].set_ylabel( r'$m=2$' )
axes[1].annotate('', xy=(0.395,-0.25), xytext=(0.38,-0.25),arrowprops=arrow)
axes[1].annotate('', xy=(0.85,-0.25), xytext=(0.7,-0.25),arrowprops=arrow)
axes[1].annotate('', xy=(1.475,0.25), xytext=(1.625,0.25),arrowprops=arrow)
axes[1].annotate('', xy=(1.93,0.25), xytext=(1.945,0.25),arrowprops=arrow)
axes[2].plot(x,y3,'M')
axes[2].plot(xn,yn,'ro')
axes[2].set_ylabel( r'$m=3$' )
axes[2].annotate('', xy=(0.395,-0.25), xytext=(0.38,-0.25),arrowprops=arrow)
axes[2].annotate('', xy=(1,0.25), xytext=(1.325,0.25),arrowprops=arrow)
axes[2].annotate('', xy=(1.945,-0.25), xytext=(1.93,-0.25),arrowprops=arrow)
axes[3].plot(x,y4,'g')
axes[3].plot(xn,yn,'ro')
axes[3].set_ylabel( r'$m=4$' )
axes[3].annotate('', xy=(0.395,-0.25), xytext=(0.38,-0.25),arrowprops=arrow)
axes[3].annotate('', xy=(0.7,0.25), xytext=(0.85,0.25),arrowprops=arrow)
axes[3].annotate('', xy=(1.625,-0.25), xytext=(1.475,-0.25),arrowprops=arrow)
axes[3].annotate('', xy=(1.93,0.25), xytext=(1.945,0.25),arrowprops=arrow)
axes[4].plot(x,y5,'k')
axes[4].plot(xn,yn,'ro')
axes[4].set_ylabel( r'$m=5$' )
axes[4].annotate('', xy=(0.395,-0.25), xytext=(0.38,-0.25),arrowprops=arrow)
axes[4].annotate('', xy=(0.7,0.25), xytext=(0.85,0.25),arrowprops=arrow)
axes[4].annotate('', xy=(1.325,-0.25), xytext=(1,-0.25),arrowprops=arrow)
axes[4].annotate('', xy=(1.475,0.25), xytext=(1.625,0.25),arrowprops=arrow)
axes[4].annotate('', xy=(1.945,-0.25), xytext=(1.93,-0.25),arrowprops=arrow)
fig.subplots_adjust(hspace=0)
plt.xlim(0, L)
plt.ylim(-0.5, 0.5)
plt.setp([a.get_xticklabels() for a in fig.axes[0:5]], visible=False)
plt.setp([a.get_yticklabels() for a in fig.axes[0:5]], visible=False)
plt.xlabel(r'$\leftarrow \hspace{12} $' 'L' r'$\hspace{12} \rightarrow$')
if (chaine == 'I' or chaine == 'i' ) :
fig, axes = plt.subplots(nrows=4, figsize=(20/2.54, 12/2.54), sharex= True, sharey = True)
axes[0].plot(x,y)
axes[0].plot(xn,yn,'ro')
axes[0].set_ylabel( r'$m=1$' )
axes[0].annotate('', xy=(0.38,-0.35), xytext=(0.395,-0.35),arrowprops=arrow2)
axes[0].annotate('', xy=(0.7,-0.35), xytext=(0.85,-0.35),arrowprops=arrow2)
axes[0].annotate('', xy=(1,-0.35), xytext=(1.325,-0.35),arrowprops=arrow2)
axes[0].annotate('', xy=(1.475,-0.35), xytext=(1.625,-0.35),arrowprops=arrow2)
axes[0].annotate('', xy=(1.93,-0.35), xytext=(1.945,-0.35),arrowprops=arrow2)
axes[0].annotate('', xy=(0.395,-0.20), xytext=(0.38,-0.20),arrowprops=arrow)
axes[0].annotate('', xy=(0.85,-0.20), xytext=(0.7,-0.20),arrowprops=arrow)
axes[0].annotate('', xy=(1.325,-0.20), xytext=(1,-0.20),arrowprops=arrow)
axes[0].annotate('', xy=(1.625,-0.20), xytext=(1.475,-0.20),arrowprops=arrow)
axes[0].annotate('', xy=(1.945,-0.20), xytext=(1.93,-0.20),arrowprops=arrow)
axes[1].plot(x,y2,'r')
axes[1].plot(xn,yn,'ro')
axes[1].set_ylabel( r'$m=2$' )
axes[1].annotate('', xy=(0.395,-0.20), xytext=(0.38,-0.20),arrowprops=arrow)
axes[1].annotate('', xy=(0.85,-0.20), xytext=(0.7,-0.20),arrowprops=arrow)
axes[1].annotate('', xy=(1.475,0.20), xytext=(1.625,0.20),arrowprops=arrow)
axes[1].annotate('', xy=(1.93,0.20), xytext=(1.945,0.20),arrowprops=arrow)
axes[1].annotate('', xy=(0.38,-0.35), xytext=(0.395,-0.35),arrowprops=arrow2)
axes[1].annotate('', xy=(0.7,-0.35), xytext=(0.85,-0.35),arrowprops=arrow2)
axes[1].annotate('', xy=(1.625,0.35), xytext=(1.475,0.35),arrowprops=arrow2)
axes[1].annotate('', xy=(1.945,0.35), xytext=(1.93,0.35),arrowprops=arrow2)
axes[2].plot(x,y3,'M')
axes[2].plot(xn,yn,'ro')
axes[2].set_ylabel( r'$m=3$ (acc)' )
axes[2].annotate('', xy=(0.395,-0.25), xytext=(0.38,-0.25),arrowprops=arrow)
axes[2].annotate('', xy=(1,0.25), xytext=(1.325,0.25),arrowprops=arrow)
axes[2].annotate('', xy=(1.945,-0.25), xytext=(1.93,-0.25),arrowprops=arrow)
axes[3].plot(x,y3,'k')
axes[3].plot(xn,yn,'ro')
axes[3].set_ylabel( r'$m=3$ (opt)' )
axes[3].annotate('', xy=(0.38,-0.25), xytext=(0.395,-0.25),arrowprops=arrow2)
axes[3].annotate('', xy=(1.325,0.25), xytext=(1,0.25),arrowprops=arrow2)
axes[3].annotate('', xy=(1.93,-0.25), xytext=(1.945,-0.25),arrowprops=arrow2)
fig.subplots_adjust(hspace=0)
plt.xlim(0, L)
plt.ylim(-0.5, 0.5)
plt.setp([a.get_xticklabels() for a in fig.axes[0:4]], visible=False)
plt.setp([a.get_yticklabels() for a in fig.axes[0:4]], visible=False)
plt.xlabel(r'$\leftarrow \hspace{12} $' 'L' r'$\hspace{12} \rightarrow$')
#plt.plot(x,y)
#plt.plot(x2,y2,'ro')
#plt.annotate('m=1', xy=(0,1), xytext=(1.3,10))
#plt.annotate('m=1', xy=(0,1), xytext=(1,1.3))
#plt.annotate('m=2', xy=(0,1), xytext=(2.8,3.5))
#plt.annotate('m=2', xy=(0,1), xytext=(2.8,9))
#plt.annotate('m=3', xy=(0,1), xytext=(4,4.6))
#plt.annotate('m=3', xy=(0,1), xytext=(4,8.5))
plt.show
nom_graph = input ("Entrer le nom du graphique :")
plt.savefig(nom_graph+'.pdf')