# 高斯消元法

**高斯消元法**是求解线性方程组与分解矩阵的一种算法：它利用初等行变换将矩阵化为上三角形式，再通过回代求出未知量。用矩阵的语言来说，它计算的是 LU 分解；若允许行交换，则得到分解 \( PA = LU \)，其中 \( P \) 为置换矩阵，\( L \) 为单位下三角矩阵，\( U \) 为上三角矩阵。<sup>[1](https://www.math.utah.edu/software/lapack/lapack-d/dgesv.html)</sup><sup> • </sup><sup>[2](https://persson.berkeley.edu/math128a/slides/ch6math128a.html)</sup> 它是数值线性代数中求解 \( Ax = b \) 的基本算法，也是 LAPACK 库中稠密线性求解器的基础。<sup>[3](https://www.stat.uchicago.edu/~lekheng/courses/302/demmel/demmch2.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 输出 | 无行交换时的分解 \( A = LU \)，或采用部分主元法与行交换时的 \( PA = LU \)<sup>[1](https://www.math.utah.edu/software/lapack/lapack-d/dgesv.html)</sup> |
| 代价 | 对 \( n \times n \) 矩阵作分解需 \( 2n^{3}/3 + O(n^{2}) \) 次浮点运算；三角求解需 \( O(n^{2}) \) 次<sup>[4](https://www.netlib.org/lapack/lawnspdf/lawn60.pdf)</sup><sup> • </sup><sup>[5](https://repository.tudelft.nl/file/File_ffc4a027-b0b1-4f86-8205-c5ef4a7fe714)</sup> |
| 主元选取 | 部分主元法将每一行与当前列中绝对值最大元素所在的行交换；此后 \( L \) 的元素绝对值均不超过一<sup>[6](https://people.eecs.berkeley.edu/~demmel/cs267/lecture12/lecture13.html)</sup> |
| 稳定性 | 最坏情形下的增长因子为 \( O(2^{n}) \) 且可以取到，但实际中部分主元法出现严重的元素增长极为罕见<sup>[7](https://link.springer.com/article/10.1007/s00440-024-01276-2)</sup> |
| 标准实现 | LAPACK 例程 DGESV 通过带部分主元法的 LU 分解求解 \( AX = B \)<sup>[1](https://www.math.utah.edu/software/lapack/lapack-d/dgesv.html)</sup> |
| 历史 | 早在高斯于 1809 年使用它之前便已为人所知；中国古代《九章算术》中载有几乎相同的方法；1881 年由杜利特尔进一步发展<sup>[8](https://link.springer.com/chapter/10.1007/978-3-030-36468-7_3)</sup><sup> • </sup><sup>[9](https://mathshistory.st-andrews.ac.uk/HistTopics/Matrices_and_determinants/)</sup> |
| 稀疏变体 | 通过高斯消元法进行的稀疏 LU 分解，被认为是一种稳健、成本高效的方法，适用于病态的大型稀疏系统，例如电网仿真<sup>[10](https://link.springer.com/article/10.1007/s11227-026-08264-4)</sup> |

## 算法

该过程通过系统的行运算，将方程组 \( Ax = b \) 化为等价的上三角方程组 \( Ux = c \)。<sup>[11](https://ua-2025q1-phys305.github.io/03/notes.html)</sup> 在第 \( k \) 步，从第 \( k \) 行以下的各行中减去第 \( k \) 行的若干倍，使第 \( k \) 列中主对角线下方的元素化为零；乘数 \( m_{ji} = a_{ji}^{(i)}/a_{ii}^{(i)} \) 正是后来构成 \( L \) 的元素。<sup>[2](https://persson.berkeley.edu/math128a/slides/ch6math128a.html)</sup> 一旦矩阵化为上三角形式，便从最后一个方程开始向上回代，求出各未知量。<sup>[11](https://ua-2025q1-phys305.github.io/03/notes.html)</sup>

消元过程可以组织成若干种循环嵌套方式，它们计算的都是同一个分解。行导向的版本逐个更新元素，而列导向的版本将内层循环作为单次向量运算执行；LAPACK 库则将该步骤表示为对尾部子矩阵的秩一更新，并且为了性能，将矩阵分块为大小为 \( n \times n_b \) 的面板，使大部分工作以三级 BLAS 矩阵-矩阵运算的形式运行。<sup>[4](https://www.netlib.org/lapack/lawnspdf/lawn60.pdf)</sup>

## LU 分解与求解

若消元过程中不作行交换，则各因子满足 \( A = LU \)，其中 \( U \) 为行阶梯形，\( L \) 记录所用的乘数。<sup>[2](https://persson.berkeley.edu/math128a/slides/ch6math128a.html)</sup><sup> • </sup><sup>[5](https://repository.tudelft.nl/file/File_ffc4a027-b0b1-4f86-8205-c5ef4a7fe714)</sup> 随后通过两个代价低廉的三角步骤求解方程组：前向代入求解 \( Ly = f \)，回代求解 \( Uw = y \)，各需 \( O(n^{2}) \) 次运算；\( L \) 与 \( U \) 的逆并不显式构造。<sup>[5](https://repository.tudelft.nl/file/File_ffc4a027-b0b1-4f86-8205-c5ef4a7fe714)</sup> 将分解与求解分离，正是当多个右端项共用同一矩阵时该方法高效的原因，因为 \( O(n^{3}) \) 的分解只需做一次。<sup>[5](https://repository.tudelft.nl/file/File_ffc4a027-b0b1-4f86-8205-c5ef4a7fe714)</sup>

LAPACK 驱动例程 DGESV 实现了这一设计：它利用部分主元法与行交换将 \( A \) 分解为 \( A = P \cdot L \cdot U \)，将各因子存回存放 \( A \) 的数组（\( L \) 的单位对角元不存储），并返回定义 \( P \) 的主元索引，然后用解 \( X \) 覆盖 \( B \)。若某个主元 \( U(i,i) \) 恰为零，则分解仍会完成，但 \( U \) 恰好奇异，不计算任何解。<sup>[1](https://www.math.utah.edu/software/lapack/lapack-d/dgesv.html)</sup>

## 主元选取与数值稳定性

在浮点运算中，朴素算法有两种失效模式。若主元 \( A(i,i) \) 为零，算法无法继续；若它极小，则乘数变得很大，舍入误差被放大，这一现象称为数值不稳定。<sup>[6](https://people.eecs.berkeley.edu/~demmel/cs267/lecture12/lecture13.html)</sup> 标准的补救办法是部分主元法：在第 \( i \) 步开始时，将第 \( i \) 行与该列剩余部分中元素 \( |A(k,i)| \) 最大的第 \( k > i \) 行交换。于是每个乘数都落在 \([-1, 1]\) 内，\( L \) 的每个元素绝对值至多为一，而求解 \( Ax = b \) 只需额外按 \( P \) 对 \( b \) 作置换。<sup>[6](https://people.eecs.berkeley.edu/~demmel/cs267/lecture12/lecture13.html)</sup>

稳定性以后向误差衡量，即扰动 \( \delta A \) 与 \( \delta b \) 的大小，使得计算所得的解恰好满足 \( (A + \delta A)\hat{x} = b + \delta b \)。英国数值分析学家詹姆斯·H·威尔金森（James H. Wilkinson）的后向误差框架奠定了现代舍入误差分析的基础，他的一项开创性结果用增长因子给出了该误差的界，而消元法的稳定性可由计算所得因子 \( \hat{L} \) 或 \( \hat{U} \) 中最大元素相对于 \( A \) 的缩放来估计。<sup>[7](https://link.springer.com/article/10.1007/s00440-024-01276-2)</sup><sup> • </sup><sup>[12](https://doi.org/10.1090/noti3191)</sup>

最坏情形很糟：对某些可逆矩阵，带部分主元法的高斯消元的增长因子为 \( O(2^{n}) \)，且该界可以取到，因此只有当单位舍入误差相对于 \( 2^{-n} \) 呈指数级小时，威尔金森界才令人满意。<sup>[7](https://link.springer.com/article/10.1007/s00440-024-01276-2)</sup> 实际情况则好得多。牛津大学数值分析教授劳埃德·N·特雷费森（Lloyd N. Trefethen）与戴维·施赖伯（David Schreiber）的经验研究表明，对于元素独立服从标准高斯分布的随机矩阵，增长因子以高概率仅随 \( n \) 呈多项式增长；艾伦·埃德尔曼（Alan Edelman）的数值研究提示，它以接近一的概率为 \( O(n^{1/2+o(1)}) \) 量级。正如戈卢布（Golub）与范 loan（Van Loan）的教科书所总结的共识：部分主元法出现严重的元素增长极为罕见，该方法可以放心使用。<sup>[7](https://link.springer.com/article/10.1007/s00440-024-01276-2)</sup> 平滑分析给出了理论上的对应结果：对于 \( (M + G)x = b \)，其中 \( M \) 为固定矩阵、\( G \) 为高斯噪声，用不选主元的消元法求解到 \( m \) 位精度至多需要 \( m + O(\log(n + \|M\|/\sigma)) \) 位精度。<sup>[7](https://link.springer.com/article/10.1007/s00440-024-01276-2)</sup>

有些矩阵完全不需要选主元。严格对角占优矩阵，即满足 \( |a_{ii}| > \sum_{j \ne i} |a_{ij}| \) 的矩阵，是非奇异的，允许不作行交换进行消元，且计算是稳定的。<sup>[2](https://persson.berkeley.edu/math128a/slides/ch6math128a.html)</sup>

## 变体

高斯-约当消元法继续进行行运算，直至矩阵化为对角形式而非止于上三角形式，从而省去回代步骤；这是线性代数入门课程中最常讲授的版本，而基于 LU 的形式则是数值计算工作中的标准。<sup>[13](https://www.d.umn.edu/~mhampton/NA/Linear/)</sup> 完全主元法在整个剩余子矩阵而非单列中寻找最大元素，用于消元必须容忍非最优主元选择的场合。<sup>[14](https://arxiv.org/abs/1602.06602)</sup>

## 稀疏系统与应用

对于出现在计算流体力学、聚变等离子体仿真、天气模拟、电磁学与材料建模中的稀疏矩阵，高斯消元法是稀疏直接求解器的基础。稀疏 LU 分解被认为是一种稳健、成本高效且内存高效的方法，适用于诸如电网仿真中的病态大型稀疏系统；在具有良好未知量排序的非常规则的网格拓扑上，它可以用 \( O(n^{3/2}) \) 次算术运算求解系统，尽管实际中运算量随规模增长的情况略差一些。<sup>[10](https://link.springer.com/article/10.1007/s11227-026-08264-4)</sup> 在分解之前重新排列方程可减少填充，即消元所产生的新非零元，这是高效稀疏直接求解的关键一步。<sup>[15](https://www.myracore.com/myramath/doc/html/multifrontal1_tutorial.html)</sup>

生产级求解器建立在这一基础之上。MUMPS 软件包是一个大规模并行稀疏直接求解器，基于高斯消元法并采用多波前方法，可求解地球物理电磁仿真中具有数百万未知量的系统，其流程包括一个对矩阵重新排序并确定主元序列的分析阶段、一个分解阶段，以及一个由前向消元与回代组成的求解阶段。<sup>[16](https://academic.oup.com/gji/article/209/3/1558/3072200)</sup> 在稀疏情形下选主元代价高昂，尤其是在分布式内存中，因此实现中常采用阈值主元法——仅在数值看起来危险时才选主元——或预先确定的静态主元法，并利用因子通过迭代精化恢复精度。<sup>[17](https://www.cs.cornell.edu/courses/cs5220/2020fa/lec/2020-10-29-splu.html)</sup>

稠密 LU 分解仍是一项基准运算：用于给超级计算机排名的高性能 Linpack 基准，衡量的正是完成一次大型分布式稠密矩阵三角因子分解所需的时间。<sup>[10](https://link.springer.com/article/10.1007/s11227-026-08264-4)</sup>

## 历史

该方法比它的名字更古老。一种与高斯消元法本质相同、先解出最后一个未知量再逐步回代的方法，出现在中国古代典籍《九章算术》中，用于训练国家官员处理实务；这一如今被称为高斯消元法的方法，直到 19 世纪初才在欧洲广为人知。<sup>[9](https://mathshistory.st-andrews.ac.uk/HistTopics/Matrices_and_determinants/)</sup> 德国数学家与天文学家卡尔·弗里德里希·高斯（Carl Friedrich Gauss）在其线性方程组的计算中应用了该方法，包括含 17 个方程的方程组；马里兰大学数值分析学家 G. W. 斯图尔特（G. W. Stewart）在 1994 年关于高斯、统计学与线性方程组求解的历史报告中对此作了综述。<sup>[18](https://drum.lib.umd.edu/items/ffab0fcf-3c3a-4964-a70f-76a0ea24a1eb)</sup><sup> • </sup><sup>[19](https://www.cs.bu.edu/fac/snyder/cs132-book/L03RowReductions.html)</sup> 该方法早在高斯于 1809 年使用它之前便已为人所知，并于 1881 年由迈里克·H·杜利特尔（Myrick H. Doolittle）进一步发展。<sup>[8](https://link.springer.com/chapter/10.1007/978-3-030-36468-7_3)</sup>

## References

1. [DGESV documentation, LAPACK, University of Utah mirror](https://www.math.utah.edu/software/lapack/lapack-d/dgesv.html)
2. [Chapter 6: Direct Methods for Solving Linear Systems, Math 128A, UC Berkeley](https://persson.berkeley.edu/math128a/slides/ch6math128a.html)
3. [Applied Numerical Linear Algebra, Ch. 2 (Demmel), University of Chicago course page](https://www.stat.uchicago.edu/~lekheng/courses/302/demmel/demmch2.pdf)
4. [LAPACK Working Note 60: On Algorithmic Variants of Parallel Gaussian Elimination](https://www.netlib.org/lapack/lawnspdf/lawn60.pdf)
5. [Solution Methods in Numerical Linear Algebra, TU Delft repository](https://repository.tudelft.nl/file/File_ffc4a027-b0b1-4f86-8205-c5ef4a7fe714)
6. [CS267 Lecture 13: Design and Implementation of LAPACK and ScaLAPACK, UC Berkeley](https://people.eecs.berkeley.edu/~demmel/cs267/lecture12/lecture13.html)
7. [Average-case analysis of the Gaussian Elimination with Partial Pivoting, Probability Theory and Related Fields](https://link.springer.com/article/10.1007/s00440-024-01276-2)
8. [Lyche, T. (2020). Gaussian Elimination and LU Factorizations. Springer](https://link.springer.com/chapter/10.1007/978-3-030-36468-7_3)
9. [Matrices and determinants, MacTutor History of Mathematics](https://mathshistory.st-andrews.ac.uk/HistTopics/Matrices_and_determinants/)
10. [Mixed-precision numerics in scientific applications: survey and perspectives, The Journal of Supercomputing](https://link.springer.com/article/10.1007/s11227-026-08264-4)
11. [Numerical Linear Algebra, PHYS 305: Computational Physics](https://ua-2025q1-phys305.github.io/03/notes.html)
12. [Notices of the American Mathematical Society, on the stability of Gaussian elimination](https://doi.org/10.1090/noti3191)
13. [Linear Algebra and Matrix Factorization, Introduction to Numerical Methods, University of Minnesota Duluth](https://www.d.umn.edu/~mhampton/NA/Linear/)
14. [Gaussian elimination corrects pivoting mistakes, arXiv](https://arxiv.org/abs/1602.06602)
15. [MyraMath tutorial for multifrontal solvers](https://www.myracore.com/myramath/doc/html/multifrontal1_tutorial.html)
16. [Large-scale 3-D EM modelling with a Block Low-Rank multifrontal direct solver, Geophysical Journal International](https://academic.oup.com/gji/article/209/3/1558/3072200)
17. [Sparse direct methods, CS5220, Cornell University](https://www.cs.cornell.edu/courses/cs5220/2020fa/lec/2020-10-29-splu.html)
18. [Stewart, G. W. Gauss, Statistics, and Gaussian Elimination, University of Maryland](https://drum.lib.umd.edu/items/ffab0fcf-3c3a-4964-a70f-76a0ea24a1eb)
19. [Gaussian Elimination, Linear Algebra, Geometry, and Computation, Boston University](https://www.cs.bu.edu/fac/snyder/cs132-book/L03RowReductions.html)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 数与代数 › Linear and multilinear algebra › Numerical linear algebra › Direct solvers for linear systems

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/gaussian-elimination

English original: https://www.edgepedia.org/gaussian-elimination
