Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Tracé du graphique quantités de matière en fonction de l'avancement
- version 03 : On ajoute une fonction de saisie des valeurs
- @author: Julien Bernon, Lycée Louis Feuillade
- """
- from matplotlib import pyplot as plt #On importe d'abord ce qui permet de tracer des graphiques
- def f(x,k,n):
- return n-k*x
- def av_max(a,na,b,nb):
- xmax1=na/a
- xmax2=nb/b
- xmax=min(xmax1,xmax2)
- return xmax
- def generation(a,na,b,nb,c,nc,ini,fin,nb_pts):
- liste_x,liste_ya,liste_yb,liste_yc=[],[],[],[]
- for i in range(nb_pts):
- x=ini+i*(fin-ini)/nb_pts
- liste_x.append(x)
- #Pour calculer les quantités de matière, on n'utilise plus que la fonction f
- liste_ya.append(f(x,a,na))
- liste_yb.append(f(x,b,nb))
- liste_yc.append(f(x,-c,nc)) #Comme C est un réactif on met un signe - devant son coefficient stoechiométrique pour modéliser son apparition plutôt que sa disparition
- plt.plot(liste_x,liste_ya)
- plt.plot(liste_x,liste_yb)
- plt.plot(liste_x,liste_yc)
- plt.show()
- return True
- def informations():
- a=float(input("Coefficient stoechiométrique de A : "))
- b=float(input("Coefficient stoechiométrique de B : "))
- c=float(input("Coefficient stoechiométrique de C : "))
- na=float(input("Quantité initiale de A (mol) : "))
- nb=float(input("Quantité initiale de B (mol) : "))
- nc=float(input("Quantité initiale de C (mol) : "))
- return a,b,c,na,nb,nc
- a,b,c,na,nb,nc=informations()
- xmax=av_max(a,na,b,nb)
- generation(a,na,b,nb,c,nc,0,xmax,100)
RAW Paste Data