kill(all);

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

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

load(lrats)$
load(facexp)$

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

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

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

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

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

p1b:kw=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.

salt: strongbase + weakbase (check  value log(10) plot  Ac(-))
===================================================
weak   acid  :  HA = H(+) + A(-)
strong base :  M(OH) => M(+) + OH(-)
===================================================
M= metal = Na,K,Li
--------------------------------------------------------------------------------------------
first prediction of the ph :  ph > 7 NaAc
K_a = 1.8*10^(-5)  ' HAc = CH3COOH carbonic acid '

example : HAc , A=Ac,acetic acid (ned : azijnzuur)
pka = -log10(ka)

-----------------------------------------------------------------------------------------------------
reaction : HA+H(2)O      ⇔ H(3)O(+) + A(-)         ....  '1'                 => K_a
reaction : A(-) +H(2)O    ⇔  HA        + OH(-)        ....  '2'                  => K_b
reaction : H(2)O+H(2)O ⇔ H(3)O(+) + OH(-)      ....  '3' = '1' + '2' => K_w
------------------------------------------------------------------------------------------------------
rem:H(3)O(+) =H, A(-) = A,OH(-)=OH
result : sum ('1' ,'2')   =  '1'+'2'  => K_a*K_b = K_w
------------------------------------------------------------------------------------------------------

p2:K_a = (H)*(A)/(HA);

given : find pH for NaAc 0.01M  => dominated OH(-)
==========================
----------------------------------------------------------------------------
reason : strong base.
----------------------------------------------------------------------------

                             A(-) +H(2)O    ⇔  HA        + OH(-)  
======================================       

init                :    0.01                      0                 0
reaction      :       --x                       x                x
======================================
equilibrium      0.01 -x                  x                x

species : solution, needed for K_b
----------------------------------------------------

p2a: A   = 0.01-x;
p2b: HA = x;
p2c: OH = x;

equilibrium constant : '2'
-------------------------------------

p3: K_b  =( (HA)*(OH))/A;

p3a:subst([p2a,p2b,p2c],p3);

we want to solve : 'p3a' , x = OH
----------------------------------------------

p4:rhs(p3a) -lhs(p3a)  = 0;

p4a:ratsimp(p4);

p4b:p4a*(-1);

result : math , nummerator 'p4b' = 0

p5:part(lhs(p4b),1) = rhs(p4b);

relation between : K_a*K_b = K_w

p5a:K_w=K_a*K_b;

p5b:solve(p5a,K_b)[1];

result : 'p5b' into  'p5'

p5c:subst([p5b],p5);

sa:ratcoef(lhs(p5c),x^2);
sb:ratcoef(lhs(p5c),x);
sc:ev(lhs(p5c),x=0);

input values : K_w,K_a
-----------------------------------

s:[K_w=10^(-14),K_a = 1.8*10^(-5)];

s1:subst(s,sa);
s2:subst(s,sb);
s3:subst(s,sc);

solve : quadratic equation
----------------------------------------

solution : list
===========

p6:quadra2(s1,s2,s3,aa);

p6a:p6[1];
p6b:p6[2];

find solution with physical meaning: 'solution must be positive'
-------------------------------------------------------

for i:1 thru length(p6) step 1 do(
if is(p6[i] >0) = true then sol:p6[i]);

sol;

p7:OH = sol;

find : OH    =>  pOH
-----------------------------
rem : pOH +ph = 14

p7a:'pOH(rhs(p7))=float(pOH(rhs(p7)));

find pH for 0.01M NaAc
===================

pH = 14-rhs(p7a);

from 'see: part 15,15a', 0.01 M NaAc, construction

=>  :first prediction was true : pH > 7  =>  8.372312565352935 > 7

How to find : pH  , 'from Figure 1'
===========================

-------------------------------------------------------------------------
intersection (red dot line,red line)  to the  ph-axes
--------------------------------------------------------------------------

=========================================
rem : Figure 1.
=========================================
legend : red line : HA, blue line A(-)
                 red  dot line = OH(-)
                 blue dot line = H(+)
=========================================

--------------------------------------------------------------------------------------------------------------------------------------------------