Berkeley Churchill

Chemical Equation Balancer

Instructions

To balance a reaction simply list all the reactants and products. Seperate different compounds with + signs. To add a charge, simply follow the chemical by a caret (^) and then the charge. If the charge is positive you should leave off the + sign before the charge, but if it's negative it should be prefixed by a - sign.

Examples

Has chembal been useful for you?

Let me know! If you're feeling generous, donations are appreciated; see the link on the bottom of the page. If this doesn't work for you, please let me know and be sure to mention your operating sytem, internet browser and version of Java. There have been some issues with not being able to use the input box; unfortunately I don't think it's the fault of my code, so I don't think I can fix it.

Less Technical Example of how the applet works:

Consider this example: H2 + O2 --> H2O. Using algebra, we will make a system of equations to solve the chemical equation. Let's force the coefficient of H2 to be a, the coefficient of O2 to be b and the coefficient of H2O to be c. Then since there are the same number of hydrogen atoms on each side of the chemical equation, we know that a = c. Since there are the same number of oxygen atoms on each side, b = 2c. Notice that a = 2, b=1 and c = 2 is a solution to this system. It is not the only one, but it is the "smallest" one that uses positive integers. Therefore the balanced reaction is 2H2 + O2 --> 2H2O. The applet above does this same process, except on a larger scale, using the tools of linear algebra.

More Technical Explaination

List the compounds in the chemical reaction, and call them c1, c2, ... , cn. Let the integer ai denote the number of occurences of ci on the left hand side of the balanced equation (or equivalently, the negation of the number of occurences on the right hand side of the balanced equation). Suppose there are m different types of atoms involved in the reaction. Let bi,j denote the occurences of atom type j in ci. Then for a fixed j there must be the same number of this type of atom on either side of the equation; so it follows that b1,ja1 + b2,ja2 + ... + bn,jan = 0. Therefore there are m equations constraining the values of the ai. These equations may be put into matrix form, Bx = 0. In simple terms, the applet solves this system of equations and returns the answer. However, it's not really that simple. Obviously, x = 0 is a solution to the above matrix equation. But if y ≠ 0 and By = 0 then B(my) = 0 for any scalar m. This means the system has one solutions, or infinitely many. If there is only one solution, the chemical equation does not balance. If all the solutions to the equations are scalar multiples of each other, then choosing any one is fine, since one may multiply both sides of a chemical equation by a scalar. It gets trickier when the solutions are not scalar multiples of each other. In linear algebraic terms, the applet finds a basis for the vector space of solutions to the matrix equation and outputs each basis vector as a chemical equation. Thus, when you get an output with multiple answers, this means you can add and subtract these chemical equations in order to produce any way to balance the equation. This happens when two reactions are happening simultaneously but independently; however there are more complicated situations where this happens as well.

Source Code

The source code is now available under the GNU General Purpose License: chembal-source.zip (25kb).



Copyright 2010 Berkeley Churchill.