import matplotlib.pyplot as plt
from math import *
Ta=90.0
La=7000
Tb=77
Lb=6000
R=8.314

def fA(T):
    return(exp(- (La/R)*((1/T)-(1/Ta))))
def fB(T):
    return(exp(- (Lb/R)*((1/T)-(1/Tb))))

def crb(T):
    a=fA(T)
    b=fB(T)
    xb=(1-a)/(b-a)
    yb=xb*b
    return(xb,yb)
def T_for_X(xref,X,T):
    goodT=-1
    i=0
    while i< len(X) and goodT<0:
        if (X[i]<xref and xref < X[i+1])or(X[i]> xref and xref > X[i+1]):
            goodT = T[i] + (T[i+1]-T[i])*(xref - X[i])/(X[i+1]-X[i])
        i+=1
    return(goodT)

T=[]
EB=[]
ROS=[]
t=Tb
dt=(Ta-Tb)/100
while t <= Ta:
    T.append(t)
    pts=crb(t)
    print(t,pts)
    EB.append(pts[0])
    ROS.append(pts[1])
    t += dt

plt.plot(EB,T,'r')
plt.plot(ROS,T,'b')
plt.show()

print ( 'Teb = ', T_for_X(0.8,EB,T))
print ( 'Tros = ', T_for_X(0.8,ROS,T)) # 0.8 car c'est la composition de l'air


