A General Program for pH-calculations in a Mixture of Acids and Bases in Watersolutions. By Stig Johansson Bräkne-Hoby, Sweden. The Purpose. With the help of this program you will be able to caculate pH of a special acid or base or a number of these substances in a watersolution. Both concentration pH and activity pH may be calculated. If there are other reactions than hydrolysis the calculations may not be valid. The Mathematical Part of the solving consists of two sections. The first section consists of a complete algebraic solving with regard to the conditions of mass balance, charge balance and equilibriums for water, acids and bases. With the help of these conditions you will be able to get [H3O+] as the only unknown factor, if the values of concentrations and dissociation constants are known. [H3O+] will not be solved explicitly but exists in an implicit form. The second section of the calculation is performed with the help of a dator program, which is based on Newton-Raphson’s method. This method is iterative in according with the following formula, where [H3O+] is represented by X, and the derived function by F’(X): Xn+1 = Xn – F(Xn)/F’ (Xn) The iteration proceeds until ABS(Xn+1 - Xn) < ABS(Xn+1/1e10). From the formula we conclude that also the derivative F’ (X) must be calculated. The categories of acids and bases, which have been used as examples, have been taken from chemical handbooks for instance Handbook of Chemistry and Physics. It is always possible to discuss which categories and how many of each sort of acid and base will be represented. It is, however, very simple for the programmer to change and construct programs with different constituents. How large the program screen is depends on what sort of monitor is used. The underlying basis of the program (ConcpH,ActpH) is adjusted to a 800*600 17¨monitor. In using monitors with other performances it is possible to have more data on the screen without scrolling. Literature: Handbook of Chemistry and Physics. 64th Edition. !983-84 G Christian: Analytical Chemistry. New York 1994. A. Gordus: Analytical Chemistry. New York 1985. G Hägg: Kemisk reaktionslära. Uppsala 1965. A.E. Kehew: Applied Chemical Hydrogeology, New Jersey. 2001 E Lundqvist and A Sjöberg: Numeriska metoder. Uppsala 1970. Acid-Base-functions in the pH-program. In the functions, [H3O+] will be replaced by x and [OH-] by y. Mathematical principle. The final functions F(x) and F’(x) have been built by adding the partial functions fi(x) respective fi’(x) , which represent the different sorts of substances where the function f1 represents the shared water and the other fi the special acids and bases. For each of the acids and bases there is a complete solution, in which water is included, but in each of their final functions the solitary terms of y and x have been taken away, as their watervalues must not be added to the shared water represented by f 1 , which participates in all calculatioins. Kw=1.00E-14 (pKw=14.00) is default but can be changed 1 Calculating ConcpH. Pure water. OH H O H O OH K 1 3 3 y x f1 x y x 0 1 y x KW 2 2 KW x0 x K f 1 x W2 1 0 x f1 x Strong 1-protic acid C1 M HA H 2 O H 3O A HA OH A H O 3 y yx has already been C1 brought x and y C1 x 0 f 2 x C1 0 f 2 x 0 Strong 2-protic acid. C1 M H2 A C2 M NaHA H 2 A H 2O H 3O A NaHA Na HA HA H 2O H 3O A2 C3 M K 2 A 2 K A2 K2 A OH HA 2 A Na 2 K H O y HA 2A C 2C (1) C C C C HA A (2) K HA x A 3 2 3 2 2 1 2 3 3 2 Tot 2 2 KW x y y 4 x CTot 2 K 2 CTot C2 2C3 x 0 x K2 x K2 f3 x x CTot 2 K 2 CTot C2 2C3 0 x K2 x K2 f 3 x K 2 CTot x K 2 2 2 Weak 1-protic acid HA H 2 O H 3 O A C1 M HA C2 M NaA aq NaA Na A OH A Na H O y A C x 1 C C C HA A 2 K HA x A 3 3 2 1 2 Tot 4 KW x y K C Tot C2 x 0 Kx K C Tot f 4 x C2 0 Kx K C Tot f 4 x 0 K x 2 y Weak 2-protic acid. H 2 A H 2 O H 3 O HA C1 M H2 A C2 M NaHA C3 M K2 A aq NaHA Na HA aq K 2 A 2 K A 2 OH HA 2 A Na 2 K H O 1 y HA 2 A C 2C x 2 C C C C H A HA A 3 K H A x HA 4 K HA x A 2 3 2 2 3 1 2 3 Tot 2 2 1 2 2 2 KW x y y 5 K 1CTot x 2 K 1 K 2 CTot C 2 2C 3 x 0 K1 K 2 K1 x x 2 K1 K 2 K1 x x 2 f 5 x K 1CTot x 2 K 2 C 2 2C 3 0 K1 K 2 K1 x x 2 f 5x K 1CTot K 1 K 2 x 2 4 K 2 x K K 1 2 K1 x x 2 2 0 3 Weak 3-protic acid. C1 M H3 A H 3 A H 2 O H 3O H 2 A C2 M LiH 2 A aq LiH 2 A Li H 2 A C3 M Na2 HA aq Na2 HA 2 Na HA C4 M K3 A aq K 3 A 3 K A 3 OH H A 2 HA 3 A Li 2 Na 3 K H O y H A 2 HA 3 A C 2C 3C x 1 C C C C C H A H A HA A 2 K H A x H A 3 K H A x HA 4 5 K HA x A 2 3 2 2 3 2 2 1 2 3 3 4 Tot 3 3 2 4 3 2 1 2 3 2 2 2 2 3 3 KW x y y 6 K 1CTot x 2 2 K 1 K 2 CTot x 3K 1 K 2 K 3 CTot C 2 2C 3 3C 4 x 0 N N N N K1 K 2 K 3 K1 K 2 x K1 x 2 x 3 f 6 x K 1CTot x 2 2 K 1 K 2 CTot x 3K 1 K 2 K 3 CTot C 2 2C 3 3C 4 0 N N N f 6 x 2 K 1CTot x K 1CTot x 2 N 2 K 1 K 2 CTot 2 K 1 K 2 CTot x N 3K 1 K 2 K 3 CTot N 0 N N N2 N2 N2 N K1 K 2 2 K1 x 3x 2 4 Weak 4-protic acid C1 M H4 A H 4 A H 2 O H 3O H 3 A C2 M LiH 3 A aq LiH 3 A Li H 3 A C3 M Na 2 H 2 A aq Na 2 H 2 A 2 Na H 2 A 2 C4 M K 3 HA aq K 3 HA 3K HA 3 C5 M Rb 4 A aq Rb 4 A 4 Rb A 4 OH H A 2 H A 3 HA 4 A Li 2 Na 3 K 4 Rb H O y H A 2H A 3HA 4A C 2C 3C 4C x 1 C C C C C C H A H A H A HA A 2 K H A x H A 3 K H A x H A 4 K H A x HA 5 6 K HA x A 2 3 3 3 4 2 2 3 4 2 2 3 1 3 2 3 4 5 Tot 1 4 2 3 3 2 4 3 4 5 2 3 4 2 3 2 2 2 3 3 4 4 KW x y 7 x 3 K 1CTot 2 x 2 K 1 K 2 CTot 3xK1 K 2 K 3 CTot 4 K 1 K 2 K 3 K 4 CTot C 2 2C 3 3C 4 4C 5 x 0 N N N N 3 2 x K 1CTot 2 x K 1 K 2 CTot 3 xK1 K 2 K 3 CTot 4 K 1 K 2 K 3 K 4 CTot f 7 x C 2 2C 3 3C 4 4C 5 0 N N N N N K1 K 2 K 3 K 4 K1 K 2 K 3 x K1 K 2 x 2 K1 x 3 x 4 y 3K 1 x 2 CTot K 1 x 3 CTot N 4 K 1 K 2 xCTot 2 K 1 K 2 x 2 CTot N 3K 1 K 2 K 3 CTot 3K 1 K 2 K 3 xCTot N 4 K 1 K 2 K 3 K 4 CTot N 0 N N N N2 N2 N2 N2 N K 1 K 2 K 3 2 K 1 K 2 x 3K 1 x 2 4 x 3 f 7 x 5 Strong 1-protic base. C M H O OH C B H 2 O BH OH B OH BH y 3 C x y C x 0 f 8 x C 0 f 8 x 0 Strong 2-protic base. B H 2 O BH OH C1 M B C2 M BHCl C3 M BH 2 Br2 aq BH 2 Br2 BH 2 2 Br 2 2 3 2 2 3 2 2 1 2 3 Tot 2 2 2 KW x y y C 2 2C 3 4 CTot K W 2 K b 2 x x0 K W Kb2 x f 9 x C 2 2C 3 CTot K W 2 K b 2 x 0 K W K b 2 x CTot K b 2 K W K W 1 2 b2 f 9 x B 0 aq BHCl BH Cl OH Cl Br BH 2 BH H O y C 2C BH 2 BH x C C C C B BH BH 3 K BH BH y dvs K b2 x 2 0 6 Weak 1-protic base. B H 2 O BH OH C1 M B C2 M BHCl aq BHCl BH Cl OH Cl BH H O y C BH x C C C B BH K B BH y 3 1 2 2 1 2 Tot 3 b 4 KW x y y C2 K b CTot x x0 K b x KW K b CTot x 0 K b x KW f10 x C 2 f10 x K b K W CTot K b x K W 2 Weak 2-protic base. B H 2 O BH OH C1 M B C2 M BHCl C3 M BH 2 Br2 aq BHCl BH Cl aq BH 2 Br2 BH 2 2 2 Br OH Cl Br BH 2 BH H O 2 2 y C2 3 BH 2 BH 2 2C3 2 C1 C 2 C3 CTot B BH BH 2 B K b1 BH y BH K b2 BH 2 2 y C 2 2C3 2 1 2 3 y KW x y x 4 5 K b1CTot K W x K b1 K b 2 x 2 K b1 K W x K W 2 2 K b1 K b 2 CTot x 2 K b1 K b 2 x 2 K b1 K W x K W 2 x0 K b1CTot K W x 2 K b1 K b 2 CTot x 2 0 N N 2 2 K C 4 K b 2 x K W K b1 CTot x2 K b 2 x K W f11 x b1 Tot 0 2 N N f11 x C 2 2C3 N K b1 K b 2 x 2 K b1 K W x K W 2 7 The calculated partial functions will be added as below F(x)=f1(x) + f2(x) + .... +f11(x) = 0 och F´(x)=f´1(x) + f´2(x) + ..... + f´11(x) = 0 After that the iterative expression xn+1 = xn - F(xn)/F´(xn) is used until ABS(xn+1-xn) <ABS(xn/1e10). [H3O+] = x2, where 1. 10-15 <= x2 =<1. At last the final concentrations can be calculated according to the following. Calculation of the final concentrations at the calculated pH. Strong 1-protic acid. C M HA 0 HA H 2 O H 3 O A HA A C C1 M H2A Strong 2-protic acid. H 2 A H 2O H 3O A C2 M HA H 2 A 0 C3 M A 2 1 H O A 2 C1 C 2 C 3 C Tot HA A 2 K 2 HA HA KC A CK x x 2 Tot 2 2 3 Tot 2 K2 x Weak 1-protic acid. C1 M HA HA H 2 O H 3O A C2 M A C1 C 2 CTot HA A K HA H 3O A A Kx CK Tot 1 2 HA CTot x xK Weak 2-protic acid. C1 M H2A H 2 A H 2 O H 3 O HA C2 M HA HA H 2 O H 3 O A 2 C3 M A 2 2 K H A x HA 3 K HA x A C1 C 2 C 3 C Tot H 2 A HA A 2 1 1 2 2 2 A x K 1 K 2 C Tot 2 2 K1 x K1 K 2 HA x K 1C Tot x 2 K1 x K1 K 2 H 2 A C Tot x 2 x 2 K1 x K1 K 2 8 Weak 3-protic acid. M H3A C2 M H 2 A M HA C4 M A 3 A K K H 2 A x HA K HA x A K2 H2 A 2 2 3 HA K K K 3 K1 K 2 x K1 x x 3 1 K 1C Tot x 2 K 1 K 2 C Tot x 2 K 3 K1 K 2 x K1 x 2 x 3 C Tot x 3 H 3 A K1 K 2 K 3 K1 K 2 x K1 x 2 x 3 1 2 3 4 2 2 2 3 K 1 K 2 K 3 C Tot 3 1 K 1 H 3 A x H 2 A 2 C3 C1 C 2 C 3 C 4 C Tot H 3 A H 2 A HA 2 A 3 C1 K1 K 2 K 3 K1 K 2 x K1 x 2 x 3 Weak 4-protic acid. C1 M H4A C2 M H 3 A C3 M H 2 A 2 C4 M HA 3 C5 M A 4 A K K 4 1 2 K 1 H 4 A x H 3 A 1 2 3 x HA 4 x A 5 K 2 H 3 A x H 2 A 2 K 3 H 2 A 2 K 4 HA 3 K 3 K 4 C Tot N H 4 A CTot x C1 C 2 C 3 C 4 C Tot H 4 A H 3 A H 2 A 2 HA 3 A 4 HA K K 3 1 2 K 3 C Tot x N 3 4 H 2 A 2 K 1 K 2 C Tot x 2 N H 3 A K 1C Tot x 3 N 4 N K1 K 2 K 3 K 4 K1 K 2 K 3 x K1 K 2 x 2 K1 x 3 x 4 N Strong 1-protic base. C M B B H 2 O BH OH B 0 BH C 9 Strong 2-protic base. B H 2 O BH OH C1 M B C2 M BH C3 M B H2 B 0 C1 C 2 C 3 C Tot BH BH 2 2 2 K b 2 BH BH 2 y 2 b2 C Tot b2 y 2 1 2 BH KC x KK K b 2 C Tot x K b2 x KW 3 KW x y BH KK 2 Tot W b2 W Weak 1-protic base. B H 2 O BH OH C1 M B C2 M BH C1 C 2 C Tot B BH K b B BH y 2 3 KW x y BH KK C y KK xC Kx b Tot b b B Tot b W 1 C Tot y C Tot K W K b y K b x KW Weak 2-protic base. B H 2 O BH OH C1 M B C2 M BH C3 M BH 2 K b1 B BH 2 K b 2 BH 2 BH K N 2 N K b1 K b 2 x 2 K b1 K W x K W b1 C Tot K W x N y BH y K W xy B CTot K W C1 C 2 C 3 C Tot B BH BH 2 2 2 2 1 2 3 4 BH K 2 2 b1 K b 2 C Tot x 2 N Acid-Base-functions in the ActpH-program. It is necessary to know the values of the ionic strength activity coefficients of the ions in a solution if the ActpH is to be calculated The ionic strength can according to all literature be calculated as below (2) 10 1 2 Ci Z i 2 Ci and the Zi conc the of ch arg e the matter of the i matter i are all the ions in the solution The activity coefficient is calculated for each of the ions and is according to (3) log f i 1 Bd i AZ i 2 EDHE : extended Debye Hückel equation fi = the activity coefficient of the ion Zi = the charge of the ion di = hydrated diameter of the ion = the ionic strength of the solution A and B are dependent on the temperature and their values can be received from tables, for instance in (3). It will be seen that each of them appear as practically linear functions between 0oC and 60oC. In the program, A and b have been input as functions: A = (8.98e-4).T + 0.242 t= temp i oC 0<=t<=60 B = (1.61e-4) T + 0.28 . EDHE is valid if <= 0.1 but it can according to (2) be valid for Davies modification log f i AZ i2 1 Bd i 0.10Z i2 The ionic activity can now be calculated aZi = Zi.fi <=0.6 if using the Davies mod ification aZi = the ionic activity. When calculating ConcpH the conc of the ions and the thermodynamic dissociation constants from tables are used. These constants are valid at unlimited dilution and can not be used together with conc of ions when calculating ActpH, rather, the concentration dissociation constants must be calculated from ionic activity coefficients and used with concentrations. This will give conc. [H+], which multiplied by its activity coefficient, gives activity [H+] or {H+}. In this program the activities of the ions have been calculated and with the help of these, the thermodynamic dissociation constants have been modified in such a manner that the concentrations can be used. After calculating of the ionic strength from the new values of the concentrations the calculations of the ion activity coefficients have been done, the ionic activities can be calculated by multiplying the concentrations of the ions by their activity factors. Ki = thermodynamic dissociation constant, and the corresponding concentration dissociation constant = aKi or bKi for the corresponding dissociation constant concerning acids and bases. Kf = the effect of the activity factors on converting of K i to aKi and bKi . After calculation of the participant aKi and ion conc values have been input, the NewtonRaphson method is used to calculate the ActpH in the same way as for ConcpH, but using an iterative procedure. 11 i The following will show how to calcualte aKi or bKi Here is one example of rhe transfer 2-protic weak acid with the thermodynamic dissociation constants K 1 and K2 H 2 A H 2 O H 3 O HA H O HA H O f HA f K H A f H A H O HA f f K H A f H O HA and K f f aK f H A H O HA K K aK K aK K H A H 3O 3 3 HA 1 2 2 H2 A H 3O 3 HA 1 2 Input H2 A H 3O 3 1 2 H2 A 1 1 1f 1 1f HA H 2 O H 3 O A 2 3 1 HA 1f 2 H O A H O f A f K HA f H A H O A f f K HA f H O A and K f f aK f HA H O A K K aK K aK K H A 2 2 H 3O 3 3 2 A2 HA 2 H 3O 3 A2 2 HA Input 2 H 3O 3 2 A2 2f HA2 2 2 2 2f 2 3 2 2f The program starts with calculating the conc pH. After that the ionic strength is calculated. Now the activity coefficient for every participating ion can be determined and the aKi-values then calculated. The new values (initial “Ed concentrations”) of every ion concentration are used in the next loop of calculation, giving revised new values. This continous until two following values of [H+] are sufficiently near each other. [H+] is then multiplied by its activity factor to give {H+}. The values you find of End concentrations after the calculation are just concentartions and not activities. I have taken methods and formulas from Gary Christian (2) and Adon Gordus (3). To summarize the approach: 1. Calculate ConcpH using thermodynamic equilibrium constant, Ki, and the initial concentrations 2. Calculate the ionic strength 3. Calculate activity coefficients 4. Calculate the concentration equilibrium constant, aKi (or bKi) from Ki and the activity coefficients. 5. Use aKi (or bKi) and the initial concentrations [H+] (or [OH-]), and End Concentrations. Use the End Concentrations to give a new ionic strength and recalculate [H+] (or [OH-]) in an iterative fashion till [H+] (or [OH-]) is constant. 6. Multiply the final [H+] (or [OH-]) by its activity coefficient to get activity of H+ (or OH-) and then ActpH. 12 2-protic strong acid with the thermodynamic dissociation constant K2 H 2 A H 2 O H 3 O HA HA H 2 O H 3 O A 2 H O A f f HA f H O A and HA K2 H 3 K2 H 3 O f H O A 2 f A2 O A 2 3 HA HA f HA 2 H 3O 3 A2 HA Input aK 2 2 K2 f 3 K 2 aK 2 K 2 f aK 2 fH 3O f A2 f HA H 3O A 2 K2 K2 f HA 1-protic weak acid with the thermodynamic dissociation constant K 1 HA H 2 O H 3 O A H O A f K HA f H O A aK HA K1 H 3 H 3 O f H O A f A O A 3 HA HA f HA 3 H 3O f A 1 Input 3 1 K 1 aK 1 K 1 f HA and aK 1 K1 f f H O f A 3 f HA H 3O A K1 K1 f HA 13 2-protic weak acid with the thermodynamic dissociation constants K 1 and K2 H 2 A H 2 O H 3 O HA H O HA H O f HA f K H A f H A H O HA f f K H A f H O HA and K f f aK f H A H O HA K K aK K aK K H A H 3O 3 3 HA 1 2 2 H2 A H 3O 3 HA 1 2 Input H2 A H 3O 3 1 1f 2 H2 A 1 1 1f 1 1f HA H 2 O H 3 O A 2 3 1 HA 2 H O A H O f A f K HA f H A H O A f f K HA f H O A and K f f aK f HA H O A K K aK K aK K H A 2 2 H 3O 3 3 2 A2 HA 2 H 3O 3 A2 2 HA Input 2 H 3O 3 2 A2 2f HA2 2 2 2 2f 2 3 2 2f 14 3-protic weak acid with the thermodynamic dissociation constants K 1 K2 and K3 H 3 A H 2 O H 3O H 2 A H O H A H O f H A f K H A f H A H O H A f f K H A f H O H A and K f f aK f H A H O H A K K aK K aK K H A 3 H 3O 3 2 2 H 2 A 1 3 3 H3 A 3 H 3O 2 H 2 A 1 3 H3 A 3 Input H 3O 2 1 H 2 A 1f 3 H3 A 1 1 1f 2 1 1f H 2 A H 2 O H 3 O HA 2 3 H O HA H O f HA f K H A f H A H O HA f f K H A f H O HA and K f f aK f H A H O HA K K aK K aK K H A 2 2 H 3O 3 3 2 HA2 2 2 H 3O 3 HA2 2 H 2 A 2 2 H 3O 3 2 H 2 A 2 2f 2 2f HA H 2 O H 3O A 3 2 3 2 2 HA2 2f 2 2 HA2 2 Input 3 1 2 H O A H O f A f K HA f H A H O A f f K HA f H O A and K f f aK f HA H O A K K aK K aK K H A 3 3 H 3O 3 3 2 3 A3 2 HA2 3 H 3O 3 A3 2 3 HA2 Input 3 H 3O 3 2 3 A3 3f HA2 3 3 3 3f 3 3 2 3 3f 15 4-protic weak acid with the thermodynamic dissociation constants K 1 K2 K3 and K4 H 4 A H 2 O H 3O H 3 A H O H K1 3 H 4 A H O H K1 Input aK 1 3 H O f A 3 3 3 H 4 A 3 3 H 3 A H 2 O H 3O H 2 A 2 A 3A H O H A H O f K H A H H O H A f f K H A f H O H A aK and H A 2 3 2 H 3O 3 2 H 3O 3 A 2 3 2 aK 2 f H O f H 3 fH 3 H 3O 3 2 3 HA3 2 H 2 A2 2 3 H 3O HA3 2 3 H 2 A2 2 3 H 3O 3 2 3 H 3 22 3 3 3 3f 2 3 4 3 3 3 4 3 3 3f H 3 A 3f 2 H 3 A H 2 O H 3O A 2 H O H 2 A 2 K2 3 K2 f H 3 A 3 3 3 4 3A 2A H O HA H O f HA f K H A H A f H O HA f f K H A f f f H O HA aK and K H A f H O HA K K aK K aK K H A H O A H O f A f K HA HA f 2 2 H 3 A K2 f 2 K 2 aK 2 K 2 f 2A H 2 A2 3 Input H 3 A H 2 O H 3 O HA f H 2 A 2 f H 3 H2 A f H4A 3A 2 2 2 3 3 f H O f H K1 f and H 3O H 3 A K1 aK 1 H 4 A K1 f 3 2 3 Input 3A 4 K 1 aK 1 K 1 f 4 H 4 A f H A H O H H 3 A f H H 4 A f H A A f H O f H 3 H 3O 2 4 H 3O A4 3 HA3 H O A f K HA f H O A aK HA 4 3 H 3O f A4 3 4 HA3 Input 4 3 4 K 4 aK 4 K 4 f 3 and aK 4 K4 f f H O f A4 3 f HA3 H O A 4 K4 3 K4 f HA 3 16 2-protic strong base with the themodynamic dissociation constant K 2 B H 2 BH OH BH H 2 O BH 2 BH OH BH f OH f OH K BH f BH BH OH f f BH OH f K BH f BH BH OH and K f Input bK f BH K BH OH K bK K bK K BH 2 2 BH 2 2 OH BH 2 BH 2 2 OH 2 BH 2 f BH BH 2 f OH BH 2 2 f OH 2f 2 BH 2 2 2 2f 2 2f 1-protic weak base with the thermodynamic dissociation constant K 1 B H 2 O BH OH K1 BH OH BH f B BH OH f K1 B f B bK1 Input BH BH OH BH B f B f OH BH OH f K1 bK1 K1 f BH f OH fB f BH f OH Kf1 and bK1 B B OH f OH fB K1 BH OH B K1 f 2-protic weak base with the thermodynamic dissociation constants K1 och K2 B H 2 O BH OH K1 BH OH BH f B BH OH f K1 B f B bK 1 Input BH OH BH H 2 O BH 2 OH B B f B f OH BH OH f B K1 f and bK 1 OH f OH K 1 bK 1 K 1 f BH BH BH f OH fB f BH f OH fB K1 BH OH B K1 f BH OH BH f OH f K BH f BH BH OH f f K f BH BH OH and K f f bK f BH K BH OH K bK K bK K BH 2 2 BH 2 2 OH BH 2 BH 2 OH 2 BH 2 Input BH 2 2 OH 2f BH 2 2 2 2 2f 2 2f 17