Numerical Linear Equations
Numerical Solution of Linear Systems
Circuit node voltages, truss member forces and temperatures on a heated plate all lead to the same task: solving a system of linear equations Ax=b, where A is an n×n matrix of known coefficients, b is a known right-hand side and x holds the unknowns. Substitution works for two or three equations by hand, but real models have hundreds or millions of unknowns and run on computers that round results. You need algorithms that are systematic, efficient and stable under rounding. We focus on nonsingular systems, which have a unique solution, using direct elimination or iteration.
Gaussian elimination and back substitution
Gaussian elimination reduces the system to an equivalent upper-triangular one by subtracting multiples of one row from the rows below it. Working on the augmented matrix [A∣b] column by column, you clear each entry below the diagonal entry akk, called the pivot:
These row operations do not change the solution. Once the matrix is triangular, back substitution solves the last equation first and works upward:
where uij and ci are the entries of the triangular system.
Elimination costs about 32n3 flops, while back substitution costs only about n2. Elimination dominates, and doubling n multiplies its cost by about eight.
Example: A dense system with n=1000 needs roughly 32(1000)3≈6.7×108 flops for elimination but only about 106 for back substitution.
Pivoting and checking the answer
A zero pivot makes the multiplier undefined. A pivot tiny relative to other entries in its column can produce huge multipliers and amplify rounding errors. Partial pivoting reduces this risk. Before clearing column k, swap in the row at or below row k whose entry in column k has the largest absolute value. With a nonzero selected pivot, every multiplier satisfies ∣mik∣≤1 in exact arithmetic. Bounded multipliers reduce one source of instability, but do not prevent matrix entries from growing or rounding errors from being amplified.
For a nonsingular matrix, partial pivoting supplies nonzero pivots in exact arithmetic. If every eligible entry in a pivot column is zero, no row swap can supply a nonzero pivot: the matrix is singular, and this unique-solution procedure cannot continue.
After solving, compute the residual r=b−Ax~ for your computed solution x~. Assess its size relative to the scales of the coefficients, solution and right-hand side, using the solver's requested tolerance. An unexpectedly large residual on that basis warrants investigating arithmetic, code or convergence; its absolute magnitude alone does not establish an error. A small residual relative to these scales means the equations are nearly satisfied, but a small residual does not guarantee a small error when the system is ill-conditioned.
Iterative methods: Jacobi and Gauss–Seidel
For large systems in which most coefficients are zero, elimination can consume time and memory by filling in entries that started as zero. Iterative methods instead start from a guess x(0) and update it sweep by sweep. The Jacobi method solves equation i for xi using only values from the previous sweep:
The Gauss–Seidel method uses the same rearrangement but substitutes each new xj as soon as it is computed, so it often converges in fewer sweeps. Both methods converge from any starting guess when A is strictly diagonally dominant by rows:
This condition is sufficient, not necessary; some systems that fail it still converge. Stop when an appropriately scaled residual meets the chosen tolerance; changes between sweeps can provide an additional check.
Feature | Gaussian elimination | Jacobi and Gauss–Seidel |
|---|---|---|
Result | Exact solution after a fixed number of steps in exact arithmetic | Successive approximations that approach the solution when convergence holds |
Cost | About 32n3 flops | About 2n2 flops per sweep for a dense matrix, far fewer when most entries are zero |
Requirement | Nonsingular matrix; partial pivoting supplies nonzero pivots in exact arithmetic | Nonzero diagonal entries and convergence conditions, such as strict row diagonal dominance |
Best suited to | Small to medium dense systems | Large sparse systems when convergence is suitable |
What to remember
- Gaussian elimination makes the system upper triangular; back substitution solves it from the bottom up. Elimination costs about 32n3 flops.
- Partial pivoting moves whole rows, including b, and bounds multiplier magnitudes by 1 in exact arithmetic. It reduces instability but cannot guarantee freedom from rounding-error amplification or rescue a singular system.
- Check the residual against the problem scale and requested tolerance. A small residual is not proof of a small solution error.
- Jacobi uses previous-sweep values; Gauss–Seidel uses the newest values. Strict row diagonal dominance guarantees that both converge.
Example: Solving a 3 × 3 system with partial pivoting
A program you are testing must solve the system below. Work it by hand so you can compare your result with the program's output. All arithmetic here is exact in decimals, so carry every value exactly.
a) Use Gaussian elimination with partial pivoting to reduce the system to upper-triangular form. Record every row swap.
Column 1 holds the entries 1, 4 and 2. The largest in absolute value is 4, in row 2, so swap rows 1 and 2:
The multiplier for row 2 is 1/4 = ________ and the multiplier for row 3 is 2/4 = ________. Subtract those multiples of row 1:
- Row 2: [1, 2, 1∣3]−0.25[4, 1, −2∣1]=[0, 1.75, 1.5∣2.75]
- Row 3: [2, 3, 4∣13]−0.5[4, 1, −2∣1]=[0, 2.5, 5∣12.5]
In column 2, the entries on and below the diagonal are 1.75 and 2.5, so the new pivot is ________ and rows 2 and 3 swap. The multiplier for the remaining row is 1.75/2.5 = ________:
The upper-triangular system is
Two swaps were made: rows 1 and 2 for column 1, then rows 2 and 3 for column 2. Every multiplier (0.25, 0.5 and 0.7) has magnitude at most 1, as partial pivoting guarantees.
b) Use back substitution to find x, y and z.
Start with the last equation: −2z=−6, so z=3.
Substitute into the second equation: 2.5y+5(3)=12.5, so 2.5y=12.5−15 = ________ and y=−1.
Substitute both into the first equation: 4x+(−1)−2(3)=1, so 4x=1+1+6 = ________ and x=2.
The solution is x=2, y=−1, z=3. As a quick check, the original first equation gives 2+2(−1)+3=3, which matches its right-hand side.
c) A classmate's code reports x~=(2.1, −1.0, 2.9). Compute the residual r=b−Ax~ using the original equations, and say what it tells you.
Evaluate each original left-hand side at x~:
- Equation 1: 2.1+2(−1.0)+2.9=3.0
- Equation 2: 4(2.1)+(−1.0)−2(2.9)=8.4−1.0−5.8 = ________
- Equation 3: 2(2.1)+3(−1.0)+4(2.9)=4.2−3.0+11.6 = ________
Subtract each from its right-hand side:
The nonzero components show that x~ is not an exact solution. Nonzero residuals can arise from rounding or an iterative method's stopping tolerance, so compare the residual size with the required accuracy before concluding that the code is faulty. The zero first component is a warning against checking only one equation: x~ differs from the true solution by (0.1, 0, −0.1), yet it satisfies equation 1 exactly.
Arrange these stages of solving a dense linear system Ax=b by Gaussian elimination with partial pivoting in the order a program carries them out.
1.
Divide each entry below the pivot by the pivot to get the multipliers.
2.
In the current column, find the row at or below the diagonal with the largest absolute entry and swap it into the pivot position.
3.
Compute the residual b−Ax~ to check the computed solution.
4.
Move to the next column and repeat until the matrix is upper triangular.
5.
Subtract each multiplier times the pivot row from its row, including the right-hand-side entry.
6.
Form the augmented matrix [A∣b].
7.
Solve for the unknowns by back substitution, starting with the last equation.
A numerical solver applies valid row operations to three separate linear systems with real-valued unknowns x and y. The resulting equations below contain exact coefficients rather than rounded approximations. Complete each classification using exactly one of these labels: no solution, infinitely many solutions, or unique solution.
System P becomes
System P has .
System Q becomes
System Q has .
System R becomes
System R has a .