kill(all)$

(tetra)protic weak acid,H(n)A => n=4
-----------------------------------
h=[H(+)],c=Ca,k1=ka(1),k2=ka(2),k3=ka(3),k4=ka(4),kw = 1E-14
peter.vlasschaert@gmail.com,22/09/2016

p1:h=((h^3*k1+2*h^2*k1*k2+3*h*k1*k2*k3+4*k1*k2*k3*k4)/(h^4+h^3*k1+h^2*k1*k2+h*k1*k2*k3+k1*k2*k3*k4))*c+kw/h;

;

p2:lhs(p1)-rhs(p1)=0$

p3:factor(lhs(p2))=0$

p4:num(lhs(p3))=0;

n1:ev(lhs(p4),h=0);
n2:coeff(lhs(p4),h);
n3:coeff(lhs(p4),h^2);
n4:coeff(lhs(p4),h^3);
n5:coeff(lhs(p4),h^4);
n6:coeff(lhs(p4),h^5);
n7:coeff(lhs(p4),h^6);

p5:n7*h^6+n6*h^5+n5*h^4+n4*h^3+n3*h^2+n2*h^1+n1=0;

p6:factor(ev(lhs(p5),k4=0))=0;

p7:(-1)*part(lhs(p6),1,2)=0;

(tri)protic weak acid ,H(n)A => n=3
-----------------------------------
h=[H(+)],c=Ca,k1=ka(1),k2=ka(2),k3=ka(3),kw = 1E-14

nn1:ev(lhs(p7),h=0);
nn2:coeff(lhs(p7),h);
nn3:coeff(lhs(p7),h^2);
nn4:coeff(lhs(p7),h^3);
nn5:coeff(lhs(p7),h^4);
nn6:coeff(lhs(p7),h^5);