import numpy as np
import matplotlib.pyplot as plt

# ============================
# PARAMETRES PHYSIQUES
# ============================
m = 0.100      # masse (kg)
g = 9.81       # gravité (m/s^2)

# ============================
# DONNEES D'ENTREE
# ============================

t = np.array([2.000,2.067,2.133,2.200,2.267,2.333,2.400,2.467,2.533,2.600,2.667,2.733,2.800,2.867,2.933,3.000,3.067,3.133,3.200,3.267,3.333,3.400,3.467,3.533,3.600,3.667,3.733,3.800,3.867,3.933,4.000,4.067,4.133,4.200,4.267,4.333,4.400,4.467,4.533,4.600])
x = np.array([-0.410,-0.342,-0.262,-0.161,-0.048,0.074,0.189,0.285,0.363,0.416,0.441,0.442,0.429,0.387,0.318,0.222,0.083,-0.042,-0.173,-0.274,-0.340,-0.383,-0.400,-0.404,-0.400,-0.324,-0.250,-0.153,-0.036,0.085,0.194,0.291,0.364,0.412,0.443,0.443,0.443,0.380,0.307,0.211])
y = np.array([-0.426,-0.456,-0.512,-0.548,-0.567,-0.563,-0.536,-0.496,-0.444,-0.400,-0.369,-0.367,-0.383,-0.430,-0.485,-0.533,-0.569,-0.571,-0.546,-0.505,-0.461,-0.422,-0.415,-0.409,-0.433,-0.460,-0.507,-0.546,-0.568,-0.565,-0.539,-0.498,-0.447,-0.404,-0.372,-0.372,-0.372,-0.431,-0.493,-0.534])

# ============================
# COORDONNEES POLAIRES
# ============================
r = 
theta = 

# ============================
# CALCUL DES VITESSES
# ============================
dt = t[1] - t[0]

vx = np.gradient(x, dt)
vy = np.gradient(y, dt)

v2 = vx**2 + vy**2

# ============================
# ENERGIES
# ============================

Ec = 

# On prend l'origine de l'énergie potentielle au point le plus bas
Ep = 

Em = 

# ============================
# GRAPHE 1 : THETA = f(t)
# ============================
plt.figure()
plt.plot(t, theta)
plt.xlabel("Temps (s)")
plt.ylabel("Theta (rad)")
plt.title("Evolution de theta en fonction du temps")
plt.show()

# ============================
# GRAPHE 2 : ENERGIES
# ============================
plt.figure()
plt.plot(t, Ec)
plt.plot(t, Ep)
plt.plot(t, Em)
plt.xlabel("Temps (s)")
plt.ylabel("Energie (J)")
plt.title("Energies du pendule")
plt.legend(["Energie cinétique", "Energie potentielle", "Energie mécanique"])
plt.show()