kill(all)$

Maxima : intro computation ,base and acid, 'part :16b,version 1.0a'
peter.vlasschaert@gmail.com, 07/01/2019

load packages
============

load(lrats)$

titration of strong acid with strong base.
=================================
given : strong acid  conc = C_Z  = 0.1 M,(vessel)
              strong base conc = C_B  = 0.1 M,(buret)

definition: fraction titrated:Φ
======================

p:Φ =( C_B*V_B)/(C_Z*V_Z);

pq1:[C_Z*V_Z = C_B*V_B/Φ];

pq2:[C_B*V_B = Φ*(C_Z*V_Z)];

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

pa:V_Z+V_B;

pb1:Na=C_B*V_B/pa;
pb2:Cl = C_Z*V_Z/pa;

charge balance:
=============
[Na(+)] +[H(+)] = [Cl(-)] + [OH(-)]

p1:H+Na = Cl+OH;

p1a:subst([pb1,pb2],p1);

1e) multiply :V_Z+V_B
-----------------------------------

p1b:(V_Z+V_B)*p1a;

p1c:ratsimp(p1b);

p1d:lhs(p1c) - rhs(p1c)=0;

p1e:expand(p1d);

2e) find coef : V_Z,V_B
-----------------------------------

p1f :V_Z*ratcoef(p1e,V_Z) +V_B*ratcoef(p1e,V_B) ;

3e) solve V_B
---------------------

p1g: solve(p1f,V_B)[1]/V_Z;

4e) both sides : C_B/C_Z
-------------------------------------------

p1h:p1g*(C_B/C_Z);

p1i:lratsubst([ (C_B*V_B)/(C_Z*V_Z)=Φ],(p1h));

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

p1j1:ratsimp(num(rhs(p1i))/(C_B*C_Z));
p1j2:ratsimp(denom(rhs(p1i))/(C_B*C_Z));

p1j11:expand(lratsubst([H-OH = a],p1j1));

p1j22:expand(lratsubst([H-OH = a],p1j2));

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

p1k:lhs(p1i) = p1j11/p1j22;

 a = H-OH

p2:Φ =(1-a/C_Z)/(1+a/C_B);

p2a:subst([a=H-OH],p2);

p2b:subst([OH=K_w/H],p2a);

p2c:ratsimp(p2b);

p3:subst([H=10^(-ph)],p2c);

d^2(Φ)/dph^2
============

p4:'diff(Φ,ph,2) = diff(rhs(p3),ph,2);

back substitution : 10^(-ph) = H
===========================

p4a:lhs(p4) =  lratsubst([10^(-ph) = H],rhs(p4));

p4b:lhs(p4) = factor(rhs(p4a));

p4c:num(rhs(p4b));

p5:[C_Z=0.1,C_B=0.1,K_w=1*10^(-14)];

p5a:factor(p4c/(-log(10)^2*C_B*(C_Z+C_B)*H));

p5b:subst(p5,p5a);

p5c:allroots(p5b);

p5c1:rhs(p5c[1]);

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

p6a:pH(x) := -log10(x);

l:[];

for i:1 thru length(p5c) step 1  do(
l:endcons(rhs(p5c[i]),l))$

l;

p7:l[1];

p8:ll:[];

p8a:map(pH,l),numer;

pH values
=========

only positive values are with physical meaning.

p8b:expand(p8a),numer;

use : p3, ' H=10^(-ph),p5'
--------------------------------------

p9:[p5[1],p5[2],p5[3]];

p9a:subst(p9,p2c);

p9b:subst([H=10^(-ph)],p9a);

p9b1:rhs(p9b);

p9c:Φ(ph):=''p9b1;

m1:makelist(i,i,0,14,0.5);

ΦΦ:map(Φ,m1);

point representation.  (xy ,graph)
-------------------------------------------------

s1(B,ph,dat) :=  block ( [dat:[] ],
l1:length(B),
for i:1 thru l1 step 1 do(
 dat:endcons([B[i],ph[i]],dat)
    )  ,
 return(dat)    
)$

p10:s1(ΦΦ,m1,dat);

wxplot2d([[discrete, p10],[discrete,p10]], [x ,-1,3], [y,0,14],
 [plot_format, xmaxima],[title,"titration weak acid,HA with NaOH"],
 [xlabel,"Φ"] , [ylabel,"ph"],
    [style,[points,0.7,red],[lines,0.6,blue]] , 
 [nticks,15])$

two positive : values  
=> two inflection points

1e) pos value
===========

ph : value
---------------

p11a:p8b[3];

Φ(p8b[3]);

Φ = 1 , EP 

2e) pos value
===========

ph : value
---------------

p11b:p8b[4];

Φ(p8b[4]);

Φ <1 , before EP 

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