BetaFree coursewareRewritten from MIT OpenCourseWareCC BY-NC-SA 4.0
Open CosmologyPhysics & cosmology, from high school to a graduate year

Elimination with matrices

Elimination, the method every software package uses, solves Ax = b by subtracting multiples of a pivot row from the rows below it, so as to get zeros under each pivot and turn A into an upper triangular U. For x + 2y + z = 2, 3x + 8y + z = 12, 4y + z = 2, the multipliers 3 and 2 give the pivots 1, 2, 5 (their product, 10, is the determinant). Carrying the right-hand side along in the augmented matrix gives Ux = c with c = (2, 6, −10), and back substitution gives z = −2, y = 1, x = 2. A zero in a pivot position calls for a row exchange; if no row below can help, the matrix is not invertible. Each step is a multiplication by an elimination matrix such as E₂₁, and by the associative law E₃₂(E₂₁A) = (E₃₂E₂₁)A = U. A row times a matrix combines the rows; matrices on the left act on rows, on the right on columns; AB ≠ BA in general; and the inverse of 'subtract 3 times row 1' is 'add it back'.

You need this first

Full reading path (6 pages)
  1. Vectors (8.01)
  2. Vectors and the dot product (18.02)
  3. Determinants and the cross product (18.02)
  4. Planes through three points, and matrices (18.02)
  5. Equations of planes and square systems (18.02)
  6. The geometry of linear equations (18.06)
On this page · 5 sections
  1. Forward elimination
  2. Back substitution
  3. Rows and columns of a product
  4. Elimination matrices
  5. Summary

The second lecture solves Ax=bAx = b by elimination, the method every software package uses, and expresses it in matrix language (transcript, p. 1). Gauss thought of it first, Strang says, but only because he was born earlier (p. 1). It continues the geometry of linear equations.

Forward elimination#

The example (transcript, pp. 1–2):

The system
x+2y+z=2,3x+8y+z=12,4y+z=2;A=(121381041),b=(2122)x + 2y + z = 2, \quad 3x + 8y + z = 12, \quad 4y + z = 2; \qquad A = \begin{pmatrix} 1 & 2 & 1 \\ 3 & 8 & 1 \\ 0 & 4 & 1 \end{pmatrix}, \quad b = \begin{pmatrix} 2 \\ 12 \\ 2 \end{pmatrix}
In words

x plus 2 y plus z equals 2, 3 x plus 8 y plus z equals 12, 4 y plus z equals 2; capital A equals 1 2 1; 3 8 1; 0 4 1, b equals 2; 12; 2

Keep the first equation, and subtract a multiple of it from the second to knock out xx (p. 2). The 1 in the top left is the first pivot (pp. 2–3). The multiplier is 3: subtracting 3 times row 1 from row 2 leaves (0,2,−2)(0, 2, -2) (p. 3). That clears position (2, 1); position (3, 1) already holds 0, so its multiplier is 0 (pp. 3–4). Now xx is gone from the last two equations, and the second pivot is the 2. Subtracting 2 times row 2 from row 3 clears position (3, 2) and leaves the third pivot, 5 (p. 4):

Upper triangular result
A=(121381041)→(12102−2041)→(12102−2005)=UA = \begin{pmatrix} 1 & 2 & 1 \\ 3 & 8 & 1 \\ 0 & 4 & 1 \end{pmatrix} \to \begin{pmatrix} 1 & 2 & 1 \\ 0 & 2 & -2 \\ 0 & 4 & 1 \end{pmatrix} \to \begin{pmatrix} 1 & 2 & 1 \\ 0 & 2 & -2 \\ 0 & 0 & 5 \end{pmatrix} = U
In words

capital A equals 1 2 1; 3 8 1; 0 4 1 goes to 1 2 1; 0 2 minus 2; 0 4 1 goes to 1 2 1; 0 2 minus 2; 0 0 5 equals U

UU is upper triangular; getting from AA to UU is the most common calculation in scientific computing (p. 5). Pivots may not be 0, and here they are 1, 2, 5; their product is the determinant, 10 (p. 5).

How elimination can fail (pp. 5–7). A 0 in a pivot position is not the end: exchange rows with a lower equation that has a nonzero entry there (pp. 5–6). Changing the 8 to a 6 would make the second pivot position 0, but the 4 below would allow an exchange (p. 6). Changing the coefficient of zz in the third equation from 1 to −4-4, however, would turn the third pivot into 0 with nothing below: complete failure, and the matrix would not be invertible (pp. 6–7).

Back substitution#

Carry the right-hand side along as an extra column, the augmented matrix [A  b][A\;b] (transcript, p. 7). The steps change b=(2,12,2)b = (2, 12, 2) to (2,6,2)(2, 6, 2) and then to c=(2,6,−10)c = (2, 6, -10) (p. 8). (On p. 7 the transcript says "2 of the first equation"; the multiplier is 3.) The equations Ux=cUx = c are (p. 9)

