import numpy as np
import matplotlib.pyplot as plt

# --- Données expérimentales ---
# Exemple : à remplacer par vos mesures
I = np.array([])*1e-3         # intensité en mA
U = np.array([])          # tension en V

# --- Régression linéaire U = a*I + b ---
a, b = np.polyfit(I, U, 1)

# --- Affichage des résultats ---
print(f"Résistance de sortie du GBF = {-a:.2e} Ω")

# --- Tracé graphique ---
I_fit = np.linspace(min(I), max(I), 100)
U_fit = a * I_fit + b

plt.figure()
plt.plot(I*1e3, U, 'x', label="Mesures")
plt.plot(I_fit*1e3, U_fit, '--', label=f"Régression : U = {a:.2e} I + {b:.2f}")
plt.xlabel("I (mA)")
plt.ylabel("U (V)")
plt.ylim(0,5)
plt.title("Caractéristique d'un GBF")
plt.legend()
plt.grid(True)
plt.show()

