kill(all)$

Maxima : intro computation ,base and acid, 'appendix 8,version 1.0'
peter.vlasschaert@gmail.com, 05/01/2019

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

load(lrats)$

experiment :
==========
titration 10.0 ml of 0.1M  HA (= weak acid) with 0.1M NaOH.

vessel : 10 ml ,0.1M HA
buret   : x ml with 0.1M NaOH (added to the vessel)   'B'

How to find midpoint 'before EP ' and 'after EP'
-----------------------------------------------------------------------
EP = Equivalance Point.

data
====

B:[0.00,1.00,2.50,5.00,7.50,8.75,9.50,9.75,9.90,10.00,10.10,10.25,10.50,12.75,15.00];

p1:length(B);

ph:[3.00,4.05,4.52,5.00,5.48,5.85,6.28,6.59,7.00,8.85,10.70,11.09,11.39,12.08,12.30];

p2:length(ph);

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

p3:s1(B,ph,dat);

select : first point of the  xy, graph
=============================

p4:p3[1];

How to make this xy,graph (= experiment)
===================================

wxplot2d([[discrete, p3],[discrete,p3]], [x ,0,15], [y,3,13],
 [plot_format, xmaxima],[title,"titration weak acid,HA with NaOH"],
 [xlabel,"x ml  NaOH added with the buret"] , [ylabel,"ph"],
    [style,[points,0.7,red],[lines,0.6,blue]] , 
 [nticks,15])$

How to make this yx,graph (= experiment)
===================================

p3a:s1(ph,B,datr);

wxplot2d([[discrete, p3a],[discrete,p3a]], [x ,0,14], [y,3,13],
 [plot_format, xmaxima],[title,"titration weak acid,HA with NaOH"],
 [xlabel,"ph"] , [ylabel,"x ml  NaOH added with the buret"],
    [style,[points,0.7,red],[lines,0.6,blue]] , 
 [nticks,15])$

average ( =  ph )  
================================

fm1(vol,v1) := block ([v1:[]],
ll : length(vol),
for i:1  thru ll -1 step 1
      do(l1:(vol[i+1]+vol[i])/2,
      v1:endcons(l1,v1)),
return(v1))$

v1:fm1(ph,v1);

find max from list v1
------------------------------

v1a:lmax(v1);

f ' = Δv/Δph
==========

fdervv1(vol,ph,fd1):= block([fd1:[] ],
 ll:length(vol) ,
  for i:1  thru ll -1 step 1
      do(l2:(vol[i+1]-vol[i])/(ph[i+1]-ph[i]),
     fd1:endcons(l2,fd1)),
return(fd1))$     

fd1:fdervv1(B,ph,fd1);

fd1a:length(fd1);

find max value fd1
---------------------------

p4:lmax(fd1);

point representation.  (f ' ,graph)
-------------------------------------------------
the spike in the graph points to the midpoint ( = before EP) 
and also one ( = after EP).

p5:s1(v1,fd1,dat1);

wxplot2d([[discrete, p5],[discrete,p5]], [x ,0,15], [y,0,2*14],
 [plot_format, xmaxima],[title,"titration weak acid,HA with NaOH"],
 [xlabel," average ph"] , [ylabel,"Δv/Δph"],
 [style,[points,0.7,red],[lines,0.6,black]] ,  [nticks,15] )$

detail : f '
========

wxplot2d([[discrete, p5],[discrete,p5]], [x ,3,12.5], [y,0,p4+0.5],
 [plot_format, xmaxima],[title,"titration weak acid,HA with NaOH"],
 [xlabel," average ph"] , [ylabel,"Δv/Δph"],
 [style,[points,0.7,red],[lines,0.6,black]] ,  [nticks,15] )$

result : f ' (Δv/Δph) , search for spikes = 'midpoints '
===========================================
see: (ph,Δv/Δph) ,'graph above '

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

two midpoints :
=============

1e) midpoint  =  ( ph = 5).
2e) midpoint =   ( ph = 12)

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