Part I · 第 3 章 多元与向量微积分 · 3.3Part I · Ch. 3 Multivariable & Vector Calculus · 3.3

雅可比:局部线性变换The Jacobian: a Local Linear Map

非线性映射会把方格网弄弯。可只要拿放大镜对准任何一点,弯曲的网格就会变回一张笔直、等距、只是被斜拉过的网格,也就是一个矩阵。这个"放大之后看到的矩阵"就是雅可比矩阵 (Jacobian)。机械臂的速度、EKF 的线性化、逆运动学的每一步迭代,都靠它。 A nonlinear map bends the square grid. Yet point a magnifying glass at any spot and the bent grid turns back into a straight, evenly spaced, merely skewed grid: a matrix. That "matrix you see when you zoom in" is the Jacobian. Arm velocities, EKF linearization and every step of inverse kinematics run on it.

约 25 分钟~25 min 前置:1.3 矩阵即变换 · 2.1 导数 · 3.1 偏导Prereqs: 1.3 Matrices as Maps · 2.1 Derivatives · 3.1 Partials 5 个交互5 interactives

    1为什么机器人需要它Why robots need this

    机械臂的控制器每毫秒都要回答一个问题:"如果让每个关节以某个速度转,手爪会朝哪个方向、以多快的速度移动?"从关节角到手爪位置的映射里全是 sin 和 cos,是弯的、非线性的。控制器想要的答案却是线性的:关节速度乘以一个矩阵,等于手爪速度。

    同样的需求在机器人里随处可见:

    • 扩展卡尔曼滤波 (EKF) 要在当前估计附近,把非线性的传感器模型"拉直"成一个矩阵,才能套用卡尔曼滤波的公式;
    • 视觉 SLAM 与相机标定要知道:三维点挪动一点点,它在图像上的像素会挪多少;
    • 逆运动学和 Gauss-Newton 优化每一步都在问:参数朝哪个方向改,误差下降得最快?

    这些问题找的是同一个东西:一个非线性映射在某一点附近的最佳线性近似。它就是本节的主角。

    An arm controller has to answer one question every millisecond: "if I spin each joint at some rate, which way and how fast does the gripper move?" The map from joint angles to gripper position is full of sines and cosines; it is curved and nonlinear. Yet the answer the controller wants is linear: joint velocities times a matrix equals gripper velocity.

    The same need shows up all over robotics:

    • An Extended Kalman Filter (EKF) must "straighten out" a nonlinear sensor model into a matrix around the current estimate before the Kalman equations apply.
    • Visual SLAM and camera calibration need to know how far a pixel moves when a 3D point moves a tiny bit.
    • Inverse kinematics and Gauss-Newton optimization ask at every step: which way should the parameters change so the error drops fastest?

    All of them are after the same thing: the best linear approximation of a nonlinear map near one point. That is this lesson's star.

    2直觉:放大到足够近,弯的都会变直Intuition: zoom in far enough and everything is straight

    先回到一维(2.1 节)。一条曲线远看是弯的,但盯住曲线上一点不断放大,它会越来越像一条直线,也就是那一点的切线。切线的斜率 \(g'(a)\) 就是导数。

    换个说法:在 \(a\) 附近,\(g\) 的行为就像"乘以 \(g'(a)\)"这个最简单的线性映射。输入挪动 \(\delta\),输出就挪动 \(g'(a)\,\delta\)。拖动黄点换个位置,再把放大倍数拉高看看。

    Start in one dimension (Lesson 2.1). A curve looks bent from afar, but keep zooming in on one of its points and it looks more and more like a straight line: the tangent at that point. The tangent's slope \(g'(a)\) is the derivative.

    Put differently: near \(a\), \(g\) behaves like the simplest linear map there is, "multiply by \(g'(a)\)". Nudge the input by \(\delta\) and the output moves by \(g'(a)\,\delta\). Drag the amber dot somewhere else, then crank up the zoom.

    FIG 1放大一条曲线Zooming in on a curve
    青色是曲线 \(g(x)\),黄色虚线是 \(a\) 处的切线。红色横边是输入的挪动 \(\delta\),绿色竖边是切线预测的输出挪动 \(g'(a)\,\delta\)。放大 100 倍后,曲线和切线已经分不开了。 Cyan is the curve \(g(x)\); the dashed amber line is the tangent at \(a\). The red run is an input nudge \(\delta\); the green rise is the tangent's predicted output change \(g'(a)\,\delta\). At 100× zoom you can no longer tell curve and tangent apart.

    二维也是同一个故事。回想 1.3 节的橡皮膜:非线性映射 \(f:\R^2\to\R^2\) 把膜上的方格网弄得弯弯曲曲。可是用放大镜对准某一点 \(\mathbf p\),放得越大,看到的网格就越接近笔直、平行、等距,只是被斜拉、旋转、伸缩过。这正是 1.3 节里线性变换的样子,而线性变换就是一个矩阵。

    这个矩阵只属于 \(\mathbf p\) 这一点,换一个点,放大后看到的斜网格就不一样。它叫做 \(f\) 在 \(\mathbf p\) 处的雅可比矩阵 \(J(\mathbf p)\):

    Two dimensions tell the same story. Recall the rubber sheet from Lesson 1.3: a nonlinear map \(f:\R^2\to\R^2\) bends the grid every which way. But aim a magnifying glass at a point \(\mathbf p\) and, the closer you zoom, the more the grid looks straight, parallel and evenly spaced, just skewed, turned and stretched. That is exactly what a linear map from Lesson 1.3 looks like, and a linear map is a matrix.

    That matrix belongs to the point \(\mathbf p\) alone; pick another point and the zoomed-in skewed grid is different. It is called the Jacobian of \(f\) at \(\mathbf p\), written \(J(\mathbf p)\):

    $$ f(\mathbf p + \boldsymbol\delta) \;\approx\; \cv{f(\mathbf p)} \;+\; \cw{J(\mathbf p)}\,\boldsymbol\delta \qquad (\boldsymbol\delta \text{ small}) $$
    核心洞见Key insight

    雅可比矩阵就是放大之后看到的那个线性变换。按 1.3 节的读法读它的列:第 1 列是"沿第 1 个输入方向轻推一下,输出往哪走、走多快",第 2 列是"沿第 2 个输入方向轻推一下"。所以第 \(j\) 列就是偏导数 \(\partial f/\partial x_j\)(3.1 节)。

    The Jacobian is the linear map you see after zooming in. Read its columns the Lesson 1.3 way: column 1 says "nudge input 1, and here is which way and how fast the output moves"; column 2 does the same for input 2. So column \(j\) is the partial derivative \(\partial f/\partial x_j\) (Lesson 3.1).

    3动手玩:雅可比实验室Play: the Jacobian lab

    左边是输入平面:拖动黄点 \(\mathbf p\),它周围有一个边长为 \(h\) 的小方块。右边是输出平面:青色的弯曲网格是 \(f\) 作用之后的网格;黄色区域是小方块的真实像(边是弯的);紫色虚线平行四边形是雅可比的预测 \(f(\mathbf p) + J\,\boldsymbol\delta\)。切换到"放大"视图,再把 \(h\) 往小拉,看两者如何重合。

    The left panel is the input plane: drag the amber point \(\mathbf p\), which carries a small square of side \(h\). The right panel is the output plane: the bent cyan grid is the grid after \(f\); the amber region is the square's true image (with curved edges); the dashed purple parallelogram is the Jacobian's prediction \(f(\mathbf p) + J\,\boldsymbol\delta\). Switch to the zoomed view and pull \(h\) down to watch the two merge.

    FIG 2雅可比实验室Jacobian lab
    小方块的红边沿第 1 个输入方向,绿边沿第 2 个输入方向;它们的像在右边仍用红、绿表示。穿过 \(\mathbf p\) 的两条网格线也标成了红、绿。黄色是真实的像,紫色虚线是线性预测,短红线连接对应的角点,长度就是误差。注意:把 \(h\) 减半,角点误差大约变成原来的四分之一。 The square's red edges run along input 1 and its green edges along input 2; their images on the right keep the same colors, as do the two grid lines through \(\mathbf p\). Amber is the true image, dashed purple the linear prediction, and the short red segments join matching corners: their length is the error. Notice: halve \(h\) and the corner error drops to about a quarter.
    试一试Try this
    • 把 \(h\) 缩小,直到相对误差低于 1%:这时弯曲的像和平行四边形已经肉眼难辨。Shrink \(h\) until the relative error drops below 1%: by then the curved image and the parallelogram are hard to tell apart.
    • 找一个让 \(J\) 退化(\(\det J \approx 0\))的点。提示:试试"复平方"的原点,或者极坐标里的 \(r = 0\)。小方块的像变成了什么?Find a point where \(J\) degenerates (\(\det J \approx 0\)). Hint: try the origin of "square z²", or \(r = 0\) in polar. What does the square's image turn into?
    • 在"镜头畸变"里找一个让网格翻面(\(\det J < 0\))的点。它们都在一个圆环外面,那个圆环就是"折痕"。In "lens distortion", find a point where the grid flips over (\(\det J < 0\)). They all lie outside a ring, and that ring is the "crease".

    从实验里可以读出两件事。第一,误差随 \(h\) 按平方缩小:\(h\) 减半,误差约变为四分之一;而方块本身只缩小一半,所以相对误差也跟着减半。这就是"一阶近似"的确切含义:剩下的误差比 \(\boldsymbol\delta\) 本身小得多。

    第二,\(J\) 在每一点都不同。在极坐标的例子里,越往外(\(r\) 越大),绿色那一列越长:同样转动角度 \(\theta\),离原点越远的点走得越远。

    Two things can be read off the lab. First, the error shrinks with the square of \(h\): halve \(h\) and the error drops to about a quarter, while the square itself only halves, so the relative error halves too. That is precisely what "first-order approximation" means: what is left over is much smaller than \(\boldsymbol\delta\) itself.

    Second, \(J\) is different at every point. In the polar example, the green column gets longer the farther out you go (larger \(r\)): turning by the same angle \(\theta\) carries a far-away point a longer distance.

    4第二视角:列是速度,行列式是面积A second view: columns are velocities, the determinant is area

    1.3 节说,矩阵的列是 î、ĵ 的去向。对雅可比来说,"去向"换成了"速度":让输入点沿第 1 个坐标方向以单位速度匀速前进,它的像会沿一条弯曲的路走,像在每一时刻的速度向量,正好是那一时刻所在点的雅可比的第 1 列。

    下面的动画就在做这件事。看实线箭头(当前位置的速度)经过 \(\mathbf p\) 时,与虚线箭头 \(J(\mathbf p)\) 的那一列完全重合。

    Lesson 1.3 said the columns of a matrix are where î and ĵ land. For a Jacobian, "where they land" becomes "velocity": move the input point along coordinate 1 at unit speed, and its image travels along a curved path; the image's velocity at each instant is exactly column 1 of the Jacobian at the point it is currently passing.

    The animation below does just that. Watch the solid arrow (velocity at the current position) line up exactly with the dashed arrow, the column of \(J(\mathbf p)\), as the dot passes \(\mathbf p\).

    FIG 3雅可比的列 = 输出的速度Columns of J = output velocities
    输入:匀速直线运动INPUT · straight, unit speed
    输出:弯曲路径上的速度OUTPUT · velocity along a curve
    箭头都按 0.55 倍长度绘制。左边的箭头始终是单位长度的 \(\hat e_j\);右边的实线箭头是当前点处的 \(J\,\hat e_j\),即第 \(j\) 列。下方的有限差分读数用 \(\big(f(\mathbf p+\varepsilon\hat e_j)-f(\mathbf p)\big)/\varepsilon\) 估计这一列:把 \(\varepsilon\) 从 1 一路拉到 \(10^{-15}\),误差会先下降、再回升。 All arrows are drawn at 0.55× length. The left arrow is always the unit vector \(\hat e_j\); the solid right arrow is \(J\,\hat e_j\) at the current point, i.e. column \(j\). The finite-difference readout estimates that column as \(\big(f(\mathbf p+\varepsilon\hat e_j)-f(\mathbf p)\big)/\varepsilon\): sweep \(\varepsilon\) from 1 down to \(10^{-15}\) and the error first falls, then climbs back up.

    再看行列式。1.5 节讲过,矩阵的行列式是面积的缩放倍数,负号表示网格翻了面。非线性映射在每一点都有自己的雅可比,也就有自己的缩放倍数 \(\det J(\mathbf p)\):那一点附近的小方块,面积被放大(或缩小)了这么多倍。

    下图把 \(\det J\) 画成输入平面上的一张热力图。把鼠标移到图上(手机上点一下),右边会显示那一点的 \(J\) 把单位正方形变成了什么。

    Now the determinant. Lesson 1.5 showed that a matrix's determinant is its area scale factor, with a minus sign meaning the grid flipped over. A nonlinear map has its own Jacobian at every point, and so its own scale factor \(\det J(\mathbf p)\): a tiny square near that point has its area multiplied by that much.

    The figure below paints \(\det J\) as a heatmap over the input plane. Hover over it (tap on a phone) and the side panel shows what the \(J\) at that point does to the unit square.

    FIG 4\(\det J\):每一点的面积缩放\(\det J\): area scaling, point by point
    < 00> 0
    青色表示 \(\det J > 0\)(保持朝向),紫色表示 \(\det J < 0\)(翻面),颜色越淡越接近 0。红色细线标出 \(\det J\) 变号的位置,也就是"折痕"。右上小图:浅色虚线是单位正方形,彩色平行四边形是它在 \(J\) 下的像,红、绿边分别是 \(J\) 的两列。 Cyan means \(\det J > 0\) (orientation kept), purple means \(\det J < 0\) (flipped); the paler, the closer to 0. Thin red lines mark where \(\det J\) changes sign: the "crease". Small panel: the faint dashed square is the unit square, the colored parallelogram its image under \(J\), with red and green edges the two columns of \(J\).

    几个值得留意的现象:漩涡看起来扭得很厉害,\(\det J\) 却处处等于 1,它只搬动不压缩,是一个保面积的映射。极坐标的 \(\det J = r\),越靠近 \(r=0\) 越淡。镜头畸变有一圈 \(\det J = 0\) 的折痕,折痕以外的部分被翻折回来,同一个像素对应了两个方向的光线。真实的鱼眼镜头模型只在折痕以内才可逆,标定时要特别小心。

    A few things worth noticing. The swirl looks violently twisted, yet \(\det J = 1\) everywhere: it moves things around without compressing them, an area-preserving map. In polar, \(\det J = r\), fading toward \(r = 0\). The lens distortion has a ring where \(\det J = 0\), and everything outside that crease is folded back, so one pixel corresponds to rays from two directions. Real fisheye models are invertible only inside the crease, something to watch out for in calibration.

    5再看数学The math

    提示:把鼠标悬停在公式中带底色的符号上,FIG 2 中对应的元素会被高亮。Tip: hover the highlighted symbols in the formulas; the matching element in FIG 2 lights up.

    定义Definition

    设 \(f:\R^n\to\R^m\),\(f = (f_1,\dots,f_m)\)。它在点 \(\mathbf p\) 处的雅可比矩阵是 \(m\times n\) 的偏导数表:第 \(i\) 行第 \(j\) 列是"第 \(i\) 个输出对第 \(j\) 个输入的偏导"。

    Let \(f:\R^n\to\R^m\) with \(f = (f_1,\dots,f_m)\). Its Jacobian at \(\mathbf p\) is the \(m\times n\) table of partial derivatives: row \(i\), column \(j\) holds "output \(i\) differentiated with respect to input \(j\)".

    $$ J_f(\mathbf p) = \begin{bmatrix} \hl{c1}{\ci{\dfrac{\partial f}{\partial x_1}}} & \hl{c2}{\cj{\dfrac{\partial f}{\partial x_2}}} & \cdots & \dfrac{\partial f}{\partial x_n} \end{bmatrix} = \begin{bmatrix} \ci{\dfrac{\partial f_1}{\partial x_1}} & \cj{\dfrac{\partial f_1}{\partial x_2}} & \cdots & \dfrac{\partial f_1}{\partial x_n} \\ \vdots & \vdots & & \vdots \\ \ci{\dfrac{\partial f_m}{\partial x_1}} & \cj{\dfrac{\partial f_m}{\partial x_2}} & \cdots & \dfrac{\partial f_m}{\partial x_n} \end{bmatrix}, \qquad J_{ij} = \frac{\partial f_i}{\partial x_j}(\mathbf p). $$

    按列读:第 \(j\) 列是沿 \(x_j\) 轻推时输出的速度(FIG 3)。按行读:第 \(i\) 行是单个输出 \(f_i\) 的梯度 \(\nabla f_i^\top\)(3.2 节)。特别地,如果输出只有一个数(\(m = 1\)),雅可比就是一行,正好是梯度的转置:\(J = \nabla f^\top\)。

    Read by columns: column \(j\) is the output velocity when you nudge \(x_j\) (FIG 3). Read by rows: row \(i\) is the gradient \(\nabla f_i^\top\) of the single output \(f_i\) (Lesson 3.2). In particular, when the output is a single number (\(m = 1\)), the Jacobian is one row, the gradient transposed: \(J = \nabla f^\top\).

    一阶泰勒展开First-order Taylor expansion

    "放大后像一个矩阵"写成公式,就是:

    "Zoomed in, it looks like a matrix" in symbols:

    $$ f(\mathbf p + \hl{d}{\boldsymbol\delta}) \;=\; \hl{fp}{\cv{f(\mathbf p)}} \;+\; \hl{J}{\cw{J(\mathbf p)}}\,\hl{d}{\boldsymbol\delta} \;+\; \hl{err}{o(\|\boldsymbol\delta\|)} $$

    余项 \(o(\|\boldsymbol\delta\|)\) 的意思是:它比 \(\|\boldsymbol\delta\|\) 消失得更快,除以 \(\|\boldsymbol\delta\|\) 后趋于 0。对光滑的 \(f\),余项的大小是 \(O(\|\boldsymbol\delta\|^2)\),这正是 FIG 2 里"\(h\) 减半,误差变为四分之一"的原因。而且 \(J(\mathbf p)\) 是唯一满足这个式子的矩阵,所以叫它"最佳"线性近似。

    The remainder \(o(\|\boldsymbol\delta\|)\) means it vanishes faster than \(\|\boldsymbol\delta\|\): divided by \(\|\boldsymbol\delta\|\), it goes to 0. For smooth \(f\) the remainder is \(O(\|\boldsymbol\delta\|^2)\), which is exactly why halving \(h\) in FIG 2 quarters the error. And \(J(\mathbf p)\) is the only matrix that makes this hold, which is what earns it the title of "best" linear approximation.

    链式法则:局部线性映射的复合就是矩阵乘法Chain rule: composing local linear maps is matrix multiplication

    先做 \(f\),再做 \(g\)。在 \(\mathbf p\) 附近,\(f\) 像矩阵 \(J_f(\mathbf p)\);在 \(f(\mathbf p)\) 附近,\(g\) 像矩阵 \(J_g(f(\mathbf p))\)。两个线性映射接连作用,就是两个矩阵相乘(1.4 节):

    Apply \(f\), then \(g\). Near \(\mathbf p\), \(f\) acts like the matrix \(J_f(\mathbf p)\); near \(f(\mathbf p)\), \(g\) acts like \(J_g(f(\mathbf p))\). Two linear maps in a row are one matrix product (Lesson 1.4):

    $$ J_{g\circ f}(\mathbf p) \;=\; J_g\big(f(\mathbf p)\big)\; J_f(\mathbf p). $$

    注意两件事:顺序是"后做的在左边",和 1.4 节的矩阵复合一样;\(J_g\) 要在 \(f(\mathbf p)\) 处求值,而不是在 \(\mathbf p\) 处。机器人里,相机投影的雅可比就是这样拼出来的:世界点 → 相机坐标(位姿变换)→ 像素(针孔投影),各自的雅可比相乘即可。

    Two details: the map applied last sits on the left, just like matrix composition in Lesson 1.4; and \(J_g\) is evaluated at \(f(\mathbf p)\), not at \(\mathbf p\). In robotics, this is how the camera-projection Jacobian is assembled: world point → camera coordinates (pose transform) → pixel (pinhole projection), multiplying the Jacobian of each stage.

    行列式与反函数Determinant and the inverse map

    由 1.5 节,小区域经过 \(f\) 后面积约放大 \(|\det J|\) 倍,这就是换元积分里那个因子的来源。在 \(\det J(\mathbf p)\ne 0\) 的地方,\(f\) 在局部可逆,反函数的雅可比就是雅可比的逆(反函数定理):

    By Lesson 1.5, a small region's area gets multiplied by about \(|\det J|\) under \(f\); that is where the factor in a change of variables comes from. Wherever \(\det J(\mathbf p)\ne 0\), \(f\) is locally invertible, and the Jacobian of the inverse is the inverse of the Jacobian (inverse function theorem):

    $$ \operatorname{area}\big(f(\Omega)\big) \approx |\det J(\mathbf p)|\cdot\operatorname{area}(\Omega), \qquad J_{f^{-1}}\big(f(\mathbf p)\big) = J_f(\mathbf p)^{-1}\quad (\det J_f(\mathbf p)\neq 0). $$

    例题:极坐标Worked example: polar coordinates

    \(f(r,\theta) = (r\cos\theta,\; r\sin\theta)\)。对 \(r\) 求偏导得第 1 列,对 \(\theta\) 求偏导得第 2 列:

    \(f(r,\theta) = (r\cos\theta,\; r\sin\theta)\). Differentiate by \(r\) for column 1 and by \(\theta\) for column 2:

    $$ J(r,\theta) = \begin{bmatrix} \ci{\cos\theta} & \cj{-r\sin\theta} \\ \ci{\sin\theta} & \cj{r\cos\theta} \end{bmatrix}, \qquad \det J = r\cos^2\theta + r\sin^2\theta = r. $$

    逐列读出几何意义:第 1 列是单位长度的径向向量,沿 \(r\) 走一步,点就朝外走一步;第 2 列垂直于径向、长度为 \(r\),转动 \(\theta\) 时,离原点越远的点走得越快。\(\det J = r\) 说明 \(dr\times d\theta\) 的小矩形变成面积约 \(r\,dr\,d\theta\) 的小扇形,这就是 \(dx\,dy = r\,dr\,d\theta\)。在 \(r=0\) 处第 2 列为零,转动 \(\theta\) 根本不动,\(J\) 退化,这正是 FIG 2 的任务 2。

    Read each column geometrically: column 1 is the unit radial vector, so a step in \(r\) moves the point one step outward; column 2 is perpendicular to it with length \(r\), so turning \(\theta\) moves far-away points faster. \(\det J = r\) says a small \(dr\times d\theta\) rectangle becomes a small wedge of area about \(r\,dr\,d\theta\): that is \(dx\,dy = r\,dr\,d\theta\). At \(r = 0\) column 2 vanishes, turning \(\theta\) does nothing, and \(J\) degenerates: task 2 of FIG 2.

    6机器人中的它:两连杆机械臂In robotics: the two-link arm

    平面两连杆机械臂,连杆长 \(l_1, l_2\),关节角 \(\theta_1, \theta_2\)。正运动学把关节角映射到末端位置,这就是一个 \(\R^2\to\R^2\) 的非线性映射,和 FIG 2 里的那些映射没有本质区别:

    A planar two-link arm has link lengths \(l_1, l_2\) and joint angles \(\theta_1, \theta_2\). Forward kinematics maps joint angles to the tip position, an \(\R^2\to\R^2\) nonlinear map no different in kind from the ones in FIG 2:

    $$ \mathbf x(\boldsymbol\theta) = \begin{bmatrix} l_1\cos\theta_1 + l_2\cos(\theta_1+\theta_2) \\ l_1\sin\theta_1 + l_2\sin(\theta_1+\theta_2) \end{bmatrix}, \qquad \cv{\dot{\mathbf x}} = J(\boldsymbol\theta)\,\dot{\boldsymbol\theta}, $$ $$ J(\boldsymbol\theta) = \begin{bmatrix} \ci{-l_1 s_1 - l_2 s_{12}} & \cj{-l_2 s_{12}} \\ \ci{l_1 c_1 + l_2 c_{12}} & \cj{l_2 c_{12}} \end{bmatrix}, \qquad \det J = l_1 l_2 \sin\theta_2 $$

    (\(s_1 = \sin\theta_1\),\(c_{12} = \cos(\theta_1+\theta_2)\),以此类推。)第 1 列是只转关节 1 时末端的速度:整条手臂绕基座转,所以它垂直于"基座→末端"的连线。第 2 列是只转关节 2 时的速度:只有前臂绕肘部转,所以它垂直于前臂。当两列平行时,也就是基座、肘部、末端三点共线(手臂完全伸直或完全折回,\(\theta_2 = 0\) 或 \(\pi\)),\(\det J = 0\),末端在某个方向上无论关节怎么转都动不了。这叫奇异位形 (singular configuration)。

    (\(s_1 = \sin\theta_1\), \(c_{12} = \cos(\theta_1+\theta_2)\), and so on.) Column 1 is the tip velocity when only joint 1 turns: the whole arm swings about the base, so it is perpendicular to the base-to-tip line. Column 2 is the velocity when only joint 2 turns: just the forearm swings about the elbow, so it is perpendicular to the forearm. When the two columns are parallel, i.e. base, elbow and tip are collinear (arm fully stretched or fully folded, \(\theta_2 = 0\) or \(\pi\)), \(\det J = 0\) and there is a direction the tip cannot move in, no matter how the joints turn. This is a singular configuration.

    左边是关节空间:拖动黄点改变 \((\theta_1, \theta_2)\),背景是 \(\det J\) 的热力图。右边是工作空间:也可以直接拖动末端,机械臂会用雅可比做逆运动学跟上来。关节空间里的黄色小圆被映射成工作空间里的黄色椭圆(速度椭圆),紫色虚线是小圆的真实像。

    The left panel is joint space: drag the amber dot to change \((\theta_1, \theta_2)\); the background is a heatmap of \(\det J\). The right panel is the workspace: you can also drag the tip directly, and the arm follows by running Jacobian-based inverse kinematics. The small amber circle in joint space maps to the amber ellipse in the workspace (the velocity ellipse); the dashed purple curve is the circle's true image.

    FIG 5两连杆机械臂的雅可比Jacobian of a two-link arm
    关节空间 (θ₁, θ₂)JOINT SPACE (θ₁, θ₂)
    工作空间 (x, y)WORKSPACE (x, y)
    末端的红、绿箭头是 \(J\) 的两列(按小圆半径 ρ 缩放),也就是只转关节 1 或只转关节 2 时末端的速度。红色细虚线是基座到末端的连线,红箭头总是垂直于它。左图中的红色虚线 \(\theta_2 = 0, \pm\pi\) 是奇异位形。把末端往工作空间的边缘拖,看看手臂和椭圆会怎样。 The red and green arrows at the tip are the two columns of \(J\) (scaled by the circle radius ρ): the tip velocity when only joint 1, or only joint 2, turns. The thin dashed red line joins base and tip, and the red arrow is always perpendicular to it. In the left panel, the dashed red lines \(\theta_2 = 0, \pm\pi\) are the singular configurations. Drag the tip toward the edge of the workspace and watch the arm and the ellipse.
    • 让机械臂进入奇异位形:速度椭圆被压扁成一条线段,两个红绿箭头变得共线。Put the arm into a singular configuration: the velocity ellipse flattens into a segment and the red and green arrows become collinear.
    真实系统里In real systems

    速度控制:给定末端期望速度 \(\dot{\mathbf x}\),求关节速度 \(\dot{\boldsymbol\theta} = J^{-1}\dot{\mathbf x}\)。靠近奇异位形时 \(J^{-1}\) 会爆炸,所以工业控制器普遍使用阻尼最小二乘 \(J^\top(JJ^\top+\lambda^2 I)^{-1}\),FIG 5 的拖动逆解用的就是它。EKF:观测模型 \(h(\mathbf x)\) 的雅可比 \(H = \partial h/\partial\mathbf x\) 决定了卡尔曼增益,每一步都要在新的估计点上重新计算。SLAM / 光束法平差:重投影误差对位姿和三维点的雅可比,按链式法则由"位姿变换"和"针孔投影"两段拼出。6 自由度机械臂的完整雅可比(包含角速度)留到 3.4 节。

    Velocity control: given a desired tip velocity \(\dot{\mathbf x}\), solve for joint rates \(\dot{\boldsymbol\theta} = J^{-1}\dot{\mathbf x}\). Near a singularity \(J^{-1}\) blows up, so industrial controllers typically use damped least squares, \(J^\top(JJ^\top+\lambda^2 I)^{-1}\); that is what the drag-the-tip IK in FIG 5 runs. EKF: the Jacobian \(H = \partial h/\partial\mathbf x\) of the measurement model sets the Kalman gain and must be recomputed at every new estimate. SLAM / bundle adjustment: the Jacobians of the reprojection error with respect to poses and 3D points are assembled by the chain rule from a "pose transform" stage and a "pinhole projection" stage. The full Jacobian of a 6-DoF arm, angular velocity included, waits for Lesson 3.4.

    7常见误区Common pitfalls

    误区 1:雅可比是一个固定的矩阵Pitfall 1: the Jacobian is one fixed matrix

    不是。它是一个矩阵场:每个点都有自己的 \(J(\mathbf p)\)。用旧点上算出的 \(J\) 去处理新点,是 EKF 和逆运动学代码里的经典 bug。状态一变,就要在新的点上重新线性化。

    It isn't. It is a field of matrices: every point has its own \(J(\mathbf p)\). Applying a \(J\) computed at an old point to a new one is a classic bug in EKF and IK code. When the state changes, relinearize at the new point.

    误区 2:把 \(J\) 当成反方向的映射,或者随手求逆Pitfall 2: treating \(J\) as the reverse map, or inverting it blindly

    \(J\) 把输入的微小变化映射成输出的微小变化,方向是固定的。反方向要用 \(J^{-1}\),而它只在 \(\det J\ne 0\) 时存在。在奇异点附近,\(J^{-1}\) 里的数会变得极大:末端只想挪一毫米,关节却要飞速转动。

    \(J\) sends small input changes to small output changes, in that direction only. Going backwards needs \(J^{-1}\), which exists only when \(\det J\ne 0\). Near a singularity the entries of \(J^{-1}\) explode: the tip wants to move a millimetre and the joints have to whip around.

    误区 3:忘了近似只在局部成立Pitfall 3: forgetting the approximation is only local

    误差按 \(\|\boldsymbol\delta\|^2\) 增长。在 FIG 2 里把 \(h\) 调大,预测很快就离谱了。Gauss-Newton 和牛顿法如果一步迈得太大,就会跳出线性近似成立的范围,所以实际实现里总有步长控制或阻尼(Levenberg-Marquardt)。

    The error grows like \(\|\boldsymbol\delta\|^2\). Turn \(h\) up in FIG 2 and the prediction goes wrong fast. Gauss-Newton or Newton steps that are too large jump out of the region where the linearization holds, which is why real implementations always add step control or damping (Levenberg-Marquardt).

    误区 4:变量顺序和单位Pitfall 4: variable ordering and units

    列的顺序跟着输入变量的顺序走:写成 \((r,\theta)\) 还是 \((\theta,r)\),矩阵的列就会对调,行列式也会变号。各列的单位也可能不同:极坐标的第 1 列是"米/米",第 2 列是"米/弧度"。把位置(米)和角度(弧度)放进同一个状态向量时,要想清楚尺度,否则矩阵的条件数会很差。

    The column order follows the order of the input variables: write \((r,\theta)\) or \((\theta,r)\) and the columns swap, flipping the sign of the determinant. Columns may also carry different units: in polar, column 1 is "metres per metre" and column 2 "metres per radian". When positions (metres) and angles (radians) share one state vector, think about scaling, or the matrix will be badly conditioned.

    误区 5:有限差分的步长随便取Pitfall 5: picking any finite-difference step

    用 \(\big(f(\mathbf p+\varepsilon\hat e_j)-f(\mathbf p)\big)/\varepsilon\) 数值求雅可比时,\(\varepsilon\) 太大有截断误差,太小则两个几乎相等的浮点数相减,舍入误差会被放大。双精度下前向差分的经验值约为 \(\varepsilon\approx 10^{-8}\times\)(变量的尺度),中心差分更准。FIG 3 下方的滑块可以亲自验证这一点。

    When estimating a Jacobian numerically as \(\big(f(\mathbf p+\varepsilon\hat e_j)-f(\mathbf p)\big)/\varepsilon\), a large \(\varepsilon\) brings truncation error, and a tiny one subtracts two nearly equal floats and amplifies round-off. In double precision the rule of thumb for forward differences is \(\varepsilon\approx 10^{-8}\times\) (the variable's scale); central differences are more accurate. The slider under FIG 3 lets you see this for yourself.

    8小练习Check yourself

    1. \(f(x,y) = (x^2,\; xy)\)。它在点 \((1, 2)\) 处的雅可比是?1. \(f(x,y) = (x^2,\; xy)\). What is its Jacobian at \((1, 2)\)?
    第 1 行是 \(f_1 = x^2\) 的偏导 \((2x,\,0)\),第 2 行是 \(f_2 = xy\) 的偏导 \((y,\,x)\)。代入 \((1,2)\) 得 \(\begin{bmatrix}2&0\\2&1\end{bmatrix}\)。选项 A 是它的转置,正是"行列搞反"的错误。Row 1 holds the partials of \(f_1 = x^2\): \((2x,\,0)\). Row 2 holds those of \(f_2 = xy\): \((y,\,x)\). At \((1,2)\) that gives \(\begin{bmatrix}2&0\\2&1\end{bmatrix}\). Option A is its transpose, the classic rows-versus-columns mix-up.
    2. 在极坐标映射下,输入平面中 \(r = 2\) 附近一个 \(dr\times d\theta\) 的小矩形,它的像面积约为?2. Under the polar map, a small \(dr\times d\theta\) rectangle near \(r = 2\) has an image of area about…?
    面积缩放倍数是 \(|\det J| = r = 2\)。直观上:径向长度不变,角向长度被放大成 \(r\,d\theta\)。The area scale is \(|\det J| = r = 2\). Intuitively: the radial side keeps its length while the angular side becomes \(r\,d\theta\).
    3. 平面两连杆机械臂(\(l_1, l_2 > 0\))在什么情况下处于奇异位形?3. When is a planar two-link arm (\(l_1, l_2 > 0\)) singular?
    \(\det J = l_1 l_2\sin\theta_2\),只和 \(\theta_2\) 有关,在 \(\theta_2 = 0, \pi\) 时为零。此时两列都垂直于同一条直线,末端沿这条直线方向动不了。\(\theta_2 = \pi/2\) 恰恰相反,\(|\det J|\) 最大,最灵活。\(\det J = l_1 l_2\sin\theta_2\) depends only on \(\theta_2\) and vanishes at \(\theta_2 = 0, \pi\). Both columns are then perpendicular to the same line, and the tip cannot move along it. \(\theta_2 = \pi/2\) is the opposite: \(|\det J|\) is largest and the arm is most dexterous.
    4. 像素坐标 = \(g(f(\mathbf p))\),其中 \(f\) 把世界点变到相机坐标系,\(g\) 是针孔投影。像素对 \(\mathbf p\) 的雅可比是?4. Pixel = \(g(f(\mathbf p))\), where \(f\) moves a world point into the camera frame and \(g\) is the pinhole projection. What is the Jacobian of the pixel with respect to \(\mathbf p\)?
    链式法则:后做的 \(g\) 在左边,而且要在 \(f(\mathbf p)\) 处求值。选项 C 把求值点弄错了,选项 A 顺序反了(维度通常也对不上:\(J_g\) 是 2×3,\(J_f\) 是 3×3)。Chain rule: \(g\), applied last, goes on the left, and it is evaluated at \(f(\mathbf p)\). Option C uses the wrong evaluation point; option A has the order reversed (and the shapes usually do not even match: \(J_g\) is 2×3, \(J_f\) is 3×3).

    9延伸阅读Further reading

    • K. Lynch & F. Park, Modern Robotics, Ch. 5 — 速度运动学与静力学(机械臂雅可比、奇异性、可操作度椭球)Velocity kinematics and statics (the manipulator Jacobian, singularities, manipulability ellipsoids)
    • Khan Academy, Multivariable Calculus — Grant Sanderson(3Blue1Brown)讲解的"局部线性"与"雅可比矩阵"系列视频Grant Sanderson's (3Blue1Brown) videos on local linearity and the Jacobian matrix
    • G. Strang, Calculus (MIT OpenCourseWare) — 偏导数、链式法则与重积分换元Partial derivatives, the chain rule and change of variables in multiple integrals
    • S. Thrun, W. Burgard & D. Fox, Probabilistic Robotics, Ch. 3.3 — 扩展卡尔曼滤波中的雅可比线性化Jacobian linearization in the Extended Kalman Filter
    • J. Nocedal & S. Wright, Numerical Optimization, Ch. 8 & 10 — 有限差分求导、Gauss-Newton 与 Levenberg-MarquardtFinite-difference derivatives, Gauss-Newton and Levenberg-Marquardt