1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| import matplotlib.pyplot as plt
#Les fonctions------------------------------------------------------
def courbes(a,b,c,d,n_Ai,n_Bi,n_Ci,n_Di,A,B,C,D):
x=0
n_A, n_B, n_C, n_D = n_Ai, n_Bi, n_Ci, n_Di
dx=(min(n_A,n_B)/100)
plt.ion()
x_max=min(n_Ai/a,n_Bi/b)
plt.xlim(0,1.2*x_max)
plt.ylim(0,1.2*max(n_A,n_B))
plt.xlabel('Avancement x (mol)')
plt.ylabel('n (en mol)')
plt.grid()
plt.plot(x,n_A,'b.',label=A)
plt.plot(x,n_B,'b+',label=B)
plt.plot(x,n_C,'r.',label=C)
plt.plot(x,n_D,'r+',label=D)
plt.legend()
while (n_A>0) and (n_B>0):
plt.plot(x,n_A,'b.')
plt.plot(x,n_B,'b+')
plt.plot(x,n_C,'r.')
plt.plot(x,n_D,'r+')
plt.pause(0.01)
x=x+dx
n_A=n_Ai-a*x
n_B=n_Bi-b*x
n_C=n_Ci+c*x
n_D=n_Di+d*x
#Le programme principal---------------------------------------------
#Equation du type aA + bB -> cC + dD
a, b, c, d = 1, 2, 1, 2
n_Ai, n_Bi, n_Ci, n_Di= 10, 30, 0, 0
A, B, C, D = "CH4", "O2", "CO2", "H2O"
courbes(a,b,c,d,n_Ai,n_Bi,n_Ci,n_Di,A,B,C,D)
plt.ioff()
plt.show() |
Partager