This second article continues my journey of acid/base titrations. In the previous article (https://daniloroccatano.blog/2020/04/14/acidsand-bases-equilibrium/), I showed how to calculate an acid-base equilibrium for strong acids and bases. This article also describes subroutines for titrations of monoprotic weak acids and bases. The method I used solves the pH calculation precisely and is based on an article published in the chemistry journal “Rassegna chimica” by Prof Luigi Campanella (and Dr G. Visco) in 1985. I received a copy of the article from the author while attending his analytical chemistry course at the University “La Sapienza” in Rome. I remember writing a program for the study of titrations was fun and stimulating, but it helped me understand the subject thoroughly. I recommend that the young reader try to convert the program into a modern language more familiar to you (e.g., Python) to understand its functioning better.
Titration of a weak acid with a strong base
Let us consider the ion concentrations at various stages of titration. We indicate the concentration of the acid
in a volume
solution, with the concentration of the titrant
and
the volume of the titrant added.
The acid dissociation constant is equal to
from which
using the relation and replacing
we obtain
from which we can derive
Substituting the previous relation into the charge equilibrium
we get
Expanding the previous relation, we get the following cubic equation:
Solving the equation using, for example, Newton’s method, one can find the initial pH.
After the addition of the titrant, the electroneutrality condition changes to
with and
The values of these concentrations change with the addition of the titrant volume () as
with and
the solution’s initial volume, the acid’s initial concentration and the titrant base.
Then using the charge equilibrium condition as in the previous derivation, we arrive at the new equation:
The following figure shows an example of a titration curve for a weak monoprotic acid with a strong base.

Titration of a weak base with a strong acid
Proceeding as in the previous case, we first obtain a similar equation from which to calculate the concentration of hydroxyl ions:
With the addition of the volume of the acid titrant, the above equation changes to
The following figure shows an example of a titration curve on a weak base with a strong acid.

Figure 2: Example of a titration curve of a weak base with a strong acid.
Titration of a weak base with a weak acid
For completeness, we add equations for the titration of a weak acid with a weak base. This type of titration is rarely performed because it is challenging to identify the endpoint.
The derivation follows the same procedure based on the electroneutrality condition of the solution. The following are only the final fourth-order equations used in the BASIC program.
The following equation gives the initial proton concentration of the weak acid as in the previous case:
With the addition of the volume of the weak base as a titrant the above equation change to
The following figure shows an example of a titration curve for a weak acid with a weak base.

The calculation of the roots of polynomials of proton concentrations with the Newton-Raphson
The values of the concentration of and
are obtained using the method of tangents or Newton–Raphson. The method consists in substituting the tangent to the curve to
for the curve itself, starting from a concentration point close to the one sought. For example, the value of the first point (
) can be taken corresponding to to
It is therefore assumed that the approximate value of the root is the value of the abscissa:
where the tangent line (of inclination ) intersects the axis of
in the corresponding interval at the pH range 1-14. Iteratively, the new point at
is used to obtain a new approximation using the general formula:
which increases the accuracy of the root value. The procedure is stopped when the accuracy level is reached.
The program in BASIC language
The curves in this article were obtained with the BASIC program shown in the appendix of the Italian version of this article. This is an updated version of the program I mentioned in the introduction. I used the QB64 open-source compiler (https://www.qb64.org/portal) to develop the program. This BASIC compiler is compatible with the QuickBasic. QB64 first translates the program into C ++ which then compiles it with a C ++ compiler. Therefore the resulting executable is considerably faster than a BASIC interpreter.
This program version also allows the simulation of titrations with weak base or weak (mono) protic acid. The program shall use predetermined values for titration parameters which may be modified. Titration can be done step by step by adding aliquots of acid and bases or entering a negative number.
The program is distributed for educational purposes and is not guaranteed to be free from programming bugs. So, if you find errors or have suggestions, feel free to comment. If you find it interesting, you could also develop it further.

