kill(all);

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

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 :
===============

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 acid: HA
================

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

reaction : HA+H(2)O ⇔ H(3)O(+) + A(-)          ....  '1'
rem:H(3)O(+) =H, A(-) = A

equilibrium:

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

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

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

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

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

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

from : '1' follows :  H=A  ... '4'
--------------------------------

p3a:A=H;

p3b:subst([p3a],p3);

result:  HA  ... '5'
--------

p3c:solve(p3b,HA)[1];

insert : '3' and '4' into  '2'
-----------------------

p4:subst([p3a,p3c],p2a);

p4a:part(rhs(p4),1);

p4b:part(rhs(p4),2);

p4c:p4*p4b;

p4d: rhs(p4c) - lhs(p4c)=0;

quadratic equation:s1*x^2+s2*x+s3= 0 ,... '5'
---------------------------.

p4e:expand(p4d);

find:si ,i=1,2,3
--------------------

p4f:args(lhs(p4e));

p4g:[H=1];

s1:subst(p4g,p4f[3]);
s2:subst(p4g,p4f[1]);
s3:subst(p4g,p4f[2]);

solve quadratic:'5'
============

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

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

assume(C_HA>0,K_a>0);

check : solutions of physical meaning
---------------------------------------------------

p6a:is(p6[1]>0);

p6b:is(p6[2]>0);

function : physical meaning: phsysicalm(sol,number)
-------------------------------------

physicalm(f1,jj):=is(f1[jj]>0);

p6a1:physicalm(p6,1);

p6b1:physicalm(p6,2);

p6a = p6a1, p6b=p6b1 , general use , physical meaning.

How to find, [H] =H  'concentration of weak acid'.
=====================================

physicalsol(K_a,C_HA,sol):=

find H: with function.  physicalsol(K_a,C_HA,sol)
------------------------------------------------------------------
rem :sol is here 'p6'

p7:if physicalm(p6,1) =true then p6[1];

p7aΑ:for i:1 thru 2 do(
if physicalm(p6,i) =true then ss:p6[i]);

ss;

function : symbolic solution
========================

p7b:physicalsol(sol,s):=block(for i:1 thru 2 do(
if physicalm(sol,i) =true then s:sol[i]),return(s));

symbolic : sol
--------------

p8:physicalsol(p6,s);

p8a:H = p8;

rem:block and return are connected with in function, 'physicalsol'

function : numerical solution
========================

p9:physicalsoln(K_an,C_HAn,sol,s):= block(
for i:1 thru 2 do(
if physicalm(sol,i) = true then s:subst([K_a=K_an,C_HA=C_HAn],sol[i])),
return(s));

numerical solution : before output symbolic equation , input the values , then 'return' 

 numerical :sol
----------------

example : values for weak acid.

p9a:K_an:10^(-5);

p9b:C_HAn:10^(-4);

p9c:H = physicalsoln(K_an,C_HAn,p6,s);

rem : use float

p9d:float(p9c);

Calculation : pH, weak acid
------------------------

p10:pH(rhs(p9d)) ;

p10a:float(p10);

How to find : from equation 'p4e' for 'strong acid'
=========================================
see: also part 2.

p11:p4e;

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

p11a:p4f;

find H: strong acid, HNO3 ,see table 'above'
---------------------------------------

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

p11b:subst([H=1,C_HA = 0.01,K_a = 2.3*10^1 ],p11a);

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

p11c:quadra2(p11b[3],p11b[1],p11b[2],aa);

find solution with physical meaning
------------------------------------------------------

p11d:H = physicalsoln( 2.3*10^1,0.01,p11c,s);

relative value of terms into quadratic equation
---------------------------------------------------------------------
use: p11a subst  p11d

p11e :subst([p11d,C_HA = 0.01,K_a = 2.3*10^1],p11a);

look last term list much smaller, 'p11'
-----------------------------------------------

Equation strong acid (with use p11a)
==================

p12:p11a[1]+p11a[2] =rhs(p11);

find H :
-----------

p12a:solve(p12,H);

find pH : we only need concentration ' strong acid'
------------

p12b:pH(0.01);

p12c:float(p12b);

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