Triangular system
x+2y+z=2,2y−2z=6,5z=−10x + 2y + z = 2, \qquad 2y - 2z = 6, \qquad 5z = -10
In words

x plus 2 y plus z equals 2, 2 y minus 2 z equals 6, 5 z equals minus 10

Solve from the bottom up, since the system is triangular: z=−2z = -2, then 2y+4=62y + 4 = 6 gives y=1y = 1, then x+2−2=2x + 2 - 2 = 2 gives x=2x = 2 (p. 9).

Rows and columns of a product#

A matrix times a column is a combination of the matrix's columns: A(3,4,5)A(3, 4, 5) is 3 times column 1 plus 4 times column 2 plus 5 times column 3 (transcript, p. 10). The parallel fact for rows, which matters because elimination works on rows (pp. 10–11):

Row times matrix
(127)A=1 (row 1)+2 (row 2)+7 (row 3)\begin{pmatrix} 1 & 2 & 7 \end{pmatrix}A = 1\,(\text{row } 1) + 2\,(\text{row } 2) + 7\,(\text{row } 3)
In words

1 2 7 capital A equals 1 ( row 1) plus 2 ( row 2) plus 7 ( row 3)

Elimination matrices#

The first step, subtracting 3 times row 1 from row 2, is a multiplication by the elimination matrix E21E_{21} (transcript, pp. 11–13). Rows 1 and 3 stay, so their rows of E21E_{21} are (1,0,0)(1, 0, 0) and (0,0,1)(0, 0, 1); leaving everything alone would be the identity matrix II (p. 12). Row 2 must take −3-3 of row 1 plus 1 of row 2 (pp. 12–13):

Elimination matrices
E21=(100−310001),E32=(1000100−21)E_{21} = \begin{pmatrix} 1 & 0 & 0 \\ -3 & 1 & 0 \\ 0 & 0 & 1 \end{pmatrix}, \qquad E_{32} = \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & -2 & 1 \end{pmatrix}
In words

E two one equals 1 0 0; minus 3 1 0; 0 0 1, E three two equals 1 0 0; 0 1 0; 0 minus 2 1

One entry of a product can be checked by a dot product: row 2 of E21E_{21} with column 3 of AA gives −3+1+0=−2-3 + 1 + 0 = -2 (p. 13). The whole of elimination is then (p. 15)

Elimination in one line
E32(E21A)=U=(E32E21)AE_{32}(E_{21}A) = U = (E_{32}E_{21})A
In words

E three two ( E two one capital A ) equals U equals ( E three two E two one ) capital A

The parentheses can be moved, the associative law, though it takes work to prove; so the single matrix E32E21E_{32}E_{21} does all of elimination at once (pp. 15–16). Strang notes that there is a better way to see it, going from UU back to AA, which is the next lecture but one (pp. 18–19).

Permutations (pp. 16–18). A permutation matrix PP exchanges rows: do the exchange to the identity matrix and use the result, P=(0110)P = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}, so P(abcd)=(cdab)P\begin{pmatrix} a & b \\ c & d \end{pmatrix} = \begin{pmatrix} c & d \\ a & b \end{pmatrix} (p. 17). To exchange columns, the same matrix must multiply on the right: matrices on the left act on rows, on the right on columns (pp. 17–18). The order matters, AB≠BAAB \ne BA in general: the commutative law is false, though the associative law holds (p. 18).

A first inverse (pp. 19–20). What undoes E21E_{21}? It subtracted 3 times row 1 from row 2, so the inverse adds it back (p. 20):

Inverse of an elimination matrix
E21−1=(100310001),E21−1E21=IE_{21}^{-1} = \begin{pmatrix} 1 & 0 & 0 \\ 3 & 1 & 0 \\ 0 & 0 & 1 \end{pmatrix}, \qquad E_{21}^{-1}E_{21} = I
In words

E two one to the power minus 1 equals 1 0 0; 3 1 0; 0 0 1, E two one to the power minus 1 E two one equals capital I

Worked example

Eliminate and back-substitute

Solve x+y+2z=4x + y + 2z = 4, 2x+5y+3z=102x + 5y + 3z = 10, −x+2y+4z=5-x + 2y + 4z = 5 by elimination; give the pivots, the elimination matrices, and the determinant.

Column 1

Pivot 1. Subtract 2 times row 1 from row 2: (0,3,−1)(0, 3, -1) with right side 2, with E21E_{21} having −2-2 in position (2, 1). Add row 1 to row 3 (multiplier −1-1): (0,3,6)(0, 3, 6) with right side 9, with E31E_{31} having +1+1 in position (3, 1).

Column 2

Pivot 3. Subtract row 2 from row 3: (0,0,7)(0, 0, 7) with right side 7, with E32E_{32} having −1-1 in position (3, 2). The pivots are 1, 3, 7, so the determinant is 21.

Back substitution

