home *** CD-ROM | disk | FTP | other *** search
-
-
- In 1986, while I was tutoring a chemistry student on the art of balancing
- chemical equations, it occurred to me that the undetermined coefficients
- we were looking for were just algebraic unknowns that could be solved
- for by solving a system of linear equations for them. I soon figured
- out how to explain my quasi-algorithm to others, but I also felt that
- creating and distributing ChemBalance might encourage people to use the
- algebraic approach themselves.
-
- This program, ChemBalance, v3.0, (Copyright 1994) is distributed free
- of charge to all who want to use it. Anyone may redistribute it as they
- please as long as due acknowledgement is given to the author, the program
- name, and the version number. Version 2.0 is found on FredFish 916. The
- current version can solve equations with as many as nine terms in it.
- It can also deal with terms having multiple asterisks as shown later in
- this writeup. The reason the program is shorter is because of the new
- recursive procedure for doing determinants.
-
- I am not expecting to release improved versions, although I haven't ruled-
- out the possibility in the distant future. If you have any questions or
- suggestions, please feel free to write me at
-
- Patrick Reany Phone: (602) 995-1637
- 2408 W Myrtle #26
- Phoenix AZ 85021
- USA
-
- What follows is a brief introduction to ChemBalance, but if you'd like a
- more thorough explanation, send me $3.00 and I'll send you a copy of the
- user's manual for ChemBalance and a writeup on the history and
- controvery over using the algebraic method rather than the
- oxidation-reduction method.
-
-
- WARNING: This program will overwrite the files ram:list, ram:mylist,
- and ram:solutions if you have them.
-
- To run the program, you must have ARexx ready to go. With that done,
- put ChemBalance in ram: then open a shell and enter
- "rx ram:chembalance".
-
- Before we start we need to establish some terminology.
-
- 1) "RHS" = right hand side
- 2) "LHS" = left hand side
- 3) "total number of terms" means the sum of terms
- from both sides of the equation
- 4) "eq" is short for equation
- 5) "coef" is short for coefficient
- 6) the "terminal coef" is the coef of the rightmost
- term of the RHS
- 7) an eq that has at least as many elements as one less
- than the total number of terms is said to be "regular"
- 8) if an eq is not regular it is said to be "nonregular"
- 9) "ansatz" means a trial solution
-
-
- Some of the syntax rules for ChemBalance are
-
- 1) use "=" to separate LHS from RHS
- 2) use "_" to indicate a subscript
- 3) use "*" to preface a (generalized) hydration such as ...*6H_2O
- or ...*NH_3
- 4) use any single capital or any single capital
- followed by a small-case letter as an element
- 5) nested parentheses are not allowed
- 6) allowable input characters are all upper- and lower-case
- letters, digits, "+","=","_","*"," ","(",")"
- 7) parentheses cannot follow an asterisk in a given term
-
-
- Some of the formation rules are
-
- 1) each eq has exactly one equal sign
- 2) both sides of every eq have at least one term
- 3) each eq has at least one plus sign
- (thus each eq has at least 3 terms total)
- 4) an eq can have up to 9 terms, perhaps more
- 5) every element in each eq must be found on both sides
- 6) only 1 or 2 digits may immediately follow an asterisk
- 7) only 1, 2, or 3 digits may immediately follow an "_"
- in input or in internal calculation
- 8) use the "+" only as a binary operator on terms
-
-
- ChemBalance does have its limitations. It won't do very simple stuff
- like O_2 + O_2 = O_3. It also won't do equations with ions in them. It
- won't do equations like
-
- HAuCl_3+K_4Fe(CN)_6=KAu(CN)_4+KAu(CN)_2+KAu(CN)_2Cl_2+KCl+HCl+
- +[4Fe(CN)_3*3Fe(CN)_2]
- the problem being the last term. Since C and N always appear as a
- multiple of CN, (CN) can be replaced by X, say, yielding
-
- HAuCl_3+K_4FeX_6=KAuX_4+KAuX_2+KAuX_2Cl_2+KCl+HCl+*4FeX_3*3FeX_2
-
- Note that with additional changes we have brought the final term into
- correct form. Remember that parentheses cannot follow an asterisks.
-
- Unfortunately, this last eq is nonregular and it is not easy to find
- any solutions for it. User-defined coefs are necessary.
-
- Now for a bit of explanation. It's pretty obvious that every unbalanced
- eq that has a solution, has an infinite number of solutions derived
- by multiplying the solved eq thru by any positive integer you like.
- Thus the coef's are determined only up to their mutual ratios. We can derive
- a unique solution then (at least for regular eq's) by setting any one of
- the coef's to a fixed integer. For convenience ChemBalance always chooses
- to set the terminal coef equal to 1.
-
- Let's try an example. Consider the eq
-
- CO + O_2 = CO_2
-
- We put a variable in front of each term to be solved for, except that
- we put a 1 in front of the terminal term, thus giving us
-
- xCO + yO_2 = 1CO_2
-
- Now, we have two unknowns, so we need two elements in the eq to solve for.
- We're in luck, since we have carbon, 'C', and oxygen, 'O'. (Thus we have
- a regular eq.) Next we balance the eq one element at a time!
-
- element term1 term2 term3
-
- C: 1x + 0y = 1
- O: 1x + 2y = 2
-
- If you know some linear algebra you can solve these types of problems
- easily, perhaps by using Cramer's rule (which is what ChemBalance uses),
- though the present problem can be easily solved by inspection.
- When you do you get
-
- x = 1, y = 1/2
-
- This fraction was introduced because of a mathematical object called
- a transformation determinant. It's there to keep us honest: If the
- transformation determinant is different from zero you get a solution.
- If it's equal to zero, you don't---at least you don't for the combination
- of elements you've chosen. In the present example it's do or die because
- there are no other elements to choose from.
-
- Now, ChemBalance does not like to deal with fractions (a trait no doubt
- inherited from me), so it eliminates them by multiplying the balanced
- eq thru by the value of the transformation determinant. The form we get
- then is
-
-
- Lcoef_1 x Lterm_1 + ... + Lcoef_L x Lterm_L =
- Rcoef_1 x Rterm_1 + ... + det x Rterm_(terminal_term#)
-
- where all the coef's are integers. Well, we did have "unique" coef's
- but we changed them. That's OK. We may change them again to put the answer
- in "reduced" form, a form in which there is no prime integer which will
- evenly divide all the coef's. Actually, it's the existence of a unique
- reduced eq for regular eq's that is of importance to us.
-
- ChemBalance finds the elements it needs to set up the simultaneous
- eq's in the elements_list. In the last problem it contained only 'C' and 'O'.
- Now let's look at the eq
-
- SO_2 + Cl_2 = SO_2Cl_2.
-
- It will contain the three elements 'S O Cl' in the elements_list, and let's
- say, for the sake of argument, that they're in it in that particular order.
- Then when ChemBalance goes to form the 2 linear eq's it needs, by taking
- the two leftmost elements in the list, after "balancing" for 'S' and 'O'
- it will have completely ignored the second term on the left. This leads to
- a 'det = 0' problem. What ChemBalance does about this is fairly good in
- practice, but not perfect in theory.
-
- The perfect thing to do is to make sure that ChemBalance takes at least one
- element to balance from each term, but for this version all it does is
- to cyclicly permute the elements_list and then try again. Don't laugh
- ---it seems to work very well. In this case the new list would be in the
- order 'O Cl S'. Then ChemBalance would balance for 'O' and 'Cl', which brings
- all terms to bear, and the solution is found.
-
- Now let's show some typical forms for input.
-
- -------> (NH_4)_2Cr_2O_7 = Cr_2O_3 + H_2O + N_2
-
- -------> CoCl_2*6H_2O = CoCl_2*4H_2O + H_2O
-
- To exit ChemBalance enter "quit" on the input line.
-
- The simplest way to enter the skeletal equations presented in this
- writeup is to 1) split the screen between the shell window on top
- and the Ed window on bottom, 2) highlight one of the skeletal eqs and then
- press right-amiga key and 'c'. This will copy the highlighted phrase to
- to the clipboard. Then activate the shell window and press the
- right-amiga and 'v', which will copy the clipboard into the prompt
- and then go from there.
-
- I wrote ChemBalance with the hope that people would use it, like it, and
- then try out its algebraic quasi-algorithm. It's good for instruction,
- but it's even better for actual use. Compare solving the following
- using ChemBalance to doing them yourself by any method you like.
-
- NaCl + H_2SO_4 + MnO_2 = Na_2SO_4 + MnSO_4 + H_2O + Cl_2
-
- RCHO + CuSO_4 + NaOH = RCOONa + Cu_2O + Na_2SO_4 + H_2O
-
- HCl + KMnO_4 = H_2O + KCl + MnCl_2 + Cl_2
-
- C_7H_16 + O_2 = CO_2 + H_2O
-
- C_12H_22O_11 + H_2SO_4 = C + H_2SO_4*H_2O
-
- (NH_4)_2SO_4*FeSO_4*6H_2O = (NH_4)_2SO_4 + FeSO_4 + H_2O
-
- The eq above containing Mohr's salt (NH_4)_2SO_4*FeSO_4*6H_2O is a
- hypothetical decomposition.
-
- P + Fe_2O_3 = P_4O_10 + Fe
-
- C_15H_32 + O_2 = CO_2 + H_2O
-
- CCl_3CHO + C_6H_5Cl = (ClC_6H_4)_2CHCCl_3 + H_2O
-
- P_4+P_2I_4+H_2O=PH_4I+H_3PO_4
-
- K_4Fe(CN)_6+KMnO_4+H_2SO_4=KHSO_4+Fe_2(SO_4)_3+MnSO_4+HNO_3+CO_2+H_2O
-
- This last eq is a regular 9-termer. ChemBalance will balance this and
- perhaps even larger skeletal eqs. Later I'll present a 20-termer that
- ChemBalance can't do. To get ChemBalance to do larger eqs perhaps all
- that needs to be done is to rewrite the determinant procedure to read
- and write from a text file the components of the large minors.
-
-
- ChemBalance 2.0 and 3.0 can solve nonregular eq's on its own.
- But first we'll see how to it uses user-defined coefficients to help
- solve them. Consider the nonregular eq:
-
- CH_4 + O_2 = C_2H_2 + CO + H_2
-
- It has five terms but only three elements. One way to get ChemBalance
- to solve it is for the user to put in at least two coef's. If you try
- the ansatz
-
- CH_4 + 1O_2 = C_2H_2 + 2CO + H_2
-
- for instance, it's true you've balanced for 'O', but you've also effectively
- (though not actually) knocked out 'O' from the elements_list, since the
- two fixed terms combine to form a single constant term, resulting in another
- nonregular eq having four terms but only two elements, 'C' and 'H',
- to use. So that didn't work.
-
- But if we try to balance it for 'C', depending on how we do it, we could
- try the ansatz
-
- 4CH_4 + O_2 = 1C_2H_2 + 2CO + H_2
-
- which gives the solution
-
- 4CH_4 + O_2 = C_2H_2 + 2CO + 7H_2
-
- But if we try the alternative ansatz for carbon
-
- 6CH_4 + O_2 = 2C_2H_2 + 2CO + H_2
-
- we get the different solution
-
- 6CH_4 + O_2 = 2C_2H_2 + 2CO + 10H_2
-
- What's neat about this solution is that it is not proportional to the
- previous solution. They are in fact nonequivalent! Notice that the two
- solutions differ by the balanced equation
-
- 2CH_4 = C_2H_2 + 3H_2
-
- The second way to let ChemBalance solve nonregular equations is to simply
- type in the equation and ChemBalance will prompt the user from there.
-
- A typical input would be:
-
- CH_4 + O_2 = C_2H_2 + CO + H_2
-
- After a bit ChemBalance will return with a long message about how
- to proceed. You have two choices: 1) hit return and enter the UDC's
- yourself, or 2) enter the lower and upper coefficients for ChemBalance
- to try (if you enter just one number ChemBalance will regard it as the
- upper value to try). If you use method 2) then ChemBalance will try out
- a bunch of coefficients and each time a solution is found it is written to
- the file `ram:solutions'. It's important to note that the solutions to
- nonregular eq's are formal, meaning that they do not guarantee to
- represent real chemical solutions. There is a considerable literature
- on the meaning of nonregular eq's that most students and professors are
- unaware of. I have written a review of these articles and it is
- included in the literature mailed with the writeup on ChemBalance.
-
- Finally, I can imagine many high-school chemistry students finding
- ChemBalance a lot of fun to play with.
-
- I leave you with this 20-termer!
-
- H_2+Ca(CN)_2+NaAlF_4+FeSO_4+MgSiO_3+KI+H_3PO_4+PbCrO_4+BrCl+CF_2Cl_2
- +SO_2 =
- PbBr_2+CrCl_3+MgCO_3+KAl(OH)_4+Fe(SCN)_3+PI_3+Na_2SiO_3+
- +CaF_2+H_2O
-
-