Using Mathematica and Maple To Obtain Chemical ... - ACS Publications

Nov 1, 1997 - William R. Smith and Ronald W. Missen. University of Guelph, School of Engineering, College of Physical and Engineering Science, Guelph,...
0 downloads 0 Views 77KB Size
Information • Textbooks • Media • Resources

Using Mathematica and Maple To Obtain Chemical Equations William R. Smith Department of Mathematics and Statistics, and School of Engineering, University of Guelph, Guelph, ON, N1G 2W1, Canada Ronald W. Missen Department of Chemical Engineering and Applied Chemistry, University of Toronto, Toronto, ON, M5S 3E5, Canada Writing chemical equations from a given list of species requires only one of the most fundamental concepts in chemistry, that of conservation of elemental species (including charge). This concept can be expressed in terms of sets of linear algebraic equations, with which even beginning students have some familiarity (1). Although this approach can (and pedagogically should) be carried out by hand in simple cases (2–4), even for a system described by a single chemical equation (5, 6), the hand-calculation approach can in some cases be extremely cumbersome. This situation includes some redox reactions, for which the task of “balancing” even a single equation may present even greater difficulty by other methods (5); it is exacerbated when more than a single chemical equation is required (7, 8). When the complexity warrants, the solution of the linear algebraic equations can be readily implemented by computer algebra software, or by a stand-alone computer program (9). The purpose of this note is to show how the computer algebra systems Mathematica 1 and Maple,2 or similar software, can be used to obtain chemical equations to represent the stoichiometry of a reacting system. Although the current use of such tools is likely more prevalent in upper-level classes, we believe that they are becoming more accessible to beginning students. Indeed, writing chemical equations might be an interesting exercise by means of which students would learn to use them. These tools eliminate any drudgery associated with this task. The student or teacher need not be deterred by any apparent complexity of the system, or by the formalism described below, since the procedure itself is straightforward. We begin by defining the problem. Then we use two examples to illustrate the procedure to obtain solutions, first with Mathematica and then with Maple. We conclude by describing some general features of this method of solution. The Problem The problem may be posed formally as: given a list of species (the construction of which is an important first step) in a reacting system represented by a formula matrix, A = (aki ), where aki is the subscript to element k in species i, obtain a matrix of stoichiometric coefficients, N = (νij ), where νij is the coefficient of species i in equation j. This involves “solving” the linear equations A N = 0, which can be accomplished with any computer software package that includes conversion of a matrix to its row-reduced form as one of its operations (as do Mathematica and Maple). Since the theory of this matrix method is described elsewhere (2– 4, 6), we proceed by means of two examples to illustrate its implementation with Mathematica and Maple in turn. The system in each example is represented by a list of the species involved (corresponding to the col-

umns in A), followed by a list of the elements making up the species (corresponding to the rows in A).

Solution by Mathematica or Maple Example 1: A Redox System (5 ) This relates to the reaction of species B—where B represents [Cr(N2 H4CO)6]4 [Cr(CN)6]3—with KMnO4 in acidic aqueous solution: {(B, KMnO4, H 2SO4, K 2Cr2O 7, MnSO4, CO2, KNO3, K2 SO4, H2O), (Cr, N, H, C, O, K, Mn, S)} Mathematica Solution A solution is in four main steps: 1. The entry of a Mathematica statement, for each species, of the formula vector formed by the subscripts to the elements (in the order listed) in the molecular formula, as follows: B = {7, 66, 96, 42, 24, 0, 0, 0} KMnO4 = {0, 0, 0, 0, 4, 1, 1, 0} H2SO4 = {0, 0, 2, 0, 4, 0, 0, 1} K2Cr2O7 = {2, 0, 0, 0, 7, 2, 0, 0} MnSO4 = {0, 0, 0, 0, 4, 0, 1, 1} CO2 = {0, 0, 0, 1, 2, 0, 0, 0} KNO3 = {0, 1, 0, 0, 3, 1, 0, 0} K2SO4 = {0, 0, 0, 0, 4, 2, 0, 1} H2O = {0, 0, 2, 0, 1, 0, 0, 0}

2. The construction of the formula matrix A by the statement: MatrixForm[Transpose[A = {B, KMnO4, H2SO4, K2Cr2O7, MnSO4, CO2, KNO3, K2SO4, H2O}]]

which is followed by the Mathematica response: 7

0

0

2

0

0

0

0

0

66

0

0

0

0

0

1

0

0

96

0

2

0

0

0

0

0

2

42

0

0

0

0

1

0

0

0

24

4

4

7

