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.