We model the titration of a weak diprotic acid by a strong base using an arc-length continuation method in Mathematica. The acid is characterized by two dissociation constants corresponding to pKa1=6, and pKa2=11 (see Ref. 1). During the titration, the solution undergoes successive deprotonation reactions, producing the species A, , and . A very common real-world example of a diprotic acid is Carbonic acid. Indeed, Carbonic acid has two acidic protons that dissociate step by step: C ⇌ + HCO HCO ⇌ + COIts approximate dissociation constants are: pKa1≈6.35, pKa2≈10.33. This acid is widely used in: blood pH regulation, ocean chemistry, carbonated drinks, natural waters, respiration and biological buffering systems.
H
2
H
-
A
2-
A
H
2
O3
+
H
-
3
-
3
+
H
2-
3
The mathematical model is based on chemical equilibrium relations, mass conservation, and electroneutrality. The nonlinear algebraic system describing the titration curve may become difficult to solve near equivalence regions because of sharp pH variations and multiple buffering zones. To improve numerical robustness, the arc-length continuation method is employed. Instead of solving independently for each added-base fraction, the continuation algorithm follows the equilibrium solution branch progressively using predictor-corrector steps. This approach ensures stable convergence even near steep transitions and equivalence points.
The simulation provides both the pH titration curve and the distribution diagram of the chemical species as a function of the normalized titrant amount x defined as moles of base added over initial moles of acid.
The simulation provides both the pH titration curve and the distribution diagram of the chemical species as a function of the normalized titrant amount x defined as moles of base added over initial moles of acid.
The results clearly show the three buffer regions associated with the three pKa values, as well as the dominance regions of each species during titration.
The method demonstrates the effectiveness of arc-length continuation for tracking highly nonlinear equilibrium systems encountered in acid-base chemistry.
The method demonstrates the effectiveness of arc-length continuation for tracking highly nonlinear equilibrium systems encountered in acid-base chemistry.
Acid concentration mol/l
Ca=0.01;
NaOH concentration mol/l
Cb=0.1;
Initial acid volume l
Va=0.05;
Dissociation constants
pKa1=6;pKa2=11;Ka1=10^-pKa1;Ka2=10^-pKa2;
Ionic product of water (also called the water dissociation constant)
Kw=10^-14;
Initial number of moles of acid present before titration begins
na0=CaVa;
Species distribution functions
alpha0[h_]:=h^2/(h^2+Ka1h+Ka1Ka2);alpha1[h_]:=Ka1h/(h^2+Ka1h+Ka1Ka2);alpha2[h_]:=Ka1Ka2/(h^2+Ka1h+Ka1Ka2);
Total volume
Vtot[x_]:=Va+(xna0)/Cb;
Charge balance equation
x=nb/na0; x is defined as moles of base added over initial moles of acid.
f[h_,x_]:=Module[{Ct,na,nb},na=na0;nb=xna0;Ct=na/Vtot[x];h+(nb/Vtot[x])-Kw/h-Ct(alpha1[h]+2alpha2[h])];
Arc-length continuation
Unknowns={h,x}
ds=0.005;(*arcstep*)nSteps=800;
(*Initialpoint*)x0=0.0;h0=10^-4.;sol={{x0,h0}};x=x0;h=h0;
Continuation loop; three steps:
(1) computes a tangent vector
(2) performs a predictor step along the tangent, then
(3) applies a corrector step using Newton iterations
(1) computes a tangent vector
(2) performs a predictor step along the tangent, then
(3) applies a corrector step using Newton iterations
Do[(*Jacobiancomponents*)fx=D[f[hvar,xvar],xvar]/.{hvar->h,xvar->x};fh=D[f[hvar,xvar],hvar]/.{hvar->h,xvar->x};(*Tangentvector*)tx=1;th=-fx/fh;(*Normalize*)norm=Sqrt[tx^2+th^2];tx=tx/norm;th=th/norm;(*Predictor*)xPred=x+dstx;hPred=h+dsth;(*Correctorsystem*)solNew=FindRoot[{f[hnew,xnew]==0,(xnew-xPred)tx+(hnew-hPred)th==0},{xnew,xPred},{hnew,hPred},MaxIterations->100];x=xnew/.solNew;h=hnew/.solNew;AppendTo[sol,{x,h}],{nSteps}]
Extract data
xVals=sol[[All,1]];hVals=sol[[All,2]];
pH
pHVals=-Log10[hVals];
Distribution fractions
a0Vals=alpha0/@hVals;a1Vals=alpha1/@hVals;a2Vals=alpha2/@hVals;
Titration curve
pHPlot=ListLinePlotTranspose[{xVals,pHVals}],
Out[]=
Distribution diagram
References
References
CITE THIS NOTEBOOK
CITE THIS NOTEBOOK
Titration of a diprotic acid by strong base
by Housam Binous
Wolfram Community, STAFF PICKS, May 27, 2026
https://community.wolfram.com/groups/-/m/t/3721709
by Housam Binous
Wolfram Community, STAFF PICKS, May 27, 2026
https://community.wolfram.com/groups/-/m/t/3721709