kill(all)$

Maxima : intro computation ,base and acid, 'part :7b,version 1.0'
peter.vlasschaert@gmail.com, 18/01/2019

Load packages
=============

load(lrats)$

Set Displayed Precision
====================

fpprintprec : 6;

Definition :  log10.
===============

log10(x):=log(x)/log(10);

Definition :  ph
============
F1 : ph = -log10(H)  ⇔ H = 10^(-ph)

see: website ( = titration calculus)
new: 26/12/2018:Maxima : intro computation ,base and acid, 'appendix 6',(titration,calculus,mono)
new: 06/01/2019:Maxima : intro computation ,base and acid, 'appendix 6a',(titration,calculus,poly)

find : dH/dph ?
----------------------

1e) subst  : H = 10^(-ph)
===================

p1:'diff(H,ph) = diff(subst([H=10^(-ph)],H),ph);

2e) subst : 10^(-ph) = H on the 'rhs'
=============================

p1a:lhs(p1) = lratsubst([10^(-ph) = H],rhs(p1));

numerical version : 'p1a'
-------------------------------------

p1b:float(p1a);

Buffer system :  example
=====================
Natrium acetate,acid acitic  

salt : Natrium acetate   :  representation   : A(-)
---------------------------------

NaAc   -> Na(+)  + Ac(-)    '1'

acid : acitc  acid           :   representation  :HA      'mono weak acid'
------------------------         

HAc ⇔  H(+) + Ac(-)           '2'  : dissociation constante : Ka

@  'strong base = NaOH' to Buffer system (A/HA):

HA + OH(-) -> A(-) + H2O ⇔ HA + OH(-)                          '3'
NaOH         ->  Na(+) + OH(-)   : cb ' concentration'   '3a'

@  'strong acid =HCl' to Buffer system (A/HA):

A(-) + H3O(+) -> HA+H2O ⇔ A(-) + H3O(+)                   '4'
HCl         ->  H(+) + Cl(-)          : ca ' concentration'   '4a'

Cas : representation 
=================
[H3O(+)] =[H(+)] = H, [A(-)] = A,[HA] =  HA,[OH(-)] = OH
[Na(+)]  = Na ,[Cl(-)]  = Cl

species : general  : charge balance
==============
[H(+)] + [Na(+)]  =[OH(-)] +[Cl(-)] +[A(-)]

ⅇ;

p2:H+Na=OH+Cl+A;

'strong acid HCl' see      '4a'
=======================

p2a:Cl = ca;

'strong base NaOH' see  '3a'
=======================

p2b:Na = cb;

put : conc 'ca,cb' into charge balance
---------------------------------------------------------

p2c: subst([p2a,p2b],p2);

' concentration buffer :Cbuf, (A/HA)'
========================

p2d: Cbuf = HA+ A;

definition
========

dissociation constant : Ka  'weak acid HA'
----------------------------------------------------------------

p3:Ka =((H)*(A))/HA;

dissociation constant :  Kw  'H2O'
--------------------------------------------------
by 25°C  Kw = 10^(-14)

p4:Kw=(H)*(OH);

Definition :Buffer index    'β'
=========================================

definition :first introduced by  :  'Van Slyke',1922

@ small conc  of   'strong base ' by (A/HA)      'Q'
---------------------------------------------------------------

p5:β = 'diff(cb,ph);

numerical : β = Δcb/Δph

@ small conc  of   'strong acid ' by (A/HA)    'QQ'
--------------------------------------------------------------

p5a:β = - 'diff(ca,ph);

numerical :  β = -Δca/Δph

 =======================================

combination : 'p3'   and  'p2d' : eliminate  HA
======================================

rem : eliminate :[HA,A] = > [eliminate,hold]

p6:eliminate ([p3,p2d],[HA,A]);

p6a: A= p6[1];

check : principle .
--------------------------

1e) step :

p6b:solve(p3,HA)[1];

2e) step:

p6c:solve(p2d,HA)[1];

3e) step:

p6d:rhs(p6b) =rhs(p6c);

4e) step:

p6e:solve(p6d,A)[1];

5e) check both solution 'p6a' and 'p6e'

is(rhs(p6a) =rhs(p6e));

reason : use eliminate better

rem : eliminate :[A,H] = > [eliminate,hold]

p7:eliminate ([p3,p2d],[A,HA]);

p7a:HA=p7[1];

rem : How to use. (other example.)
new: 16/01/2019:Maxima:How to use : eliminate ' chemical equations solving : titration'

check : principle .
--------------------------

p7b:solve(p3,A)[1];
p7c:solve(p2d,A)[1];
p7d:rhs(p7b) =rhs(p7c);
p7e:solve(p7d,HA)[1];
is(rhs(p7a) =rhs(p7e));

rem : charged species , charge balance.

