#############################
######### Z - score #########
############ J.B ############
########### 2021  ###########
#############################
#############################


import matplotlib.pyplot as plt
import numpy as np
from math import pi
plt.rcParams['font.size'] = 12
plt.close('all')

## mesures

# frequence
V1 = 10.0  # mL
V2 = 12.2 # mL v eq

u_1 = .1  # mL incertitude
u_2 = .1  # incertitude
C1 = 1e-2 # mol/L
u_C = 1e-3  # mol/L
#pour affichage
nom_resultat = "$C$" # inductance
unite = "mol/L" # unité à afficher


## Méthode de Monté-Carlo
N =  10000 # nombre de tirages
V1_a = V1 + np.random.uniform(-u_1,u_1,N)
V2_a = V2 + np.random.uniform(-u_2,u_2,N)

C1_a = C1 + np.random.uniform(-u_C,u_C,N)
C2_a = C1_a*V1_a/V2_a

## représentation graphique
plt.figure(figsize=(10,6))

_,bins,_ = plt.hist(L_alea, 50,
                            density = True,
                            color ='green',
                            alpha = 0.3)
# Répartition gaussienne
sigma, mu = np.std(L_alea,ddof=1), np.mean(L_alea)
y = ((1 / (np.sqrt(2 * np.pi) * sigma)) *
     np.exp(-0.5 * (1 / sigma * (bins - mu))**2))
plt.plot(bins, y, '--', color ='black')
# Affichage moyenne
plt.plot([mu,mu],[0,max(y)],'--r')
texte = "$\mu$ = {:.3e} ".format(mu) +  unite
plt.text(mu+sigma/10,max(y)/20,texte,color='r')
# Affichage écart type
plt.plot([mu,mu+sigma],2*[0.6*max(y)],'k',linewidth=3)
texte = "$\sigma =  {:.1e} $".format(sigma) + unite
plt.text(mu+sigma/10,max(y)*.56,texte)
# noms des axes et titre
plt.xlabel(nom_resultat + ' ('+unite + ')')
plt.ylabel('Fréquence')
plt.title('Méthode de Monté-Carlo')
plt.show()




