# -*- coding: utf-8 -*-

import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import quad



###############################################################################
###  Periode du pendule ###############################################################################
 
# Definition des ctes du pb
omega0 = 3.0                    # pulsation des petites oscillations
periode0 = 2*np.pi/omega0       # periode des petites oscillations


# Question 2  #################################################################
def integrande_pendule(theta,theta0):       # definition de l'integrande
    return                                  # a completer

# Question 3  #################################################################
periode1 =                                   # a completer
#La fonction quad(f) integre sur le premier argument de la fonction f
#Si f est une fonction de plusieurs variables,
#on utilise args=(ensemble des valeurs des autres arguments de f)
periode2 =                                   # a completer

##Question 3 avec les fonctions lambda
#theta01=0.1
#periode1=(2*np.sqrt(2)/omega0)*quad(lambda x: 1/np.sqrt(np.cos(x)-np.cos(theta01)), 0, theta01)[0]
#
#theta02=3
#periode2= (2*np.sqrt(2)/omega0)*quad(lambda x: 1/np.sqrt(np.cos(x)-np.cos(theta02)), 0, theta02)[0]


# Question 4  #################################################################
# Je choisis par exemple une centaine de points :
THETA = np.linspace(                  # a completer
PERIODE=[]
for k in THETA[1:]:  # Exclure theta=0 !
    PERIODE.append(                      # a completer


plt.figure()
plt.plot(THETA[1:],PERIODE,label="Expression integrale")
plt.xlabel('amplitude (rad)')
plt.ylabel('periode (s)')


# Question 5  #################################################################
plt.plot(THETA,periode0*(1+THETA**2/16),label="Approximation quadratique de Borda")
plt.plot([0,np.pi],[periode0,periode0],label="Approximation lineaire")
plt.xlim(0,np.pi)
plt.ylim(0,4*periode0)
plt.grid()
plt.title('Periode du pendule simple')
plt.legend(loc='upper left')
plt.show()


# Question 6  #################################################################
def borda_juste(p):  # a completer
   