kill(all)$

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

maple version : Prof Denis Constales , UGent.

load(lrats)$

function :
========

p1:CA(H,K_a,Kw):=(H/K_a+1)*(H-Kw/H);

definition : log10  , log10(100) = 2
--------------------------
Math : ln(x) , Maxima : log(x) , both base '%e' =2,7.......

p2:log10(x):=log(x)/log(10);

relation : pH = -log10(H)  ⇔ H= 10^(-pH)  ,both direction
----------------------------------------------------------------------------------

info : K_a = 1.76 *10^(-5)               ,value HAc = CH3COOH
           Kw = [OH]*[H] =10^(-14)     , value H(2)O

p3:[H=10^(-ph),Kw=1.0*10^(-14),K_a=1.76*10^(-5)];

p3a:subst(p3,-log10(CA(H,K_a,Kw)));

function : 'ph' and  '-log10(C_HA)'   , C_HA = HAc = CH3COOH
====================================================

p4:wxplot2d([%], [ph,0,6.99999999],
 [plot_format, xmaxima])$

p5:(H/K_a+1)*(H-Kw/H);

p5a:subst(p3,-log10(p5));

wxplot2d([%], [ph,0,6.8888888], 
 [plot_format, xmaxima])$

p6:diff(p5a,ph);

p6a:factor(%);

p7:subst([H=10^(-ph)],-log10(p5));

f'(ph)
====

p7a:diff(p7,ph);

f''(ph)
=====

p7b:factor(diff(%,ph));

f'(H)
===

p7c:lratsubst([10^(-ph) = H ],p7b);

p7d:factor(p7c);

f''(H) = 0
=======

p7e:part(p7d,1,1,3);

p7f:subst([K_a=1.76*10^(-5),Kw=1.0*10^(-14)],p7e);

p7g:allroots(1.76*10^-5*H^4-4.0*10^-14*H^3-1.76*10^-18*H^2-1.23904*10^-23*H+1.76*10^-33);

-log10(1.420425886139144*10^-10),float,numer;

-log10(9.27786464458991*10^-7),float,numer;

find the inflection point (ned: buigpunt), calculation second order derivative =0
-----------------------------------------------------------------------------------------------------------------------

pH must be less than 7, also true for the inflection point
===============================================

'p7g' are the roots for 'fourth order' polynomial equation in 'H'

p8a:p7g[1];
p8b:p7g[2];
p8c:p7g[3];
p8d:p7g[4];

p9a:-log10(part(p8a,2)),numer,float;
p9b:-log10(part(p8b,2)),numer,float;
p9c:-log10(part(p8c,2)),numer,float;
p9d:-log10(part(p8d,2)),numer,float;

p10:[p9a,p9b,p9c,p9d];

search value below pH < 7
----------------------------------------

p11:for i:1 thru length(p10) do(
if is(p10[i]<7) = true then s:p10[i]);

s;

check: root p7f, inflection point  f''(H) = 'p7f' = 0
-----------------------------------------------------------------------

p12:subst([p8b],p7f = 0);

rem : log(-x) =log(x)+n*π*i ,  i = sqrt(-1) ,assume (x>0)
=>  representation:  -x = a+i*b 
=>  principal value : log(-x) = log (x) + π*i  , n=1
why : see : Maxima : intro computation ,base and acid, 'part :8a,version 1.0'. 
           (discrete values in the list, we only select pos values )

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