result : charge balance  'p2c' subst 'p6a'
==================================

p8:subst([p6a],p2c);

We want find : buffer index (β)  ,  QQ
===============================

1e) step,solve cb (use equation : 'p8' )
---------------------------------------------------

p8a:solve(p8,cb)[1];

2e) step , remove  OH   ( use equation :'p4')
-----------------------------------------------------------------

p8b:solve(p4,OH);

3e) step , subst 'p8b' into 'p8a'
----------------------------------------------)

p8c:subst([p8b],p8a);

p8c1:ratsimp(p8c);

β = dcb/dph = dcb/dH*dH/dph,  chance rule : mathematics
=================================================

p9:'diff(cb,ph) = 'diff(cb,H) *'diff(H,ph);

a) all ready : ('diff(H,ph,1))  see  'p1b'
------------------------------------------------------

p9a:p1b;

p9b:subst([p9a],p9);

b)  find :('diff(cb,H,1))
--------------------------------

p9c:'diff(cb,H) = diff(rhs(p8c1),H);

p9d:lhs(p9c) =ratsimp(rhs(p9c));

p9e:factor(p9d);

c) β ?
-------

p9f:β =subst([p9e],rhs(p9b));

p9f1:rhs(p9f);

p9f2:subst([H=10^(-ph)],p9f1);

How to use this :  β  ( = Buffer Index)
===============================

 β = β (ph)  or  β = β (H)
==============================
function :  β by   'βH  and βph'
------------------------------------------------------
relation : H = 10^(-ph)
------------------------------------------------------

p10:βH(H,Ka,Kw,Cbuf):=''p9f1;
p11:βph(ph,Ka,Kw,Cbuf):=''p9f2;

numerical values :
===============
 HAc , NaAc  , system (HAc/Ac)
+>                                    concentration : 0.01 molar HAc
+>                                    concentration : 0.01  molar NaAc
+>                                     Ka = 1.75 e-5,Kw = 10^(-14)

p12:subst([Ka=1.75e-5],p3);

p12a:Cbuf = 0.01+0.01;

charge balance : [H(+)] +[Na(+)]  = [OH(-)]+[Ac(-)]
------------------------------------------------------------------------

p12b:H +Na = OH +Ac;

@ acid ,neglect  OH,H ( concentration)
---------------------------------

p12c:subst([OH=0,H=0],p12b);

NaAc  -> Na(+) + Ac(-)
--------------------------------

p12d: Na=0.01;
p12e: subst([p12d],p12c);

result : henderson hasselbalch equation
==================================
Ac = A , HAc = HA  (info above)

p12f : HA = A;

p12g:solve(p12,H)[1];

p12h:subst([p12f],p12g);

p12h1:float(p12h);

find  ph
=======

p13:ph  = -log10(rhs(p12h)),float,numer;

@ strong acid 0.001 mole HCl  to one liter of Buffer
----------------------------------------------------------------------------

calculation : β  => β(ph)

p14:[Kw=10^(-14),Ka=1.75e-5,Cbuf =rhs(p12a),ph=rhs(p13)];

p14a:β= subst(p14,βph(ph,Ka,Kw,Cbuf)),float;

from definition : Q ,buffer index.
===========================

ph after @ 0.001mole HCl  = Δca

numerical definition :  QQ
--------------------------------

p15: β = - Δca/Δph;

p15a:subst([p14a,Δca=0.001],p15);

p15b:solve(p15a,Δph)[1],float;

new  ph (@ strong acid)
====================

p16:ph_new = ph + Δph;

p16a:subst([Δph =rhs(p15b),p13],p16);

Make graph  β = β(ph)
==================

p17:[p14[1],p14[2],Cbuf = 0.2];

p17a:subst(p17,βph(ph,Ka,Kw,Cbuf));

p17b:subst([ph=t],p17a);

draw vertical line @ ph = 4.75696  (= pKa)
=====================================
x1(t) := 4.76
y1(t) := t
syntax : [parametric, x1(t),y1(t),[t,ymin,ymax]]
======================================

x1(t) :=4.76;
y1(t) := t;

curve :β= β(t)   t is here ph
======================================
x2(t) := t
y2(t) := β(t)
syntax : [parametric, x1(t),y1(t),[t,ymin,ymax]]
======================================

cor :10^2;   /*to see peak graph for pKa  (HAc) */

x2(t):=t;
y2(t):=''p17b*cor;

p18:[[parametric,x2(t),y2(t),[t,0,13]],[parametric,x1(t),y1(t),[t,0,13]]]$

wxplot2d(p18, [x,0,13],[y,0,13],[color,red,blue],[xlabel,"ph"],
 [plot_format, xmaxima],grid2d,[title,"β(ph)"] ,[ylabel,"β"],[legend,"β(ph)","pka"])$

'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------