MATH-125 · Lesson 2 of 5 · 39 min

Systems of linear equations

Write the equilibrium equations at every joint of a bridge truss and you get a system of linear equations. So do Kirchhoff's laws for a circuit, mass balances around a chemical plant, the stiffness equations of a finite-element model and the least-squares fit of a calibration curve. Large engineering models routinely produce systems with thousands or millions of unknowns, and solving them is one of the most heavily used computations in the world.

This chapter teaches the method behind nearly all of those solvers: Gaussian elimination. You will learn to set up a system as an augmented matrix, reduce it with row operations, read off the solution, and recognize when a system has no solution or infinitely many. You will also see why a computer can give a badly wrong answer to a system that looks harmless.

Linear equations and what a solution means

A linear equation in the unknowns \(x_1, x_2, \dots, x_n\) has the form \(a_1x_1 + a_2x_2 + \dots + a_nx_n = b\), where the coefficients \(a_i\) and the right-hand side \(b\) are constants. The unknowns appear only to the first power, never multiplied together, never inside a sine or a square root. \(3x - 2y + z = 7\) is linear; \(xy = 4\) and \(x^2 + y = 1\) are not.

A system is a set of such equations that must hold at the same time. A solution is a set of values that satisfies every equation. The key fact about linear systems is that there are only three possibilities:

  • exactly one solution;
  • no solution (the system is inconsistent);
  • infinitely many solutions.

There is never exactly two or exactly five. With two unknowns you can see why: each equation is a straight line, and two lines either cross once, are parallel, or are the same line.

Three panels. Left: two lines crossing at the point (2, 2). Middle: two parallel lines that never meet. Right: two equations describing the same line.
The three possibilities for two equations in two unknowns.

In three unknowns each equation is a plane. Three planes usually meet at a single point, but they can also share a whole line, coincide, or have no common point at all. The algebra below sorts out which case you are in without any need to picture it.

The augmented matrix

Writing \(x\), \(y\), \(z\) and the plus signs again at every step is wasteful. Since only the numbers change, we record the coefficients and right-hand sides in a rectangular table called the augmented matrix. The system

\[\begin{aligned} x + y + z &= 6 \\ 2x - y + z &= 3 \\ x + 2y - z &= 2 \end{aligned} \qquad\text{becomes}\qquad \left[\begin{array}{ccc|c} 1 & 1 & 1 & 6 \\ 2 & -1 & 1 & 3 \\ 1 & 2 & -1 & 2 \end{array}\right]\]

Each row is one equation, each column to the left of the bar belongs to one unknown, and the last column holds the right-hand sides. The left part alone is the coefficient matrix \(A\). In matrix notation (Lesson 3) the system is written \(A\mathbf{x} = \mathbf{b}\).

Row operations

Three operations change a system into an equivalent one, meaning it has exactly the same solutions:

  • Swap two rows (write the equations in a different order).
  • Multiply a row by a non-zero constant.
  • Add a multiple of one row to another row.

None of these can create or destroy a solution, and each can be undone. The third is the workhorse: we use it to eliminate unknowns. Notation: \(R_2 \to R_2 - 2R_1\) means "replace row 2 with row 2 minus twice row 1".

Gaussian elimination

The goal is row echelon form: a staircase shape in which each row's first non-zero entry (its pivot) lies to the right of the pivot above it, and everything below each pivot is zero. Then the last equation has one unknown, the one above it has two, and so on, and you can solve from the bottom up by back substitution.

The procedure, column by column:

  • Choose a pivot: a non-zero entry in the current column, at or below the current row. Swap it into place if needed.
  • Use it to make every entry below it zero, with operations of the form \(R_i \to R_i - m R_{\text{pivot}}\), where the multiplier \(m\) is the entry divided by the pivot.
  • Move one row down and one column right, and repeat.

Worked problem

A full elimination

Solve \(x + y + z = 6\), \(2x - y + z = 3\), \(x + 2y - z = 2\).

