kill(all)$

Maxima : superposition parametric plots ( = distributionfunctions).'version 1.0a'
peter.vlasschaert@gmail.com,23/01/2019

'n' parametric plots on the graph.
============================

αnplotr(l,t,t1,t2,xmin,xmax,ymin,ymax,opt1,opt2,opt3,opt4):=block( [m:[]],
    d:length(l),        
    for i:1 thru d/2  do (    
   m :endcons([parametric,l[1+2*(i-1)],l[2*i],[t,t1,t2]],m) 
                                   ),
    wxplot2d(m,[x,xmin,xmax],[y,ymin,ymax],opt1,
                     opt2,opt3,opt4)                     
    )$

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

opt1:title 
opt2:xlabel
opt3:ylabel
opt4:legend
------------------------------------------------------------------------------
' x-direction'
xmin  :min of the range of the canvas         => value
xmax :max of the range of the canvas        => value
rem : xmin < xmax
' y-direction'
ymin  :min of the range of the canvas         => value
ymax :max of the range of the canvas        => value
rem : ymin < ymax
' t-parameter'
t1  :min of the range to draw       => value
t2 :max of the range to draw       => value
rem : t1 < t2
-----------------------------------------------------------------------------
How to use : 'see' : example  'p6' and 'p7' ,below.

definition :  pH
============

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

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

distribution function :  H3A
======================
n=3 , αi  i=0,1,..n  
dissociation constants : Ka1,Ka2,Ka3
representation :
=============
[H(+)] = h  ⇒ h = 10^(-ph)

nn:h^3+h^2*Ka1+h*Ka1*Ka2+Ka1*Ka2*Ka3;

p1:α0= h^3/nn;
p2:α1= (h^2*Ka1)/nn;
p3:α2=( h*Ka1*Ka2)/nn;
p4:α3=(Ka1*Ka2*Ka3 )/nn;

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

dissociation constant  ( A= PO4)  
===========================
info : 'acid phosphoric '

Ka1:7.11*10^(-3);
Ka2:6.34*10^(-8);;
Ka3:4.22*10^(-13);

relation beween  h and ph
======================
h = 10^(-ph)

paa:[h= 10^(-ph)];

p1a:subst(paa,rhs(p1));
p2a:subst(paa,rhs(p2));
p3a:subst(paa,rhs(p3));
p4a:subst(paa,rhs(p4));

p5a:α0(ph) :=''p1a;
p5b:α1(ph) :=''p2a;
p5c:α2(ph) :=''p3a;
p5d:α3(ph) :=''p4a;

how to use : 'αnplotr'
==================

l:[ph,α0(ph),ph,α1(ph),ph,α2(ph),ph,α3(ph)]$

opt1:[[title,"distribution function α,i=0,1,..,3"],[xlabel,"ph"],[ylabel,"αi"]
   ,[legend,"α0","α1","α2","α3"]];

d1:length(opt1);

test for : opt1: check four entries 'opt1' 
----------------------------------------------------------

test(opt1):= if is(length(opt1) = d1) then true else false;

test(opt1);

display : distribution functions
-----------------------------------------------

if test(opt1) = true then
   p6: αnplotr(l,ph,0,14,0,14,0,1,opt1[1],opt1[2],opt1[3],opt1[4])
else 
    disp ("you need four entries,title,xlabel,ylabel,legend")    ;

rem : display : no title , no legend.
=============================

opt2:opt1:[[title,""],[xlabel,"ph"],[ylabel,"αi"]
   ,[legend,""]];

if test(opt2) = true then
    p7:αnplotr(l,ph,0,14,0,14,0,1,opt2[1],opt2[2],opt2[3],opt2[4])
else 
    disp ("you need four entries,title,xlabel,ylabel,legend")    ;

rem :α0 = [H3A]/C_A,α1 = [H2A(-)]/C_A,α2 = [HA(2-)]/C_A,α3 = [A(3-)]/C_A
A = PO4
-----------------------------------------------------------------------------------------------------------

C_A = concentration acid ( = H3PO4)
----------------------------------------------------------------------------------------------------------

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