kill(all);

Maxima : intro computation ,base and acid, 'part :17,version 1.0'
peter.vlasschaert@gmail.com, 28/12/2018

How to find , ph  for polyprotic ampholyt
-------------------------------------------------------------

polyprotic acid solution  (here n=2,diprotic)
====================

load packages :
------------------------

load(lrats)$

convert:
-----------

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

definition : pH,pOH
================

p1: pH(x)   :=-log10(x)$
p1a:pOH(x):=-log10(x)$

dissociation : aq :
===============

p1b:K_w=10^(-14);

quadratic equation :  s1*x^2+s2*x+s3= 0
=================

quadra2(s1,s2,s3,aa):= block([x1,x2,disc], disc: sqrt(s2^2-4*s1*s3),
                                                     x1:(-s2+disc)/(2*s1),
                                                     x2:(-s2-disc)/(2*s1),
                                                     aa:[x1,x2])$  

rem:solution of quadratic equation ,only pos solution have a physical meaning.

Weak acid: H(n)A    (n=3) ,example : H(3)PO4
===============

reaction : H(3)A+H(2)O        ⇔ H(3)O(+) + H2A(-)           ....  '1a' => K_a1
reaction : H2A(-)+H(2)O       ⇔ H(3)O(+) +HA(2-)            ....  '1b'=> K_a2
reaction : H(2)O+HA(2-)        ⇔ H(3)O(+) +A(3-)          .    ...  '1c'=> K_a3
reaction : H(2)O +H(2)O        ⇔H(3)O(+) + OH(-)              ... '1d' => K_w
--------------------------------------------------------------------------------------
rem:H(3)O(+) =H, A(2-) = A,OH(-)=OH,HA(2-)=HA H(2)A=H2A
         H2A(-) = H2A
--------------------------------------------------------------------------------------

p2a : K_a1 =( (H)*(H2A))/(H3A);

p2b : K_a2 =( (H)*(HA))/(H2A);

p2c : K_a3 =( (H)*(A))/(HA);

p2d: K_w=(H)*(OH);

start : polyprotic ampholyt salt : Na H(2)PO4  -> Na(+) + H(2)PO4(-)
                                                              Na      H(2)A  -> Na(+) + H(2)A(-)
---------------------------------------------------------------------------------------------------
result : A=PO4,  'example'
---------------------------------------------------------------------------------------------------

Definition: Ampholyt
==================

Ampholyt : both proton acceptor(= base) and proton donor( = acid).
------------------------------------------------------------------------------------------------------
other name  : zwitterion , biological chemistry (amino acid)

simplified : version 'ampholyt H2A(-)'

three reactions :  
=============
H2A (-)             = H(+) + HA(2-)   ...  '2a'   ' proton donor '       = formed
H2A (-)  + H(+) = H3A                  ...  '2b'   ' proton acceptor '  = consumed
H2O                   = H(+) + OH(-)    ...  '2c'                                        = formed

F :  [H(+)] tot = [H(+)] formed - [H(+)] consumed

result: F
=====

p3:H = HA + OH - H3A;

find : H3A = f1(H2A)   , from 'p2a'
================

p4a:solve(p2a,H3A);

find : HA = f2(H2A)   , from 'p2b'
================

p4b:solve(p2b,HA);

find : OH = f3(H2A)   , from 'p2d'
================

p4c:solve(p2d,OH);

above : result into 'p3'
===================

p3a:subst([p4a[1],p4b[1],p4c[1]],p3);

solve: [H(+)]
===========

p3b:solve(p3a,H);

select : positive solution , because concentration can't be negative

sol: p3b[2];

find ph  : 0.1M NaH2PO4
given : K_a1 = 5.9*10^(-3),K_a2 = 6.15*10^-8,K_a3 =  4.8*10^-(13)

solution :
========

p5:[K_a1 = 5.9*10^(-3),K_a2 = 6.15*10^-8,K_a3 =  4.8*10^-(13)];

p5a:H2A = 0.1;

p5b:subst([p5[1],p5[2],p5[3],p5a,p1b],sol);

ph ? ,solution of 0.1M NaH2PO4 
====

p6:ph = float(pH(rhs(p5b)));

other example :
=============

start : polyprotic ampholyt salt : Na2 HPO4  -> Na(+) + H(2)PO4(-)
                                                              Na2     HA  -> 2Na(+) + HA(2-)
---------------------------------------------------------------------------------------------------
result : A=PO4,  'example'
---------------------------------------------------------------------------------------------------

simplified : version 'ampholyt HA(2-)'

three reactions :  
=============
HA (2-)               = H(+) + A(3-)   ...  '22a'   ' proton donor '       = formed
HA (2-)  + H(+)  = H2A(-)            ...  '22b'   ' proton acceptor '  = consumed
H2O                   = H(+) + OH(-)   ...  '22c'                                        = formed

result: F
=====

p8: H = A+ OH - H2A;

find : H2A = f1(HA)   , from 'p2b'
================

p8a:solve(p2b,H2A);

find : A = f2(HA)    , from 'p2c'
================

p8b:solve(p2c,A);

above : result into 'p8'
===================

p9:subst([p8a[1],p8b[1],p4c[1]],p8);

solve: [H(+)]
===========

p9a:solve(p9,H);

select : positive solution , because concentration can't be negative

sol1:p9a[2];

find ph  : 0.1M Na2HPO4
given : K_a1 = 5.9*10^(-3),K_a2 = 6.15*10^-8,K_a3 =  4.8*10^-(13)

solution :
========

p10a:HA=0.1;

p10b:subst([p5[1],p5[2],p5[3],p10a,p1b],sol1);

ph ? ,solution of 0.1M Na2HPO4 
====

p11:ph = float(pH(rhs(p10b)));

relation between : sol and sol1
==========================

p12: sol;

p12a:subst([K_a2=K_a3,H2A=HA],p12)$

p12b:subst([K_a1=K_a2],p12a);

check :relation , between (sol1,p12b)
-----------------------

use : 'is' command maxima.

p13 : is(rhs(sol1) =rhs(p12b));

simplified version: approximation of solution , sol,sol1

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