Show solution
  1. Pivot is the 1 in row 1, column 1. Clear below it with \(R_2 \to R_2 - 2R_1\) and \(R_3 \to R_3 - R_1\):
  2. \[\left[\begin{array}{ccc|c} 1 & 1 & 1 & 6 \\ 0 & -3 & -1 & -9 \\ 0 & 1 & -2 & -4 \end{array}\right]\]
  3. Next pivot is the \(-3\) in row 2, column 2. Multiplier for row 3 is \(1/(-3)\), so \(R_3 \to R_3 + \tfrac13 R_2\):
  4. \[\left[\begin{array}{ccc|c} 1 & 1 & 1 & 6 \\ 0 & -3 & -1 & -9 \\ 0 & 0 & -\tfrac73 & -7 \end{array}\right]\]
  5. Back substitution. Row 3: \(-\tfrac73 z = -7\), so \(z = 3\).
  6. Row 2: \(-3y - 3 = -9\), so \(y = 2\).
  7. Row 1: \(x + 2 + 3 = 6\), so \(x = 1\).
  8. Check in the original second equation: \(2(1) - 2 + 3 = 3\). Correct.

Answer: x = 1, y = 2, z = 3

Reduced row echelon form

If you keep going, scaling each pivot to 1 and clearing the entries above the pivots as well as below, you reach reduced row echelon form (RREF). This is Gauss–Jordan elimination. In RREF the solution can be read directly with no back substitution. For the example above, the RREF is

\[\left[\begin{array}{ccc|c} 1 & 0 & 0 & 1 \\ 0 & 1 & 0 & 2 \\ 0 & 0 & 1 & 3 \end{array}\right]\]

By hand, plain elimination with back substitution takes fewer operations. Gauss–Jordan becomes the method of choice when you want a matrix inverse (Lesson 3), and the RREF is the clearest way to see the structure of systems with many or no solutions.

Systems with no solution or many solutions

Elimination detects the other two cases automatically.

If a row reduces to \(\left[\,0 \;\; 0 \;\; \cdots \;\; 0 \mid c\,\right]\) with \(c \ne 0\), it says \(0 = c\). That is impossible, so the system has no solution. The equations contradict each other.

Worked problem

An inconsistent system

Solve \(x + y + 2z = 4\), \(2x - y + z = 2\), \(3x + 3z = 7\).

Show solution
  1. \(R_2 \to R_2 - 2R_1\) gives \([0, -3, -3 \mid -6]\). \(R_3 \to R_3 - 3R_1\) gives \([0, -3, -3 \mid -5]\).
  2. \(R_3 \to R_3 - R_2\) gives \([0, 0, 0 \mid 1]\), meaning \(0 = 1\).
  3. Looking back, the left side of equation 3 is the sum of equations 1 and 2, but its right side is 7, not 4 + 2 = 6.

Answer: No solution. The three planes have no common point

If there is no contradiction but some column has no pivot, the unknown for that column is a free variable. It can take any value, and the pivot variables are expressed in terms of it. Every value of the free variable gives a solution, so there are infinitely many.

Worked problem

A free variable

Solve \(x + 2y - z = 3\), \(2x + 4y + z = 9\), \(3x + 6y = 12\).

Show solution
  1. \(R_2 \to R_2 - 2R_1\): \([0, 0, 3 \mid 3]\). \(R_3 \to R_3 - 3R_1\): \([0, 0, 3 \mid 3]\).
  2. \(R_3 \to R_3 - R_2\): \([0, 0, 0 \mid 0]\), which says \(0 = 0\). No contradiction.
  3. Pivots are in the \(x\) and \(z\) columns. The \(y\) column has none, so \(y\) is free. Let \(y = t\).
  4. Row 2: \(3z = 3\), so \(z = 1\). Row 1: \(x + 2t - 1 = 3\), so \(x = 4 - 2t\).

Answer: (x, y, z) = (4 − 2t, t, 1) for any t: a whole line of solutions

