kill(all)$

Maxima : Example 1: strong Acid H2SO4 ,0.05M (find ph)
peter.vlasschaert@gmail.com, 23/01/2019

problem :  What is the ph of a 0.05M sulphuric acid solution.
                    --------------------------------------------------------------------------
                     Ka2  (H2SO4) : 1.2 e-2
                    --------------------------------------------------------------------------

definition 
========

log10(xx) := log(xx)/log(10);

ph  : definition
============

ph(xx) := - log10(xx);

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])$  

solution problem 
===============

reaction :  H2SO4   ⇒ H(+) + HSO4(-)        '1'   , full dissociation frist deprotonation
                    HSO4(-) ⇔ H(+) + SO4(2-)         '2'    , Ka2'

representation : 'cas'
[HSO4(-)]  = HSO4, [SO4(2-)] = SO4  , [H(+)] = H

p1: Ka2= (H*SO4)/(HSO4);

from '1' reaction : 
--------------------------

                                               H2SO4  ⇔ H(+) + HSO4(-)       '1'
  initial concentration :      0.05M    ⇔ 0.05M  +0.05M      

from '2' reaction :  
--------------------------

                                              HSO4(-) ⇔ H(+) + SO4(2-)         '2' 
initial concentration         0.05  M       0.05M      0               ' result '1'
reaction                                -  x              + x          +x
----------------------------------------------------------------------------------------------
equilibrium                        0.05 - x       0.05+ x     x

equilibrium   ( use  'p1' )
==========

p2a:HSO4 = 0.05-x;
p2b: H        = 0.05 + x;
p2c:  SO4  = x;

p2:Ka2 = subst([p2a,p2b,p2c],rhs(p1));

find  value :  x ( solve : quadratic equation )
============

p3:lhs(p2) - rhs(p2) =0;

p3a:ratsimp(p3);

see : above , s1,s2,s3
--------------------------------

p3b:num(lhs(p3a)) = rhs(p3a);

s1:coeff(lhs(p3b),x,2);
s2:coeff(lhs(p3b),x,1);
s3:coeff(lhs(p3b),x,0);

p4:Ka2 = 1.2*10^(-2);

s2:subst([p4],s2);
s3:subst([p4],s3);

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

p5a:float(p5);

only positive values has physical meaning : 'quadratic equation'
=====================================

p5b:p5a[1];
p5c:p5a[2];

p5d:x=p5b;

How to find ph : ? 'use  'p2b'
========================

p6:subst([p5d],p2b);

ph = ?
=====

p6a:float(ph(rhs(p6)));

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