163 lines
3.8 KiB
Python
163 lines
3.8 KiB
Python
#################
|
|
# Bibliothèques #
|
|
#################
|
|
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
############################
|
|
# PARAMETRES EXPERIMENTAUX #
|
|
############################
|
|
m = 0.2
|
|
delta_m = 0.001 # imprécision sur la mesure de m (kg)
|
|
|
|
#############################
|
|
# CHARGEMENT DU FICHIER CSV #
|
|
#############################
|
|
fichier = "./tp14/data.csv"
|
|
data = np.loadtxt(fichier, skiprows=1, delimiter=",")#, max_rows = 2000
|
|
indStart = 12431 #permet d'ajuster le premier point pour retirer les données ne correspondant pas aux oscillations
|
|
indEnd = 62173
|
|
t = data[indStart:indEnd,0] - data[indStart,0]
|
|
a = data[indStart:indEnd,2]
|
|
a_abs = np.abs(a)
|
|
|
|
|
|
|
|
#####################################
|
|
# TRACE GRAPHIQUE DE L'ACCELERATION #
|
|
#####################################
|
|
fig = plt.figure(1)
|
|
plt.title("Oscillations d'un système masse-ressort")
|
|
plt.ylabel("Acceleration $m\cdot s^{-2}$")
|
|
plt.xlabel("temps($s$)")
|
|
plt.plot(t, a)
|
|
plt.show()
|
|
|
|
|
|
###############################
|
|
# RECHERCHE DES MAXIMA LOCAUX #
|
|
###############################
|
|
""" Objectifs :
|
|
Ecrire une structure algorithmique qui trouve les extrema locaux de
|
|
l'accélération et leurs instants t. On pourra rechercher les maximas de a_abs = |a|
|
|
Ces maximas et instants seront stockés dans deux listes a_max, et t_max.
|
|
"""
|
|
|
|
a_max = []
|
|
t_max = []
|
|
|
|
|
|
# Etape 1 : recherche des zeros
|
|
a_mean = np.mean(a)
|
|
liste_indice = []
|
|
for i in range(len(a)-1):
|
|
if (a[i]-a_mean)*(a[i+1]-a_mean)<0 :
|
|
liste_indice.append(i)
|
|
|
|
#Etape 2 : recherche des maximas sur la fonction valeur absolue de a
|
|
|
|
|
|
a_max = []
|
|
t_max = []
|
|
|
|
|
|
|
|
max_index = []
|
|
|
|
for i in range(len(liste_indice)-1):
|
|
indiceMin = liste_indice[i]
|
|
indiceMax = liste_indice[i+1]
|
|
max_index = indiceMin + np.argmax(a_abs[indiceMin:indiceMax]) # Pour avoir l'indice du maximum
|
|
if a_abs[max_index] > a_mean + 1 :
|
|
a_max.append(a_abs[max_index]) # Valeur maximum
|
|
t_max.append(t[max_index]) # instant de la vale
|
|
|
|
|
|
# tracé graphique de ces maxima
|
|
# Vérifier l'absence fausses detections
|
|
fig = plt.figure(2)
|
|
plt.title("Oscillations d'un système masse-ressort")
|
|
plt.ylabel("Acceleration $m\cdot s^{-2}$")
|
|
plt.xlabel("temps($s$)")
|
|
plt.plot(t, a_abs)
|
|
plt.scatter(t_max, a_max, color='r')
|
|
plt.show()
|
|
|
|
###############################
|
|
# DETERMINATION DE LA PERIODE #
|
|
###############################
|
|
""" Objectifs :
|
|
Ecrire une structure algorithmique détermine la période moyenne des oscillations.
|
|
On définit ainsi T.
|
|
En déduire la pulsation omega et la constante de raideur k
|
|
"""
|
|
|
|
Delta_t_max = []
|
|
for i in range(len(t_max)-1):
|
|
Delta_t_max.append(t_max[i+1]-t_max[i])
|
|
|
|
T = np.mean(Delta_t_max)
|
|
omega = 2*3.14159/T
|
|
k = m*(omega**2) #approximation
|
|
|
|
|
|
|
|
|
|
|
|
#######################
|
|
# DETERMINATION DE Em #
|
|
#######################
|
|
"""
|
|
Ecrire l'expression de Em à partir des maximas locaux a_max
|
|
"""
|
|
|
|
Em = []
|
|
for a in a_max:
|
|
Em.append(0.5*m*(omega**2)*(a**2))
|
|
|
|
|
|
#############################
|
|
# TRACE GRAPHIQUE DE ln(Em) #
|
|
#############################
|
|
fig = plt.figure(3)
|
|
plt.title("Ajustement de l'énergie mécanique")
|
|
plt.ylabel("$\ln{E_m}$")
|
|
plt.xlabel("temps($s$)")
|
|
plt.plot(t_max, np.log(Em))
|
|
plt.show()
|
|
|
|
|
|
|
|
|
|
|
|
############################
|
|
# TRAITEMENT DE DONNEES : #
|
|
############################
|
|
# Hypothèse frottement linéaire
|
|
# On applique un ajustement linéaire d'ordre 1 à ln(Em)
|
|
coeffDir, OrdOrigine = np.polyfit(t_max, np.log(Em),1) # A COMPLETER
|
|
|
|
mu = -coeffDir
|
|
|
|
fig = plt.figure(4)
|
|
plt.title("Hypothèse frottement linéaire")
|
|
plt.ylabel("$\ln{E_m}$")
|
|
plt.xlabel("t")
|
|
plt.scatter(t_max, np.log(Em), label="Données")
|
|
plt.plot(t_max,
|
|
coeffDir*np.array(t_max) + OrdOrigine,
|
|
"r-",
|
|
label="Ajustement linéaire")
|
|
plt.legend()
|
|
plt.show()
|
|
|
|
|
|
print("Coefficient µ\n")
|
|
print(mu)
|
|
|
|
# alpha = # A COMPLETER
|
|
|
|
# print("Coefficient de frottements\n")
|
|
# print(alpha)
|