kill(all);

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

polyprotic acid solution  (here n=2,diprotic)
====================

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: H(n)A    (n=2)
===============

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

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

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

----------------------------------------
 [H(3)O(+)]  =[HA(-)] +2* [A(2-)] 
----------------------------------------

p1c:H = HA + 2*A;

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

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

definition : K_a i (i=1,2)     .... '2'
==============

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

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

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

rem : H2A = f(HA,...), A=g(HA,..)

H2A = f(HA,...)
============

p3a:solve(p2a,H2A);

A    =g(HA,..)
===========

p3b:solve(p2b,A);

put 'p3a' and 'p3b' into 'p3'
======================

p3c:subst([p3a[1],p3b[1]],p3);

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

p3d:subst(p3b,p1c);

How to find : cubic equation H
==========================

1e)  'p3c'/'p4'
--------------------

p4:p3c/p3d;

p4a:ratsimp(p4);

2e) find cubic equation H
--------------------------------------

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

p5b:ratsimp(p5a);

result : above part p5b must be equal to zero

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

p6a:expand(p6);

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

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

result : we solve cubic equation.

p8:to_poly_solve([p6a], [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 carbonic acid H(2)CO3, solution 10^(-4) M, K_a 1
K_a 1: 4*10^(-7)     , first dissociation.
K_a 2: 5*10^(-11)   , second dissociation.
--------------------------------------------------------------------------------------------------
rem : Kw : 10^(-14)
==============================================================

p9:[C_H2A=10^(-4),K_a1=4*10^(-7),K_a2=5*10^(-11),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,p6a);

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

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

rem : pK_a1 > pKa2
=======================
rule : pK_a1 = pK_a2 +3
-----------------------------------------
result : pK_a2 = 0 into 'p6a'

p15:[C_H2A=10^(-4),K_a1=4*10^(-7),K_a2=0,Kw=10^(-14)];

p15a:subst(p15,p6a);

p15b:factor(p15a);

H ≠0 , into p15b : so

p15c:part(p15b,1,1)=rhs(p15b);

other part = 0,quadratic equation.

p15d:part(p15c,1,2)=rhs(p15b);

s1:coeff(lhs(p15d),H^2);
s2:coeff(lhs(p15d),H);
s3:subst([H=0],lhs(p15d));

solve : quadratic equation(with function)
-------------------------------------------------------------

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

p16a:for i:1 thru 2 do(
if is(p16[i]>0) = true then y: p16[i]);

p16b:y;

find pH
======

p16c:pH(y),numer,float;

result : cubic           => 5.213,,'p14'
              quadratic    => 5.123, 'p16c'

H(4)Y : ethyleendiaminetetra-acetic acid solution (n=4)
=============================================
K_a1 : 8.5*10^(-3)
K_a2 : 1.8*10^(-3)
K_a3 : 7.0*10^(-7)
K_a4 : 4.6*10^(-11)
--------------------------------------------------------------------------------
treat : dibasic acid ( = poly weak acid (n=2))
--------------------------------------------------------------------------------

'---------------------------------------------------------------------------------------------------'