In solving chemical equilibrium, we often make approximation to simplify the mathematical solution. For instance, the approximation of negligible dissociation of weak acids. Here, we will explore the use of R to solve equilibrium without approximations. We find the equation to solve through aplication of a systematic analysis of equilibrium, which takes into account the equilibrium, charge balance, and mass balance expressions.
We can show four equations:
HF dissociation
\(HF \rightleftarrows H^+ + F^-\)
\(K_a = \large \frac{[H^+][F^-]}{[HF]} = 6.8 \times 10^{-4}\)
Water Dissociation
\(H_2O \rightleftarrows H^+ + OH^-\)
\(K_w = [H^+][OH^-]] = 10^{-14}\)
Mass Balance
\([HF]_i = [HF] + [F^-]\)
Charge Balance
\([H^+] = [F^-]+ [OH^-]\)
Successively substituting the mass balance, charge balance, and \(K_w\) into the dissociation expression:
eliminate \([HF]\)
\(K_a = \large \frac{[H^+][F^-]}{[HF]_i-[[F^-]]}\)
eliminate \([F^-]\)
\(K_a = \large \frac{[H^+]([H^+]-[OH^-])}{[HF]_i-[H^+]+[OH^-]}\)
eliminate \([OH^-]\)
\(K_a = \large \frac{[H^+]([H^+]-\frac{K_w}{[H^+]})}{[HF]_i-[H^+]+\frac{K_w}{[H^+]}}\)
Finally, simplifying a bit:
\(K_a\times([HF]_i[H^+]-[H^+]^2+K_w)-([H^+]^3-K_w[H^+] = 0\)
We can solve this for \([H^+]\) using the uniroot command.
Ka <- 6.8 * 10^-4
Kw <- 10^(-14)
CHF <- 0.0010
Ka
## [1] 0.00068
Kw
## [1] 1e-14
HFFunc <- function(H) {
Ka * (CHF*H - H^2 + Kw) -(H^3-Kw*H)
}
Hroot <- uniroot(HFFunc,c(10^-6,10^-2),tol = 10^-18)
hC <- Hroot$root
hC
## [1] 0.0005519641
solpH <- -log(hC,base = 10)
solpH
## [1] 3.258089
# compare with approximate method
hapx <- sqrt(0.001 * Ka)
hapx
## [1] 0.0008246211
pHapx <- -log(hapx,base=10)
pHapx
## [1] 3.083746
We can also make a graphical illustration of root finding. We can explore the value of HFFunc for values of H+ ariund the root.
phseq <- seq(3.2,3.4,0.01)
phseq
## [1] 3.20 3.21 3.22 3.23 3.24 3.25 3.26 3.27 3.28 3.29 3.30 3.31 3.32 3.33 3.34
## [16] 3.35 3.36 3.37 3.38 3.39 3.40
hval <- 10^-phseq
hval
## [1] 0.0006309573 0.0006165950 0.0006025596 0.0005888437 0.0005754399
## [6] 0.0005623413 0.0005495409 0.0005370318 0.0005248075 0.0005128614
## [11] 0.0005011872 0.0004897788 0.0004786301 0.0004677351 0.0004570882
## [16] 0.0004466836 0.0004365158 0.0004265795 0.0004168694 0.0004073803
## [21] 0.0003981072
val <- HFFunc(hval)
val
## [1] -9.285051e-11 -7.366706e-11 -5.592871e-11 -3.954115e-11 -2.441606e-11
## [6] -1.047071e-11 2.372399e-12 1.418583e-11 2.503756e-11 3.499124e-11
## [11] 4.410651e-11 5.243921e-11 6.004165e-11 6.696282e-11 7.324858e-11
## [16] 7.894192e-11 8.408307e-11 8.870971e-11 9.285714e-11 9.655839e-11
## [21] 9.984442e-11
plot(phseq,val)