kill(all);

Maxima : intro computation ,base and acid, 'appendix 5,version 1.0'
peter.vlasschaert@gmail.com,19/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 :
===============

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.

reaction : H2A+H(2)O       ⇔ H(3)O(+) +HA(-)           ....  '1a'   ,K_a1
reaction : HA(-)+H(2)O      ⇔ H(3)O(+) + A(2-)           ....  '1b'  ,K_a2
reaction : B +H(2)O            => BH(+) + OH(-)              strong base
reaction : H(2)O+ H(2)O    ⇔ H(3)O(+) + OH(-)          ....   '3'    ,K_w
--------------------------------------------------------------------------------------------
rem:H(3)O(+) =H, A(2-) = A,HA(-) = HA, BH(+) = BH ,OH(-) = OH  
====================================================
rem : kw = [OH(-)]*[H(+)]
====================================================
---------------------------------------------------------------------------------------------
K_ij  = dissociation constant   , " i = symbol , j = number  "
---------------------------------------------------------------------------------------------
i = a, a=acid
i = b ,b=base
====================================================

equilibrium:  =>    '1a' and '1b'  and  '3'

definition : pKa
============

p2:pKa(x)   :=-log10(x)$

Dibasic weak acid (n=2)
-----------------------------------

definition : K_a1, K_a2      .... '2a'
===================

p2a:K_a1 = ((H)*(HA))/(H2A);
p2b:K_a2 = ((H)*(A))/(HA);
p2c: p2a*p2b;

concentration : H2A     ...'2b'
=================

p2d:C_H2A=(H2A)+(HA)+(A);

distribution functions : α(0),α(1),α(2)
==============================
HnA  : α(0),α(1),α(2), ...α(n)
-------------------------------------------------------------------------------------------
see: Maxima : intro computation ,base and acid, 'appendix 2'
,(Distribution diagram,acid,poly) = > Formula
-------------------------------------------------------------------------------------------

distribution : part '1' (definition)
------------------------------------------------

p2e1:α(0) = (H2A)/lhs(p2d);
p2e2:α(1) = (HA)/lhs(p2d);
p2e3:α(2) = (A)/lhs(p2d);

distribution : part '2' (only function H,K_ij)
---------------------------------------------------------------

p2f:H^2+K_a1*H +K_a1*K_a2;
p2f1: α(0) = (part(p2f,3))/p2f;
p2f2: α(1) = (part(p2f,2))/p2f;
p2f3: α(2) = (part(p2f,1))/p2f;

info : H(n)A ( 'distribution function')
==============================

n=2 , H^2+K_a1*H+K_a1*K_a2 .
n=3 , H^3 +K_a1*H^2+K_a1*K_a2*H +K_a1*K_a2*K_a3 .

strong base(n=1)
----------------------------------------

concentration : B   .... '3b'
================

p3a:C_B=(HB)+(B);

rem :strong base: 'complete dissociation'
---------------------------------------------------------------
rem : B = 0

p3b:subst([B=0],p3a);

charge balance: all species in the solution
===================================
--------------------------------------------------------------------
[H(+)] + [BH(+)]  = [OH(-)] +1*[HA(-)] +2*[A(2-)] 
======================================
NaOH = MOH =>  BH(+) = M(+)
======================================
reaction : M(OH)  -> M(+) + OH(-)
---------------------------------------------------------------------
 M = C_B

p4:subst([BH = M],H+BH = OH + HA+2*A);

find : {OH,HA,B,A}
===============
===============

rem : K_w : w = aq. 'see above'
==========================

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

p4b:solve(p4a,OH);

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

find HA,A : for 'p4'
===============

p6a:solve(p2e2,HA);

p6b:solve(p2e3,A);

result 1: charge balance
=====================

p7:subst([p4b[1],p6b[1],p6a[1],p6b[1]],p4);

p7a: p7-M;

p7b:subst([M=C_b],p7a);

result 2: charge balance
=====================

p8:subst([p2f2,p2f3],p7);

Titration of polyprotic acid (HnA )with strong base (MOH).
================================================
example : H(2)A , diprotic acid.
                    ------------------------------
                    => n =2, succinic acid
                    K_a1 : 6.4E-05
                    K_a2 : 3.3E-06
                    NaOH , strong base
                    ------------------------------

1e)  [H(+)] total
============

Formula : [H(+)] total =[H(+)] formed -[H(+)] reacted
---------------------------------------------------------------------------------
[H(+)] = [H(+)] 'C_H2A' + [H(+)] 'aq' - [H(+)] 'strong base'
=============================================
rem : M = [H(+)] 'strong base' = C_b ,' = C_B'
---------------------------------------------------------------------------------

