def ET(l1, l2, m1, m2, th1, th2, o1, o2, g):
    # Energía cinética
    T1 = 0.5*m1*(l1**2)*(o1**2)
    T2 = 0.5*m2*(l1**2*o1**2 + l2**2*o2**2 + 2*l1*l2*o1*o2*np.cos(th1 - th2))
    
    # Energía potencial
    U1 = -m1*g*l1*np.cos(th1)
    U2 = -m2*g*(l1*np.cos(th1) + l2*np.cos(th2))
    
    # Energía total
    E = T1 + T2 + U1 + U2
    return E

# Calcula la energía total en cada paso del tiempo
Et = np.array([ET(l1, l2, m1, m2, th1[i], th2[i], o1[i], o2[i], g) for i in range(len(t))])

# Grafica la energía total
plt.figure(figsize=(10, 6))
plt.plot(t, Et, 'g-', linewidth=2)
plt.xlabel('$t\,(s)$', fontsize=12)
plt.ylabel('Energía Total (J)', fontsize=12)
plt.grid(True)
plt.show()

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: