kill(all);

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

Base Mixtures (mono'B1',mono,'B2')
=================================

B1,B2         : representation weak base.

see : Maxima : intro computation ,base and acid, 'part :11,version 1.0'
==========================================================

HA1,HA2   : representation weak acid.

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.

Weak base: B1,B2
==================

================================
definition : base ,acid
---------------------------------
base : [H(+)] acceptor   : B    => BH(+)
acid  : [H(+)] donor         : HA =>  A(-)
================================

Maxima : intro computation ,base and acid, 'part :11,version 1.0'
=>   HA  or ' HA1  or HA2' mixture

reaction : B1+H(2)O      ⇔ OH(-) + BH1(+)         ....  '1a'
reaction : B2+H(2)O      ⇔ OH(-) + BH2(+)         ....  '1a'
reaction : H(2)O+H(2)O ⇔ H(3)O(+) + OH(-)        ....  '1c'
----------------------------------------------------------------------------
rem:H(3)O(+) =H, BHi(+) = BHi,OH(-)=OH  , i=1,2
----------------------------------------------------------------------------

equilibrium: take account both  '1a' and '1b' and '1c'
-------------------------------------------------------------------------------

Charge balance : all species with charge in the solution.
==============

------------------------------------------------------
 [OH(-)]  = [BH1(+)] +[BH2(+)] + [H(+)] 
------------------------------------------------------

p1c:OH = H+BH1+BH2;

definition : pKb
============

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

definition : K_bi  ,i=1,2     with   '1a,1b'
=============

p2a:K_b1 = ((OH)*(BH1))/(B1);
p2b:K_b2 = ((OH)*(BH2))/(B2);

C_Bi = concentration weak base  ... '3a,b', i=1,2
-------------------------------------------------

p3a:C_B1=(B1)+(BH1);
p3b:C_B2=(B2)+(BH2);

How to find A from charge balance, 'p1c'
------------------------------------------------------------

1e)  solve for Bi from 'p3a,b' i=1,2
========================

p4a:solve(p3a,B1);
p4b:solve(p3b,B2);

2e)  put  Bi into  'p2a,p2b', i=1,2
=======================

p5a:subst(p4a,p2a);
p5b:subst(p4b,p2b);

3e)  solve for 'p5a,p5b'  for BH1,BH2
============================

p6a:solve(p5a,BH1)[1];
p6b:solve(p5b,BH2)[1];

How to find OH from charge balance, 'p1c'
---------------------------------------------------------------

p7a: Kw = (OH)*(H);
p7b:solve(p7a,H)[1];

Kw: see above.

insert 'p6a' and 'p6b' and 'p7b' into 'p1c'
==================================

p8:subst([p6a,p6b,p7b],p1c);

p8a: rhs(p8)-lhs(p8)=0;

p8b:ratsimp(p8a);

result : above part p8b must be equal to zero

p9:part(lhs(p8b),1)=0;

p9a:part(lhs(p9),1);

p9b:args(lhs(p9a));

find coef : OH^4,OH^3,OH^2 ,OH,constant .
====================================

p10a:coeff(lhs(p9a),OH^4);
p10b:coeff(lhs(p9a),OH^3);
p10c:coeff(lhs(p9a),OH^2);
p10d:coeff(lhs(p9a),OH);
p10e:ev(lhs(p9a),OH=0);

Only roots who have physical meaning : here only positive roots.
---------------------------------------------------------------------------------------------------
Why concentration can be never negative

solution : quartic equation ? , intro course ,we  use approximation.
========================================================

rem: Menu: Equations : Roots of polynomials.(Newton raphson to find roots quartic equation)

We go back 'p8' for approximation.
=============================

p11:p8;

assumption  :   [OH(-)] > K_b1 and [OH(-)] > K_b2

p11a:part(rhs(p11),2,1);

p11b:part(rhs(p11),2,2);

p11c:subst([K_b1 = 0],p11b);

endcons: ' Maxima command ' to fill  a list

start : with empty list :
--------------------------------

list:[];

fill the list :
--------------

for i:1 thru 3 do(
    list:endcons(part(rhs(p11),i,1),list),
    if i=1 then list:endcons(subst([K_b2=0],part(rhs(p11),i,2)),list),
    if i=2 then list:endcons(subst([K_b1=0],part(rhs(p11),i,2)),list),
    if i=3 then list:endcons(part(rhs(p11),i,2),list)
);

list ;

p12:lhs(p11) = list[1]/list[2]+list[3]/list[4] +list[5]/list[6];

p12a:lhs(p11)=sum(list[2*i-1]/list[2*i],i,1,3);

p12b:ratsimp(p12a*OH);

first prediction : [OH(-)]
------------------------------------------------

assume(OH>0);

p12c:sqrt(p12b);

first prediction : pOH ( symbol pOh)
-----------------------------------------------------

p13: pOH(p12c);

p14: pOh = rhs(p13);

rem : pOH + pH = 14 => symbolic : pOh + ph = 14

first prediction : pH ( symbol ph)
-----------------------------------------------------

p14a:ph = 14 + rhs(p14);

How to check : [OH(-)]     use , 'p14' as first  approximation  'p11'
==================

a) start : orginal equation
--------------------------------------

p15:p11;

p15a: lhs(p15) -rhs(p15)=0;

b) first  approximation into 'p15a'
-------------------------------------------------

p15b: subst([p12c],p15a);

when solution : approximation lhs  +/-  zero of  very small the solution acceptable.

find solution :  use 'p15' : consective approximations to get solution.
====================

a) first approximation : Oh1 from 'p12c'
--------------------------------------------------------

p16:Oh1=rhs(p12c);

b) second approximation : h2 put into h1= H from rhs(p15)
-----------------------------------------------------------------------------------------

p16a: Oh2=subst([OH=Oh1],rhs(p15));

c) third approximation : Oh3 put into h2=h1 from rhs(p16a)
--------------------------------------------------------------------------------------

p16b:Oh3=subst([Oh1=Oh2],rhs(p16a));

d)  again and again 
-----------------------------
rem : Oh1-> Oh2-> Oh3  ->  ...... Ohi     > Ohn   , n = ' finite number  '
--------------------------------------------------------------------------------------------------
=> stop : approximation converge after a couple of tries.
--------------------------------------------------------------------------------------------------

rem  h3= Kw/Oh3, because : K_w =[OH(-)]*[H(+)]

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

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