p9:p7b;

2e) titration
==========

part a:
=====

before titration : 'no base added'.  
---------------------------------------------------
C_H2A = C0_H2A   ' initial concentration H2A '
======================================
V : initial volume  C0_H2A , 'ml'

p9a:subst([C_H2A=C0_H2A,C_b = 0],p9);

part b:
=====

 during titration : ' base added: Mb , y ml  'from the buret ''.
--------------------------------------------------------------------------------------
Mb : molarity of NaOH buret added.
================================================
V+y : volume ' Analyte solution', 'ml'

use : 'p9'
=======

concentration during 'titration
---------------------------------------------

p10a:C_H2A = C0_H2A*(V/(V+y));
p10b:C_b = Mb*(y/(V+y));

formula C_b
-------------------

p10 : solve(p9,C_b)[1];

p11:expand(p10);

p12:[p10a,p10b];
p12a:subst(p12,p11);

solve for  y 'ml'
----------------------

p13:solve(p12a,y)[1];

p13a:rhs(p13);

relation between , pH and  y , 'ml'
===========================

p14: H = 10^(-ph);

α(1),α(2) in relation with ph
----------------------------------------

p14a:subst([p14],p2f2);
p14b:subst([p14],p2f3);

p14c:subst([p14,p14a,p14b],p13);

p14c1:subst([p14],p13);

after use ' ratsimp'  on ' y ml'
-------------------------------------------

p14d:ratsimp(p14c);

Numerical :  'titration curve  'succinic acid ' with the strong base 'NaOH' '
=========

===========================================================
Mb : 0.0954 M, 'NaOH'
V    : 50.2 ml
C0_H2A : 0.0617M, 'succinic acid '
===========================================================

use : 'p14c1'  for titration curve  : ph = ph(y)
=====================================
y , 'ml' added NaOH

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

1e) ph = 2.50 to 11,5  step value .25
       -----------------------------------------------
ph  = > l1  , list
α(1) => l2  ,list
α(2) => l3  ,list

How to make list { ph,α(1),α(2)}
----------------------------------------------

ph : list
======

l1:makelist(i1,i1,2.5,11.5,0.25);
p15: length(l1);

α(1),α(2) : list
===========

p15a:K_a1=6.4*10^(-5);
p15b:K_a2=3.3*10^(-6);

l2: makelist(subst([ph=l1[i],p15a,p15b],rhs(p14a)),i,1,p15);

l3: makelist(subst([ph=l1[i],p15a,p15b],rhs(p14b)),i,1,p15);

2e) y 'ml'
-------------

p16:subst([H=10^(-ph)],p13a);

p16a:subst([α(1)=α1,α(2)=α2],p16);

addedy(K_w,C0_H2A,Mb,V,ph,α1,α2):=''p16a;

list : y => ly, from buret  'ml'
-----------------------------------------

ly:makelist(addedy(10^(-14),0.0617,0.0954,50.2,l1[i],l2[i],l3[i]),i,1,p15);

 wxplot2d 
========

a) data (from x:ly,y:l1)
-----------

l4:[];

for i:1 thru p15 do(
l4:endcons([ly[i],l1[i]],l4))$

l4;

b) plot
----------

wxplot2d([[discrete,l4],[discrete,l4]],[style,points,lines],[xlabel,"ml : 'y' added from the buret  0.0954 M NaOH"],
[ylabel,"pH of the 'analyte solution' "],[title,"titration curve : succinic acid versus NaOH"],grid2d);

internet:
=======

Acid Strength and the Acid Dissociation Constant (Ka) = K_a
===================================================

https://chem.libretexts.org/Textbook_Maps/General_Chemistry
/Map%3A_A_Molecular_Approach_(Tro)/
16%3A_Acids_and_Bases/
16.04%3A_Acid_Strength_and_the_Acid_Dissociation_Constant_(Ka)

Table  16.4.1 : Values of  Ka ,  pKa ,  Kb , and  pKb  for Selected Acids ( HA  and Their Conjugate Bases ( A− )

acid  : HA                               K_a              , pK_a     
----------------------------------------------------------------------------------------
nitric   acid  :HNO3              2.3×10^1       ,−1.37       => strong acid
acetic acid  : CH3COOH   1.7×10^(-5)    ,4.76         => weak acid

given : concentration,C_HA = 0.01 M 
rem : removes memory :  C_HA,K_a

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