Any system of N linear equations in N unknowns can be solved by means of Gaussian elimination (assuming it was solvable to begin with). This method is completely systematic and very efficient. For smallish N, the method is easy to carry out using only pencil and paper. (Remember that Gauss worked in the early 1800s, long before computers were available.)
For large N (larger than 4 or 5) it might be quicker to solve the equations using a computer. You don’t need to know about Gaussian elimination to do this; you just use the matrix-inverse function (which uses Gaussian elimination internally). This function is available in garden-variety spreadsheet programs and elsewhere. There are also more-specialized programs specifically targeted at chemistry applications. We won’t discuss the details here.
We shall see that even a somewhat complicated-looking reaction can be balanced easily. I will do an example, and explain the rules as I go along. The following reaction1 – taken from reference 1 – will serve as good illustration:
| Cd + a (H+ NO3–) + b (H+ OH–) → x Cd++ + y NO3– + z NO (1) |
The first rule is to write the reaction using undetermined coefficients, as was done in equation 1, where the coefficients are a, b, x, y, and z. This is in preference to writing just the “skeleton” of the reaction, in which the coefficients are omitted entirely, as in equation 2. The skeleton may have the superficial attraction of brevity, and you need to recognize skeletons because they commonly appear in books and elsewhere, but for present purposes we really need to see the coefficients. In particular, equation 2 does not assert that the coefficient in front of each reactant is unity; it doesn’t say anything about the coefficients.
| Cd + (H+ NO3–) + (H+ OH–) → Cd++ + NO3– + NO [skeleton] (2) |
The second rule is to pick one of the species involved in the reaction and set its coefficient equal to 1 (or at least to some definite constant). Again this has already been done in equation 1 – the coefficient in front of Cd has been set to 1.
The reason for this rule is simple: without such a rule, there would be innumerably many different ways of balancing the reaction, all mathematically equivalent. Even an ultra-simple reaction such as
| C + O2 → CO2 (3) |
can also be written as
| 13 C + 13 O2 → 13 CO2 (4) |
which is mathematically correct ... just not in lowest terms. Gaussian elimination does not (in general) give you a solution in lowest terms, so we need to handle that separately: First we do the Gaussian elimination, then afterward we rewrite the answer in lowest terms.
Now for the next step. It is recommended that you pounce on any coefficients that have obvious solutions. In equation 1, it is pretty obvious that x = 1, since Cd has a coefficient of 1 on the LHS and there is only one term involving Cd on the RHS. Similarly, once you set x = 1, it becomes pretty obvious that y = 2, since the LHS is manifestly charge-neutral, no matter what the values of the coefficients, and the NO3– ion is the only thing on the RHS that could possibly balance the charge of the Cd++ ion.
Taking advantage of these obvious simplifications is entirely optional. If you skip this step, you will have a system of 5 equations in 5 unknowns ... which is easy enough to handle. But if you do make the simplifications, you are left with a system of 3 equations in 3 unknowns ... which is even easier.
So let’s rewrite the equation as
| Cd + a (H+ NO3–) + b (H+ OH–) → Cd++ + 2 NO3– + z NO (5) |
From this we can pick off our system of three equations in three unknowns. In its verbose form, it is:
| (6) |
The trick to making Gaussian elimination really systematic and really efficient is to rewrite this in a less-verbose form:
| (7) | ||||||||||||||||||||||||||||||
The correctness of equation 7 is most easily verified by looking at each column. For example, we know a is the coefficient in front of HNO3, so it is good to see 1,1,3 in the H, N, and O rows of the appropriate column.
The only thing that is even halfway tricky about this is that you must remember to put minus-signs in each column corresponding to a coefficient from the RHS of the reaction, because in equation 7 we have pulled all the variables to the LHS of the equal sign.2
With a little practice, you will be able to write equation 7 just by looking at the reaction (equation 5), without bothering with equation 6.
The next phase is the heart of the Gaussian elimination algorithm. The goal of this phase is to convert the matrix in equation 7 to upper-triangular form. We do this by subtracting one row from another, step by step, as many times as necessary.
The motto for this phase is “multiply by ... and add”. That is, we take one row, multiply it by some constant, and add it to another row. You choose the constant so as to create a stragetically-placed zero in the result.
As a first application of this motto, we multiply the first row by -1 and add that to the second row. That gives us:
| (8) | ||||||||||||||||||||||||||||||||||||
You will notice that I have grayed-out one row of the table. If you were doing this with pencil and paper, you would just lightly cross out that row. We won’t be needing that row again, but as a general principle that you should never erase any of your work ... I recommend keeping it around, to facilitate checking your work.
Also over on the right, in square brackets, I have written a hint as to where the new line came from: The first number (2 in this case) indicates that this is a replacement for line #2, and the other number (1 in this case) indicates that line #1 was also involved in the construction of this line. This is not necessary, just recommended, to facilitate checking your work.
The rule here is that we have combined two lines to create a new one, and the new line should be considered a replacement for one of the old lines. It doesn’t really matter which of the old lines you cross out. Just pick one. The method will work either way.3
Continuing down this road, we multiply the first line by -3 and add it to the third line. That gives us:
| (9) | |||||||||||||||||||||||||||||||||||||||||||
This has the nice property that we have nothing but zeros in the first column, except for the first row, not counting the crossed-out rows. That is good. That is what we were trying to do.
The bottom two rows in equation 9 can be viewed as two linear equations in two unknowns, and can be solved by continuing the good-old Gaussian elimination process.
The second-best way to proceed would be to multiply the next-to-last row by -5/2 and add that to the last row. But paper is cheap, and many people find it advantageous to use a two-step process. First we multiply the last line by 2, which gives us:
| (10) | |||||||||||||||||||||||||||||||||||||||||||||||||
Then we multiply line #4 by -5 and add it to line #6. That gives us:
| (11) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
We have succeeded in putting the matrix into upper-triangular form. (As always, we are ignoring the crossed-out rows.)
The bottom row tells us directly that 3z = 2, hence z = 2/3.
The next phase is to convert the matrix into fully diagonal form. This is even easier than the previous phase, because we work from the bottom up, and the bottom rows have lots of zeros, making the multiplications really easy.
We multiply line #4 by 3 to get:
| (12) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
and then we add line #7:
| (13) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
which tells us that −6b = 8, hence b = −4/3. The fact that b is negative tells us that we guessed wrong when we wrote the H2O term on the LHS of the reaction; we need to move it to the RHS (which will flip the sign of the coefficient).
We can see from the top line of the matrix that a + 2b = 0, hence a = −2b, hence a = 8/3, which you can do in your head easily enough. Or you could just carry out the final step of the Gaussian elimination algorithm, using line #9 to clean out the b column of the top row in equation 13. This is completely routine, but for completeness I’ll show the final form of the tableau:
| (14) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
so you can see we have succeeded in putting the matrix into diagonal form. This completes the Gaussian elimination. You can pick off the values of all the coefficients from equation 14.
We plug these values into equation 1, and then rescale everything to bring it into standard form. The final result is:
| 3 Cd + 8 (H+ NO3–) → 3 Cd++ + 6 NO3– + 2 NO + 4 H2O (15) |
This equation is even easier to verify than it was to derive. Please take a moment to convince yourself that this result is balanced w.r.t cadmium, hydrogen, nitrogen, oxygen, and charge. You can do this in your head; it requires little more than counting.
Gaussian elimination follows a simple pattern: Basically you work your way down, cleaning out the columns one by one until the matrix is in upper-triangular form. Then you work your way back up, putting the matrix into diagonal form. With a little practice, you can do it very quickly with very high confidence in the results.
The work required goes roughly like N cubed, so a N=4 system is about twice as laborious as a N=3 system, and a N=5 system is about twice as laborious as a N=4 system.
There is nothing mysterious about Gaussian elimination. The validity of every step is based on the most basic laws of algebra: multiplying both sides of an equation by a constant, adding one equation to another, and things like that.
The advantage of the method is that it gives you a compact and tidy way of doing the algebra, and it gives you some guidance as to which equation should be multiplied by a constant, and which equation should be added to which other.
Each row of in the Gaussian elimination tableau is an equation with N variables ... we have just omitted the names of the variables for convenience.
I emphasize that Gaussian elimination will efficiently solve any system of N linear equations in N unknowns, provided the system was solvable to begin with.
When you have N unknowns, the normal case is for there to be N equations, and for all N of them to be linearly independent. In this case, we say the system is nonsingular. There will be exactly one solution, and Gaussian elimination will find it.
Otherwise we say the system is singular. A singular system will be either underdetermined (section 2.2) or overdetermined (section 2.3). Note that a singular system is an example of an ill-posed problem, as discussed in reference 2.
If you have N unknowns, and more than N linearly-independent equations, the system is overdetermined. Examples include equation 16 and equation 21. Overdetermined systems are very bad news. They express a built-in contradiction. An overdetermined system has no solution, i.e. the reaction is not balanceable.
This typically results from an erroneous reaction equation. A common error is to write a reaction equation that fails to mention one of the reactants or one of the products. (This is particularly easy to do if H2O is participating in the reaction.)
If you try to solve an overdetermined system using Gaussian elimination, the process will fail. You will observe the following symptom: At some point when you attempt to clear out one of the entries, you will get a self-contradictory expression of the form 0 = k, for some nonzero k.
Here is an example:
| (16) |
There are three equations (representing conservation of Pb, N, and O) but only two unknowns.
| (17) |
where the first two equations tell us that x=1/3 and y=2, but the third equation is a contradiction because 6 is not equal to 4/3 + 2.
To get out of this mess, you must find the correct reaction equation. Doing this requires knowing some actual chemistry, not just mathematics. As such, it is beyond the scope of this document ... but we can offer some illustrations of what might result from a proper analysis. Here is a first guess at a more-plausible replacement for equation 16:
| Pb(NO3)2→x Pb3O4 + y NO + z O2 (18) |
This is at least balanceable:
| (19) |
which has the solution (x, y, z) = (1/3, 2, 4/3).
Depending on reaction conditions, it may well be that NO2 would be evolved instead of O2:
| (20) |
which is also balanceable.
The same logic applies to other examples, including the following:
| (21) |
Just as in equation 16, this is overdetermined. It cannot proceed as written. It would evolve excess oxygen in some form, which the RHS of the reaction equation fails to take into account.
It is very common to encounter systems that are singular because they are underdetermined. Sometimes the underdeterminedness is obvious, and sometimes not quite so obvious.
| C + a O2 → x CO + y CO2 (22) |
where we have N equations in N+1 unknowns; specifically, 2 equations in 3 unknowns.
| (23) |
This has five equations (expressing conservation of Pb, Cr, Mn, N, and O) but six unknowns.
We begin our analysis by noting that this can be considered as two separate, independent reactions occurring in the same vessel, namely:
| (24) |
Each of the rows in equation 24 is separately well-posed and balanceable. However, if you combine the two reactions into one, as in equation 23, the combination is underdetermined.
This is related to the second rule set forth in section 1. For each system, you get to set one of the coefficients equal to some definite constant, thereby setting the overall scale-factor for the reaction. In equation 24, we recognize two separate reactions, and set two coefficients equal to 1, namely the coefficient of the reactant on the LHS of each equation. In equation 23, we unwisely recognize only one reaction, so we set only one coefficient equal to 1, and that leaves us with N equations in N+1 unknowns.
| C + a O2 → x CO + (1−x) CO2 (25) |
The mathematical rule is this: no matter how many equations you have, what matters is how many of them are linearly independent. Imagine collecting from your list of equations a subset wherein all the equations are linearly independent. If the biggest such set has fewer than N members, the system is underdetermined. Practically speaking, Gaussian elimination is often the most efficient way to determine if a given system of equations is underdetermined or not.
An underdetermined system has more than one answer. Indeed there will be an infinite number of answers, spanning a N−E dimensional space, where N is the number of unknowns, and E is the number of linearly-independent equations.
Whether you can succeed in solving an underdetermined system depends on how you define success. If you insist on finding “the” unique solution, that’s impossible. One thing you can do is to find “some” solution, i.e. some member of the solution-set. A more impressive feat is to find the equation that describes the entire solution-set.
If you have an underdetermined system, there are various ways to extend the Gaussian elimination method to handle such a case, i.e. to efficiently find the solution set.
Here’s one way to do it: If there are N equations and N+1 variables, designate one of the variables as adjustable quantities, to be adjusted by the Gaussian elimination calculation. The remaining variable will not be adjusted by the calculation. Note that in all the examples considered previously, all the parameters were constants with numerical values, but in this case one of the “constants” is only temporarily constant and has an unknown value, which we denote by some symbol, according to the usual rules of algebra. Let’s call it “X” for now. This means you will not be able to use a calculator or simple spreadsheet to do the calculation, but you can still go through all the Gaussian elimination steps algebraically. The result gives each of the N adjustable variables as a function of X.)
Sometimes you encounter a reaction that is genuinely intrinsically underdetermined. The reaction in equation 22 is a perfectly reasonable reaction that commonly occurs in the real world, but it does not, in general, have any fixed stoichiometry. Equation 22 has three unknowns but only two constraints, and no amount of mathematics will change this. If for some reason you want there to be a unique solution, the only way to make progress is to supplement equation 22 with additional information about the chemistry and physics of the situation ... perhaps information about the thermodynamics and/or kinetics. The details of such non-stoichiometric considerations are beyond the scope of this document.
Suppose you have a system that is underdetermined, but not obviously so, as in equation 25. You try to solve it using Gaussian elimination. You start out with N equations in N unknowns. The typical symptom is this: At some point when you attempt to clear out one of the entries, you will zero out the entire row, thereby expressing the tautology that 0 = 0 ... which is not wrong, but also not useful.
At this point, you nominally still have N equations in N unknowns, but the 0 = 0 row isn’t telling you anything useful, so you might as well cross it out and forget about it. This leaves you with a non-square matrix, because you now have N unknowns but only N−1 equations. You’ve lost one of the equations, because it was linearly dependent on one of the other equations.
If you want there to be a unique solution, you will have to go back to square one and find another equation, another linearly-independent equation.
Also, if you ever get into a situation where all of the rows in your Gaussian elimination tableau (all of the non-crossed-out rows, that is) have zero on the RHS, i.e. to the right of the equals sign, that is yet another symptom of an underdetermined system.
If you ignore the second rule given in section 1, your system of equations will be underdetermined for sure ... so don’t do that.
A system that starts out nonsingular can become singular if you inadvertently cross out the wrong row during the Gaussian elimination procedure.
Consider the following very troublesome equation:
| (26) |
which can be seen as a subset of equation 23.
Again we begin our analysis by noting that this can be considered as two separate, independent reactions occurring in the same vessel, namely:
| (27) |
As discussed in section 2.2, neither of these equations can proceed as written. Both evolve excess oxygen in some form, which the RHS of the equation fails to take into account. If you combine the two reactions in a single vessel, this doesn’t improve the situation. Equation 26 cannot proceed as written.
There are at least three basic ways to proceed. One is to declare equation 26 to be a bogus reaction, and to walk away from it. This is certainly a reasonable option.
Another option is to try to salvage equation 26 by accounting somehow for the excess evolved oxygen. This makes a lot of sense, but requires a modicum of thought, because this makes equation 26 underdetermined. What you really need to do then is to repair each row of equation 27 separately, and then balance them separately.
A more desperate type of salvage effort involves following multi-step argument: First, fix both rows of equation 27 to account for the excess oxygen. Make the questionable assumption that the Pb row in equation 27 evolves its excess oxygen in the form of O2 (as in equation 18) rather than NO2 (as in equation 20) or something else. Similarly, make the questionable assumption that the Cr row evolves its excess oxygen in the form of O2. Then let one of the two reactions proceed forward. Make the questionable assumption that we can make the other reaction proceed backwards, soaking up the excess oxygen. This desperate process results in the “salvaged” reaction equation given below, namely equation 28.
This illustrates something that may seem like a weakness of the Gaussian elimination procedure, but which may sometimes be a strength, in the proper hands. Note that equation 26 is mathematically well-posed; that is, it is neither overdetermined nor underdetermined. If you just feed it into the Gaussian elimination procedure and turn the crank, you will find a solution.
The tricky thing is that it will find a negative value for the coefficient (a).
There is a simple rule: If you see a negative coefficient in front of an alleged reactant, it is really a product. You should move it to the other side of the reaction equation (which changes the sign of the coefficient). Similarly, if you see a negative coefficient in front of an alleged product, it is really a reactant. Move it to the other side.
The following rewrite of equation 26 can be solved using only positive coefficients:
| (28) |
Generally, though, if you see a negative coefficient it should put you on guard. It indicates there was a misconception in the original reaction equation. Perhaps it was just a benign, isolated misconception, but perhaps not; perhaps it is only the tip of the iceberg. You should careful re-examine the situation, and do whatever you have to do to obtain the correct reaction equation.
In particular, the argument leading to equation 28 depends on a multitude of questionable assumptions.
Important remark: Stoichiometry and equation-balancing are simple mathematical exercises if – and only if – you can rely on the correctness of the reaction equation you are asked to balance. To say the same thing the other way: mathematics is not a viable substitute for understanding what chemistry is actually occurring.
Gaussian elimination requires a lot of steps. Each step is extremely simple – a ten-year-old could do each step – but there are a lot of steps.
Suppose there are 11 rows in your tableau, as there are in equation 14. Each row requires a few very simple one-digit multiplications and one-digit additions. So all in all, there could be something like 100 elementary operations.
Now, suppose you can do each elementary operation with 95% reliability. Do you think this should be considered “grade-A” work, because 95% of it is correct? There’s a problem with that. At this rate, the probability that you will generate a fully-correct tableau is 0.95 to the 100th power, which is less than one percent!
You will know that you’ve made a mistake, because the coefficients you have calculated do not in fact balance the equation. This is your cue to re-do the problem, more carefully.
To turn the previous probability calculation on its head, if you want to be able to finish the tableau and have a 95% chance that the whole thing is correct, you need to perform each elementary operation with reliability 99.95%. That sounds like a pretty high probability, but there’s no reason why you can’t achieve it. Remember, each of the elementary operations is very simple.
So the question is: can you do simple things reliably?
Some standard advice to increase the convenience and/or reliability of your calculations can be found in reference 3.