# program calculating pH - Base Acid Titration and Equilibria - finding equilibrium

For a detailed discussion on methods of calculating pH and for the outline of derivation of the formula displayed below check out our lectures on pH calculation (more specifically calculating pH of a salt solution section).

Calculating pH BATE calculates equilibrium state of mixture of acid and base and pH of this mixture always in the same manner.

Solution containing mixture of acid and base is described by a set of equations:

- acid number of moles balance,
- base number of moles balance,
- charge balance,
- acid dissociation equilibria (one for every step of dissociation),
- base dissociation equilibria (one for every step of dissociation),
- water ionization constant.

As we need method of calculating pH we can combine all these equations into one, containing only constants and H^{+} concentration:

Here m is a number of base dissociation steps and n number of acid dissociation steps. K_{a} and K_{b} are overall dissociation constants for acid and base respectively, K_{w} is water ionization constant. C_{a} and C_{b} are analytical (total) concentrations of acid and base.

This equation can be rearranged into polynomial form, which is rather easily solved numerically using Newton method. Calculating pH we could also try to numerically solve full set of equations - but approach used gives faster code at the price of additional work done when deriving above equation.

For the titration curves concentrations of titrant and titrated substance (C_{a} and C_{b}) are first calculated for every curve point taking volume changes into account. Then program starts calculating pH for every curve point in usual way.

## Debye-Hückel equation

Calculating pH we have to remember about its thermodynamic definition - minus log of H^{+} activity. To calculate activities of ions we use Debye-Hückel theory. Ionic strength is defined as:

The activity coefficients are calculated as:

where C_{i} and z_{i} are concentration and charge of i^{th} ion present in the solution.

Calculations of ionic strength and activity coefficients are done iteratively, using concentrations of all ion forms calculated as a function of [H_{3}O^{+}].