翻译 Yingjia 校对 ZSC 时间轴 ahuoguo
Jerry: 天哪，你真是疯了！
Kramer: 真的吗？或者也许，我是理智的，而你的脑子已经乱得快爆炸了？
Jerry: 这不可能！
Kramer: 哦真的吗？或者也许是你晕乎乎得正像陀螺一样旋转呢？
在之前的视频 我们曾讨论过线性方程组 In a previous video, I've talked about linear systems of equations,
我刻意没有提及它们实际的解法 and I sort of brushed aside the discussion of actually computing solutions to these systems.
虽然这些单纯的数字计算完全可以留给计算机完成 And while it's true that number-crunching is something we typically leave to the computers,
但是 深入了解这些计算方法是一个很好的途径 digging into some of these computational methods is a good litmus test
来检验你是否透彻理解了具体的细节 for whether or not you actually understand what's going on,
因为这连接着理论和实际 since this is really where the rubber meets the road.
今天要说的 是其中一个计算法则背后的几何原理 Here I want to describe the geometry behind a certain method for computing solutions to these systems,
这个方法叫克莱姆法则 known as Cramer's rule.
这期视频需要的背景知识有 The relevant background needed here is an understanding of
行列式 点积 线性方程组等 determinants, dot products, and of linear systems of equations,
如果你对这些概念有些模糊 请看我之前的系列视频 so be sure to watch the relevant videos on those topics if you're unfamiliar or rusty.
但是 我得先说清 But first! I should say up front that
克莱姆法则并不是计算线性方程组最好的方法 Cramer's rule is not the best way for computing solutions to linear systems of equations.
比如高斯消元法 会算得更快 Gaussian elimination, for example, will always be faster.
所以为什么要学习克莱姆法则呢 So why learn it?
不妨当作是扩展视野 Think of this as a sort of cultural excursion;
它会帮你加深对线性方程组的理解 it's a helpful exercise in deepening your knowledge of the theory of these systems.
当你不断思考这些概念时 会巩固你的线性代数知识 Wrapping your mind around this concept will help consolidate ideas from linear algebra,
比如行列式和线性方程组 你会发现它们非常相关 like the determinant and linear systems, by seeing how they relate to each other.
而从纯美学角度来说 它的最终结果很值得欣赏和思考 Also, from a purely artistic standpoint, the ultimate result is just really pretty to think about,
这是高斯消元法不具备的 way more so that Gaussian elimination.
好 那么我们从一些线性方程组讲起 Alright, so the setup here will be some linear system of equations,
这里有x和y两个未知数 和两个方程式 say with two unknowns, x and y, and two equations.
原则上 只要未知数和方程的个数一样 In principle, everything we're talking about will work systems with a larger number of unknowns,
我们所说的都适用 and the same number of equations.
但为了简化理解 这个小例子会更容易思考 But for simplicity, a smaller example is nicer to hold in our heads.
就像之前一个视频里说的那样 So as I talked about in a previous video,
可以把这个方程组看作对[x;y]向量的一个已知的矩阵变换 you can think of this setup geometrically as a certain known matrix transforming an unknown vector, [x; y],
而且变换后的结果已知 在这里是[-4;-2] where you know what the output is going to be, in this case [-4; -2].
注意 矩阵的列向量反映了矩阵是如何变换的 Remember, the columns of this matrix are telling you how the matrix acts as a transform,
分别告诉你基向量变换后的位置 each one telling you where the basis vectors of the input space land.
所以问题变成了 什么样的输入向量[x;y] 在变换后会成为[-4;-2] So what we have is a sort of puzzle, what input [x; y], is going to land on this output [-4; -2]?
一种思路是 我们已知的向量 One way to think about our puzzle is that we know the given output vector
是矩阵列向量的一个线性组合 is some linear combination of the columns of the matrix;
x乘以基向量i 加上 y乘以基向量j x*(the vector where i-hat lands) + y*(the vector where j-hat lands),
但我们希望能准确地计算出x与y的值 but we want is to figure out what exactly that linear combination should be
注意 这里的结果取决于矩阵变换是否降维 /*超行*/Remember, the type of answer you get here can depend on whether or not the transformation squishes all of space into a lower dimension.
也就是说矩阵的行列式为零 That is if it has zero determinant.
在这种情况下 要么任何输入向量都不会变换到给定的输出向量 In that case, either none of the inputs land on our given output
要么有无数个向量都会变换到给定的向量 or there are a whole bunch of inputs landing on that output.
但在这个视频里 我们将只讨论非零行列式的情况 But for this video we'll limit our view to the case of a non-zero determinant,
意味着线性变换后维数依然相同 meaning the outputs of this transformation still span the full n-dimensional space it started in;
每一个输入向量有且仅有一个输出向量 every input lands on one and only one output
且每一个输出向量也仅对应一个输入向量 and every output has one and only one input.
我们先来看一个错误的例子 但是它的大方向是对的 As a first pass, let me show an idea that is wrong, but in the right direction.
这个未知输入向量的x坐标 The x-coordinate of this mystery input vector is what you get
等于它与第一个基向量[1;0]的点积 by taking its dot product with the first basis vector, [1; 0].
同样 它的y坐标是与第二个基向量[0; 1]的点积 Likewise, the y-coordinate is what you get by dotting it with the second basis vector, [0; 1].
所以也许你希望在矩阵变换后 So maybe you hope that after the transformation,
变换后的未知向量 与变换后的两个基向量 的点积 the dot products with the transformed version of the mystery vector with the transformed versions of the basis vectors
也等于原来的x和y坐标 will also be these coordinates x and y.
那样就太完美了 因为这3个变换后的向量都是已知的 That'd be fantastic because we know what the transformed versions of each of these vectors are.
好了只剩一个问题 这个假设是不成立的 There's just one problem with this: it's not at all true!
对大多数线性变换来说 点积会随着变换而改变 For most linear transformations, the dot product before and after the transformation will be very different.
比如说 有两个向量大致指向同一个方向 点积为正 For example, you could have two vectors generally pointing in the same direction, with a positive dot product,
在变换后被拉远 which get pulled apart from each other during the transformation,
像这样它们的点积就变成负数了 in such a way that they end up having a negative dot product.
类似的 就算两向量相互垂直 点积为零 比如两个基向量 Likewise, things that start off perpendicular, with dot product zero, like the two basis vectors,
我们也无法保证它们在变换后依然相互垂直 there's no guarantee that they will stay perpendicular after the transformation,
点积依然为零 that is they don't preserve that zero dot product.
在这些例子中 点积并不是一定是不变的 Looking at the example I just show, dot products certainly aren't preserved.
而可能会变大 因为大部分向量被拉伸 They tend to get bigger since most vectors are getting stretched out.
事实上 那些不改变点积的矩阵变换 In fact, worthwhile sidenote here, transformations which do preserve dot products
有一个特殊的名字 正交变换 are special enough to have their own name: Orthonormal transformations.
它们使基向量在变换后依然保持单位长度 且相互垂直 These are the ones which leave all the basis vectors perpendicular to each other and still with unit lengths.
可以想成是旋转矩阵 You often think of these as rotation matrices.
相当于作刚体运动 没有拉伸 压缩或变形 The correspond to rigid motion, with no stretching, squishing or morphing.
用正交矩阵来求解线性系统非常简单 Solving a linear system with an orthonormal matrix is actually super easy:
因为点积保持不变 Because dot products are preserved,
所以已知的输出向量和矩阵的列向量的点积 taking the dot product between the output vector and all the columns of your matrix
分别等同于未知输入向量和各个基向量的点积 will be the same as taking the dot products between the mystery input vector and all the basis vectors,
也就是输入向量的每一个坐标 which is the same as just finding the coordinates of that mystery input.
因此 在特殊情况下 x等于第一列向量已知向量的点积 So, in that very special case, x would be the dot product of the first column with the output vector,
y等于第二列向量与已知向量的点积 and y would be the dot product of the second column with the output vector.
虽然这个思路对大多数线性方程组都不成立 why am I bringing this up when this idea breaks down for almost all linear systems,
但它给了我们一个方向去思考 well, it points us in the direction of something to look for:
有没有另一种对输入向量坐标值的几何解释 Is there an alternate geometric understanding for the coordinates of our input vector
能在矩阵变换后保持不变呢 that remains unchanged after the transformation?
如果你非常熟悉行列式 你可能会想到一个很棒的想法 If your mind has been mulling over determinants, you might think of the following clever idea:
这个由第一个基向量 i 和未知的输入向量 [x;y] 组成的平行四边形 Take the parallelogram defined by the first basis vector, i-hat, and the mystery input vector [x; y].
面积是 长度为1的底 乘上与底边垂直的高 The area of this parallelogram is its base, 1, times the height perpendicular to that base,
也就是输入向量的y坐标值 which is the y-coordinate of that input vector.
因此 我们拐了一个弯 用这个平行四边形的面积来表示y值 So, the area of that parallelogram is sort of a screwy roundabout way to describe the vector's y-coordinate;
这样讨论坐标轴有些奇怪 但请继续跟着我的思路 it's a wacky way to talk about coordinates, but run with me.
更准确地来说 你应该考虑这个平行四边形的有向面积 And actually, to be a little more accurate, you should think of this as the signed area of that parallelogram,
我们在行列式的视频中曾讨论过 in the sense described by the determinant video.
如果向量的y坐标为负 则四边形面积也为负 That way, a vector with negative y-coordinate would correspond to a negative area for this parallelogram.
前提是你把基向量i放在第一位来定义平行四边形 at least if you think of i-hat as in some sense being the first out of these two vectors defining the parallelogram.
同样 观察由未知的输入向量 And symmetrically, if you look at the parallelogram spanned by our mystery input vector
和第二基向量j组成的平行四边形 and the second basis vector, j-hat,
它的面积等于向量的x坐标 its area is gonna be the x-coordinate of that mystery vector.
确实 用这种方式来表示x的值也有点奇怪 Again, it's a strange way to represent the x-coordinate,
但过一会你就会知道我们为什么要讨论它了 but you'll see what it buys us in a moment.
举一反三 我们来看看三维的情况 and just make sure it's clear how this might generalize, let's look in three dimensions
可能你的第一反应是 向量在z轴上的坐标值 Ordinarily the way you might think of one of a vector's coordinate, say its z-coordinate,
是它与第三个基向量k的点积 would be to take its dot product with the third standard basis vector, often called k-hat.
但更好的办法是 But an alternate geometric interpretation would be
考虑向量与另外两个基向量i和j所组成的平行六面体 to consider the parallelepiped it creates with the other two basis vectors, i-hat and j-hat.
底面是由基向量i和j组成的正方形 面积是1 If you think of the square with area 1 spanned by i-hat and j-hat as the base of this whole shape,
所以它的体积值等同与它的高 也就是我们这个向量的z坐标 then its volume is the same as its height, which is the third coordinate of our vector.
同样的 用这个奇怪的方法来描述向量在某一个轴上的坐标值 and likewise, the wacky way to think about any other coordinate of this vector
可以先考虑向量 would be to form the parallelepiped using the vector
和除这个轴之外的两个基向量组成的平行六面体 and then all of the basis vectors other than the one corresponding to the direction you're looking for,
然后其体积就是对应的坐标值 then the volumn of this gives you the coordinate.
另外 我们可以讨论平行六面体的有向体积 Or, rather, we should talk about the signed volume of these parallelepipeds,
就是之前在行列式视频中提到的右手法则 in the sense described in the determinant video using the right-hand rule,
这时 你列出的这三个向量的顺序就很重要了 so the order in which you list these three vectors matters.
这样一来 坐标的正负性也是有意义的 That way negative coordinates still make sense.
好了 为什么要把坐标值和面积或体积联系起来呢 Okay, so why think of coordinates as areas and volumes like this?
因为当你做矩阵变换后 Or as you apply some sort of matrix transformation,
平行四边形的面积不一定保持不变 the areas of the parallelograms don't stay the same,
可能成比例增大或减小 they might get scaled up or down.
但注意！这正是行列式的关键 所有面积伸缩的比例都是一样的 But(! ), and this is a key idea of determinants, all of the areas get scaled by the same amount.
都等于给定的变换矩阵的行列式 Namely, the determinant of our transformation matrix.
比如 考虑一个新的平行四边形 For example, if you look the parallelogram spanned by
第一条边是变换后的第一基向量(也就是矩阵的第一列) the vector where your first basis vector lands, which is the first column of the matrix,
第二条边是变换后的[x,y] 那它的面积是多大呢 and the transformed version of [x; y], what is its area?
其实这就是我们之前提及的平行四边形的变换 Well, this is the transformed version of that parallelogram we were looking at earlier,
而变换前 面积是未知输入向量的y坐标值 the one whose area was the y-coordinate of the mystery input vector.
所以变换后的面积等于矩阵的行列式乘以y值 So its area is just gonna be the determinant of the transformation multiplied by that y-coordinate.
所以可以用输出的平行四边形面积 So that means we can solve for y by taking the area of this new parallelogram in the output space,
除以矩阵的行列式计算出y divided by the determinant of the full transformation.
那么 怎么计算出面积呢 And how do you get that area?
既然我们已知最终变换后的向量 Well, we know the coordinates for where the mystery input vector lands,
毕竟这是一个线性方程组 that's the whole point of a linear system of equations.
那么 可以构造一个新矩阵 第一列和我们原先的矩阵相同 So what I can do is create a matrix whose first column is the same as that of our matrix,
而第二列是输出向量 然后取新矩阵的行列式 but whose second column is the output vector, and you take its determinant.
你看 我们只需使用到变换后的两个向量 So look at that; just using data from the output of the transformation,
也就是矩阵的列向量们和已知输出向量 namely the columns of the matrix and the coordinates of our output vector,
就能计算得出未知输入向量的y值 方程已经解好一半了 we can recover the y-coordinate of our mystery input vector, which is the halfway to solve the system
我们可以用同样的方法得出x值 Likewise, the same idea can get us the x-coordinate.
回头来看 我们之前定义的平行四边形 Look at that parallelogram we defined earlier
(有向)面积为输入向量的x值 由未知向量和j基向量构成 which encodes the x-coordinate of the mystery input vector, spanned by that vector and j-hat.
而变换后的它 由输出向量和矩阵的第二列组成 The transformed version of this guy is spanned by the output vector and the second column of the matrix,
面积增大的比例是矩阵的行列式 and its area will have been multiplied by the determinant of that matrix.
所以输入向量的x值是新的面积除以变换矩阵的行列式 So, to solve for x, you can take this new area divided by the determinant of the transformation.
我们如法炮制 And similar to what we did before,
可以创造一个新矩阵来计算变换后的平行四边形的面积 you can compute the area of that output parallelogram by creating a new matrix
这个新矩阵第一列为输出向量 第二列和变换矩阵相同 whose first column is the output vector, and whose second column is the same as the original matrix.
同样 仅使用到输出部分的数值 So again, just using data from the output space,
这些我们在最初线性方程组里已知的数值 就能解出x值 the numbers we see in our original linear system, we can solve for what x must be
这个线性方程组的解法 被称为克莱姆法则 This formula for finding the solutions to a linear system of equations is known as Cramer's rule.
现在 我们代入具体数值 验证我们的理解 Here, just to sanity check ourselves, plug in the numbers here.
分子上的矩阵行列式为4+2 得6 The determinant of that top altered matrix is 4+2, which is 6,
分母的行列式为2 则x值应当为3 and the bottom determinant is 2, so the x-coordinate should be 3.
而回头看我们的输入向量 x轴确实为3 And indeed, looking back at that input vector we started with, it's x-coordinate is 3.
同样的 克莱姆法则告诉我们y值应当为4/2 得2 Likewise, Cramer's rule suggests the y-coordinate should be 4/2, or 2,
确实是最初的输入向量的y值 and that is in fact the y-coordinate of the input vector that we were starting with.
三维或高维的情况是相似的 The case with three dimensions or more is similar,
我强烈建议你停一停 好好想一想 and I highly recommend that you take a moment to pause to think it through yourself.
好了我来给你一些提示 Here, I'll give you a little momentum.
我们已知这个三阶变换矩阵 What we have is a known transformation, given by a 3x3 matrix,
和由线性系统等式的右边给出的输出向量 and a known output vector, given by the right side of our linear system,
我们想知道什么样的输入向量能得到这样的输出值 and we want to know what input vector lands on that output.
如果你把输入向量的z值 If you think of, say, the z-coordinate of that input vector
看作平行六面体的体积 as the volume of that special parallelepiped we were looking at earlier
它由基向量i j 和未知输入向量构成 spanned by i-hat, j-hat, and the mystery input vector,
那转换后它的体积会发生什么变化呢 what happens to that volume after the transformation?
你如何来计算新的体积呢 And what of the various way that you can compute that volume?
真的 停下来花一点时间好好想一想 如何扩展到更高的维度 Really, pause and take a moment to think through the details of generalizing this to higher dimensions;
找到每一个坐标投影值对应的表达式 finding an expression for each coordinate of the solution to a larger linear system.
思考更通用的情况 Thinking through more general cases like this
自己慢慢消化 才是学习的关键 and convincing yourself that it works and why it works is where all the learning really happens,
比在视频里光听人再讲一遍要有用得多 much more so than listening to some dude on YouTube walk you through the same reasoning again