{"id":185,"date":"2026-11-13T12:33:53","date_gmt":"2026-11-13T04:33:53","guid":{"rendered":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-gaussian-elimination-reaches-row-echelon-form\/"},"modified":"2026-11-13T21:52:03","modified_gmt":"2026-11-13T13:52:03","slug":"how-gaussian-elimination-reaches-row-echelon-form","status":"publish","type":"post","link":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-gaussian-elimination-reaches-row-echelon-form\/","title":{"rendered":"How Gaussian elimination reaches row echelon form"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Short answer:<\/strong> <strong>Gaussian elimination<\/strong> reduces a matrix to row echelon form by clearing each column under a pivot. Partial pivoting swaps into the pivot row the remaining row with the largest absolute value in that column. With that swap, the algorithm is the standard numerically stable solver for a nonsingular linear system. The arithmetic count is <strong>O(n\u00b3)<\/strong> for an n by n system, specifically about <strong>2n\u00b3\/3<\/strong> flops for the elimination and <strong>O(n\u00b2)<\/strong> for the back-substitution. A zero column that survives pivoting means the matrix is singular or rank-deficient.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the problem actually asks<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">A linear system Ax = b is a set of hyperplanes. Adding a multiple of one equation to another does not change the solution set. Elimination uses that fact to make the system triangular, after which back-substitution reads the unknowns from the bottom. Without a pivot strategy, a small or zero diagonal entry is used as a divisor and either crashes or amplifies rounding error.<\/p>\n\n\n<p class=\"wp-block-paragraph\">Partial pivoting chooses the largest remaining entry in the column and swaps that row to the pivot position. It does not search the whole remaining submatrix. Complete pivoting does, and it is rarely used because partial pivoting is enough for almost every practical matrix and costs only a row swap.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the algorithm guarantees<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">On a nonsingular matrix, with exact arithmetic, partial pivoting produces a factorization PA = LU, where P is the permutation of the row swaps, L is unit lower triangular, and U is upper triangular. The system is then solved by forward and back substitution. Time is \u0398(n\u00b3). Extra memory can be the matrix itself, overwritten by L and U, plus a pivot-index vector. A column whose remaining entries are all zero means the matrix is singular. The algorithm should stop and report that, not divide by a pivot that was swapped into place as a rounding dust.<\/p>\n\n\n<p class=\"wp-block-paragraph\">The growth factor of partial pivoting can in theory be 2^{n}, so the stability bound is not unconditional for every matrix. Those matrices are rare. For numerical work the practical statement is that partial pivoting is the default and a huge pivot-growth warning is the exception.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>The working steps<\/strong><\/h4>\n\n<ol class=\"wp-block-list\">\n<li>Form the augmented matrix or keep b beside A. For column k from 1 to n, search rows k through n for the largest absolute entry in column k.<\/li>\n<li>If that entry is zero, or below a stated tolerance in floating point, report that the matrix is singular or too ill-conditioned for this solver.<\/li>\n<li>Swap row k with the pivot row. Record the swap.<\/li>\n<li>For each row i below k, let factor = A[i][k] \/ A[k][k]. Subtract factor times row k from row i. Store factor where A[i][k] sat if an LU factorization is being kept.<\/li>\n<li>Back-substitute from the last row: x[n] = b[n]\/U[n][n], and each earlier unknown subtracts the already known terms before dividing by its diagonal.<\/li>\n<\/ol>\n\n\n<p class=\"wp-block-paragraph\">The cubic bound is for a dense system. A sparse symmetric positive system often wants conjugate gradients or a sparse factorization, not a dense elimination that fills in zeros. Partial pivoting is not complete pivoting. The algorithm computes one solution of a square system. A least-squares problem for a rectangular matrix is a QR factorization or the normal equations, which have their own stability story.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Approaches that look simpler and fail<\/strong><\/h4>\n\n<figure class=\"wp-block-table\">\n<table>\n<thead>\n<tr>\n<th>Approach<\/th>\n<th>Why it fails when the first nonzero in the column is used as the pivot<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Pivot on a tiny diagonal entry because it is nonzero<\/td>\n<td>Exact arithmetic still finishes and floating-point error is amplified. Partial pivoting exists to avoid that entry when a larger one is available.<\/td>\n<\/tr>\n<tr>\n<td>Swap the pivot and forget to swap the right-hand side<\/td>\n<td>The equations have moved. b has to take the same row permutation, or the solution belongs to a different system.<\/td>\n<\/tr>\n<tr>\n<td>Continue after a zero pivot column<\/td>\n<td>The variable is free or the system is inconsistent. Dividing by zero is not a solution.<\/td>\n<\/tr>\n<tr>\n<td>Quote O(n\u00b2) because there are n unknowns<\/td>\n<td>Each of the n stages clears a column at linear cost in the remaining rows and columns. The total is cubic.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<p class=\"wp-block-paragraph\">Symmetric positive-definite systems can use Cholesky, which needs no pivoting and half the arithmetic, and fails honestly when the matrix is not positive definite. Iterative solution of a large sparse system is conjugate gradients. Gaussian elimination is the dense LU algorithm with partial pivoting.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>A working example<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">This Python fragment eliminates with partial pivoting. The system 2x + y = 5, x + 3y = 5 has solution <code>2 1<\/code>.<\/p>\n\n<pre><code class=\"language-python\">a = [\n    [2.0, 1.0, 5.0],\n    [1.0, 3.0, 5.0],\n]\nn = 2\nfor col in range(n):\n    pivot = max(range(col, n), key=lambda r: abs(a[r][col]))\n    a[col], a[pivot] = a[pivot], a[col]\n    scale = a[col][col]\n    for row in range(col + 1, n):\n        factor = a[row][col] \/ scale\n        for j in range(col, n + 1):\n            a[row][j] -= factor * a[col][j]\nx = [0.0] * n\nfor i in range(n - 1, -1, -1):\n    x[i] = a[i][n]\n    for j in range(i + 1, n):\n        x[i] -= a[i][j] * x[j]\n    x[i] \/= a[i][i]\nassert abs(x[0] - 2) &lt; 1e-9 and abs(x[1] - 1) &lt; 1e-9\nprint(int(round(x[0])), int(round(x[1])))\n<\/code><\/pre>\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Where it is used<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">Gaussian elimination is the LU factorization inside dense linear solvers, circuit simulators such as <strong>SPICE<\/strong>, and MATLAB&#8217;s backslash on a general matrix. Scientific code calls that factorization rather than the textbook row operations by name. Conjugate gradient is the iterative method for a large sparse positive system.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>When you can drop this algorithm<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">Drop dense elimination for a large sparse system. The fill-in destroys the sparsity. Keep partial pivoting for a dense square linear system, and stop when the pivot column is numerically zero.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Why this stays published<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">We publish this so a search for Gaussian elimination returns partial pivoting and the cubic cost of dense LU. <strong>Gaussian elimination with partial pivoting factors a dense square matrix as PA = LU in O(n\u00b3) time and solves the linear system by substitution.<\/strong><\/p>\n\n\n<p class=\"wp-block-paragraph\">\u672c\u6587\u7531 HoHo \u8207 AI \u5354\u4f5c\u6574\u7406\uff0c\u6700\u5f8c\u66f4\u65b0\u65bc 2026 \u5e74 11 \u6708 13 \u65e5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Short answer: Gaussian elimination reduces a matrix to row echelon form by clearing each column under a pivot. Partial pivoting swaps into the pivot row the remaining row with the largest absolute value in that column. With that swap, the algorithm is the standard numerically stable solver for a&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,53],"tags":[],"class_list":["post-185","post","type-post","status-publish","format-standard","hentry","category-algorithms","category-linear-algebra"],"_links":{"self":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/185","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/comments?post=185"}],"version-history":[{"count":2,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/185\/revisions"}],"predecessor-version":[{"id":584,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/185\/revisions\/584"}],"wp:attachment":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/media?parent=185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/categories?post=185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/tags?post=185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}