kill(all)$

maxima : analytical chemistry ,species NaH2PO4,version 1.0a
peter.vlasschaert@gmail.com,20/03/2022

load packages,option
----------------------------

ratprint:false$

problem : Nah2po4 =0,1 molar, find pH
                 conc : other species  ?
=============================

→ charge balance :

p1:h+na=oh+h2po4+2*hpo4+3*po4;

→ mass balance :

p2:h3po4+h2po4+hpo4+po4 =0.1;
p3:na=0.1;

→ equilibria , three: h3po4,one :h2o

eql1:h*h2po4 = 5.9*10^(-3)*h3po4;
eql2:h*hpo4 =6.15*10^(-8)*h2po4;
eql3:h*po4 = 4.8*10^(-12)*hpo4;
eqh2o:h*oh = 10^(-14);

reason : H3PO4 = PO4(3-)+3*H(+), value three before H(+).
result :{eql1,eql2,eql3}

h=[H+],oh=[OH-],h2po4=[H2PO4-],hpo4=[HPO4(-2)],po4=[PO4(-3)]

first step:solve p2 for h2po4

p4:solve(p2,h2po4);

second step :makelist "p4" & "p3"

p5a:[p3];
p5b:[p4,p5a];
p5c:flatten(p5b);

thrid step: subst "p5c" into "p1"

p6a:subst(p5c,p1);

p6b:expand(float(p6a));

→ solve for h, to remove numerical values (lhs,rhs)

p6c:solve(p6b,h);

fourth step: h3po4 from rhs → lhs

p7:(p6c+h3po4)[1];

solve problem pH : neglect po4,oh
---------------------------------------------

step 1: neglect values =0

p8a:[oh=0,po4=0];

step 2: use "p7" & "p8a"

p8b:subst(p8a,p7);

step 3 : neglect for salt given above in p2,h3po4,hpo4,po4;

p9:subst([h3po4=0,hpo4=0,po4=0],p2);

step 4:use equilibria : salt 

p10:eql1;

step5:subst "p9" into "p10"

p11:subst([p9],p10)/0.1;

step6:solve "p11" for h

p12:float(solve(p11,h));

step7:"p12" into "p8b"

p13:reverse(subst(p12,p8b));

step8:equilibria hpo4 & h2po4

p14:eql2;

step9:use "p10" & "p14", *,/h2po4

p15:(p10*p14)/h2po4;

step10:subst "p13" into "p15"

p16:subst([p13],p15)/h3po4;

step11:solve "p16" for h

h : pos quantity

p17a:solve(p16,h);

p17b:float(p17a[2]);

step12: make definition pH

pH(x):=-float(log(x)/log(10));

step13: use "p17b" & pH

print( "pH(0,1M,NaH2PO4)=",pH(rhs(p17b)))$

rem : p14,p10 (use : eliminate)

p18a:p10;
p18b:p14;

rem : eliminate = h2po4

p18c:eliminate([p10,p14],[h2po4]);

rem : you can't eliminate more variables than equations.

p18d:p18c[1]=0;

rem :inside of the list = 0

use : p13

p18c:subst([p13],p18d);

p18d:float(solve(p18c,h));

p18e:p18d[2];

check : orginal : p17b → true

?  find two equilibria are needed

step14 : thrid step ionization h3po4 = equilibria (first)

p19:eql3;

step15 : equilibria h20 =[H2O]

p20:eqh2o;

species :

1e species : h2po4

→ use p9

sp1:print("conc:[H2PO4-] =",rhs(p9))$

2e species:h3po4

use p12,p18e

p21a:subst([p18e],p12);

p21b:solve(p21a,h3po4)[1];

sp2:print("conc:[H3PO4] =",float(rhs(p21b)))$

3e species:hpo4

use ; p8b,p21b,p18e

p22:reverse(subst([p18e,p21b],p8b));

sp3:print("conc:[HPO4(-2)] =",float(rhs(p22)))$

4e species:po4

use :p19,p22,p18e

p23a:subst([p22,p18e],p19);

p23b:solve(p23a,po4)[1];

sp4:print("conc:[PO4(-3)] =",float(rhs(p23b)))$

5e species:oh

use:p20,p18e

p24a:subst([p18e],p20);

p24b:solve(p24a,oh);

p24b1:float(p24b);

sp5:print("conc:[OH-] =",rhs(p24b1[1]))$

find :pOH

rem : poh +ph = 14 ,pH+pOH = 14

definition : pOH
---------------------

p25:pOH(x) := 14-pH(x);

print("pOH =",pOH(rhs(p18e)))$

makelist:species:

p26a:[sp1,sp2,sp3,sp4,sp5];

rem : print statements are removed only values.

p26b:[h2po4,h3po4,hpo4,po4,oh];

use : map

p26c:map("=",p26b,p26a);

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