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^-]}{[HA]} = 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 [H^+]([H^+]-\frac{K_w}{[H^+]})\)
\(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.010
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)
Hroot
## $root
## [1] 0.002289753
##
## $f.root
## [1] 0
##
## $iter
## [1] 12
##
## $init.it
## [1] NA
##
## $estim.prec
## [1] 9.729952e-07
We can also make a graphical illustration of root finding. We can explore the value of HFFunc for values of H+ ariund the root.
Kh <- 0.0034
Khyd <- 0.0026
Ka1 <- 1.67 * 10^-4
Ka2 <- 5.6 * 10^-11
Kw <- 1.00 * 10^-14
ca <- 1.41 * 10^-5 # concentration of co2(aq)
Kh
## [1] 0.0034
Khyd
## [1] 0.0026
Ka1
## [1] 0.000167
Ka2
## [1] 5.6e-11
Kw
## [1] 1e-14
ca
## [1] 1.41e-05
froot3 <- function(H)
{H^3 - Kw*H - Ka1 * Khyd * ca * H - 2.0 * Ka1 * Ka2 * Khyd * ca}
X <- uniroot(froot3, c(10^(-6),10^(-4)), tol = 10^(-18))$root
X
## [1] 2.476388e-06
pH <- -log10(X)
pH
## [1] 5.606181
# graph of froot3 in area around solution
ph <- seq(5.5,5.7,0.02)
ph
## [1] 5.50 5.52 5.54 5.56 5.58 5.60 5.62 5.64 5.66 5.68 5.70
h <- 10^-ph
h
## [1] 3.162278e-06 3.019952e-06 2.884032e-06 2.754229e-06 2.630268e-06
## [6] 2.511886e-06 2.398833e-06 2.290868e-06 2.187762e-06 2.089296e-06
## [11] 1.995262e-06
val <- froot3(h)
val
## [1] 1.223031e-17 9.022593e-18 6.302128e-18 4.002739e-18 2.066941e-18
## [6] 4.448060e-19 -9.070142e-19 -2.026146e-18 -2.945236e-18 -3.692601e-18
## [11] -4.292791e-18
plot(ph,val)
# the pH of standing water is 5.6