Rank and counting solutions

The number of pivots is the rank of the matrix. For a system with \(n\) unknowns:

  • If the augmented matrix has a pivot in its last column, there is no solution.
  • Otherwise, if the rank equals \(n\), there is exactly one solution.
  • Otherwise there are \(n - \text{rank}\) free variables and infinitely many solutions.

A homogeneous system, where every right-hand side is zero (\(A\mathbf{x} = \mathbf{0}\)), always has at least the solution \(\mathbf{x} = \mathbf{0}\). It has other solutions exactly when there are free variables. Homogeneous systems turn up in balancing chemical equations and, in Lesson 5, in finding eigenvectors.

Worked problem

Balancing a combustion equation

Balance \(a\,\text{C}_3\text{H}_8 + b\,\text{O}_2 \to c\,\text{CO}_2 + d\,\text{H}_2\text{O}\) for propane burning in a furnace.

Show solution
  1. Conserve each element. Carbon: \(3a = c\). Hydrogen: \(8a = 2d\). Oxygen: \(2b = 2c + d\).
  2. Three equations, four unknowns, all right-hand sides zero: a homogeneous system with one free variable. Take \(a\) as free.
  3. Then \(c = 3a\), \(d = 4a\), and \(2b = 6a + 4a\), so \(b = 5a\).
  4. Choose \(a = 1\) for the smallest whole numbers.

Answer: C₃H₈ + 5 O₂ → 3 CO₂ + 4 H₂O. Every multiple is also balanced, which is the free variable at work

Engineering applications