4

2

3

4

1

0

1

0

2

0

0

1

2

0

0

1

0

0

1

0

0

0

0

0

0

1

0

1

0

0

1

0

Vol. 74 No. 11 November 1997 • Journal of Chemical Education

1369

Information • Textbooks • Media • Resources 3. The reduction of A to the unit matrix form A* by the statement:

2. transpose(array([Hplus, OHminus, H2O, NOplus, NO2minus, N2O3, HNO2, Tlplus, TlNO2]));

followed by the Maple response:

RowReduce[%]

which is followed by the Mathematica response: 1 0

0 1

0 0

0 0

0 0

0 0

0 0

1

1

2

0

0

0

1

0

0

10/1879

0

1

1

1

2

3

2

0

2

0

1176/1879

0

0

0

1

1

2

1

0

1

0

0

0

1

0

0

0

0

0

1399/1879

0

0

0

0

0

0

0

1

1

0

0

0

1

0

0

0

0

{35/1879

1

0

1

{1

0

0

1

0

0

0

0

0

1

0

0

0

{1176/1879

{1

0

0

0

0

0

1

0

0

{420/1879

0

0

0

0

0

0

1

0

{660/1879

0

0

0

0

0

0

0

1

{223/1879

3. rref (”); followed by the Maple response:

4. Obtaining the chemical equation(s): A component species is indicated by a standard unit vector in the corresponding column in A* (a column with a single “1” entry and “0”s elsewhere). Here, the first 8 columns correspond to component species. A noncomponent species is indicated by each of the remaining columns. Here, there is only one noncomponent species, H2O, corresponding to column 9, which begins with the entry “10/1879”. A chemical equation is written for each noncomponent species so as to form one mole of it (on the right side) from the component species (on the left side). The coefficients of the component species in each such equation are given by the entries in the column corresponding to that noncomponent species. Here, there is only one equation, and, from A* above, it is

or, as we normally write, on eliminating fractions and minus signs, and replacing B by its molecular formula, 10[Cr(N2H4CO)6]4[Cr(CN)6]3 + 1176KMnO4 + 1399H2SO4 = 35K 2Cr 2O 7 + 1176MnSO 4 + 420CO 2 + 660KNO 3 + 223K2SO 4 + 1879H2O

Hplus : = [1, 0, 0, 0, 1]; OHminus: = [1, 1, 0, 0, {1]; H2O: = [2, 1, 0, 0, 0]; NOplus: = [0, 1, 1, 0, 1]; NO2minus: = [0, 2, 1, 0, {1];

Tlplus: = [0, 0, 0, 1, 1]; TlNO2: = [0, 2, 1, 1, 0];

1370

{1

{1

0

0

{1

0

1

1

0

1

1

1

0

1

0

0

0

1

1

2

1

0

1

0

0

0

0

0

0

0

1

1

0

0

0

0

0

0

0

0

0

1 H+

+

1 OH{

+

0 NO+

+ 0 Tl+

=

1 H2O

+

1 OH{

+

1 NO+

+ 0 Tl+

=

1 NO2{

{1 H+

+

1 OH{

+

2 NO+

+ 0 Tl+

=

1 N2O3

H+

+

1

OH{

+

1

NO+

+ 0 Tl+

=

1 HNO2

{1 H+

+

1 OH{

+

1 NO+

+ 1 Tl+

= 1 TlNO2

0

(note that the last row of 0’s is ignored in this step— see explanation in point 2 in the next section), or, as we normally write, on eliminating minus signs and omitting species with zero coefficients, H+

+

OH { =

H2O

OH {

+

NO + =

NO2{

+ H+

OH {

+

2 NO + =

N2O3

+ H+

OH {

+

NO + =

HNO2

OH { + NO +

+

Tl + =

TlNO2

+ H+

General Features Illustrated by the Examples The two examples illustrate the procedure for determining an appropriate chemical equation or, in general, a set of such equations for a given system (A). This procedure is an implementation of the matrix method (2–4, 6). To this bare outline, we add further comments relating to general features of the method of solution. 1. The number of component species, C, is given by rank(A) = rank(A*) = C ≤ M

N2O3: = [0, 3, 2, 0, 0]; HNO2: = [1, 2, 1, 0, 0];

0

{1 H+

{(H+, OH{, H2O, NO+, NO2{, N2O 3, HNO2 , Tl+, TlNO2 ), (H, O, N, Tl, p)} (p is charge, treated as an element)

1. with (linalg):

1

Following the explanation in step 4, example 1, we identify the component species from the standard unit vectors in columns 1, 2, 4, and 8, corresponding to H+ , OH { , NO + , and Tl + , respectively. Similarly, the noncomponent species, from columns 3, 5, 6, 7, and 9, are H2O, NO 2{, N2O3, HNO 2, and TlNO 2. From the entries in each of these columns, the 5 chemical equations, corresponding to each noncomponent species in turn, are thus:

Example 2: Complexation of Tl+ by NO2{ (8 )

Maple Solution A solution involves the same four steps as in the previous example, but the syntax of the commands is slightly different.

0

4. obtaining the chemical equation(s):

+ 10 B + 1176 KMnO4 + 1399 H2SO4 – 35 K2Cr2O7 1879 1879 1879 1879 – 1176 MnSO4 – 420 CO2 – 660 KNO3 – 223 K2SO4 = H2O 1879 1879 1879 1879

1

where M is the number of elements. The rank of A* is the number of columns that are standard unit vectors, and is easily determined by inspection. These vectors form a C × C unit submatrix of A*.

Journal of Chemical Education • Vol. 74 No. 11 November 1997

Information • Textbooks • Media • Resources 2. Usually C = M, as in example 1, where C = M = 8. When rank(A) = C < M, A is said to be rank deficient. This is the case in example 2, where C = 4 and M = 5. This rank deficiency is also indicated by the existence of M – C rows of 0’s in A*; there is one such row in example 2. 3. The maximum number of linearly independent chemical equations, R, is given by R=N–C where N is the number of species. Note that R is determined by the procedure itself. In example 1, R = 9 – 8 = 1, and in example 2, R = 9 – 4 = 5. The equation or set of equations produced represents stoichiometry only, and has no necessary implications for reaction mechanism or for “reactants” or “products”. When R > 1, the set is not unique; any equation of the set could be replaced by a linear combination of members of the set. 4. Finally, we note that arbitrary ordering of the species may result in the columns of the unit submatrix of A* being interspersed with the remaining columns. This is illustrated in example 2. When R = 1, as in example 1, this never occurs.

plications stemming from the arbitrariness of oxidation numbers (7, 10), we believe that students would welcome a method that guarantees success in much less time and with much less effort. The matrix method can be used for any type and complexity of system. For redox systems, the oxidation-number method usually implicitly assumes that only one equation is required (as in the original treatment of example 1 [5]). This begs the questions as to how the number of equations required can be systematically determined by this method, and how the equations can be obtained, if more than one is required. (An example requiring two equations is cited by Porter [7].) Acknowledgments Financial assistance has been received from the Natural Sciences and Engineering Research Council of Canada, and from the University of Toronto. Winnie Chiu assisted with the solutions. Notes 1. Mathematica is a registered trademark of Wolfram Research Inc. 2. Maple is a registered trademark of Waterloo Maple Inc.

Literature Cited

Discussion The use of Mathematica or Maple (or their equivalent) to implement the matrix method provides a “painless” and straightforward means of writing or “balancing” chemical equations, regardless of the complexity of the system. The matrix method is based only on the conservation of elements; additional artifices, such as oxidation numbers or half reactions, whatever their value otherwise, are unnecessary for this purpose. These points are particularly evident in example 1. This was posed (5) as an “incredibly challenging” case that required “several hours” to obtain the final result (shown above), by means of a procedure involving oxidation numbers; it is further stated that “No freshman chemistry student…has balanced this reaction…” Given this and com-

1. Olson, J. A. J. Chem. Educ. 1997, 74, 538. 2. Alberty, R. A. J. Chem. Educ. 1991, 68, 984. 3. Smith, W. R.; Missen, R. W. Chemical Reaction Equilibrium Analysis: Theory and Algorithms; Krieger: Malabar, FL, 1991; Chapter 2. 4. Smith, W. R.; Missen, R. W. Chem. Eng. Ed. 1979, 13, 26– 32. 5. Stout, R. J. Chem. Educ. 1995, 72, 1125. 6. Blakley, G. R. J. Chem. Educ. 1982, 59, 728–734. 7. Porter, S. K. J. Chem. Educ. 1985, 62, 507–508. 8. Cobranchi, D. P.; Eyring, E. M. J. Chem. Educ. 1991, 68, 40–41. 9. Missen, R. W.; Smith, W. R. J. Chem. Educ. 1989, 66, 217– 218; erratum, J. Chem. Educ. 1989, 66, 534. 10. Ludwig, O. G. J. Chem. Educ. 1996, 73, 507.

Vol. 74 No. 11 November 1997 • Journal of Chemical Education

1371