• Practice
  • About 22 min
  • 5 practice questions

Solving systems of linear equations: matrix inversion, Cramer's rule and Gaussian elimination

Write a system of linear equations in the form AX = B, interpret its solutions geometrically, and solve it by the matrix inversion method, Cramer's rule and the Gaussian elimination method.

If something looks wrong, please tell us.

By the end of this lesson you can

  • Form a system of linear equations from a word problem and write it as AX = B.
  • Tell homogeneous from non-homogeneous systems and consistent from inconsistent ones.
  • Solve a system with a non-singular coefficient matrix by X = A⁻¹B.
  • Solve a system by Cramer's rule, xᵢ = Δᵢ/Δ.
  • Solve a system by Gaussian elimination and back substitution.

Systems of linear equations model problems in physics, chemistry, economics and engineering, from electric circuits to the balance of chemical reactions. This lesson writes such systems in matrix form and develops three methods to solve them.

Forming a system and its matrix form

Suppose (made-up data) two pens and three notebooks cost ₹110, while three pens and two notebooks cost ₹90. If a pen costs ₹x and a notebook ₹y, then 2x + 3y = 110 and 3x + 2y = 90. Both equations must hold for the same x and y; such values form a solution of the system.

In general, a system of m linear equations in n unknowns x₁, ..., xₙ has the form aᵢ₁x₁ + aᵢ₂x₂ + ... + aᵢₙxₙ = bᵢ for i = 1, ..., m. It is written AX = B, where the coefficient matrix A = [aᵢⱼ] is m × n, X is the n × 1 column of unknowns and B is the m × 1 column of constants. The matrix [A | B], formed by attaching B as an extra column, is the augmented matrix. If every bᵢ = 0 the system is homogeneous; if at least one bᵢ ≠ 0 it is non-homogeneous.

For example, the system 2x + 3y − 5z = 7, 7y + 2z = 1, 3x − y + 4z = 6 has A = [2 3 −5; 0 7 2; 3 −1 4], X = [x; y; z], B = [7; 1; 6] and [A | B] = [2 3 −5 | 7; 0 7 2 | 1; 3 −1 4 | 6]. Note the 0 for the missing x in the second equation.

What a solution looks like

A system with at least one solution is consistent; a system with no solution is inconsistent. In two unknowns each equation is a straight line, and three things can happen:

Two equations in two unknowns

  • Unique solution
    • x + y = 4 and x − y = 2
    • Lines cross at one point (3, 1)
    • Consistent
  • Infinitely many
    • x + 2y = 3 and 2x + 4y = 6
    • Second equation is twice the first
    • Same line: consistent
  • No solution
    • x + 2y = 3 and 2x + 4y = 7
    • Parallel, distinct lines
    • Inconsistent

Three operations never change the solutions of a system: interchanging two equations, multiplying an equation by a non-zero constant, and adding a multiple of one equation to another. They are exactly the elementary row operations of lesson 3, applied to the augmented matrix.

Method 1: matrix inversion

This method works when A is square and non-singular. Pre-multiplying AX = B by A⁻¹ gives A⁻¹AX = A⁻¹B, so X = A⁻¹B, and the solution is unique.

Worked example 1: matrix inversion method

Solve x + y + z = 4, x + 2y + 3z = 9, x + 4y + 9z = 25. Working: A = [1 1 1; 1 2 3; 1 4 9], and from lesson 1, |A| = 2 and A⁻¹ = (1/2)[6 −5 1; −6 8 −2; 2 −3 1]. Then X = A⁻¹B = (1/2)[6·4 − 5·9 + 1·25; −6·4 + 8·9 − 2·25; 2·4 − 3·9 + 1·25] = (1/2)[24 − 45 + 25; −24 + 72 − 50; 8 − 27 + 25] = (1/2)[4; −2; 6] = [2; −1; 3]. So x = 2, y = −1, z = 3. Check in the third equation: 2 − 4 + 27 = 25.

Method 2: Cramer's rule

For n equations in n unknowns with Δ = |A| ≠ 0, let Δᵢ be the determinant obtained from Δ by replacing its i-th column by the column of constants. Then xᵢ = Δᵢ/Δ. If Δ = 0, Cramer's rule cannot be applied.

x = Δ₁/Δ, y = Δ₂/Δ, z = Δ₃/Δ, where Δ₁, Δ₂, Δ₃ replace the x-, y- and z-columns of Δ by the constants. Valid only when Δ ≠ 0.

— Cramer's rule

Worked example 2: Cramer's rule

Solve x + y + z = 6, 2x − y + z = 3, x + 2y − z = 2. Working: Δ = |1 1 1; 2 −1 1; 1 2 −1| = 1(1 − 2) − 1(−2 − 1) + 1(4 + 1) = −1 + 3 + 5 = 7. Δ₁ = |6 1 1; 3 −1 1; 2 2 −1| = 6(1 − 2) − 1(−3 − 2) + 1(6 + 2) = −6 + 5 + 8 = 7. Δ₂ = |1 6 1; 2 3 1; 1 2 −1| = 1(−3 − 2) − 6(−2 − 1) + 1(4 − 3) = −5 + 18 + 1 = 14. Δ₃ = |1 1 6; 2 −1 3; 1 2 2| = 1(−2 − 6) − 1(4 − 3) + 6(4 + 1) = −8 − 1 + 30 = 21. So x = 7/7 = 1, y = 14/7 = 2, z = 21/7 = 3. Check: 2 − 2 + 3 = 3 and 1 + 4 − 3 = 2.