7z=77z = 7 gives z=1z = 1; 3y−1=23y - 1 = 2 gives y=1y = 1; x+1+2=4x + 1 + 2 = 4 gives x=1x = 1. Check the third equation: −1+2+4=5-1 + 2 + 4 = 5.

Summary#

Symbols on this page

Show the 18 symbols used here
ℓ\ell script l.
A length or distance; ℓ_p is a physical distance and ℓ_c a comoving one. Unit: m (a comoving ℓ_c is in notches, Guth's units). Say it: “ell”.
≠\neq not equal.
Is not equal to. Say it: “is not equal to”.
→\to arrow.
Goes to (tends to), or becomes. Say it: “goes to”.
aa a.
An entry of a 2 × 2 matrix. Say it: “a”.
zz z.
The third unknown. Say it: “z”.
cc c.
The right-hand side after elimination: Ux = c; in the 2 × 2 example, an entry of the matrix. Say it: “c”.
xx x.
The first unknown; in bold, the vector of unknowns. Say it: “x”.
yy y.
The second unknown. Say it: “y”.
dd d.
An entry of a 2 × 2 matrix. Say it: “d”.
PP P.
A permutation matrix, which exchanges rows (on the left) or columns (on the right). Say it: “capital P”.
AA A.
The coefficient matrix. Say it: “capital A”.
BB B.
A second matrix (in AB ≠ BA). Say it: “capital B”.
bb b.
The right-hand side vector; in the 2 × 2 example, an entry of the matrix. Say it: “b”.
UU U.
The upper triangular matrix that elimination produces from A. Say it: “U”.
II I.
The identity matrix. Say it: “capital I”.
E21E_{21} E two one.
The elimination matrix that clears position (2, 1). Say it: “E two one”.
E31E_{31} E three one.
The elimination matrix that clears position (3, 1). Say it: “E three one”.
E32E_{32} E three two.
The elimination matrix that clears position (3, 2). Say it: “E three two”.

Tap or click a symbol in a formula to see the same explanation. All symbols: symbols and notation.

Words on this page

Show the 19 words used here

New here

triangular matrix.
A square matrix with only zeros below its diagonal (upper triangular) or only zeros above it (lower triangular).
augmented matrix.
A matrix with an extra column, the right-hand side b, added to it, so that elimination works on the equations and b together.
elimination matrix.
A matrix that carries out one step of elimination, subtracting a multiple of one row from another, when it multiplies a matrix.
associative law.
The rule that grouping does not matter: when three things are combined, which pair is combined first makes no difference.
permutation.
A rearrangement of a list of things into a new order.
permutation matrix.
A matrix made by reordering the rows of the identity matrix; multiplying by it reorders the rows of another matrix the same way.

Also used

elimination.
Solving equations by subtracting multiples of one from another until each unknown can be found in turn. Explained in The geometry of linear equations.
matrix.
A rectangular table of numbers, which acts on vectors to give new ones and so describes a linear change of coordinates. Explained in Planes through three points, and matrices.
p..
Page, in a reference to a source; pp. means pages, as in pp. 3–5.
linear.
Of a map, operator or equation: respecting sums and multiples, so that L(au + bv) = aL(u) + bL(v). Explained in The geometry of linear equations.
pivot.
In elimination, the first nonzero number in a row, used to clear out the entries below it. Explained in Positive definite matrices and minima.
determinant.
A single number worked out from a square array of numbers (a matrix), which measures how the matrix stretches areas or volumes. Explained in Determinants and the cross product.
invertible.
Of a square matrix or operator: having an inverse that undoes it; for a matrix this happens exactly when its determinant is not zero. Explained in The geometry of linear equations.
identity matrix.
The square matrix with ones down its main diagonal and zeros elsewhere; it leaves every vector unchanged. Explained in Planes through three points, and matrices.
dot product.
A way of multiplying two vectors that gives a number: multiply matching components and add, or lengths times the cosine of the angle between them. Explained in Vectors and the dot product.
commutative.
Of an operation: giving the same result in either order, as in a + b = b + a. Explained in Vectors.
inverse.
The thing that undoes another: a matrix times its inverse gives the identity matrix, as a function followed by its inverse gives back the start. Explained in Planes through three points, and matrices.
row exchange.
Swapping two rows of a matrix, needed in elimination when a zero sits where a pivot should be.

Academic

transcript.
A written record of exactly what was said in a recorded lecture, word for word.

Tap or click a word, here or in the text, for its meaning in this lesson. All words: the glossary. How many words are marked in the text: Reading options (the “Aa” button).

Where this leads

In cosmology

33 more cosmology pages that build on this

Pages that build on this

Practise

Check your understanding

  1. Which matrix subtracts 3 times row 1 from row 2 (of a 3 × 3 matrix)?
  2. To exchange the columns of a matrix, a permutation matrix must multiply it…
  3. When does elimination fail completely?
0 of 3 answered

Flashcards

1 / 3