kill(all);

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

Mixture :Weak acid: HA + Weak base : B
==================================

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

reaction : HA+H(2)O       ⇔ H(3)O(+) + A(-)           ....  '1'
reaction : B +H(2)O         ⇔  BH(+)  + OH(-)          ....  '2'
reaction : H(2)O+ H(2)O  ⇔ H(3)O(+) + OH(-)       ..... '12'
-------------------------------------------------------------------------------
rem:H(3)O(+) =H, A(-) = A,BH(+) = BH    
rem : kw = [OH(-)]*[H(+)]

equilibrium:

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

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

definition : K_a       .... '2a'
============

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

definition : K_b       .... '2b'
============

p2b:K_b = ((BH)*(OH))/(B);

C_HA = concentration weak Acid  ... '3a'
----------------------------------------------

p3a:C_HA=(HA)+(A);

C_B = concentration weak base  ... '3b'
----------------------------------------------

p3b:C_B=(B)+(BH);

charge balance:
==============
[H(+)] + [BH(+)] = [OH(-)] + [A(-)]

p3c:H+BH = OH + A;

find : [A(-)]
=========

p4:solve(p2a,A)[1];
p4a:solve(p3a,HA)[1];

p4b:subst([p4a],p4);

p4c:solve(p4b,A)[1];

find : [BH(+)]
===========

p5:solve(p2b,BH)[1];
p5a:solve(p3b,B)[1];

p5b:subst([p5a],p5);

p5c:solve(p5b,BH)[1];

find :[OH(-)] ,rem 'above'
==========

p6:K_w=(OH)*(H);
p6a:solve(p6,OH)[1];

use : charge balance 'p3c', find 'above'
=================================

p7:subst([p4c,p5c,p6a],p3c);

p7a:lhs(p7) - rhs(p7)=0;

p7b:ratsimp(p7a);

p8:num(lhs(p7b)) = rhs(p7b);

p8a:expand(p8);

solve : newton raphson method to find values H
========================================

reduce : approximations , suppose , neglect , constant term, first order term H
=================================================================
result : quadratic equation
---------------------------------------------------------------------------------------------------------------------

find coef polynomial : H^4,H^3,H^2,H,constant
=======================================

p9a:ratcoef(lhs(p8a),H^4);
p9b:ratcoef(lhs(p8a),H^3);
p9c:ratcoef(lhs(p8a),H^2);
p9d:ratcoef(lhs(p8a),H);
p9e:subst([H=0],lhs(p8a));

constant term, first order term H : neglect  
===========================
1e)  ([H(+)]  >> [OH(-)])    ,excess acidic

p10:p9a*H^4+p9b*H^3+p9c*H^2 = rhs(p8a);

p10a:factor(p10);

p10b:p10a/(-H^2);

p10c:ratsimp(lhs(p10b)*(-1))=rhs(p10);

coef : H^2,H,constant
==================

p11a:ratcoef(lhs(p10c),H^2);
p11b:ratcoef(lhs(p10c),H);
p11c:subst([H=0],lhs(p10c));

rem :  when : [OH(-)] > > [H(+)]
=========================
p10c :  [H(+)] => [OH(-)]          , excess base
              K_a => K_b
              K_b => K_a
               C_HA => C_B
               C_B    => C_HB
  ========================

coef : OH^2,OH,constant
=====================

p11a1:subst([K_b =K_a],p11a);
p11b1:K_w+K_a*(C_HA+K_b);
p11c1:(K_b-K_a)*K_w+(C_HA-C_B)*K_a*K_b;

result : quadratic equation

first and last term order term H :neglect
==========================
-----------------------------------------------------------
1e)  [H(+)] :  not far from neutral
2e)  C_B >> [H(+)] and C_HB >> [OH(-)]
-----------------------------------------------------------

p12:p9b*H^3+p9c*H^2+p9d*H=0;

p12a:expand(p12);

p12b:ratsimp(p12a/H);

p13a:ratcoef(lhs(p12b),H^2);
p13b:ratcoef(lhs(p12b),H);
p13c:subst([H=0],lhs(p12b));

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

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