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

Upload New File

parent 6f5e5f0d
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 = 3.407
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.650, 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.067, 1.084, 1.101, 1.117, 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.534, 1.551, 1.568, 1.584, 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.951, 1.968, 1.985, 2.001, 2.018, 2.035, 2.052, 2.068]
angulo_medido = [3.407, 3.283, 3.177, 3.083, 3.005, 2.548, 2.951, 2.499, 2.846, 2.755, 2.193, 2.026, 1.838, 2.125, 1.577, 1.498, 1.837, 1.750, 1.633, 1.498, 1.310, 1.108, 0.939, 0.761, 0.623, 0.520, 0.423, 0.308, 0.200, 2.808E-2, -0.147, -0.373, -0.570, -1.155, -1.286, -1.390, -1.459, -1.564, -1.671, -1.804, -1.968, -2.133, -2.292, -2.419, -2.512, -2.576, -2.623, -2.666, -2.733, -2.820, -2.913, -3.012, -3.095, -3.157, -3.179, -3.170, -3.148, -3.133, -3.129, -3.145, -3.167, -3.203, -3.214, -3.209, -3.149, -3.067, -2.965, -2.855, -2.791, -2.721, -2.673, -2.626, -2.562, -2.482, -2.364, -2.223, -2.078, -1.936, -1.798, -1.705, -1.616, -1.507, -1.405, -1.257, -1.091, -0.916, -0.713, -0.542, -0.386, -0.245, -0.121, -1.490E-2, 0.114, 0.254, 0.423, 0.612, 0.794, 0.959, 1.102, 1.229, 1.341, 1.437, 1.542, 1.671, 1.818, 1.976, 2.120, 2.271, 2.389, 2.476, 2.541, 2.598, 2.674, 2.761, 2.859, 2.967, 3.061, 3.146, 3.207, 3.233, 3.240, 3.246, 3.254, 3.261, 3.296]
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