-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntro_educ_computing.py
More file actions
283 lines (211 loc) · 8.71 KB
/
Intro_educ_computing.py
File metadata and controls
283 lines (211 loc) · 8.71 KB
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
import numpy as _np
import matplotlib.pyplot as _plt
import scipy.integrate as _scyint
class Basic_kinematics():
def __init__(self, learning_level, v_0=None, s_0=None, time=None):
# Kinematics is a subject that requires some
if v_0 is None:
v0 = 10 # in Internatinal System of Units [m/s]
if s_0 is None:
s0 = 0 # in Internatinal System of Units [m]
if time is None:
t = _np.linspace(0, 50, 5000)
if 'infantil' in learning_level:
self._learn = 'infantil'
elif 'fundamental' in learning_level:
self._learn = 'fundamental'
elif 'médio' in learning_level:
self._learn = 'médio'
else:
self._learn = 'graduação'
if self._learn == 'graduação':
# _b when the force is proportional to velocity, this parameter is the drag_coefficient. It is well known as damping coefficient
# when studying the harmonic damped oscilator
self._b = 0.1 # in Internatinal System of Units [kg/s]
else:
# Forces proportional to velocity aren't a familiar theme for kids and undergraduated studants, so take it ease :),
# one day they will know about it, if it is their interest
self._b = 0
self._v_0 = v0
self._s_0 = s0
self._a = 0 # taking acceleration to be zero so the moviment of the body is an Uniform Motion
self._theta = None # this angle must be the angle of the oblique throwing
self._gravity = 10 # approximatly, [m/s^2] in International System of Units
self._time = t
self._space = _np.linspace(0,100, 10000) # this parameter is important when velocity can be described in terms of the space
self._frequency = 10000 # wheel's rotation
self._light_speed = 299792458 # in International System of Units [m/s]
self._sound_speed = 343 # in International System of Units [m/s]
self.frequency = None
self._reverb_time = 0.1 # [s]
self._mass = 10 # kg
self._force = None
@property
def v_0(self):
return self._v_0
@v_0.setter
def v_0(self, new_value):
self._v_0 = new_value
@property
def s_0(self):
return self._s_0
@s_0.setter
def v_0(self, new_value):
self._s_0 = new_value
@property
def acceleration(self):
return self._a
@acceleration.setter
def acceleration(self, new_value):
self._a = new_value
@property
def theta(self):
if self._theta is None:
self._theta = _np.pi/4 # If u ask me why I chose this angle, keep in mind that it keep an important property in an oblique throw.
# Hint: compare the distance traveled by a particle thrown by an angle of pi/6 and pi/3
return self._theta
@theta.setter
def theta(self, new_value):
self._theta = new_value
@property
def gravity(self):
return self._gravity
@gravity.setter
def gravity(self, new_value): # user could set the value of the gravity if is desired travel to another planet :O
self._theta = new_value
@property
def drag_coef(self):
return self._b
@drag_coef.setter
def drag_coef(self, new_value):
if 'graduation' in self._learn:
self._b = new_value
else:
print('O educador poderá te auxiliar a obter informações sobre este assunto! \n Não tenha medo de perguntar, divirta-se!')
@property
def time(self):
return self._time
@time.setter
def time(self, time_range, nsteps):
t = _np.linspace(0,time_range, nsteps)
self._time = t
@property
def light_speed(self):
return self._light_speed
@property
def sound_speed(self):
return self._sound_speed
@property
def space(self):
return self._space
@space.setter
def space(self, new_intial_bound,new_space, nsteps):
spc = _np.linspace(new_intial_bound, new_space, nsteps)
self._space = spc
@property
def mass(self):
return self._mass
@mass.setter
def mass(self, new_value):
self._mass = new_value # forneça a massa em unidades do SI
@property
def force(self):
if self._force is None:
self._force = self._mass * self._a
return self._force
@force.setter
def force(self, new_value):
self._force = new_value
def seno(self):
return _np.sin(self._time)
def exp(self):
return _np.exp(self.time)
def quadratica(self, posicao_0, speed_0, acceleration_0):
s_position = posicao_0
s_position += speed_0 * self._time
s_position += 1/2 * acceleration_0 * self._time ** 2
return s_position
def line(self, posicao_0, speed_0):
s_position = posicao_0
s_position+= speed_0 * self._time
return s_position
def graficos_para_EM(self, acceleration_0, speed_0, posicao_0):
# como este é um método estático não é necessário criar estruturas
# de decisão para diferenciar as diferentes formas de movimento
fig, (a1,a2,a3) = _plt.subplots(nrows=1, ncols=3, figsize=(10,5))
time = self._time
s_position = posicao_0
s_position += speed_0 * time
s_position += 1/2 * acceleration_0 * time ** 2
speed = speed_0
speed += acceleration_0 * time
acceleration = acceleration_0 * _np.ones(time.size)
a1.set_title(r'Posição $\times$ tempo', fontsize=16)
a1.set_ylabel(r'S [$m$]', fontsize=14)
a1.set_xlabel(r'tempo [$s$]', fontsize=14)
a1.grid(True, alpha=0.5, ls='--', color='k')
a1.tick_params(axis='both', labelsize=12)
a2.set_title(r'Velocidade $\times$ tempo', fontsize=16)
a2.set_ylabel(r'v [$m/s$]', fontsize=14)
a2.set_xlabel(r'tempo [$s$]', fontsize=14)
a2.grid(True, alpha=0.5, ls='--', color='k')
a2.tick_params(axis='both', labelsize=12)
a3.set_title(r'Aceleração $\times$ tempo', fontsize=16)
a3.set_ylabel(r'a [$m/s^{2}$]', fontsize=14)
a3.set_xlabel(r'tempo [$s$]', fontsize=14)
a3.grid(True, alpha=0.5, ls='--', color='k')
a3.tick_params(axis='both', labelsize=12)
a1.plot(time, s_position, label='calma_mat')
a1.legend()
a2.plot(time, speed, label='calma_mat')
a2.legend()
a3.plot(time, acceleration, label='calma_mat')
a3.legend()
return
def creat_dict(self):
dic = {}
dic['seno'] = self.seno()
dic['exp'] = self.exp()
dic['quadratico'] = self.quadratica(-6,-1,2)
dic['reta'] = self.line(5, 2)
return dic
def plotar_intersec(self, name1, name2):
dic = self.creat_dict()
array_pos_1 = dic['name1']
array_pos_2 = dic['name2']
fig, ax = _plt.subplots(figsize=(10,5))
time = self._time
ax.set_title('Intersecção entre as posições de duas partículas', fontsize=16)
ax.plot(time, array_pos_1, label=r'$s_{1}$')
ax.plot(time, array_pos_2, label=r'$s_{2}$')
ax.set_ylabel(r'posição das partículas [m]', fontsize=14)
ax.set_xlabel(r'tempo [s]', fontsize=14)
ax.grid(True, alpha=0.5, ls='--', color='k')
ax.tick_params(axis='both', labelsize=12)
ax.tight_layout()
# depois criar as funções para determinar quanto tempo o som ou a luz demoram para percorrer determinada distancia
# caso o aluno tenha curiosidade o computador pode fazer isso em segundos
def time_sordis(self,sound_or_light, echos=None, time=None, dis=None):
if 'light' in sound_or_light:
v = self._light_speed
elif 'sound' in sound_or_light:
v = self._sound_speed
if time is None and dis is None:
print('defina ao menos o tempo ou a distancia como sendo diferente de None')
return
elif dis is None:
d = v * time
resul = d
elif time is None:
t = dis / v
resul = t
if (echos is True) and ('sound' in sound_or_light):
# 1/2 factor comes because to listen to the sound echo, the sound must
# travel the distance between the obstacle and you two times
dminfor_echos = 1/2 * v * self._reverb_time
elif echos is None:
return resul
else:
print('Só faz sentido falar em eco definindo os parâmetros echos como True e sound_or_light como sound')
return resul
return resul, dminfor_echos