kill(all);

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

general :   6 ≤ ph=7 ≤ 8 : cubic equation
=================================

part 8:weak acid : ph just  'below ph = 7'
------------------------------------------------------------

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

rem : part 9 :weak base : ph just  'above ph = 7'

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

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

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

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

equilibrium: take account both  '1' and '1a'.
----------------------------------------------------------------

Charge balance :
==============

----------------------------------------
 [H(3)O(+)]  = [A(-)] + [OH(-)] 
----------------------------------------

p1c:H = OH + A;

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);

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

1e)  solve for HA from 'p3'
======================

p4:solve(p3,HA);

2e)  put  HA into  'p2a'
======================

p4a:subst(p4,p2a);

3e)  solve for 'p4a'  for A
======================

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

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

p4c: Kw = (OH)*(H);
p4d:solve(p4c,OH)[1];

Kw: see above.

insert 'p4b' and 'p4d' into 'p1c'
==========================

p5:subst([p4b,p4d],p1c);

p5a: rhs(p5)-lhs(p5)=0;

p5b:ratsimp(p5a);

result : above part p5b must be equal to zero

p6:part(lhs(p5b),1)=0;

p6a:expand(p6);

p6b:p6a*(-1);

p6c:args(lhs(p6b));

find coef : H^3,H^2,H , constant .
============================

p7a:coeff(lhs(p6b),H^3);
p7b:coeff(lhs(p6b),H^2);
p7c:coeff(lhs(p6b),H^1);
p7d:ev(lhs(p6b),H=0);

rem :  before H = A, for weak acid , because pH  around 7 then
            dissociation water must be taken into account.

result : we solve cubic equation.

p8:to_poly_solve([p6b], [H])$

cubic equation : three roots, 'p8a,p8b,p8c'

symbolic : cubic equation.
========

p8a:part(p8,1);

p8b:part(p8,2);

p8c:part(p8,3);

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

example : pH caculation benzoic acid , solution 10^(-5) M, K_a : 6.3*10^(-5)
rem : Kw : 10^(-14)
==============================================================

p9:[C_HA=10^(-5),K_a=6.3*10^(-5),Kw=10^(-14)];

solution : cubic equation

fpprintprec : 4;

symbolic :
========

p9a:subst(p9,p8a),numer;
p9b:subst(p9,p8b),numer;
p9c:subst(p9,p8c),numer;

numeric :
========

p10:subst(p9,p6b);

p10a:allroots(p10);

rem: Menu: Equations : Roots of polynomials.

p11a:p10a[1];
p11b:p10a[2];
p11c:p10a[3];

p12:[part(p11a,2),part(p11b,2),part(p11c,2)];

find : solution with physical meaning 'pos'
===============================

p13:for i:1 thru 3 do(
if is(p12[i]>0) = true then x: p12[i]);

x;

check : 'p10'
==========

p13a:subst([H=x],p10);

result : pH , solution benzoic acid
=========

p14:pH(x),float,numer;

to solve other problem ,you only need to change 'p9'

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

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