This commit is contained in:
Arkitu 2026-01-14 17:40:29 +01:00
parent 02631ffa78
commit 1be90aecbd
3 changed files with 352 additions and 1 deletions

View File

@ -0,0 +1,162 @@
#################
# 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)

View File

@ -0,0 +1,189 @@
#################
# Bibliothèques #
#################
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import quad
############################
# PARAMETRES EXPERIMENTAUX #
############################
m = 0.2
delta_m = 0.001 # imprécision sur la mesure de m (kg)
#############################
# CHARGEMENT DU FICHIER CSV #
#############################
# A ADAPTER EN FONCTION DE VOS DONNEES
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,4]
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 #
###############################
# max_index : liste contenant les indices des maxima locaux
# a_max : liste des maxima locaux
# t_max : liste des instants où ont lieu les maxima
max_index = []
a_max = []
t_max = []
a_mean = np.mean(a)
for i in range(1, len(a)-1):
if a[i-1] < a[i] and a[i] > a[i+1] and a[i] > a_mean:
max_index.append(i)
a_max.append(a[i])
t_max.append(t[i])
###############################
# DETERMINATION DE LA PERIODE #
###############################
T = len(a_max) / (t_max[-1]-t_max[0]) # période en s
# u_T = # A COMPLETER # incertitude sur la période
omega0 = 2*3.14159/T
# u_omega0 = omega0*u_T/T
k = m*(omega0**2)
#####################################################
# TRACE GRAPHIQUE DE L'ACCELERATION AVEC VALEUR MAX #
#####################################################
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)
plt.show()
#############################
# TRAITEMENT DE DONNEES 1 : #
#############################
# Hypothèse frottement linéaire
# On applique le décrément logarithmique
CoeffDir, OrdOrigine = np.polyfit(t_max, a_max, 1) # Déterminer le coefficient directeur et l'ordonnée à l'origne de la droite moyenne
fig = plt.figure(3)
plt.title("Hypothèse frottement linéaire")
plt.ylabel("") #A COMPLETER)
plt.xlabel("t")
plt.scatter(t_max, # A COMPLETER)
plt.plot(t_max, coeffDir*np.array(t_max) + OrdOrigine , "r-" )
plt.show()
# #############################
# # TRAITEMENT DE DONNEES 2 : #
# #############################
# # Hypothèse frottement quadratique
# coeffDir, OrdOrigine = # A COMPLETER # Déterminer le coefficient directeur et l'ordonnée à l'origne de la droite moyenne
# fig = plt.figure(4)
# plt.title("Hypothèse frottement quadratique")
# plt.ylabel("") A COMPLETER)
# plt.xlabel("t")
# plt.scatter(t_max, # A COMPLETER)
# plt.plot(t_max, coeffDir*np.array(t_max) + OrdOrigine, "r-" )
# plt.show()
# #############################
# # TRAITEMENT DE DONNEES 3 : #
# #############################
# # Hypothèse frottement en v^p
# # A COMPLETER SI BESOIN
# #################################################################
# # AJUSTEMENT ET INCERTITUDES UTILISANT LA MATRICE DE COVARIANCE #
# #################################################################
# out,cov = np.polyfit(t_max,1/np.array(a_max)**(p-1),1,cov=True) #note : les coefficients a et b sont dans out
# coeffDir = out[0]
# OrdOrigine = out[1]
# #la matrice de covariance cov permet d'extraire l'incertitude sur les paramètres du modèle linéaire
# U = np.sqrt(np.diag(cov))
# UcoeffDir = U[0]
# UOrdOrigine = U[1]
# print("PARAMÈTRES DE L'AJUSTEMENT")
# print("Coefficient directeur a :", coeffDir)
# print("Ordonnée à l'origine b :", OrdOrigine)
# print("Incertitude sur le Coefficient directeur : u(a) =", UcoeffDir)
# print("Incertitude sur l' Ordonnée à l'origine : u(b) =", UOrdOrigine)
# fig = plt.figure(6)
# plt.scatter(t_max, 1/np.array(a_max)**(p-1))
# plt.plot(t_max, coeffDir*np.array(t_max)+OrdOrigine, "r-" , label="Ajustement 2")
# plt.title("Regression linéaire")
# plt.xlabel("x")
# plt.ylabel("y")
# plt.legend()
# plt.show()
# ############
# # FONCTION #
# ############
# #Calcul de Ip
# def I_p(p):
# """
# Calcul numérique de la valeur de Ip
# quad(f,a,b) permet l'integration d'une fonction f entre deux bornes a et b
# """
# def fun_f(x):
# return np.abs(np.sin(x))**(p+1)
# return quad(fun_f, 0, 2*3.14159)[0]
# #On calcule la valeur de Ip numériquement
# Ip = I_p(p)
# #Calcul de alpha à partir du coefficient directeur
# def fun_alpha(omega0, m, coeffDir):
# alpha = coeffDir*2*3.14159/(p-1)/Ip*m/omega0**(p-1)
# return alpha
# # Simulation de n mesures à partir des données : méthode de Monté Carlo
# n = 10000
# omega0_s = omega0 + np.random.normal(0, u_omega0, n)
# m_s = m + np.random.uniform(-delta_m, delta_m, n)
# coeffDir_s = coeffDir + np.random.normal(0, UcoeffDir, n)
# alpha_s = fun_alpha(omega0_s, m_s, coeffDir_s)
# ###############################
# # Analyse des données simulée #
# ###############################
# alpha_moy = np.mean(alpha_s)
# u_alpha = np.std(alpha_s, ddof=1)
# print("Coefficient alpha : ", alpha_moy)
# print("Incertitude sur alpha : ", u_alpha)

View File

@ -1,4 +1,4 @@
"Time (s)","Acceleration x (m/s^2)","Acceleration y (m/s^2)","Acceleration z (m/s^2)","Absolute acceleration (m/s^2)"
"t","ax","ay","az","a"
1.511495700E-2,9.756372124E-2,9.895236015E0,-4.165911078E-1,9.904481947E0
1.711610200E-2,8.319851011E-2,9.904812813E0,-4.070142806E-1,9.913521043E0
1.911834200E-2,7.841010392E-2,9.904812813E0,-4.213795066E-1,9.914082191E0

Can't render this file because it is too large.