#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Aug  25 15:16:34 2022

@author: mvictor
"""

import numpy as np
import matplotlib.pyplot as plt

# Données expérimentales et incertitudes
T = np.array([                  ]) # température en Kelvin
u_T = np.array([                ]) # en Kelvin


DeltaG = np.array([                         ]) # enthalpie libre de dissolution en kJ/mol
u_DeltaG = np.array([                       ]) # en kJ/mol

a, b = np.polyfit(              ) # a est la pente et b est l’ordonnée à l’origine

# Calcul des résidus
res = DeltaG - (a * T + b) 

# Paramètre graphiques
Tfit = np.array([min(T)-10,max(T)+10])

# Graphiques
plt.subplot(1,2,1)
plt.plot(Tfit, b + a*Tfit, 'r', label='Régression linéaire')
plt.errorbar(T,DeltaG,xerr=u_T,yerr=u_DeltaG,fmt='bo',zorder=2,label='Mesures')
plt.legend()
plt.ylabel('enthalpie libre de dissolution')
plt.xlabel('Température (K)')
plt.subplot(1,2,2)
plt.errorbar(T,res,xerr=u_T,yerr=u_DeltaG,fmt='bo',zorder=2)
plt.plot(Tfit,[0,0],'r')
plt.ylabel(r'Résidu')
plt.xlabel(r'T (K)')
plt.title(r'Tracé des résidus')
plt.show()


# Simulation Monte Carlo

N = 10000 
a1 = []
b1 = []

# Simulation Monte Carlo
for i in range(N):
    T_sim = T + u_T*np.sqrt(3)*np.random.uniform(-1,1,len(T))
    DeltaG_sim = 
    a_temp, b_temp = np.polyfit(             )
    a1.append(a_temp)
    b1.append(b_temp)

a1_moy = sum(a1)/N                 #Calcul de la valeur moyenne
u_a1 = np.std(a1,ddof=1)           #Calcul de l'écart-type
b1_moy = sum(b1)/N                 #Calcul de la valeur moyenne
u_b1 = np.std(b1,ddof=1)           #Calcul de l'écart-type

#Affichage des résultats
print(f'Enthalpie standard de dissolution: {b1_moy} kJ/mol') 
print(f'Incertitude-type u : {u_b1} kJ/mol')
print(f'Entropie standard de dissolution: {- a1_moy} kJ.K-1.mol-1') 
print(f'Incertitude-type u : {u_a1} kJ.K-1.mol-1')




