kill(all)$

# Charge Balance :
(Di,n=2)protic Weak Acid,H(2)A
1*[H(+)] = 1*[0H(-)]+2*[A(2-)]+1*[HA(1-)]

ka(1) =([H(+)]*[HA(-)])/[H(2)A],ka(2) =([H(+)]*[A(2-)])/[HA(-)]
Ca = [H(2)A]+[HA(-)]+[A(2-)],[OH(-)]=kw/[H(+)]
use:
h=[H(+)],ka(1)=k1,ka(2)=k2

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

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

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

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

# polynoom :(Di)protic weak acid,general equation    (p4)

n1 -> coef Cte
n2 -> coef h
n3 -> coef h^2
n4 -> coef h^3
n5 -> coef h^4

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

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

# polynoom :(Mono)protic weak acid,general equation (p7)

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

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

third order polynoom ( with real coef):two complex roots,one real root.
only real root will be solution of (p7).

 Solve : Monoprotic acid in general.

p8:solve(p7,h)$

p9:part(p8,3,2);