kill(all)$

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

graphics titration : acid base with strong base :
see:Maxima : intro computation ,base and acid, 'part 16,version 1.0'

load packages :
------------------------

load(lrats)$
load(facexp)$

convert:
-----------

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

definition : pH,pOH
================

p1: pH(x)   :=-log10(x)$
p1a:pOH(x):=-log10(x)$

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

titration : strong acid (mono: HCl)  'vessel' with strong base (NaOH) 'buret'.
===============================================================

reaction :  HCl + NaOH   => NaCl + H2O  ... '1'
1e)  HCl     -> H(+) + Cl(-)
2e) NaOH  -> Na(+) + OH(-)
rem :[H3O(+)]  = [H(+)] = H
          [OH(-)] = OH
          [Na(+)] = Na,[Cl(-)] = Cl

charge balance :
==============
-------------------------------------------------
sum ( +  charge) = sum( - charge)
-------------------------------------------------

p2:Na + H = Cl + OH;

definition : fraction  'f'
========
Nomemclature  ' titration'
    buret   :    Cb*V, ' NaOH' = titrant
f= ====== = ======
    vessel :    Cv*V0,   'HCl'  = titrated
-------------------------------------------------------------------
volume             : 'ml' ,  V,V0
concentration : 'M'  ,  Cb,Cv
b = buret
v = vessel
--------------------------------------------------------------------
example :
========
titration f,ratio of 'mmoles 'of base added as 'titrant
to (mmoles) of acid titrated.

simplified : principle
=================

symbolic : strong acid = C_HA , V0 = volume vessel
                     strong base=C_B    , V   = volume buret

added : 'Na OH'  : result : [H3O+] down , [OH(-)] up

before : Eq  (Equivalance  point)
===========================

definition : f    'above reaction system  '1' '
==========

p3: f=(C_B*V)/(C_HA*V0);

rem : K_w = [OH(-)]*[H] = 10^(-14)

p3a:K_w = OH*H;

p3b:solve(p3a,OH);

 general treatement, '1'
===================

vessel :conc  'strong acid' => vessel
======================

p4a:Cl=C_HA*V0/(V+V0);

buret :conc  'strong base'   => added
======================

p4b:Na=C_B*V/(V+V0);

insert : charge balance 'p4a,p4b'.
-------------------------------------------------

p4c:subst([p4a,p4b],p2);

p4d:part(rhs(p4c),1) -part(lhs(p4c),1)=H - OH;

p4e:factor(p4d);

subst  => f
=========

p5:lratsubst([rhs(p3)=lhs(p3)],lhs(p4d)) =rhs(p4e);

p5a:p5*(-1);

p5b:subst(p3b,p5a);

before  Eq :   [H(+)] >[OH(-)]  ,  f < 1
=======================
result : OH = 0
call :acid approximation

p6a:subst([OH = 0],p5a);

p6a1:p6a*(-1);

p6a2:rhs(p6a1) = lhs(p6a1);

@ Eq  : [H(+)] =[OH(-)]             , show before  f=1 ,  'part 16'
==================
call : jump acid to base.

p6b:[f=1];

p6b1:subst(p6b,p5a);

p6b2:solve(p6b1,H)[1];

after  Eq :   [H(+)] <[OH(-)]    , f >1
=====================
result : H = 0
call :base approximation

p6c:subst([H = 0],p5a);

p6c1:subst(p3b,p6c);

find : [H(+)]
-----------------

p6c2:solve(p6c1,H)[1];

p6c3:factor(p6c2);

How to draw  : f = f(ph)
===================

rem: ph = -log10(H)   <=> H = 10^(-ph)

p7:H= 10^(-ph);

values :  
=======
C_HA  'HCl      ' = 1*10^(-1)
V0        'vessel'  = 50 ml  ' HCl'
C_B     'NaOHl' = 1*10^(-4)
V          'buret  '  = ?

q:[C_HA = 1*10^(-4),V0=50,C_B=0.0001];

find f = f(V)
=========

insert f : 'q' values

q1:subst(q,p3);

q2:solve(q1,V)[1];

first curve :
=========

from acid approximation : curve
-------------------------------------------------

p7a:subst([p7,q2],p6a2);

p7b:solve(p7a,ph)[1];

p7c:subst([q[1],q[2]],p7b);

wxplot2d(rhs(p7c),[f,0.,2],[title,"acid approximation"],[ylabel,"ph"],
[xtics , 0,0.1,2],grid2d)$

second curve :
============

from base approximation : curve
-------------------------------------------------

p8a:subst([p7,q2],p6c3);

p8b:solve(p8a,ph)[1];

p8c:subst([q[1],q[2],K_w=10^'(-14)],p8b);

wxplot2d(rhs(p8c),[f,0.,2],[style,[points,0.3,red]],[title,"base approximation"],
[ylabel ,"ph"],[xtics , 0,0.1,2],grid2d)$

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

combination : graph ' acid approximation and base approximation '.
=========================================================

wxplot2d([rhs(p7c),rhs(p8c)],[f,0,2],[xtics,0,0.1,2],
                 [style,[points,0.4,blue],[points,0.4,red]],
                 [title,"acid and base approximation"],[ylabel,"ph"],grid2d,[legend,false])$

rem : Equivalence point by ' ph = 7'

general graph , "p5b"
==================

p9:p5b;

p9a:subst([p7],p9);

p9b:solve(p9a,ph)[1];

p9c:subst([q2,q[1],q[2],K_w=10^'(-14)],p9b);

draw graph,general
------------------------------

wxplot2d(rhs(p9c),[f,0.1,2],[style,[lines,0.3,black]],[title,"general"],
[ylabel ,"ph"],[xtics , 0,0.1,2],grid2d)$
========================================================================================
=> error
\[\mbox{}\\\mbox{plot2d: expression evaluates to non-numeric value everywhere in plotting range.}\]

Why we get error
==============

l:makelist(i,i,0.1,1.3,0.2);

l1:makelist(subst([f=l[i]],rhs(p9c)),i,1,length(l));

rem : l1 = ph  , complex value, ph = real

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