# find distribution diagram for acetic acid # 1: provide equilibrium constants for all equilibrium reactions Kw = 1.00e-14 Ka = 1.75e-5 # 2: provide total concentration for all mass balance equations C = 0.1 # 3: set up master variable pH = seq(1, 14, 0.0001) # 4: calculate concentrations for all species in system H3O = 10^-pH OH = Kw/H3O HA = C * H3O/(Ka + H3O) A = C - HA # 5: plot distribution diagram as function of concentration or as # function of log(conc) plot(x = pH, y = HA, type = "l", col = "blue", lwd = 2, xlab = "pH", ylab = "concentration of HA or A-", main = "Distribution Diagram for Acetic Acid") lines(x = pH, y = A, col = "red", lwd = 2) legend(x = "right", legend = c("HA", "A-"), lty = 1, lwd = 2, col = c("blue", "red"), bty = "n") grid(col = "black") plot(pH, log10(HA), type = "l", col = "blue", lwd = 2, xlab = "pH", ylab = "log(conc) of HA or A-", ylim = c(-10, 0), main = "Log Distribution Diagram for Acetic Acid") lines(pH, log10(A), col = "red", lwd = 2) lines(pH, log10(H3O), lwd = 0.25, col = "lightgray") lines(pH, log10(OH), lwd = 0.25, col = "lightgray") legend(x = "right", legend = c("HA", "A-"), lty = 1, lwd = 2, col = c("blue", "red"), bty = "n") grid(col = "black")