Skip to content
Snippets Groups Projects
Commit 930e83c2 authored by Juan Sebastian Urrea Vega's avatar Juan Sebastian Urrea Vega
Browse files

Upload New File

parent 245b429e
No related branches found
No related tags found
No related merge requests found
import math
import numpy as np
import matplotlib.pyplot as plt
def integral(k, theta):
def integrando(t):
return 1 / math.sqrt(1 - k**2 * math.sin(t)**2)
puntos = 1000
h = (theta - 0) / puntos
sumadelaintegral = 0.0
for i in range(puntos + 1):
t = i * h
weight = 2 if i == 0 or i == puntos else 4 if i % 2 == 1 else 2
sumadelaintegral += weight * integrando(t)
return (h / 3) * sumadelaintegral
def periodo(L, g, theta):
alpha = theta / 2
k = math.sin(alpha)
T = 4 * math.sqrt(L / g) * integral(k, math.pi/2)
return T
longitudpendulo = 1.0
aceleraciongravedad = 9.81
anguloinicialengrados = 17.12
anguloinicialenradianes = math.radians(anguloinicialengrados)
periodo_calculado = periodo(longitudpendulo, aceleraciongravedad, anguloinicialenradianes)
def movimiento_pendulo(tiempo, L, g, angulo_inicial):
alpha = angulo_inicial / 2
k = math.sin(math.radians(alpha))
T = periodo(L, g, math.radians(angulo_inicial))
omega = 2 * math.pi / T
theta = math.radians(angulo_inicial)
omega_t = 0.0
angulos = []
tiempos = []
for t in tiempo:
angulos.append(math.degrees(theta))
tiempos.append(t)
alpha = theta / 2
k = math.sin(alpha)
omega_t = omega_t + (-g / L) * math.sin(theta) * (T / len(tiempo))
theta = theta + omega_t * (T / len(tiempo))
return tiempos, angulos
tiempo_inicial = 0.0
tiempo_final = 5.0
numero_puntos = 1000
tiempo = np.linspace(tiempo_inicial, tiempo_final, numero_puntos)
# --------Datos medidos con Tracker-----------------
tiempo_medido = [0.000, 0.017, 0.033, 0.050, 0.067, 0.083, 0.100, 0.117, 0.133, 0.150, 0.167, 0.183, 0.200, 0.217, 0.234, 0.250, 0.267, 0.284, 0.300, 0.317, 0.334, 0.350, 0.367, 0.384, 0.400, 0.417, 0.434, 0.450, 0.467, 0.484, 0.500, 0.517, 0.534, 0.550, 0.567, 0.584, 0.600, 0.617, 0.634, 0.651, 0.667, 0.684, 0.701, 0.717, 0.734, 0.751, 0.767, 0.784, 0.801, 0.817, 0.834, 0.851, 0.867, 0.884, 0.901, 0.917, 0.934, 0.951, 0.967, 0.984, 1.001, 1.017, 1.034, 1.051, 1.068, 1.084, 1.101, 1.118, 1.134, 1.151, 1.168, 1.184, 1.201, 1.218, 1.234, 1.251, 1.268, 1.284, 1.301, 1.318, 1.334, 1.351, 1.368, 1.384, 1.401, 1.418, 1.434, 1.451, 1.468, 1.484, 1.501, 1.518, 1.535, 1.551, 1.568, 1.585, 1.601, 1.618, 1.635, 1.651, 1.668, 1.685, 1.701, 1.718, 1.735, 1.751, 1.768, 1.785, 1.801, 1.818, 1.835, 1.851, 1.868, 1.885, 1.901, 1.918, 1.935, 1.952, 1.968, 1.985, 2.002, 2.018, 2.035, 2.052, 2.068]
angulo_medido = [17.12, 16.78, 16.41, 15.98, 15.57, 14.94, 14.31, 13.80, 13.40, 12.94, 12.50, 12.11, 11.54, 11.04, 10.50, 10.05, 9.274, 8.667, 8.150, 7.351, 6.653, 5.881, 5.203, 4.492, 3.810, 3.077, 2.320, 1.607, 0.867, 0.160, -0.619, -1.286, -1.957, -2.651, -3.288, -3.884, -4.470, -5.035, -5.574, -6.140, -6.558, -6.999, -7.213, -7.891, -8.296, -8.914, -9.307, -9.706, -10.03, -10.29, -10.51, -10.70, -10.83, -11.03, -11.15, -11.34, -11.54, -11.61, -11.80, -11.94, -11.97, -11.97, -11.82, -11.76, -11.56, -11.33, -11.03, -10.70, -10.40, -10.07, -9.656, -9.304, -8.912, -8.493, -8.069, -7.665, -7.028, -6.616, -5.951, -5.424, -4.855, -4.241, -3.628, -2.983, -2.298, -1.593, -0.916, -0.185, 0.534, 1.295, 2.086, 2.754, 3.465, 4.127, 4.718, 5.338, 6.001, 6.645, 7.197, 7.801, 8.537, 9.064, 9.860, 10.51, 11.53, 12.10, 12.73, 13.08, 13.66, 13.95, 14.44, 14.86, 15.06, 15.50, 15.74, 15.99, 16.26, 16.49, 16.69, 16.91, 17.09, 17.24, 17.30, 17.35, 17.36]
tiempo_medido_arr = np.array(tiempo_medido)
angulo_medido_arr = np.array(angulo_medido)
tiempos_simulados, angulos_simulados = movimiento_pendulo(tiempo_medido_arr, longitudpendulo, aceleraciongravedad, anguloinicialengrados)
#-----------------Gráfica--------------------
plt.plot(tiempo_medido, angulo_medido, 'bo', label='Datos medidos')
plt.plot(tiempos_simulados, angulos_simulados, 'r-', label='Simulación')
plt.xlabel('Tiempo (s)')
plt.ylabel('Ángulo (grados)')
plt.title('Comparación Datos Medidos y Simulación del Péndulo')
plt.legend()
plt.grid(True)
plt.show()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment