TExcelTAD
Home › Linear Algebra & Matrix Theory › Elementary Matrices

Elementary Matrices

Every elementary row operation can be carried out by multiplying on the left by a special matrix, an elementary matrix. This turns row reduction, an algorithm, into algebra: products of matrices. It explains why the [A∣I][A \mid I] method finds inverses, and it is the seed of the LU factorisation used by every numerical library.

Three kinds

An elementary matrix is what you get by applying one elementary row operation to the identity matrix II. There is one kind per row operation (Elementary Operations):

Row operation Elementary matrix (3×33 \times 3 example) Inverse
Swap rows ii and jj II with rows 1 and 3 swapped: [001010100]\begin{bmatrix} 0 & 0 & 1 \\ 0 & 1 & 0 \\ 1 & 0 & 0 \end{bmatrix} itself
Multiply row ii by c≠0c \ne 0 II with cc in position (2,2)(2,2): [1000c0001]\begin{bmatrix} 1 & 0 & 0 \\ 0 & c & 0 \\ 0 & 0 & 1 \end{bmatrix} same with 1/c1/c
Add c⋅(row j)c \cdot (\text{row } j) to row ii II with cc in position (3,1)(3,1): [100010c01]\begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ c & 0 & 1 \end{bmatrix} same with −c-c

Key fact: if EE is obtained from II by a row operation, then for any matrix AA with the right number of rows, EAEA is the result of applying that same row operation to AA.

The reason is the row view of multiplication: row ii of EAEA is (row i of E)⋅A(\text{row } i \text{ of } E) \cdot A, a combination of the rows of AA with the weights in row ii of EE. For the "add c⋅row 1c \cdot \text{row } 1 to row 3" matrix, row 3 of EE is [c,0,1][c, 0, 1], so row 3 of EAEA is c⋅(row 1 of A)+(row 3 of A)c \cdot (\text{row 1 of } A) + (\text{row 3 of } A).

python · try it yourself
from sympy import Matrix, eye

A = Matrix([[1, 2, 3],
            [4, 5, 6],
            [7, 8, 10]])

E_swap = eye(3); E_swap.row_swap(0, 2)
E_scale = eye(3); E_scale[1, 1] = 5
E_add = eye(3); E_add[2, 0] = -7          # R3 <- R3 - 7 R1

print("swap R1,R3 :", (E_swap * A).tolist())
print("5 * R2     :", (E_scale * A).tolist())
print("R3 - 7 R1  :", (E_add * A).tolist())
print("E_add inverse:", E_add.inv().tolist())
swap R1,R3 : [[7, 8, 10], [4, 5, 6], [1, 2, 3]]
5 * R2     : [[1, 2, 3], [20, 25, 30], [7, 8, 10]]
R3 - 7 R1  : [[1, 2, 3], [4, 5, 6], [0, -6, -11]]
E_add inverse: [[1, 0, 0], [0, 1, 0], [7, 0, 1]]

Multiplying on the right (AEAE) does the corresponding operation on the columns of AA instead.

Elementary matrices are invertible

Every row operation can be undone by another row operation of the same type (swap back, divide by cc, subtract c⋅row jc \cdot \text{row } j again). Hence every elementary matrix is invertible and its inverse is elementary, as the table shows.

Row reduction as a product

Row-reducing AA to its reduced echelon form RR with operations E1,E2,…,EkE_1, E_2, \ldots, E_k (in that order) means

Ek⋯E2E1A=RE_k \cdots E_2E_1 A = R

If AA is invertible, R=IR = I, so Ek⋯E1=A−1E_k \cdots E_1 = A^{-1}. Applying the same operations to II produces exactly that product, which is why [A∣I]→[I∣A−1][A \mid I] \to [I \mid A^{-1}] works (Matrix Inverses). Taking inverses gives the

Theorem. A square matrix is invertible if and only if it is a product of elementary matrices:

A=E1−1E2−1⋯Ek−1A = E_1^{-1}E_2^{-1} \cdots E_k^{-1}
python · try it yourself
from sympy import Matrix, Rational

