Skip to article frontmatterSkip to article content

Chapter 6: Balancing Chemical Equations and Systems of Linear Algebraic Equations

Learning Objectives

By the end of this lecture, you should be able to:

  1. Balance chemical equations using algebraic methods and matrix representation.
  2. Solve systems of linear equations for stoichiometric coefficients using Python and NumPy.
  3. Apply the null space method to find balanced coefficients for chemical reactions.
  4. Interpret and generalize solutions to balance hydrocarbon combustion reactions and other chemical equations.

Balancing Chemical Equations

In the chemical sciences, one of the foundational skills is balancing chemical equations to ensure that no mass is lost or created, as dictated by the law of conservation of mass. This process ensures that the number of atoms of each element is the same on both sides of the reaction.

Consider the combustion of methane in oxygen:

aCH4(g)+bO2(g)cCO2(g)+dH2O(g)a \text{CH}_4(g) + b \text{O}_2(g) \rightarrow c \text{CO}_2(g) + d \text{H}_2\text{O}(g)

The goal is to determine the stoichiometric coefficients aa, bb, cc, and dd that balance the equation. We can do this systematically by ensuring the number of each type of atom is equal on both sides of the reaction. A useful approach is to create a table that tracks the number of atoms in the reactants and products for each element:

ElementReactantsProducts
Caacc
H4a4a2d2d
O2b2b2c+d2c + d

From this table, we can see the relationships between the variables. First, we know that for carbon to balance, a=ca = c, since there is one carbon atom in both methane and carbon dioxide. Substituting this into the table gives:

ElementReactantsProducts
Caaaa
H4a4a2d2d
O2b2b2a+d2a + d

Next, we balance hydrogen. Since there are 4 hydrogen atoms in methane, and each water molecule contains 2 hydrogen atoms, we know that 4a=2d4a = 2d, which simplifies to d=2ad = 2a. Updating the table:

ElementReactantsProducts
Caaaa
H4a4a4a4a
O2b2b2a+2a=4a2a + 2a = 4a

Finally, we balance oxygen. We have 2b2b oxygen atoms on the reactant side and 4a4a on the product side, so 2b=4a2b = 4a, meaning b=2ab = 2a.

Now, substituting these values into the chemical equation, with a=1a = 1 for simplicity, we get:

CH4(g)+2O2(g)CO2(g)+2H2O(g)\text{CH}_4(g) + 2 \text{O}_2(g) \rightarrow \text{CO}_2(g) + 2 \text{H}_2\text{O}(g)

Thus, the balanced chemical equation for the combustion of methane is:

CH4(g)+2O2(g)CO2(g)+2H2O(g)\text{CH}_4(g) + 2 \text{O}_2(g) \rightarrow \text{CO}_2(g) + 2 \text{H}_2\text{O}(g)

This systematic approach shows that we can think of balancing chemical equations as solving a set of linear equations for the stoichiometric coefficients.

Systems of Linear Algebraic Equations

Balancing chemical equations can be thought of as solving a system of linear algebraic equations. If we have the same number of equations as unknowns, we can solve for the unknowns using linear algebra techniques. Let’s revisit the methane combustion problem and express it as a system of equations.

For the balanced reaction:

aCH4(g)+bO2(g)cCO2(g)+dH2O(g)a \text{CH}_4(g) + b \text{O}_2(g) \rightarrow c \text{CO}_2(g) + d \text{H}_2\text{O}(g)

We can write the following set of equations based on the element balances:

  1. Carbon balance: ac=0a - c = 0 (since there is one carbon atom in both methane and carbon dioxide)
  2. Hydrogen balance: 4a2d=04a - 2d = 0 (4 hydrogen atoms in methane, 2 per water molecule)
  3. Oxygen balance: 2b2cd=02b - 2c - d = 0 (2 oxygen atoms in each oxygen molecule, balancing with oxygen in carbon dioxide and water)

This system of equations can be expressed as:

ac=04a2d=02b2cd=0\begin{align*} a - c &= 0 \\ 4a - 2d &= 0 \\ 2b - 2c - d &= 0 \\ \end{align*}

Next, we can write this in matrix form as:

[101040020221][abcd]=[000]\begin{align*} \begin{bmatrix} 1 & 0 & -1 & 0 \\ 4 & 0 & 0 & -2 \\ 0 & 2 & -2 & -1 \\ \end{bmatrix} \begin{bmatrix} a \\ b \\ c \\ d \\ \end{bmatrix} &= \begin{bmatrix} 0 \\ 0 \\ 0 \\ \end{bmatrix} \end{align*}

Here, the matrix on the left represents the coefficients of the unknowns aa, bb, cc, and dd, and the vector on the right is the zero vector because we are balancing the equation.

More concisely, this can be written as:

Ax=0\mathbf{A} \mathbf{x} = \mathbf{0}

Where:

Solving the System of Equations