Two problems show how systems arise in practice. In both, the physics gives one equation per unknown, and the equations are linear because the underlying laws (equilibrium, Ohm's law) are linear.

Forces at a joint

A 10 kN load hangs from a joint held by two cables. Cable A rises to the left at 30 degrees above horizontal; cable B rises to the right at 45 degrees.
Two cables hold a 10 kN load. The tensions are the unknowns.

Worked problem

Cable tensions

A 10 kN load hangs from two cables. Cable A pulls up and to the left at 30° above horizontal; cable B pulls up and to the right at 45°. Find both tensions.

Show solution
  1. Equilibrium at the joint: the forces sum to zero in each direction.
  2. Horizontal: \(-T_A\cos 30^\circ + T_B\cos 45^\circ = 0\), that is \(-0.8660\,T_A + 0.7071\,T_B = 0\).
  3. Vertical: \(T_A\sin 30^\circ + T_B\sin 45^\circ = 10\), that is \(0.5\,T_A + 0.7071\,T_B = 10\).
  4. Subtract the first equation from the second: \(1.3660\,T_A = 10\), so \(T_A = 7.321\) kN.
  5. From the first equation: \(T_B = 0.8660 \times 7.321 / 0.7071 = 8.966\) kN.

Answer: T_A ≈ 7.32 kN, T_B ≈ 8.97 kN. The steeper cable carries more load

A real truss has one pair of equations like this at every joint. A bridge with 40 joints gives 80 equations, and the computer solves them by exactly the elimination you just did.

Currents in a circuit

A circuit with a 10 V battery, a 2 ohm resistor in the left loop, a 4 ohm resistor shared between the loops, and a 6 ohm resistor in the right loop. Clockwise mesh currents I1 and I2 are marked.
Two mesh currents; the shared 4 Ω resistor carries their difference.

Worked problem

Mesh analysis

In the circuit shown, find the mesh currents \(I_1\) and \(I_2\).

Show solution
  1. Kirchhoff's voltage law around each loop: the source voltage equals the sum of the resistor voltage drops.
  2. Left loop: \(2I_1 + 4(I_1 - I_2) = 10\), which simplifies to \(6I_1 - 4I_2 = 10\).
  3. Right loop (no source): \(6I_2 + 4(I_2 - I_1) = 0\), which simplifies to \(-4I_1 + 10I_2 = 0\).
  4. From the second equation, \(I_1 = 2.5\,I_2\). Substitute: \(15I_2 - 4I_2 = 10\), so \(I_2 = 10/11 = 0.909\) A.
  5. Then \(I_1 = 25/11 = 2.273\) A. The 4 Ω resistor carries \(I_1 - I_2 = 1.364\) A.

Answer: I₁ ≈ 2.27 A, I₂ ≈ 0.91 A

Notice that the coefficient matrix \(\begin{pmatrix} 6 & -4 \\ -4 & 10 \end{pmatrix}\) is symmetric. Resistor networks and spring networks always give symmetric matrices, and solvers exploit that to halve the work.

When computers struggle: pivoting and ill-conditioning

Elimination is exact in theory, but computers round every number to about 16 significant digits. Two practical issues follow.

First, partial pivoting. If a pivot is very small, the multipliers become huge and rounding errors are magnified. Software therefore swaps rows so that the largest available entry in the column becomes the pivot. When you work by hand you only need to swap when a pivot is exactly zero, but knowing why programs swap will help you read their documentation.

Second, some systems are ill-conditioned: tiny changes in the data cause huge changes in the solution. Geometrically, the lines (or planes) are nearly parallel, so their crossing point is poorly defined.

Worked problem

A nearly parallel system

Solve \(x + y = 2\), \(x + 1.0001y = 2.0001\). Then change the second right-hand side to 2.0002 and solve again.

Show solution
  1. Subtract: \(0.0001\,y = 0.0001\), so \(y = 1\) and \(x = 1\).
  2. With 2.0002: \(0.0001\,y = 0.0002\), so \(y = 2\) and \(x = 0\).
  3. A change of 0.005% in one number moved the solution from (1, 1) to (0, 2).

Answer: The two answers are completely different, because the two lines are almost parallel

If your data come from measurements, an ill-conditioned model means the measurement error can swamp the answer. The cure is usually in the engineering, not the arithmetic: choose better-separated sensor positions, or reformulate the model. Numerical-methods courses quantify this with the condition number of a matrix.

Common mistakes

  • MistakeApplying a row operation to the coefficients but forgetting the right-hand side.

    InsteadThe augmented column is part of every row. Whatever you do to a row, do it to the last entry too.

  • MistakeReplacing a row with a multiple of another row (R₂ → 3R₁), which loses an equation.

    InsteadOnly add a multiple of another row to a row: R₂ → R₂ − 3R₁.

  • MistakeReading a row of zeros, [0 0 0 | 0], as "no solution".

    Instead0 = 0 is always true; it signals a free variable. Only [0 0 0 | c] with c ≠ 0 means no solution.

  • MistakeGiving one particular solution when there are infinitely many.

    InsteadName the free variable as a parameter and give the general solution, e.g. (4 − 2t, t, 1).

  • MistakeChecking the answer in the reduced system.

    InsteadSubstitute into the original equations, where an arithmetic slip during elimination will show up.

  • MistakeTrusting a computed answer to many digits for a nearly singular system.

    InsteadIf small changes in the data move the answer a lot, the problem is ill-conditioned. Treat the result with suspicion.

Summary and key terms

  • A linear system has exactly one solution, none, or infinitely many.
  • Record the system as an augmented matrix [A | b]. Row swaps, row scaling and adding a multiple of one row to another do not change the solutions.
  • Gaussian elimination reduces to row echelon form; back substitution then solves from the bottom up. Gauss–Jordan continues to reduced row echelon form.
  • A row [0 … 0 | c] with c ≠ 0 means no solution. A column without a pivot gives a free variable and infinitely many solutions.
  • Rank is the number of pivots. One solution requires rank equal to the number of unknowns.
  • Equilibrium, Kirchhoff's laws and conservation balances all produce linear systems.
  • Computers pivot to control rounding. Ill-conditioned systems are sensitive to tiny data changes.
Linear equation
An equation in which unknowns appear only to the first power, multiplied by constants.
Augmented matrix
The coefficients and right-hand sides of a system written as one table.
Row operations
Swap, scale and add-a-multiple: they do not change the solution set.
Pivot
The first non-zero entry of a row in echelon form.
Row echelon form
A staircase shape with zeros below every pivot.
Back substitution
Solving an echelon system from the last equation upward.
Free variable
An unknown whose column has no pivot; it can take any value.
Rank
The number of pivots in the echelon form.
Inconsistent
Having no solution.
Ill-conditioned
Very sensitive to small changes in the data.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Solve \(3x + 2y = 7\) and \(x - y = -1\).

    Show answer

    From the second, x = y − 1. Then 3y − 3 + 2y = 7, so y = 2 and x = 1.

  2. Solve by elimination: \(x + 2y + z = 4\), \(2x + 5y + 3z = 9\), \(-x + y + 2z = 3\).

    Show answer

    R₂ − 2R₁: [0 1 1 | 1]. R₃ + R₁: [0 3 3 | 7]. R₃ − 3R₂: [0 0 0 | 4]. That says 0 = 4, so no solution.

  3. Solve \(x - y + z = 2\), \(2x + y - z = 1\), \(x + 2y + 2z = 9\).

    Show answer

    R₂ − 2R₁: [0 3 −3 | −3]. R₃ − R₁: [0 3 1 | 7]. R₃ − R₂: [0 0 4 | 10], z = 2.5. Then 3y − 7.5 = −3, y = 1.5. x = 2 + 1.5 − 2.5 = 1.

  4. Find the general solution of \(x + y - z = 1\), \(2x + 3y + z = 4\).

    Show answer

    R₂ − 2R₁: [0 1 3 | 2]. z is free; let z = t. y = 2 − 3t, x = 1 − y + z = −1 + 4t. Solution (−1 + 4t, 2 − 3t, t).

  5. For which value of \(k\) does \(x + 2y = 3\), \(2x + ky = 6\) have infinitely many solutions? For which values does it have exactly one?

    Show answer

    R₂ − 2R₁: [0, k − 4 | 0]. If k = 4 the row is 0 = 0: infinitely many. Any other k: exactly one solution (x, y) = (3, 0).

  6. What is the rank of \(\begin{pmatrix} 1 & 2 & 3 \\ 2 & 4 & 6 \\ 1 & 0 & 1 \end{pmatrix}\)?

    Show answer

    Row 2 is twice row 1, so it reduces to zero. Rows 1 and 3 are independent. Rank 2.

  7. Balance \(a\,\text{CH}_4 + b\,\text{O}_2 \to c\,\text{CO}_2 + d\,\text{H}_2\text{O}\).

    Show answer

    C: a = c. H: 4a = 2d. O: 2b = 2c + d. With a = 1: c = 1, d = 2, b = 2. CH₄ + 2 O₂ → CO₂ + 2 H₂O.

  8. A 600 N lamp hangs from two cables, each at 40° above horizontal on either side. Find the tension in each.

    Show answer

    By symmetry the tensions are equal: 2T sin 40° = 600, T = 600/(2 × 0.6428) ≈ 467 N.

  9. Two loops share a 3 Ω resistor. The left loop has a 12 V source and a 1 Ω resistor; the right loop has a 2 Ω resistor and no source. Find the mesh currents.

    Show answer

    Left: I₁ + 3(I₁ − I₂) = 12, so 4I₁ − 3I₂ = 12. Right: 2I₂ + 3(I₂ − I₁) = 0, so I₁ = 5I₂/3. Then (20/3 − 3)I₂ = 12, I₂ = 36/11 ≈ 3.27 A, I₁ = 60/11 ≈ 5.45 A.

  10. Explain in one sentence why \(x + y = 1\), \(x + 0.999y = 1.001\) is risky to solve from measured data.

    Show answer

    The two lines are almost parallel, so a tiny error in any coefficient or right-hand side moves the intersection a long way (here the solution is x = 2, y = −1).

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz