A1323 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

A13 · Lesson 23 · Gaussian elimination: pivoting, cost and accuracy

The workhorse of linear algebra, and the one swap that keeps it honest

A7 factored matrices into LU and used the factors to solve systems. This lesson asks the numerical questions. How long does it take for a 10 000-node circuit? Why does every library swap rows as it goes, and what goes wrong if it doesn't? And when the computed solution satisfies the equations to 16 digits, why might it still be wrong in the fifth? The answers are an operation count of 23n3, a tiny pivot that magnifies rounding by 1020, and the condition number from lesson 3.

  • The system is εx1+x2=1, x1+x2=2, whose solution is x1=11−ε≈1. Both curves are computed in double precision in your browser.
  • Eliminating with ε as the pivot, without swapping rows, multiplies by 1/ε. As ε shrinks, rounding errors are magnified by that much: wrong in the fifth digit near 10−12, and x1=0 below 10−16.
  • Swapping the rows first (partial pivoting) makes the multiplier ε instead, and the answer stays right for every ε.

Predict

Solving a dense 1000 × 1000 system by LU takes about 0.07 s on a laptop. About how long does a dense 10 000 × 10 000 system take?

Name it

Cost

StepOperations
LU factorization, n×n23n3
forward and back substitution, per right-hand side2n2
tridiagonal (banded) factorization and solveabout 8n
inverse (don't form it)2n3

Factor once and reuse: k right-hand sides cost 23n3+2kn2. Solving with an explicit inverse costs more and is less accurate.

Pivoting

Elimination divides by the pivot, the diagonal entry of the current column. A small pivot makes large multipliers, which magnify rounding errors in everything they touch. Partial pivoting swaps rows so the pivot is the largest entry (in size) in its column below the diagonal; every multiplier is then at most 1. With it, LU is backward stable in practice: the computed solution solves (A+δA)x^=b with ‖δA‖ a modest multiple of u‖A‖.

Residual and error

The residual r=b−Ax^ is computable; the error x−x^ isn't. A backward-stable solver always makes the residual tiny, but

‖x−x^‖‖x‖≤κ(A)‖r‖‖A‖‖x^‖

so with κ=1011 a residual at rounding level still allows an error in the fifth digit. Iterative refinement (solve Aδ=r with the same LU and add δ, computing r in higher precision) recovers digits when κu < 1.

Scaling

Equations with wildly different units (volts, microamps and gigaohms in one matrix) make pivoting choose badly. Scale rows and columns to comparable sizes first; circuit simulators do this.

Worked example

Solve 10−20x1+x2=1, x1+x2=2 with and without pivoting, in double.

Show the solution
  1. Without pivoting: eliminate. The multiplier is 1020, so the second row becomes (1−1020)x2=2−1020
  2. Rounding. Both sides round to −1020, so x2=1.
  3. Back substitute. x1=(1−1)/10−20=0 Completely wrong.
  4. With the rows swapped. The multiplier is 10−20, and the second row becomes (1−10−20)x2=1−2×10−20 so x2=1.
  5. Back substitute. x1=2−1=1 Right to full precision.

Answer without pivoting the computed solution is x1=0, x2=1, completely wrong; with pivoting it is x1=x2=1, right to full precision.

Worked example

A transient simulation of a 2000-node circuit takes 10 000 time steps with the same matrix. Compare refactoring every step with factoring once.

Show the solution
  1. One factorization. 23(2000)3=5.3×109 operations.
  2. One solve. 2(2000)2=8×106
  3. Factor once and solve 10 000 times. 5.3×109+8×1010=8.5×1010
  4. Refactor every step. That costs 5.3×1013, over 600 times more.
  5. Nonlinear circuits. They change the matrix each Newton step, which is why their simulators work so hard on sparsity.

Answer factoring once costs about 8.5×1010 operations, against 5.3×1013 for refactoring every step, over 600 times more.

Worked example

Factor A=(211433879) as LU, and find its determinant.

Show the solution
  1. Eliminate the first column. Subtract 2 × row 1 from row 2 and 4 × row 1 from row 3: the rows become (0, 1, 1) and (0, 3, 5).
  2. Eliminate the second column. Subtract 3 × the new row 2 from row 3: (0, 0, 2).
  3. The factors. U is what's left, and L holds the multipliers: U=(211011002) L=(100210431)
  4. Determinant. It is the product of the pivots: 2×1×2=4
  5. Reuse. With the factors stored, each new right-hand side costs two triangular solves, about 2n2 operations instead of 23n3.

Answer L=(100210431), U=(211011002), and the determinant is 4.

Check

About how many arithmetic operations does LU factorization of a dense 2000 × 2000 matrix take?

Check

A computer runs dense linear algebra at 10 GFLOP/s. About how long does an LU factorization of a 3000 × 3000 matrix take?

Write units the way you normally would: 1.5 s and 1500 ms are the same answer.

Check

You factor a 500 × 500 matrix once and solve for 10 right-hand sides. About how many operations in all?

Check

How much memory does a dense 10000 × 10000 matrix of doubles need?

Check

A stable solver leaves a residual at rounding level, and κ(A)=1010. About how many digits of the solution can you trust?

Check

In partial pivoting, which row becomes the pivot row for a column?

Check

Factor A=(2118)=LU without pivoting.

(a)

What is the multiplier l21?

(b)

What is u22?

Check

Solve ax1+bx2=e, cx1+dx2=f by elimination.

Step 1

After subtracting ca times the first equation from the second, what is the second's right side?

Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.

Explain why

Why does a tiny pivot ruin Gaussian elimination even when the matrix is well-conditioned?

Practice

Keep practicing

9 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.