#pip install numpy et pip install matplotlib si non installés
importmatplotlib.pyplotaspltdefcourbes(a,n_Ai,b,n_Bi):x=0n_A=n_Ain_B=n_Bidx=(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='n(A)')plt.plot(x,n_B,'r.',label='n(B)')plt.legend()while (n_A>0)and(n_B>0):plt.plot(x,n_A,'b.')plt.plot(x,n_B,'r.')plt.pause(0.01)x=x+dxn_A=n_Ai-a*xn_B=n_Bi-b*xdefavancement_maximal(a,n_Ai,b,n_Bi):x_max=min(n_Ai/a,n_Bi/b)returnx_maxdefetat_final(a,n_Ai,b,n_Bi,x_max):n_A=n_Ai-a*x_maxn_B=n_Bi-b*x_maxif (n_A<1E-10andn_B<1E-10):print('Nous sommes dans les conditions stoechiométriques')print('x_max = {0:1.2E} mol.'.format(x_max))elifn_A<1E-10:n_A=0print('A est le réactif limitant.')print('x_max = {0:1.2E} mol.'.format(x_max))#print('A la fin de la transformation, il n'y a plus de A.')
print('Il reste {0:1.2E} mol de B.'.format(n_B))else:n_B=0print('B est le réactif limitant.')print('x_max = {0:1.2E} mol.'.format(x_max))#print('A la fin de la transformation, il n'y a plus de B.')
print('Il reste {0:1.2E} mol de A.'.format(n_A))#Le programme principal---------------------------------------------
#Equation du type aA + bB -> ........
#print('Entrez le nombre stoechiométrique a :')
a=int(input('Entrez le nombre stoechiométrique a :'))#print('Entrez la quantité initiale de A :')
n_Ai=float(input('Entrez la quantité initiale de A :'))b=int(input('Entrez le nombre stoechiométrique b :'))n_Bi=float(input('Entrez la quantité initiale de B '))x_max=avancement_maximal(a,n_Ai,b,n_Bi)etat_final(a,n_Ai,b,n_Bi,x_max)courbes(a,n_Ai,b,n_Bi)plt.ioff()plt.show()
During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:
Ensure the proper functioning of the site (essential cookies); and
Track your browsing to send you personalized communications if you have created a professional account on the site and can be contacted (audience measurement cookies).
With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.