# 矩阵微积分

**矩阵微积分**是微分学向自变量或取值是向量或矩阵的函数所作的推广：标量值函数有梯度，向量值函数有雅可比矩阵，标量函数的二阶导数则是它的海森矩阵。<sup>[1](https://mathworld.wolfram.com/MatrixCalculus.html)</sup> 它提供了必要的记号与法则，用以对涉及矩阵的函数做优化、做灵敏度分析，以及在统计学、计量经济学、控制理论、机器学习和工程学中出现的长串线性代数复合中传播导数。<sup>[2](https://doi.org/10.1016/j.jeconom.2024.105862)</sup>

| 关键事实 | 细节 |
|---|---|
| 核心对象 | 以向量为自变量的标量值函数的梯度、向量值函数的雅可比矩阵 \( J_{ij} = \partial f_i / \partial x_j \)、标量函数二阶导数的海森矩阵<sup>[1](https://mathworld.wolfram.com/MatrixCalculus.html)</sup> |
| 布局问题 | 分子布局与分母布局这两种约定会使某些向量和矩阵导数互为转置，因此任何矩阵微积分公式都必须明确说明所采用的约定<sup>[1](https://mathworld.wolfram.com/MatrixCalculus.html)</sup> |
| 微分方法 | Magnus–Neudecker 的处理方式于1988年首次出版，现已出至第三版（2019），它把整个学科建立在微分之上，而不是建立在偏导数阵列之上<sup>[3](https://www.wiley-vch.de/en/areas-interest/mathematics-statistics/matrix-differential-calculus-with-its-applications-in-statistics-and-econometrics-978-0-471-98633-1)</sup> |
| 矩阵函数 | 对于矩阵函数 \( f : \mathbb{C}^{n \times n} \to \mathbb{C}^{n \times n} \)，Fréchet 导数 \( L_f \) 刻画了对小扰动的灵敏度，其范数可作为条件数<sup>[4](https://epubs.siam.org/doi/abs/10.1137/130945259)</sup> |
| 不可交换性 | 由于矩阵不可交换，\( \mathrm{d}(A^3) = A^2(\mathrm{d}A) + A(\mathrm{d}A)A + (\mathrm{d}A)A^2 \)，而不是 \( 3A^2\,\mathrm{d}A \)<sup>[5](https://ocw.mit.edu/courses/18-s096-matrix-calculus-for-machine-learning-and-beyond-january-iap-2023/pages/lecture-notes-and-readings/)</sup> |
| 计算上的收益 | 反向模式（伴随、反向传播）微分能以约一次函数求值三倍的代价，给出多参数标量值函数的梯度，这使大规模优化变得可行<sup>[6](https://docs.jax.dev/en/latest/jacobian-vector-products.html)</sup> |

## 导数作为线性算子

现代表述把导数定义为一个线性算子。对于函数 \( f \)，微分 \( \mathrm{d}f = f'(x)[\mathrm{d}x] \) 是给出输入发生小变化 \( \mathrm{d}x \) 时输出一阶变化的线性映射。<sup>[5](https://ocw.mit.edu/courses/18-s096-matrix-calculus-for-machine-learning-and-beyond-january-iap-2023/pages/lecture-notes-and-readings/)</sup> 对于 \( x \in \mathbb{R}^n \) 的标量函数 \( f(x) \in \mathbb{R} \)，这个算子是一个行向量，即梯度列向量 \( \nabla f \) 的转置，于是 \( \mathrm{d}f = (\nabla f)^{\mathsf{T}}\,\mathrm{d}x \)。对于向量函数 \( f : \mathbb{R}^n \to \mathbb{R}^m \)，导数是 \( m \times n \) 的雅可比矩阵。<sup>[5](https://ocw.mit.edu/courses/18-s096-matrix-calculus-for-machine-learning-and-beyond-january-iap-2023/pages/lecture-notes-and-readings/)</sup> 一旦内积固定下来，任何标量函数的梯度就是满足 \( f'(x)[\mathrm{d}x] = \nabla f \cdot \mathrm{d}x \) 的唯一向量，它指向最速上升的方向。<sup>[5](https://ocw.mit.edu/courses/18-s096-matrix-calculus-for-machine-learning-and-beyond-january-iap-2023/pages/lecture-notes-and-readings/)</sup>

熟悉的一维法则作为这些线性算子上的法则延续下来：和法则 \( \mathrm{d}(f+g) = \mathrm{d}f + \mathrm{d}g \)、积法则 \( \mathrm{d}(fg) = (\mathrm{d}f)g + f(\mathrm{d}g) \)，以及一条链式法则——复合的导数是两个线性映射的复合，因此次序要紧。<sup>[5](https://ocw.mit.edu/courses/18-s096-matrix-calculus-for-machine-learning-and-beyond-january-iap-2023/pages/lecture-notes-and-readings/)</sup> 对于向量函数，链式法则就是雅可比矩阵的乘积；在 Magnus–Neudecker 记号下，若 \( u \) 是 \( v \) 的函数、\( v \) 是 \( x \) 的函数，则 \( \mathrm{d}u/\mathrm{d}x^{\mathsf{T}} = (\mathrm{d}u/\mathrm{d}v^{\mathsf{T}})(\mathrm{d}v/\mathrm{d}x^{\mathsf{T}}) \)，而核对各因子的维数是发现错误的实用手段。<sup>[7](https://link.springer.com/chapter/10.1007/978-3-030-10534-1_2)</sup>

## 布局约定

向量关于向量的导数可以有不止一种排布方式，而这一选择会改变建立在它之上的每一个公式的形状。在分母布局中，标量的梯度是列向量；在分子布局中则是行向量，相应的向量与矩阵导数互为转置。<sup>[1](https://mathworld.wolfram.com/MatrixCalculus.html)</sup><sup> • </sup><sup>[8](https://www.allisone.co.jp/note/mathematics/derivative/matrix-calculus/field-layouts_en.html)</sup> 不同领域偏好不同的约定，往往是为了在其典型问题中获得记号上的便利，因此引用其他来源的公式时必须记着它的约定来读。<sup>[1](https://mathworld.wolfram.com/MatrixCalculus.html)</sup> Magnus–Neudecker 记号在写矩阵导数时先施加 vec 算子，它把矩阵堆叠成一个列向量，于是 \( m \times n \) 矩阵 \( Y \) 关于 \( p \times q \) 矩阵 \( X \) 的导数是 \( mn \times pq \) 的矩阵 \( \mathrm{d}\,\mathrm{vec}\,Y / \mathrm{d}(\mathrm{vec}\,X)^{\mathsf{T}} \)。<sup>[7](https://link.springer.com/chapter/10.1007/978-3-030-10534-1_2)</sup>

还有一个更细微的问题涉及对称矩阵。对于对称矩阵的实值函数，研究论文使用两种不同的梯度概念，会给出两种不同的结果；统计学、经济学和电气工程文献使用对称梯度 \( G_s = G + G^{\mathsf{T}} - G \circ I \)，其中 \( G \) 是相对于一般矩阵的 Fréchet 导数所给出的梯度，\( \circ \) 是 Hadamard（逐元素）积。<sup>[9](https://arxiv.org/abs/1911.06491)</sup>

## 基于微分的方法

矩阵微积分作为一门系统学科，于20世纪60年代开始发展。基于微分的方法由 Heinz Neudecker 于1969年引入，并由当时在蒂尔堡大学、后来在阿姆斯特丹大学任教的计量经济学家 Jan R. Magnus 与 Neudecker 于1985年加以扩展；他们1988年的专著给出了全面的处理。<sup>[10](https://link.springer.com/chapter/10.1007/978-3-030-10534-1_1)</sup> 《矩阵微分计算及其在统计学与计量经济学中的应用》呈现了一套统一而自足的展开，面向计量经济学家和统计学家，从矩阵代数出发，经由一阶与二阶微分、雅可比矩阵与海森矩阵、vec 算子与克罗内克积，直到优化、最小二乘、最大似然和线性回归模型。<sup>[3](https://www.wiley-vch.de/en/areas-interest/mathematics-statistics/matrix-differential-calculus-with-its-applications-in-statistics-and-econometrics-978-0-471-98633-1)</sup> 作者们主张，对于计量经济学和统计学中的多变量函数，微分比导数阵列更合用，尽管这两个概念在理论上是等价的。<sup>[11](https://www.janmagnus.nl/misc/mdc-ch18.pdf)</sup> 该方法的关键在于微分与导数之间的关系：导数由微分还原出来，而在作这一辨认之前，微分是用普通代数法则来操作的。<sup>[7](https://link.springer.com/chapter/10.1007/978-3-030-10534-1_2)</sup>

## 矩阵函数与 Fréchet 导数

当函数本身以矩阵为自变量并返回一个矩阵时，例如 \( f(A) = e^A \)、\( \log A \) 或 \( A^{1/2} \)，导数不可能以任何简单的方式成为逐元素的阵列，而自然的对象是 Fréchet 导数：即给出扰动 \( E \) 所引起的 \( f(A) \) 一阶变化的线性映射 \( L_f(A, E) \)。不可交换性是核心困难。1956年 Rinehart 只对与 \( A \) 交换的 \( E \) 处理了差 \( f(A+E) - f(A) \)，在这种情形下导数退化为 \( f'(A) \)；Eberhard Stickel 1987年的论文处理了非交换情形，得到了 Fréchet 导数的一个显式积分表示，并指出了它在求解非线性矩阵方程的牛顿法中的用途。<sup>[12](https://www.sciencedirect.com/science/article/pii/0024379587900620)</sup>

具体的例子显示了法则的形状。对于 \( f(A) = A^3 \)，\( \mathrm{d}(A^3) = A^2(\mathrm{d}A) + A(\mathrm{d}A)A + (\mathrm{d}A)A^2 \)，这与看似标量的 \( 3A^2\,\mathrm{d}A \) 不同；对于逆，\( \mathrm{d}(A^{-1}) = -A^{-1}(\mathrm{d}A)A^{-1} \)。<sup>[5](https://ocw.mit.edu/courses/18-s096-matrix-calculus-for-machine-learning-and-beyond-january-iap-2023/pages/lecture-notes-and-readings/)</sup> 这样的线性算子可以通过向量化转化为普通矩阵，用克罗内克积来表示它们。<sup>[5](https://ocw.mit.edu/courses/18-s096-matrix-calculus-for-machine-learning-and-beyond-january-iap-2023/pages/lecture-notes-and-readings/)</sup> 一个著名的恒等式——归功于 Mathias——从分块矩阵计算 Fréchet 导数：对于在包含 \( X \) 的谱的某个区域上充分可微的标量函数 \( \phi \)，

\[ \phi\left(\begin{bmatrix} X & E \\ 0 & X \end{bmatrix}\right) = \begin{bmatrix} \phi(X) & L_{\phi}(X,E) \\ 0 & \phi(X) \end{bmatrix}. \]

这一关系是诸如指数函数和对数函数之类函数的实用算法的基础。<sup>[13](https://www.tandfonline.com/doi/full/10.1080/03081087.2026.2634872)</sup>

Fréchet 导数也度量精度。它的范数给出 \( f \) 在 \( A \) 处的条件数，量化了数据中的小扰动——包括被解释为扰动的舍入误差——在 \( f(A) \) 中可能被放大的程度。<sup>[4](https://epubs.siam.org/doi/abs/10.1137/130945259)</sup><sup> • </sup><sup>[14](https://epubs.siam.org/doi/book/10.1137/1.9780898717778)</sup> 高阶 Fréchet 导数引出二级条件数，即“条件数的条件数”；曼彻斯特大学的数值分析学家 Nicholas J. Higham 与 Samuel D. Relton 推导了 \( k \) 阶导数的算法，并证明了对于正规矩阵和指数函数，一级与二级绝对条件数在2-范数下重合。即便只算一阶导数的克罗内克形式也要花 \( O(n^5) \) 次浮点运算，因此这条路线只对小矩阵可行。<sup>[4](https://epubs.siam.org/doi/abs/10.1137/130945259)</sup><sup> • </sup><sup>[15](https://epubs.siam.org/doi/pdf/10.1137/130945259)</sup>

## 自动微分与机器学习

在机器学习中，矩阵微积分被应用在雅可比矩阵根本不会被写下来的规模上。对于 \( n \) 达到数百万乃至数十亿的损失函数 \( f : \mathbb{R}^n \to \mathbb{R} \)，前向模式微分每次只构造雅可比矩阵的一列，每列约需一次函数求值，因而无法扩展。<sup>[6](https://docs.jax.dev/en/latest/jacobian-vector-products.html)</sup> 反向模式微分，也称伴随微分或反向传播微分，从左到右求值链式法则，以约一次函数求值三倍的代价一趟算出完整梯度；这一代价特性是大规模优化得以实用的关键因素。<sup>[6](https://docs.jax.dev/en/latest/jacobian-vector-products.html)</sup><sup> • </sup><sup>[5](https://ocw.mit.edu/courses/18-s096-matrix-calculus-for-machine-learning-and-beyond-january-iap-2023/pages/lecture-notes-and-readings/)</sup> JAX 和 PyTorch 等框架同时提供两种模式，输出多于输入时优先用前向模式，反之用反向模式。<sup>[6](https://docs.jax.dev/en/latest/jacobian-vector-products.html)</sup><sup> • </sup><sup>[16](https://docs.pytorch.org/tutorials/intermediate/jacobians_hessians.html)</sup>

矩阵函数自身的导数如今也正被纳入自动微分。2025年的一种方法把解析函数演算与前向、反向模式自动微分结合起来，计算矩阵对数与 \( p \) 次方根的雅可比矩阵和梯度，并应用于硅晶体分子模拟中矩阵对数的迹的梯度。<sup>[17](https://doi.org/10.1016/J.CPC.2025.109832)</sup>

## 应用

凡是对矩阵函数做优化或做灵敏度分析的地方，都需要这门学科。Magnus 称它在经济学、统计学、数学、心理学、控制理论和工程学中被广泛使用。<sup>[2](https://doi.org/10.1016/j.jeconom.2024.105862)</sup> 在多变量统计中，它支持线性模型中的效率比较、灵敏度分析和局部影响诊断。<sup>[18](https://www.sciencedirect.com/science/article/pii/S0047259X21001275)</sup> 在人口学和生态学中，矩阵微积分是种群模型灵敏度分析的基础，其中增长率、预期寿命和净生殖率等统计量关于模型参数的导数就是用这些工具计算的。<sup>[10](https://link.springer.com/chapter/10.1007/978-3-030-10534-1_1)</sup> 在数值线性代数中，指数、对数和平方根的条件数与 Fréchet 导数是可靠计算矩阵函数的标准组成部分。<sup>[14](https://epubs.siam.org/doi/book/10.1137/1.9780898717778)</sup>

## References

1. [Matrix Calculus, Wolfram MathWorld](https://mathworld.wolfram.com/MatrixCalculus.html)
2. [Jan R. Magnus (2024). A gentle introduction to matrix calculus. Journal of Econometrics.](https://doi.org/10.1016/j.jeconom.2024.105862)
3. [Magnus, Jan R. / Neudecker, Heinz, Matrix Differential Calculus with its Applications in Statistics and Econometrics, Wiley](https://www.wiley-vch.de/en/areas-interest/mathematics-statistics/matrix-differential-calculus-with-its-applications-in-statistics-and-econometrics-978-0-471-98633-1)
4. [Higham, Nicholas J. and Relton, Samuel D. Higher Order Fréchet Derivatives of Matrix Functions and the Level-2 Condition Number, SIAM J. Matrix Anal. Appl.](https://epubs.siam.org/doi/abs/10.1137/130945259)
5. [Lecture Notes and Readings, Matrix Calculus for Machine Learning and Beyond, MIT OpenCourseWare](https://ocw.mit.edu/courses/18-s096-matrix-calculus-for-machine-learning-and-beyond-january-iap-2023/pages/lecture-notes-and-readings/)
6. [Forward- and reverse-mode autodiff in JAX, JAX documentation](https://docs.jax.dev/en/latest/jacobian-vector-products.html)
7. [Hal Caswell, Matrix Calculus and Notation, in Sensitivity Analysis: Matrix Methods in Demography and Ecology, Springer](https://link.springer.com/chapter/10.1007/978-3-030-10534-1_2)
8. [Matrix Calculus Layout Conventions by Field, Technical Notes](https://www.allisone.co.jp/note/mathematics/derivative/matrix-calculus/field-layouts_en.html)
9. [What is the gradient of a scalar function of a symmetric matrix? arXiv:1911.06491](https://arxiv.org/abs/1911.06491)
10. [Hal Caswell, Introduction: Sensitivity Analysis – What and Why?, Springer](https://link.springer.com/chapter/10.1007/978-3-030-10534-1_1)
11. [Magnus & Neudecker, Matrix Differential Calculus, Third Edition, Chapter 18 (PDF)](https://www.janmagnus.nl/misc/mdc-ch18.pdf)
12. [Eberhard Stickel (1987). On the Fréchet derivative of matrix functions. Linear Algebra and its Applications 91, 83–88.](https://www.sciencedirect.com/science/article/pii/0024379587900620)
13. [On a class of functions of two non-commuting matrices: general properties, Fréchet derivatives and conditioning, Linear Algebra and its Applications](https://www.tandfonline.com/doi/full/10.1080/03081087.2026.2634872)
14. [Nicholas J. Higham, Functions of Matrices: Theory and Computation, SIAM](https://epubs.siam.org/doi/book/10.1137/1.9780898717778)
15. [Higham & Relton, Higher Order Fréchet Derivatives of Matrix Functions (PDF)](https://epubs.siam.org/doi/pdf/10.1137/130945259)
16. [Jacobians, Hessians, hvp, vhp, and more, PyTorch Tutorials](https://docs.pytorch.org/tutorials/intermediate/jacobians_hessians.html)
17. [Fast automatically differentiable matrix functions and applications in molecular simulations, Computer Physics Communications 317 (2025)](https://doi.org/10.1016/J.CPC.2025.109832)
18. [Matrix differential calculus with applications in the multivariate linear model and its diagnostics, Journal of Multivariate Analysis](https://www.sciencedirect.com/science/article/pii/S0047259X21001275)

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

Topic: 物质世界与数学 › 数学与统计学 › 数与代数 › Linear and multilinear algebra › Matrix theory › Matrix functions and matrix calculus

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/matrix-calculus

English original: https://www.edgepedia.org/matrix-calculus
