Part I · 第 1 章 线性代数 · 1.5Part I · Ch. 1 Linear Algebra · 1.5

行列式The Determinant

矩阵可以把平面拉伸、剪切、旋转,但有一件事对所有形状都一样:面积被放大了同一个倍数。这个倍数就是行列式。它为正,空间保持朝向;为负,空间被翻了面;为零,空间被压扁,再也回不来。 A matrix can stretch, shear and rotate the plane, but one thing is the same for every shape: its area is multiplied by the same factor. That factor is the determinant. Positive, and space keeps its orientation; negative, and space is flipped over; zero, and space is squashed flat and can never be restored.

约 25 分钟~25 min 前置:1.3 矩阵即变换 · 1.4 矩阵乘法Prereqs: 1.3 Matrices as Transformations · 1.4 Matrix Multiplication 8 个交互8 interactives

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

    行列式只是一个数,却能一眼看出一个矩阵"好不好用"。机器人里有三个场合天天碰到它。

    • 奇异位形。机械臂的雅可比矩阵 \(J\) 把关节速度变成手端速度。一旦 \(\det J = 0\),手端就丢了一个运动方向:不管关节怎么转,手都不能往那个方向动。手臂完全伸直就是典型例子(本课第 8 节会亲手试;3.3、3.4 节会深入)。
    • 手性(handedness)。你用标定数据拟合出一个"旋转矩阵",或者从文件里读到一个"旋转",它的行列式却是 \(-1\)。那不是旋转,而是带镜像的变换。机器人会很听话地伸向目标的镜像位置,左手变右手,而且没有任何报错。这是机器人代码里的经典 bug。
    • 概率密度的变换。变量经过线性(或局部线性)变换后,概率密度要除以 \(|\det|\):同样多的概率被摊到了面积放大后的区域上。粒子滤波、扩展卡尔曼滤波和之后的归一化流(normalizing flow)都离不开它。

    The determinant is just one number, yet it tells you at a glance whether a matrix is "usable". Robots run into it in three places every day.

    • Singularities. An arm's Jacobian \(J\) turns joint speeds into hand speed. When \(\det J = 0\), the hand has lost a direction of motion: whatever the joints do, the hand cannot move that way. A fully stretched arm is the classic example (you will try it in Section 8; Lessons 3.3 and 3.4 go deeper).
    • Handedness. You fit a "rotation matrix" to calibration data, or load one from a file, and its determinant is \(-1\). That is not a rotation but a transformation with a mirror in it. The robot will obediently reach for the mirror image of the target, left hand becomes right hand, and no error is raised. It is a classic bug in robot code.
    • Probability densities. When a variable goes through a linear (or locally linear) change, its density must be divided by \(|\det|\): the same probability mass is spread over a region whose area has been scaled. Particle filters, the EKF, and later normalizing flows all rely on this.

    2直觉:同一个面积倍数Intuition: one area factor for everything

    回到 1.3 节的实验室。\(\ihat\) 被送到第一列,\(\jhat\) 被送到第二列,面积为 1 的单位正方形变成了一个平行四边形。这个平行四边形的面积,就是本课的主角。

    但这只是一个正方形。换成一个圆、一个三角形、一个机器人的轮廓,会怎样?想一想:把任何形状切成很多很多小方格。线性变换把网格变成平行、等距的平行四边形网格,每一个小方格都变成同样大小的平行四边形。所以每个小格子的面积都乘以同一个数,加起来,整块区域的面积也乘以这个数。

    这个数叫行列式,记作 \(\det A\)。它还带一个符号:如果变换把平面"翻了面"(像照镜子,\(\ihat\) 转到了 \(\jhat\) 的顺时针一侧),我们就记为负数。

    Back to the lab of Lesson 1.3. \(\ihat\) is sent to column one, \(\jhat\) to column two, and the unit square, of area 1, becomes a parallelogram. The area of that parallelogram is the star of this lesson.

    But that is only one square. What about a circle, a triangle, the outline of a robot? Think of any shape as cut into very many tiny squares. A linear map turns the grid into a grid of parallel, evenly spaced parallelograms, so every tiny square becomes a parallelogram of the same size. Each cell's area is multiplied by the same number, so the area of the whole region is multiplied by it too.

    That number is the determinant, written \(\det A\). It also carries a sign: if the map "flips the plane over" (like a mirror: \(\ihat\) ends up on the clockwise side of \(\jhat\)) we count it as negative.

    FIG 1三个形状,同一个倍数Three shapes, one factor
    淡色虚线是变换前,实色是变换后。右侧列出每个形状变换前后的面积(带符号)和它们的比值:方形、圆、三角形长得完全不同,比值却一模一样,都等于 \(\det A\)。选"翻面",面积变成负数;选"压扁",所有形状的面积都变成 0。 Faint dashed outlines are before, solid shapes are after. The panel lists each shape's area (signed) before and after, and their ratio: square, circle and triangle look nothing alike, yet the ratio is identical, equal to \(\det A\). Pick "flip" and the areas turn negative; pick "squash" and every area becomes 0.
    核心洞见Key insight

    行列式是矩阵作用下面积(三维里是体积)的缩放倍数,对所有形状相同。\(|\det A| > 1\) 放大,\(|\det A| < 1\) 缩小,\(\det A < 0\) 表示空间被翻了面,\(\det A = 0\) 表示空间被压到更低的维度(一条线,甚至一个点)。

    The determinant is the factor by which a matrix scales area (volume in 3D), the same for every shape. \(|\det A| > 1\) enlarges, \(|\det A| < 1\) shrinks, \(\det A < 0\) means space is flipped over, and \(\det A = 0\) means space is squashed into a lower dimension (a line, or even a point).

    3动手玩:行列式实验室Play: the determinant lab

    拖动红色 Aî 和绿色 Aĵ 的箭头尖,或者直接改矩阵里的数,或者点一个预设。图里有三样东西:单位正方形(它的像是平行四边形)、一块不规则的"轮廓",以及一个不对称的字母 F。虚线是变换前,实色是变换后。小弧线从 Aî 转向 Aĵ:逆时针说明朝向保持,顺时针说明被翻了面,这时平行四边形变紫,F 变成镜像。

    Drag the tips of the red Aî and green Aĵ arrows, edit the entries, or pick a preset. The figure holds three things: the unit square (whose image is a parallelogram), an irregular "blob", and an asymmetric letter F. Dashed outlines are before, solid shapes after. The little arc turns from Aî to Aĵ: counter-clockwise means orientation is kept, clockwise means the plane flipped, and then the parallelogram turns purple and the F is mirrored.

    FIG 2行列式实验室Determinant lab
    矩阵 A(拖动或输入)Matrix A (drag or type)
    预设Presets
    淡色网格是变换后的坐标网格:每个小格子的面积都是 \(|\det A|\)。右侧读数里,单位正方形和"轮廓"变换前后的面积比是同一个数,且带符号,等于 \(\det A\)。紫色表示 \(\det A < 0\),青色表示 \(\det A > 0\),红色表示接近 0(平面被压扁)。 The faint grid is the transformed coordinate grid: every little cell has area \(|\det A|\). In the readout, the before/after area ratio of the unit square and of the blob is one and the same number, with a sign, and it equals \(\det A\). Purple means \(\det A < 0\), cyan means \(\det A > 0\), red means near 0 (the plane is squashed).
    试一试Try this
    • 让 \(\det A = 2\)(误差 ±0.05)。不止一种做法,试试看能找到几种。Make \(\det A = 2\) (within ±0.05). There is more than one way; how many can you find?
    • 做出一个保持面积(\(\det A = 1\))但形状变了的矩阵,而且它不是旋转。提示:剪切。Build a matrix that keeps area (\(\det A = 1\)) but changes shapes, and is not a rotation. Hint: a shear.
    • 找一个非零矩阵,让 \(\det A = 0\)。单位正方形变成了什么?Find a non-zero matrix with \(\det A = 0\). What does the unit square turn into?
    • 让平面翻面(\(\det A < 0\)),但不要用纯镜像(对角线上只有 ±1 的那种)。提示:把 Aî 和 Aĵ 互换位置,看看会怎样。Make the plane flip over (\(\det A < 0\)) without a pure reflection (the kind with only ±1 on the diagonal). Hint: swap the places of Aî and Aĵ.

    小游戏:估一估面积Mini-game: estimate the area

    下面随机给一个矩阵,单位正方形被变成了平行四边形。不要算,凭眼睛估计它的 \(\det\):数一数平行四边形盖住了几个原来的方格(每格面积 1),注意颜色和 F 的方向(紫色表示负)。用滑块给出你的猜测,点"检查"。误差在 10% 以内算猜中。

    A random matrix is applied to the unit square. Do not compute: eyeball its \(\det\). Count how many of the original square cells (area 1 each) the parallelogram covers, and watch the color and the direction of the F (purple means negative). Set your guess with the slider and hit "Check". Within 10% counts as a good guess.

    FIG 3估一估面积Estimate the area
    虚线是单位正方形,实色是它的像。背景里的方格是原来的单位网格,每格面积为 1:平行四边形盖住了大约几格?这个数就是 \(|\det|\),符号看颜色和 F。青色的斜网格是变换后的格子,平行四边形本身正好是其中一格。想让游戏变简单,可以点"显示矩阵",直接用 \(ad - bc\) 算,但那样练不到眼力。 The dashed outline is the unit square and the solid shape its image. The square grid behind is the original unit grid, each cell of area 1: about how many cells does the parallelogram cover? That count is \(|\det|\); the color and the F give the sign. The slanted cyan grid is the transformed one, and the parallelogram itself is exactly one of its cells. To make the game easy, click "Show the matrix" and use \(ad - bc\), but that will not train your eye.
    • 累计猜中 3 次(误差在 10% 以内)。Get 3 good guesses (within 10%).

    4第二视角:\(ad - bc\) 从哪里来A second view: where \(ad - bc\) comes from

    二阶行列式的公式 \(\det\begin{bmatrix}a&b\\c&d\end{bmatrix} = ad - bc\) 看起来像是凭空冒出来的。其实它就是一幅小图。平行四边形的两条边是 \((a, c)\) 和 \((b, d)\):先用一个长方形把它框住,再把四周多出来的角减掉,剩下的就是它。

    按"下一步",一步步看。(图里取 \(a,b,c,d\) 全为正、\(\det > 0\);其他情形思路一样,只是要小心符号。)

    The formula \(\det\begin{bmatrix}a&b\\c&d\end{bmatrix} = ad - bc\) looks like it fell from the sky. It is really a small picture. The parallelogram has sides \((a, c)\) and \((b, d)\): enclose it in a rectangle, cut away the corners that stick out, and what remains is the parallelogram.

    Press "Next" to go step by step. (The picture takes \(a,b,c,d\) all positive and \(\det > 0\); other cases follow the same idea, with care for signs.)

    FIG 4框住它,再减去角落Box it, then cut the corners
    红色三角形的两条直角边是 \(a\) 和 \(c\),正是 Aî 的两个分量;绿色三角形的直角边是 \(b\) 和 \(d\),是 Aĵ 的分量;紫色长方形是 \(b\times c\)。拖动箭头尖换一个平行四边形,结论依然是 \(ad - bc\)(箭头被限制在四个数都为正、\(\det > 0\) 的区域内,这样图才成立)。 The red triangles have legs \(a\) and \(c\), the two components of Aî; the green triangles have legs \(b\) and \(d\), the components of Aĵ; the purple rectangles are \(b\times c\). Drag the arrow tips to get another parallelogram and the result is still \(ad - bc\) (the arrows are limited to the region where all four numbers are positive and \(\det > 0\), so that the picture is valid).
    • 走到最后一步,然后拖动一个箭头尖,确认剩下的面积始终等于 \(ad - bc\)。Go to the last step, then drag an arrow tip and check that what is left always equals \(ad - bc\).

    有符号面积:两个向量围成的平行四边形Signed area: the parallelogram spanned by two vectors

    公式里没有绝对值,所以 \(ad - bc\) 可以是负的。把两列记作 \(\mathbf u = (a, c)\)、\(\mathbf w = (b, d)\),则 \(\det[\mathbf u\ \mathbf w] = u_x w_y - u_y w_x\) 是 \(\mathbf u\) 和 \(\mathbf w\) 围成的平行四边形的有符号面积:\(\mathbf w\) 在 \(\mathbf u\) 的逆时针一侧(左边)为正,在顺时针一侧(右边)为负,两者共线时为 0。等价地,\(\det[\mathbf u\ \mathbf w] = |\mathbf u||\mathbf w|\sin\theta\),\(\theta\) 是从 \(\mathbf u\) 转到 \(\mathbf w\) 的有向夹角。这就是二维叉积;1.8 节会用它做"左转还是右转"的判断,并推广到三维。

    The formula has no absolute value, so \(ad - bc\) can be negative. Write the two columns as \(\mathbf u = (a, c)\) and \(\mathbf w = (b, d)\); then \(\det[\mathbf u\ \mathbf w] = u_x w_y - u_y w_x\) is the signed area of the parallelogram they span: positive when \(\mathbf w\) lies on the counter-clockwise side (the left) of \(\mathbf u\), negative on the clockwise side (the right), and 0 when they are collinear. Equivalently \(\det[\mathbf u\ \mathbf w] = |\mathbf u||\mathbf w|\sin\theta\), with \(\theta\) the directed angle from \(\mathbf u\) to \(\mathbf w\). This is the 2D cross product; Lesson 1.8 uses it for "left turn or right turn" tests and extends it to 3D.

    FIG 5有符号面积Signed area
    拖动 u 和 w 的箭头尖。小弧线表示从 u 转向 w 的方向。把 w 拖过 u 所在的直线,符号会翻转,经过共线的瞬间面积为 0。 Drag the tips of u and w. The little arc shows the turn from u to w. Drag w across the line through u and the sign flips, passing through area 0 at the moment they are collinear.
    • 让 u 和 w 保持足够长(都大于 0.8),但面积为 0(共线)。Make u and w collinear (area 0) while keeping both longer than 0.8.
    • 点"交换 u 与 w",观察符号怎么变。交换两列,行列式发生了什么?Press "Swap u and w" and watch the sign. What happens to the determinant when you swap two columns?

    5第三视角:复合时面积相乘A third view: areas multiply under composition

    1.4 节说过,先做 \(B\) 再做 \(A\) 就是乘积 \(AB\)。既然每个矩阵都对所有面积乘一个固定倍数,那么两步下来,面积就连续乘了两次:\(B\) 乘以 \(\det B\),\(A\) 再乘以 \(\det A\)。所以

    Lesson 1.4 said that "do \(B\), then \(A\)" is the product \(AB\). Since each matrix multiplies all areas by one fixed factor, two steps multiply twice: \(B\) by \(\det B\), then \(A\) by \(\det A\). Hence

    $$ \det(AB) \;=\; \det A \cdot \det B. $$

    拖动阶段滑块(或点"播放"),看单位正方形先被 \(B\) 变换、再被 \(A\) 变换,面积一步步变化。可以改两个矩阵,也可以点例子。

    Scrub the stage slider (or press "Play") to watch the unit square go through \(B\) and then \(A\), its area changing stage by stage. Edit either matrix, or pick an example.

    FIG 6先 B,后 A:面积相乘B first, then A: areas multiply
    ① 先做 B① B, applied first
    ② 再做 A② A, applied second
    例子Examples
    虚线紫色平行四边形是第 ① 步之后的位置,虚线方框是起点。滑块到 1 时面积等于 \(|\det B|\),到 2 时等于 \(|\det A\cdot\det B|\)。右侧最后一行同时给出直接算出的 \(\det(AB)\),两者始终一致。 The dashed purple parallelogram marks the position after step ①, the dashed square the start. At stage 1 the area is \(|\det B|\); at stage 2 it is \(|\det A\cdot\det B|\). The last readout line also gives \(\det(AB)\) computed directly, and the two always agree.
    • 让 \(A\) 和 \(B\) 各自都翻面(行列式都为负),看乘积会怎样。负负得正,翻两次又翻回来了。Make both \(A\) and \(B\) flip the plane (both determinants negative) and see what the product does. Two flips make a flip back.
    • 让 \(B\) 把平面压扁(\(\det B = 0\)),而 \(A\) 的行列式的绝对值大于 0.5。后面的 \(A\) 能把它"救回来"吗?Let \(B\) squash the plane (\(\det B = 0\)) while \(|\det A| > 0.5\). Can the \(A\) that follows "rescue" it?
    • 让 \(\det(AB) = 1\),同时 \(A\) 和 \(B\) 的行列式都不是 1(偏离 1 超过 0.4):一个放大,一个正好缩回去。Make \(\det(AB) = 1\) while neither \(\det A\) nor \(\det B\) is 1 (each off by more than 0.4): one enlarges, the other shrinks it right back.
    两个推论Two consequences

    逆矩阵:\(AA^{-1} = I\),且 \(\det I = 1\),所以 \(\det(A^{-1}) = 1/\det A\)。压扁不可逆:\(\det A = 0\) 时 \(1/\det A\) 不存在。平面被压到一条线上后,不同的点已经叠在了一起,没有任何矩阵能把它们重新分开,这是 1.6 节要讲的内容。上面的第二个任务就是这个道理:只要 \(B\) 压扁了平面,不管后面接什么,乘积的行列式永远是 0。

    Inverses: \(AA^{-1} = I\) and \(\det I = 1\), so \(\det(A^{-1}) = 1/\det A\). Squashing cannot be undone: when \(\det A = 0\), \(1/\det A\) does not exist. Once the plane is squashed onto a line, different points have landed on top of each other, and no matrix can pull them apart again; Lesson 1.6 makes this precise. The second task above shows it: once \(B\) squashes the plane, whatever follows, the product's determinant stays 0.

    6三维:体积与手性In 3D: volume and handedness

    一切照搬到三维:\(3\times3\) 矩阵把单位立方体变成一个平行六面体(parallelepiped),它的体积就是 \(|\det A|\),三条棱是 \(A\) 的三列。符号讲的是手性:右手系的三根轴 \((\ihat, \jhat, \khat)\) 被送到 \((A\ihat, A\jhat, A\khat)\) 后,如果仍然满足右手定则(右手四指从 \(A\ihat\) 弯向 \(A\jhat\),拇指指向 \(A\khat\) 一侧),则 \(\det A > 0\);如果变成了左手系,则 \(\det A < 0\)。\(\det A = 0\) 时立方体被压成一块平板、一条线,甚至一个点。

    选一个预设或编辑矩阵,拖动画面转动视角。

    Everything carries over to 3D: a \(3\times3\) matrix turns the unit cube into a parallelepiped whose volume is \(|\det A|\) and whose three edges are the columns of \(A\). The sign is about handedness: the right-handed axes \((\ihat, \jhat, \khat)\) are sent to \((A\ihat, A\jhat, A\khat)\); if these still obey the right-hand rule (curl the fingers of your right hand from \(A\ihat\) toward \(A\jhat\) and your thumb points to the side of \(A\khat\)) then \(\det A > 0\); if the frame has become left-handed, \(\det A < 0\). When \(\det A = 0\) the cube is crushed into a slab, a line, or even a point.

    Pick a preset or edit the matrix, and drag the view to orbit.

    FIG 7单位立方体 → 平行六面体Unit cube → parallelepiped
    矩阵 A(3×3)Matrix A (3×3)
    预设Presets
    虚线是原来的单位立方体,红、绿、蓝箭头是 \(A\ihat, A\jhat, A\khat\),也就是新坐标系的三根轴。青色表示右手系(\(\det > 0\)),紫色表示左手系(\(\det < 0\)),红色表示被压扁(\(\det \approx 0\))。体积等于三列的混合积 \(\mathbf a\cdot(\mathbf b\times\mathbf c)\),1.8 节会讲。 The dashed cube is the original unit cube; the red, green and blue arrows are \(A\ihat, A\jhat, A\khat\), the three axes of the new frame. Cyan means a right-handed frame (\(\det > 0\)), purple a left-handed one (\(\det < 0\)), red a crushed cube (\(\det \approx 0\)). The volume is the triple product \(\mathbf a\cdot(\mathbf b\times\mathbf c)\) of the columns, which Lesson 1.8 covers.
    • 让右手系变成左手系:右上角的标签变成"左手系"。提示:交换两列。Turn the right-handed frame into a left-handed one: the label in the corner changes. Hint: swap two columns.
    • 让立方体塌成一个平面(\(\det \approx 0\),矩阵非零)。三列之间是什么关系?Make the cube collapse into a plane (\(\det \approx 0\), matrix non-zero). How are the three columns related?

    7再看数学The math

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

    用三条性质定义Definition by three properties

    行列式是方阵的一个数,把方阵看成 \(n\) 个列向量 \([\mathbf a_1\ \cdots\ \mathbf a_n]\),它由三条性质唯一确定:

    The determinant is a number attached to a square matrix, viewed as \(n\) column vectors \([\mathbf a_1\ \cdots\ \mathbf a_n]\). Three properties pin it down uniquely:

    1. 单位不变:\(\det I = 1\)。单位正方形(立方体)体积为 1。
    2. Normalized: \(\det I = 1\). The unit square (cube) has volume 1.
    3. 对每一列线性:把某一列放大 \(s\) 倍,行列式放大 \(s\) 倍;\(\det[\mathbf u+\mathbf u',\ \mathbf w] = \det[\mathbf u,\ \mathbf w] + \det[\mathbf u',\ \mathbf w]\)。几何上:拉长一条边,面积同比例变化。
    4. Linear in each column: scaling one column by \(s\) scales the determinant by \(s\), and \(\det[\mathbf u+\mathbf u',\ \mathbf w] = \det[\mathbf u,\ \mathbf w] + \det[\mathbf u',\ \mathbf w]\). Geometrically: stretching one edge changes the area in proportion.
    5. 交替:交换两列,行列式变号。于是两列相同时行列式为 0(与自己交换,结果既不变又变号,只能是 0)。结合第 2 条还能推出:把一列加上另一列的倍数(剪切)不改变行列式,因为 \(\det[\mathbf u + s\mathbf w,\ \mathbf w] = \det[\mathbf u,\ \mathbf w] + s\det[\mathbf w,\ \mathbf w] = \det[\mathbf u,\ \mathbf w]\)。
    6. Alternating: swapping two columns flips the sign. So two equal columns give 0 (swapping them changes nothing and flips the sign, so the value must be 0). Together with property 2 this shows that adding a multiple of one column to another (a shear) leaves the determinant unchanged: \(\det[\mathbf u + s\mathbf w,\ \mathbf w] = \det[\mathbf u,\ \mathbf w] + s\det[\mathbf w,\ \mathbf w] = \det[\mathbf u,\ \mathbf w]\).

    二阶与三阶公式The 2×2 and 3×3 formulas

    几何定义:\(S\) 取任意形状,面积比都是同一个数。二阶的具体公式是 \(ad-bc\)(第 4 节已经看到它从哪来):

    The geometric definition: for any shape \(S\), the area ratio is one and the same number. For 2×2 the explicit formula is \(ad-bc\) (Section 4 showed where it comes from):

    $$ \hl{det}{\det A} \;=\; \det\begin{bmatrix} \hl{a1}{\ci{\mathbf a_1}} & \hl{a2}{\cj{\mathbf a_2}} \end{bmatrix} \;=\; \frac{\hl{ratio}{\text{area}(A\,S)}}{\text{area}(S)}, \qquad \det\begin{bmatrix}\ci{a} & \cj{b}\\ \ci{c} & \cj{d}\end{bmatrix} = \ci{a}\cj{d} - \cj{b}\ci{c}. $$

    三阶可以沿第一行做余子式展开(cofactor expansion),符号按 \(+,-,+\) 交替:

    For 3×3, expand along the first row (cofactor expansion), with alternating signs \(+,-,+\):

    $$ \det A = a_{11}\begin{vmatrix}a_{22}&a_{23}\\a_{32}&a_{33}\end{vmatrix} - a_{12}\begin{vmatrix}a_{21}&a_{23}\\a_{31}&a_{33}\end{vmatrix} + a_{13}\begin{vmatrix}a_{21}&a_{22}\\a_{31}&a_{32}\end{vmatrix} \;=\; \mathbf a\cdot(\mathbf b\times\mathbf c). $$

    最右边是三列 \(\mathbf a, \mathbf b, \mathbf c\) 的混合积(triple product,1.8 节),它给出平行六面体的有符号体积。算一个例子:\(A = \begin{bmatrix}2&0&1\\1&3&2\\0&1&1\end{bmatrix}\),展开得 \(2(3\cdot1-2\cdot1) - 0 + 1(1\cdot1-3\cdot0) = 2 + 1 = 3\)。用混合积核对:三列是 \(\mathbf a=(2,1,0)\)、\(\mathbf b=(0,3,1)\)、\(\mathbf c=(1,2,1)\),\(\mathbf b\times\mathbf c = (1,1,-3)\),\(\mathbf a\cdot(1,1,-3) = 2+1+0 = 3\)。一致。

    The right-hand side is the triple product of the columns \(\mathbf a, \mathbf b, \mathbf c\) (Lesson 1.8), the signed volume of the parallelepiped. An example: \(A = \begin{bmatrix}2&0&1\\1&3&2\\0&1&1\end{bmatrix}\) expands to \(2(3\cdot1-2\cdot1) - 0 + 1(1\cdot1-3\cdot0) = 2 + 1 = 3\). Check with the triple product: the columns are \(\mathbf a=(2,1,0)\), \(\mathbf b=(0,3,1)\), \(\mathbf c=(1,2,1)\); \(\mathbf b\times\mathbf c = (1,1,-3)\) and \(\mathbf a\cdot(1,1,-3) = 2+1+0 = 3\). They agree.

    常用性质Properties you will use

    性质Property几何含义Geometric meaning
    \(\det(AB) = \det A\,\det B\)先后两次变换,面积倍数相乘(FIG 6)two maps in a row: area factors multiply (FIG 6)
    \(\det A^{\top} = \det A\)用行围成的平行四边形,面积与用列围成的相同the parallelogram spanned by the rows has the same area as the one spanned by the columns
    \(\det(cA) = c^{n}\det A\)每个方向都放大 \(c\) 倍,\(n\) 维体积放大 \(c^n\)(二维面积放大 \(c^2\),不是 \(c\))scaling every direction by \(c\) scales an \(n\)-dimensional volume by \(c^n\) (area by \(c^2\) in 2D, not \(c\))
    \(\det A^{-1} = 1/\det A\)逆变换把面积倍数倒过来the inverse map undoes the area factor
    \(\det A = 0 \iff\) 列线性相关 \(\iff A\) 不可逆columns dependent \(\iff A\) not invertible平行四边形(六面体)塌了;压扁的空间无法复原(1.6 节)the parallelogram (box) collapses; a squashed space cannot be restored (Lesson 1.6)
    三角矩阵:对角元之积triangular matrix: product of the diagonal这也是用 LU 分解算行列式的原理the reason determinants are computed from an LU factorization
    旋转 \(\det R = +1\),镜像 \(\det = -1\)rotation \(\det R = +1\), reflection \(\det = -1\)旋转不改变面积和朝向;镜像不改变面积,但翻面(1.10 节)a rotation keeps area and orientation; a reflection keeps area but flips orientation (Lesson 1.10)
    实际怎么算How it is computed in practice

    教科书里的余子式展开要做约 \(n!\) 次乘法,\(n=20\) 就已经不可能。数值库(NumPy、Eigen、LAPACK)先做 LU 分解 \(PA = LU\),行列式就是 \(U\) 对角线之积乘以置换的符号,代价约 \(n^3\)。矩阵稍大时行列式很容易上溢或下溢(\(100\times100\) 的 \(0.1I\) 的行列式是 \(10^{-100}\)),所以常算它的对数 np.linalg.slogdet。

    The cofactor expansion in textbooks takes about \(n!\) multiplications, hopeless already at \(n=20\). Numerical libraries (NumPy, Eigen, LAPACK) do an LU factorization \(PA = LU\); the determinant is then the product of \(U\)'s diagonal times the sign of the permutation, at a cost of about \(n^3\). Determinants of larger matrices overflow or underflow easily (\(0.1I\) at \(100\times100\) has determinant \(10^{-100}\)), so people often compute the logarithm instead, np.linalg.slogdet.

    8机器人中的它:奇异位形与手性检查In robotics: singularities and handedness checks

    两连杆机械臂:行列式何时为零A two-link arm: when does the determinant vanish?

    把雅可比 \(J\) 当成"把关节速度变成手端速度的矩阵":\(\dot{\mathbf x} = J\dot{\mathbf q}\)(它怎么来的是 3.3、3.4 节的内容)。\(J\) 的第 1 列是只转关节 1 时手端的速度,第 2 列是只转关节 2 时的速度。两个关节速度都在 \([0,1]\) 内时,手端的速度就落在 \(J\) 的两列围成的速度平行四边形里,它的面积是 \(|\det J|\)。对平面两连杆臂(杆长 \(\ell_1,\ell_2\)),

    Treat the Jacobian \(J\) as "the matrix that turns joint speeds into hand speed": \(\dot{\mathbf x} = J\dot{\mathbf q}\) (where it comes from is Lessons 3.3 and 3.4). Column 1 of \(J\) is the hand velocity when only joint 1 turns, column 2 when only joint 2 turns. For joint speeds in \([0,1]\), the hand velocity falls in the velocity parallelogram spanned by the two columns, with area \(|\det J|\). For a planar two-link arm (link lengths \(\ell_1,\ell_2\)),

    $$ J = \begin{bmatrix} \ci{-\ell_1 s_1 - \ell_2 s_{12}} & \cj{-\ell_2 s_{12}} \\ \ci{\ell_1 c_1 + \ell_2 c_{12}} & \cj{\ell_2 c_{12}} \end{bmatrix}, \qquad \det J = \ell_1\ell_2\,\sin\theta_2 . $$

    (\(s_1=\sin\theta_1\),\(c_{12}=\cos(\theta_1+\theta_2)\),依此类推。)注意 \(\det J\) 只和肘关节角 \(\theta_2\) 有关,与肩关节角 \(\theta_1\) 无关:手臂整体转一个角度,只是把速度平行四边形整个转一下,面积不变。\(\theta_2 = 0\)(手臂完全伸直)或 \(\theta_2 = \pm\pi\)(完全折叠)时 \(\det J = 0\),两列平行,平行四边形塌成线段:手端不能沿手臂方向运动。\(\theta_2\) 的符号决定 \(\det J\) 的符号:肘朝两侧弯,是两种"手性"不同的位形。

    拖动肘部(圆圈)或手端,或者用滑块。右侧小图画出 \(\det J\) 随 \(\theta_2\) 的变化。

    (\(s_1=\sin\theta_1\), \(c_{12}=\cos(\theta_1+\theta_2)\), and so on.) Note that \(\det J\) depends only on the elbow angle \(\theta_2\), not on the shoulder angle \(\theta_1\): swinging the whole arm just rotates the velocity parallelogram, area unchanged. At \(\theta_2 = 0\) (arm fully stretched) or \(\theta_2 = \pm\pi\) (fully folded), \(\det J = 0\): the columns are parallel and the parallelogram collapses to a segment, so the hand cannot move along the arm. The sign of \(\theta_2\) sets the sign of \(\det J\): an elbow bent to either side gives two configurations of opposite "handedness".

    Drag the elbow (circle) or the hand, or use the sliders. The small plot shows \(\det J\) against \(\theta_2\).

    FIG 8速度平行四边形与 \(\det J\)The velocity parallelogram and \(\det J\)
    杆长 \(\ell_1 = 1.2\),\(\ell_2 = 1.0\)。手端处的红、绿箭头是 \(J\) 的两列(缩小到 0.6 倍),它们围成的平行四边形是"单位关节速度"能产生的手端速度范围;\(\det J > 0\) 时青色,\(< 0\) 时紫色,接近 0 时红色。右侧曲线是 \(\ell_1\ell_2\sin\theta_2\),圆点是当前位形,红点标出奇异位形 \(\theta_2 = 0\) 和 \(\theta_2 = \pm\pi\)(\(-\pi\) 与 \(\pi\) 是同一个姿态)。 Link lengths \(\ell_1 = 1.2\), \(\ell_2 = 1.0\). The red and green arrows at the hand are the columns of \(J\) (drawn at 0.6 scale); the parallelogram they span is the range of hand velocities that unit joint speeds can produce, cyan when \(\det J > 0\), purple when \(< 0\), red near 0. The curve on the right is \(\ell_1\ell_2\sin\theta_2\); the dot marks the current pose and the red dots mark the singular poses \(\theta_2 = 0\) and \(\theta_2 = \pm\pi\) (\(-\pi\) and \(\pi\) are the same pose).
    • 把机械臂带到奇异位形(\(|\det J| < 0.07\))。平行四边形变成了什么?手端被"锁"住了哪个方向?Bring the arm to a singular pose (\(|\det J| < 0.07\)). What does the parallelogram become? Which direction of motion is "locked"?
    • 让 \(\det J\) 分别取到一次明显为正、一次明显为负(绝对值大于 0.3)。你是怎么过去的?必须经过什么?Make \(\det J\) clearly positive once and clearly negative once (magnitude above 0.3). How did you get from one to the other? What did you have to pass through?
    真实系统里:手性检查In real systems: handedness checks

    凡是"估计出来"或"从文件里读出来"的旋转矩阵,都应该检查 assert abs(np.linalg.det(R) - 1) < 1e-6(同时 \(R^\top R = I\),1.10 节)。常见的出错来源:(1) 基于 SVD 的位姿拟合(如 Kabsch / Umeyama 算法)在点几乎共面或噪声较大时,可能返回 \(\det R = -1\) 的"最佳正交矩阵",必须修正符号:\(R = V\,\mathrm{diag}(1,1,\operatorname{sign}\det(VU^\top))\,U^\top\)(SVD 见 1.12 节);(2) 左手系与右手系之间的转换:Unity 用左手系,ROS 用右手系,从一个引擎搬位姿到另一个,要做一次镜像,漏掉就是镜像世界;(3) 图像坐标 \(y\) 轴朝下,相机内参和坐标轴的约定一旦写错一个符号,也会让整个场景左右翻转。

    Any rotation matrix that is "estimated" or "loaded from a file" deserves a check: assert abs(np.linalg.det(R) - 1) < 1e-6 (together with \(R^\top R = I\), Lesson 1.10). Typical culprits: (1) SVD-based pose fitting (Kabsch / Umeyama) can return the "best orthogonal matrix" with \(\det R = -1\) when the points are nearly coplanar or noisy, and needs a sign fix: \(R = V\,\mathrm{diag}(1,1,\operatorname{sign}\det(VU^\top))\,U^\top\) (SVD is Lesson 1.12); (2) converting between left- and right-handed conventions: Unity is left-handed, ROS right-handed, so moving a pose from one to the other needs a mirror, and forgetting it gives a mirror world; (3) image coordinates have \(y\) pointing down, so one wrong sign in a camera or axis convention flips the whole scene left to right.

    9常见误区Common pitfalls

    误区 1:行列式小,就说明矩阵"快要奇异"Pitfall 1: a small determinant means "nearly singular"

    不对。\(\det(0.1\,I_3) = 0.1^3 = 0.001\),可这个矩阵是均匀缩小,处处表现良好,求逆一点问题也没有。行列式把"整体尺度"和"有多扁"混在了一起。衡量"快要奇异"要用与尺度无关的量:奇异值之比,即条件数(1.12 节)。反过来也成立:\(\operatorname{diag}(10^6, 10^{-6})\) 的行列式是 1,却极其病态。

    No. \(\det(0.1\,I_3) = 0.1^3 = 0.001\), yet this matrix is a uniform shrink, perfectly well-behaved, and inverting it is no trouble. The determinant mixes up "overall scale" with "how flat". The scale-free measure of "nearly singular" is the ratio of singular values, the condition number (Lesson 1.12). The converse also holds: \(\operatorname{diag}(10^6, 10^{-6})\) has determinant 1 and is terribly ill-conditioned.

    误区 2:\(\det(A+B) = \det A + \det B\)Pitfall 2: \(\det(A+B) = \det A + \det B\)

    不成立。行列式对乘积友好(\(\det AB = \det A\det B\)),对和不友好。反例:\(A = I\),\(B = -I\)(二维)。\(\det A = \det B = 1\),可 \(A + B = 0\),\(\det(A+B) = 0 \ne 2\)。同理 \(\det(cA) = c^n\det A\),而不是 \(c\det A\)。

    False. The determinant is friendly to products (\(\det AB = \det A\det B\)) and unfriendly to sums. Counterexample in 2D: \(A = I\), \(B = -I\). \(\det A = \det B = 1\), but \(A + B = 0\) and \(\det(A+B) = 0 \ne 2\). Likewise \(\det(cA) = c^n\det A\), not \(c\det A\).

    误区 3:任何矩阵都有行列式Pitfall 3: every matrix has a determinant

    只有方阵才有。\(3\times2\) 的矩阵把平面送进三维空间,\(ad-bc\) 这类公式根本写不出来,"翻面"也没有意义(在三维里平面可以随意翻转)。它的面积缩放倍数依然存在,等于 \(\sqrt{\det(A^\top A)}\)(所有奇异值之积),但永远非负。机械臂的雅可比如果不是方阵(冗余臂),\(\det J\) 没有意义,该用奇异值或 Yoshikawa 可操作度 \(\sqrt{\det(JJ^\top)}\)(1.12 节)。

    Only square matrices do. A \(3\times2\) matrix sends the plane into 3D; there is no \(ad-bc\)-style formula, and "flipped over" loses its meaning (inside 3D a plane can simply be turned over). Its area scaling factor still exists, \(\sqrt{\det(A^\top A)}\) (the product of all singular values), but it is never negative. If an arm's Jacobian is not square (a redundant arm), \(\det J\) is meaningless; use the singular values, or Yoshikawa's manipulability \(\sqrt{\det(JJ^\top)}\) (Lesson 1.12).

    误区 4:行列式告诉你变换的"样子"Pitfall 4: the determinant tells you what the map looks like

    它只告诉你面积倍数,不告诉你形状怎么变。单位矩阵、旋转、剪切 \(\begin{bmatrix}1&1\\0&1\end{bmatrix}\) 的行列式全是 1,形状却天差地别(FIG 2 的第二个任务)。要知道"拉伸了多少、朝哪个方向",要看奇异值(1.12 节)和特征值(1.11 节)。

    It tells you the area factor and nothing about how the shape changes. The identity, a rotation and the shear \(\begin{bmatrix}1&1\\0&1\end{bmatrix}\) all have determinant 1, yet they do very different things (the second task of FIG 2). To know "how much stretch, in which directions", look at singular values (Lesson 1.12) and eigenvalues (Lesson 1.11).

    误区 5:用余子式展开去算大矩阵的行列式Pitfall 5: computing big determinants by cofactor expansion

    展开公式适合手算 \(2\times2\)、\(3\times3\)。它的运算量按 \(n!\) 增长:\(10\times10\) 要三百多万次乘法,\(20\times20\) 要 \(10^{18}\) 次以上。代码里用 LU 分解(\(n^3\)),并且尽量不要判断 "det == 0" 来决定能否求逆:浮点数里几乎永远不会恰好等于 0,该看条件数或最小奇异值。

    The expansion formula is for pencil-and-paper \(2\times2\) and \(3\times3\). Its cost grows like \(n!\): over three million multiplications at \(10\times10\), over \(10^{18}\) at \(20\times20\). In code, use an LU factorization (\(n^3\)), and avoid testing "det == 0" to decide whether a matrix is invertible: in floating point it is almost never exactly 0. Look at the condition number or the smallest singular value instead.

    10小练习Check yourself

    1. \(A = \begin{bmatrix}2&1\\1&3\end{bmatrix}\)。一块面积为 3 的区域经过 \(A\) 变换后,面积是多少?1. Let \(A = \begin{bmatrix}2&1\\1&3\end{bmatrix}\). A region of area 3 goes through \(A\). What is its new area?
    \(\det A = 2\cdot3 - 1\cdot1 = 5\),任何形状的面积都乘以 5:\(3\times5 = 15\)。(5 是倍数本身,不是新面积;21 把行列式算成了 \(2\cdot3+1\cdot1 = 7\)。)\(\det A = 2\cdot3 - 1\cdot1 = 5\) and every shape's area is multiplied by 5: \(3\times5 = 15\). (5 is the factor itself, not the new area; 21 comes from computing the determinant as \(2\cdot3+1\cdot1 = 7\).)
    2. 标定程序输出 \(R = \begin{bmatrix}0&1&0\\1&0&0\\0&0&1\end{bmatrix}\),三列长度都是 1、两两垂直,但 \(\det R = -1\)。这说明什么?2. A calibration routine outputs \(R = \begin{bmatrix}0&1&0\\1&0&0\\0&0&1\end{bmatrix}\); the columns have unit length and are mutually perpendicular, yet \(\det R = -1\). What does it mean?
    正交归一的列保证长度和夹角不变,\(|\det| = 1\);符号才决定是旋转(+1)还是带镜像(−1)。这个矩阵交换了 x 和 y,是关于平面 \(x = y\) 的镜像。绕 z 转 180° 的矩阵是 \(\operatorname{diag}(-1,-1,1)\),行列式 \(+1\)。它显然可逆(\(|\det| = 1 \ne 0\)),所以"不可逆"不对。Orthonormal columns guarantee that lengths and angles are preserved, \(|\det| = 1\); the sign decides rotation (+1) versus mirror (−1). This matrix swaps x and y: a reflection across the plane \(x = y\). A 180° turn about z is \(\operatorname{diag}(-1,-1,1)\), with determinant \(+1\). The matrix is clearly invertible (\(|\det| = 1 \ne 0\)), so "not invertible" is wrong.
    3. 已知 \(\det A = 2\),\(\det B = -3\)。\(\det(A^{-1}B^2)\) 是多少?3. Given \(\det A = 2\) and \(\det B = -3\), what is \(\det(A^{-1}B^2)\)?
    \(\det(A^{-1}B^2) = \det(A^{-1})\,(\det B)^2 = \tfrac12\cdot9 = 4.5\)。\(B\) 用了两次,翻面两次又翻回来,所以符号为正。\(\det(A^{-1}B^2) = \det(A^{-1})\,(\det B)^2 = \tfrac12\cdot9 = 4.5\). \(B\) is applied twice; flipping twice flips back, so the sign is positive.
    4. \(A = 0.1\,I_3\) 的行列式是 0.001。怎样理解?4. \(A = 0.1\,I_3\) has determinant 0.001. How should you read that?
    \(\det(cA) = c^n\det A\),所以 \(0.1^3 = 0.001\) 只反映整体尺度。\(A^{-1} = 10\,I\) 很规矩,条件数(最大奇异值比最小奇异值)是 1。体积被缩小到千分之一,不是放大。判断"快要奇异"要看奇异值之比,不是行列式的大小。\(\det(cA) = c^n\det A\), so \(0.1^3 = 0.001\) only reflects the overall scale. \(A^{-1} = 10\,I\) is perfectly tame and the condition number (largest over smallest singular value) is 1. Volumes are shrunk to a thousandth, not enlarged. "Nearly singular" is judged by the ratio of singular values, not by the size of the determinant.
    5. 两连杆臂,\(\ell_1 = 0.4\ \text{m}\),\(\ell_2 = 0.3\ \text{m}\),肘关节角 \(\theta_2 = -30°\)。\(\det J\) 是多少?5. A two-link arm has \(\ell_1 = 0.4\ \text{m}\), \(\ell_2 = 0.3\ \text{m}\) and elbow angle \(\theta_2 = -30°\). What is \(\det J\)?
    \(\det J = \ell_1\ell_2\sin\theta_2 = 0.4\times0.3\times\sin(-30°) = 0.12\times(-0.5) = -0.06\)。肘朝另一侧弯,符号为负;\(-0.12\) 忘了乘 \(\sin\theta_2\);\(-0.104\) 错用了 \(\cos 30°\)。|\(\det J\)| 与 \(\theta_1\) 无关。\(\det J = \ell_1\ell_2\sin\theta_2 = 0.4\times0.3\times\sin(-30°) = 0.12\times(-0.5) = -0.06\). With the elbow bent the other way the sign is negative; \(-0.12\) forgets the factor \(\sin\theta_2\); \(-0.104\) used \(\cos 30°\) by mistake. \(\det J\) does not depend on \(\theta_1\).

    11延伸阅读Further reading

    • 3Blue1Brown, Essence of Linear Algebra — 第 6 章 "The determinant"(行列式)Ch. 6, "The determinant"
    • G. Strang, Introduction to Linear Algebra, Ch. 5 — 行列式(性质、余子式、体积)Determinants (properties, cofactors, volumes)
    • K. Lynch & F. Park, Modern Robotics, §5.3 — 奇异位形分析Singularity analysis
    • J. Ström et al., Immersive Linear Algebra — 行列式一章,带可拖动的交互插图the chapter on determinants, with draggable interactive figures