Now, let’s apply what we’ve learned to solve the combustion of methane using Python. We’ll employ the numpy library for matrix operations and the scipy.linalg.null_space function to solve the system by finding the null space of the coefficient matrix.

Step 1: Import the Necessary Libraries

We’ll first import the libraries needed for our computation.

import numpy as np
from scipy.linalg import null_space

Step 2: Define the Coefficient Matrix, A\mathbf{A}

Next, we define the matrix A\mathbf{A}, which represents the coefficients of the unknowns aa, bb, cc, and dd in the system of equations:

A = np.array([[1, 0, -1, 0],
              [4, 0, 0, -2],
              [0, 2, -2, -1]])

This matrix corresponds to the carbon, hydrogen, and oxygen balances, respectively, for the combustion reaction.

Step 3: Compute the Null Space

To solve for the stoichiometric coefficients, we find the null space of matrix A\mathbf{A}. This will provide the ratios between aa, bb, cc, and dd that satisfy the system of linear equations:

# Calculate the null space of matrix A
null_vec = null_space(A)

The result is a vector of relative coefficients. However, we need to convert these into the smallest possible integer values to balance the equation correctly.

Step 4: Normalize and Convert to Integer Coefficients

We can normalize the null space vector by dividing by its smallest positive value and then round to obtain integer coefficients:

# Normalize the coefficients to the smallest integer values
coefficients = null_vec[:, 0] / np.min(null_vec[null_vec > 0])
coefficients = np.round(coefficients).astype(int)

coefficients
array([1, 2, 1, 2])

The resulting coefficients correspond to the stoichiometric coefficients for the reaction:

Step 5: The Balanced Chemical Equation

The balanced chemical equation for the combustion of methane is:

CH4(g)+2O2(g)CO2(g)+2H2O(g)\text{CH}_4(g) + 2\text{O}_2(g) \rightarrow \text{CO}_2(g) + 2\text{H}_2\text{O}(g)

This method can be generalized to balance any chemical equation using matrix algebra and Python.



Summary

In this section, we demonstrated how to solve the combustion reaction of methane by representing it as a system of linear equations. By using Python, we computed the null space of the coefficient matrix and found the stoichiometric coefficients needed to balance the equation. This same approach can be extended to balance more complex chemical reactions.

Example: Reduction of Tin(IV) Oxide by Hydrogen

Next, let’s explore the reduction of tin(IV) oxide by hydrogen to produce tin and water. The unbalanced chemical equation for this reaction is:

SnO2(s)+H2(g)Sn(s)+H2O(g)\text{SnO}_2(s) + \text{H}_2(g) \rightarrow \text{Sn}(s) + \text{H}_2\text{O}(g)

Balancing the Equation by Hand

Before we jump into solving this problem using Python, take a moment to try balancing this equation manually. Start by creating a table that tracks the number of atoms of each element on both sides of the reaction.

ElementReactantsProducts
Sn11
O21
H22

From this, you can see that the oxygen atoms are not balanced. We have 2 oxygen atoms on the left (from SnO₂) and only 1 oxygen atom on the right (in H₂O). Therefore, we’ll need to add a coefficient of 2 to the water molecule on the product side.

SnO2(s)+H2(g)Sn(s)+2H2O(g)\text{SnO}_2(s) + \text{H}_2(g) \rightarrow \text{Sn}(s) + 2\text{H}_2\text{O}(g)

Now, check the hydrogen atoms. We now have 4 hydrogen atoms on the right side (from 2 H₂O molecules), so we need 2 H₂ molecules on the left side to balance the hydrogen.

The balanced equation is:

SnO2(s)+2H2(g)Sn(s)+2H2O(g)\text{SnO}_2(s) + 2\text{H}_2(g) \rightarrow \text{Sn}(s) + 2\text{H}_2\text{O}(g)

Solving the Equation Using Python

Once you’ve manually balanced the equation, let’s confirm the result using Python. By writing the system of equations for the element balances, we can solve for the stoichiometric coefficients using matrix algebra.

import numpy as np
from scipy.linalg import null_space

# Define the matrix of coefficients
A = np.array([[1, 0, -1, 0],   # Sn balance
              [2, 0, 0, -1],   # O balance
              [0, 2, 0, -2]])  # H balance

# Compute the null space of the matrix A
null_vec = null_space(A)

# Normalize and convert to integer coefficients
coefficients = null_vec[:, 0]
coefficients = coefficients / np.min(coefficients[coefficients > 0])
coefficients = np.round(coefficients).astype(int)

# Output the coefficients
coefficients
array([1, 2, 1, 2])

This gives us the same result: 1 SnO₂ reacts with 2 H₂ to produce 1 Sn and 2 H₂O.


Recap

In this example, we manually balanced the reduction of tin(IV) oxide by hydrogen and confirmed our result using Python. You can apply this process to more complex reactions where balancing by hand might be more challenging.

By leveraging matrix algebra and Python, we can efficiently balance chemical equations, saving time and ensuring accuracy, especially for reactions involving multiple reactants and products.