Gaussian Elimination

Work in progress. This note is still being written and incomplete.

6 min read Last updated Mon Jul 20 2026 07:30:04 GMT+0000 (Coordinated Universal Time)

Gaussian elimination reduces Ax=bA\vec{x} = \vec{b} to echelon form by row operations, then solves it by back substitution.

Forward elimination

The pivot element of a column is the entry used to eliminate the other entries in that column.

Provided a110a_{11} \neq 0, eliminate x1x_1 from equations 22 through nn using

Rjaj1a11R1Rj,j=2,3,,nR_j - \frac{a_{j1}}{a_{11}} R_1 \to R_j, \quad j = 2, 3, \ldots, n

More generally, eliminate xix_i below row ii, for i=1,2,,n1i = 1, 2, \ldots, n-1, using

Rjaji(i)aii(i)RiRj,j=i+1,i+2,,nR_j - \frac{a_{ji}^{(i)}}{a_{ii}^{(i)}} R_i \to R_j, \quad j = i+1, i+2, \ldots, n

provided aii(i)0a_{ii}^{(i)} \neq 0. This reduces [Ab][A \mid \vec{b}] to upper triangular form

(a11a12a1nb1(1)0a22(1)a2nb2(2)00ann(n1)bn(n1))\begin{pmatrix} a_{11} & a_{12} & \cdots & a_{1n} & b_1^{(1)} \\ 0 & a_{22}^{(1)} & \cdots & a_{2n} & b_2^{(2)} \\ \vdots & & \ddots & \vdots & \vdots \\ 0 & 0 & \cdots & a_{nn}^{(n-1)} & b_n^{(n-1)} \end{pmatrix}

Back substitution

Once [Ab][A \mid \vec{b}] is upper triangular, each row has 1 fewer unknown than the row above it. The last row has only xnx_n

xn=bn(n1)ann(n1)x_n = \frac{b_n^{(n-1)}}{a_{nn}^{(n-1)}}

Each remaining unknown is then found from the bottom up, substituting in the ones already solved

xi=bi(i1)j=i+1naij(i1)xjaii(i1),i=n1,n2,,1x_i = \frac{b_i^{(i-1)} - \sum\limits_{j=i+1}^{n} a_{ij}^{(i-1)}x_j}{a_{ii}^{(i-1)}}, \quad i = n-1, n-2, \ldots, 1

Here, j=i+1naij(i1)xj\sum_{j=i+1}^{n} a_{ij}^{(i-1)}x_j is the contribution of the already-solved unknowns xi+1,,xnx_{i+1}, \ldots, x_n to row ii.

Pivoting

Pivoting is interchanging rows to place a useful entry in the pivot position. It only reorders rows, so the system produced is still equivalent to the original.

Partial pivoting

At stage ii, scan column ii from row ii to row nn, and swap the row with the largest absolute entry into row ii before eliminating.

Using the largest available entry as the pivot keeps the multipliers aji(i)aii(i)\frac{a_{ji}^{(i)}}{a_{ii}^{(i)}} at or below 11 in size, which stops them from amplifying rounding error.

Scaled partial pivoting

Partial pivoting alone can still pick a poor pivot if rows are scaled very differently, since an entry can be large only because its whole row has large entries.

Scaled partial pivoting corrects for this. For candidate entry aji(i)a_{ji}^{(i)}, compute the scale factor

sj=maxkajks_j = \max_k |a_{jk}|

then choose the row maximizing aji(i)sj\frac{|a_{ji}^{(i)}|}{s_j} instead of the raw entry aji(i)|a_{ji}^{(i)}|. This picks the pivot largest relative to its own row, not largest in absolute terms.

Apply scaled partial pivoting to

30.00x1+591400x2=5917005.291x16.130x2=46.78\begin{aligned} 30.00x_1 + 591400x_2 &= 591700 \\ 5.291x_1 - 6.130x_2 &= 46.78 \end{aligned} s1=max{30.00,591400}=591400,s2=max{5.291,6.130}=6.130s_1 = \max\{|30.00|, |591400|\} = 591400, \quad s_2 = \max\{|5.291|, |6.130|\} = 6.130 a11s1=30591400=5.073×105,a21s2=5.2916.130=0.8631\frac{|a_{11}|}{s_1} = \frac{30}{591400} = 5.073 \times 10^{-5}, \quad \frac{|a_{21}|}{s_2} = \frac{5.291}{6.130} = 0.8631