Worked example 3: a curve through three points

Find the parabola y = ax² + bx + c through (1, 2), (2, 3) and (3, 6), and its height at x = 4. Working: the points give a + b + c = 2, 4a + 2b + c = 3, 9a + 3b + c = 6. Δ = |1 1 1; 4 2 1; 9 3 1| = 1(2 − 3) − 1(4 − 9) + 1(12 − 18) = −1 + 5 − 6 = −2. Δₐ = |2 1 1; 3 2 1; 6 3 1| = 2(−1) − 1(3 − 6) + 1(9 − 12) = −2 + 3 − 3 = −2, so a = 1. Δ_b = |1 2 1; 4 3 1; 9 6 1| = 1(3 − 6) − 2(4 − 9) + 1(24 − 27) = −3 + 10 − 3 = 4, so b = 4/(−2) = −2. Δ_c = |1 1 2; 4 2 3; 9 3 6| = 1(12 − 9) − 1(24 − 27) + 2(12 − 18) = 3 + 3 − 12 = −6, so c = 3. The curve is y = x² − 2x + 3, and at x = 4, y = 16 − 8 + 3 = 11.

Method 3: Gaussian elimination

Reduce the augmented matrix [A | B] to row-echelon form, write the equivalent equations, and solve them from the last equation upwards (back substitution). This is the method of substitution organised by matrices, and unlike the first two methods it also works when A is singular or not square.

Worked example 4: Gaussian elimination

Solve 2x + y − z = 3, x − y + 2z = 5, 3x + 2y + z = 10. Working: [A | B] = [2 1 −1 | 3; 1 −1 2 | 5; 3 2 1 | 10]. R₁ ↔ R₂: [1 −1 2 | 5; 2 1 −1 | 3; 3 2 1 | 10]. R₂ → R₂ − 2R₁: [0 3 −5 | −7]. R₃ → R₃ − 3R₁: [0 5 −5 | −5], and R₃ → (1/5)R₃: [0 1 −1 | −1]. R₂ ↔ R₃, then R₃ → R₃ − 3R₂: [0 0 −2 | −4]. The echelon form gives x − y + 2z = 5, y − z = −1, −2z = −4. Back substitution: z = 2, y = −1 + 2 = 1, x = 5 + 1 − 4 = 2. So (x, y, z) = (2, 1, 2). Check in the third equation: 6 + 2 + 2 = 10.

Choosing a method
MethodNeedsBest for
Matrix inversionA square, |A| ≠ 0Several systems with the same A
Cramer's ruleA square, Δ ≠ 0Small systems; one unknown alone
Gaussian eliminationNothing extraAny system, including singular or non-square A

Key takeaways: write the system as AX = B and check |A| first; X = A⁻¹B and Cramer's xᵢ = Δᵢ/Δ need |A| ≠ 0; Gaussian elimination with back substitution always works; and always substitute the answer back into an equation you did not use last.

Check your understanding

  1. 1. Using Cramer's rule, what is x for the system 2x + y = 7, x − y = 2?

    1. 1
    2. −3
    3. 3
    4. 9
    Show answer

    Answer: C. Δ = |2 1; 1 −1| = −2 − 1 = −3. Δ₁ = |7 1; 2 −1| = −7 − 2 = −9. So x = Δ₁/Δ = −9/−3 = 3. (Then y = 1, and 2·3 + 1 = 7 checks.)

  2. 2. In the matrix inversion method for AX = B, which formula gives X, and when can it be used?

    1. X = BA⁻¹, whenever A is square
    2. X = A⁻¹B, when A is square and |A| ≠ 0
    3. X = A⁻¹B, for any matrix A
    4. X = (adj A)B, when |A| = 0
    Show answer

    Answer: B. Pre-multiplying AX = B by A⁻¹ gives X = A⁻¹B. This needs A⁻¹ to exist, so A must be square and non-singular. BA⁻¹ is the wrong order (B is a column) and adj A alone is missing the factor 1/|A|.

  3. 3. When can Cramer's rule NOT be applied to a system of n equations in n unknowns?

    1. When the constants are all positive
    2. When Δ₁ = 0
    3. When the system has three unknowns
    4. When Δ = 0
    Show answer

    Answer: D. Cramer's rule divides by Δ = |A|, so it fails when Δ = 0. Δ₁ = 0 is no problem: it just gives x₁ = 0.

  4. 4. After Gaussian elimination a system becomes x + y + z = 6, y + 2z = 8, 3z = 9. What is x?

    1. 1
    2. 2
    3. 3
    4. 6
    Show answer

    Answer: A. Back substitution: 3z = 9 gives z = 3; y + 2(3) = 8 gives y = 2; x + 2 + 3 = 6 gives x = 1.

  5. 5. What can be said about the system x + 2y = 4, 2x + 4y = 9?

    1. It has the unique solution (2, 1)
    2. It has infinitely many solutions
    3. It is inconsistent: the lines are parallel and distinct
    4. It is homogeneous
    Show answer

    Answer: C. Doubling the first equation gives 2x + 4y = 8, which contradicts 2x + 4y = 9 (8 ≠ 9). The two lines have the same slope but different intercepts, so they never meet and the system has no solution.

Privacy · Terms · Refunds · Delivery