A = Matrix([[2, 4], [3, 7]])
E1 = Matrix([[Rational(1, 2), 0], [0, 1]])       # R1 <- R1 / 2
E2 = Matrix([[1, 0], [-3, 1]])                   # R2 <- R2 - 3 R1
E3 = Matrix([[1, -2], [0, 1]])                   # R1 <- R1 - 2 R2
print("E3 E2 E1 A =", (E3 * E2 * E1 * A).tolist())
print("E3 E2 E1 == A^-1:", E3 * E2 * E1 == A.inv())
print("A == E1^-1 E2^-1 E3^-1:", A == E1.inv() * E2.inv() * E3.inv())
E3 E2 E1 A = [[1, 0], [0, 1]]
E3 E2 E1 == A^-1: True
A == E1^-1 E2^-1 E3^-1: True

LU factorisation

If you reduce AA to an upper triangular UU using only "add a multiple of a higher row to a lower row" operations, every EiE_i is lower triangular with 1s on the diagonal, and so is the product of their inverses, LL. The result is

A=LUL lower triangular (the multipliers), U upper triangular (the echelon form)A = LU \qquad L \text{ lower triangular (the multipliers)}, \ U \text{ upper triangular (the echelon form)}

With row swaps for numerical safety it becomes PA=LUPA = LU, where PP is a permutation matrix (a product of swap matrices). SciPy returns all three:

python · try it yourself
import numpy as np
from scipy.linalg import lu

A = np.array([[2.0, 1.0, 1.0],
              [4.0, 3.0, 3.0],
              [8.0, 7.0, 9.0]])
P, L, U = lu(A)                 # SciPy convention: A = P @ L @ U
print("L =", np.round(L, 4).tolist())
print("U =", np.round(U, 4).tolist())
print("A == P L U:", np.allclose(A, P @ L @ U))
L = [[1.0, 0.0, 0.0], [0.25, 1.0, 0.0], [0.5, 0.6667, 1.0]]
U = [[8.0, 7.0, 9.0], [0.0, -0.75, -1.25], [0.0, 0.0, -0.6667]]
A == P L U: True

Solving Ax=bA\mathbf{x} = \mathbf{b} then takes two cheap triangular solves (Ly=PTbL\mathbf{y} = P^T\mathbf{b}, then Ux=yU\mathbf{x} = \mathbf{y}), each O(n2)O(n^2) instead of O(n3)O(n^3).

In software

  • LU is how solve works. np.linalg.solve, MATLAB's A\b and LAPACK's gesv compute PA=LUPA = LU with partial pivoting (the PP chooses the largest available pivot for stability), then do two triangular solves. Factor once, solve many right-hand sides cheaply.
  • Nobody builds EE explicitly in code. Multiplying an n×nn \times n matrix by a dense elementary matrix costs about n3n^3 operations, while the row operation itself touches one row: about nn operations. The matrices are a proof tool; the loops are the implementation.
  • Permutation matrices reorder rows. In NumPy this is fancy indexing, A[[2, 0, 1]], which is the same as multiplying by the matching permutation matrix but far cheaper.

Exercises

Exercise 1: Name the operation

Which row operation does E=[1000100−41]E = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & -4 & 1 \end{bmatrix} perform, and what is E−1E^{-1}?

Answer

R3←R3−4⋅R2R_3 \leftarrow R_3 - 4 \cdot R_2; E−1=[100010041]E^{-1} = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 4 & 1 \end{bmatrix}.

Solution

EE differs from II only in entry (3,2)=−4(3, 2) = -4, so EAEA has row 3 replaced by row 3−4⋅row 2\text{row } 3 - 4 \cdot \text{row } 2. To undo it, add 4⋅row 24 \cdot \text{row } 2 back, which is the same matrix with +4+4 in position (3,2)(3, 2).

Exercise 2: Write the matrix

Write the 4×44 \times 4 elementary matrix that swaps rows 2 and 4, and check that it is its own inverse.

Answer

[1000000100100100]\begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \end{bmatrix}; E⋅E=IE \cdot E = I.

Solution

Swap rows 2 and 4 of I4I_4. Swapping twice restores the original order, so E2=IE^2 = I and E−1=EE^{-1} = E.

python · try it yourself
from sympy import eye
E = eye(4); E.row_swap(1, 3)
print(E.tolist(), E * E == eye(4))
[[1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0], [0, 1, 0, 0]] True