a21s2\dfrac{|a_{21}|}{s_2} is larger, so exchange R1R2R_1 \leftrightarrow R_2. Gauss elimination on the reordered system gives x1=10.00x_1 = 10.00 and x2=1.000x_2 = 1.000.

Pitfalls

Zero pivot

If aii(i)=0a_{ii}^{(i)} = 0 at any stage, the elimination formula divides by zero, even though the system may still have a unique solution.

Small pivot

A pivot that is small rather than zero doesn’t stop the algorithm, but dividing by it inflates the multipliers aji(i)aii(i)\frac{a_{ji}^{(i)}}{a_{ii}^{(i)}}. This amplifies rounding error already present in aji(i)a_{ji}^{(i)} and bj(i)b_j^{(i)}, which then propagates through every later stage and into back substitution.

Ill conditioning

A problem is ill-conditioned iff a small change in any of its elements causes a large change in its solution. Otherwise the problem is well-conditioned.

Round-off errors effectively change the elements of AA and b\vec{b} slightly. If the system is ill-conditioned, these small changes produce large errors in the solution.

If AA is close to singular, small errors in the input data or in rounding get magnified into large errors in x\vec{x}, even with pivoting. Pivoting controls error growth from the algorithm itself, but cannot fix a system that is inherently sensitive to small changes in its input.

Consider

(1111.0001)(xy)=(22.0001)\begin{pmatrix} 1 & 1 \\ 1 & 1.0001 \end{pmatrix}\begin{pmatrix}x\\y\end{pmatrix} = \begin{pmatrix}2\\2.0001\end{pmatrix}

with solution x=1,y=1x = 1, y = 1. Changing b2b_2 from 2.00012.0001 to 2.00022.0002, a change of 0.00010.0001, gives

(1111.0001)(xy)=(22.0002)\begin{pmatrix} 1 & 1 \\ 1 & 1.0001 \end{pmatrix}\begin{pmatrix}x\\y\end{pmatrix} = \begin{pmatrix}2\\2.0002\end{pmatrix}

with solution x=0,y=2x = 0, y = 2. A 0.00010.0001 change in b2b_2 moved xx by 11 and yy by 11. No amount of pivoting prevents this, since the coefficient matrix itself is nearly singular, det(1111.0001)=0.0001\det \begin{pmatrix} 1 & 1 \\ 1 & 1.0001 \end{pmatrix} = 0.0001.

Condition Number

A measure of the degree of ill-conditioning. Denoted as κ(A)\kappa(A). Defined as:

κ(A)=AA1\kappa(A) = \|A\| \, \|A^{-1}\|

A large κ(A)\kappa(A) means AA is close to singular, and small errors in b\vec{b} or in rounding get magnified into large errors in x\vec{x}.

{x+y=2x+1.001y=2{x+y=2x+1.001y=2.001\begin{cases} x + y = 2 \\ x + 1.001y = 2 \end{cases} \qquad \begin{cases} x + y = 2 \\ x + 1.001y = 2.001 \end{cases}

The left system has solution x=2x = 2, y=0y = 0. The right system, obtained by a 0.0010.001 change in one constant, has solution x=1x = 1, y=1y = 1. The coefficient matrix is ill-conditioned, with condition number 40044004.

Cost

MethodTimeSpace
Forward eliminationO(n3)O(n^3)O(n2)O(n^2)
Back substitutionO(n2)O(n^2)O(n2)O(n^2)

Space is O(n2)O(n^2) for both, for storing the augmented matrix [Ab][A \mid \vec{b}]. Elimination is done in place, so no extra storage proportional to n2n^2 is needed beyond this.

The O(n3)O(n^3) time cost of forward elimination makes Gaussian elimination unsuitable for repeatedly solving Ax=bA\vec{x} = \vec{b} for many different b\vec{b} with the same AA.

Was this helpful?