def Triple(): ''' Realiza una animacion del pendulo triple. Permite elegir parametros iniciales con sliders. ''' # Se genera la ventana de sliders para seleccionar los parametros iniciales con func_sliders button, reset_func, sliders = fs.sliders_window(fs.triple) button.on_clicked(reset_func) plt.show() # Se toman los valores iniciales desde los sliders g, m1, m2, m3, L1, L2, L3, w1, w2, w3, th1, th2, th3 = [slider.val for slider in sliders] th1 = np.radians(th1) th2 = np.radians(th2) th3 = np.radians(th3) ctes = g, m1, m2, m3, L1, L2, L3 # Se crean las barras y las esferas a partir de los datos iniciales xy1 = vector(L1 * np.sin(th1), - L1 *np.cos(th1), 0) xy2 = vector(L2 * np.sin(th2), - L2 *np.cos(th2), 0) xy3 = vector(L3 * np.sin(th3), - L3 *np.cos(th3), 0) rb = L1/50 re1 = L1 / 10 * np.sqrt(m1) re2 = L1 / 10 * np.sqrt(m2) re3 = L1 / 10 * np.sqrt(m3) barra1 = cylinder(pos=vector(0, 0, 0), axis=xy1, radius=rb) esfera1 = sphere(pos=xy1, radius=re1, color = vector(1,0,0), make_trail = True) barra2 = cylinder(pos=xy1, axis=xy2, radius=rb) esfera2 = sphere(pos=xy1 + xy2, radius=re2, color = vector(0,1,0), make_trail = True) barra3 = cylinder(pos=xy1 + xy2, axis=xy3, radius=rb) esfera3 = sphere(pos=xy1 + xy2 + xy3, radius=re3, color = vector(0,0,1), make_trail = True) # Se establece el intervalo temporal dt = 1e-3 # Se realiza un bucle infinito para visualizar la animacion while True: # Se establece el ratio de frames rate(1e3) # Se actualizan posicion y velocidad por metodo numerico th, w = paso(ode.a_triple, dt, [th1,th2,th3], [w1,w2,w3], ctes) th1, th2, th3 = th; w1, w2, w3 = w # Se actualizan la posiciones de las esferas y las barras xy1 = vector(L1 * np.sin(th1), - L1 *np.cos(th1), 0) xy2 = vector(L2 * np.sin(th2), - L2 *np.cos(th2), 0) xy3 = vector(L3 * np.sin(th3), - L3 *np.cos(th3), 0) esfera1.pos = xy1 esfera2.pos = xy1 + xy2 esfera3.pos = xy1 + xy2 + xy3 barra1.axis = xy1 barra2.pos = xy1 barra2.axis = xy2 barra3.pos = xy1 + xy2 barra3.axis = xy3
def Triple(): ''' Proceso que realiza una representacion grafica de niveles energeticos del pendulo triple. Permite elegir parametros iniciales con sliders. ''' # Se genera la ventana de sliders para seleccionar los parametros iniciales con func_sliders button, reset_func, sliders = fs.sliders_window( np.array(fs.triple)[:-2, :].tolist()) button.on_clicked(reset_func) plt.show() # Se toman los valores iniciales desde los sliders g, m1, m2, m3, L1, L2, L3, w1, w2, w3, th1 = [ slider.val for slider in sliders ] # Se generan arrays para las variables th2 = np.linspace(-np.pi, np.pi, 1000) th3 = np.linspace(-np.pi, np.pi, 1000) # Se realiza un np.meshgrid de las variables que nos servira para calcular la energia en cada punto TH2, TH3 = np.meshgrid(th2, th3) # Energia del pendulo triple E = (m1 + m2 + m3) * L1**2 * w1**2 / 2 + ( m2 + m3 ) * L2**2 * w2**2 / 2 + m3 * L3**2 * w3**2 / 2 + (m2 + m3) * L1 * L2 * abs( w1) * abs(w2) * np.cos(TH2 - th1) + m3 * L3 * abs(w3) * ( L1 * abs(w1) * np.cos(TH3 - th1) + L2 * abs(w2) * np.cos(TH3 - TH2)) - g * ( (m1 + m2 + m3) * L1 * np.cos(th1) + (m2 + m3) * L2 * np.cos(TH2) + m3 * L3 * np.cos(TH3)) + g * ( (m1 + m2 + m3) * L1 + (m2 + m3) * L2 + m3 * L3) # Se crean la figura y los axes fig, ax = plt.subplots() # Se toman los niveles de energia que distinguira la representacion desde 0 hasta la energia maxima posible nivel = np.linspace( 0, (m1 + m2 + m3) * L1**2 * w1**2 / 2 + (m2 + m3) * L2**2 * w2**2 / 2 + m3 * L3**2 * w3**2 / 2 + (m2 + m3) * L1 * L2 * abs(w1) * abs(w2) + m3 * L3 * abs(w3) * (L1 * abs(w1) + L2 * abs(w2)) + g * ((m1 + m2 + m3) * L1 + (m2 + m3) * L2 + m3 * L3) + g * ((m1 + m2 + m3) * L1 + (m2 + m3) * L2 + m3 * L3), 40) # Se usa Fases para realizar la representacion Fases(fig, ax, th2, th3, E, nivel, 'E (J)') # Se detalla informacion sobre la representacion set_angle_label(ax, 'x', r'\theta_2') set_angle_label(ax, 'y', r'\theta_3') # Se muestra plt.show()
def Triple(): ''' Proceso que realiza el experimento del pendulo triple. Permite elegir parametros iniciales con sliders, calcula de forma numerica precisa la trayectoria y realiza una animacion en 2D. ''' # Se genera la ventana de sliders para seleccionar los parametros iniciales con func_sliders button, reset_func, sliders = fs.sliders_window(fs.triple) button.on_clicked(reset_func) plt.show() # Se toman los valores iniciales desde los sliders g, m1, m2, m3, L1, L2, L3, w1_0, w2_0, w3_0, th1_0, th2_0, th3_0 = [ slider.val for slider in sliders ] th1_0 = np.radians(th1_0) th2_0 = np.radians(th2_0) th3_0 = np.radians(th3_0) # Se establecen los parametros temporales t_0, t_f = 0, 20 dt = 0.02 # Se crea el array de tiempos y las tuplas de parametros iniciales y constantes t = np.arange(t_0, t_f + dt, dt) params = (th1_0, w1_0, th2_0, w2_0, th3_0, w3_0) args = (g, L1, L2, L3, m1, m2, m3) # Sol_Triple resuelve numericamente el problema th1, w1, th2, w2, th3, w3, x1, y1, x2, y2, x3, y3 = Sol_Triple( t, params, args) # Se reducen los angulos al intervalo (-pi,pi) th2_red = th2 % (2 * np.pi) th2_red = np.where(th2_red > np.pi, th2_red - 2 * np.pi, th2_red) th3_red = th3 % (2 * np.pi) th3_red = np.where(th3_red > np.pi, th3_red - 2 * np.pi, th3_red) # Animacion2D anima los datos obtenidos an = fa.Animacion2D(t, 1.1 * (L1 + L2 + L3), [x1, x2, x3], [y1, y2, y3], th2_red, th3_red, r'$\theta_2$ (rad)', r'$\theta_3$ (rad)', [m1, m2, m3]) # Se muestra plt.show()
def Esferico(): ''' Proceso que realiza una representacion grafica de niveles energeticos del pendulo esferico. Permite elegir parametros iniciales con sliders. ''' # Se genera la ventana de sliders para seleccionar los parametros iniciales con func_sliders button, reset_func, sliders = fs.sliders_window( np.array(fs.esferico)[:-2, :].tolist()) button.on_clicked(reset_func) plt.show() # Se toman los valores iniciales desde los sliders m, g, L, wph, wth = [slider.val for slider in sliders] # Se generan arrays para las variables ph = np.linspace(-np.pi, np.pi, 1000) th = np.linspace(-2 * np.pi, 2 * np.pi, 1000) # Se realiza un np.meshgrid de las variables que nos servira para calcular la energia en cada punto PH, TH = np.meshgrid(ph, th) # Energia del pendulo esferico E = m * L**2 / 2 * ( wph**2 + wth**2 * np.sin(PH)**2) - m * g * L * np.cos(PH) + m * g * L # Se crean la figura y los axes fig, ax = plt.subplots() # Se toman los niveles de energia que distinguira la representacion desde 0 hasta la energia maxima posible nivel = np.linspace(0, m * L**2 / 2 * (wph**2 + wth**2) + 2 * m * g * L, 40) # Se usa Fases para realizar la representacion Fases(fig, ax, ph, th, E, nivel, 'E (J)') # Se detalla informacion sobre la representacion set_angle_label(ax, 'x', r'\phi') set_angle_label(ax, 'y', r'\theta') # Se muestra plt.show()
def Esferico(): ''' Realiza una animacion del pendulo esferico. Permite elegir parametros iniciales con sliders. ''' # Se genera la ventana de sliders para seleccionar los parametros iniciales con func_sliders button, reset_func, sliders = fs.sliders_window(fs.esferico) button.on_clicked(reset_func) plt.show() # Se toman los valores iniciales desde los sliders m, g, L, wph, wth, ph, th = [slider.val for slider in sliders] th = np.radians(th) ph = np.radians(ph) ctes = g, L # Se crea la barra y la esfera a partir de los datos iniciales xyz = vector(L * np.sin(ph) * np.sin(th), -L * np.cos(ph) ,L * np.sin(ph) * np.cos(th)) rb = L/50 re = L/10 barra = cylinder(pos=vector(0, 0, 0), axis=xyz, radius=rb) esfera = sphere(pos=xyz, radius=re, color = vector(1,0,0), make_trail = True) # Se establece el intervalo temporal dt = 1e-4 # Se realiza un bucle infinito para visualizar la animacion while True: # Se establece el ratio de frames rate(1e4) # Se actualizan posicion y velocidad por metodo numerico ang, w = paso(ode.a_esferico, dt, [th,ph], [wth,wph], ctes) th, ph = ang; wth, wph = w # Se actualizan la posiciones de las esferas y las barras xyz = vector(L * np.sin(ph) * np.sin(th), -L * np.cos(ph) ,L * np.sin(ph) * np.cos(th)) esfera.pos = xyz barra.axis = xyz
def Esferico(): ''' Proceso que realiza el experimento del pendulo esferico. Permite elegir parametros iniciales con sliders, calcula de forma numerica precisa la trayectoria y realiza una animacion en 3D. ''' # Se genera la ventana de sliders para seleccionar los parametros iniciales con func_sliders button, reset_func, sliders = fs.sliders_window(fs.esferico) button.on_clicked(reset_func) plt.show() # Se toman los valores iniciales desde los sliders m, g, L, wph_0, wth_0, ph_0, th_0 = [slider.val for slider in sliders] th_0 = np.radians(th_0) ph_0 = np.radians(ph_0) # Se establecen los parametros temporales t_0, t_f = 0, 20 dt = 0.02 # Se crea el array de tiempos y las tuplas de parametros iniciales y constantes t = np.arange(t_0, t_f + dt, dt) params = (th_0, wth_0, ph_0, wph_0) args = (g, L) # Sol_Esferico resuelve numericamente el problema th, wth, ph, wph, x, y, z = Sol_Esferico(t, params, args) # Se reducen los angulos al intervalo (-pi,pi) th_red = th % (2 * np.pi) th_red = np.where(th_red > np.pi, th_red - 2 * np.pi, th_red) ph_red = ph % (2 * np.pi) ph_red = np.where(ph_red > np.pi, ph_red - 2 * np.pi, ph_red) # Animacion3D anima los datos obtenidos an = fa.Animacion3D(t, 1.1 * L, [x], [y], [z], th_red, ph_red, r'$\theta$ (rad)', r'$\phi$ (rad)') # Se muestra plt.show()
def Simple(): ''' Proceso que realiza una representacion grafica de niveles energeticos del pendulo simple. Permite elegir parametros iniciales con sliders. ''' # Se genera la ventana de sliders para seleccionar los parametros iniciales con func_sliders button, reset_func, sliders = fs.sliders_window( np.array(fs.simple)[:-3, :].tolist()) button.on_clicked(reset_func) plt.show() # Se toman los valores iniciales desde los sliders m, g, L = [slider.val for slider in sliders] # Se generan arrays para las variables th = np.linspace(-np.pi, np.pi, 100) w = np.linspace(-10, 10, 100) # Se realiza un np.meshgrid de las variables que nos servira para calcular la energia en cada punto TH, W = np.meshgrid(th, w) # Energia del pendulo simple E = m * L**2 * W**2 / 2 - m * g * L * np.cos(TH) + m * g * L # Se crean la figura y los axes fig, ax = plt.subplots() # Se toman los niveles de energia que distinguira la representacion desde 0 hasta la energia maxima posible nivel = np.linspace(0, m * L**2 * 50 + 2 * m * g * L, 40) # Se usa Fases para realizar la representacion Fases(fig, ax, th, w, E, nivel, 'E (J)') # Se detalla informacion sobre la representacion set_angle_label(ax, 'x', r'\theta') ax.set_ylabel('$\omega$ (rad/s)') # Se muestra plt.show()
def Simple(): ''' Realiza una animacion del pendulo simple. Permite elegir parametros iniciales con sliders. ''' # Se genera la ventana de sliders para seleccionar los parametros iniciales con func_sliders button, reset_func, sliders = fs.sliders_window(fs.simple) button.on_clicked(reset_func) plt.show() # Se toman los valores iniciales desde los sliders m, g, L, w, th, b = [slider.val for slider in sliders] th = np.radians(th) ctes = g, L, b, m # Se crean la barra y la esfera a partir de los datos iniciales xy = vector(L * np.sin(th), - L *np.cos(th), 0) rb = L/50 re = L/10 barra = cylinder(pos=vector(0, 0, 0), axis=xy, radius=rb) esfera = sphere(pos=xy, radius=re, color = vector(1,0,0), make_trail = True) # Se establece el intervalo temporal dt = 1e-3 # Se realiza un bucle infinito para visualizar la animacion while True: # Se establece el ratio de frames rate(1e3) # Se actualizan posicion y velocidad por metodo numerico th, w = paso(ode.a_simple, dt, [th], [w], ctes) th = th[0]; w = w[0] # Se actualiza la posicion de la esfera y la barra xy = vector(L * np.sin(th), - L *np.cos(th), 0) esfera.pos = xy barra.axis = xy