How does one calculate the pH of an aqueous solution of a weak acid and a weak base?

In order to create a simple program which calculates titration curves (also to provide some closure in the comments here) I am trying to come up with all the equations so I can calculate the equilibrium proton concentration for any given concentrations of any two given weak acids/bases.

This is a collection of what I've come up with so far and what I assume I still need. If someone could help me back on track I'd kindly appreciate it.

We're looking at the following reactions: \begin{align} \ce{HA &<=>[K_{\text{a, 1}}][K_{\text{b, 1}}] H+ + A- && (1) }\\ \ce{H+ + B- &<=>[K_{\text{b, 2}}][K_{\text{a, 2}}] HB && (2)} \end{align} A is the weak acid and B the weak base with the according equilibrium constants (the indices 1 and 2 refer to the acid and base respectively).

For the total masses I've got the following: \begin{align} \ce{[A]_{tot} &= [HA] + [A- ] && (3) }\\ \ce{[B]_{tot} &= [HB] + [B- ] && (4) } \end{align}

The equilibrium constants are linked via $$K_\text{a, 1} \times K_\text{b, 2} = \frac{\ce{[A- ][HB]}}{\ce{[HA][B- ]}}$$

Furthermore: $$\ce{[H+ ]_{eq}} = \frac{\ce{[A]_{tot}} K_\text{a, 1}}{\ce{[A- ]}} - K_\text{a, 1} = \frac{\ce{[HB]}}{K_\text{b, 2} (\ce{[B]_{tot} - [HB]})}$$

For the equilibrium proton concentration I've derived $$\ce{[H+ ]_{eq}} = K_\text{a, 1} \ce{[HA]} + K_\text{a, 2} \ce{[HB]} + K_\text{w} \ce{[H2O]}$$ where I neglect the influence of the water (the additional term $[\dots] + K_\text{w} \ce{[H2O]}$) since it is so small.

Now, I'm struggling with the following: $$\ce{[H+ ]_{tot}} = ?$$

I believe that with the last equation I will be able to solve for $\ce{[H+ ]_{eq}}$. But maybe I'm wrong there as well.

Thanks for any pointers.

• Here is a derivation and solution of this question. – Karsten Theis Mar 5 at 15:38

Equations and variables

To calculate the proton concentration in a solution as given in the question the following five equations are used for the following five unknown variables: $\ce{[H+ ]}$, $\ce{[HA]}$, $\ce{[A- ]}$, $\ce{[HB]}$ and $\ce{[B- ]}$.

Ion balance: $$\ce{[H+ ]} = \ce{[A- ] + [B- ]} + \frac{K_\text{w}}{\ce{[H+ ]}}$$

Mass balances: \begin{align} \ce{[A]_{tot}} &= \ce{[HA] + [A- ]} \\ \ce{[B]_{tot}} &= \ce{[HB] + [B- ]} \end{align}

Law of mass action: \begin{align} K_\text{a, 1} &= \frac{\ce{[H+ ][A- ]}}{\ce{[HA]}} \\ K_\text{a, 2} &= \frac{\ce{[H+ ][B- ]}}{\ce{[HB]}} \end{align}

Solution

Combining the above equations we get: $$\ce{[H+ ]} = \frac{K_\text{a, 1} \ce{[A]_{tot}} }{\ce{[H+ ]}+K_\text{a, 1}} + \frac{K_\text{a, 2} \ce{[B]_{tot}} }{\ce{[H+ ]}+K_\text{a, 2}} + \frac{K_\text{w}}{\ce{[H+ ]} }$$

After some reforming we get a fourth-order polynomial for the proton concentration: \begin{align} 0 = & \ce{[H+ ]^4} + \ce{[H+ ]^3}(K_\text{a, 1} + K_\text{a, 2}) \\ &- \ce{[H+ ]^2}(\ce{[A]_{tot}} K_\text{a, 1} + \ce{[B]_{tot}} K_\text{a, 2} - K_\text{a, 1} K_\text{a, 2} + K_\text{w}) \\ & -\ce{[H+ ]}\left[ (\ce{[A]_{tot}} + \ce{[B]_{tot}}) K_\text{a, 1} K_\text{a, 2} + K_\text{w}(K_\text{a, 1} K_\text{a, 2}) \right] \\ & - K_\text{w} K_\text{a, 1} K_\text{a, 2} \end{align}

• I would be very glad if somebody could verify my result. – tschoppi Dec 17 '13 at 23:55
• it seems fine but does this kinda equation have general solution? – santimirandarp Sep 16 '18 at 17:16

This is the way I would tackle the problem:

\begin{align} \ce{HA &<=>[K_\text{a}] H+ + A- && (1) }\\ \ce{B +H2O&<=>[K_\text{b}] BH+ + OH- && (2)} \end{align}

The mass balance writes:

\begin{align} \ce{[A]_{tot} &= [HA] + [A- ] && (3) }\\ \ce{[B]_{tot} &= [B] + [BH+ ] && (4) } \end{align}

The charge balance writes:

\begin{align} \ce{[A- ] + [OH- ]&=[H+] + [BH+ ] && (5) } \end{align}

Therefore, by introducing eq. (3) into the definition of $K_\text{a}$, one gets:

$$\ce{[A- ]} = \frac{\ce{[A]_{tot}} K_\text{a}}{\ce{[H+ ]}+K_\text{a}}$$

And using the charge balance (eq. 5), one writes:

$$\ce{[BH+ ] +[H+ ]}-\frac{K_\text{w}}{\ce{[H+ ] }} = \frac{\ce{[A]_{tot}} K_\text{a}}{\ce{[H+ ]}+K_\text{a}}$$

The same can be done for the base:

$$\ce{[BH+ ]} = \frac{\ce{[H+ ]}\ce{[B]_{tot}} K_\text{b}}{K_\text{b}\ce{[H+ ] }+K_\text{w}}$$

Putting the last two equations together, one obtains:

$$\frac{K_\text{w}}{\ce{[H+ ]}} + \frac{\ce{[A]_{tot}} K_\text{a}}{\ce{[H+ ]}+K_\text{a}}=\frac{\ce{[H+ ]}\ce{[B]_{tot}} K_\text{b}}{K_\text{b}\ce{[H+ ] }+K_\text{w}}+\ce{[H+ ]}$$

which is the desired equation with $\ce{[H+ ]}$ as the unique unknown variable.

Hope that helps.

• Thank you very much. However, I also just stumbled upon the charge balance thing and got my stuff sorted out (and subsequently posted an answer). – tschoppi Dec 18 '13 at 0:03

[H+]tot would have to equal [H+]eq. All of your sources of H+ are involved in the equilibria. If you were working with a weak acid and it's conjugate base you could just use the Henderson-Hasselbach equation, eliminating the need for a Kb.

If I understand correctly, this is a titration of a weak acid by a weak base (or vice versa). Therefore H+ would be neutralized immediately, as you add base. So the pH would start low (~pKa, I believe), then slowly increase to where all the acid would be used, and continue to slowly increase until ~pKb. But wow, that endpoint would be hard to find any other way than graphically!

• I think you're right, that $\ce{[H+ ]_{tot}} = \ce{[H +]_{eq}}$, but I just can't get the equations to work themselves down to one unknown variable (the proton concentration). – tschoppi Dec 17 '13 at 21:35
• At each point in the titration curve, the H+ concentration will need to be calculated individually. Taking into account how much has been consumed by the titration. And the equations will change based on your position in the curve. For example, when more acid is present, [H+] = Ka([HA]/[A-]) - [B-] (with all the concentrations adjusted for the additional volume). – lizard053 Dec 17 '13 at 21:50