《Fundamentals of Computer Graphics》第六章 线性代数
<h1 id="开篇">开篇</h1><p> 也许,图形程序中最通用的的工具就是那些用来<strong>变换</strong>(<strong>Transform</strong>)点和向量的矩阵,这章主要讲的是线性代数的基础知识。</p>
<h1 id="行列式determinants">行列式(Determinants)</h1>
<p> 我们一般可能会想行列式会在线性方程组的解中出现,不过可以先以向量相乘的方式来思考行列式。对于二维向量来说,行列式<span class="math inline">\(|\mathbf{a}\mathbf{b}|\)</span>是由向量<span class="math inline">\(\mathbf{a}\)</span>和向量<span class="math inline">\(\mathbf{b}\)</span>围成的平行四边形的面积决定的,如下图所示。<br>
<img src="https://img2023.cnblogs.com/blog/2774734/202506/2774734-20250624203542433-229188150.png"></p>
<p>不过这个面积是有符号的,如果是右手的那么为正,反之则为负,因此我们可以得到<span class="math inline">\(|\mathbf{a}\mathbf{b}|=-|\mathbf{b}\mathbf{a}|\)</span>。这里的“右手的”可以理解为当逆时针旋转第一个向量时,它和第二个向量的夹角会变小。在三维中,行列式要用到三个向量,对于三个向量<span class="math inline">\(\mathbf{a}\)</span>、<span class="math inline">\(\mathbf{b}\)</span>、<span class="math inline">\(\mathbf{c}\)</span>来说,行列式<span class="math inline">\(|\mathbf{a}\mathbf{b}\mathbf{c}|\)</span>是由这三个向量围成的平行六面体的有符号容积决定的。<br>
为了计算二阶行列式,我们首先可以了解下它的相关性质,缩放某个向量会缩放平行四边形的面积,因此可以得到</p>
<p></p><div class="math display">\[|(k\mathbf{a})\mathbf{b}|=|\mathbf{a}(k\mathbf{b})|=k|\mathbf{a}\mathbf{b}|
\]</div><p></p><p><img src="https://img2023.cnblogs.com/blog/2774734/202506/2774734-20250601230304127-1830531749.png"></p>
<p>剪切平行四边形不会改变它的面积,因此</p>
<p></p><div class="math display">\[|(\mathbf{a}+k\mathbf{b})\mathbf{b}|=|\mathbf{a}(\mathbf{b}+k\mathbf{a})|=|\mathbf{a}\mathbf{b}|
\]</div><p></p><p><img src="https://img2023.cnblogs.com/blog/2774734/202506/2774734-20250601230502031-2057861188.png"></p>
<p>假设我们用笛卡尔坐标来表示<span class="math inline">\(\mathbf{a}\)</span>和<span class="math inline">\(\mathbf{b}\)</span>,行列式<span class="math inline">\(|\mathbf{ab}|\)</span>可以如下计算</p>
<p></p><div class="math display">\[\begin{align*}
|\mathbf{ab}| &= |(x_a\mathbf{x}+y_a\mathbf{y})(x_b\mathbf{x}+y_b\mathbf{y})| \\
&=x_ax_b|\mathbf{xx}|+x_ay_b|\mathbf{xy}|+y_ax_b|\mathbf{yx}|+y_ay_b|\mathbf{yy}| \\
&=x_ax_b(0)+x_ay_b(+1)+y_ax_b(-1)+y_ay_b(0)\\
&=x_ay_b-y_ax_b
\end{align*}
\]</div><p></p><p>因此在三维中</p>
<p></p><div class="math display">\[\begin{align*}
|\mathbf{abc}| &= |(x_a\mathbf{x}+y_a\mathbf{y}+z_a\mathbf{z})(x_b\mathbf{x}+y_b\mathbf{y}+z_b\mathbf{z})(x_c\mathbf{x}+y_c\mathbf{y}+z_c\mathbf{z})| \\
&=x_ay_bz_c-x_az_by_c-y_ax_bz_c+y_az_bx_c+z_ax_by_c-z_ay_bx_c
\end{align*}
\]</div><p></p><h1 id="矩阵matrices">矩阵(Matrices)</h1>
<p> 一个矩阵是遵循某些算术规则的数值元素数组,一个两行三列的矩阵可以如下所示</p>
<p></p><div class="math display">\[\begin{bmatrix}
1.7 & -1.2 & 4.2 \\ 3.0 & 4.5 & -7.2
\end{bmatrix}
\]</div><p></p><h2 id="矩阵算数matrix-arithmetic">矩阵算数(Matrix Arithmetic)</h2>
<p>对于给定的矩阵,乘以一个常数可以得到</p>
<p></p><div class="math display">\[2 \begin{bmatrix}1 & -4 \\ 3 & 2 \end{bmatrix} = \begin{bmatrix} 2 & -8 \\ 6 & 4 \end{bmatrix}
\]</div><p></p><p>两个矩阵求和可以得到</p>
<p></p><div class="math display">\[\begin{bmatrix} 1 & -4 \\ 3 & 2 \end{bmatrix} + \begin{bmatrix} 2 & 2 \\ 2 & 2 \end{bmatrix} = \begin{bmatrix} 3 & -2 \\ 5 & 4 \end{bmatrix}
\]</div><p></p><p>两个矩阵相乘可以得到</p>
<p></p><div class="math display">\[\begin{bmatrix} a_{11} & \cdots & a_{1m} \\ \vdots && \vdots \\ \boxed{a_{i1}} & \boxed{\cdots} & \boxed{a_{im}} \\ \vdots && \vdots \\ a_{r1} & \cdots & a_{rm} \end{bmatrix} \begin{bmatrix} b_{11} & \cdots & \boxed{b_{1j}} & \cdots & b_{1c} \\ \vdots && \boxed{\vdots} && \vdots \\ b_{m1} & \cdots & \boxed{b_{mj}} & \cdots & n_{mc} \end{bmatrix} = \begin{bmatrix} p_{11} & \cdots & p_{1j} & \cdots & p_{1c} \\ \vdots && \vdots && \vdots \\ p_{i1} & \cdots & \boxed{p_{ij}} & \cdots & p_{ic} \\ \vdots && \vdots && \vdots \\ p_{r1} & \cdots & p_{rj} & \cdots & p_{rc} \end{bmatrix}
\]</div><p></p><p></p><div class="math display">\[p_{ij}=a_{i1}b_{1j}+a_{i2}b_{2j}+\cdots+a_{im}b_{mj}
\]</div><p></p><p>下面是个矩阵相乘的例子</p>
<p></p><div class="math display">\[\begin{bmatrix} 0 & 1 \\ 2 & 3 \\ 4 & 5 \end{bmatrix} \begin{bmatrix} 6 & 7 & 8 & 9 \\ 0 & 1 & 2 & 3 \end{bmatrix} = \begin{bmatrix} 0 & 1 & 2 & 3 \\ 12 & 17 & 22 & 27 \\ 24 & 33 & 42 &51 \end{bmatrix}
\]</div><p></p><p>要注意的是矩阵相乘不服从交换律,因此</p>
<p></p><div class="math display">\[\mathbf{A}\mathbf{B} \neq \mathbf{B}\mathbf{A}
\]</div><p></p><p>而且如果已知<span class="math inline">\(\mathbf{A}\mathbf{B} = \mathbf{A}\mathbf{C}\)</span>,矩阵<span class="math inline">\(\mathbf{B}\)</span>有可能不会等于矩阵<span class="math inline">\(\mathbf{C}\)</span>。不过幸运的是矩阵相乘服从结合律和分配律,因此</p>
<p></p><div class="math display">\[\begin{align*}
\mathbf{(AB)C}&=\mathbf{A(BC)}\\
\mathbf{A(B+C)}&=\mathbf{AB+AC}\\
\mathbf{(A+B)C}&=\mathbf{AC+BC}
\end{align*}
\]</div><p></p><h2 id="矩阵中的操作operation-on-matrices">矩阵中的操作(Operation on Matrices)</h2>
<p> 对于一个矩阵来说我们可能会考虑到它的逆,就像对于实数<span class="math inline">\(x\)</span>来说的<span class="math inline">\(1/x\)</span>一样。实数<span class="math inline">\(x\)</span>乘以它的逆<span class="math inline">\(1/x\)</span>为实数<span class="math inline">\(1\)</span>,那么矩阵<span class="math inline">\(\mathbf{A}\)</span>乘以它的逆<span class="math inline">\(\mathbf{A}^{-1}\)</span>,应该等于“矩阵<span class="math inline">\(1\)</span>”。这种矩阵只在方块矩阵中出现,它被称为<strong>单位矩阵</strong>(<strong>Identity Matrix</strong>)。这个矩阵的主对角线上的元素为<span class="math inline">\(1\)</span>其它元素为<span class="math inline">\(0\)</span>,比如</p>
<p></p><div class="math display">\[\mathbf{I} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}
\]</div><p></p><p>因此<span class="math inline">\(\mathbf{A}\mathbf{A}^{-1}=\mathbf{I}\)</span>,下面是个矩阵求逆的例子</p>
<p></p><div class="math display">\[\begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix}^{-1} = \begin{bmatrix} -2.0 & 1.0 \\ 1.5 & -0.5 \end{bmatrix}
\]</div><p></p><p>因为</p>
<p></p><div class="math display">\[\begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} \begin{bmatrix} -2.0 & 1.0 \\ 1.5 & -0.5 \end{bmatrix} = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}
\]</div><p></p><p>此外矩阵的逆还有如下性质</p>
<p></p><div class="math display">\[(\mathbf{AB})^{-1}=\mathbf{B^{-1}A^{-1}}
\]</div><p></p><p>一个矩阵的转置<span class="math inline">\(\mathbf{A^{\mathrm{T}}}\)</span>和<span class="math inline">\(\mathbf{A}\)</span>有相同的数字,不过是<span class="math inline">\(\mathbf{A}\)</span>行列交换后的结果,因此</p>
<p></p><div class="math display">\[\begin{bmatrix} 1 & 2 \\ 3 & 4 \\ 5 & 6 \end{bmatrix}^{\mathrm{T}} = \begin{bmatrix} 1 & 3 & 5 \\ 2 & 4 &6 \end{bmatrix}
\]</div><p></p><p>矩阵的转置有如下性质</p>
<p></p><div class="math display">\[\mathbf{(AB)}^{\mathrm{T}}=\mathbf{B^{\mathrm{T}}A^{\mathrm{T}}}
\]</div><p></p><p>矩阵的行列式就是把矩阵的括号替换成竖线,有如下性质</p>
<p></p><div class="math display">\[|\mathbf{AB}|=|\mathbf{A}||\mathbf{B}|
\]</div><p></p><p></p><div class="math display">\[|\mathbf{A}^{-1}|=\frac{1}{|\mathbf{A}|}
\]</div><p></p><p></p><div class="math display">\[|\mathbf{A}^{\mathrm{T}}|=|\mathbf{A}|
\]</div><p></p><h2 id="使用矩阵操作向量vector-operations-in-matrix-form">使用矩阵操作向量(Vector Operations in Matrix Form)</h2>
<p> 有时候我们有可能想旋转一个二维向量<span class="math inline">\(\mathbf{a}=(x_a,y_a)90°\)</span>到<span class="math inline">\(\mathbf{a}^{\prime}=(-y_a,x_a)\)</span>,可以使用一个<span class="math inline">\(2 \times 2\)</span>的矩阵乘以一个<span class="math inline">\(2 \times 1\)</span>的矩阵来表示这一变换,这个<span class="math inline">\(2 \times 1\)</span>的矩阵叫做<strong>列向量</strong>(<strong>Column Vector</strong>),因此</p>
<p></p><div class="math display">\[\begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix} \begin{bmatrix} x_a \\ y_a \end{bmatrix} = \begin{bmatrix} -y_a \\ x_a \end{bmatrix}
\]</div><p></p><p>我们也可以使用行向量和上式的矩阵的转置相乘来得到这一变换</p>
<p></p><div class="math display">\[\begin{bmatrix} x_a & y_a \end{bmatrix} \begin{bmatrix} 0 & 1 \\ -1 & 0 \end{bmatrix} = \begin{bmatrix} -y_a & x_a \end{bmatrix}
\]</div><p></p><p>此外我们也可以用矩阵相乘来得到向量点乘的结果,假设有列向量<span class="math inline">\(\mathbf{a}\)</span>和<span class="math inline">\(\mathbf{b}\)</span>,可以得到</p>
<p></p><div class="math display">\[\mathbf{a} \cdot \mathbf{b} = \mathbf{a}^{\mathrm{T}} \mathbf{b}
\]</div><p></p><p>以三维向量的点积为例,可以得到</p>
<p></p><div class="math display">\[\begin{bmatrix} x_a & y_a & z_a \end{bmatrix} \begin{bmatrix} x_b \\ y_b \\ z_b \end{bmatrix} = \begin{bmatrix} x_ax_b + y_ay_b + z_az_b \end{bmatrix}
\]</div><p></p><p>对于<span class="math inline">\(\mathbf{ab^{\mathrm{T}}}\)</span>的情况我们也可以了解下,这个时候</p>
<p></p><div class="math display">\[\begin{bmatrix} x_a \\ y_a \\ z_a \end{bmatrix} \begin{bmatrix} x_b & y_b & z_b \end{bmatrix} = \begin{bmatrix} x_ax_b & x_ay_b & x_az_b \\ y_ax_b & y_ay_b & y_az_b \\ z_ax_b & z_ay_b & z_az_b \end{bmatrix}
\]</div><p></p><p>其实我们还可以从不同的角度看待矩阵变换向量和点,接下来以<span class="math inline">\(3 \times 3\)</span>的矩阵变换为例,对于<span class="math inline">\(\mathbf{y}=\mathbf{Ax}\)</span>我们可知</p>
<p></p><div class="math display">\[\begin{bmatrix} | \\ \mathbf{y} \\ | \end{bmatrix} = \begin{bmatrix} - & \mathbf{r}_1 & - \\ - & \mathbf{r}_2 & - \\ - & \mathbf{r}_3 & - \end{bmatrix} \begin{bmatrix} | \\ \mathbf{x} \\ | \end{bmatrix}
\]</div><p></p><p></p><div class="math display">\[y_i = \mathbf{r}_i \cdot \mathbf{x}
\]</div><p></p><p><span class="math inline">\(\mathbf{y}\)</span>的第<span class="math inline">\(i\)</span>个分量实际上是矩阵的<span class="math inline">\(\mathbf{r}_i\)</span>行向量和<span class="math inline">\(\mathbf{x}\)</span>点积的结果,这实际上就是把<span class="math inline">\(\mathbf{x}\)</span>投影到了<span class="math inline">\(\{\mathbf{r}_1,\mathbf{r}_2,\mathbf{r}_3\}\)</span>这个坐标系中,且投影的结果为<span class="math inline">\(\mathbf{y}\)</span>。此外从另一个角度我们还可以知道</p>
<p></p><div class="math display">\[\begin{bmatrix} | \\ \mathbf{y} \\ | \end{bmatrix} = \begin{bmatrix} | & | & | \\ \mathbf{c}_1 & \mathbf{c}_2 & \mathbf{c}_3 \\ | & | & | \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix}
\]</div><p></p><p></p><div class="math display">\[\mathbf{y}=x_1\mathbf{c}_1+x_2\mathbf{c}_2+x_3\mathbf{c}_3
\]</div><p></p><p>在这里假设有个全局坐标系,这实际上就是以全局坐标系中的<span class="math inline">\(\mathbf{c}_1\)</span>、<span class="math inline">\(\mathbf{c}_2\)</span>、<span class="math inline">\(\mathbf{c}_3\)</span>为基向量建立了另一个坐标系,并以在这个坐标系中的坐标<span class="math inline">\((x_1,x_2,x_3)\)</span>得到全局坐标系中的<span class="math inline">\(\mathbf{y}\)</span>。上述的两个角度提供了独到的见解来了解<span class="math inline">\(\mathbf{y}=\mathbf{Ax}\)</span>这一抽象操作中的几何含义。</p>
<h2 id="矩阵的特殊类型special-types-of-matrices">矩阵的特殊类型(Special Types of Matrices)</h2>
<p> 矩阵有些特殊的类型,比如单位矩阵就是<strong>对角矩阵</strong>(<strong>Diagonal Matrix</strong>),这种矩阵的非零元素只出现在主对角线上。此外单位矩阵的转置等于它本身,这种有对称性的矩阵就叫做<strong>对称矩阵</strong>(<strong>Symmetric Matrix</strong>)。最后单位矩阵还是<strong>正交矩阵</strong>(<strong>Orthogonal Matrix</strong>),因为这种矩阵的每一列的向量与它当中的其它列向量都相互垂直。正交矩阵的行列式非<span class="math inline">\(+1\)</span>即<span class="math inline">\(-1\)</span>,而且有个非常好的性质</p>
<p></p><div class="math display">\[\mathbf{R}^\mathrm{T}\mathbf{R}=\mathbf{I}=\mathbf{R}\mathbf{R}^\mathrm{T}
\]</div><p></p><p>利用之前提到过的对矩阵变换向量的理解可以很容易得到这个结论,下面有些矩阵的例子</p>
<p></p><div class="math display">\[\begin{bmatrix} 8 & 0 & 0 \\ 0 & 2 & 0 \\ 0 & 0 & 9 \end{bmatrix}
\]</div><p></p><p>这个矩阵是对角矩阵也是对称矩阵,不是正交矩阵</p>
<p></p><div class="math display">\[\begin{bmatrix} 1 & 1 & 2 \\ 1 & 9 & 7 \\ 2 & 7 & 1 \end{bmatrix}
\]</div><p></p><p>这个矩阵是对称矩阵,不是对角矩阵也不是正交矩阵</p>
<p></p><div class="math display">\[\begin{bmatrix} 0 & 1 & 0 \\ 0 & 0 & 1 \\ 1 & 0 & 0 \end{bmatrix}
\]</div><p></p><p>这个矩阵是正交矩阵,不是对角矩阵也不是对称矩阵</p>
<h1 id="使用矩阵和行列式计算computing-with-matrices-and-determinants">使用矩阵和行列式计算(Computing with Matrices and Determinants)</h1>
<p> 之前的部分提到,取n个n维向量的行列式,是由这n个n维向量定义的n维平行体的n维有符号容积决定的,对于二维来说就是由向量围成的平行四边形的面积。我们可以使用矩阵解决行列式计算的机制,假设有二维向量<span class="math inline">\(\mathbf{r}\)</span>和<span class="math inline">\(\mathbf{s}\)</span>,我们表示行列式为<span class="math inline">\(|\mathbf{r} \mathbf{s}|\)</span>,它的值是由向量围成的平行四边形的有符号面积。假设有笛卡尔坐标的两个二维向量<span class="math inline">\((a,b)\)</span>、<span class="math inline">\((A,B)\)</span>,行列式可以这么写</p>
<p></p><div class="math display">\[\begin{vmatrix} \begin{bmatrix} a \\ b \end{bmatrix} \begin{bmatrix} A \\ B \end{bmatrix} \end{vmatrix} \equiv \begin{vmatrix} a & A \\ b & B \end{vmatrix} = aB-Ab
\]</div><p></p><p> 最开始的部分提到用暴力展开计算行列式,不过使用那个方法计算会遇到许多<span class="math inline">\(0\)</span>系数,而且还会遇到很多正负号,行列式计算的一个标准方法就是<strong>拉普拉斯展开</strong>(<strong>Laplace's Expansion</strong>),使用这个方法计算的关键就是找到<strong>余子式</strong>(<strong>Cofactor</strong>),方块矩阵的每个元素都有一个余子式,这个余子式是当前方块矩阵少一行少一列的行列式,而且每个余子式的符号由所属元素所在的行和列决定,如果行列相加为偶符号为正反之为负,因此可以得到符号矩阵</p>
<p></p><div class="math display">\[\begin{bmatrix} + & - & + & - & \cdots \\ - & + & - & + & \cdots \\ + & - & + & - & \cdots \\ - & + & - & + & \cdots \\ \vdots & \vdots & \vdots & \vdots & \ddots \end{bmatrix}
\]</div><p></p><p>对于下面的<span class="math inline">\(4 \times 4\)</span>矩阵来说</p>
<p></p><div class="math display">\[\mathbf{A}=\begin{bmatrix} a_{11} & a_{12} & a_{13} & a_{14} \\ a_{21} & a_{22} & a_{23} & a_{24} \\ a_{31} & a_{32} & a_{33} & a_{34} \\ a_{41} & a_{42} & a_{43} & a_{44} \end{bmatrix}
\]</div><p></p><p>第一行的余子式是</p>
<p></p><div class="math display">\[a^{c}_{11} = \begin{vmatrix} a_{22} & a_{23} & a_{24} \\ a_{32} & a_{33} & a_{34} \\ a_{42} & a_{43} & a_{44} \end{vmatrix},a^{c}_{12} = - \begin{vmatrix} a_{21} & a_{23} & a_{24} \\ a_{31} & a_{33} & a_{34} \\ a_{41} & a_{43} & a_{44}\end{vmatrix} , a^{c}_{13} = \begin{vmatrix} a_{21} & a_{22} & a_{24} \\ a_{31} & a_{32} & a_{34} \\ a_{41} & a_{42} & a_{44} \end{vmatrix},a^{c}_{14} = - \begin{vmatrix} a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \\ a_{41} & a_{42} & a_{43} \end{vmatrix}
\]</div><p></p><p>矩阵的行列式就是累加某列或某行的每个元素与它们的余子式的乘积,以第二列为例</p>
<p></p><div class="math display">\[|\mathbf{A}| = a_{12}a^{c}_{12} + a_{22}a^{c}_{22} + a_{32}a^{c}_{32} + a_{42}a^{c}_{42}
\]</div><p></p><p>剩下要做的就是展开<span class="math inline">\(a^{c}_{12}\)</span>、<span class="math inline">\(a^{c}_{22}\)</span>、<span class="math inline">\(a^{c}_{32}\)</span>、<span class="math inline">\(a^{c}_{42}\)</span>以及后续的余子式。</p>
<h2 id="计算逆computing-inverse">计算逆(Computing Inverse)</h2>
<p> 行列式的标准计算方法也给了我们一个工具来计算矩阵的逆,通过上个部分的拉普拉斯展开,我们可以知道一个<span class="math inline">\(4 \times 4\)</span>的矩阵<span class="math inline">\(\mathbf{A}\)</span>的逆<span class="math inline">\(\mathbf{A}^{-1}\)</span>为</p>
<p></p><div class="math display">\[\mathbf{A}^{-1} = \frac{1}{|\mathbf{A}|} \begin{bmatrix} a^{c}_{11} & a^{c}_{21} & a^{c}_{31} & a^{c}_{41} \\ a^{c}_{12} & a^{c}_{22} & a^{c}_{32} & a^{c}_{42} \\ a^{c}_{13} & a^{c}_{23} & a^{c}_{33} & a^{c}_{43} \\ a^{c}_{14} & a^{c}_{24} & a^{c}_{34} & a^{c}_{44} \end{bmatrix}
\]</div><p></p><p>等式右侧的矩阵实际上是把矩阵的每个元素替换成它的余子式所得到的矩阵的转置,把它与<span class="math inline">\(\mathbf{A}\)</span>相乘可得到主对角线上的元素为</p>
<p></p><div class="math display">\[\begin{bmatrix} a_{11} & a_{12} & a_{13} & a_{14} \\
\cdot & \cdot & \cdot & \cdot \\
\cdot & \cdot & \cdot & \cdot \\
\cdot & \cdot & \cdot & \cdot \end{bmatrix} \begin{bmatrix} a^{c}_{11} & \cdot & \cdot & \cdot \\ a^{c}_{12} & \cdot & \cdot & \cdot \\ a^{c}_{13} & \cdot & \cdot & \cdot \\ a^{c}_{14} & \cdot & \cdot & \cdot \\ \end{bmatrix} = \begin{bmatrix} |\mathbf{A}| & \cdot & \cdot & \cdot \\ \cdot & \cdot & \cdot & \cdot \\ \cdot & \cdot & \cdot & \cdot \\ \cdot & \cdot & \cdot & \cdot \\ \end{bmatrix}
\]</div><p></p><p>非主对角线上的元素为</p>
<p></p><div class="math display">\[\begin{bmatrix} \cdot & \cdot & \cdot & \cdot \\ a_{21} & a_{22} & a_{23} & a_{24} \\ \cdot & \cdot & \cdot & \cdot \\ \cdot & \cdot & \cdot & \cdot \end{bmatrix} \begin{bmatrix} a^{c}_{11} & \cdot & \cdot & \cdot \\ a^{c}_{12} & \cdot & \cdot & \cdot \\ a^{c}_{13} & \cdot & \cdot & \cdot \\ a^{c}_{14} & \cdot & \cdot & \cdot \\ \end{bmatrix} = \begin{bmatrix} \cdot & \cdot & \cdot & \cdot \\ 0 & \cdot & \cdot & \cdot \\ \cdot & \cdot & \cdot & \cdot \\ \cdot & \cdot & \cdot & \cdot \\ \end{bmatrix}
\]</div><p></p><p>因为可以从<span class="math inline">\(a_{21}a^{c}_{11} + a_{22}a^{c}_{12} + a_{23}a^{c}_{13} + a_{24}a^{c}_{14}\)</span>得到另外一个矩阵</p>
<p></p><div class="math display">\[\mathbf{B}=\begin{bmatrix} a_{21} & a_{22} & a_{23} & a_{24} \\ a_{21} & a_{22} & a_{23} & a_{24} \\ a_{31} & a_{32} & a_{33} & a_{34} \\ a_{41} & a_{42} & a_{43} & a_{44} \end{bmatrix}
\]</div><p></p><p>这个矩阵是奇异的,因此它的行列式<span class="math inline">\(a_{21}a^{c}_{11} + a_{22}a^{c}_{12} + a_{23}a^{c}_{13} + a_{24}a^{c}_{14}\)</span>求出来为<span class="math inline">\(0\)</span>。</p>
<h2 id="线性系统linear-systems">线性系统(Linear Systems)</h2>
<p>有时我们可能会遇到由<span class="math inline">\(n\)</span>个等式<span class="math inline">\(n\)</span>个未知量组成的线性方程组,以<span class="math inline">\(n=3\)</span>为例</p>
<p></p><div class="math display">\[\begin{align*}
&3x+7y+2z=4 \\
&2x-4y-3z=-1\\
&5x+2y+z=1
\end{align*}
\]</div><p></p><p>我们可以写成如下形式</p>
<p></p><div class="math display">\[\begin{bmatrix} 3 & 7 & 2 \\ 2 & -4 & -3 \\ 5 & 2 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \end{bmatrix} = \begin{bmatrix} 4 \\ -1 \\ 1 \end{bmatrix}
\]</div><p></p><p>使用<strong>克拉默法则</strong>(<strong>Cramer's rule</strong>)可以得到</p>
<p></p><div class="math display">\[x = \frac{\begin{vmatrix} 4 & 7 & 2 \\ -1 & -4 & -3 \\ 1 & 2 & 1 \end{vmatrix}}{\begin{vmatrix} 3 & 7 & 2 \\ 2 & -4 & -3 \\ 5 & 2 & 1 \end{vmatrix}},y = \frac{\begin{vmatrix} 3 & 4 & 2 \\ 2 & -1 & -3 \\ 5 & 1 & 1 \end{vmatrix}}{\begin{vmatrix} 3 & 7 & 2 \\ 2 & -4 & -3 \\ 5 & 2 & 1 \end{vmatrix}},z = \frac{\begin{vmatrix} 3 & 7 & 4 \\ 2 & -4 & -1 \\ 5 & 2 & 1 \end{vmatrix}}{\begin{vmatrix} 3 & 7 & 2 \\ 2 & -4 & -3 \\ 5 & 2 & 1 \end{vmatrix}}
\]</div><p></p><p>这里要注意的是分母也就是矩阵的行列式<span class="math inline">\(|\mathbf{A}|\)</span>不能为<span class="math inline">\(0\)</span>,如果为<span class="math inline">\(0\)</span>那么意味着方程没有唯一解。</p>
<h1 id="特征值和矩阵对角化eigenvalues-and-matrix-diagonalization">特征值和矩阵对角化(Eigenvalues and Matrix Diagonalization)</h1>
<p> 有些方块矩阵有<strong>特征值</strong>(<strong>Eigenvalues</strong>)和<strong>特征向量</strong>(<strong>Eigenvectors</strong>),特征向量是非零的且与矩阵相乘时方向不变,现有矩阵<span class="math inline">\(\mathbf{A}\)</span>和向量<span class="math inline">\(\mathbf{a}\)</span>,可以得到</p>
<p></p><div class="math display">\[\mathbf{Aa}=\lambda\mathbf{a}
\]</div><p></p><p>公式中的<span class="math inline">\(\lambda\)</span>就是和特征向量关联的特征值,矩阵的特征值和特征向量在很多应用中很有用。接下来先为矩阵求特征值和特征向量。我们有<span class="math inline">\(\mathbf{Aa}=\lambda\mathbf{a}\)</span>,因此可以得到</p>
<p></p><div class="math display">\[\mathbf{Aa}=\lambda\mathbf{Ia}
\]</div><p></p><p>这里的<span class="math inline">\(\mathbf{I}\)</span>为单位矩阵,因此可以得到</p>
<p></p><div class="math display">\[\begin{align*}
\mathbf{Aa}-\lambda\mathbf{Ia} &=0 \\
(\mathbf{A}-\lambda\mathbf{I})\mathbf{a} &=0
\end{align*}
\]</div><p></p><p>因为<span class="math inline">\(\mathbf{a}\)</span>不为<span class="math inline">\(0\)</span>向量,所以矩阵<span class="math inline">\(\mathbf{A}-\lambda\mathbf{I}\)</span>是奇异的,这就使得它的行列式为<span class="math inline">\(0\)</span>,因此我们可以计算出特征值<span class="math inline">\(\lambda\)</span>,求出特征值<span class="math inline">\(\lambda\)</span>后可以利用<span class="math inline">\((\mathbf{A}-\lambda\mathbf{I})\mathbf{a}=0\)</span>为每个特征值<span class="math inline">\(\lambda\)</span>求出关联的特征向量<span class="math inline">\(\mathbf{a}\)</span>。<br>
有一个非常重要的特殊情况就是当矩阵为对称矩阵时,它的特征值和特征向量很简单,而且这种矩阵可以对角化变成如下形式</p>
<p></p><div class="math display">\[\mathbf{A}=\mathbf{QDQ}^\mathrm{T}
\]</div><p></p><p>这里的<span class="math inline">\(\mathbf{Q}\)</span>是正交矩阵,<span class="math inline">\(\mathbf{D}\)</span>是对角矩阵。<span class="math inline">\(\mathbf{Q}\)</span>的每一列是特征向量,<span class="math inline">\(\mathbf{D}\)</span>的主对角线上的元素是<span class="math inline">\(\mathbf{A}\)</span>的特征值。把<span class="math inline">\(\mathbf{A}\)</span>以这种形式分解就叫做<strong>特征值分解</strong>(<strong>Eigenvalue Decomposition</strong>),因为这样分解能揭示矩阵的特征向量和特征值。下面以一个<span class="math inline">\(2 \times 2\)</span>的对称矩阵为例。</p>
<p>给定矩阵</p>
<p></p><div class="math display">\[\mathbf{A} = \begin{bmatrix} 2 & 1 \\ 1 & 1 \end{bmatrix}
\]</div><p></p><p>可以得到</p>
<p></p><div class="math display">\[\lambda^{2}-3\lambda+1=0
\]</div><p></p><p>可以解出<span class="math inline">\(\lambda\)</span>为</p>
<p></p><div class="math display">\[\lambda = \frac{3 \pm \sqrt{5}}{2}, \approx \begin{bmatrix} 2.618 \\ 0.382 \end{bmatrix}
\]</div><p></p><p>把<span class="math inline">\(\lambda=2.618\)</span>带入<span class="math inline">\((\mathbf{A}-\lambda\mathbf{I})\mathbf{a} =0\)</span>可得</p>
<p></p><div class="math display">\[\begin{bmatrix} 2-2.618 & 1 \\ 1 & 1-2.618 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \end{bmatrix}
\]</div><p></p><p>特征向量约等于<span class="math inline">\((0.8507,0.5257)\)</span>,对于另一个特征值<span class="math inline">\(\lambda = 0.382\)</span>,与它关联的特征向量为<span class="math inline">\((-0.5257,0.8507)\)</span>,因此可以把<span class="math inline">\(\mathbf{A}\)</span>分解为</p>
<p></p><div class="math display">\[\begin{bmatrix} 2 & 1 \\ 1 & 1 \end{bmatrix} = \begin{bmatrix} 0.8507 & -0.5257 \\ 0.5257 & 0.8507 \end{bmatrix} \begin{bmatrix} 2.618 & 0 \\ 0 & 0.382 \end{bmatrix} \begin{bmatrix} 0.8507 & 0.5257 \\ -0.5257 & 0.8507 \end{bmatrix}
\]</div><p></p><h2 id="奇异值分解singular-value-decomposition">奇异值分解(Singular Value Decomposition)</h2>
<p> 通过上一个部分我们可以知道对称矩阵可以被对角化,然而我们遇到的大部分矩阵可能都不是对称的,因此有个更加通用的方法叫<strong>奇异值分解</strong>(<strong>Singular Value Decomposition</strong>,<strong>SVD</strong>),使用这个方法可以把矩阵分解为</p>
<p></p><div class="math display">\[\mathbf{A}=\mathbf{USV}^\mathrm{T}
\]</div><p></p><p>其中<span class="math inline">\(\mathbf{U}\)</span>和<span class="math inline">\(\mathbf{V}\)</span>是可能不同的正交矩阵,前者的每列是<span class="math inline">\(\mathbf{A}\)</span>的左奇异向量,后者的每列是<span class="math inline">\(\mathbf{A}\)</span>的右奇异向量。<span class="math inline">\(\mathbf{S}\)</span>是对角矩阵,主对角线上面的每个元素是<span class="math inline">\(\mathbf{A}\)</span>的奇异值。为了得到奇异值和奇异向量,我们可以在<span class="math inline">\(\mathbf{A}\)</span>的基础上构造对称矩阵<span class="math inline">\(\mathbf{M}\)</span></p>
<p></p><div class="math display">\[\mathbf{M}=\mathbf{AA}^\mathrm{T}=(\mathbf{USV}^\mathrm{T})(\mathbf{USV}^\mathrm{T})^{\mathrm{T}}=\mathbf{US(V^{\mathrm{T}}V)SU^{\mathrm{T}}}=\mathbf{US}^{2}\mathbf{U}^\mathrm{T}
\]</div><p></p><p>接下来可以通过<span class="math inline">\(\mathbf{M}\)</span>求出<span class="math inline">\(\mathbf{U}\)</span>和<span class="math inline">\(\mathbf{S}\)</span>接着利用<span class="math inline">\(\mathbf{A}=\mathbf{USV}^\mathrm{T}\)</span>求出<span class="math inline">\(\mathbf{V}\)</span>,以下面的矩阵为例</p>
<p></p><div class="math display">\[\mathbf{A}=\begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix},\mathbf{M}=\mathbf{AA}^\mathrm{T}=\begin{bmatrix} 2 & 1 \\ 1 & 1 \end{bmatrix}
\]</div><p></p><p>由上个部分的计算可以得到</p>
<p></p><div class="math display">\[\begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix} = \begin{bmatrix} 0.8507 & -0.5257 \\ 0.5257 & 0.8507 \end{bmatrix} \begin{bmatrix} \sqrt{2.618} & 0 \\ 0 & \sqrt{0.382} \end{bmatrix} \mathbf{V}^\mathrm{T}
\]</div><p></p><p>那么</p>
<p></p><div class="math display">\[\mathbf{V}=(\mathbf{S}^{-1}\mathbf{U}^\mathrm{T}\mathbf{A})^\mathrm{T}
\]</div><p></p><p>因此</p>
<p></p><div class="math display">\[\begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix} =\mathbf{U} \begin{bmatrix} \sigma_{1} & 0 \\ 0 & \sigma_{2} \end{bmatrix} \mathbf{V}^\mathrm{T} = \begin{bmatrix} 0.8507 & -0.5257 \\ 0.5257 & 0.8507 \end{bmatrix} \begin{bmatrix} 1.618 & 0 \\ 0 & 0.618 \end{bmatrix} \begin{bmatrix} 0.5257 & 0.8507 \\ -0.8507 & 0.5257 \end{bmatrix}
\]</div><p></p><p>式中的<span class="math inline">\(\sigma_{i}\)</span>是矩阵的第<span class="math inline">\(i\)</span>个奇异值的标准符号。</p>
</div>
<div id="MySignature" role="contentinfo">
<p>本文来自博客园,作者:TiredInkRaven,转载请注明原文链接:https://www.cnblogs.com/TiredInkRaven/p/18903425</p><br><br>
来源:https://www.cnblogs.com/TiredInkRaven/p/18903425
頁:
[1]