Exercise 3: Factor into elementary matrices

Write A=[1328]A = \begin{bmatrix} 1 & 3 \\ 2 & 8 \end{bmatrix} as a product of elementary matrices.

Answer

One answer: A=[1021]⋅[1002]⋅[1301]A = \begin{bmatrix} 1 & 0 \\ 2 & 1 \end{bmatrix} \cdot \begin{bmatrix} 1 & 0 \\ 0 & 2 \end{bmatrix} \cdot \begin{bmatrix} 1 & 3 \\ 0 & 1 \end{bmatrix}.

Solution
R2−2R1:[1302]E1=[10−21]R2/2:[1301]E2=[1001/2]R1−3R2:[1001]E3=[1−301]A=E1−1E2−1E3−1=[1021]⋅[1002]⋅[1301]\begin{aligned} R_2 - 2R_1\text{:} \quad & \begin{bmatrix} 1 & 3 \\ 0 & 2 \end{bmatrix} && E_1 = \begin{bmatrix} 1 & 0 \\ -2 & 1 \end{bmatrix} \\ R_2 / 2\text{:} \quad & \begin{bmatrix} 1 & 3 \\ 0 & 1 \end{bmatrix} && E_2 = \begin{bmatrix} 1 & 0 \\ 0 & 1/2 \end{bmatrix} \\ R_1 - 3R_2\text{:} \quad & \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} && E_3 = \begin{bmatrix} 1 & -3 \\ 0 & 1 \end{bmatrix} \\[1ex] A &= E_1^{-1}E_2^{-1}E_3^{-1} = \begin{bmatrix} 1 & 0 \\ 2 & 1 \end{bmatrix} \cdot \begin{bmatrix} 1 & 0 \\ 0 & 2 \end{bmatrix} \cdot \begin{bmatrix} 1 & 3 \\ 0 & 1 \end{bmatrix} \end{aligned}
python · try it yourself
from sympy import Matrix
print(Matrix([[1, 0], [2, 1]]) * Matrix([[1, 0], [0, 2]]) * Matrix([[1, 3], [0, 1]]))
Matrix([[1, 3], [2, 8]])

Exercise 4: Columns from the right

Compute A⋅EA \cdot E where A=[1234]A = \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} and E=[1501]E = \begin{bmatrix} 1 & 5 \\ 0 & 1 \end{bmatrix}. Which column operation happened?

Answer

AE=[17319]AE = \begin{bmatrix} 1 & 7 \\ 3 & 19 \end{bmatrix}: column 2←column 2+5⋅column 1\text{column } 2 \leftarrow \text{column } 2 + 5 \cdot \text{column } 1.

Solution
AE=[1⋅1+2⋅01⋅5+2⋅13⋅1+4⋅03⋅5+4⋅1]=[17319]column 2 changed from [2,4] to [7,19]=[2,4]+5⋅[1,3]\begin{aligned} &AE = \begin{bmatrix} 1 \cdot 1 + 2 \cdot 0 & 1 \cdot 5 + 2 \cdot 1 \\ 3 \cdot 1 + 4 \cdot 0 & 3 \cdot 5 + 4 \cdot 1 \end{bmatrix} = \begin{bmatrix} 1 & 7 \\ 3 & 19 \end{bmatrix} \\ &\text{column 2 changed from } [2, 4] \text{ to } [7, 19] = [2, 4] + 5 \cdot [1, 3] \end{aligned}

Test yourself

EE is I3I_3 with its rows 1 and 2 swapped. What is EAEA for a 3×n3 \times n matrix AA?

  1. AA with columns 1 and 2 swapped
  2. The transpose of AA
  3. AA unchanged
  4. AA with rows 1 and 2 swapped

What is the inverse of the elementary matrix that multiplies row 2 by 3?

  1. The matrix that multiplies row 2 by −3-3
  2. Itself
  3. The matrix that multiplies row 2 by 1/31/3
  4. It has no inverse

Which statement is true for an n×nn \times n matrix AA?

  1. Every product of elementary matrices is singular
  2. AA is invertible iff it is a product of elementary matrices
  3. Only diagonal matrices are products of elementary matrices
  4. Elementary matrices can be singular