from math import *
from matplotlib import pyplot as plt
def E(X):
    x=0
    for i in X:
        x+=i
    return(x/len(X))

def E2(X,Y):
    xy=0
    n=len(X)
    for i in range(n):
        xy+=X[i]*Y[i]
    return(xy/n)

def V(X):
    n=len(X)
    x=0
    x2=0
    for i in X:
        x+=i
        x2+=i**2
    return((x2/n)-(x/n)**2)

def COV(X,Y):
    return(E2(X,Y)-E(X)*E(Y))

def CORR(X,Y):
    return(COV(X,Y)/sqrt(V(X)*V(Y)))

def pente(X,Y):
    return(COV(X,Y)/COV(X,X))

def ordonnee(X,Y):
    return(E(Y)-pente(X,Y)*E(X))

def reglin(X,Y):
    return(pente(X,Y), ordonnee(X,Y),CORR(X,Y))

pH=[1.26,1.33,1.44,1.51,1.59,1.7,1.84,2.04,2.96,8.07]
Y=[]#ÃƒÂ  remplir
X=[3.6,4.5,5.5,6,6.5,7,7.5,8,8.7,9.1]#ÃƒÂ  remplir
for i in range(len(X)):
    a=(100+X[i])*(10**(-1*pH[i]))
    Y.append(a)
a=pente(X,Y)
b=ordonnee(X,Y)
print(CORR(X,Y))
print(a,b)
plt.plot(X,Y,'+')

plt.axis([X[0],X[len(X)-1],Y[0],Y[len(Y)-1]])
plt.show()
