We discuss our use of SageMathCell, a webbased, opensource mathsolver, in conjunction with the systematic method, to solve problems involving multivariable equilibrium reactions while avoiding the use of simplifying approximations. Students initially face a steep learning curve, but after about a week are able to solve fairly complex equilibrium problems in just minutes. We find this to be an excellent first introduction to coding, which students will likely encounter elsewhere in their academic or work careers. For those instructors who use traditional “ICE” tables but still want to give their students exposure to coding, we also provide a representative example of simple SageMath code.
Introduction
SageMathCell is a web interface for SageMath, an opensource mathematics software system that uses a Pythonbased language. Our students use SageMathCell to solve problems involving equilibrium reactions using the systematic method. The systematic method relies on an engineering model that incorporates the principles of charge and mole balance to allow one to write a series of algebraic equations to model chemical systems at equilibrium.^{1,2,3,4} This method is an extremely versatile alternative to ICE tables as it allows one to solve for multiple unknowns simultaneously while avoiding simplifying approximations. For example, the systematic method accounts for the autoionization of water in problems involving weak acid and weak base equilibria; in contrast, most general chemistry textbooks arbitrarily avoid using dilute solutions of acids and bases and instead choose relatively concentrated solutions of acids and bases with comparatively large K values in order to ignore the contributions of the autoionization of water. Table 1 lists pH values of weak acid solutions calculated using both the systematic method and ICE tables. Acetic acid is a commonly used example in textbooks because it has a relatively high K_{a} value. Even at very dilute concentrations, the respective calculated pH values are equivalent up to three decimal places. The calculated pH values start to vary significantly, however, for an acid such as hypoiodous acid (K_{a} = 2.3x10^{11}), even at fairly high concentrations.
Acid 
K_{a} 
[HA]_{initial} (M) 
Calculated pH (systematic method) 
Calculated pH (ICE table) 
Acetic acid 
1.8x10^{5} 
1.00 
2.373 
2.373 


1.00x10^{1} 
2.875 
2.875 


1.00x10^{2} 
3.382 
3.382 


1.00x10^{3} 
3.902 
3.902 


1.00x10^{4} 
4.464 
4.464 


1.00x10^{5} 
5.145 
5.145 
Hypoiodous acid 
2.3x10^{11} 
1.00 
5.319 
5.319 


1.00x10^{1} 
5.818 
5.819 


1.00x10^{2} 
6.310 
6.319 


1.00x10^{3} 
6.741 
6.819 


1.00x10^{4} 
6.955 
7.319 


1.00x10^{5} 
6.995 
7.819 
Table 1. Comparison of pH values calculated via the systematic method and ICE tables.
We first introduce our students to the systematic method and SageMath using problems involving a single equilibrium reaction. Below is a representative example of student work using the systematic method to solve a simple gas phase equilibrium problem with three variables (figure 1):
Example 1: A chemist adds 5.0 M hydrogen gas and 4.0 M iodine gas into a closed container. Determine the concentrations of all the gases once the system has achieved equilibrium.
Figure 1. Student work using the systematic method to solve a simple equilibrium problem.
After assigning variables to each species, the student defined the input (initial) and output (equilibrium) concentrations, along with the known K_{c} value. Because there are three unknowns, the student then wrote three equations: the K_{c} expression and mole balance equations for hydrogen and iodine.
Below is the corresponding SageMathCell code for the above problem (Figure 2):
Figure 2. SageMathCell code to solve the equations developed in Figure 1.
Students are provided with the last two lines of code as a template (these lines tell SageMath to output solutions in decimal form). Students write the remainder of the code themselves by simply listing the variables and equations they wrote. SageMath often provides multiple solution sets, including any negative solutions, and students must choose the solution set that makes physical sense and report their answers in terms of the actual chemical species:
Figure 3. Solutions to Example 1 calculated from equations in Figure 1 and SageMathCell code in Figure 2.
It generally takes students about a week to become proficient at using SageMath. At first, students often make syntax errors because they forget to include coding elements like multiplication symbols, double equal signs, etc. Frustration levels are generally high during this week as this is usually the first time students have encountered coding, but this frustration usually subsides as students grow accustomed to using the software. Even given this initial steep learning curve, however, we find this to be an excellent first introduction to coding, which students will likely encounter at some other point in their academic or work careers.
Within 23 class periods, students are ready to move on to more complex equilibrium systems (e.g., pH buffers and acidbase titrations), where they are required to account for each reaction occurring in aqueous solution. Below is a representative example of student work using the systematic method to solve a pH buffer problem (figure 4):
Example 2: Find the pH after adding 0.025 L of 1.20 M HCl to a 1.200 L buffer solution that consists of 1.3 M sodium phenolate (C_{6}H_{5}ONa) and 1.2 M phenol (C_{6}H_{5}OH) (pK_{a} of phenol = 10.00).
Figure 4. Student work using the systematic method to solve a more complicated buffer problem.
The student first wrote the equations for each reaction occurring in solution: the dissociation of a salt, the equilibrium reaction of a weak acid in water, the autoionization of water, and the dissociation of a strong base. The student then assigned variables to each species in solution, determined the input and output concentrations (while accounting for dilution), and wrote four equations to solve for the four unknowns.
Below is the corresponding SageMathCell code:
Figure 5. SageMathCell code to solve the equations developed in Figure 4.
This code allows for the direct calculation of the pH (the last solution in set 2).
This is as complex as the problems get for general chemistry students at West Point and Maryville. Students in Maryville’s analytical chemistry courses use SageMath to solve for up to twenty unknowns simultaneously. Because SageMath can also complete dilution and pH calculations, students do not have to rely on multiple computing devices. Additionally, once students have written code for the first step of a multipart problem, they can easily modify the code to incorporate any new parameters. This is especially useful in titration problems, where typically using ICE tables there is a significant amount of work associated with each different point in the titration. Using the systematic method, students can solve for the pH at multiple points in an acidbase titration in just a few minutes.
If you are loathe to relinquish ICE tables, but still want to expose your students to simple coding in a chemistry class, your students could still use SageMath to bypass any algebra involving successive approximations or the quadratic equation. Here is what the SageMath code would look like for example 1 (Figure 1) using ICE tables:
Figure 6. SageMathCell code to solve an ICE table for Example 1.
Your students could then use the above value of x (0.56 M) to calculate the actual equilibrium concentrations of each species (or you could even have SageMath do that work for you).
In conclusion, the systematic method, in conjunction with SageMath, are powerful tools for solving multivariable problems involving chemical equilibrium reactions. Although students initially encounter a steep learning curve, with practice they can become proficient at solving even relatively complex equilibrium problems. This exposure to an engineering model for solving for multiple unknowns also helps students hone their problemsolving skills and provides students with a first experience in coding.
References.
1) de Levie, R. (1999). Aqueous acidbase equilibria and titrations. Oxford University Primers, v. 80. New York: Oxford University Press.
2) Kalainoff, M., Lachance, R., Riegner, D., Biaglow, A. “A computer algebra approach to solving chemical equilibria in general chemistry.” Primus: Problems, Resources & Issues in Mathematics Undergraduate Studies; May/Jun2012, Vol. 22 Issue 4, p284302, 19p
3) Kalainoff, M., Ulrich, N., Kowalski, E., Spudich, T. Chemical Equilibrium using the Systematic Method, unpublished document.
4) BaezaBaeza, J. J., GarcíaÁlvarezCoque, M. C. J. Chem. Educ. 88, 2, 169173.