对向量求导的常用公式
鲁鹏
北京理工大学,宇航学院
2019.05.09
最近经常会遇到常数和向量对向量求导的计算,感觉需要总结点什么了。以后,我还会在这个文档中添加新的公式。
前提和定义
首先明确本文规定求导使用
分子布局约定
(
numerator layout convention
)。在这中布局约定下,函数
f
\boldsymbol{f}
f
(包括标量值函数)关于
x
∈
R
n
\boldsymbol{x}\in\mathbb{R}^{n}
x
∈
R
n
的微分可以用公式
d
f
(
x
)
=
∂
f
∂
x
d
x
\mathrm{d}\boldsymbol{f}(\boldsymbol{x}) = \dfrac{\partial \boldsymbol{f}}{\partial\boldsymbol{x}}\mathrm{d}\boldsymbol{x}
d
f
(
x
)
=
∂
x
∂
f
d
x
计算。向量求导有两种约定形式,
分子布局约定
(numerator layout convention)和
分母布局约定
(denominator layout convention)。
接下来给出在分子布局约定下,向量相关求导的定义。
已知
f
(
x
)
f(\boldsymbol{x})
f
(
x
)
是关于列向量
x
=
[
x
1
x
2
.
.
.
x
n
]
T
\boldsymbol{x}= [x_{1}\quad x_{2}\quad …\quad x_{n}]^{T}
x
=
[
x
1
x
2
…
x
n
]
T
的标量函数,则
f
(
x
)
f(\boldsymbol{x})
f
(
x
)
是关于列向量
x
\boldsymbol{x}
x
的导数为
∂
f
(
x
)
∂
x
=
[
∂
f
∂
x
1
∂
f
∂
x
2
.
.
.
∂
f
∂
x
n
]
\frac{\partial f(\boldsymbol{x})}{\partial \boldsymbol{x}} = \left[\begin{matrix} \frac{\partial f}{\partial x_{1}} & \frac{\partial f}{\partial x_{2}} &…& \frac{\partial f}{\partial x_{n}} \end{matrix}\right]
∂
x
∂
f
(
x
)
=
[
∂
x
1
∂
f
∂
x
2
∂
f
…
∂
x
n
∂
f
]
函数
f
(
x
)
f(\boldsymbol{x})
f
(
x
)
的梯度记为
∇
f
(
x
)
\nabla f(\boldsymbol{x})
∇
f
(
x
)
,则梯度和导数的关系如下
∇
f
(
x
)
=
[
∂
f
(
x
)
∂
x
]
T
\nabla f(\boldsymbol{x}) = \left[\frac{\partial f(\boldsymbol{x})}{\partial \boldsymbol{x}}\right]^{T}
∇
f
(
x
)
=
[
∂
x
∂
f
(
x
)
]
T
函数
f
(
x
)
f(\boldsymbol{x})
f
(
x
)
的Hessian矩阵是
n
×
n
n \times n
n
×
n
矩阵,记为
∇
2
f
(
x
)
\nabla^2 f(\boldsymbol{x})
∇
2
f
(
x
)
∇
2
f
(
x
)
=
[
∂
2
f
∂
x
1
2
∂
2
f
∂
x
1
∂
x
2
.
.
.
∂
2
f
∂
x
1
∂
x
n
∂
2
f
∂
x
2
∂
x
1
∂
2
f
∂
x
2
2
.
.
.
∂
2
f
∂
x
2
∂
x
n
.
.
.
.
.
.
.
.
.
.
.
.
∂
2
f
∂
x
n
∂
x
1
∂
2
f
∂
x
n
∂
x
2
.
.
.
∂
2
f
∂
x
n
2
]
\nabla^2 f(\boldsymbol{x}) = \left[\begin{matrix} \frac{\partial^{2} f}{\partial x_{1}^{2}} & \frac{\partial^{2} f}{\partial x_{1}\partial x_{2}} & … & \frac{\partial^{2} f}{\partial x_{1}\partial x_{n}}\\ \frac{\partial^{2} f}{\partial x_{2}\partial x_{1}} & \frac{\partial^{2} f}{\partial x_{2}^{2}} & …& \frac{\partial^{2} f}{\partial x_{2}\partial x_{n}} \\ … & … & … & … \\ \frac{\partial^{2} f}{\partial x_{n}\partial x_{1}} & \frac{\partial^{2} f}{\partial x_{n}\partial x_{2}} & … & \frac{\partial^{2} f}{\partial x_{n}^{2}} \end{matrix}\right]
∇
2
f
(
x
)
=
∂
x
1
2
∂
2
f
∂
x
2
∂
x
1
∂
2
f
…
∂
x
n
∂
x
1
∂
2
f
∂
x
1
∂
x
2
∂
2
f
∂
x
2
2
∂
2
f
…
∂
x
n
∂
x
2
∂
2
f
…
…
…
…
∂
x
1
∂
x
n
∂
2
f
∂
x
2
∂
x
n
∂
2
f
…
∂
x
n
2
∂
2
f
已知
F
(
x
)
=
[
f
1
(
x
)
f
2
(
x
)
.
.
.
f
m
(
x
)
]
T
F(\boldsymbol{x}) = [f_{1}(\boldsymbol{x})\quad f_{2}(\boldsymbol{x})\quad …\quad f_{m}(\boldsymbol{x})]^{T}
F
(
x
)
=
[
f
1
(
x
)
f
2
(
x
)
…
f
m
(
x
)
]
T
是关于列向量
x
\boldsymbol{x}
x
的向量值函数,则
F
(
x
)
F(\boldsymbol{x})
F
(
x
)
关于
x
\boldsymbol{x}
x
的导数为
∂
F
(
x
)
∂
x
=
[
∂
f
1
∂
x
1
∂
f
1
∂
x
2
.
.
.
∂
f
1
∂
x
n
∂
f
2
∂
x
1
∂
f
2
∂
x
2
.
.
.
∂
f
2
∂
x
n
.
.
.
.
.
.
.
.
.
.
.
.
∂
f
m
∂
x
1
∂
f
m
∂
x
2
.
.
.
∂
f
m
∂
x
n
]
\frac{\partial F(\boldsymbol{x})}{\partial \boldsymbol{x}} = \left[\begin{matrix} \frac{\partial f_{1}}{\partial x_{1}} & \frac{\partial f_{1}}{\partial x_{2}} &…& \frac{\partial f_{1}}{\partial x_{n}}\\ \frac{\partial f_{2}}{\partial x_{1}} & \frac{\partial f_{2}}{\partial x_{2}} &…& \frac{\partial f_{2}}{\partial x_{n}} \\ … & … & … & …\\ \frac{\partial f_{m}}{\partial x_{1}} & \frac{\partial f_{m}}{\partial x_{2}} &…& \frac{\partial f_{m}}{\partial x_{n}} \end{matrix}\right]
∂
x
∂
F
(
x
)
=
∂
x
1
∂
f
1
∂
x
1
∂
f
2
…
∂
x
1
∂
f
m
∂
x
2
∂
f
1
∂
x
2
∂
f
2
…
∂
x
2
∂
f
m
…
…
…
…
∂
x
n
∂
f
1
∂
x
n
∂
f
2
…
∂
x
n
∂
f
m
函数
F
(
x
)
F(\boldsymbol{x})
F
(
x
)
的雅克比矩阵记为
J
J
J
,则
J
=
∂
F
(
x
)
/
∂
x
J = {\partial F(\boldsymbol{x})}/{\partial \boldsymbol{x}}
J
=
∂
F
(
x
)
/
∂
x
,雅克比矩阵
J
J
J
等于向量值函数
F
(
x
)
F(\boldsymbol{x})
F
(
x
)
关于
x
\boldsymbol{x}
x
的导数。记函数
F
(
x
)
F(\boldsymbol{x})
F
(
x
)
的梯度记为
∇
F
(
x
)
\nabla F(\boldsymbol{x})
∇
F
(
x
)
,梯度和导数的关系为
∂
F
(
x
)
/
∂
x
=
∇
F
(
x
)
T
{\partial F(\boldsymbol{x})}/{\partial \boldsymbol{x}}=\nabla F(\boldsymbol{x})^{T}
∂
F
(
x
)
/
∂
x
=
∇
F
(
x
)
T
。
已知向量
a
=
[
a
1
a
2
a
3
]
T
\boldsymbol{a}= [a_{1}\quad a_{2}\quad a_{3}]^{T}
a
=
[
a
1
a
2
a
3
]
T
,则
a
\boldsymbol{a}
a
的叉乘矩阵
a
×
\boldsymbol{a}^{\times}
a
×
定义如下
a
×
=
[
0
−
a
3
a
2
a
3
0
−
a
1
−
a
2
a
1
0
]
\boldsymbol{a}^{\times} = \left[\begin{matrix} 0 & -a_{3} & a_{2}\\ a_{3} & 0 & -a_{1}\\ -a_{2} & a_{1} & 0 \end{matrix}\right]
a
×
=
0
a
3
−
a
2
−
a
3
0
a
1
a
2
−
a
1
0
有了叉乘矩阵,向量叉乘可以像等式(1)那样表示
a
×
b
=
a
×
b
(1)
\boldsymbol{a} \times \boldsymbol{b} = \boldsymbol{a}^{\times} \boldsymbol{b} \tag{1}
a
×
b
=
a
×
b
(
1
)
常用求导公式
在以上前提和定义的基础上,可以总结以下常用的求导公式,用于求函数的微分
d
f
(
x
)
=
∂
f
∂
x
d
x
\mathrm{d}\boldsymbol{f}(\boldsymbol{x}) = \dfrac{\partial \boldsymbol{f}}{\partial\boldsymbol{x}}\mathrm{d}\boldsymbol{x}
d
f
(
x
)
=
∂
x
∂
f
d
x
∂
∥
a
∥
∂
a
=
∂
a
∂
a
=
a
T
a
(2)
\frac{\partial \lVert \boldsymbol{a}\rVert}{\partial \boldsymbol{a}} = \frac{\partial a}{\partial \boldsymbol{a}} = \frac{\boldsymbol{a}^{T}}{a} \tag{2}
∂
a
∂
∥
a
∥
=
∂
a
∂
a
=
a
a
T
(
2
)
读者可以将所有向量写成坐标的形式检验下
d
a
(
a
)
\mathrm{d}a(\boldsymbol{a})
d
a
(
a
)
和
∂
a
∂
a
d
a
\dfrac{\partial a}{\partial\boldsymbol{a}}\mathrm{d}\boldsymbol{a}
∂
a
∂
a
d
a
是否相等,明显
d
a
(
a
)
=
a
T
a
d
a
\mathrm{d}a(\boldsymbol{a}) = \dfrac{\boldsymbol{a}^{T}}{a}\mathrm{d}\boldsymbol{a}
d
a
(
a
)
=
a
a
T
d
a
是成立的 。
∂
a
T
a
∂
a
=
∂
a
2
∂
a
=
2
a
T
(3)
\frac{\partial \boldsymbol{a}^{T}\boldsymbol{a}}{\partial \boldsymbol{a}} = \frac{\partial a^{2}}{\partial \boldsymbol{a}} = 2\boldsymbol{a}^{T}\tag{3}
∂
a
∂
a
T
a
=
∂
a
∂
a
2
=
2
a
T
(
3
)
∂
(
A
x
)
∂
x
=
A
(雅可比矩阵)
(4)
\frac{\partial(A \boldsymbol{x})}{\partial \boldsymbol{x}} = A (雅可比矩阵)\tag{4}
∂
x
∂
(
A
x
)
=
A
(雅可比矩阵)
(
4
)
∂
x
T
A
x
∂
x
=
x
T
(
A
+
A
T
)
(5)
\frac{\partial \boldsymbol{x}^{T} A \boldsymbol{x}}{\partial \boldsymbol{x}}= \boldsymbol{x}^{T}(A + A^{T}) \tag{5}
∂
x
∂
x
T
A
x
=
x
T
(
A
+
A
T
)
(
5
)
已知
y
=
a
×
b
+
c
\boldsymbol{y} = \boldsymbol{a} \times \boldsymbol{b}+\boldsymbol{c}
y
=
a
×
b
+
c
,则
∂
y
∂
b
=
y
T
y
a
×
(6)
\frac{\partial y}{\partial\boldsymbol{b}} = \frac{\boldsymbol{y}^{T}}{y}\boldsymbol{a}^{\times} \tag{6}
∂
b
∂
y
=
y
y
T
a
×
(
6
)
∂
α
∂
r
=
[
∂
α
∂
V
1
∂
α
∂
V
2
∂
α
∂
V
3
]
[
∂
V
1
∂
r
1
∂
V
1
∂
r
2
∂
V
1
∂
r
3
∂
V
2
∂
r
1
∂
V
2
∂
r
2
∂
V
2
∂
r
3
∂
V
3
∂
r
1
∂
V
3
∂
r
2
∂
V
3
∂
r
3
]
=
∂
α
∂
V
∂
V
∂
r
(7)
\frac{\partial\alpha}{\partial\boldsymbol{r}} = \left[\begin{matrix} \frac{\partial\alpha}{\partial V_{1}} & \frac{\partial\alpha}{\partial V_{2}} & \frac{\partial\alpha}{\partial V_{3}} \end{matrix}\right] \left[\begin{matrix} \frac{\partial V_{1}}{\partial r_{1}} & \frac{\partial V_{1}}{\partial r_{2}} & \frac{\partial V_{1}}{\partial r_{3}}\\ \frac{\partial V_{2}}{\partial r_{1}} & \frac{\partial V_{2}}{\partial r_{2}} & \frac{\partial V_{2}}{\partial r_{3}}\\ \frac{\partial V_{3}}{\partial r_{1}} & \frac{\partial V_{3}}{\partial r_{2}} & \frac{\partial V_{3}}{\partial r_{3}}\\ \end{matrix}\right]= \frac{\partial\alpha}{\partial\boldsymbol{V}}\frac{\partial\boldsymbol{V}}{\partial\boldsymbol{r}} \tag{7}
∂
r
∂
α
=
[
∂
V
1
∂
α
∂
V
2
∂
α
∂
V
3
∂
α
]
∂
r
1
∂
V
1
∂
r
1
∂
V
2
∂
r
1
∂
V
3
∂
r
2
∂
V
1
∂
r
2
∂
V
2
∂
r
2
∂
V
3
∂
r
3
∂
V
1
∂
r
3
∂
V
2
∂
r
3
∂
V
3
=
∂
V
∂
α
∂
r
∂
V
(
7
)
d
(
a
×
b
)
d
t
=
d
a
d
t
×
b
+
a
×
d
b
d
t
(8)
\frac{ d(\boldsymbol{a} \times \boldsymbol{b}) }{dt} = \frac{ d\boldsymbol{a} }{dt} \times \boldsymbol{b} + \boldsymbol{a} \times \frac{ d\boldsymbol{b} }{dt} \tag{8}
d
t
d
(
a
×
b
)
=
d
t
d
a
×
b
+
a
×
d
t
d
b
(
8
)
∂
[
f
(
x
)
a
]
∂
x
=
a
∂
f
(
x
)
∂
x
(9)
\frac{\partial[f(\boldsymbol{x})\boldsymbol{a}]}{\partial\boldsymbol{x}} = \boldsymbol{a} \frac{\partial f(\boldsymbol{x})}{\partial \boldsymbol{x}} \tag{9}
∂
x
∂
[
f
(
x
)
a
]
=
a
∂
x
∂
f
(
x
)
(
9
)
已知
ω
=
[
ω
1
ω
2
ω
3
]
T
\boldsymbol{\omega} = \begin{bmatrix} \omega_{1} & \omega_{2} & \omega_{3} \end{bmatrix}^{T}
ω
=
[
ω
1
ω
2
ω
3
]
T
,
r
=
[
r
1
r
2
r
3
]
T
\boldsymbol{r} = \begin{bmatrix} r_{1} & r_{2} & r_{3} \end{bmatrix}^{T}
r
=
[
r
1
r
2
r
3
]
T
,
I
3
I_{3}
I
3
是
3
×
3
3\times3
3
×
3
单位矩阵
∂
[
(
r
T
ω
)
r
]
∂
r
=
(
r
T
ω
)
I
3
+
r
ω
T
(10)
\frac{\partial [(\boldsymbol{r}^{T} \boldsymbol{\omega}) \boldsymbol{r}]}{\partial \boldsymbol{r}} = (\boldsymbol{r}^{T} \boldsymbol{\omega})I_{3} + \boldsymbol{r}\boldsymbol{\omega}^{T} \tag{10}
∂
r
∂
[(
r
T
ω
)
r
]
=
(
r
T
ω
)
I
3
+
r
ω
T
(
10
)
叉乘运算公式
已知
ω
=
[
ω
1
ω
2
ω
3
]
T
\boldsymbol{\omega} = \begin{bmatrix} \omega_{1} & \omega_{2} & \omega_{3} \end{bmatrix}^{T}
ω
=
[
ω
1
ω
2
ω
3
]
T
,
r
=
[
r
1
r
2
r
3
]
T
\boldsymbol{r} = \begin{bmatrix} r_{1} & r_{2} & r_{3} \end{bmatrix}^{T}
r
=
[
r
1
r
2
r
3
]
T
ω
×
(
ω
×
r
)
=
ω
×
ω
×
r
=
[
−
ω
2
2
−
ω
3
2
ω
1
ω
2
ω
1
ω
3
ω
1
ω
2
−
ω
1
2
−
ω
3
2
ω
2
ω
3
ω
1
ω
3
ω
2
ω
3
−
ω
1
2
−
ω
2
2
]
[
r
1
r
2
r
3
]
(11)
\begin{aligned} \boldsymbol{\omega} \times (\boldsymbol{\omega}\times \boldsymbol{r}) &= \boldsymbol{\omega}^{\times}\boldsymbol{\omega}^{\times}\boldsymbol{r}\\ &=\begin{bmatrix} -\omega_{2}^{2} – \omega_{3}^{2} & \omega_{1}\omega_{2} & \omega_{1}\omega_{3}\\ \omega_{1}\omega_{2} & -\omega_{1}^{2} – \omega_{3}^{2} & \omega_{2}\omega_{3} \\ \omega_{1}\omega_{3} & \omega_{2}\omega_{3} & -\omega_{1}^{2} – \omega_{2}^{2} \end{bmatrix} \begin{bmatrix} r_{1} \\ r_{2} \\ r_{3} \end{bmatrix} \end{aligned} \tag{11}
ω
×
(
ω
×
r
)
=
ω
×
ω
×
r
=
−
ω
2
2
−
ω
3
2
ω
1
ω
2
ω
1
ω
3
ω
1
ω
2
−
ω
1
2
−
ω
3
2
ω
2
ω
3
ω
1
ω
3
ω
2
ω
3
−
ω
1
2
−
ω
2
2
r
1
r
2
r
3
(
11
)
雅克比恒等式:
a
×
(
b
×
c
)
=
b
×
(
a
×
c
)
+
c
×
(
b
×
a
)
\mathbf{a}\times(\mathbf{b}\times\mathbf{c}) = \mathbf{b}\times(\mathbf{a}\times\mathbf{c}) + \mathbf{c}\times(\mathbf{b}\times\mathbf{a})
a
×
(
b
×
c
)
=
b
×
(
a
×
c
)
+
c
×
(
b
×
a
)
拉格朗日公式:
a
×
(
b
×
c
)
=
(
a
⋅
c
)
b
−
(
a
⋅
b
)
c
\mathbf{a}\times(\mathbf{b}\times\mathbf{c}) = (\mathbf{a}\cdot\mathbf{c}) \mathbf{b} – (\mathbf{a}\cdot\mathbf{b}) \mathbf{c}
a
×
(
b
×
c
)
=
(
a
⋅
c
)
b
−
(
a
⋅
b
)
c
使用软件计算导数
可以使用编程语言提供的符号运算功能来求导,例如:Python、Julia、C++和MATLAB等等。下面给出几个简单的例子。比较出名的一个符号运算库是
symengine
,它是使用C++开发的,很多编程语言都可以使用该符号运算库。
例如,现在要求向量函数
g
=
−
r
∥
r
∥
3
\boldsymbol{g} = -\dfrac{\boldsymbol{r}}{\Vert\boldsymbol{r}\Vert^3}
g
=
−
∥
r
∥
3
r
关于
r
\boldsymbol{r}
r
的雅克比矩阵,下面分别用Python和MATLAB实现。
- 使用Python求解的代码:
import sympy as sp # 导入符号运算库
r = sp.Matrix(sp.symbols('r_x r_y r_z', real=True)); # A 3 by 1 vector
g = -r / sp.sqrt(sp.DotProduct(r,r).doit())**3 # 计算g的表达式
dgdr = g.jacobian(r) # 计算雅克比矩阵
dgdrs = sp.sympify(dgdr) # 简化雅克比矩阵,有没有这一步结果竟然一样
print(sp.latex(dgdrs)) # 输出雅克比矩阵公式的latex代码
结果:
[
3
r
x
2
(
r
x
2
+
r
y
2
+
r
z
2
)
5
2
−
1
(
r
x
2
+
r
y
2
+
r
z
2
)
3
2
3
r
x
r
y
(
r
x
2
+
r
y
2
+
r
z
2
)
5
2
3
r
x
r
z
(
r
x
2
+
r
y
2
+
r
z
2
)
5
2
3
r
x
r
y
(
r
x
2
+
r
y
2
+
r
z
2
)
5
2
3
r
y
2
(
r
x
2
+
r
y
2
+
r
z
2
)
5
2
−
1
(
r
x
2
+
r
y
2
+
r
z
2
)
3
2
3
r
y
r
z
(
r
x
2
+
r
y
2
+
r
z
2
)
5
2
3
r
x
r
z
(
r
x
2
+
r
y
2
+
r
z
2
)
5
2
3
r
y
r
z
(
r
x
2
+
r
y
2
+
r
z
2
)
5
2
3
r
z
2
(
r
x
2
+
r
y
2
+
r
z
2
)
5
2
−
1
(
r
x
2
+
r
y
2
+
r
z
2
)
3
2
]
\left[\begin{matrix}\frac{3 r_{x}^{2}}{\left(r_{x}^{2} + r_{y}^{2} + r_{z}^{2}\right)^{\frac{5}{2}}} – \frac{1}{\left(r_{x}^{2} + r_{y}^{2} + r_{z}^{2}\right)^{\frac{3}{2}}} & \frac{3 r_{x} r_{y}}{\left(r_{x}^{2} + r_{y}^{2} + r_{z}^{2}\right)^{\frac{5}{2}}} & \frac{3 r_{x} r_{z}}{\left(r_{x}^{2} + r_{y}^{2} + r_{z}^{2}\right)^{\frac{5}{2}}}\\\frac{3 r_{x} r_{y}}{\left(r_{x}^{2} + r_{y}^{2} + r_{z}^{2}\right)^{\frac{5}{2}}} & \frac{3 r_{y}^{2}}{\left(r_{x}^{2} + r_{y}^{2} + r_{z}^{2}\right)^{\frac{5}{2}}} – \frac{1}{\left(r_{x}^{2} + r_{y}^{2} + r_{z}^{2}\right)^{\frac{3}{2}}} & \frac{3 r_{y} r_{z}}{\left(r_{x}^{2} + r_{y}^{2} + r_{z}^{2}\right)^{\frac{5}{2}}}\\\frac{3 r_{x} r_{z}}{\left(r_{x}^{2} + r_{y}^{2} + r_{z}^{2}\right)^{\frac{5}{2}}} & \frac{3 r_{y} r_{z}}{\left(r_{x}^{2} + r_{y}^{2} + r_{z}^{2}\right)^{\frac{5}{2}}} & \frac{3 r_{z}^{2}}{\left(r_{x}^{2} + r_{y}^{2} + r_{z}^{2}\right)^{\frac{5}{2}}} – \frac{1}{\left(r_{x}^{2} + r_{y}^{2} + r_{z}^{2}\right)^{\frac{3}{2}}}\end{matrix}\right]
(
r
x
2
+
r
y
2
+
r
z
2
)
2
5
3
r
x
2
−
(
r
x
2
+
r
y
2
+
r
z
2
)
2
3
1
(
r
x
2
+
r
y
2
+
r
z
2
)
2
5
3
r
x
r
y
(
r
x
2
+
r
y
2
+
r
z
2
)
2
5
3
r
x
r
z
(
r
x
2
+
r
y
2
+
r
z
2
)
2
5
3
r
x
r
y
(
r
x
2
+
r
y
2
+
r
z
2
)
2
5
3
r
y
2
−
(
r
x
2
+
r
y
2
+
r
z
2
)
2
3
1
(
r
x
2
+
r
y
2
+
r
z
2
)
2
5
3
r
y
r
z
(
r
x
2
+
r
y
2
+
r
z
2
)
2
5
3
r
x
r
z
(
r
x
2
+
r
y
2
+
r
z
2
)
2
5
3
r
y
r
z
(
r
x
2
+
r
y
2
+
r
z
2
)
2
5
3
r
z
2
−
(
r
x
2
+
r
y
2
+
r
z
2
)
2
3
1
- 使用MATLAB求解的代码:
syms r [3, 1]; % 定义符号变量r
assume(r, 'real'); % 设置r为实向量
g = -r/norm(r)^3; % 构造符号表达式g
dgdr = jacobian(g, r); % 计算雅克比矩阵
dgdrs = simplify(dgdr); % 简化雅克比矩阵
latex(dgdrs) % 输出雅克比矩阵公式的latex代码
结果:
(
−
−
2
r
1
2
+
r
2
2
+
r
3
2
(
r
1
2
+
r
2
2
+
r
3
2
)
5
/
2
3
r
1
r
2
(
r
1
2
+
r
2
2
+
r
3
2
)
5
/
2
3
r
1
r
3
(
r
1
2
+
r
2
2
+
r
3
2
)
5
/
2
3
r
1
r
2
(
r
1
2
+
r
2
2
+
r
3
2
)
5
/
2
−
r
1
2
−
2
r
2
2
+
r
3
2
(
r
1
2
+
r
2
2
+
r
3
2
)
5
/
2
3
r
2
r
3
(
r
1
2
+
r
2
2
+
r
3
2
)
5
/
2
3
r
1
r
3
(
r
1
2
+
r
2
2
+
r
3
2
)
5
/
2
3
r
2
r
3
(
r
1
2
+
r
2
2
+
r
3
2
)
5
/
2
−
r
1
2
+
r
2
2
−
2
r
3
2
(
r
1
2
+
r
2
2
+
r
3
2
)
5
/
2
)
\left(\begin{array}{ccc} -\frac{-2\,{r_{1}}^2+{r_{2}}^2+{r_{3}}^2}{
{\left({r_{1}}^2+{r_{2}}^2+{r_{3}}^2\right)}^{5/2}} & \frac{3\,r_{1}\,r_{2}}{
{\left({r_{1}}^2+{r_{2}}^2+{r_{3}}^2\right)}^{5/2}} & \frac{3\,r_{1}\,r_{3}}{
{\left({r_{1}}^2+{r_{2}}^2+{r_{3}}^2\right)}^{5/2}}\\ \frac{3\,r_{1}\,r_{2}}{
{\left({r_{1}}^2+{r_{2}}^2+{r_{3}}^2\right)}^{5/2}} & -\frac{
{r_{1}}^2-2\,{r_{2}}^2+{r_{3}}^2}{
{\left({r_{1}}^2+{r_{2}}^2+{r_{3}}^2\right)}^{5/2}} & \frac{3\,r_{2}\,r_{3}}{
{\left({r_{1}}^2+{r_{2}}^2+{r_{3}}^2\right)}^{5/2}}\\ \frac{3\,r_{1}\,r_{3}}{
{\left({r_{1}}^2+{r_{2}}^2+{r_{3}}^2\right)}^{5/2}} & \frac{3\,r_{2}\,r_{3}}{
{\left({r_{1}}^2+{r_{2}}^2+{r_{3}}^2\right)}^{5/2}} & -\frac{
{r_{1}}^2+{r_{2}}^2-2\,{r_{3}}^2}{
{\left({r_{1}}^2+{r_{2}}^2+{r_{3}}^2\right)}^{5/2}} \end{array}\right)
−
(
r
1
2
+
r
2
2
+
r
3
2
)
5/2
−
2
r
1
2
+
r
2
2
+
r
3
2
(
r
1
2
+
r
2
2
+
r
3
2
)
5/2
3
r
1
r
2
(
r
1
2
+
r
2
2
+
r
3
2
)
5/2
3
r
1
r
3
(
r
1
2
+
r
2
2
+
r
3
2
)
5/2
3
r
1
r
2
−
(
r
1
2
+
r
2
2
+
r
3
2
)
5/2
r
1
2
−
2
r
2
2
+
r
3
2
(
r
1
2
+
r
2
2
+
r
3
2
)
5/2
3
r
2
r
3
(
r
1
2
+
r
2
2
+
r
3
2
)
5/2
3
r
1
r
3
(
r
1
2
+
r
2
2
+
r
3
2
)
5/2
3
r
2
r
3
−
(
r
1
2
+
r
2
2
+
r
3
2
)
5/2
r
1
2
+
r
2
2
−
2
r
3
2