Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

4.4: Swapping rows

Our factorization procedure divides by pivots. What if a pivot is zero? Sometimes the system has a unique solution, but its equations are in an inconvenient order.


When the first pivot is zero

Consider

[032−1][xy]=[68].\begin{bmatrix}0&3\\2&-1\end{bmatrix}\begin{bmatrix}x\\y\end{bmatrix} =\begin{bmatrix}6\\8\end{bmatrix}.

To find an LU factorization, we would need

[032−1]=[10ℓ1][pq0r].\begin{bmatrix}0&3\\2&-1\end{bmatrix} =\begin{bmatrix}1&0\\\ell&1\end{bmatrix}\begin{bmatrix}p&q\\0&r\end{bmatrix}.

The first row forces p=0p=0 and q=3q=3. But then the bottom-left entry of the product is ℓ⋅0=0\ell\cdot0=0, whereas we need it to be 2. There is no LU factorization in this row order.

The system itself is easy to solve: 3y=63y=6 gives y=2y=2, and 2x−y=82x-y=8 then gives x=5x=5.

Swap the two equations, keeping each right-hand side with its equation:

[2−103][xy]=[86].\begin{bmatrix}2&-1\\0&3\end{bmatrix}\begin{bmatrix}x\\y\end{bmatrix} =\begin{bmatrix}8\\6\end{bmatrix}.

Now the matrix is upper triangular, so its LU factorization has L=I2L=I_2 and U=[2−103]U=\begin{bmatrix}2&-1\\0&3\end{bmatrix}.


Permutation matrices

We can describe a row reordering with matrix multiplication too.

For two rows,

P=[0110],P[abcd]=[cdab],P[b1b2]=[b2b1].P=\begin{bmatrix}0&1\\1&0\end{bmatrix},\qquad P\begin{bmatrix}a&b\\c&d\end{bmatrix}=\begin{bmatrix}c&d\\a&b\end{bmatrix},\qquad P\begin{bmatrix}b_1\\b_2\end{bmatrix}=\begin{bmatrix}b_2\\b_1\end{bmatrix}.

For example, our reordered system above has PA=LUPA=LU.

Multiplying the original equation by PP gives

Ax⃗=b⃗⟺PAx⃗=Pb⃗⟺LUx⃗=Pb⃗.A\vec x=\vec b\quad\Longleftrightarrow\quad PA\vec x=P\vec b \quad\Longleftrightarrow\quad LU\vec x=P\vec b.

The equivalence holds because a row reordering can be undone: PP is invertible.

For our example, Pb⃗=[86]P\vec b=\begin{bmatrix}8\\6\end{bmatrix}. Since L=I2L=I_2, the first solve gives y⃗=Pb⃗\vec y=P\vec b, and the second gives x⃗=[52]\vec x=\begin{bmatrix}5\\2\end{bmatrix}.


Existence and uniqueness

The theorem does not say that PP is unique, or that every invertible matrix factors without reordering. Our first example shows why we may need a row swap.

Why reordering helps

At each stage, we subtract contributions already accounted for and look for the next nonzero pivot among the remaining rows. If the current row supplies a zero but a later row supplies a nonzero value, we move that row into the next position.

For an invertible matrix, a suitable row reordering always exists. We’ll explain why in Chapter 5, after introducing linear independence. For now, we’ll work out the complete two-by-two argument below.

Why the factors are unique

Once the row ordering is fixed, matching entries forces the first row of UU. The nonzero first pivot forces the first column of LL. Next, matching entries forces the second row of UU, and its nonzero pivot forces the second column of LL. Continuing leaves no choices.

The ones on the diagonal of LL matter. Without that convention, even A=I2A=I_2 could be written as (2I2)(12I2)(2I_2)(\frac12I_2) as well as I2I2I_2I_2.


The general two-by-two case

Let A=[abcd]A=\begin{bmatrix}a&b\\c&d\end{bmatrix} be invertible. Matching entries in

[abcd]=[10ℓ1][pq0r]\begin{bmatrix}a&b\\c&d\end{bmatrix} =\begin{bmatrix}1&0\\\ell&1\end{bmatrix} \begin{bmatrix}p&q\\0&r\end{bmatrix}

gives p=ap=a, q=bq=b, ℓa=c\ell a=c, and ℓb+r=d\ell b+r=d.

Case 1: a≠0a\ne0

We can divide by aa, giving ℓ=c/a\ell=c/a and r=d−cb/ar=d-cb/a. Thus

A=[10c/a1][ab0d−cb/a].\boxed{A=\begin{bmatrix}1&0\\c/a&1\end{bmatrix} \begin{bmatrix}a&b\\0&d-cb/a\end{bmatrix}.}

The second pivot is nonzero because

d−cba=ad−bca,d-\frac{cb}{a}=\frac{ad-bc}{a},

and invertibility means ad−bc≠0ad-bc\ne0, by the two-by-two inverse formula from Chapter 3.6. Every entry of the factors was forced, so they are unique.

Case 2: a=0a=0

Since AA is invertible, ad−bc=−bc≠0ad-bc=-bc\ne0. Thus both bb and cc are nonzero. The equation ℓ⋅0=c\ell\cdot0=c is impossible, so there is no LU factorization in the original row order.

Swapping the rows gives

PA=[cd0b]=[1001]⏟L[cd0b]⏟U.\boxed{PA=\begin{bmatrix}c&d\\0&b\end{bmatrix} =\underbrace{\begin{bmatrix}1&0\\0&1\end{bmatrix}}_L \underbrace{\begin{bmatrix}c&d\\0&b\end{bmatrix}}_U.}

Both pivots are nonzero, so substitution works.

For an invertible two-by-two matrix, we now have a complete rule: factor in the original order when a≠0a\ne0; swap the equations first when a=0a=0. Larger matrices can require swaps at later stages too.

A zero pivot by itself does not tell us that a matrix is non-invertible. We first need to ask whether reordering can resolve it. Next, we’ll turn to square matrices that really are non-invertible, and then to systems whose coefficient matrices aren’t square.