How to get a
titration curve by
using Python
Strong acid-strong base
titrations
Example
▸ Considering the titration of 100 mL
of 2 M HCl with 1 M NaOH and
plotting the pH of the solution
being analyzed as a function of the
amount of titrant added.
○ equivalence point
○ x-axis values
○ y-axis values
2
Python example (1)
3
import pylab
a1 , b1 , a2 = 2 , 0.1 , 1
c , b2 = a1*b1 , a1*b1/a2
n , eps = 50 , 1.e-10
db = b2/n
# NaOH added in mL
bs1 = pylab.linspace(db,b2,n)
bs2 = pylab.linspace(b2,2*b2,n)
# compute pH
as1 = -pylab.log10( (c - a2*bs1 + eps)/(b1 + bs2) )
as2 = 14 + pylab.log10( (a2*bs2 - c + eps)/(b1 + bs2) )
Python example (2)
4
# plot figure
# the curve before equivalence point
pylab.plot(bs1,as1,color='r')
# the curve near equivalence point
pylab.plot([bs1[-1],bs2[1]],[as1[-1],as2[1]],color='r')
# the curve after equivalence point
pylab.plot(bs2[1:],as2[1:],color='r')
# setup figure property
pylab.title("The Titration Curve")
pylab.xlabel("Vol of NaOH added (L)")
pylab.ylabel("pH")
pylab.grid()
# display figure
pylab.show()
Result
The titration curve
5

化學系 python 教學

  • 1.
    How to geta titration curve by using Python
  • 2.
    Strong acid-strong base titrations Example ▸Considering the titration of 100 mL of 2 M HCl with 1 M NaOH and plotting the pH of the solution being analyzed as a function of the amount of titrant added. ○ equivalence point ○ x-axis values ○ y-axis values 2
  • 3.
    Python example (1) 3 importpylab a1 , b1 , a2 = 2 , 0.1 , 1 c , b2 = a1*b1 , a1*b1/a2 n , eps = 50 , 1.e-10 db = b2/n # NaOH added in mL bs1 = pylab.linspace(db,b2,n) bs2 = pylab.linspace(b2,2*b2,n) # compute pH as1 = -pylab.log10( (c - a2*bs1 + eps)/(b1 + bs2) ) as2 = 14 + pylab.log10( (a2*bs2 - c + eps)/(b1 + bs2) )
  • 4.
    Python example (2) 4 #plot figure # the curve before equivalence point pylab.plot(bs1,as1,color='r') # the curve near equivalence point pylab.plot([bs1[-1],bs2[1]],[as1[-1],as2[1]],color='r') # the curve after equivalence point pylab.plot(bs2[1:],as2[1:],color='r') # setup figure property pylab.title("The Titration Curve") pylab.xlabel("Vol of NaOH added (L)") pylab.ylabel("pH") pylab.grid() # display figure pylab.show()
  • 5.