Advertisement
J_Bernon

graphique avancement facile

Oct 21st, 2019
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Tracé du graphique quantités de matière en fonction de l'avancement
  4. version 02 : on n'utilise qu'une seule fonction pour calculer les quantités de matière
  5.  
  6. @author: Julien Bernon, Lycée Louis Feuillade
  7. """
  8.  
  9. from matplotlib import pyplot as plt #On importe d'abord ce qui permet de tracer des graphiques
  10.  
  11. def f(x,k,n):
  12.     return n-k*x
  13.  
  14. def av_max(a,na,b,nb):
  15.     xmax1=na/a
  16.     xmax2=nb/b
  17.     xmax=min(xmax1,xmax2)
  18.     return xmax
  19.  
  20. def generation(a,na,b,nb,c,nc,ini,fin,nb_pts):
  21.     liste_x,liste_ya,liste_yb,liste_yc=[],[],[],[]
  22.     for i in range(nb_pts):
  23.         x=ini+i*(fin-ini)/nb_pts
  24.         liste_x.append(x)
  25.         #Pour calculer les quantités de matière, on n'utilise plus que la fonction f
  26.        
  27.         liste_ya.append(f(x,a,na))
  28.         liste_yb.append(f(x,b,nb))
  29.         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
  30.     plt.plot(liste_x,liste_ya)
  31.     plt.plot(liste_x,liste_yb)
  32.     plt.plot(liste_x,liste_yc)
  33.     plt.show()
  34.     return True
  35.  
  36. a,b,c,na,nb,nc=1,2,3,0.05,0.03,0.01
  37. xmax=av_max(a,na,b,nb)
  38. generation(a,na,b,nb,c,nc,0,xmax,100)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement