<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

 <title>Linear Algebra Self-Learning</title>
 <link href="https://linear-algebra-self-learning.pages.dev/atom.xml" rel="self"/>
 <link href="https://linear-algebra-self-learning.pages.dev/"/>
 <updated>2026-12-05T04:02:02+00:00</updated>
 <id>https://linear-algebra-self-learning.pages.dev</id>
 <author>
   <name>Nguyen Le Linh</name>
   <email>nglelinh@gmail.com</email>
 </author>

 
 <entry>
   <title>Tensor và hình dạng dữ liệu</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter14/14_05_Tensor_Va_Hinh_Dang_Du_Lieu/"/>
   <updated>2026-01-14T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter14/14_05_Tensor_Va_Hinh_Dang_Du_Lieu</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;đọc hình dạng (shape) của tensor dữ liệu thường gặp: lô vectơ, lô ảnh, lô chuỗi token;&lt;/li&gt;
    &lt;li&gt;dùng reshape, chuyển trục và broadcasting đúng cách;&lt;/li&gt;
    &lt;li&gt;viết tích ma trận, tích vô hướng, vết và phép nhân theo lô bằng quy ước tổng Einstein (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;einsum&lt;/code&gt;);&lt;/li&gt;
    &lt;li&gt;kiểm tra hình dạng của từng bước trong một phép tính attention.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Lỗi thường gặp nhất khi lập trình học máy không phải công thức sai mà là &lt;strong&gt;sai hình dạng&lt;/strong&gt;: “shapes (32, 784) and (128, 784) not aligned”. Lỗi này thật ra là một câu hỏi đại số tuyến tính: tích $AB$ chỉ xác định khi số cột của $A$ bằng số hàng của $B$ (Bài 03-01). Ở đây $X$ có $32$ mẫu, mỗi mẫu $784$ đặc trưng, và $W$ có $128$ hàng, $784$ cột, nên phải viết $XW^T$, không phải $XW$ (Bài 14-03). Bài này hệ thống hoá cách nghĩ về hình dạng khi dữ liệu có nhiều hơn hai chiều.&lt;/p&gt;

&lt;h2 id=&quot;tensor-là-mảng-nhiều-chiều&quot;&gt;Tensor là mảng nhiều chiều&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa.&lt;/strong&gt; Trong học máy, một &lt;strong&gt;tensor&lt;/strong&gt; cấp $p$ là một mảng số $T$ được đánh chỉ số bởi $p$ chỉ số $T_{i_1 i_2 \dots i_p}$, với $1 \le i_k \le n_k$. Bộ $(n_1, \dots, n_p)$ là &lt;strong&gt;hình dạng&lt;/strong&gt; (shape) của nó, và mỗi chỉ số là một &lt;strong&gt;trục&lt;/strong&gt; (axis). Số $0$ chiều là tensor cấp $0$, vectơ cấp $1$, ma trận cấp $2$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;(Trong vật lý và hình học vi phân, “tensor” còn mang nghĩa ánh xạ đa tuyến tính với quy tắc đổi toạ độ; ở đây ta chỉ dùng nghĩa mảng.)&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Dữ liệu&lt;/th&gt;
      &lt;th&gt;Hình dạng điển hình&lt;/th&gt;
      &lt;th&gt;Ý nghĩa các trục&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Lô vectơ đặc trưng&lt;/td&gt;
      &lt;td&gt;$(N, d)$&lt;/td&gt;
      &lt;td&gt;mẫu, đặc trưng (Bài 14-01)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Ảnh màu&lt;/td&gt;
      &lt;td&gt;$(3, H, W)$&lt;/td&gt;
      &lt;td&gt;kênh màu, hàng, cột&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Lô ảnh (PyTorch)&lt;/td&gt;
      &lt;td&gt;$(N, 3, H, W)$&lt;/td&gt;
      &lt;td&gt;mẫu, kênh, hàng, cột&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Lô câu đã nhúng&lt;/td&gt;
      &lt;td&gt;$(N, T, d)$&lt;/td&gt;
      &lt;td&gt;mẫu, vị trí token, chiều embedding&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Video&lt;/td&gt;
      &lt;td&gt;$(N, F, 3, H, W)$&lt;/td&gt;
      &lt;td&gt;mẫu, khung hình, kênh, hàng, cột&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Một lô $32$ ảnh RGB $224 \times 224$ có hình dạng $(32, 3, 224, 224)$, gồm $32 \cdot 3 \cdot 224 \cdot 224 = 4\,816\,896$ số; với số thực 32 bit là khoảng $19{,}3$ MB.&lt;/p&gt;

&lt;h2 id=&quot;đổi-hình-dạng-và-chuyển-trục&quot;&gt;Đổi hình dạng và chuyển trục&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Reshape&lt;/strong&gt; sắp lại các phần tử theo thứ tự lưu trữ (theo hàng trong NumPy, PyTorch) thành một hình dạng mới có cùng tổng số phần tử. Ví dụ “làm phẳng” một lô ảnh $(N, 1, 28, 28)$ thành $(N, 784)$ để đưa vào một lớp kết nối đầy đủ. Đây chính là phép đẳng cấu $\mathbb{R}^{28 \times 28} \cong \mathbb{R}^{784}$ (Bài 06-04): cùng dữ liệu, cách đánh chỉ số khác.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chuyển trục&lt;/strong&gt; (transpose, permute) tổng quát hoá phép chuyển vị: đổi thứ tự các trục, chẳng hạn $(N, H, W, 3) \to (N, 3, H, W)$ khi chuyển giữa định dạng của TensorFlow và PyTorch. Reshape và chuyển trục &lt;strong&gt;không&lt;/strong&gt; thay thế được nhau: reshape một ma trận $2 \times 3$ thành $3 \times 2$ khác với chuyển vị nó.&lt;/p&gt;

&lt;h2 id=&quot;broadcasting&quot;&gt;Broadcasting&lt;/h2&gt;

&lt;p&gt;Khi cộng hai tensor khác hình dạng, NumPy và PyTorch &lt;strong&gt;broadcast&lt;/strong&gt;: so hình dạng từ trục cuối lên, hai trục tương thích nếu bằng nhau hoặc một trong hai bằng $1$ (hoặc vắng mặt), và trục cỡ $1$ được lặp lại cho khớp.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Với $A = \begin{bmatrix} 0 &amp;amp; 1 &amp;amp; 2 \\ 3 &amp;amp; 4 &amp;amp; 5 \end{bmatrix}$ hình dạng $(2, 3)$:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$b = (10, 20, 30)$ hình dạng $(3,)$ được cộng vào &lt;strong&gt;mỗi hàng&lt;/strong&gt;: $A + b = \begin{bmatrix} 10 &amp;amp; 21 &amp;amp; 32 \\ 13 &amp;amp; 24 &amp;amp; 35 \end{bmatrix}$. Đây là $XW^T + \mathbf{1}b^T$ của Bài 14-03.&lt;/li&gt;
    &lt;li&gt;$c$ hình dạng $(2, 1)$ với giá trị $1, 2$ được cộng vào &lt;strong&gt;mỗi cột&lt;/strong&gt;: $A + c = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 3 \\ 5 &amp;amp; 6 &amp;amp; 7 \end{bmatrix}$.&lt;/li&gt;
    &lt;li&gt;Cộng $A$ với vectơ hình dạng $(2,)$ báo lỗi, vì trục cuối $3 \ne 2$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;p&gt;Về đại số, broadcasting là cách viết gọn tích ngoài với vectơ toàn số $1$: $A + \mathbf{1}b^T$ và $A + c\mathbf{1}^T$. Chuẩn hoá các hàng của $X$ trong Bài 14-01, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;X / norms[:, None]&lt;/code&gt;, cũng là broadcasting.&lt;/p&gt;

&lt;h2 id=&quot;quy-ước-tổng-einstein&quot;&gt;Quy ước tổng Einstein&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;einsum&lt;/code&gt; mô tả một phép toán bằng tên các chỉ số: chỉ số xuất hiện ở đầu vào nhưng không có ở đầu ra thì được &lt;strong&gt;lấy tổng&lt;/strong&gt;.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Biểu thức&lt;/th&gt;
      &lt;th&gt;Công thức&lt;/th&gt;
      &lt;th&gt;Ý nghĩa&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&apos;ij,j-&amp;gt;i&apos;&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;$y_i = \sum_j A_{ij}x_j$&lt;/td&gt;
      &lt;td&gt;$Ax$&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&apos;ij,jk-&amp;gt;ik&apos;&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;$C_{ik} = \sum_j A_{ij}B_{jk}$&lt;/td&gt;
      &lt;td&gt;$AB$&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&apos;i,i-&amp;gt;&apos;&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;$\sum_i x_iy_i$&lt;/td&gt;
      &lt;td&gt;$x^Ty$&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&apos;i,j-&amp;gt;ij&apos;&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;$x_iy_j$&lt;/td&gt;
      &lt;td&gt;tích ngoài $xy^T$&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&apos;ii-&amp;gt;&apos;&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;$\sum_i A_{ii}$&lt;/td&gt;
      &lt;td&gt;vết&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&apos;ij,ij-&amp;gt;&apos;&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;$\sum_{ij} A_{ij}B_{ij}$&lt;/td&gt;
      &lt;td&gt;$\operatorname{tr}(A^TB)$, tích trong Frobenius&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&apos;bij,bjk-&amp;gt;bik&apos;&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;$C_{bik} = \sum_j A_{bij}B_{bjk}$&lt;/td&gt;
      &lt;td&gt;nhân ma trận theo lô&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Ví dụ với $A$ của Ví dụ 1: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;einsum(&apos;ij,j-&amp;gt;i&apos;, A, [1,1,1])&lt;/code&gt; cho tổng các hàng $(3, 12)$, và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;einsum(&apos;ij,ij-&amp;gt;&apos;, A, A)&lt;/code&gt; cho $\lVert A \rVert_F^2 = 55$.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-kiểm-tra-hình-dạng-trong-attention&quot;&gt;Ứng dụng: kiểm tra hình dạng trong attention&lt;/h2&gt;

&lt;p&gt;Một lớp attention nhận $X$ hình dạng $(B, T, d)$: $B$ câu, mỗi câu $T$ token, mỗi token một vectơ $d$ chiều. Theo dõi hình dạng:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;$Q = XW_Q$, $K = XW_K$, $V = XW_V$ với $W$ hình dạng $(d, d_k)$: mỗi tensor $(B, T, d_k)$. Phép nhân áp dụng cho trục cuối, broadcast theo $B, T$.&lt;/li&gt;
  &lt;li&gt;Điểm số $S$ = &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;einsum(&apos;btd,bsd-&amp;gt;bts&apos;, Q, K)&lt;/code&gt; $/\sqrt{d_k}$: hình dạng $(B, T, T)$, $S_{bts} = q_{bt}^Tk_{bs}$ là tích vô hướng (Bài 14-01).&lt;/li&gt;
  &lt;li&gt;Softmax theo trục cuối, rồi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;einsum(&apos;bts,bsd-&amp;gt;btd&apos;, A, V)&lt;/code&gt;: trở lại $(B, T, d_k)$, mỗi đầu ra là tổ hợp lồi của các vectơ giá trị.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Với $B = 8$, $T = 1024$, tensor điểm số có $8 \cdot 1024^2 = 8\,388\,608$ phần tử cho &lt;strong&gt;mỗi&lt;/strong&gt; đầu attention: chi phí bình phương theo độ dài chuỗi là lý do người ta tìm các biến thể attention hiệu quả hơn.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: tensor và hình dạng dữ liệu&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Đổi kích thước, chọn phần tử, thớ hoặc lát cắt, xem vị trí trong bộ nhớ.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter14/tensor.html&quot; title=&quot;Minh hoạ: tensor và hình dạng dữ liệu&quot; loading=&quot;lazy&quot; style=&quot;height: 760px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter14/tensor.html&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Một lô $16$ video, mỗi video $8$ khung hình RGB $112 \times 112$. Viết hình dạng theo quy ước PyTorch $(N, F, C, H, W)$ và số phần tử. Sau khi reshape thành $(N \cdot F, C, H, W)$ để xử lý từng khung hình, hình dạng là gì?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$(16, 8, 3, 112, 112)$, có $16 \cdot 8 \cdot 3 \cdot 112^2 = 4\,816\,896$ phần tử (trùng với lô 32 ảnh $224 \times 224$ vì $16 \cdot 8 \cdot 112^2 = 32 \cdot 224^2$). Sau reshape: $(128, 3, 112, 112)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Với $A$ hình dạng $(5, 1, 3)$ và $B$ hình dạng $(4, 3)$, $A + B$ có hình dạng gì? Còn $A + C$ với $C$ hình dạng $(5, 4)$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

So từ trục cuối: $(5, 1, 3)$ và $(\ , 4, 3)$ cho $(5, 4, 3)$. Với $C$: $(5, 1, 3)$ và $(\ , 5, 4)$, trục cuối $3 \ne 4$ nên báo lỗi.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Viết bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;einsum&lt;/code&gt;: (a) $x^TAy$; (b) ma trận Gram $XX^T$ (Bài 14-01); (c) với lô $X$ hình dạng $(B, N, d)$, ma trận Gram cho từng phần tử của lô.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

(a) `einsum(&apos;i,ij,j-&amp;gt;&apos;, x, A, y)`. (b) `einsum(&apos;id,jd-&amp;gt;ij&apos;, X, X)`. (c) `einsum(&apos;bid,bjd-&amp;gt;bij&apos;, X, X)`, hình dạng $(B, N, N)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Giải thích vì sao reshape một ma trận $2 \times 3$ thành $3 \times 2$ khác với chuyển vị, bằng ví dụ $A$ của Ví dụ 1.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Reshape đọc các phần tử theo hàng $0, 1, 2, 3, 4, 5$ rồi xếp lại: $\begin{bmatrix} 0 &amp;amp; 1 \\ 2 &amp;amp; 3 \\ 4 &amp;amp; 5 \end{bmatrix}$. Chuyển vị đổi vai hàng và cột: $A^T = \begin{bmatrix} 0 &amp;amp; 3 \\ 1 &amp;amp; 4 \\ 2 &amp;amp; 5 \end{bmatrix}$. Hai ma trận khác nhau.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Tensor (theo nghĩa học máy) là mảng nhiều chiều; hình dạng cho biết ý nghĩa và cỡ của từng trục.&lt;/li&gt;
    &lt;li&gt;Reshape giữ thứ tự lưu trữ, chuyển trục đổi vai các chỉ số; hai việc này khác nhau.&lt;/li&gt;
    &lt;li&gt;Broadcasting so hình dạng từ trục cuối, lặp trục cỡ $1$; về đại số là cộng tích ngoài với $\mathbf{1}$.&lt;/li&gt;
    &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;einsum&lt;/code&gt; biểu diễn mọi tích ma trận, tích vô hướng, vết và phép nhân theo lô; theo dõi hình dạng là cách kiểm tra nhanh mọi công thức.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Hệ gợi ý bằng phân rã ma trận</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter14/14_04_He_Goi_Y_Bang_Phan_Ra_Ma_Tran/"/>
   <updated>2026-01-14T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter14/14_04_He_Goi_Y_Bang_Phan_Ra_Ma_Tran</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;mô hình hoá ma trận đánh giá bằng phân rã hạng thấp $R \approx UV^T$ và giải thích ý nghĩa các vectơ ẩn;&lt;/li&gt;
    &lt;li&gt;dùng giả thiết hạng thấp để điền ô thiếu trong ví dụ nhỏ;&lt;/li&gt;
    &lt;li&gt;viết bài toán tối ưu trên các ô đã quan sát và thuật toán bình phương tối thiểu xen kẽ (ALS), nhận ra mỗi bước là một bài hồi quy ridge;&lt;/li&gt;
    &lt;li&gt;liên hệ với SVD rút gọn và định lý Eckart–Young.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Bốn người dùng chấm điểm bốn bộ phim (thang $1$–$5$; dấu ? là chưa xem):&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt; &lt;/th&gt;
      &lt;th&gt;Phim 1&lt;/th&gt;
      &lt;th&gt;Phim 2&lt;/th&gt;
      &lt;th&gt;Phim 3&lt;/th&gt;
      &lt;th&gt;Phim 4&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;An&lt;/td&gt;
      &lt;td&gt;$5$&lt;/td&gt;
      &lt;td&gt;$4$&lt;/td&gt;
      &lt;td&gt;$1$&lt;/td&gt;
      &lt;td&gt;?&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Bình&lt;/td&gt;
      &lt;td&gt;?&lt;/td&gt;
      &lt;td&gt;$2$&lt;/td&gt;
      &lt;td&gt;$5$&lt;/td&gt;
      &lt;td&gt;$4$&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Chi&lt;/td&gt;
      &lt;td&gt;$3$&lt;/td&gt;
      &lt;td&gt;$3$&lt;/td&gt;
      &lt;td&gt;$3$&lt;/td&gt;
      &lt;td&gt;$3$&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Dũng&lt;/td&gt;
      &lt;td&gt;$4{,}2$&lt;/td&gt;
      &lt;td&gt;$3{,}6$&lt;/td&gt;
      &lt;td&gt;?&lt;/td&gt;
      &lt;td&gt;$2{,}4$&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Nên gợi ý Phim 3 cho Dũng không? Không có quan hệ gì giữa các ô thì không thể đoán. Nhưng sở thích của con người không ngẫu nhiên: Phim 1, 2 có vẻ là phim hành động, Phim 3, 4 là phim tình cảm; An thích hành động, Bình thích tình cảm. Nếu mỗi người và mỗi phim được mô tả bằng &lt;strong&gt;vài con số&lt;/strong&gt;, ma trận đánh giá sẽ có &lt;strong&gt;hạng thấp&lt;/strong&gt;, và chính điều đó cho phép điền ô trống.&lt;/p&gt;

&lt;h2 id=&quot;mô-hình-nhân-tố-ẩn&quot;&gt;Mô hình nhân tố ẩn&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa.&lt;/strong&gt; Với ma trận đánh giá $R \in \mathbb{R}^{m \times n}$ ($m$ người dùng, $n$ sản phẩm), một &lt;strong&gt;mô hình nhân tố ẩn&lt;/strong&gt; hạng $k$ gán cho người dùng $i$ vectơ $u_i \in \mathbb{R}^k$ và sản phẩm $j$ vectơ $v_j \in \mathbb{R}^k$, và dự đoán&lt;/p&gt;

  &lt;p&gt;\(\hat r_{ij} = u_i^Tv_j, \qquad \text{tức } \hat R = UV^T,\ U \in \mathbb{R}^{m \times k},\ V \in \mathbb{R}^{n \times k}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Mỗi toạ độ của $v_j$ đo mức độ sản phẩm có một “tính chất” nào đó, còn toạ độ tương ứng của $u_i$ đo người dùng thích tính chất đó đến đâu. Điểm dự đoán là tích vô hướng: sở thích khớp với tính chất thì điểm cao (Bài 14-01). Ma trận $UV^T$ có hạng $\le k$ (Bài 14-03, Định lý 1). Mô hình có $(m + n)k$ tham số thay vì $mn$ ô, nhỏ hơn rất nhiều khi $k \ll m, n$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (bảng đầy đủ).&lt;/strong&gt; Bảng ở ví dụ mở đầu được sinh từ $k = 2$ nhân tố (hành động, tình cảm):&lt;/p&gt;

\[U = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \\ 0{,}5 &amp;amp; 0{,}5 \\ 0{,}8 &amp;amp; 0{,}2 \end{bmatrix}, \quad
V = \begin{bmatrix} 5 &amp;amp; 1 \\ 4 &amp;amp; 2 \\ 1 &amp;amp; 5 \\ 2 &amp;amp; 4 \end{bmatrix}, \quad
UV^T = \begin{bmatrix} 5 &amp;amp; 4 &amp;amp; 1 &amp;amp; 2 \\ 1 &amp;amp; 2 &amp;amp; 5 &amp;amp; 4 \\ 3 &amp;amp; 3 &amp;amp; 3 &amp;amp; 3 \\ 4{,}2 &amp;amp; 3{,}6 &amp;amp; 1{,}8 &amp;amp; 2{,}4 \end{bmatrix}.\]

  &lt;p&gt;Ma trận này có hạng $2$ (giá trị kỳ dị khác $0$ là $\approx 12{,}04$ và $4{,}75$). Các ô còn trống được dự đoán là An–Phim 4: $2$; Bình–Phim 1: $1$; Dũng–Phim 3: $1{,}8$. Không nên gợi ý Phim 3 cho Dũng.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (người dùng mới).&lt;/strong&gt; Biết $V$ như trên, một người mới chấm Phim 1 là $5$ và Phim 3 là $2$. Tìm $u$ sao cho $5u_1 + u_2 = 5$ và $u_1 + 5u_2 = 2$:&lt;/p&gt;

\[\begin{bmatrix} 5 &amp;amp; 1 \\ 1 &amp;amp; 5 \end{bmatrix} u = \begin{bmatrix} 5 \\ 2 \end{bmatrix} \implies u = \tfrac1{24}\begin{bmatrix} 23 \\ 5 \end{bmatrix} \approx (0{,}958;\ 0{,}208).\]

  &lt;p&gt;Dự đoán Phim 2: $4 \cdot \tfrac{23}{24} + 2 \cdot \tfrac{5}{24} = 4{,}25$; Phim 4: $2 \cdot \tfrac{23}{24} + 4 \cdot \tfrac{5}{24} = 2{,}75$. Khi người dùng chấm nhiều phim hơn $k$, hệ trở thành bài bình phương tối thiểu (Chương 08).&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;học-u-và-v-từ-dữ-liệu-thiếu&quot;&gt;Học $U$ và $V$ từ dữ liệu thiếu&lt;/h2&gt;

&lt;p&gt;Dữ liệu thật rất thưa (mỗi người chỉ xem một phần rất nhỏ trong kho phim) và có nhiễu. Gọi $\Omega$ là tập các ô đã biết. Ta giải&lt;/p&gt;

\[\min_{U, V}\ \sum_{(i, j) \in \Omega} \left(r_{ij} - u_i^Tv_j\right)^2 + \lambda\left(\lVert U \rVert_F^2 + \lVert V \rVert_F^2\right).\]

&lt;p&gt;Hàm này không lồi theo $(U, V)$ cùng lúc, nhưng là bình phương tối thiểu nếu cố định một trong hai.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (một bước ALS).&lt;/strong&gt; Cố định $V$. Với người dùng $i$, gọi $V_i$ là ma trận gồm các hàng $v_j^T$ của những sản phẩm $i$ đã chấm, và $r_i$ là vectơ điểm tương ứng. Khi đó $u_i$ tối ưu là nghiệm của bài hồi quy ridge&lt;/p&gt;

\[(V_i^TV_i + \lambda I)\,u_i = V_i^Tr_i.\]

  &lt;p&gt;Tương tự cho mỗi $v_j$ khi cố định $U$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Khi $V$ cố định, hàm mục tiêu tách thành tổng các hạng tử độc lập theo từng $u_i$: $\lVert V_iu_i - r_i \rVert^2 + \lambda\lVert u_i \rVert^2$ (cộng hằng số). Đây là hồi quy ridge với ma trận thiết kế $V_i$; gradient bằng $0$ cho phương trình trên (Bài 14-02, Bài tập 3), và ma trận $V_i^TV_i + \lambda I$ xác định dương khi $\lambda &amp;gt; 0$ nên nghiệm duy nhất. $\blacksquare$&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Thuật toán ALS:&lt;/strong&gt; khởi tạo $V$ ngẫu nhiên nhỏ; lặp lại: giải mọi $u_i$ (mỗi bài chỉ là một hệ $k \times k$), rồi giải mọi $v_j$. Mỗi bước không làm tăng hàm mục tiêu, và các bài con độc lập nên chạy song song được. Một lựa chọn khác là hạ gradient ngẫu nhiên trên từng ô $(i, j) \in \Omega$.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Liên hệ với SVD.&lt;/strong&gt; Nếu mọi ô đều biết và $\lambda = 0$, bài toán là $\min \lVert R - UV^T \rVert_F$ với hạng $\le k$; theo Eckart–Young (Bài 11-03), nghiệm là SVD rút gọn $R_k = U_k\Sigma_kV_k^T$, chẳng hạn chọn $U = U_k\Sigma_k^{1/2}$, $V = V_k\Sigma_k^{1/2}$. Với dữ liệu thiếu không còn công thức đóng, nhưng một cách làm đơn giản là điền ô thiếu bằng điểm trung bình rồi lấy SVD rút gọn.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-giải-thưởng-netflix&quot;&gt;Ứng dụng: giải thưởng Netflix&lt;/h2&gt;

&lt;p&gt;Năm 2006 Netflix công bố khoảng 100 triệu đánh giá của 480 nghìn người dùng cho 17 nghìn phim (chỉ khoảng 1% số ô được biết) và treo giải một triệu đô la cho ai giảm được 10% sai số dự đoán. Các đội dẫn đầu đều dựa vào phân rã ma trận như trên (cộng thêm hệ số lệch cho từng người, từng phim và yếu tố thời gian); đội thắng năm 2009 kết hợp hàng trăm mô hình mà lõi là các nhân tố ẩn. Ngày nay, các “embedding” người dùng và sản phẩm trong hệ gợi ý thương mại vẫn là hậu duệ trực tiếp của $u_i$ và $v_j$.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: hệ gợi ý bằng phân rã ma trận&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Bấm vào ô để sửa điểm, kéo hạng k và λ, xem các ô trống được dự đoán.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter14/goi_y.html&quot; title=&quot;Minh hoạ: hệ gợi ý bằng phân rã ma trận&quot; loading=&quot;lazy&quot; style=&quot;height: 820px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter14/goi_y.html&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Trong ví dụ mở đầu, giả sử hai hàng An, Bình đã biết đầy đủ ($5, 4, 1, 2$ và $1, 2, 5, 4$) và ma trận có hạng $2$. Không dùng $U, V$, chỉ từ hai cột đầu của Dũng, hãy suy ra ô Dũng–Phim 3.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Hai hàng An, Bình độc lập nên mọi hàng khác là tổ hợp của chúng: Dũng $= a \cdot$ An $+ b \cdot$ Bình. Từ $5a + b = 4{,}2$ và $4a + 2b = 3{,}6$ được $a = 0{,}8$, $b = 0{,}2$. Ô cần tìm $= 0{,}8 \cdot 1 + 0{,}2 \cdot 5 = 1{,}8$; kiểm tra cột 4: $0{,}8 \cdot 2 + 0{,}2 \cdot 4 = 2{,}4$ đúng.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Phân rã $R = UV^T$ không duy nhất. Chứng minh rằng với mọi ma trận khả nghịch $A \in \mathbb{R}^{k \times k}$, cặp $(UA, VA^{-T})$ cho cùng $R$. Điều đó nói gì về việc “đặt tên” cho các nhân tố ẩn?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$(UA)(VA^{-T})^T = UAA^{-1}V^T = UV^T$. Các nhân tố chỉ được xác định đến một phép đổi cơ sở trong $\mathbb{R}^k$ (Bài 05-06), nên trục &quot;hành động/tình cảm&quot; không tự xuất hiện; ta chỉ có thể diễn giải chúng sau khi chọn một cơ sở thuận tiện (hiệu chỉnh $\lambda$ giảm bớt nhưng không loại hết sự tự do này).

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Với $V$ của Ví dụ 1 và $\lambda = 1$, một người dùng chỉ chấm Phim 1 là $5$. Tính $u$ theo Định lý 1 và dự đoán điểm Phim 3. So với trường hợp $\lambda = 0$, vì sao cần $\lambda &amp;gt; 0$ ở đây?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$V_i = \begin{bmatrix} 5 &amp;amp; 1 \end{bmatrix}$, $V_i^TV_i + I = \begin{bmatrix} 26 &amp;amp; 5 \\ 5 &amp;amp; 2 \end{bmatrix}$, $V_i^Tr_i = (25, 5)$. Giải được $u = \tfrac{1}{27}(25, 5) \approx (0{,}926;\ 0{,}185)$. Dự đoán Phim 3: $(25 + 25)/27 \approx 1{,}85$. Với $\lambda = 0$, $V_i^TV_i$ hạng $1$ nên có vô số $u$ khớp đúng một điểm; $\lambda &amp;gt; 0$ phạt chuẩn của $u$ nên nghiệm duy nhất (và co về $0$ theo hướng thiếu thông tin).

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (lập trình).&lt;/strong&gt; Tải bộ dữ liệu MovieLens 100K, giữ lại 20% đánh giá làm tập kiểm tra. Điền ô thiếu trong tập huấn luyện bằng trung bình của từng phim, dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.svd&lt;/code&gt; lấy xấp xỉ hạng $k$ và đo RMSE trên tập kiểm tra với $k = 2, 5, 10, 20, 50$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Gợi ý: `U, s, Vt = np.linalg.svd(R_filled, full_matrices=False)`; `Rk = U[:, :k] * s[:k] @ Vt[:k]`; RMSE $= \sqrt{\operatorname{mean}((R_k[i, j] - r_{ij})^2)}$ trên các ô kiểm tra. RMSE thường giảm rồi tăng lại khi $k$ lớn (quá khớp vào giá trị điền), với $k$ tốt nhất khoảng vài đến vài chục; ALS có hiệu chỉnh thường cho kết quả tốt hơn.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Hệ gợi ý giả thiết ma trận đánh giá gần hạng thấp: $\hat r_{ij} = u_i^Tv_j$, $\hat R = UV^T$.&lt;/li&gt;
    &lt;li&gt;Hạng thấp cho phép điền ô thiếu: hàng mới là tổ hợp tuyến tính của các hàng cũ.&lt;/li&gt;
    &lt;li&gt;Huấn luyện trên các ô đã biết; ALS xen kẽ các bài hồi quy ridge nhỏ $(V_i^TV_i + \lambda I)u_i = V_i^Tr_i$.&lt;/li&gt;
    &lt;li&gt;Dữ liệu đầy đủ, $\lambda = 0$: nghiệm là SVD rút gọn (Eckart–Young).&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Một lớp mạng nơ-ron là phép biến đổi tuyến tính</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter14/14_03_Mot_Lop_Mang_No_Ron_La_Phep_Bien_Doi_Tuyen_Tinh/"/>
   <updated>2026-01-14T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter14/14_03_Mot_Lop_Mang_No_Ron_La_Phep_Bien_Doi_Tuyen_Tinh</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;viết một lớp mạng nơ-ron $y = \sigma(Wx + b)$ và dạng theo lô $\sigma(XW^T + \mathbf{1}b^T)$, đếm số tham số;&lt;/li&gt;
    &lt;li&gt;chứng minh rằng chồng các lớp tuyến tính (không có hàm kích hoạt) vẫn là một phép biến đổi afin;&lt;/li&gt;
    &lt;li&gt;giải thích bằng hình học vai trò của hàm kích hoạt, qua ví dụ XOR;&lt;/li&gt;
    &lt;li&gt;tính gradient của mất mát theo $W$ dưới dạng tích ngoài.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Bài toán XOR: bốn điểm $(0, 0)$ và $(1, 1)$ có nhãn $0$, còn $(1, 0)$ và $(0, 1)$ có nhãn $1$. Không có đường thẳng nào tách hai nhóm này, nên mọi mô hình tuyến tính $w^Tx + c$ (với ngưỡng) đều thất bại. Ta sẽ thấy một mạng chỉ hai nơ-ron ẩn giải được nó, và rằng phần “phi tuyến” nhỏ xíu là điều kiện bắt buộc: thiếu nó, chồng bao nhiêu lớp cũng vô ích.&lt;/p&gt;

&lt;h2 id=&quot;một-lớp-mạng&quot;&gt;Một lớp mạng&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa.&lt;/strong&gt; Một &lt;strong&gt;lớp kết nối đầy đủ&lt;/strong&gt; từ $\mathbb{R}^n$ sang $\mathbb{R}^m$ là ánh xạ&lt;/p&gt;

\[x \mapsto \sigma(Wx + b), \qquad W \in \mathbb{R}^{m \times n},\ b \in \mathbb{R}^m,\]

  &lt;p&gt;trong đó &lt;strong&gt;hàm kích hoạt&lt;/strong&gt; $\sigma$ tác động lên từng thành phần, chẳng hạn $\operatorname{ReLU}(t) = \max(t, 0)$ hoặc $\tanh t$. Hàng $i$ của $W$ cùng với $b_i$ là trọng số của &lt;strong&gt;nơ-ron&lt;/strong&gt; thứ $i$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Phần $x \mapsto Wx + b$ là một phép biến đổi &lt;strong&gt;afin&lt;/strong&gt;: phép biến đổi tuyến tính $W$ (Chương 06) rồi tịnh tiến $b$. Như Bài 12-01, có thể gộp nó thành một ma trận bằng toạ độ thuần nhất: $\begin{bmatrix} W &amp;amp; b \end{bmatrix}\begin{bmatrix} x \\ 1 \end{bmatrix}$. Lớp có $mn + m$ tham số; ví dụ một lớp từ ảnh $28 \times 28 = 784$ điểm ảnh sang $128$ nơ-ron có $784 \cdot 128 + 128 = 100\,480$ tham số.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dạng theo lô.&lt;/strong&gt; Với ma trận dữ liệu $X \in \mathbb{R}^{N \times n}$ (hàng là mẫu, Bài 14-01), cả lô được tính một lần: $H = \sigma(XW^T + \mathbf{1}b^T) \in \mathbb{R}^{N \times m}$. Thư viện như PyTorch lưu sẵn $W^T$ và cộng $b$ theo cơ chế broadcasting (Bài 14-05). Gần như toàn bộ thời gian chạy của mạng nơ-ron là các phép nhân ma trận như vậy.&lt;/p&gt;

&lt;h2 id=&quot;không-có-hàm-kích-hoạt-thì-chồng-lớp-vô-ích&quot;&gt;Không có hàm kích hoạt thì chồng lớp vô ích&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Hợp của các phép biến đổi afin là một phép biến đổi afin. Cụ thể, $W_2(W_1x + b_1) + b_2 = (W_2W_1)x + (W_2b_1 + b_2)$. Hơn nữa, nếu $W_1 \in \mathbb{R}^{k \times n}$ thì $\operatorname{rank}(W_2W_1) \le k$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Đẳng thức có được bằng cách khai triển. Ảnh của $W_2W_1$ nằm trong ảnh của $W_2$ áp lên $\operatorname{Col}(W_1) \subseteq \mathbb{R}^k$, một không gian có chiều $\le k$, nên hạng $\le k$ (Bài 05-05). $\blacksquare$&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Vậy mạng sâu mười lớp không có $\sigma$ vẫn chỉ biểu diễn được hàm afin, tức chỉ vẽ được biên quyết định thẳng; và một lớp ẩn hẹp $k$ nơ-ron còn ép hàm đó có hạng $\le k$ (ý tưởng của bộ tự mã hoá tuyến tính, tương đương PCA, Bài 11-05).&lt;/p&gt;

&lt;h2 id=&quot;hàm-kích-hoạt-bẻ-cong-không-gian&quot;&gt;Hàm kích hoạt bẻ cong không gian&lt;/h2&gt;

&lt;p&gt;Về hình học, $Wx + b$ biến lưới ô vuông thành lưới hình bình hành (Bài 06-06); ReLU rồi “gập” mọi toạ độ âm về $0$, ép các vùng của mặt phẳng lên các cạnh của góc phần tư dương. Hai thao tác xen kẽ, lặp lại qua nhiều lớp, làm biến dạng không gian đủ để các lớp dữ liệu trở nên tách được bằng một đường thẳng ở lớp cuối.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (XOR bằng hai nơ-ron ReLU).&lt;/strong&gt; Lấy&lt;/p&gt;

\[W = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}, \quad b = \begin{bmatrix} 0 \\ -1 \end{bmatrix}, \quad h = \operatorname{ReLU}(Wx + b), \quad \hat y = h_1 - 2h_2.\]

  &lt;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th&gt;$x$&lt;/th&gt;
        &lt;th&gt;$Wx + b$&lt;/th&gt;
        &lt;th&gt;$h$&lt;/th&gt;
        &lt;th&gt;$\hat y$&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
      &lt;tr&gt;
        &lt;td&gt;$(0, 0)$&lt;/td&gt;
        &lt;td&gt;$(0, -1)$&lt;/td&gt;
        &lt;td&gt;$(0, 0)$&lt;/td&gt;
        &lt;td&gt;$0$&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td&gt;$(1, 0)$&lt;/td&gt;
        &lt;td&gt;$(1, 0)$&lt;/td&gt;
        &lt;td&gt;$(1, 0)$&lt;/td&gt;
        &lt;td&gt;$1$&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td&gt;$(0, 1)$&lt;/td&gt;
        &lt;td&gt;$(1, 0)$&lt;/td&gt;
        &lt;td&gt;$(1, 0)$&lt;/td&gt;
        &lt;td&gt;$1$&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td&gt;$(1, 1)$&lt;/td&gt;
        &lt;td&gt;$(2, 1)$&lt;/td&gt;
        &lt;td&gt;$(2, 1)$&lt;/td&gt;
        &lt;td&gt;$0$&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;

  &lt;p&gt;Lớp ẩn đưa bốn điểm về ba điểm $(0, 0)$, $(1, 0)$, $(2, 1)$ trong không gian $h$, và ở đó đường thẳng $h_1 - 2h_2 = \tfrac12$ tách được hai nhãn. Bỏ ReLU thì $\hat y = (x_1 + x_2) - 2(x_1 + x_2 - 1) = 2 - x_1 - x_2$, cho $2, 1, 1, 0$: sai ở $(0, 0)$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;gradient-theo-ma-trận-trọng-số&quot;&gt;Gradient theo ma trận trọng số&lt;/h2&gt;

&lt;p&gt;Huấn luyện mạng cần $\partial L/\partial W$. Với $z = Wx + b$ và $\delta = \partial L/\partial z \in \mathbb{R}^m$ (do lan truyền ngược từ các lớp sau), vì $z_i = \sum_j W_{ij}x_j + b_i$ nên $\partial L/\partial W_{ij} = \delta_i x_j$, tức&lt;/p&gt;

\[\frac{\partial L}{\partial W} = \delta\, x^T, \qquad \frac{\partial L}{\partial b} = \delta, \qquad \frac{\partial L}{\partial x} = W^T\delta.\]

&lt;p&gt;Gradient theo $W$ là một &lt;strong&gt;tích ngoài&lt;/strong&gt;, ma trận hạng $1$; với một lô, $\partial L/\partial W = \Delta^TX$ là tổng các tích ngoài. Lan truyền ngược qua lớp là nhân với &lt;strong&gt;ma trận chuyển vị&lt;/strong&gt; $W^T$. Hai phép nhân ma trận này chiếm phần lớn chi phí huấn luyện.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-lớp-chiếu-trong-transformer&quot;&gt;Ứng dụng: lớp chiếu trong Transformer&lt;/h2&gt;

&lt;p&gt;Trong một Transformer (khoá Học sâu, Chương 07), mỗi token là vectơ $x \in \mathbb{R}^d$ và được nhân với ba ma trận học được $W_Q, W_K, W_V$ để có các vectơ truy vấn, khoá và giá trị. Điểm chú ý giữa hai token là tích vô hướng $q_i^Tk_j$ (Bài 14-01), và đầu ra là tổ hợp tuyến tính của các vectơ giá trị. Các mô hình ngôn ngữ lớn có hàng tỉ tham số, nhưng phần lớn chúng nằm trong những ma trận $W$ như vậy; kỹ thuật tinh chỉnh LoRA chỉ học thêm một ma trận hạng thấp $\Delta W = BA$ (Bài 11-03) cho mỗi lớp.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: một lớp mạng nơ-ron bẻ cong mặt phẳng&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo W, b và chọn hàm kích hoạt để xem lưới biến đổi ra sao.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter14/lop_no_ron.html&quot; title=&quot;Minh hoạ: một lớp mạng nơ-ron bẻ cong mặt phẳng&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter14/lop_no_ron.html&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-một-lớp-mạng-nơ-ron-bẻ-cong-lưới-toạ-độ&quot;&gt;Video ngắn: Một lớp mạng nơ-ron bẻ cong lưới toạ độ&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/layer-warps-grid.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;XOR: hai điểm nhãn 0 và hai điểm nhãn 1, không đường thẳng nào tách được. Bước 1, phần afin x ↦ Wx + b với W = [1 1; 1 1], b = (0; −1): lưới bị ép dẹp về một đường vì W có hạng 1. Bước 2, ReLU = max(t, 0): không gian bị gập lại. Trong không gian ẩn h, đường thẳng h₁ − 2h₂ = 1/2 tách được hai nhãn. Bỏ ReLU thì chỉ còn phép afin. Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Hai lớp tuyến tính $W_1 = \begin{bmatrix} 1 &amp;amp; 2 \\ 0 &amp;amp; 1 \end{bmatrix}$, $b_1 = (1, 0)$ và $W_2 = \begin{bmatrix} 1 &amp;amp; -1 \end{bmatrix}$, $b_2 = 3$. Viết hợp của chúng thành một lớp duy nhất.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$W_2W_1 = \begin{bmatrix} 1 &amp;amp; 1 \end{bmatrix}$, $W_2b_1 + b_2 = 1 + 3 = 4$. Hợp là $x \mapsto x_1 + x_2 + 4$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Một mạng $784 \to 256 \to 64 \to 10$ (ba lớp kết nối đầy đủ có hệ số tự do) có bao nhiêu tham số? Nếu bỏ mọi hàm kích hoạt, hàm tương đương có hạng tối đa bao nhiêu?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$784 \cdot 256 + 256 = 200\,960$; $256 \cdot 64 + 64 = 16\,448$; $64 \cdot 10 + 10 = 650$; tổng $218\,058$. Không có kích hoạt, mạng là $x \mapsto W_3W_2W_1x + c$ với ma trận $10 \times 784$ hạng $\le \min(784, 256, 64, 10) = 10$ (ở đây giới hạn bởi số đầu ra).

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Kiểm tra lại Ví dụ 1 với $\hat y = h_1 - 2h_2$ và cho biết vì sao không thể dùng $\sigma(t) = t$ (hàm đồng nhất) để giải XOR, dù chọn $W, b$ và lớp ra thế nào.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Bảng ở Ví dụ 1 cho $0, 1, 1, 0$. Với $\sigma$ đồng nhất, theo Định lý 1 mạng là hàm afin $f(x) = a^Tx + c$. Khi đó $f(0,0) + f(1,1) = 2c + a_1 + a_2 = f(1,0) + f(0,1)$, nên không thể có vế trái bằng $0 + 0$ và vế phải bằng $1 + 1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Với $L = \tfrac12\lVert Wx - t \rVert^2$, chứng minh $\partial L/\partial W = (Wx - t)x^T$ và giải thích vì sao một bước hạ gradient trên một mẫu chỉ thay đổi $W$ bằng một ma trận hạng $1$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Ở đây $z = Wx$, $\delta = \partial L/\partial z = Wx - t$, nên $\partial L/\partial W = \delta x^T$. Bước cập nhật $W \leftarrow W - \eta\,\delta x^T$ cộng vào $W$ một tích ngoài $u v^T$, có hạng $\le 1$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Một lớp: $y = \sigma(Wx + b)$, phép biến đổi afin rồi hàm kích hoạt từng thành phần; theo lô, $\sigma(XW^T + \mathbf{1}b^T)$.&lt;/li&gt;
    &lt;li&gt;Hợp các lớp afin vẫn afin: $(W_2W_1)x + (W_2b_1 + b_2)$; thiếu $\sigma$, mạng sâu không mạnh hơn một lớp.&lt;/li&gt;
    &lt;li&gt;ReLU gập không gian; hai nơ-ron ReLU đủ giải XOR.&lt;/li&gt;
    &lt;li&gt;$\partial L/\partial W = \delta x^T$ (tích ngoài), lan truyền ngược nhân với $W^T$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Hồi quy tuyến tính dưới dạng ma trận</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter14/14_02_Hoi_Quy_Tuyen_Tinh_Duoi_Dang_Ma_Tran/"/>
   <updated>2026-01-14T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter14/14_02_Hoi_Quy_Tuyen_Tinh_Duoi_Dang_Ma_Tran</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;viết mô hình hồi quy tuyến tính và hàm mất mát MSE dưới dạng ma trận;&lt;/li&gt;
    &lt;li&gt;tính gradient $\nabla L(w) = \tfrac2n X^T(Xw - y)$ và nhận ra nghiệm của $\nabla L = 0$ là phương trình chuẩn;&lt;/li&gt;
    &lt;li&gt;chạy hạ gradient, chọn bước học theo trị riêng của $X^TX$ và giải thích vì sao điều kiện số ảnh hưởng tới tốc độ hội tụ.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Chương 08 đã giải bình phương tối thiểu bằng phương trình chuẩn và QR. Trong học máy, cùng bài toán đó được nhìn như &lt;strong&gt;huấn luyện một mô hình&lt;/strong&gt;: chọn tham số $w$ để cực tiểu một hàm mất mát, thường bằng hạ gradient. Lý do là với hàng triệu mẫu và hàng nghìn đặc trưng, hoặc với mô hình phi tuyến (Bài 14-03), không còn công thức đóng; nhưng gradient thì luôn tính được. Hồi quy tuyến tính là nơi ta thấy rõ nhất hai cách tiếp cận gặp nhau, và đại số tuyến tính cho biết hạ gradient chạy nhanh hay chậm.&lt;/p&gt;

&lt;p&gt;Dữ liệu dùng trong bài: bốn điểm $(x, y) = (0, 1), (1, 3), (2, 4), (3, 6)$.&lt;/p&gt;

&lt;h2 id=&quot;mô-hình-và-hàm-mất-mát&quot;&gt;Mô hình và hàm mất mát&lt;/h2&gt;

&lt;p&gt;Với ma trận dữ liệu $X \in \mathbb{R}^{n \times d}$ (Bài 14-01; nếu có hệ số tự do, thêm một cột toàn số $1$) và nhãn $y \in \mathbb{R}^n$, mô hình tuyến tính dự đoán $\hat y = Xw$. &lt;strong&gt;Sai số bình phương trung bình&lt;/strong&gt; (MSE) là&lt;/p&gt;

\[L(w) = \frac1n \lVert Xw - y \rVert^2 = \frac1n\left(w^TX^TXw - 2y^TXw + y^Ty\right).\]

&lt;p&gt;Đây là một dạng toàn phương của $w$ (Bài 10-03) với ma trận $\tfrac1n X^TX$, nửa xác định dương; nên $L$ lồi, và mọi điểm dừng đều là cực tiểu.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (gradient của MSE).&lt;/strong&gt; $\nabla L(w) = \dfrac2n X^T(Xw - y)$ và ma trận Hessian là $H = \dfrac2n X^TX$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Với hướng $h$ bất kỳ, $L(w + h) = \tfrac1n\lVert (Xw - y) + Xh \rVert^2 = L(w) + \tfrac2n (Xw - y)^TXh + \tfrac1n \lVert Xh \rVert^2$. Phần tuyến tính theo $h$ là $\big(\tfrac2n X^T(Xw - y)\big)^T h$, nên đó là gradient; phần bậc hai là $\tfrac12 h^T\big(\tfrac2n X^TX\big)h$, cho Hessian. $\blacksquare$&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Đặt $\nabla L = 0$ được $X^TXw = X^Ty$: đúng &lt;strong&gt;phương trình chuẩn&lt;/strong&gt; của Bài 08-02. Hai góc nhìn (hình học: chiếu $y$ lên $\operatorname{Col}(X)$; giải tích: gradient bằng $0$) cho cùng một nghiệm.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (nghiệm đóng).&lt;/strong&gt; Với cột $1$ và cột $x$,&lt;/p&gt;

\[X = \begin{bmatrix} 1 &amp;amp; 0 \\ 1 &amp;amp; 1 \\ 1 &amp;amp; 2 \\ 1 &amp;amp; 3 \end{bmatrix}, \quad X^TX = \begin{bmatrix} 4 &amp;amp; 6 \\ 6 &amp;amp; 14 \end{bmatrix}, \quad X^Ty = \begin{bmatrix} 14 \\ 29 \end{bmatrix}.\]

  &lt;p&gt;Giải được $w = (1{,}1;\ 1{,}6)$, tức $\hat y = 1{,}1 + 1{,}6x$. Phần dư $Xw - y = (0{,}1;\ -0{,}3;\ 0{,}3;\ -0{,}1)$, nên $L(w) = 0{,}2/4 = 0{,}05$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;hạ-gradient&quot;&gt;Hạ gradient&lt;/h2&gt;

&lt;p&gt;Bắt đầu từ $w_0$, lặp&lt;/p&gt;

\[w_{k+1} = w_k - \eta\,\nabla L(w_k) = w_k - \frac{2\eta}{n} X^T(Xw_k - y),\]

&lt;p&gt;với &lt;strong&gt;bước học&lt;/strong&gt; $\eta &amp;gt; 0$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2 (hội tụ).&lt;/strong&gt; Gọi $w^{\star}$ là nghiệm, $0 &amp;lt; \lambda_{\min} \le \lambda_{\max}$ là trị riêng của Hessian $H$ (giả sử $X$ có hạng cột đầy đủ). Khi đó $w_{k+1} - w^{\star} = (I - \eta H)(w_k - w^{\star})$, và hạ gradient hội tụ khi và chỉ khi $0 &amp;lt; \eta &amp;lt; 2/\lambda_{\max}$. Sai số giảm ít nhất theo hệ số $\rho = \max(\lvert 1 - \eta\lambda_{\min}\rvert, \lvert 1 - \eta\lambda_{\max}\rvert)$ mỗi bước.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Vì $\nabla L(w^{\star}) = 0$ và $\nabla L$ tuyến tính afin, $\nabla L(w_k) = H(w_k - w^{\star})$; thay vào công thức lặp được hệ thức đầu. $H$ đối xứng nên chéo hoá trực giao được (Bài 10-02); theo cơ sở trị riêng, mỗi thành phần của sai số nhân với $1 - \eta\lambda_i$ mỗi bước. Dãy tiến về $0$ với mọi điểm đầu khi và chỉ khi $\lvert 1 - \eta\lambda_i \rvert &amp;lt; 1$ với mọi $i$, tức $0 &amp;lt; \eta &amp;lt; 2/\lambda_{\max}$. $\blacksquare$&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Đây là cùng một lập luận như luỹ thừa ma trận (Bài 09-06) và chuỗi Markov (Bài 13-03): tốc độ do trị riêng quyết định. Chọn tốt nhất $\eta = 2/(\lambda_{\min} + \lambda_{\max})$ cho $\rho = \dfrac{\kappa - 1}{\kappa + 1}$ với $\kappa = \lambda_{\max}/\lambda_{\min}$ là số điều kiện của $X^TX$ (Bài 08-05). Đặc trưng có thang đo rất khác nhau làm $\kappa$ lớn và hạ gradient chậm: đó là lý do người ta &lt;strong&gt;chuẩn hoá đặc trưng&lt;/strong&gt; trước khi huấn luyện.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (hạ gradient trên dữ liệu mẫu).&lt;/strong&gt; Ở đây $n = 4$, $H = \tfrac12 X^TX$ có trị riêng $\lambda = \tfrac12(9 \pm \sqrt{61}) \approx 0{,}595$ và $8{,}405$. Vậy cần $\eta &amp;lt; 2/8{,}405 \approx 0{,}238$.&lt;/p&gt;

  &lt;p&gt;Với $\eta = 0{,}2$ và $w_0 = 0$: $\nabla L(w_0) = -\tfrac12 X^Ty = (-7;\ -14{,}5)$, nên $w_1 = (1{,}4;\ 2{,}9)$ với $L(w_1) = 7{,}225$ (so với $L(w_0) = 15{,}5$). Sau 10 bước $w_{10} \approx (1{,}002;\ 1{,}601)$ với $L \approx 0{,}0595$; sau khoảng 100 bước $w$ trùng $(1{,}1;\ 1{,}6)$ tới bốn chữ số. Hệ số co $\rho = \max(1 - 0{,}2 \cdot 0{,}595;\ 0{,}2 \cdot 8{,}405 - 1) \approx 0{,}881$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Hạ gradient ngẫu nhiên.&lt;/strong&gt; Khi $n$ rất lớn, mỗi bước chỉ dùng một lô nhỏ $B$ gồm vài chục đến vài trăm hàng của $X$: $\nabla L \approx \tfrac{2}{\lvert B\rvert} X_B^T(X_Bw - y_B)$. Phép tính vẫn là hai phép nhân ma trận–vectơ, rất hợp với GPU.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-dự-đoán-nhiều-đầu-ra-cùng-lúc&quot;&gt;Ứng dụng: dự đoán nhiều đầu ra cùng lúc&lt;/h2&gt;

&lt;p&gt;Nếu mỗi mẫu có $m$ nhãn (ví dụ dự báo nhiệt độ ở $m$ trạm), xếp chúng thành $Y \in \mathbb{R}^{n \times m}$ và tìm $W \in \mathbb{R}^{d \times m}$ cực tiểu $\tfrac1n\lVert XW - Y \rVert_F^2$. Gradient là $\tfrac2n X^T(XW - Y)$, và nghiệm $W = (X^TX)^{-1}X^TY$: $m$ bài hồi quy độc lập dùng chung một ma trận $X^TX$, chỉ cần phân rã nó một lần (chẳng hạn Cholesky, Bài 10-05). Lớp cuối của nhiều mạng nơ-ron chính là một mô hình như vậy đặt trên các đặc trưng do mạng học được.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: hồi quy tuyến tính bằng ma trận&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo các điểm dữ liệu, đổi bậc đa thức, xem nghiệm của XᵀXβ = Xᵀy.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter08/binh_phuong_toi_thieu.html?mode=fit&quot; title=&quot;Minh hoạ: hồi quy tuyến tính bằng ma trận&quot; loading=&quot;lazy&quot; style=&quot;height: 680px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter08/binh_phuong_toi_thieu.html?mode=fit&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Với dữ liệu Ví dụ 1, kiểm tra rằng $X^T(Xw - y) = 0$ tại $w = (1{,}1;\ 1{,}6)$, và giải thích ý nghĩa hình học.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$r = Xw - y = (0{,}1;\ -0{,}3;\ 0{,}3;\ -0{,}1)$. Tổng các thành phần $= 0$; $0 \cdot 0{,}1 + 1 \cdot (-0{,}3) + 2 \cdot 0{,}3 + 3 \cdot (-0{,}1) = 0$. Phần dư vuông góc với cả hai cột của $X$, tức $Xw$ là hình chiếu của $y$ lên $\operatorname{Col}(X)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Với $H$ của Ví dụ 2, điều gì xảy ra khi chạy hạ gradient với $\eta = 0{,}25$? Bước học nào cho tốc độ tốt nhất, và hệ số co khi đó là bao nhiêu?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\eta = 0{,}25 &amp;gt; 0{,}238$: $\lvert 1 - 0{,}25 \cdot 8{,}405 \rvert \approx 1{,}10 &amp;gt; 1$, thành phần theo vectơ riêng của $\lambda_{\max}$ dao động và lớn dần, thuật toán phân kỳ. Tốt nhất $\eta = 2/(0{,}595 + 8{,}405) = 2/9 \approx 0{,}222$, với $\rho = (8{,}405 - 0{,}595)/9 \approx 0{,}868$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Thêm hiệu chỉnh ridge: $L_\lambda(w) = \tfrac1n\lVert Xw - y \rVert^2 + \lambda \lVert w \rVert^2$. Tính gradient và nghiệm, rồi so với Bài 08-05.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\nabla L_\lambda = \tfrac2n X^T(Xw - y) + 2\lambda w$. Cho bằng $0$: $(X^TX + n\lambda I)w = X^Ty$. Đây là hồi quy ridge với tham số $n\lambda$; Hessian $\tfrac2n X^TX + 2\lambda I$ có mọi trị riêng tăng thêm $2\lambda$, nên số điều kiện giảm và hạ gradient nhanh hơn.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (lập trình).&lt;/strong&gt; Viết hạ gradient bằng NumPy cho dữ liệu Ví dụ 1, chạy với $\eta = 0{,}05$; $0{,}2$; $0{,}25$ và vẽ $L(w_k)$ theo $k$ (trục tung thang log).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

`for k in range(K): w -= eta * 2/n * X.T @ (X @ w - y)`. Với $0{,}05$ hội tụ chậm ($\rho \approx 0{,}97$); với $0{,}2$ khoảng 100 bước; với $0{,}25$ đồ thị tăng vọt (phân kỳ). Trên thang log, phần đuôi gần như một đường thẳng với độ dốc $2\log\rho$ (vì $L - L^{\star}$ tỉ lệ với bình phương sai số).

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Hồi quy tuyến tính: $\hat y = Xw$, $L(w) = \tfrac1n\lVert Xw - y \rVert^2$, một dạng toàn phương lồi.&lt;/li&gt;
    &lt;li&gt;$\nabla L = \tfrac2n X^T(Xw - y)$; $\nabla L = 0$ chính là phương trình chuẩn.&lt;/li&gt;
    &lt;li&gt;Hạ gradient: sai số nhân với $I - \eta H$ mỗi bước; hội tụ khi $\eta &amp;lt; 2/\lambda_{\max}$, tốc độ do số điều kiện $\kappa$ quyết định.&lt;/li&gt;
    &lt;li&gt;Nhiều đầu ra: $W = (X^TX)^{-1}X^TY$, dùng chung một phân rã.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Vectơ đặc trưng, ma trận dữ liệu và độ tương tự cosin</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter14/14_01_Vecto_Dac_Trung_Ma_Tran_Du_Lieu_Va_Do_Tuong_Tu_Cosin/"/>
   <updated>2026-01-14T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter14/14_01_Vecto_Dac_Trung_Ma_Tran_Du_Lieu_Va_Do_Tuong_Tu_Cosin</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;biểu diễn dữ liệu bằng ma trận $X$ cỡ $n \times d$ (mỗi hàng là một mẫu, mỗi cột là một đặc trưng);&lt;/li&gt;
    &lt;li&gt;tính ma trận Gram $XX^T$ và ma trận độ tương tự cosin của các mẫu;&lt;/li&gt;
    &lt;li&gt;giải thích khi nào nên dùng cosin thay cho khoảng cách Euclid, và liên hệ với tìm kiếm bằng vectơ biểu diễn (embedding).&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Bốn văn bản ngắn được mô tả bằng số lần xuất hiện của ba từ “vectơ”, “ma trận”, “xác suất”:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Văn bản&lt;/th&gt;
      &lt;th&gt;vectơ&lt;/th&gt;
      &lt;th&gt;ma trận&lt;/th&gt;
      &lt;th&gt;xác suất&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;$a$&lt;/td&gt;
      &lt;td&gt;$1$&lt;/td&gt;
      &lt;td&gt;$2$&lt;/td&gt;
      &lt;td&gt;$0$&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;$b$&lt;/td&gt;
      &lt;td&gt;$2$&lt;/td&gt;
      &lt;td&gt;$4$&lt;/td&gt;
      &lt;td&gt;$0$&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;$c$&lt;/td&gt;
      &lt;td&gt;$0$&lt;/td&gt;
      &lt;td&gt;$1$&lt;/td&gt;
      &lt;td&gt;$1$&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;$d$&lt;/td&gt;
      &lt;td&gt;$3$&lt;/td&gt;
      &lt;td&gt;$0$&lt;/td&gt;
      &lt;td&gt;$1$&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Văn bản $b$ chính là $a$ viết dài gấp đôi. Theo khoảng cách Euclid, $\lVert a - b \rVert = \sqrt5 \approx 2{,}24$ nhưng $\lVert a - c \rVert = \sqrt3 \approx 1{,}73$: $c$ “gần” $a$ hơn $b$. Điều đó sai với trực giác về nội dung. Ta cần một thước đo chỉ quan tâm đến &lt;strong&gt;hướng&lt;/strong&gt; của vectơ.&lt;/p&gt;

&lt;h2 id=&quot;ma-trận-dữ-liệu&quot;&gt;Ma trận dữ liệu&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa.&lt;/strong&gt; Với $n$ mẫu, mỗi mẫu là một &lt;strong&gt;vectơ đặc trưng&lt;/strong&gt; $x_i \in \mathbb{R}^d$, &lt;strong&gt;ma trận dữ liệu&lt;/strong&gt; là $X \in \mathbb{R}^{n \times d}$ có hàng thứ $i$ là $x_i^T$. Cột thứ $j$ của $X$ chứa giá trị của đặc trưng $j$ trên mọi mẫu.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Quy ước “hàng là mẫu” là chuẩn trong NumPy, pandas, scikit-learn và PyTorch. Nhiều phép toán trên toàn bộ dữ liệu trở thành một phép nhân ma trận:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;$Xw$ là vectơ gồm $n$ tích vô hướng $x_i^Tw$ (dự đoán của một mô hình tuyến tính trên mọi mẫu, Bài 14-02);&lt;/li&gt;
  &lt;li&gt;$\tfrac1n\mathbf{1}^TX$ là vectơ trung bình của các đặc trưng;&lt;/li&gt;
  &lt;li&gt;$X^TX$ (cỡ $d \times d$) so sánh các &lt;strong&gt;đặc trưng&lt;/strong&gt;; sau khi trừ trung bình, chia $n - 1$ là ma trận hiệp phương sai (Bài 11-05);&lt;/li&gt;
  &lt;li&gt;$XX^T$ (cỡ $n \times n$) so sánh các &lt;strong&gt;mẫu&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa.&lt;/strong&gt; &lt;strong&gt;Ma trận Gram&lt;/strong&gt; của các mẫu là $K = XX^T$, với $K_{ij} = x_i^Tx_j$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;$K$ đối xứng và nửa xác định dương (Bài 10-04), và $K_{ii} = \lVert x_i \rVert^2$. Khoảng cách Euclid cũng đọc được từ $K$: $\lVert x_i - x_j \rVert^2 = K_{ii} - 2K_{ij} + K_{jj}$.&lt;/p&gt;

&lt;h2 id=&quot;độ-tương-tự-cosin&quot;&gt;Độ tương tự cosin&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa.&lt;/strong&gt; &lt;strong&gt;Độ tương tự cosin&lt;/strong&gt; của hai vectơ khác $0$ là&lt;/p&gt;

  &lt;p&gt;\(\cos(x, y) = \frac{x^Ty}{\lVert x \rVert\,\lVert y \rVert} \in [-1, 1].\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Theo Bài 01-02, đây là cosin của góc giữa $x$ và $y$. Nó bằng $1$ khi hai vectơ cùng hướng, $0$ khi vuông góc, $-1$ khi ngược hướng, và &lt;strong&gt;không đổi khi nhân một vectơ với số dương&lt;/strong&gt;. Nếu chuẩn hoá mỗi hàng của $X$ thành vectơ đơn vị (được $\hat X$), ma trận độ tương tự cosin chính là ma trận Gram $\hat X\hat X^T$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (ví dụ mở đầu).&lt;/strong&gt; Với $X$ là bảng trên,&lt;/p&gt;

\[XX^T = \begin{bmatrix} 5 &amp;amp; 10 &amp;amp; 2 &amp;amp; 3 \\ 10 &amp;amp; 20 &amp;amp; 4 &amp;amp; 6 \\ 2 &amp;amp; 4 &amp;amp; 2 &amp;amp; 1 \\ 3 &amp;amp; 6 &amp;amp; 1 &amp;amp; 10 \end{bmatrix}, \qquad \hat X\hat X^T \approx \begin{bmatrix} 1 &amp;amp; 1 &amp;amp; 0{,}632 &amp;amp; 0{,}424 \\ 1 &amp;amp; 1 &amp;amp; 0{,}632 &amp;amp; 0{,}424 \\ 0{,}632 &amp;amp; 0{,}632 &amp;amp; 1 &amp;amp; 0{,}224 \\ 0{,}424 &amp;amp; 0{,}424 &amp;amp; 0{,}224 &amp;amp; 1 \end{bmatrix}.\]

  &lt;p&gt;Chẳng hạn $\cos(a, c) = \tfrac{2}{\sqrt5\sqrt2} = \tfrac{2}{\sqrt{10}} \approx 0{,}632$. Theo cosin, $b$ giống hệt $a$ (cosin bằng $1$), rồi tới $c$, cuối cùng là $d$. Thứ tự này khớp trực giác về nội dung.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Liên hệ với khoảng cách.&lt;/strong&gt; Với vectơ đơn vị, $\lVert \hat x - \hat y \rVert^2 = 2 - 2\cos(x, y)$: trên mặt cầu đơn vị, xếp hạng theo cosin và theo khoảng cách Euclid là một. Vì vậy nhiều hệ thống chuẩn hoá embedding rồi dùng tích vô hướng.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-tìm-kiếm-ngữ-nghĩa-bằng-embedding&quot;&gt;Ứng dụng: tìm kiếm ngữ nghĩa bằng embedding&lt;/h2&gt;

&lt;p&gt;Các mô hình ngôn ngữ hiện đại biến mỗi câu, đoạn văn hay ảnh thành một vectơ &lt;strong&gt;embedding&lt;/strong&gt; $e \in \mathbb{R}^d$ (thường $d$ từ vài trăm đến vài nghìn), sao cho nội dung giống nhau cho vectơ gần cùng hướng. Tìm kiếm ngữ nghĩa (và hệ RAG cung cấp ngữ cảnh cho chatbot) làm như sau: lập ma trận $\hat E$ gồm embedding đã chuẩn hoá của mọi tài liệu, tính embedding $\hat q$ của câu hỏi, rồi lấy các tài liệu có giá trị lớn nhất trong vectơ $\hat E\hat q$, tức cosin lớn nhất. Một phép nhân ma trận–vectơ thay cho việc so khớp từ khoá. Cơ chế attention trong Transformer (khoá Học sâu, Chương 07) cũng dựa trên tích vô hướng giữa các vectơ truy vấn và khoá.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: độ tương tự cosin&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo các vectơ bài báo và truy vấn q, so sánh cosin với khoảng cách.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter14/cosin.html&quot; title=&quot;Minh hoạ: độ tương tự cosin&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter14/cosin.html&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-độ-tương-tự-cosin-giữa-các-vectơ-biểu-diễn&quot;&gt;Video ngắn: Độ tương tự cosin giữa các vectơ biểu diễn&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/cosine-embedding.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Văn bản a = (1; 2; 0), b = (2; 4; 0) = 2a, c = (0; 1; 1), d = (3; 0; 1). Theo khoảng cách Euclid, c gần a hơn b (√3 &amp;lt; √5), trái trực giác. Chuẩn hoá về mặt cầu đơn vị: a và b trùng nhau. Cosin: cos(a, b) = 1, cos(a, c) ≈ 0,63, cos(a, d) ≈ 0,42. Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Với $X$ của Ví dụ 1, dùng ma trận Gram tính $\lVert c - d \rVert$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\lVert c - d \rVert^2 = K_{33} - 2K_{34} + K_{44} = 2 - 2 + 10 = 10$, nên $\lVert c - d \rVert = \sqrt{10}$. Kiểm tra trực tiếp: $c - d = (-3, 1, 0)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Chứng minh $\cos(x, y)$ không đổi khi thay $x$ bằng $tx$ với $t &amp;gt; 0$, và đổi dấu khi $t &amp;lt; 0$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\cos(tx, y) = \dfrac{t\,x^Ty}{\lvert t\rvert\,\lVert x \rVert\,\lVert y \rVert} = \operatorname{sign}(t)\cos(x, y)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Chứng minh với $x, y$ đơn vị, $\lVert x - y \rVert^2 = 2 - 2\cos(x, y)$. Suy ra: trong các vectơ đơn vị, vectơ gần $q$ nhất theo Euclid cũng là vectơ có cosin lớn nhất với $q$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\lVert x - y \rVert^2 = \lVert x \rVert^2 - 2x^Ty + \lVert y \rVert^2 = 2 - 2x^Ty$, với $x^Ty = \cos(x, y)$. Hàm $c \mapsto 2 - 2c$ giảm, nên cực tiểu khoảng cách tương ứng cực đại cosin.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (lập trình).&lt;/strong&gt; Với $X$ cỡ $n \times d$ trong NumPy, viết một dòng tính ma trận cosin $n \times n$, và một hàm trả về chỉ số $k$ mẫu giống vectơ truy vấn $q$ nhất.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

`Xh = X / np.linalg.norm(X, axis=1, keepdims=True)`; `S = Xh @ Xh.T`. Với truy vấn: `s = Xh @ (q / np.linalg.norm(q))`, rồi `np.argsort(-s)[:k]`.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Ma trận dữ liệu $X \in \mathbb{R}^{n \times d}$: hàng là mẫu, cột là đặc trưng.&lt;/li&gt;
    &lt;li&gt;Ma trận Gram $XX^T$ chứa mọi tích vô hướng giữa các mẫu; $\lVert x_i - x_j \rVert^2 = K_{ii} - 2K_{ij} + K_{jj}$.&lt;/li&gt;
    &lt;li&gt;Cosin $x^Ty/(\lVert x \rVert\lVert y \rVert)$ so sánh hướng, không phụ thuộc độ dài; với hàng đã chuẩn hoá, ma trận cosin là $\hat X\hat X^T$.&lt;/li&gt;
    &lt;li&gt;Tìm kiếm bằng embedding: một phép nhân $\hat E\hat q$ rồi lấy các giá trị lớn nhất.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Tensors and the Shape of Data</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter14/14_05_Tensor_Va_Hinh_Dang_Du_Lieu/"/>
   <updated>2026-01-14T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter14/14_05_Tensor_Va_Hinh_Dang_Du_Lieu</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;read the shapes of common data tensors: batches of vectors, batches of images, batches of token sequences;&lt;/li&gt;
    &lt;li&gt;use reshaping, axis permutation and broadcasting correctly;&lt;/li&gt;
    &lt;li&gt;write matrix products, dot products, traces and batched products with the Einstein summation convention (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;einsum&lt;/code&gt;);&lt;/li&gt;
    &lt;li&gt;check the shape at every step of an attention computation.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;The most common bug in machine-learning code is not a wrong formula but a &lt;strong&gt;wrong shape&lt;/strong&gt;: “shapes (32, 784) and (128, 784) not aligned”. This error is really a linear algebra question: the product $AB$ is defined only when the number of columns of $A$ equals the number of rows of $B$ (Lesson 03-01). Here $X$ has $32$ samples of $784$ features, and $W$ has $128$ rows and $784$ columns, so we must write $XW^T$, not $XW$ (Lesson 14-03). This lesson organises how to think about shapes when data has more than two dimensions.&lt;/p&gt;

&lt;h2 id=&quot;tensors-are-multidimensional-arrays&quot;&gt;Tensors are multidimensional arrays&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition.&lt;/strong&gt; In machine learning, a &lt;strong&gt;tensor&lt;/strong&gt; of order $p$ is an array of numbers $T$ indexed by $p$ indices $T_{i_1 i_2 \dots i_p}$, with $1 \le i_k \le n_k$. The tuple $(n_1, \dots, n_p)$ is its &lt;strong&gt;shape&lt;/strong&gt;, and each index is an &lt;strong&gt;axis&lt;/strong&gt;. A scalar is an order-$0$ tensor, a vector order $1$, a matrix order $2$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;(In physics and differential geometry “tensor” also means a multilinear map with a change-of-coordinates rule; here we use only the array meaning.)&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Data&lt;/th&gt;
      &lt;th&gt;Typical shape&lt;/th&gt;
      &lt;th&gt;Meaning of the axes&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Batch of feature vectors&lt;/td&gt;
      &lt;td&gt;$(N, d)$&lt;/td&gt;
      &lt;td&gt;sample, feature (Lesson 14-01)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Colour image&lt;/td&gt;
      &lt;td&gt;$(3, H, W)$&lt;/td&gt;
      &lt;td&gt;colour channel, row, column&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Batch of images (PyTorch)&lt;/td&gt;
      &lt;td&gt;$(N, 3, H, W)$&lt;/td&gt;
      &lt;td&gt;sample, channel, row, column&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Batch of embedded sentences&lt;/td&gt;
      &lt;td&gt;$(N, T, d)$&lt;/td&gt;
      &lt;td&gt;sample, token position, embedding dimension&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Video&lt;/td&gt;
      &lt;td&gt;$(N, F, 3, H, W)$&lt;/td&gt;
      &lt;td&gt;sample, frame, channel, row, column&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;A batch of $32$ RGB images of $224 \times 224$ has shape $(32, 3, 224, 224)$, holding $32 \cdot 3 \cdot 224 \cdot 224 = 4{,}816{,}896$ numbers; as 32-bit floats that is about $19.3$ MB.&lt;/p&gt;

&lt;h2 id=&quot;reshaping-and-permuting-axes&quot;&gt;Reshaping and permuting axes&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Reshape&lt;/strong&gt; rearranges the entries in storage order (row-major in NumPy and PyTorch) into a new shape with the same total number of entries. For example, “flatten” a batch of images $(N, 1, 28, 28)$ into $(N, 784)$ to feed a fully connected layer. This is exactly the isomorphism $\mathbb{R}^{28 \times 28} \cong \mathbb{R}^{784}$ (Lesson 06-04): the same data, indexed differently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Permuting axes&lt;/strong&gt; (transpose, permute) generalises the transpose: it reorders the axes, for example $(N, H, W, 3) \to (N, 3, H, W)$ when converting between TensorFlow and PyTorch layouts. Reshaping and permuting are &lt;strong&gt;not&lt;/strong&gt; interchangeable: reshaping a $2 \times 3$ matrix into $3 \times 2$ is different from transposing it.&lt;/p&gt;

&lt;h2 id=&quot;broadcasting&quot;&gt;Broadcasting&lt;/h2&gt;

&lt;p&gt;When adding two tensors of different shapes, NumPy and PyTorch &lt;strong&gt;broadcast&lt;/strong&gt;: shapes are compared from the last axis backwards; two axes are compatible if they are equal or one of them is $1$ (or missing), and a size-$1$ axis is repeated to match.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; With $A = \begin{bmatrix} 0 &amp;amp; 1 &amp;amp; 2 \\ 3 &amp;amp; 4 &amp;amp; 5 \end{bmatrix}$ of shape $(2, 3)$:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$b = (10, 20, 30)$ of shape $(3,)$ is added to &lt;strong&gt;each row&lt;/strong&gt;: $A + b = \begin{bmatrix} 10 &amp;amp; 21 &amp;amp; 32 \\ 13 &amp;amp; 24 &amp;amp; 35 \end{bmatrix}$. This is the $XW^T + \mathbf{1}b^T$ of Lesson 14-03.&lt;/li&gt;
    &lt;li&gt;$c$ of shape $(2, 1)$ with values $1, 2$ is added to &lt;strong&gt;each column&lt;/strong&gt;: $A + c = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 3 \\ 5 &amp;amp; 6 &amp;amp; 7 \end{bmatrix}$.&lt;/li&gt;
    &lt;li&gt;Adding $A$ to a vector of shape $(2,)$ raises an error, since the last axes $3 \ne 2$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;p&gt;Algebraically, broadcasting is shorthand for an outer product with the all-ones vector: $A + \mathbf{1}b^T$ and $A + c\mathbf{1}^T$. Normalising the rows of $X$ in Lesson 14-01, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;X / norms[:, None]&lt;/code&gt;, is broadcasting too.&lt;/p&gt;

&lt;h2 id=&quot;the-einstein-summation-convention&quot;&gt;The Einstein summation convention&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;einsum&lt;/code&gt; describes an operation by naming indices: an index that appears in the inputs but not in the output is &lt;strong&gt;summed over&lt;/strong&gt;.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Expression&lt;/th&gt;
      &lt;th&gt;Formula&lt;/th&gt;
      &lt;th&gt;Meaning&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&apos;ij,j-&amp;gt;i&apos;&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;$y_i = \sum_j A_{ij}x_j$&lt;/td&gt;
      &lt;td&gt;$Ax$&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&apos;ij,jk-&amp;gt;ik&apos;&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;$C_{ik} = \sum_j A_{ij}B_{jk}$&lt;/td&gt;
      &lt;td&gt;$AB$&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&apos;i,i-&amp;gt;&apos;&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;$\sum_i x_iy_i$&lt;/td&gt;
      &lt;td&gt;$x^Ty$&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&apos;i,j-&amp;gt;ij&apos;&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;$x_iy_j$&lt;/td&gt;
      &lt;td&gt;outer product $xy^T$&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&apos;ii-&amp;gt;&apos;&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;$\sum_i A_{ii}$&lt;/td&gt;
      &lt;td&gt;trace&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&apos;ij,ij-&amp;gt;&apos;&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;$\sum_{ij} A_{ij}B_{ij}$&lt;/td&gt;
      &lt;td&gt;$\operatorname{tr}(A^TB)$, the Frobenius inner product&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&apos;bij,bjk-&amp;gt;bik&apos;&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;$C_{bik} = \sum_j A_{bij}B_{bjk}$&lt;/td&gt;
      &lt;td&gt;batched matrix product&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;For example, with $A$ from Example 1, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;einsum(&apos;ij,j-&amp;gt;i&apos;, A, [1,1,1])&lt;/code&gt; gives the row sums $(3, 12)$, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;einsum(&apos;ij,ij-&amp;gt;&apos;, A, A)&lt;/code&gt; gives $\lVert A \rVert_F^2 = 55$.&lt;/p&gt;

&lt;h2 id=&quot;application-checking-shapes-in-attention&quot;&gt;Application: checking shapes in attention&lt;/h2&gt;

&lt;p&gt;An attention layer takes $X$ of shape $(B, T, d)$: $B$ sentences of $T$ tokens, each token a $d$-dimensional vector. Follow the shapes:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;$Q = XW_Q$, $K = XW_K$, $V = XW_V$ with $W$ of shape $(d, d_k)$: each tensor is $(B, T, d_k)$. The product acts on the last axis and broadcasts over $B, T$.&lt;/li&gt;
  &lt;li&gt;Scores $S$ = &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;einsum(&apos;btd,bsd-&amp;gt;bts&apos;, Q, K)&lt;/code&gt; $/\sqrt{d_k}$: shape $(B, T, T)$, with $S_{bts} = q_{bt}^Tk_{bs}$ a dot product (Lesson 14-01).&lt;/li&gt;
  &lt;li&gt;Softmax over the last axis, then &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;einsum(&apos;bts,bsd-&amp;gt;btd&apos;, A, V)&lt;/code&gt;: back to $(B, T, d_k)$, each output a convex combination of value vectors.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With $B = 8$ and $T = 1024$, the score tensor has $8 \cdot 1024^2 = 8{,}388{,}608$ entries for &lt;strong&gt;each&lt;/strong&gt; attention head: the cost quadratic in sequence length is why more efficient attention variants are sought.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: tensors and data shapes&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Change the shape, pick an element, fiber or slice, and see its memory position.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter14/tensor.html?lang=en&quot; title=&quot;Interactive: tensors and data shapes&quot; loading=&quot;lazy&quot; style=&quot;height: 760px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter14/tensor.html?lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; A batch of $16$ videos, each $8$ RGB frames of $112 \times 112$. Write its shape in the PyTorch convention $(N, F, C, H, W)$ and the number of entries. After reshaping to $(N \cdot F, C, H, W)$ to process each frame separately, what is the shape?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$(16, 8, 3, 112, 112)$, with $16 \cdot 8 \cdot 3 \cdot 112^2 = 4{,}816{,}896$ entries (the same as the batch of 32 images of $224 \times 224$, since $16 \cdot 8 \cdot 112^2 = 32 \cdot 224^2$). After reshaping: $(128, 3, 112, 112)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; With $A$ of shape $(5, 1, 3)$ and $B$ of shape $(4, 3)$, what is the shape of $A + B$? And of $A + C$ with $C$ of shape $(5, 4)$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Comparing from the last axis: $(5, 1, 3)$ and $(\ , 4, 3)$ give $(5, 4, 3)$. With $C$: $(5, 1, 3)$ and $(\ , 5, 4)$; the last axes $3 \ne 4$, so it is an error.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Write with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;einsum&lt;/code&gt;: (a) $x^TAy$; (b) the Gram matrix $XX^T$ (Lesson 14-01); (c) for a batch $X$ of shape $(B, N, d)$, the Gram matrix of each batch element.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

(a) `einsum(&apos;i,ij,j-&amp;gt;&apos;, x, A, y)`. (b) `einsum(&apos;id,jd-&amp;gt;ij&apos;, X, X)`. (c) `einsum(&apos;bid,bjd-&amp;gt;bij&apos;, X, X)`, of shape $(B, N, N)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Explain, using $A$ from Example 1, why reshaping a $2 \times 3$ matrix to $3 \times 2$ differs from transposing it.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Reshape reads the entries row by row, $0, 1, 2, 3, 4, 5$, and refills: $\begin{bmatrix} 0 &amp;amp; 1 \\ 2 &amp;amp; 3 \\ 4 &amp;amp; 5 \end{bmatrix}$. Transposing swaps rows and columns: $A^T = \begin{bmatrix} 0 &amp;amp; 3 \\ 1 &amp;amp; 4 \\ 2 &amp;amp; 5 \end{bmatrix}$. The two matrices differ.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;A tensor (in the machine-learning sense) is a multidimensional array; its shape gives the meaning and size of each axis.&lt;/li&gt;
    &lt;li&gt;Reshape keeps storage order, permuting axes swaps the roles of indices; the two are different.&lt;/li&gt;
    &lt;li&gt;Broadcasting compares shapes from the last axis and repeats size-$1$ axes; algebraically it adds an outer product with $\mathbf{1}$.&lt;/li&gt;
    &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;einsum&lt;/code&gt; expresses every matrix product, dot product, trace and batched product; tracking shapes is a quick check on any formula.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Recommender Systems by Matrix Factorisation</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter14/14_04_He_Goi_Y_Bang_Phan_Ra_Ma_Tran/"/>
   <updated>2026-01-14T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter14/14_04_He_Goi_Y_Bang_Phan_Ra_Ma_Tran</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;model a ratings matrix by a low-rank factorisation $R \approx UV^T$ and interpret the latent vectors;&lt;/li&gt;
    &lt;li&gt;use the low-rank assumption to fill missing entries in a small example;&lt;/li&gt;
    &lt;li&gt;write the optimisation problem over the observed entries and the alternating least squares (ALS) algorithm, recognising each step as a ridge regression;&lt;/li&gt;
    &lt;li&gt;relate this to the truncated SVD and the Eckart–Young theorem.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Four users rate four films (scale $1$–$5$; ? means not yet watched):&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt; &lt;/th&gt;
      &lt;th&gt;Film 1&lt;/th&gt;
      &lt;th&gt;Film 2&lt;/th&gt;
      &lt;th&gt;Film 3&lt;/th&gt;
      &lt;th&gt;Film 4&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;An&lt;/td&gt;
      &lt;td&gt;$5$&lt;/td&gt;
      &lt;td&gt;$4$&lt;/td&gt;
      &lt;td&gt;$1$&lt;/td&gt;
      &lt;td&gt;?&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Bình&lt;/td&gt;
      &lt;td&gt;?&lt;/td&gt;
      &lt;td&gt;$2$&lt;/td&gt;
      &lt;td&gt;$5$&lt;/td&gt;
      &lt;td&gt;$4$&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Chi&lt;/td&gt;
      &lt;td&gt;$3$&lt;/td&gt;
      &lt;td&gt;$3$&lt;/td&gt;
      &lt;td&gt;$3$&lt;/td&gt;
      &lt;td&gt;$3$&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Dũng&lt;/td&gt;
      &lt;td&gt;$4.2$&lt;/td&gt;
      &lt;td&gt;$3.6$&lt;/td&gt;
      &lt;td&gt;?&lt;/td&gt;
      &lt;td&gt;$2.4$&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Should we recommend Film 3 to Dũng? If the entries had no relation to one another, there would be no way to guess. But human taste is not random: Films 1 and 2 look like action films, Films 3 and 4 like romances; An likes action, Bình likes romance. If each user and each film is described by &lt;strong&gt;a few numbers&lt;/strong&gt;, the ratings matrix has &lt;strong&gt;low rank&lt;/strong&gt;, and that is exactly what lets us fill the gaps.&lt;/p&gt;

&lt;h2 id=&quot;the-latent-factor-model&quot;&gt;The latent factor model&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition.&lt;/strong&gt; For a ratings matrix $R \in \mathbb{R}^{m \times n}$ ($m$ users, $n$ items), a rank-$k$ &lt;strong&gt;latent factor model&lt;/strong&gt; assigns user $i$ a vector $u_i \in \mathbb{R}^k$ and item $j$ a vector $v_j \in \mathbb{R}^k$, and predicts&lt;/p&gt;

  &lt;p&gt;\(\hat r_{ij} = u_i^Tv_j, \qquad \text{i.e. } \hat R = UV^T,\ U \in \mathbb{R}^{m \times k},\ V \in \mathbb{R}^{n \times k}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Each coordinate of $v_j$ measures how much the item has some “property”, and the matching coordinate of $u_i$ measures how much the user likes that property. The predicted rating is a dot product: when taste matches properties, the score is high (Lesson 14-01). The matrix $UV^T$ has rank $\le k$ (Lesson 14-03, Theorem 1). The model has $(m + n)k$ parameters instead of $mn$ entries, far fewer when $k \ll m, n$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (the full table).&lt;/strong&gt; The table in the motivating example was generated from $k = 2$ factors (action, romance):&lt;/p&gt;

\[U = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \\ 0.5 &amp;amp; 0.5 \\ 0.8 &amp;amp; 0.2 \end{bmatrix}, \quad
V = \begin{bmatrix} 5 &amp;amp; 1 \\ 4 &amp;amp; 2 \\ 1 &amp;amp; 5 \\ 2 &amp;amp; 4 \end{bmatrix}, \quad
UV^T = \begin{bmatrix} 5 &amp;amp; 4 &amp;amp; 1 &amp;amp; 2 \\ 1 &amp;amp; 2 &amp;amp; 5 &amp;amp; 4 \\ 3 &amp;amp; 3 &amp;amp; 3 &amp;amp; 3 \\ 4.2 &amp;amp; 3.6 &amp;amp; 1.8 &amp;amp; 2.4 \end{bmatrix}.\]

  &lt;p&gt;This matrix has rank $2$ (its nonzero singular values are $\approx 12.04$ and $4.75$). The missing entries are predicted as An–Film 4: $2$; Bình–Film 1: $1$; Dũng–Film 3: $1.8$. Film 3 should not be recommended to Dũng.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (a new user).&lt;/strong&gt; With $V$ as above, a new user rates Film 1 as $5$ and Film 3 as $2$. Find $u$ with $5u_1 + u_2 = 5$ and $u_1 + 5u_2 = 2$:&lt;/p&gt;

\[\begin{bmatrix} 5 &amp;amp; 1 \\ 1 &amp;amp; 5 \end{bmatrix} u = \begin{bmatrix} 5 \\ 2 \end{bmatrix} \implies u = \tfrac1{24}\begin{bmatrix} 23 \\ 5 \end{bmatrix} \approx (0.958, 0.208).\]

  &lt;p&gt;Predicted Film 2: $4 \cdot \tfrac{23}{24} + 2 \cdot \tfrac{5}{24} = 4.25$; Film 4: $2 \cdot \tfrac{23}{24} + 4 \cdot \tfrac{5}{24} = 2.75$. When the user has rated more than $k$ films, the system becomes a least-squares problem (Chapter 08).&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;learning-u-and-v-from-incomplete-data&quot;&gt;Learning $U$ and $V$ from incomplete data&lt;/h2&gt;

&lt;p&gt;Real data is very sparse (each user has seen a tiny fraction of the catalogue) and noisy. Let $\Omega$ be the set of known entries. We solve&lt;/p&gt;

\[\min_{U, V}\ \sum_{(i, j) \in \Omega} \left(r_{ij} - u_i^Tv_j\right)^2 + \lambda\left(\lVert U \rVert_F^2 + \lVert V \rVert_F^2\right).\]

&lt;p&gt;This function is not convex in $(U, V)$ jointly, but it is least squares once either factor is fixed.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (one ALS step).&lt;/strong&gt; Fix $V$. For user $i$, let $V_i$ be the matrix of rows $v_j^T$ of the items user $i$ has rated, and $r_i$ the vector of those ratings. Then the optimal $u_i$ solves the ridge regression&lt;/p&gt;

\[(V_i^TV_i + \lambda I)\,u_i = V_i^Tr_i.\]

  &lt;p&gt;Similarly for each $v_j$ with $U$ fixed.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; With $V$ fixed, the objective splits into a sum of independent terms, one per $u_i$: $\lVert V_iu_i - r_i \rVert^2 + \lambda\lVert u_i \rVert^2$ (plus constants). This is ridge regression with design matrix $V_i$; setting the gradient to $0$ gives the equation above (Lesson 14-02, Exercise 3), and $V_i^TV_i + \lambda I$ is positive definite for $\lambda &amp;gt; 0$, so the solution is unique. $\blacksquare$&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;The ALS algorithm:&lt;/strong&gt; initialise $V$ with small random values; repeat: solve for every $u_i$ (each a $k \times k$ system), then for every $v_j$. No step increases the objective, and the subproblems are independent, so they run in parallel. An alternative is stochastic gradient descent over the entries $(i, j) \in \Omega$.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Relation to the SVD.&lt;/strong&gt; If every entry is known and $\lambda = 0$, the problem is $\min \lVert R - UV^T \rVert_F$ over rank $\le k$; by Eckart–Young (Lesson 11-03) the solution is the truncated SVD $R_k = U_k\Sigma_kV_k^T$, for instance with $U = U_k\Sigma_k^{1/2}$, $V = V_k\Sigma_k^{1/2}$. With missing data there is no closed form, but a simple approach is to fill missing entries with average ratings and take the truncated SVD.&lt;/p&gt;

&lt;h2 id=&quot;application-the-netflix-prize&quot;&gt;Application: the Netflix Prize&lt;/h2&gt;

&lt;p&gt;In 2006 Netflix released about 100 million ratings by 480 thousand users of 17 thousand films (only about 1% of the entries known) and offered a million dollars to anyone who could cut the prediction error by 10%. The leading teams all relied on matrix factorisation as above (plus per-user and per-film bias terms and time effects); the 2009 winning team blended hundreds of models whose core was latent factors. Today the user and item “embeddings” in commercial recommender systems are direct descendants of $u_i$ and $v_j$.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: a recommender via matrix factorization&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Click cells to edit ratings, drag rank k and λ, and see the predicted blanks.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter14/goi_y.html?lang=en&quot; title=&quot;Interactive: a recommender via matrix factorization&quot; loading=&quot;lazy&quot; style=&quot;height: 820px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter14/goi_y.html?lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; In the motivating example, suppose the rows of An and Bình are fully known ($5, 4, 1, 2$ and $1, 2, 5, 4$) and the matrix has rank $2$. Without using $U, V$, deduce the Dũng–Film 3 entry from Dũng’s first two columns alone.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The rows of An and Bình are independent, so every other row is a combination of them: Dũng $= a \cdot$ An $+ b \cdot$ Bình. From $5a + b = 4.2$ and $4a + 2b = 3.6$ we get $a = 0.8$, $b = 0.2$. The entry is $0.8 \cdot 1 + 0.2 \cdot 5 = 1.8$; check column 4: $0.8 \cdot 2 + 0.2 \cdot 4 = 2.4$, correct.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; The factorisation $R = UV^T$ is not unique. Show that for any invertible $A \in \mathbb{R}^{k \times k}$ the pair $(UA, VA^{-T})$ gives the same $R$. What does this say about “naming” the latent factors?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$(UA)(VA^{-T})^T = UAA^{-1}V^T = UV^T$. The factors are determined only up to a change of basis in $\mathbb{R}^k$ (Lesson 05-06), so &quot;action/romance&quot; axes do not appear by themselves; we can interpret them only after choosing a convenient basis (regularisation with $\lambda$ reduces but does not remove this freedom).

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; With $V$ from Example 1 and $\lambda = 1$, a user has rated only Film 1, as $5$. Compute $u$ by Theorem 1 and predict the rating of Film 3. Compared with $\lambda = 0$, why is $\lambda &amp;gt; 0$ needed here?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$V_i = \begin{bmatrix} 5 &amp;amp; 1 \end{bmatrix}$, $V_i^TV_i + I = \begin{bmatrix} 26 &amp;amp; 5 \\ 5 &amp;amp; 2 \end{bmatrix}$, $V_i^Tr_i = (25, 5)$. Solving gives $u = \tfrac{1}{27}(25, 5) \approx (0.926, 0.185)$. Predicted Film 3: $(25 + 25)/27 \approx 1.85$. With $\lambda = 0$, $V_i^TV_i$ has rank $1$, so infinitely many $u$ fit the single rating exactly; $\lambda &amp;gt; 0$ penalises the norm of $u$, making the solution unique (shrinking it towards $0$ in the direction the data says nothing about).

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (programming).&lt;/strong&gt; Download the MovieLens 100K dataset and hold out 20% of the ratings as a test set. Fill missing training entries with each film’s mean, use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.svd&lt;/code&gt; to take a rank-$k$ approximation, and measure test RMSE for $k = 2, 5, 10, 20, 50$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Hint: `U, s, Vt = np.linalg.svd(R_filled, full_matrices=False)`; `Rk = U[:, :k] * s[:k] @ Vt[:k]`; RMSE $= \sqrt{\operatorname{mean}((R_k[i, j] - r_{ij})^2)}$ over the test entries. RMSE usually falls and then rises again for large $k$ (overfitting the filled-in values), with the best $k$ between a few and a few dozen; regularised ALS usually does better.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Recommenders assume the ratings matrix is close to low rank: $\hat r_{ij} = u_i^Tv_j$, $\hat R = UV^T$.&lt;/li&gt;
    &lt;li&gt;Low rank lets us fill gaps: a new row is a linear combination of known rows.&lt;/li&gt;
    &lt;li&gt;Train on the known entries; ALS alternates small ridge regressions $(V_i^TV_i + \lambda I)u_i = V_i^Tr_i$.&lt;/li&gt;
    &lt;li&gt;Complete data with $\lambda = 0$: the solution is the truncated SVD (Eckart–Young).&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>A Neural Network Layer Is a Linear Transformation</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter14/14_03_Mot_Lop_Mang_No_Ron_La_Phep_Bien_Doi_Tuyen_Tinh/"/>
   <updated>2026-01-14T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter14/14_03_Mot_Lop_Mang_No_Ron_La_Phep_Bien_Doi_Tuyen_Tinh</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;write a neural network layer $y = \sigma(Wx + b)$ and its batched form $\sigma(XW^T + \mathbf{1}b^T)$, and count its parameters;&lt;/li&gt;
    &lt;li&gt;prove that stacking linear layers (without activations) still gives an affine map;&lt;/li&gt;
    &lt;li&gt;explain geometrically what the activation function does, through the XOR example;&lt;/li&gt;
    &lt;li&gt;compute the gradient of the loss with respect to $W$ as an outer product.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;The XOR problem: the four points $(0, 0)$ and $(1, 1)$ have label $0$, while $(1, 0)$ and $(0, 1)$ have label $1$. No straight line separates the two groups, so every linear model $w^Tx + c$ (with a threshold) fails. We will see that a network with just two hidden neurons solves it, and that the tiny “nonlinear” ingredient is essential: without it, stacking any number of layers is useless.&lt;/p&gt;

&lt;h2 id=&quot;one-layer&quot;&gt;One layer&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition.&lt;/strong&gt; A &lt;strong&gt;fully connected layer&lt;/strong&gt; from $\mathbb{R}^n$ to $\mathbb{R}^m$ is the map&lt;/p&gt;

\[x \mapsto \sigma(Wx + b), \qquad W \in \mathbb{R}^{m \times n},\ b \in \mathbb{R}^m,\]

  &lt;p&gt;where the &lt;strong&gt;activation function&lt;/strong&gt; $\sigma$ acts entrywise, for example $\operatorname{ReLU}(t) = \max(t, 0)$ or $\tanh t$. Row $i$ of $W$ together with $b_i$ holds the weights of &lt;strong&gt;neuron&lt;/strong&gt; $i$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The part $x \mapsto Wx + b$ is an &lt;strong&gt;affine&lt;/strong&gt; map: the linear map $W$ (Chapter 06) followed by the translation $b$. As in Lesson 12-01 it can be packed into one matrix using homogeneous coordinates: $\begin{bmatrix} W &amp;amp; b \end{bmatrix}\begin{bmatrix} x \\ 1 \end{bmatrix}$. The layer has $mn + m$ parameters; for example a layer from a $28 \times 28 = 784$-pixel image to $128$ neurons has $784 \cdot 128 + 128 = 100{,}480$ parameters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Batched form.&lt;/strong&gt; With a data matrix $X \in \mathbb{R}^{N \times n}$ (rows are samples, Lesson 14-01), the whole batch is computed at once: $H = \sigma(XW^T + \mathbf{1}b^T) \in \mathbb{R}^{N \times m}$. Libraries such as PyTorch store $W^T$ directly and add $b$ by broadcasting (Lesson 14-05). Almost all of a neural network’s running time is matrix products like this.&lt;/p&gt;

&lt;h2 id=&quot;without-activations-stacking-is-useless&quot;&gt;Without activations, stacking is useless&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; A composition of affine maps is affine. Specifically, $W_2(W_1x + b_1) + b_2 = (W_2W_1)x + (W_2b_1 + b_2)$. Moreover, if $W_1 \in \mathbb{R}^{k \times n}$ then $\operatorname{rank}(W_2W_1) \le k$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; The identity follows by expanding. The image of $W_2W_1$ is the image under $W_2$ of $\operatorname{Col}(W_1) \subseteq \mathbb{R}^k$, a space of dimension $\le k$, so the rank is $\le k$ (Lesson 05-05). $\blacksquare$&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;So a ten-layer deep network without $\sigma$ still represents only an affine function, drawing only straight decision boundaries; and a narrow hidden layer of $k$ neurons forces that function to have rank $\le k$ (the idea behind the linear autoencoder, which is equivalent to PCA, Lesson 11-05).&lt;/p&gt;

&lt;h2 id=&quot;activations-bend-space&quot;&gt;Activations bend space&lt;/h2&gt;

&lt;p&gt;Geometrically, $Wx + b$ turns the square grid into a grid of parallelograms (Lesson 06-06); ReLU then “folds” every negative coordinate to $0$, squashing regions of the plane onto the edges of the positive quadrant. Alternating the two operations over many layers distorts space enough that the classes become separable by a straight line at the last layer.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (XOR with two ReLU neurons).&lt;/strong&gt; Take&lt;/p&gt;

\[W = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}, \quad b = \begin{bmatrix} 0 \\ -1 \end{bmatrix}, \quad h = \operatorname{ReLU}(Wx + b), \quad \hat y = h_1 - 2h_2.\]

  &lt;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th&gt;$x$&lt;/th&gt;
        &lt;th&gt;$Wx + b$&lt;/th&gt;
        &lt;th&gt;$h$&lt;/th&gt;
        &lt;th&gt;$\hat y$&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
      &lt;tr&gt;
        &lt;td&gt;$(0, 0)$&lt;/td&gt;
        &lt;td&gt;$(0, -1)$&lt;/td&gt;
        &lt;td&gt;$(0, 0)$&lt;/td&gt;
        &lt;td&gt;$0$&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td&gt;$(1, 0)$&lt;/td&gt;
        &lt;td&gt;$(1, 0)$&lt;/td&gt;
        &lt;td&gt;$(1, 0)$&lt;/td&gt;
        &lt;td&gt;$1$&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td&gt;$(0, 1)$&lt;/td&gt;
        &lt;td&gt;$(1, 0)$&lt;/td&gt;
        &lt;td&gt;$(1, 0)$&lt;/td&gt;
        &lt;td&gt;$1$&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td&gt;$(1, 1)$&lt;/td&gt;
        &lt;td&gt;$(2, 1)$&lt;/td&gt;
        &lt;td&gt;$(2, 1)$&lt;/td&gt;
        &lt;td&gt;$0$&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;

  &lt;p&gt;The hidden layer sends the four points to three points $(0, 0)$, $(1, 0)$, $(2, 1)$ in $h$-space, where the line $h_1 - 2h_2 = \tfrac12$ separates the labels. Drop the ReLU and $\hat y = (x_1 + x_2) - 2(x_1 + x_2 - 1) = 2 - x_1 - x_2$, giving $2, 1, 1, 0$: wrong at $(0, 0)$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;gradient-with-respect-to-the-weight-matrix&quot;&gt;Gradient with respect to the weight matrix&lt;/h2&gt;

&lt;p&gt;Training needs $\partial L/\partial W$. With $z = Wx + b$ and $\delta = \partial L/\partial z \in \mathbb{R}^m$ (supplied by backpropagation from later layers), since $z_i = \sum_j W_{ij}x_j + b_i$ we get $\partial L/\partial W_{ij} = \delta_i x_j$, that is&lt;/p&gt;

\[\frac{\partial L}{\partial W} = \delta\, x^T, \qquad \frac{\partial L}{\partial b} = \delta, \qquad \frac{\partial L}{\partial x} = W^T\delta.\]

&lt;p&gt;The gradient with respect to $W$ is an &lt;strong&gt;outer product&lt;/strong&gt;, a rank-$1$ matrix; for a batch, $\partial L/\partial W = \Delta^TX$ is a sum of outer products. Backpropagating through the layer is multiplication by the &lt;strong&gt;transpose&lt;/strong&gt; $W^T$. These two matrix products account for most of the cost of training.&lt;/p&gt;

&lt;h2 id=&quot;application-projection-layers-in-transformers&quot;&gt;Application: projection layers in Transformers&lt;/h2&gt;

&lt;p&gt;In a Transformer (Deep Learning course, Chapter 07), each token is a vector $x \in \mathbb{R}^d$, multiplied by three learned matrices $W_Q, W_K, W_V$ to get query, key and value vectors. The attention score between two tokens is the dot product $q_i^Tk_j$ (Lesson 14-01), and the output is a linear combination of value vectors. Large language models have billions of parameters, but most of them sit in such matrices $W$; the LoRA fine-tuning technique learns only an extra low-rank matrix $\Delta W = BA$ (Lesson 11-03) per layer.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: one neural-network layer warps the plane&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag W and b and pick an activation to see how the grid is transformed.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter14/lop_no_ron.html?lang=en&quot; title=&quot;Interactive: one neural-network layer warps the plane&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter14/lop_no_ron.html?lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-a-neural-network-layer-warps-the-coordinate-grid&quot;&gt;Short video: A neural network layer warps the coordinate grid&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/layer-warps-grid.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;XOR: two points labeled 0 and two labeled 1; no straight line separates them. Step 1, the affine part x ↦ Wx + b with W = [1 1; 1 1], b = (0; −1): the grid is squashed onto one line because W has rank 1. Step 2, ReLU = max(t, 0): space is folded. In the hidden space h, the line h₁ − 2h₂ = 1/2 separates the two labels. Without ReLU only the affine map remains. Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Two linear layers $W_1 = \begin{bmatrix} 1 &amp;amp; 2 \\ 0 &amp;amp; 1 \end{bmatrix}$, $b_1 = (1, 0)$ and $W_2 = \begin{bmatrix} 1 &amp;amp; -1 \end{bmatrix}$, $b_2 = 3$. Write their composition as a single layer.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$W_2W_1 = \begin{bmatrix} 1 &amp;amp; 1 \end{bmatrix}$, $W_2b_1 + b_2 = 1 + 3 = 4$. The composition is $x \mapsto x_1 + x_2 + 4$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; How many parameters does a $784 \to 256 \to 64 \to 10$ network (three fully connected layers with biases) have? If all activations are removed, what is the largest possible rank of the equivalent map?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$784 \cdot 256 + 256 = 200{,}960$; $256 \cdot 64 + 64 = 16{,}448$; $64 \cdot 10 + 10 = 650$; total $218{,}058$. Without activations the network is $x \mapsto W_3W_2W_1x + c$ with a $10 \times 784$ matrix of rank $\le \min(784, 256, 64, 10) = 10$ (here limited by the number of outputs).

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Recheck Example 1 with $\hat y = h_1 - 2h_2$, and explain why $\sigma(t) = t$ (the identity) cannot solve XOR, whatever $W, b$ and output layer are chosen.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The table in Example 1 gives $0, 1, 1, 0$. With the identity $\sigma$, by Theorem 1 the network is an affine function $f(x) = a^Tx + c$. Then $f(0,0) + f(1,1) = 2c + a_1 + a_2 = f(1,0) + f(0,1)$, so the left side cannot be $0 + 0$ while the right side is $1 + 1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; For $L = \tfrac12\lVert Wx - t \rVert^2$, show that $\partial L/\partial W = (Wx - t)x^T$, and explain why one gradient step on a single sample changes $W$ by a rank-$1$ matrix.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Here $z = Wx$ and $\delta = \partial L/\partial z = Wx - t$, so $\partial L/\partial W = \delta x^T$. The update $W \leftarrow W - \eta\,\delta x^T$ adds an outer product $uv^T$ to $W$, which has rank $\le 1$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;One layer: $y = \sigma(Wx + b)$, an affine map followed by an entrywise activation; batched, $\sigma(XW^T + \mathbf{1}b^T)$.&lt;/li&gt;
    &lt;li&gt;Compositions of affine layers are affine: $(W_2W_1)x + (W_2b_1 + b_2)$; without $\sigma$ a deep network is no stronger than one layer.&lt;/li&gt;
    &lt;li&gt;ReLU folds space; two ReLU neurons suffice for XOR.&lt;/li&gt;
    &lt;li&gt;$\partial L/\partial W = \delta x^T$ (an outer product); backpropagation multiplies by $W^T$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Linear Regression in Matrix Form</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter14/14_02_Hoi_Quy_Tuyen_Tinh_Duoi_Dang_Ma_Tran/"/>
   <updated>2026-01-14T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter14/14_02_Hoi_Quy_Tuyen_Tinh_Duoi_Dang_Ma_Tran</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;write the linear regression model and the MSE loss in matrix form;&lt;/li&gt;
    &lt;li&gt;compute the gradient $\nabla L(w) = \tfrac2n X^T(Xw - y)$ and recognise $\nabla L = 0$ as the normal equations;&lt;/li&gt;
    &lt;li&gt;run gradient descent, choose the learning rate from the eigenvalues of $X^TX$, and explain why conditioning affects the speed of convergence.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Chapter 08 solved least squares with the normal equations and QR. In machine learning the same problem is seen as &lt;strong&gt;training a model&lt;/strong&gt;: choose parameters $w$ to minimise a loss function, usually by gradient descent. The reason is that with millions of samples and thousands of features, or with nonlinear models (Lesson 14-03), there is no closed form any more; but a gradient can always be computed. Linear regression is where the two approaches meet most clearly, and linear algebra tells us whether gradient descent runs fast or slowly.&lt;/p&gt;

&lt;p&gt;Data used in this lesson: the four points $(x, y) = (0, 1), (1, 3), (2, 4), (3, 6)$.&lt;/p&gt;

&lt;h2 id=&quot;model-and-loss&quot;&gt;Model and loss&lt;/h2&gt;

&lt;p&gt;With a data matrix $X \in \mathbb{R}^{n \times d}$ (Lesson 14-01; for an intercept, add a column of ones) and labels $y \in \mathbb{R}^n$, the linear model predicts $\hat y = Xw$. The &lt;strong&gt;mean squared error&lt;/strong&gt; (MSE) is&lt;/p&gt;

\[L(w) = \frac1n \lVert Xw - y \rVert^2 = \frac1n\left(w^TX^TXw - 2y^TXw + y^Ty\right).\]

&lt;p&gt;This is a quadratic form in $w$ (Lesson 10-03) with the positive semidefinite matrix $\tfrac1n X^TX$; so $L$ is convex and every stationary point is a minimum.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (gradient of the MSE).&lt;/strong&gt; $\nabla L(w) = \dfrac2n X^T(Xw - y)$ and the Hessian is $H = \dfrac2n X^TX$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; For any direction $h$, $L(w + h) = \tfrac1n\lVert (Xw - y) + Xh \rVert^2 = L(w) + \tfrac2n (Xw - y)^TXh + \tfrac1n \lVert Xh \rVert^2$. The part linear in $h$ is $\big(\tfrac2n X^T(Xw - y)\big)^T h$, so that is the gradient; the quadratic part is $\tfrac12 h^T\big(\tfrac2n X^TX\big)h$, giving the Hessian. $\blacksquare$&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Setting $\nabla L = 0$ gives $X^TXw = X^Ty$: exactly the &lt;strong&gt;normal equations&lt;/strong&gt; of Lesson 08-02. The two viewpoints (geometric: project $y$ onto $\operatorname{Col}(X)$; analytic: gradient equals $0$) give the same solution.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (closed form).&lt;/strong&gt; With a column of ones and a column of $x$,&lt;/p&gt;

\[X = \begin{bmatrix} 1 &amp;amp; 0 \\ 1 &amp;amp; 1 \\ 1 &amp;amp; 2 \\ 1 &amp;amp; 3 \end{bmatrix}, \quad X^TX = \begin{bmatrix} 4 &amp;amp; 6 \\ 6 &amp;amp; 14 \end{bmatrix}, \quad X^Ty = \begin{bmatrix} 14 \\ 29 \end{bmatrix}.\]

  &lt;p&gt;Solving gives $w = (1.1, 1.6)$, i.e. $\hat y = 1.1 + 1.6x$. The residual is $Xw - y = (0.1, -0.3, 0.3, -0.1)$, so $L(w) = 0.2/4 = 0.05$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;gradient-descent&quot;&gt;Gradient descent&lt;/h2&gt;

&lt;p&gt;Starting from $w_0$, iterate&lt;/p&gt;

\[w_{k+1} = w_k - \eta\,\nabla L(w_k) = w_k - \frac{2\eta}{n} X^T(Xw_k - y),\]

&lt;p&gt;with &lt;strong&gt;learning rate&lt;/strong&gt; $\eta &amp;gt; 0$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2 (convergence).&lt;/strong&gt; Let $w^{\star}$ be the solution and $0 &amp;lt; \lambda_{\min} \le \lambda_{\max}$ the eigenvalues of the Hessian $H$ (assume $X$ has full column rank). Then $w_{k+1} - w^{\star} = (I - \eta H)(w_k - w^{\star})$, and gradient descent converges if and only if $0 &amp;lt; \eta &amp;lt; 2/\lambda_{\max}$. The error shrinks by at least the factor $\rho = \max(\lvert 1 - \eta\lambda_{\min}\rvert, \lvert 1 - \eta\lambda_{\max}\rvert)$ per step.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Since $\nabla L(w^{\star}) = 0$ and $\nabla L$ is affine, $\nabla L(w_k) = H(w_k - w^{\star})$; substituting into the iteration gives the first relation. $H$ is symmetric, hence orthogonally diagonalisable (Lesson 10-02); in the eigenbasis each component of the error is multiplied by $1 - \eta\lambda_i$ per step. The sequence tends to $0$ for every starting point if and only if $\lvert 1 - \eta\lambda_i \rvert &amp;lt; 1$ for all $i$, i.e. $0 &amp;lt; \eta &amp;lt; 2/\lambda_{\max}$. $\blacksquare$&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;This is the same argument as for matrix powers (Lesson 09-06) and Markov chains (Lesson 13-03): the speed is set by eigenvalues. The best choice $\eta = 2/(\lambda_{\min} + \lambda_{\max})$ gives $\rho = \dfrac{\kappa - 1}{\kappa + 1}$, where $\kappa = \lambda_{\max}/\lambda_{\min}$ is the condition number of $X^TX$ (Lesson 08-05). Features on very different scales make $\kappa$ large and gradient descent slow: that is why features are &lt;strong&gt;standardised&lt;/strong&gt; before training.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (gradient descent on the sample data).&lt;/strong&gt; Here $n = 4$, and $H = \tfrac12 X^TX$ has eigenvalues $\lambda = \tfrac12(9 \pm \sqrt{61}) \approx 0.595$ and $8.405$. So we need $\eta &amp;lt; 2/8.405 \approx 0.238$.&lt;/p&gt;

  &lt;p&gt;With $\eta = 0.2$ and $w_0 = 0$: $\nabla L(w_0) = -\tfrac12 X^Ty = (-7, -14.5)$, so $w_1 = (1.4, 2.9)$ with $L(w_1) = 7.225$ (versus $L(w_0) = 15.5$). After 10 steps $w_{10} \approx (1.002, 1.601)$ with $L \approx 0.0595$; after about 100 steps $w$ agrees with $(1.1, 1.6)$ to four digits. The contraction factor is $\rho = \max(1 - 0.2 \cdot 0.595,\ 0.2 \cdot 8.405 - 1) \approx 0.881$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Stochastic gradient descent.&lt;/strong&gt; When $n$ is huge, each step uses only a small batch $B$ of a few dozen to a few hundred rows of $X$: $\nabla L \approx \tfrac{2}{\lvert B\rvert} X_B^T(X_Bw - y_B)$. The computation is still two matrix–vector products, which suits GPUs well.&lt;/p&gt;

&lt;h2 id=&quot;application-predicting-several-outputs-at-once&quot;&gt;Application: predicting several outputs at once&lt;/h2&gt;

&lt;p&gt;If each sample has $m$ labels (say temperature forecasts at $m$ stations), stack them as $Y \in \mathbb{R}^{n \times m}$ and find $W \in \mathbb{R}^{d \times m}$ minimising $\tfrac1n\lVert XW - Y \rVert_F^2$. The gradient is $\tfrac2n X^T(XW - Y)$ and the solution $W = (X^TX)^{-1}X^TY$: $m$ independent regressions sharing one matrix $X^TX$, which needs to be factorised only once (for example by Cholesky, Lesson 10-05). The last layer of many neural networks is exactly such a model on top of features the network has learned.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: linear regression with matrices&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag the data points, change the degree and see the solution of XᵀXβ = Xᵀy.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter08/binh_phuong_toi_thieu.html?mode=fit&amp;amp;lang=en&quot; title=&quot;Interactive: linear regression with matrices&quot; loading=&quot;lazy&quot; style=&quot;height: 680px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter08/binh_phuong_toi_thieu.html?mode=fit&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; With the data of Example 1, check that $X^T(Xw - y) = 0$ at $w = (1.1, 1.6)$ and explain its geometric meaning.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$r = Xw - y = (0.1, -0.3, 0.3, -0.1)$. The entries sum to $0$; $0 \cdot 0.1 + 1 \cdot (-0.3) + 2 \cdot 0.3 + 3 \cdot (-0.1) = 0$. The residual is orthogonal to both columns of $X$, so $Xw$ is the projection of $y$ onto $\operatorname{Col}(X)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; With $H$ from Example 2, what happens when gradient descent runs with $\eta = 0.25$? Which learning rate gives the best speed, and what is the contraction factor then?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\eta = 0.25 &amp;gt; 0.238$: $\lvert 1 - 0.25 \cdot 8.405 \rvert \approx 1.10 &amp;gt; 1$, so the component along the eigenvector of $\lambda_{\max}$ oscillates and grows; the method diverges. The best is $\eta = 2/(0.595 + 8.405) = 2/9 \approx 0.222$, with $\rho = (8.405 - 0.595)/9 \approx 0.868$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Add ridge regularisation: $L_\lambda(w) = \tfrac1n\lVert Xw - y \rVert^2 + \lambda \lVert w \rVert^2$. Compute the gradient and the solution, and compare with Lesson 08-05.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\nabla L_\lambda = \tfrac2n X^T(Xw - y) + 2\lambda w$. Setting it to $0$: $(X^TX + n\lambda I)w = X^Ty$. This is ridge regression with parameter $n\lambda$; the Hessian $\tfrac2n X^TX + 2\lambda I$ has all eigenvalues raised by $2\lambda$, so the condition number drops and gradient descent speeds up.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (programming).&lt;/strong&gt; Implement gradient descent in NumPy for the data of Example 1, run it with $\eta = 0.05$, $0.2$, $0.25$ and plot $L(w_k)$ against $k$ (log scale on the vertical axis).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

`for k in range(K): w -= eta * 2/n * X.T @ (X @ w - y)`. With $0.05$ convergence is slow ($\rho \approx 0.97$); with $0.2$ about 100 steps; with $0.25$ the curve blows up (divergence). On the log scale the tail is nearly a straight line with slope $2\log\rho$ (since $L - L^{\star}$ is proportional to the squared error).

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Linear regression: $\hat y = Xw$, $L(w) = \tfrac1n\lVert Xw - y \rVert^2$, a convex quadratic form.&lt;/li&gt;
    &lt;li&gt;$\nabla L = \tfrac2n X^T(Xw - y)$; $\nabla L = 0$ is the normal equations.&lt;/li&gt;
    &lt;li&gt;Gradient descent multiplies the error by $I - \eta H$ each step; it converges for $\eta &amp;lt; 2/\lambda_{\max}$, at a speed set by the condition number $\kappa$.&lt;/li&gt;
    &lt;li&gt;Several outputs: $W = (X^TX)^{-1}X^TY$, sharing one factorisation.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Feature Vectors, Data Matrices and Cosine Similarity</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter14/14_01_Vecto_Dac_Trung_Ma_Tran_Du_Lieu_Va_Do_Tuong_Tu_Cosin/"/>
   <updated>2026-01-14T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter14/14_01_Vecto_Dac_Trung_Ma_Tran_Du_Lieu_Va_Do_Tuong_Tu_Cosin</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;represent data as an $n \times d$ matrix $X$ (each row a sample, each column a feature);&lt;/li&gt;
    &lt;li&gt;compute the Gram matrix $XX^T$ and the cosine-similarity matrix of the samples;&lt;/li&gt;
    &lt;li&gt;explain when cosine similarity is preferable to Euclidean distance, and relate it to embedding search.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Four short documents are described by how often three words appear: “vector”, “matrix”, “probability”:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Document&lt;/th&gt;
      &lt;th&gt;vector&lt;/th&gt;
      &lt;th&gt;matrix&lt;/th&gt;
      &lt;th&gt;probability&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;$a$&lt;/td&gt;
      &lt;td&gt;$1$&lt;/td&gt;
      &lt;td&gt;$2$&lt;/td&gt;
      &lt;td&gt;$0$&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;$b$&lt;/td&gt;
      &lt;td&gt;$2$&lt;/td&gt;
      &lt;td&gt;$4$&lt;/td&gt;
      &lt;td&gt;$0$&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;$c$&lt;/td&gt;
      &lt;td&gt;$0$&lt;/td&gt;
      &lt;td&gt;$1$&lt;/td&gt;
      &lt;td&gt;$1$&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;$d$&lt;/td&gt;
      &lt;td&gt;$3$&lt;/td&gt;
      &lt;td&gt;$0$&lt;/td&gt;
      &lt;td&gt;$1$&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Document $b$ is just $a$ written twice as long. In Euclidean distance, $\lVert a - b \rVert = \sqrt5 \approx 2.24$ but $\lVert a - c \rVert = \sqrt3 \approx 1.73$, so $c$ is “closer” to $a$ than $b$ is. That contradicts our sense of content. We need a measure that only cares about the &lt;strong&gt;direction&lt;/strong&gt; of a vector.&lt;/p&gt;

&lt;h2 id=&quot;the-data-matrix&quot;&gt;The data matrix&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition.&lt;/strong&gt; For $n$ samples, each a &lt;strong&gt;feature vector&lt;/strong&gt; $x_i \in \mathbb{R}^d$, the &lt;strong&gt;data matrix&lt;/strong&gt; is $X \in \mathbb{R}^{n \times d}$ whose $i$-th row is $x_i^T$. Column $j$ of $X$ holds the value of feature $j$ across all samples.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The “rows are samples” convention is standard in NumPy, pandas, scikit-learn and PyTorch. Many whole-dataset operations become a single matrix product:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;$Xw$ is the vector of the $n$ dot products $x_i^Tw$ (the predictions of a linear model on every sample, Lesson 14-02);&lt;/li&gt;
  &lt;li&gt;$\tfrac1n\mathbf{1}^TX$ is the vector of feature means;&lt;/li&gt;
  &lt;li&gt;$X^TX$ ($d \times d$) compares &lt;strong&gt;features&lt;/strong&gt;; after centring, dividing by $n - 1$ gives the covariance matrix (Lesson 11-05);&lt;/li&gt;
  &lt;li&gt;$XX^T$ ($n \times n$) compares &lt;strong&gt;samples&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition.&lt;/strong&gt; The &lt;strong&gt;Gram matrix&lt;/strong&gt; of the samples is $K = XX^T$, with $K_{ij} = x_i^Tx_j$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;$K$ is symmetric positive semidefinite (Lesson 10-04), and $K_{ii} = \lVert x_i \rVert^2$. Euclidean distances can also be read off $K$: $\lVert x_i - x_j \rVert^2 = K_{ii} - 2K_{ij} + K_{jj}$.&lt;/p&gt;

&lt;h2 id=&quot;cosine-similarity&quot;&gt;Cosine similarity&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition.&lt;/strong&gt; The &lt;strong&gt;cosine similarity&lt;/strong&gt; of two nonzero vectors is&lt;/p&gt;

  &lt;p&gt;\(\cos(x, y) = \frac{x^Ty}{\lVert x \rVert\,\lVert y \rVert} \in [-1, 1].\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;By Lesson 01-02 this is the cosine of the angle between $x$ and $y$. It equals $1$ when the vectors point the same way, $0$ when they are orthogonal, $-1$ when opposite, and it is &lt;strong&gt;unchanged when a vector is scaled by a positive number&lt;/strong&gt;. If each row of $X$ is normalised to a unit vector (giving $\hat X$), the cosine-similarity matrix is exactly the Gram matrix $\hat X\hat X^T$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (the motivating example).&lt;/strong&gt; With $X$ the table above,&lt;/p&gt;

\[XX^T = \begin{bmatrix} 5 &amp;amp; 10 &amp;amp; 2 &amp;amp; 3 \\ 10 &amp;amp; 20 &amp;amp; 4 &amp;amp; 6 \\ 2 &amp;amp; 4 &amp;amp; 2 &amp;amp; 1 \\ 3 &amp;amp; 6 &amp;amp; 1 &amp;amp; 10 \end{bmatrix}, \qquad \hat X\hat X^T \approx \begin{bmatrix} 1 &amp;amp; 1 &amp;amp; 0.632 &amp;amp; 0.424 \\ 1 &amp;amp; 1 &amp;amp; 0.632 &amp;amp; 0.424 \\ 0.632 &amp;amp; 0.632 &amp;amp; 1 &amp;amp; 0.224 \\ 0.424 &amp;amp; 0.424 &amp;amp; 0.224 &amp;amp; 1 \end{bmatrix}.\]

  &lt;p&gt;For instance $\cos(a, c) = \tfrac{2}{\sqrt5\sqrt2} = \tfrac{2}{\sqrt{10}} \approx 0.632$. By cosine, $b$ is identical to $a$ (cosine $1$), then comes $c$, and finally $d$. This ordering matches our sense of content.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Relation to distance.&lt;/strong&gt; For unit vectors, $\lVert \hat x - \hat y \rVert^2 = 2 - 2\cos(x, y)$: on the unit sphere, ranking by cosine and by Euclidean distance agree. That is why many systems normalise embeddings and then use dot products.&lt;/p&gt;

&lt;h2 id=&quot;application-semantic-search-with-embeddings&quot;&gt;Application: semantic search with embeddings&lt;/h2&gt;

&lt;p&gt;Modern language models turn each sentence, passage or image into an &lt;strong&gt;embedding&lt;/strong&gt; vector $e \in \mathbb{R}^d$ (typically $d$ from a few hundred to a few thousand) such that similar content gives vectors pointing in nearly the same direction. Semantic search (and RAG systems that supply context to a chatbot) works like this: form the matrix $\hat E$ of normalised embeddings of all documents, compute the embedding $\hat q$ of the query, and return the documents with the largest entries of $\hat E\hat q$, that is, the largest cosines. One matrix–vector product replaces keyword matching. The attention mechanism in Transformers (Deep Learning course, Chapter 07) is also built on dot products between query and key vectors.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: cosine similarity&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag the document vectors and the query q; compare cosine with distance.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter14/cosin.html?lang=en&quot; title=&quot;Interactive: cosine similarity&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter14/cosin.html?lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-cosine-similarity-between-embedding-vectors&quot;&gt;Short video: Cosine similarity between embedding vectors&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/cosine-embedding.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Documents a = (1; 2; 0), b = (2; 4; 0) = 2a, c = (0; 1; 1), d = (3; 0; 1). By Euclidean distance, c is closer to a than b is (√3 &amp;lt; √5), against intuition. Normalizing onto the unit sphere: a and b coincide. Cosine: cos(a, b) = 1, cos(a, c) ≈ 0.63, cos(a, d) ≈ 0.42. Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; With $X$ from Example 1, use the Gram matrix to compute $\lVert c - d \rVert$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\lVert c - d \rVert^2 = K_{33} - 2K_{34} + K_{44} = 2 - 2 + 10 = 10$, so $\lVert c - d \rVert = \sqrt{10}$. Direct check: $c - d = (-3, 1, 0)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Show that $\cos(x, y)$ is unchanged when $x$ is replaced by $tx$ with $t &amp;gt; 0$, and changes sign when $t &amp;lt; 0$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\cos(tx, y) = \dfrac{t\,x^Ty}{\lvert t\rvert\,\lVert x \rVert\,\lVert y \rVert} = \operatorname{sign}(t)\cos(x, y)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Show that for unit $x, y$, $\lVert x - y \rVert^2 = 2 - 2\cos(x, y)$. Deduce that among unit vectors, the one nearest to $q$ in Euclidean distance is also the one with the largest cosine with $q$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\lVert x - y \rVert^2 = \lVert x \rVert^2 - 2x^Ty + \lVert y \rVert^2 = 2 - 2x^Ty$, and $x^Ty = \cos(x, y)$. The map $c \mapsto 2 - 2c$ is decreasing, so minimising distance is maximising cosine.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (programming).&lt;/strong&gt; For an $n \times d$ NumPy array $X$, write one line computing the $n \times n$ cosine matrix, and a function returning the indices of the $k$ samples most similar to a query vector $q$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

`Xh = X / np.linalg.norm(X, axis=1, keepdims=True)`; `S = Xh @ Xh.T`. For a query: `s = Xh @ (q / np.linalg.norm(q))`, then `np.argsort(-s)[:k]`.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Data matrix $X \in \mathbb{R}^{n \times d}$: rows are samples, columns are features.&lt;/li&gt;
    &lt;li&gt;The Gram matrix $XX^T$ holds all dot products between samples; $\lVert x_i - x_j \rVert^2 = K_{ii} - 2K_{ij} + K_{jj}$.&lt;/li&gt;
    &lt;li&gt;Cosine $x^Ty/(\lVert x \rVert\lVert y \rVert)$ compares directions, independent of length; with normalised rows the cosine matrix is $\hat X\hat X^T$.&lt;/li&gt;
    &lt;li&gt;Embedding search: one product $\hat E\hat q$, then take the largest entries.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>PageRank</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter13/13_04_PageRank/"/>
   <updated>2026-01-13T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter13/13_04_PageRank</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;mô hình người lướt web ngẫu nhiên bằng ma trận liên kết $M$ và xử lý trang không có liên kết ra;&lt;/li&gt;
    &lt;li&gt;dựng ma trận Google $G = \alpha M + \tfrac{1 - \alpha}{n}\mathbf{1}\mathbf{1}^T$ và tính PageRank bằng lặp luỹ thừa;&lt;/li&gt;
    &lt;li&gt;giải thích vì sao hệ số damping $\alpha$ làm chuỗi chính quy và bảo đảm hội tụ với tốc độ $\alpha^k$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Bốn trang web với các liên kết: trang 1 trỏ tới 2 và 3; trang 2 trỏ tới 3; trang 3 trỏ tới 1; trang 4 trỏ tới 1 và 3. Trang nào “quan trọng” nhất? Đếm số liên kết trỏ vào thì trang 3 thắng (ba liên kết). Nhưng ý tưởng của PageRank (Brin và Page, 1998) tinh tế hơn: &lt;strong&gt;một trang quan trọng nếu được các trang quan trọng trỏ tới&lt;/strong&gt;. Định nghĩa vòng tròn này chính là một bài toán vectơ riêng.&lt;/p&gt;

&lt;h2 id=&quot;người-lướt-web-ngẫu-nhiên&quot;&gt;Người lướt web ngẫu nhiên&lt;/h2&gt;

&lt;p&gt;Hình dung một người lướt web: ở mỗi bước, từ trang hiện tại bấm vào một liên kết chọn đều ngẫu nhiên. Đây là bước ngẫu nhiên trên đồ thị có hướng (Bài 13-01), với ma trận liên kết&lt;/p&gt;

\[m_{ij} = \begin{cases} 1/\text{(số liên kết ra của } j) &amp;amp; \text{nếu } j \text{ trỏ tới } i, \\ 0 &amp;amp; \text{nếu không.} \end{cases}\]

&lt;p&gt;Với ví dụ mở đầu:&lt;/p&gt;

\[M = \begin{bmatrix} 0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0{,}5 \\ 0{,}5 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\ 0{,}5 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0{,}5 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \end{bmatrix}.\]

&lt;p&gt;Hạng của các trang là phân phối dừng $r = Mr$: tỷ lệ thời gian người lướt web ở mỗi trang về lâu dài. Ở đây $r = (0{,}4;\ 0{,}2;\ 0{,}4;\ 0)$. Nhưng có hai trục trặc:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Trang cụt&lt;/strong&gt; (không có liên kết ra) cho một cột toàn số $0$, nên $M$ không còn ngẫu nhiên. Cách xử lý thông thường: thay cột đó bằng $\tfrac1n\mathbf{1}$ (người lướt web nhảy tới một trang bất kỳ).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bẫy và chu trình.&lt;/strong&gt; Một nhóm trang chỉ trỏ vào nhau giữ người lướt web mãi; đồ thị không liên thông cho nhiều phân phối dừng; chu trình làm phép lặp dao động (Bài 13-02). Ngoài ra, trang 4 có hạng $0$ vì không trang nào trỏ tới nó.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;ma-trận-google&quot;&gt;Ma trận Google&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa.&lt;/strong&gt; Với $M$ ngẫu nhiên theo cột (đã xử lý trang cụt) và &lt;strong&gt;hệ số damping&lt;/strong&gt; $0 &amp;lt; \alpha &amp;lt; 1$, &lt;strong&gt;ma trận Google&lt;/strong&gt; là&lt;/p&gt;

\[G = \alpha M + \frac{1 - \alpha}{n}\mathbf{1}\mathbf{1}^T.\]

  &lt;p&gt;&lt;strong&gt;PageRank&lt;/strong&gt; là phân phối dừng của $G$: $Gr = r$, $r \ge 0$, $\sum r_i = 1$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Ý nghĩa: ở mỗi bước, với xác suất $\alpha$ người lướt web bấm một liên kết, với xác suất $1 - \alpha$ họ chán và gõ địa chỉ một trang bất kỳ. Google ban đầu dùng $\alpha = 0{,}85$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; $G$ là ma trận ngẫu nhiên theo cột với mọi phần tử dương, nên chính quy. Do đó PageRank tồn tại, duy nhất, dương, và lặp luỹ thừa $r_{k+1} = Gr_k$ hội tụ về nó từ mọi phân phối ban đầu. Hơn nữa mọi trị riêng khác $1$ của $G$ thoả $\lvert\lambda\rvert \le \alpha$, nên sai số giảm ít nhất như $\alpha^k$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Mỗi phần tử $g_{ij} \ge \tfrac{1 - \alpha}{n} &amp;gt; 0$, và $\mathbf{1}^TG = \alpha\mathbf{1}^T + (1 - \alpha)\mathbf{1}^T = \mathbf{1}^T$. Phần tồn tại, duy nhất, hội tụ là Định lý Perron–Frobenius (Bài 13-02). Về tốc độ: với phân phối $x$, $Gx = \alpha Mx + \tfrac{1 - \alpha}{n}\mathbf{1}$. Với hai phân phối $x, y$, hiệu $d = x - y$ có $\mathbf{1}^Td = 0$, nên $G(x - y) = \alpha M(x - y)$, và $\lVert G^kd \rVert_1 = \alpha^k\lVert M^kd \rVert_1 \le \alpha^k\lVert d \rVert_1$ (vì $M$ ngẫu nhiên không làm tăng chuẩn $\ell^1$). Áp dụng với $y = r$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Không cần tạo ma trận dày $G$: vì $\mathbf{1}^Tr_k = 1$,&lt;/p&gt;

\[r_{k+1} = \alpha Mr_k + \frac{1 - \alpha}{n}\mathbf{1},\]

&lt;p&gt;chỉ cần nhân với ma trận thưa $M$ (mỗi trang có vài chục liên kết). Với $\alpha = 0{,}85$, khoảng $50$ đến $100$ vòng lặp đủ cho độ chính xác cần thiết, bất kể đồ thị có hàng tỷ trang.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (ví dụ mở đầu, $\alpha = 0{,}85$).&lt;/strong&gt; Bắt đầu từ $r_0 = (\tfrac14, \tfrac14, \tfrac14, \tfrac14)$:&lt;/p&gt;

\[r_1 \approx \begin{bmatrix} 0{,}356 \\ 0{,}144 \\ 0{,}463 \\ 0{,}038 \end{bmatrix}, \quad r_2 \approx \begin{bmatrix} 0{,}447 \\ 0{,}189 \\ 0{,}327 \\ 0{,}038 \end{bmatrix}, \quad \dots, \quad r \approx \begin{bmatrix} 0{,}380 \\ 0{,}199 \\ 0{,}384 \\ 0{,}0375 \end{bmatrix}.\]

  &lt;p&gt;Trang 3 đứng đầu, nhưng trang 1 gần như ngang bằng dù chỉ có hai liên kết trỏ vào: liên kết duy nhất của trang 3 (trang quan trọng) đổ toàn bộ “uy tín” của nó vào trang 1. Trang 4 không có liên kết vào nên chỉ nhận phần “nhảy ngẫu nhiên” $\tfrac{1 - \alpha}{n} = 0{,}0375$. Trị riêng lớn thứ hai của $G$ có môđun khoảng $0{,}60 \le \alpha$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Vai trò của $\alpha$.&lt;/strong&gt; $\alpha$ gần $1$: hạng phản ánh trung thực cấu trúc liên kết, nhưng hội tụ chậm và nhạy với bẫy. $\alpha$ nhỏ: hội tụ nhanh, hạng gần đều, ít thông tin. $\alpha = 0{,}85$ là thoả hiệp giữa hai điều này.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-xếp-hạng-ngoài-web&quot;&gt;Ứng dụng: xếp hạng ngoài web&lt;/h2&gt;

&lt;p&gt;Cùng thuật toán được dùng để xếp hạng bài báo khoa học theo trích dẫn, tìm người có ảnh hưởng trong mạng xã hội, xếp hạng đội thể thao (đội thua “trỏ tới” đội thắng), và tìm gen quan trọng trong mạng tương tác protein. Trong học sâu, các mạng nơ-ron đồ thị (GNN) dùng ma trận kề chuẩn hoá có cấu trúc giống $M$, và một biến thể (APPNP) lan truyền đặc trưng đúng bằng phép lặp PageRank.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: PageRank với hệ số d&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Bấm để thêm hoặc bỏ liên kết, kéo d và số lần lặp k.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter13/pagerank.html&quot; title=&quot;Minh hoạ: PageRank với hệ số d&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter13/pagerank.html&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-pagerank-hạng-của-trang-web&quot;&gt;Video ngắn: PageRank: hạng của trang web&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/pagerank-bubbles.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Bốn trang: 1 → 2, 3; 2 → 3; 3 → 1; 4 → 1, 3. Lặp r ← G r với α = 0,85, bong bóng co giãn theo hạng. Giới hạn r ≈ (0,380; 0,199; 0,384; 0,0375): trang 3 đứng đầu, trang 1 gần bằng; trang 4 chỉ nhận phần nhảy ngẫu nhiên. Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Ba trang: 1 trỏ tới 2; 2 trỏ tới 3; 3 trỏ tới 1 và 2. Lập $M$ và tìm PageRank khi không có damping ($\alpha = 1$).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$M = \begin{bmatrix} 0 &amp;amp; 0 &amp;amp; 0{,}5 \\ 1 &amp;amp; 0 &amp;amp; 0{,}5 \\ 0 &amp;amp; 1 &amp;amp; 0 \end{bmatrix}$. Giải $Mr = r$: $r_1 = 0{,}5r_3$, $r_3 = r_2$, nên $r \propto (1, 2, 2)$ và $r = (0{,}2;\ 0{,}4;\ 0{,}4)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Chứng minh: trang không có liên kết trỏ vào có PageRank đúng bằng $\tfrac{1 - \alpha}{n}$ (khi không có trang cụt).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Hàng $i$ của $M$ toàn số $0$, nên $(Gr)_i = \alpha(Mr)_i + \tfrac{1 - \alpha}{n}\mathbf{1}^Tr = 0 + \tfrac{1 - \alpha}{n}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Chứng minh khi không có trang cụt, $r = \dfrac{1 - \alpha}{n}(I - \alpha M)^{-1}\mathbf{1}$, và giải thích vì sao $I - \alpha M$ khả nghịch.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Từ $r = \alpha Mr + \tfrac{1 - \alpha}{n}\mathbf{1}$ (dùng $\mathbf{1}^Tr = 1$) được $(I - \alpha M)r = \tfrac{1 - \alpha}{n}\mathbf{1}$. Mọi trị riêng của $\alpha M$ có môđun $\le \alpha &amp;lt; 1$, nên $1$ không phải trị riêng của $\alpha M$ và $I - \alpha M$ khả nghịch. Hơn nữa $(I - \alpha M)^{-1} = \sum_k\alpha^kM^k$: PageRank cộng các đường đi độ dài $k$ với trọng số $\alpha^k$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (lập trình).&lt;/strong&gt; Dựng một đồ thị có hướng $10$ đỉnh, tính PageRank bằng lặp luỹ thừa với $\alpha = 0{,}85$ và so với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;networkx.pagerank&lt;/code&gt;.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Lập $M$ từ danh sách cạnh (xử lý trang cụt bằng cột $\tfrac1n\mathbf{1}$), lặp `r = a * M @ r + (1 - a) / n` tới khi `abs(r - r_old).sum() &amp;lt; 1e-10`. Kết quả khớp `networkx.pagerank(G, alpha=0.85)` tới khoảng $10^{-6}$ (networkx dùng cùng quy ước cho trang cụt nhưng dừng theo ngưỡng sai số mặc định của nó).

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Ma trận liên kết $M$: $m_{ij} = 1/\text{out}(j)$ nếu $j \to i$; trang cụt thay bằng cột $\tfrac1n\mathbf{1}$.&lt;/li&gt;
    &lt;li&gt;Ma trận Google $G = \alpha M + \tfrac{1 - \alpha}{n}\mathbf{1}\mathbf{1}^T$ dương, chính quy; PageRank là phân phối dừng duy nhất.&lt;/li&gt;
    &lt;li&gt;Lặp $r_{k+1} = \alpha Mr_k + \tfrac{1 - \alpha}{n}\mathbf{1}$ chỉ cần nhân ma trận thưa; sai số giảm như $\alpha^k$.&lt;/li&gt;
    &lt;li&gt;$\alpha$ cân bằng giữa trung thực với cấu trúc liên kết và tốc độ hội tụ; Google dùng $0{,}85$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Tốc độ hội tụ và trị riêng thứ hai</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter13/13_03_Toc_Do_Hoi_Tu_Va_Tri_Rieng_Thu_Hai/"/>
   <updated>2026-01-13T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter13/13_03_Toc_Do_Hoi_Tu_Va_Tri_Rieng_Thu_Hai</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;viết $x_k - \pi$ theo các vectơ riêng của $P$ và chứng minh sai số giảm như $\lvert\lambda_2\rvert^k$;&lt;/li&gt;
    &lt;li&gt;tính $P^k$ bằng chéo hoá và ước lượng số bước cần để sai số nhỏ hơn một ngưỡng;&lt;/li&gt;
    &lt;li&gt;giải thích khoảng phổ $1 - \lvert\lambda_2\rvert$ và nhận biết chuỗi hội tụ chậm.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Chuỗi thời tiết (Bài 13-01) gần như đạt phân phối dừng sau $10$ ngày. Chuỗi $P = \begin{bmatrix} 0{,}99 &amp;amp; 0{,}01 \\ 0{,}01 &amp;amp; 0{,}99 \end{bmatrix}$ (hai trạng thái gần như không chuyển qua lại) có phân phối dừng $(\tfrac12, \tfrac12)$, nhưng xuất phát từ $(1, 0)$ thì sau $10$ bước vẫn ở khoảng $(0{,}91;\ 0{,}09)$. Điều gì quyết định tốc độ? Câu trả lời nằm ở trị riêng &lt;strong&gt;thứ hai&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;phân-tích-theo-vectơ-riêng&quot;&gt;Phân tích theo vectơ riêng&lt;/h2&gt;

&lt;p&gt;Giả sử $P$ chéo hoá được với trị riêng $\lambda_1 = 1 &amp;gt; \lvert\lambda_2\rvert \ge \lvert\lambda_3\rvert \ge \dots$ và vectơ riêng $v_1 = \pi, v_2, \dots, v_n$. Viết $x_0 = c_1\pi + c_2v_2 + \dots + c_nv_n$. Khi đó (Bài 09-06)&lt;/p&gt;

\[x_k = P^kx_0 = c_1\pi + c_2\lambda_2^kv_2 + \dots + c_n\lambda_n^kv_n.\]

&lt;p&gt;Với $i \ge 2$: $\mathbf{1}^Tv_i = \mathbf{1}^TPv_i = \lambda_i\mathbf{1}^Tv_i$ (vì $\mathbf{1}^TP = \mathbf{1}^T$), nên $\mathbf{1}^Tv_i = 0$ khi $\lambda_i \neq 1$: các vectơ riêng khác có tổng thành phần bằng $0$. Lấy tổng các thành phần của $x_0$ được $c_1 = 1$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Với $P$ chính quy và chéo hoá được, tồn tại hằng số $C$ (phụ thuộc $x_0$) sao cho&lt;/p&gt;

\[\lVert x_k - \pi \rVert \le C\,\lvert\lambda_2\rvert^k \quad\text{với mọi } k.\]

  &lt;p&gt;Số $1 - \lvert\lambda_2\rvert$ gọi là &lt;strong&gt;khoảng phổ&lt;/strong&gt; (spectral gap). Khoảng phổ càng lớn, chuỗi hội tụ càng nhanh.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; $x_k - \pi = \sum_{i \ge 2}c_i\lambda_i^kv_i$, nên $\lVert x_k - \pi \rVert \le \sum_{i \ge 2}\lvert c_i\rvert\lvert\lambda_i\rvert^k\lVert v_i \rVert \le \Big(\sum_{i \ge 2}\lvert c_i\rvert\lVert v_i \rVert\Big)\lvert\lambda_2\rvert^k$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Nếu $P$ không chéo hoá được, kết luận vẫn đúng với thêm một nhân tử đa thức theo $k$ (dạng Jordan, Bài 09-08), không làm thay đổi tốc độ mũ.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (chuỗi thời tiết).&lt;/strong&gt; $P = \begin{bmatrix} 0{,}8 &amp;amp; 0{,}4 \\ 0{,}2 &amp;amp; 0{,}6 \end{bmatrix}$ có $\operatorname{tr} P = 1{,}4$, nên $\lambda_2 = 0{,}4$, với vectơ riêng $v_2 = (1, -1)$. Từ $x_0 = (1, 0) = \pi + \tfrac13(1, -1)$:&lt;/p&gt;

\[x_k = \begin{bmatrix} 2/3 \\ 1/3 \end{bmatrix} + \frac{0{,}4^k}{3}\begin{bmatrix} 1 \\ -1 \end{bmatrix}.\]

  &lt;p&gt;Kiểm tra: $k = 1$ cho $(0{,}8;\ 0{,}2)$, $k = 2$ cho $(0{,}72;\ 0{,}28)$, khớp Bài 13-01. Sai số nhỏ hơn $10^{-6}$ khi $0{,}4^k &amp;lt; 3 \cdot 10^{-6}$, tức $k \ge 14$.&lt;/p&gt;

  &lt;p&gt;Với cả ma trận:&lt;/p&gt;

\[P^k = \begin{bmatrix} 2/3 &amp;amp; 2/3 \\ 1/3 &amp;amp; 1/3 \end{bmatrix} + 0{,}4^k\begin{bmatrix} 1/3 &amp;amp; -2/3 \\ -1/3 &amp;amp; 2/3 \end{bmatrix}.\]

  &lt;p&gt;Số hạng đầu là $\pi\mathbf{1}^T$, giới hạn của Định lý Perron–Frobenius (Bài 13-02).&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (ví dụ mở đầu).&lt;/strong&gt; Với $P = \begin{bmatrix} 0{,}99 &amp;amp; 0{,}01 \\ 0{,}01 &amp;amp; 0{,}99 \end{bmatrix}$, $\lambda_2 = 0{,}98$ và $x_k = (\tfrac12, \tfrac12) + \tfrac12 \cdot 0{,}98^k(1, -1)$. Sau $10$ bước, $0{,}98^{10} \approx 0{,}82$: $x_{10} \approx (0{,}91;\ 0{,}09)$. Để sai số dưới $1\%$ cần $0{,}98^k &amp;lt; 0{,}02$, tức $k \ge 194$. Khoảng phổ $0{,}02$ rất nhỏ: chuỗi có hai “cụm” gần như tách rời, và việc chuyển giữa hai cụm là nút thắt.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Thời gian trộn.&lt;/strong&gt; Số bước để sai số giảm $e$ lần xấp xỉ $1/\ln(1/\lvert\lambda_2\rvert) \approx 1/(1 - \lvert\lambda_2\rvert)$ khi $\lvert\lambda_2\rvert$ gần $1$. Đây là ý nghĩa thực hành của khoảng phổ.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chu kỳ.&lt;/strong&gt; Nếu có trị riêng khác $1$ mà $\lvert\lambda\rvert = 1$ (như $-1$ ở đường $1 - 2 - 3$), khoảng phổ bằng $0$ và chuỗi không hội tụ. Mẹo thường dùng: thay $P$ bằng chuỗi &lt;strong&gt;lười&lt;/strong&gt; $\tfrac12(I + P)$, có cùng phân phối dừng và trị riêng $\tfrac12(1 + \lambda)$, nên $-1$ biến thành $0$.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-xào-bài-bao-nhiêu-lần-là-đủ&quot;&gt;Ứng dụng: xào bài bao nhiêu lần là đủ?&lt;/h2&gt;

&lt;p&gt;Xào một bộ bài $52$ lá là một chuỗi Markov trên $52!$ hoán vị, với phân phối dừng là phân phối đều. Bayer và Diaconis (1992) phân tích kiểu xào “riffle” (chia đôi rồi đan xen) và chứng minh cần khoảng $7$ lần xào để bộ bài gần với ngẫu nhiên đều; ít hơn thì bộ bài còn giữ rõ dấu vết thứ tự ban đầu. Trong MCMC (Bài 13-02), khoảng phổ của chuỗi quyết định cần chạy bao lâu trước khi lấy mẫu, nên người ta thiết kế các bước chuyển để khoảng phổ lớn.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: |λ₂| quyết định tốc độ hội tụ&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;So sánh sai số ‖xₖ − π‖ với |λ₂|ᵏ cho các ma trận khác nhau.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter13/markov.html?mode=rate&amp;amp;preset=slow&quot; title=&quot;Minh hoạ: |λ₂| quyết định tốc độ hội tụ&quot; loading=&quot;lazy&quot; style=&quot;height: 820px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter13/markov.html?mode=rate&amp;amp;preset=slow&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Chứng minh với chuỗi hai trạng thái $P = \begin{bmatrix} 1 - a &amp;amp; b \\ a &amp;amp; 1 - b \end{bmatrix}$, $\lambda_2 = 1 - a - b$. Khi nào chuỗi hội tụ nhanh nhất?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\operatorname{tr} P = 2 - a - b = 1 + \lambda_2$. Nhanh nhất khi $\lambda_2 = 0$, tức $a + b = 1$: khi đó mọi cột của $P$ bằng $\pi$ và chuỗi đạt phân phối dừng chỉ sau một bước.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Với chuỗi cửa hàng $P = \begin{bmatrix} 0{,}7 &amp;amp; 0{,}1 \\ 0{,}3 &amp;amp; 0{,}9 \end{bmatrix}$ và $x_0 = (0{,}5;\ 0{,}5)$, cần bao nhiêu tuần để thị phần của A chênh lệch với giá trị dừng $0{,}25$ ít hơn $0{,}01$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\lambda_2 = 1 - 0{,}3 - 0{,}1 = 0{,}6$, $x_0 - \pi = (0{,}25;\ -0{,}25)$, nên $(x_k)_1 - 0{,}25 = 0{,}25 \cdot 0{,}6^k$. Cần $0{,}6^k &amp;lt; 0{,}04$, tức $k \ge 7$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Tính $P^{10}$ cho chuỗi thời tiết bằng công thức của Ví dụ 1 (đến $6$ chữ số thập phân).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$0{,}4^{10} \approx 1{,}0486 \cdot 10^{-4}$. $P^{10} \approx \begin{bmatrix} 0{,}666702 &amp;amp; 0{,}666597 \\ 0{,}333298 &amp;amp; 0{,}333403 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Tìm trị riêng của bước ngẫu nhiên lười $\tfrac12(I + P)$ trên đường $1 - 2 - 3$ và tốc độ hội tụ của nó.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$P_{\text{đường}}$ có trị riêng $1, 0, -1$, nên chuỗi lười có $1, \tfrac12, 0$. Sai số giảm như $(\tfrac12)^k$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$x_k - \pi = \sum_{i \ge 2}c_i\lambda_i^kv_i$; sai số giảm như $\lvert\lambda_2\rvert^k$.&lt;/li&gt;
    &lt;li&gt;Khoảng phổ $1 - \lvert\lambda_2\rvert$; thời gian trộn cỡ $1/(1 - \lvert\lambda_2\rvert)$.&lt;/li&gt;
    &lt;li&gt;$P^k = \pi\mathbf{1}^T + \sum_{i \ge 2}\lambda_i^k(\dots)$; tính bằng chéo hoá.&lt;/li&gt;
    &lt;li&gt;Trị riêng môđun $1$ khác $1$ ngăn hội tụ; chuỗi lười $\tfrac12(I + P)$ khắc phục.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Phân phối dừng và trị riêng 1</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter13/13_02_Phan_Phoi_Dung_Va_Tri_Rieng_1/"/>
   <updated>2026-01-13T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter13/13_02_Phan_Phoi_Dung_Va_Tri_Rieng_1</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;chứng minh mọi ma trận ngẫu nhiên theo cột có trị riêng $1$ và mọi trị riêng có $\lvert\lambda\rvert \le 1$;&lt;/li&gt;
    &lt;li&gt;tìm phân phối dừng $\pi$ bằng cách giải $(P - I)\pi = 0$ với $\sum\pi_i = 1$;&lt;/li&gt;
    &lt;li&gt;nhận biết khi nào phân phối dừng duy nhất và khi nào $P^kx_0$ hội tụ về nó (chuỗi chính quy, định lý Perron–Frobenius).&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Trong chuỗi thời tiết của Bài 13-01, $x_k$ tiến về $(\tfrac23, \tfrac13)$. Nếu hôm nay xác suất nắng đúng bằng $\tfrac23$, ngày mai thì sao?&lt;/p&gt;

\[\begin{bmatrix} 0{,}8 &amp;amp; 0{,}4 \\ 0{,}2 &amp;amp; 0{,}6 \end{bmatrix}\begin{bmatrix} 2/3 \\ 1/3 \end{bmatrix} = \begin{bmatrix} 2/3 \\ 1/3 \end{bmatrix}.\]

&lt;p&gt;Phân phối không đổi: nó là một &lt;strong&gt;điểm cố định&lt;/strong&gt; của $x \mapsto Px$, tức là một vectơ riêng của $P$ với trị riêng $1$.&lt;/p&gt;

&lt;h2 id=&quot;phân-phối-dừng&quot;&gt;Phân phối dừng&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa.&lt;/strong&gt; Một &lt;strong&gt;phân phối dừng&lt;/strong&gt; của chuỗi Markov có ma trận chuyển $P$ là vectơ $\pi$ với $\pi \ge 0$, $\sum_i\pi_i = 1$ và $P\pi = \pi$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Nếu $P$ ngẫu nhiên theo cột thì $1$ là trị riêng của $P$, và mọi trị riêng (thực hoặc phức) của $P$ thoả $\lvert\lambda\rvert \le 1$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Tổng mỗi cột bằng $1$ nghĩa là $P^T\mathbf{1} = \mathbf{1}$, nên $1$ là trị riêng của $P^T$; $P$ và $P^T$ có cùng đa thức đặc trưng (Bài 09-02), nên $1$ là trị riêng của $P$.&lt;/p&gt;

  &lt;p&gt;Với $P^Ty = \lambda y$, $y \neq 0$, chọn $i$ có $\lvert y_i\rvert$ lớn nhất. Khi đó $\lvert\lambda\rvert\lvert y_i\rvert = \lvert\sum_jp_{ji}y_j\rvert \le \sum_jp_{ji}\lvert y_i\rvert = \lvert y_i\rvert$, nên $\lvert\lambda\rvert \le 1$. Lại dùng $P$ và $P^T$ có cùng trị riêng.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Trị riêng $1$ có vectơ riêng; người ta chứng minh được luôn chọn được một vectơ riêng không âm (định lý Perron–Frobenius dạng yếu), và chuẩn hoá cho tổng bằng $1$ được một phân phối dừng. Vậy &lt;strong&gt;mọi chuỗi Markov hữu hạn trạng thái có ít nhất một phân phối dừng&lt;/strong&gt;.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (chuỗi hai trạng thái tổng quát).&lt;/strong&gt; $P = \begin{bmatrix} 1 - a &amp;amp; b \\ a &amp;amp; 1 - b \end{bmatrix}$ với $0 &amp;lt; a, b \le 1$. Phương trình $(P - I)\pi = 0$ là $-a\pi_1 + b\pi_2 = 0$, nên $\pi \propto (b, a)$ và&lt;/p&gt;

\[\pi = \left(\frac{b}{a + b}, \frac{a}{a + b}\right).\]

  &lt;p&gt;Với chuỗi thời tiết, $a = 0{,}2$, $b = 0{,}4$: $\pi = (\tfrac23, \tfrac13)$. Về lâu dài, hai phần ba số ngày là ngày nắng.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (bước ngẫu nhiên trên đồ thị vô hướng).&lt;/strong&gt; Với đồ thị vô hướng liên thông, $\pi_i = \dfrac{\deg(i)}{2\lvert E\rvert}$ là phân phối dừng: $(P\pi)_i = \sum_{j \sim i}\dfrac{1}{\deg(j)}\cdot\dfrac{\deg(j)}{2\lvert E\rvert} = \dfrac{\deg(i)}{2\lvert E\rvert}$. Với đường $1 - 2 - 3$ (Ví dụ 2, Bài 13-01): $\pi = (\tfrac14, \tfrac12, \tfrac14)$. Đỉnh càng nhiều cạnh, càng hay được ghé thăm.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;khi-nào-duy-nhất-khi-nào-hội-tụ&quot;&gt;Khi nào duy nhất, khi nào hội tụ?&lt;/h2&gt;

&lt;p&gt;Hai hiện tượng có thể làm hỏng câu chuyện:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Không duy nhất.&lt;/strong&gt; Với $P = I$ (không ai di chuyển), mọi phân phối đều dừng. Tổng quát, nếu chuỗi tách thành hai nhóm trạng thái không liên lạc với nhau, mỗi nhóm có phân phối dừng riêng, và trị riêng $1$ có bội lớn hơn $1$.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Không hội tụ.&lt;/strong&gt; Với $P = \begin{bmatrix} 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix}$, phân phối dừng duy nhất là $(\tfrac12, \tfrac12)$, nhưng $x_0 = (1, 0)$ cho $x_k$ luân phiên $(0, 1), (1, 0), \dots$ mãi. Nguyên nhân: $P$ có trị riêng $-1$, cũng có môđun $1$. Đường $1 - 2 - 3$ cũng vậy (trị riêng $1, 0, -1$).&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa.&lt;/strong&gt; Ma trận ngẫu nhiên $P$ là &lt;strong&gt;chính quy&lt;/strong&gt; nếu có $k$ sao cho mọi phần tử của $P^k$ đều dương: từ mọi trạng thái có thể tới mọi trạng thái trong đúng $k$ bước.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2 (Perron–Frobenius cho ma trận ngẫu nhiên, phát biểu không chứng minh).&lt;/strong&gt; Nếu $P$ chính quy thì:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;trị riêng $1$ là đơn và mọi trị riêng khác có $\lvert\lambda\rvert &amp;lt; 1$;&lt;/li&gt;
    &lt;li&gt;có duy nhất một phân phối dừng $\pi$, và $\pi &amp;gt; 0$;&lt;/li&gt;
    &lt;li&gt;với mọi phân phối ban đầu $x_0$, $P^kx_0 \to \pi$; tương đương, $P^k \to \pi\mathbf{1}^T$ (mọi cột của $P^k$ tiến về $\pi$).&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;p&gt;Chuỗi thời tiết là chính quy ($P &amp;gt; 0$ ngay từ $k = 1$). Phần 3 giải thích vì sao trong Bài 13-01 phân phối sau $30$ ngày hầu như không phụ thuộc thời tiết hôm nay.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-thuật-toán-metropolis-và-mcmc&quot;&gt;Ứng dụng: thuật toán Metropolis và MCMC&lt;/h2&gt;

&lt;p&gt;Trong thống kê Bayes và vật lý thống kê, ta cần lấy mẫu từ một phân phối $\pi$ phức tạp trên một tập trạng thái khổng lồ. Ý tưởng &lt;strong&gt;MCMC&lt;/strong&gt; (Markov chain Monte Carlo) đảo ngược bài học này: thay vì cho $P$ rồi tìm $\pi$, ta &lt;em&gt;thiết kế&lt;/em&gt; một chuỗi chính quy có phân phối dừng đúng bằng $\pi$ (thuật toán Metropolis–Hastings làm được điều đó), rồi chạy chuỗi đủ lâu. Theo Định lý 2, trạng thái sau nhiều bước có phân phối gần $\pi$.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: mọi điểm xuất phát đều về phân phối dừng&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo x₀ trong tam giác xác suất, xem dãy xₖ chạy về π.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter13/markov.html?mode=stat&quot; title=&quot;Minh hoạ: mọi điểm xuất phát đều về phân phối dừng&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter13/markov.html?mode=stat&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-chuỗi-markov-hội-tụ-về-phân-phối-dừng&quot;&gt;Video ngắn: Chuỗi Markov hội tụ về phân phối dừng&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/markov-stationary.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Thời tiết: P = [0,8 0,4; 0,2 0,6]. Bắt đầu từ nắng chắc chắn hay mưa chắc chắn, xác suất nắng đều tiến về 2/3: phân phối dừng π = (2/3; 1/3), vectơ riêng ứng với trị riêng 1. Sai số co lại 0,4 lần mỗi ngày. Mô phỏng 60 ngày: tỷ lệ ngày nắng ≈ 0,67. Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Tìm phân phối dừng của chuỗi cửa hàng $P = \begin{bmatrix} 0{,}7 &amp;amp; 0{,}1 \\ 0{,}3 &amp;amp; 0{,}9 \end{bmatrix}$ (Bài tập 1, Bài 13-01).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$a = 0{,}3$, $b = 0{,}1$: $\pi = (\tfrac{0{,}1}{0{,}4}, \tfrac{0{,}3}{0{,}4}) = (0{,}25;\ 0{,}75)$. Về lâu dài nhãn B chiếm $75\%$ thị phần.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Tìm phân phối dừng của $P = \begin{bmatrix} 0{,}5 &amp;amp; 0{,}25 &amp;amp; 0 \\ 0{,}5 &amp;amp; 0{,}5 &amp;amp; 0{,}5 \\ 0 &amp;amp; 0{,}25 &amp;amp; 0{,}5 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Từ hàng 1: $0{,}5\pi_1 = 0{,}25\pi_2$, nên $\pi_2 = 2\pi_1$; từ hàng 3: $0{,}5\pi_3 = 0{,}25\pi_2$, nên $\pi_3 = \pi_1$. Chuẩn hoá: $\pi = (\tfrac14, \tfrac12, \tfrac14)$. (Đây là bước ngẫu nhiên &quot;lười&quot; trên đường $1 - 2 - 3$: $P = \tfrac12(I + P_{\text{đường}})$.)

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Cho một chuỗi bốn trạng thái mà $\{1, 2\}$ và $\{3, 4\}$ không liên lạc với nhau. Chứng minh phân phối dừng không duy nhất.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$P = \begin{bmatrix} A &amp;amp; 0 \\ 0 &amp;amp; B \end{bmatrix}$ với $A$, $B$ ngẫu nhiên $2 \times 2$. Nếu $\alpha$, $\beta$ là phân phối dừng của $A$, $B$ thì $(\alpha, 0)$ và $(0, \beta)$ đều dừng, và mọi tổ hợp lồi $t(\alpha, 0) + (1 - t)(0, \beta)$ cũng vậy.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Ma trận $P = \begin{bmatrix} 0 &amp;amp; 0 &amp;amp; 1 \\ 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 0 \end{bmatrix}$ (đi vòng $1 \to 2 \to 3 \to 1$) có chính quy không? Tìm các trị riêng và phân phối dừng.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Không chính quy: $P^3 = I$, các luỹ thừa của $P$ luôn có số $0$. Trị riêng là ba căn bậc ba của $1$: $1$, $e^{\pm 2\pi i/3}$, đều có môđun $1$. Phân phối dừng duy nhất $(\tfrac13, \tfrac13, \tfrac13)$, nhưng $P^kx_0$ không hội tụ nếu $x_0$ khác phân phối đều.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Phân phối dừng: $P\pi = \pi$, $\pi \ge 0$, $\sum\pi_i = 1$; là vectơ riêng của trị riêng $1$.&lt;/li&gt;
    &lt;li&gt;Mọi ma trận ngẫu nhiên có trị riêng $1$ và $\lvert\lambda\rvert \le 1$; luôn có ít nhất một phân phối dừng.&lt;/li&gt;
    &lt;li&gt;Hai trạng thái: $\pi = (b, a)/(a + b)$; bước ngẫu nhiên trên đồ thị vô hướng: $\pi_i = \deg(i)/2\lvert E\rvert$.&lt;/li&gt;
    &lt;li&gt;Chuỗi chính quy (Perron–Frobenius): $\pi$ duy nhất, dương, và $P^kx_0 \to \pi$ với mọi $x_0$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Chuỗi Markov và ma trận chuyển</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter13/13_01_Chuoi_Markov_Va_Ma_Tran_Chuyen/"/>
   <updated>2026-01-13T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter13/13_01_Chuoi_Markov_Va_Ma_Tran_Chuyen</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;định nghĩa chuỗi Markov hữu hạn trạng thái và ma trận chuyển (ma trận ngẫu nhiên theo cột);&lt;/li&gt;
    &lt;li&gt;lập ma trận chuyển cho một mô hình đơn giản từ mô tả bằng lời hoặc từ đồ thị;&lt;/li&gt;
    &lt;li&gt;tính phân phối sau $k$ bước $x_k = P^kx_0$ và đọc phần tử của $P^k$ là xác suất chuyển $k$ bước.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Một mô hình thời tiết đơn giản: mỗi ngày hoặc &lt;strong&gt;nắng&lt;/strong&gt; hoặc &lt;strong&gt;mưa&lt;/strong&gt;. Nếu hôm nay nắng, ngày mai nắng với xác suất $0{,}8$ và mưa với xác suất $0{,}2$. Nếu hôm nay mưa, ngày mai nắng với xác suất $0{,}4$ và mưa với xác suất $0{,}6$. Hôm nay (ngày $0$) trời nắng. Xác suất trời nắng sau $3$ ngày là bao nhiêu? Sau $30$ ngày?&lt;/p&gt;

&lt;p&gt;Điều quan trọng: thời tiết ngày mai chỉ phụ thuộc vào hôm nay, không phụ thuộc vào những ngày trước đó. Đó là &lt;strong&gt;tính chất Markov&lt;/strong&gt;, và nó biến bài toán xác suất thành bài toán nhân ma trận.&lt;/p&gt;

&lt;h2 id=&quot;ma-trận-chuyển&quot;&gt;Ma trận chuyển&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa.&lt;/strong&gt; Một &lt;strong&gt;chuỗi Markov&lt;/strong&gt; trên $n$ trạng thái $1, \dots, n$ là một dãy trạng thái ngẫu nhiên $S_0, S_1, S_2, \dots$ sao cho xác suất chuyển $p_{ij} = \Pr(S_{k+1} = i \mid S_k = j)$ không phụ thuộc vào $k$ và vào các trạng thái trước $S_k$. &lt;strong&gt;Ma trận chuyển&lt;/strong&gt; là $P = [p_{ij}]$: cột $j$ liệt kê xác suất đi từ trạng thái $j$ tới mỗi trạng thái.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Mỗi cột của $P$ là một phân phối xác suất, nên $p_{ij} \ge 0$ và &lt;strong&gt;tổng mỗi cột bằng $1$&lt;/strong&gt;. Ma trận như vậy gọi là &lt;strong&gt;ma trận ngẫu nhiên theo cột&lt;/strong&gt; (column-stochastic).&lt;/p&gt;

&lt;p&gt;Với ví dụ mở đầu, trạng thái $1$ = nắng, $2$ = mưa:&lt;/p&gt;

\[P = \begin{bmatrix} 0{,}8 &amp;amp; 0{,}4 \\ 0{,}2 &amp;amp; 0{,}6 \end{bmatrix}.\]

&lt;p&gt;&lt;strong&gt;Lưu ý quy ước.&lt;/strong&gt; Nhiều sách xác suất dùng &lt;strong&gt;ma trận ngẫu nhiên theo hàng&lt;/strong&gt; $Q = P^T$ (hàng $i$ là phân phối của bước tiếp theo khi đang ở $i$) và viết phân phối là vectơ hàng: $\pi_{k+1} = \pi_kQ$. Khoá này dùng quy ước cột, khớp với $x_{k+1} = Mx_k$ ở Bài 09-06. Hai quy ước chỉ khác nhau một phép chuyển vị.&lt;/p&gt;

&lt;h2 id=&quot;phân-phối-sau-k-bước&quot;&gt;Phân phối sau $k$ bước&lt;/h2&gt;

&lt;p&gt;Gọi $x_k$ là vectơ phân phối tại bước $k$: $(x_k)_i = \Pr(S_k = i)$, với $x_k \ge 0$ và tổng các thành phần bằng $1$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; $x_{k+1} = Px_k$, do đó $x_k = P^kx_0$. Phần tử $(P^k)_{ij}$ là xác suất đi từ trạng thái $j$ tới trạng thái $i$ sau đúng $k$ bước.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Theo công thức xác suất toàn phần, $\Pr(S_{k+1} = i) = \sum_j\Pr(S_{k+1} = i \mid S_k = j)\Pr(S_k = j) = \sum_jp_{ij}(x_k)_j = (Px_k)_i$. Quy nạp cho $x_k = P^kx_0$. Chọn $x_0 = e_j$ (chắc chắn bắt đầu ở $j$): $x_k = P^ke_j$ là cột $j$ của $P^k$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Hệ quả: $P^k$ cũng là ma trận ngẫu nhiên theo cột, và $(P^{k+l})_{ij} = \sum_m(P^l)_{im}(P^k)_{mj}$: để đi từ $j$ tới $i$ trong $k + l$ bước, đi tới một trạng thái trung gian $m$ sau $k$ bước rồi từ $m$ tới $i$ sau $l$ bước (phương trình Chapman–Kolmogorov).&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (ví dụ mở đầu).&lt;/strong&gt; $x_0 = (1, 0)$.&lt;/p&gt;

\[x_1 = \begin{bmatrix} 0{,}8 \\ 0{,}2 \end{bmatrix}, \quad x_2 = \begin{bmatrix} 0{,}72 \\ 0{,}28 \end{bmatrix}, \quad x_3 = \begin{bmatrix} 0{,}688 \\ 0{,}312 \end{bmatrix}, \quad \dots, \quad x_{10} \approx \begin{bmatrix} 0{,}66670 \\ 0{,}33330 \end{bmatrix}.\]

  &lt;p&gt;Xác suất nắng sau $3$ ngày là $0{,}688$. Dãy có vẻ tiến về $(\tfrac23, \tfrac13)$; Bài 13-02 và 13-03 giải thích vì sao và nhanh tới mức nào.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bước-ngẫu-nhiên-trên-đồ-thị&quot;&gt;Bước ngẫu nhiên trên đồ thị&lt;/h2&gt;

&lt;p&gt;Một nguồn chuỗi Markov quan trọng: &lt;strong&gt;bước ngẫu nhiên&lt;/strong&gt; trên đồ thị. Ở mỗi bước, từ đỉnh hiện tại đi tới một đỉnh kề chọn đều ngẫu nhiên. Với đồ thị có hướng, đi theo một cạnh ra chọn đều ngẫu nhiên. Khi đó $p_{ij} = 1/\deg(j)$ nếu có cạnh $j \to i$, và $0$ nếu không.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; Đường thẳng ba đỉnh $1 - 2 - 3$. Từ $1$ chắc chắn sang $2$; từ $3$ chắc chắn sang $2$; từ $2$ sang $1$ hoặc $3$ với xác suất $\tfrac12$ mỗi bên:&lt;/p&gt;

\[P = \begin{bmatrix} 0 &amp;amp; 0{,}5 &amp;amp; 0 \\ 1 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 0{,}5 &amp;amp; 0 \end{bmatrix}.\]

  &lt;p&gt;Bắt đầu tại $1$: $x_1 = (0, 1, 0)$, $x_2 = (0{,}5;\ 0;\ 0{,}5)$, $x_3 = (0, 1, 0)$, … Phân phối dao động mãi, không hội tụ; Bài 13-02 sẽ xem xét hiện tượng này.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-mô-hình-ngôn-ngữ-đơn-giản-nhất&quot;&gt;Ứng dụng: mô hình ngôn ngữ đơn giản nhất&lt;/h2&gt;

&lt;p&gt;Trước các mô hình ngôn ngữ lớn, cách đơn giản nhất để sinh văn bản là chuỗi Markov trên các từ: trạng thái là từ hiện tại, $p_{ij}$ là tần suất từ $i$ đứng sau từ $j$ trong một kho văn bản (mô hình bigram). Andrey Markov đã dùng ý tưởng này năm 1913 để phân tích chuỗi nguyên âm và phụ âm trong tác phẩm &lt;em&gt;Eugene Onegin&lt;/em&gt; của Pushkin. Các ứng dụng hiện đại: mô hình hàng đợi, sinh học (chuỗi DNA), tài chính (xếp hạng tín dụng chuyển đổi), và thuật toán lấy mẫu MCMC trong thống kê Bayes.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: ma trận chuyển trạng thái&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Sửa P, kéo bước k để xem xác suất ở mỗi trạng thái thay đổi.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter13/markov.html?mode=chain&quot; title=&quot;Minh hoạ: ma trận chuyển trạng thái&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter13/markov.html?mode=chain&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Một cửa hàng: khách mua nhãn A tuần này thì tuần sau mua lại A với xác suất $0{,}7$, chuyển sang B với $0{,}3$; khách mua B thì tuần sau mua A với $0{,}1$, B với $0{,}9$. Lập $P$. Nếu tuần này $50\%$ mua A, tính phân phối hai tuần sau.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$P = \begin{bmatrix} 0{,}7 &amp;amp; 0{,}1 \\ 0{,}3 &amp;amp; 0{,}9 \end{bmatrix}$. $x_1 = P(0{,}5;\ 0{,}5) = (0{,}4;\ 0{,}6)$, $x_2 = (0{,}28 + 0{,}06;\ 0{,}12 + 0{,}54) = (0{,}34;\ 0{,}66)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Chứng minh: nếu $P$ ngẫu nhiên theo cột và $x \ge 0$ có tổng thành phần bằng $1$ thì $Px$ cũng vậy. Suy ra $P^k$ ngẫu nhiên theo cột.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$Px \ge 0$ vì mọi phần tử không âm. Với $\mathbf{1} = (1, \dots, 1)$: tổng cột bằng $1$ nghĩa là $\mathbf{1}^TP = \mathbf{1}^T$, nên $\mathbf{1}^T(Px) = \mathbf{1}^Tx = 1$. Mỗi cột của $P^k$ là $P^ke_j$, áp dụng $k$ lần.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Lập ma trận chuyển cho bước ngẫu nhiên trên tam giác (ba đỉnh, mỗi đỉnh nối với hai đỉnh kia) và tính $P^2$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$P = \tfrac12\begin{bmatrix} 0 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 0 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 0 \end{bmatrix}$, $P^2 = \tfrac14\begin{bmatrix} 2 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 2 \end{bmatrix}$: sau hai bước, quay về chỗ cũ với xác suất $\tfrac12$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (lập trình).&lt;/strong&gt; Mô phỏng $10\,000$ ngày theo chuỗi thời tiết của ví dụ mở đầu và so tỷ lệ số ngày nắng với $\tfrac23$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Ở mỗi bước, lấy `rng.random() &amp;lt; P[0, s]` để quyết định ngày mai nắng ($s$ là trạng thái hôm nay). Tỷ lệ ngày nắng xấp xỉ $0{,}667$, sai lệch cỡ $0{,}01$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Chuỗi Markov: bước tiếp theo chỉ phụ thuộc trạng thái hiện tại; $p_{ij} = \Pr(\text{tới } i \mid \text{từ } j)$.&lt;/li&gt;
    &lt;li&gt;Ma trận chuyển ngẫu nhiên theo cột: phần tử không âm, $\mathbf{1}^TP = \mathbf{1}^T$.&lt;/li&gt;
    &lt;li&gt;$x_k = P^kx_0$; $(P^k)_{ij}$ là xác suất chuyển $k$ bước.&lt;/li&gt;
    &lt;li&gt;Bước ngẫu nhiên trên đồ thị: $p_{ij} = 1/\deg(j)$ khi có cạnh $j \to i$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>PageRank</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter13/13_04_PageRank/"/>
   <updated>2026-01-13T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter13/13_04_PageRank</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;model the random surfer with a link matrix $M$ and handle pages without outgoing links;&lt;/li&gt;
    &lt;li&gt;build the Google matrix $G = \alpha M + \tfrac{1 - \alpha}{n}\mathbf{1}\mathbf{1}^T$ and compute PageRank by power iteration;&lt;/li&gt;
    &lt;li&gt;explain why the damping factor $\alpha$ makes the chain regular and guarantees convergence at rate $\alpha^k$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Four web pages with links: page 1 links to 2 and 3; page 2 links to 3; page 3 links to 1; page 4 links to 1 and 3. Which page is most “important”? Counting incoming links, page 3 wins (three links). But the idea of PageRank (Brin and Page, 1998) is subtler: &lt;strong&gt;a page is important if important pages link to it&lt;/strong&gt;. This circular definition is exactly an eigenvector problem.&lt;/p&gt;

&lt;h2 id=&quot;the-random-surfer&quot;&gt;The random surfer&lt;/h2&gt;

&lt;p&gt;Picture a web surfer who, at each step, clicks a link on the current page chosen uniformly at random. This is a random walk on a directed graph (Lesson 13-01), with link matrix&lt;/p&gt;

\[m_{ij} = \begin{cases} 1/\text{(number of links out of } j) &amp;amp; \text{if } j \text{ links to } i, \\ 0 &amp;amp; \text{otherwise.} \end{cases}\]

&lt;p&gt;For the motivating example:&lt;/p&gt;

\[M = \begin{bmatrix} 0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0.5 \\ 0.5 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\ 0.5 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0.5 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \end{bmatrix}.\]

&lt;p&gt;The page ranks are the stationary distribution $r = Mr$: the long-run fraction of time the surfer spends on each page. Here $r = (0.4, 0.2, 0.4, 0)$. But there are two problems:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Dangling pages&lt;/strong&gt; (no outgoing links) give a column of zeros, so $M$ is no longer stochastic. The usual fix: replace that column with $\tfrac1n\mathbf{1}$ (the surfer jumps to a random page).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Traps and cycles.&lt;/strong&gt; A group of pages linking only to each other traps the surfer forever; a disconnected graph has many stationary distributions; cycles make the iteration oscillate (Lesson 13-02). Also, page 4 gets rank $0$ because no page links to it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;the-google-matrix&quot;&gt;The Google matrix&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition.&lt;/strong&gt; For a column-stochastic $M$ (with dangling pages fixed) and a &lt;strong&gt;damping factor&lt;/strong&gt; $0 &amp;lt; \alpha &amp;lt; 1$, the &lt;strong&gt;Google matrix&lt;/strong&gt; is&lt;/p&gt;

\[G = \alpha M + \frac{1 - \alpha}{n}\mathbf{1}\mathbf{1}^T.\]

  &lt;p&gt;&lt;strong&gt;PageRank&lt;/strong&gt; is the stationary distribution of $G$: $Gr = r$, $r \ge 0$, $\sum r_i = 1$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Meaning: at each step, with probability $\alpha$ the surfer clicks a link, and with probability $1 - \alpha$ gets bored and types the address of a random page. Google originally used $\alpha = 0.85$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; $G$ is column-stochastic with all entries positive, hence regular. So PageRank exists, is unique and positive, and power iteration $r_{k+1} = Gr_k$ converges to it from every initial distribution. Moreover, every eigenvalue of $G$ other than $1$ satisfies $\lvert\lambda\rvert \le \alpha$, so the error decays at least like $\alpha^k$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Each entry $g_{ij} \ge \tfrac{1 - \alpha}{n} &amp;gt; 0$, and $\mathbf{1}^TG = \alpha\mathbf{1}^T + (1 - \alpha)\mathbf{1}^T = \mathbf{1}^T$. Existence, uniqueness and convergence follow from Perron–Frobenius (Lesson 13-02). For the rate: for a distribution $x$, $Gx = \alpha Mx + \tfrac{1 - \alpha}{n}\mathbf{1}$. For two distributions $x, y$, the difference $d = x - y$ has $\mathbf{1}^Td = 0$, so $G(x - y) = \alpha M(x - y)$ and $\lVert G^kd \rVert_1 = \alpha^k\lVert M^kd \rVert_1 \le \alpha^k\lVert d \rVert_1$ (a stochastic $M$ does not increase the $\ell^1$ norm). Apply this with $y = r$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;There is no need to form the dense matrix $G$: since $\mathbf{1}^Tr_k = 1$,&lt;/p&gt;

\[r_{k+1} = \alpha Mr_k + \frac{1 - \alpha}{n}\mathbf{1},\]

&lt;p&gt;which only needs products with the sparse matrix $M$ (each page has a few dozen links). With $\alpha = 0.85$, about $50$ to $100$ iterations give the required accuracy, no matter that the graph has billions of pages.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (the motivating example, $\alpha = 0.85$).&lt;/strong&gt; Starting from $r_0 = (\tfrac14, \tfrac14, \tfrac14, \tfrac14)$:&lt;/p&gt;

\[r_1 \approx \begin{bmatrix} 0.356 \\ 0.144 \\ 0.463 \\ 0.038 \end{bmatrix}, \quad r_2 \approx \begin{bmatrix} 0.447 \\ 0.189 \\ 0.327 \\ 0.038 \end{bmatrix}, \quad \dots, \quad r \approx \begin{bmatrix} 0.380 \\ 0.199 \\ 0.384 \\ 0.0375 \end{bmatrix}.\]

  &lt;p&gt;Page 3 comes first, but page 1 is nearly tied with only two incoming links: the single outgoing link of page 3 (an important page) passes all of its “authority” to page 1. Page 4 has no incoming links, so it receives only the “random jump” share $\tfrac{1 - \alpha}{n} = 0.0375$. The second-largest eigenvalue of $G$ has modulus about $0.60 \le \alpha$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;The role of $\alpha$.&lt;/strong&gt; $\alpha$ close to $1$: the ranks faithfully reflect the link structure, but convergence is slow and sensitive to traps. Small $\alpha$: fast convergence, but nearly uniform, uninformative ranks. $\alpha = 0.85$ is a compromise between the two.&lt;/p&gt;

&lt;h2 id=&quot;application-ranking-beyond-the-web&quot;&gt;Application: ranking beyond the web&lt;/h2&gt;

&lt;p&gt;The same algorithm ranks scientific papers by citations, finds influential people in social networks, ranks sports teams (the loser “links to” the winner), and finds important genes in protein interaction networks. In deep learning, graph neural networks (GNNs) use normalized adjacency matrices with the same structure as $M$, and one variant (APPNP) propagates features with exactly the PageRank iteration.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: PageRank with damping d&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Click to add or remove links, drag d and the iteration count k.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter13/pagerank.html?lang=en&quot; title=&quot;Interactive: PageRank with damping d&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter13/pagerank.html?lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-pagerank-ranking-web-pages&quot;&gt;Short video: PageRank: ranking web pages&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/pagerank-bubbles.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Four pages: 1 → 2, 3; 2 → 3; 3 → 1; 4 → 1, 3. Iterate r ← G r with α = 0.85; bubbles grow and shrink with rank. Limit r ≈ (0.380; 0.199; 0.384; 0.0375): page 3 is first, page 1 close behind; page 4 only gets the random-jump share. Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Three pages: 1 links to 2; 2 links to 3; 3 links to 1 and 2. Build $M$ and find PageRank without damping ($\alpha = 1$).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$M = \begin{bmatrix} 0 &amp;amp; 0 &amp;amp; 0.5 \\ 1 &amp;amp; 0 &amp;amp; 0.5 \\ 0 &amp;amp; 1 &amp;amp; 0 \end{bmatrix}$. Solving $Mr = r$: $r_1 = 0.5r_3$ and $r_3 = r_2$, so $r \propto (1, 2, 2)$ and $r = (0.2, 0.4, 0.4)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Prove: a page with no incoming links has PageRank exactly $\tfrac{1 - \alpha}{n}$ (when there are no dangling pages).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Row $i$ of $M$ is all zeros, so $(Gr)_i = \alpha(Mr)_i + \tfrac{1 - \alpha}{n}\mathbf{1}^Tr = 0 + \tfrac{1 - \alpha}{n}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Prove that with no dangling pages, $r = \dfrac{1 - \alpha}{n}(I - \alpha M)^{-1}\mathbf{1}$, and explain why $I - \alpha M$ is invertible.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

From $r = \alpha Mr + \tfrac{1 - \alpha}{n}\mathbf{1}$ (using $\mathbf{1}^Tr = 1$) we get $(I - \alpha M)r = \tfrac{1 - \alpha}{n}\mathbf{1}$. Every eigenvalue of $\alpha M$ has modulus $\le \alpha &amp;lt; 1$, so $1$ is not an eigenvalue of $\alpha M$ and $I - \alpha M$ is invertible. Moreover $(I - \alpha M)^{-1} = \sum_k\alpha^kM^k$: PageRank adds up paths of length $k$ with weight $\alpha^k$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (programming).&lt;/strong&gt; Build a directed graph with $10$ vertices, compute PageRank by power iteration with $\alpha = 0.85$, and compare with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;networkx.pagerank&lt;/code&gt;.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Build $M$ from the edge list (fixing dangling pages with the column $\tfrac1n\mathbf{1}$), and iterate `r = a * M @ r + (1 - a) / n` until `abs(r - r_old).sum() &amp;lt; 1e-10`. The result matches `networkx.pagerank(G, alpha=0.85)` to about $10^{-6}$ (networkx uses the same dangling-page convention but stops at its own default tolerance).

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Link matrix $M$: $m_{ij} = 1/\text{out}(j)$ if $j \to i$; dangling pages get the column $\tfrac1n\mathbf{1}$.&lt;/li&gt;
    &lt;li&gt;The Google matrix $G = \alpha M + \tfrac{1 - \alpha}{n}\mathbf{1}\mathbf{1}^T$ is positive and regular; PageRank is its unique stationary distribution.&lt;/li&gt;
    &lt;li&gt;The iteration $r_{k+1} = \alpha Mr_k + \tfrac{1 - \alpha}{n}\mathbf{1}$ needs only sparse products; the error decays like $\alpha^k$.&lt;/li&gt;
    &lt;li&gt;$\alpha$ balances faithfulness to the link structure against convergence speed; Google used $0.85$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Rate of Convergence and the Second Eigenvalue</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter13/13_03_Toc_Do_Hoi_Tu_Va_Tri_Rieng_Thu_Hai/"/>
   <updated>2026-01-13T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter13/13_03_Toc_Do_Hoi_Tu_Va_Tri_Rieng_Thu_Hai</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;write $x_k - \pi$ in terms of the eigenvectors of $P$ and prove that the error decays like $\lvert\lambda_2\rvert^k$;&lt;/li&gt;
    &lt;li&gt;compute $P^k$ by diagonalization and estimate how many steps make the error smaller than a threshold;&lt;/li&gt;
    &lt;li&gt;explain the spectral gap $1 - \lvert\lambda_2\rvert$ and recognize slowly mixing chains.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;The weather chain (Lesson 13-01) nearly reached its stationary distribution after $10$ days. The chain $P = \begin{bmatrix} 0.99 &amp;amp; 0.01 \\ 0.01 &amp;amp; 0.99 \end{bmatrix}$ (two states that rarely switch) has stationary distribution $(\tfrac12, \tfrac12)$, but starting from $(1, 0)$ it is still at about $(0.91, 0.09)$ after $10$ steps. What decides the speed? The answer lies in the &lt;strong&gt;second&lt;/strong&gt; eigenvalue.&lt;/p&gt;

&lt;h2 id=&quot;the-eigenvector-expansion&quot;&gt;The eigenvector expansion&lt;/h2&gt;

&lt;p&gt;Suppose $P$ is diagonalizable with eigenvalues $\lambda_1 = 1 &amp;gt; \lvert\lambda_2\rvert \ge \lvert\lambda_3\rvert \ge \dots$ and eigenvectors $v_1 = \pi, v_2, \dots, v_n$. Write $x_0 = c_1\pi + c_2v_2 + \dots + c_nv_n$. Then (Lesson 09-06)&lt;/p&gt;

\[x_k = P^kx_0 = c_1\pi + c_2\lambda_2^kv_2 + \dots + c_n\lambda_n^kv_n.\]

&lt;p&gt;For $i \ge 2$: $\mathbf{1}^Tv_i = \mathbf{1}^TPv_i = \lambda_i\mathbf{1}^Tv_i$ (since $\mathbf{1}^TP = \mathbf{1}^T$), so $\mathbf{1}^Tv_i = 0$ when $\lambda_i \neq 1$: the other eigenvectors have entries summing to $0$. Summing the entries of $x_0$ gives $c_1 = 1$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; For $P$ regular and diagonalizable, there is a constant $C$ (depending on $x_0$) such that&lt;/p&gt;

\[\lVert x_k - \pi \rVert \le C\,\lvert\lambda_2\rvert^k \quad\text{for all } k.\]

  &lt;p&gt;The number $1 - \lvert\lambda_2\rvert$ is called the &lt;strong&gt;spectral gap&lt;/strong&gt;. The larger the spectral gap, the faster the chain converges.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; $x_k - \pi = \sum_{i \ge 2}c_i\lambda_i^kv_i$, so $\lVert x_k - \pi \rVert \le \sum_{i \ge 2}\lvert c_i\rvert\lvert\lambda_i\rvert^k\lVert v_i \rVert \le \Big(\sum_{i \ge 2}\lvert c_i\rvert\lVert v_i \rVert\Big)\lvert\lambda_2\rvert^k$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;If $P$ is not diagonalizable, the conclusion still holds up to a polynomial factor in $k$ (Jordan form, Lesson 09-08), which does not change the exponential rate.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (the weather chain).&lt;/strong&gt; $P = \begin{bmatrix} 0.8 &amp;amp; 0.4 \\ 0.2 &amp;amp; 0.6 \end{bmatrix}$ has $\operatorname{tr} P = 1.4$, so $\lambda_2 = 0.4$, with eigenvector $v_2 = (1, -1)$. From $x_0 = (1, 0) = \pi + \tfrac13(1, -1)$:&lt;/p&gt;

\[x_k = \begin{bmatrix} 2/3 \\ 1/3 \end{bmatrix} + \frac{0.4^k}{3}\begin{bmatrix} 1 \\ -1 \end{bmatrix}.\]

  &lt;p&gt;Check: $k = 1$ gives $(0.8, 0.2)$ and $k = 2$ gives $(0.72, 0.28)$, matching Lesson 13-01. The error is below $10^{-6}$ when $0.4^k &amp;lt; 3 \cdot 10^{-6}$, i.e. $k \ge 14$.&lt;/p&gt;

  &lt;p&gt;For the whole matrix:&lt;/p&gt;

\[P^k = \begin{bmatrix} 2/3 &amp;amp; 2/3 \\ 1/3 &amp;amp; 1/3 \end{bmatrix} + 0.4^k\begin{bmatrix} 1/3 &amp;amp; -2/3 \\ -1/3 &amp;amp; 2/3 \end{bmatrix}.\]

  &lt;p&gt;The first term is $\pi\mathbf{1}^T$, the limit in the Perron–Frobenius theorem (Lesson 13-02).&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (the motivating example).&lt;/strong&gt; For $P = \begin{bmatrix} 0.99 &amp;amp; 0.01 \\ 0.01 &amp;amp; 0.99 \end{bmatrix}$, $\lambda_2 = 0.98$ and $x_k = (\tfrac12, \tfrac12) + \tfrac12 \cdot 0.98^k(1, -1)$. After $10$ steps, $0.98^{10} \approx 0.82$: $x_{10} \approx (0.91, 0.09)$. For an error below $1\%$ we need $0.98^k &amp;lt; 0.02$, i.e. $k \ge 194$. The spectral gap $0.02$ is tiny: the chain has two nearly separate “clusters”, and moving between them is the bottleneck.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Mixing time.&lt;/strong&gt; The number of steps for the error to shrink by a factor $e$ is about $1/\ln(1/\lvert\lambda_2\rvert) \approx 1/(1 - \lvert\lambda_2\rvert)$ when $\lvert\lambda_2\rvert$ is close to $1$. This is the practical meaning of the spectral gap.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Periodicity.&lt;/strong&gt; If some eigenvalue other than $1$ has $\lvert\lambda\rvert = 1$ (like $-1$ for the path $1 - 2 - 3$), the spectral gap is $0$ and the chain does not converge. A common fix is the &lt;strong&gt;lazy&lt;/strong&gt; chain $\tfrac12(I + P)$, which has the same stationary distribution and eigenvalues $\tfrac12(1 + \lambda)$, so $-1$ becomes $0$.&lt;/p&gt;

&lt;h2 id=&quot;application-how-many-shuffles-are-enough&quot;&gt;Application: how many shuffles are enough?&lt;/h2&gt;

&lt;p&gt;Shuffling a $52$-card deck is a Markov chain on the $52!$ permutations, whose stationary distribution is uniform. Bayer and Diaconis (1992) analyzed the riffle shuffle (cut in half and interleave) and showed that about $7$ shuffles are needed for the deck to be close to uniformly random; with fewer, the deck still clearly remembers its original order. In MCMC (Lesson 13-02), the spectral gap of the chain decides how long to run before sampling, so moves are designed to make the gap large.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: |λ₂| sets the convergence speed&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Compare the error ‖xₖ − π‖ with |λ₂|ᵏ for different matrices.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter13/markov.html?mode=rate&amp;amp;preset=slow&amp;amp;lang=en&quot; title=&quot;Interactive: |λ₂| sets the convergence speed&quot; loading=&quot;lazy&quot; style=&quot;height: 820px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter13/markov.html?mode=rate&amp;amp;preset=slow&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Show that for the two-state chain $P = \begin{bmatrix} 1 - a &amp;amp; b \\ a &amp;amp; 1 - b \end{bmatrix}$, $\lambda_2 = 1 - a - b$. When does the chain converge fastest?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\operatorname{tr} P = 2 - a - b = 1 + \lambda_2$. Fastest when $\lambda_2 = 0$, i.e. $a + b = 1$: then every column of $P$ equals $\pi$ and the chain is stationary after a single step.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; For the store chain $P = \begin{bmatrix} 0.7 &amp;amp; 0.1 \\ 0.3 &amp;amp; 0.9 \end{bmatrix}$ with $x_0 = (0.5, 0.5)$, how many weeks until brand A’s share is within $0.01$ of its stationary value $0.25$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\lambda_2 = 1 - 0.3 - 0.1 = 0.6$ and $x_0 - \pi = (0.25, -0.25)$, so $(x_k)_1 - 0.25 = 0.25 \cdot 0.6^k$. We need $0.6^k &amp;lt; 0.04$, i.e. $k \ge 7$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Compute $P^{10}$ for the weather chain with the formula of Example 1 (to $6$ decimal places).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$0.4^{10} \approx 1.0486 \cdot 10^{-4}$. $P^{10} \approx \begin{bmatrix} 0.666702 &amp;amp; 0.666597 \\ 0.333298 &amp;amp; 0.333403 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Find the eigenvalues of the lazy random walk $\tfrac12(I + P)$ on the path $1 - 2 - 3$ and its rate of convergence.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$P_{\text{path}}$ has eigenvalues $1, 0, -1$, so the lazy chain has $1, \tfrac12, 0$. The error decays like $(\tfrac12)^k$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$x_k - \pi = \sum_{i \ge 2}c_i\lambda_i^kv_i$; the error decays like $\lvert\lambda_2\rvert^k$.&lt;/li&gt;
    &lt;li&gt;Spectral gap $1 - \lvert\lambda_2\rvert$; the mixing time is about $1/(1 - \lvert\lambda_2\rvert)$.&lt;/li&gt;
    &lt;li&gt;$P^k = \pi\mathbf{1}^T + \sum_{i \ge 2}\lambda_i^k(\dots)$, computed by diagonalization.&lt;/li&gt;
    &lt;li&gt;Eigenvalues of modulus $1$ other than $1$ prevent convergence; the lazy chain $\tfrac12(I + P)$ fixes this.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Stationary Distributions and the Eigenvalue 1</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter13/13_02_Phan_Phoi_Dung_Va_Tri_Rieng_1/"/>
   <updated>2026-01-13T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter13/13_02_Phan_Phoi_Dung_Va_Tri_Rieng_1</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;prove that every column-stochastic matrix has eigenvalue $1$ and that every eigenvalue satisfies $\lvert\lambda\rvert \le 1$;&lt;/li&gt;
    &lt;li&gt;find a stationary distribution $\pi$ by solving $(P - I)\pi = 0$ with $\sum\pi_i = 1$;&lt;/li&gt;
    &lt;li&gt;recognize when the stationary distribution is unique and when $P^kx_0$ converges to it (regular chains, the Perron–Frobenius theorem).&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;In the weather chain of Lesson 13-01, $x_k$ approached $(\tfrac23, \tfrac13)$. If today’s probability of sun is exactly $\tfrac23$, what about tomorrow?&lt;/p&gt;

\[\begin{bmatrix} 0.8 &amp;amp; 0.4 \\ 0.2 &amp;amp; 0.6 \end{bmatrix}\begin{bmatrix} 2/3 \\ 1/3 \end{bmatrix} = \begin{bmatrix} 2/3 \\ 1/3 \end{bmatrix}.\]

&lt;p&gt;The distribution does not change: it is a &lt;strong&gt;fixed point&lt;/strong&gt; of $x \mapsto Px$, that is, an eigenvector of $P$ with eigenvalue $1$.&lt;/p&gt;

&lt;h2 id=&quot;stationary-distributions&quot;&gt;Stationary distributions&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition.&lt;/strong&gt; A &lt;strong&gt;stationary distribution&lt;/strong&gt; of a Markov chain with transition matrix $P$ is a vector $\pi$ with $\pi \ge 0$, $\sum_i\pi_i = 1$ and $P\pi = \pi$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; If $P$ is column-stochastic, then $1$ is an eigenvalue of $P$, and every (real or complex) eigenvalue of $P$ satisfies $\lvert\lambda\rvert \le 1$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Columns summing to $1$ means $P^T\mathbf{1} = \mathbf{1}$, so $1$ is an eigenvalue of $P^T$; $P$ and $P^T$ have the same characteristic polynomial (Lesson 09-02), so $1$ is an eigenvalue of $P$.&lt;/p&gt;

  &lt;p&gt;For $P^Ty = \lambda y$ with $y \neq 0$, choose $i$ with $\lvert y_i\rvert$ largest. Then $\lvert\lambda\rvert\lvert y_i\rvert = \lvert\sum_jp_{ji}y_j\rvert \le \sum_jp_{ji}\lvert y_i\rvert = \lvert y_i\rvert$, so $\lvert\lambda\rvert \le 1$. Again, $P$ and $P^T$ have the same eigenvalues.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The eigenvalue $1$ has an eigenvector; one can prove that a nonnegative eigenvector can always be chosen (a weak form of the Perron–Frobenius theorem), and normalizing it to sum $1$ gives a stationary distribution. So &lt;strong&gt;every finite-state Markov chain has at least one stationary distribution&lt;/strong&gt;.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (the general two-state chain).&lt;/strong&gt; $P = \begin{bmatrix} 1 - a &amp;amp; b \\ a &amp;amp; 1 - b \end{bmatrix}$ with $0 &amp;lt; a, b \le 1$. The equation $(P - I)\pi = 0$ reads $-a\pi_1 + b\pi_2 = 0$, so $\pi \propto (b, a)$ and&lt;/p&gt;

\[\pi = \left(\frac{b}{a + b}, \frac{a}{a + b}\right).\]

  &lt;p&gt;For the weather chain, $a = 0.2$, $b = 0.4$: $\pi = (\tfrac23, \tfrac13)$. In the long run, two thirds of the days are sunny.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (random walk on an undirected graph).&lt;/strong&gt; For a connected undirected graph, $\pi_i = \dfrac{\deg(i)}{2\lvert E\rvert}$ is a stationary distribution: $(P\pi)_i = \sum_{j \sim i}\dfrac{1}{\deg(j)}\cdot\dfrac{\deg(j)}{2\lvert E\rvert} = \dfrac{\deg(i)}{2\lvert E\rvert}$. For the path $1 - 2 - 3$ (Example 2, Lesson 13-01): $\pi = (\tfrac14, \tfrac12, \tfrac14)$. The more edges a vertex has, the more often it is visited.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;when-unique-when-convergent&quot;&gt;When unique, when convergent?&lt;/h2&gt;

&lt;p&gt;Two phenomena can spoil the story:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Non-uniqueness.&lt;/strong&gt; With $P = I$ (nobody moves), every distribution is stationary. More generally, if the chain splits into two groups of states that never communicate, each group has its own stationary distribution, and the eigenvalue $1$ has multiplicity greater than $1$.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Non-convergence.&lt;/strong&gt; With $P = \begin{bmatrix} 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix}$, the unique stationary distribution is $(\tfrac12, \tfrac12)$, but $x_0 = (1, 0)$ gives $x_k$ alternating $(0, 1), (1, 0), \dots$ forever. The reason: $P$ has the eigenvalue $-1$, also of modulus $1$. The path $1 - 2 - 3$ behaves the same way (eigenvalues $1, 0, -1$).&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition.&lt;/strong&gt; A stochastic matrix $P$ is &lt;strong&gt;regular&lt;/strong&gt; if some power $P^k$ has all entries positive: every state can reach every state in exactly $k$ steps.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2 (Perron–Frobenius for stochastic matrices, stated without proof).&lt;/strong&gt; If $P$ is regular, then:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;the eigenvalue $1$ is simple and every other eigenvalue has $\lvert\lambda\rvert &amp;lt; 1$;&lt;/li&gt;
    &lt;li&gt;there is a unique stationary distribution $\pi$, and $\pi &amp;gt; 0$;&lt;/li&gt;
    &lt;li&gt;for every initial distribution $x_0$, $P^kx_0 \to \pi$; equivalently, $P^k \to \pi\mathbf{1}^T$ (every column of $P^k$ tends to $\pi$).&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;p&gt;The weather chain is regular ($P &amp;gt; 0$ already for $k = 1$). Part 3 explains why in Lesson 13-01 the distribution after $30$ days hardly depends on today’s weather.&lt;/p&gt;

&lt;h2 id=&quot;application-the-metropolis-algorithm-and-mcmc&quot;&gt;Application: the Metropolis algorithm and MCMC&lt;/h2&gt;

&lt;p&gt;In Bayesian statistics and statistical physics we need samples from a complicated distribution $\pi$ on a huge state space. The idea of &lt;strong&gt;MCMC&lt;/strong&gt; (Markov chain Monte Carlo) reverses this lesson: instead of being given $P$ and finding $\pi$, we &lt;em&gt;design&lt;/em&gt; a regular chain whose stationary distribution is exactly $\pi$ (the Metropolis–Hastings algorithm does this), and run it long enough. By Theorem 2, the state after many steps is distributed approximately as $\pi$.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: every start converges to the stationary distribution&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag x₀ in the probability triangle and watch xₖ run to π.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter13/markov.html?mode=stat&amp;amp;lang=en&quot; title=&quot;Interactive: every start converges to the stationary distribution&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter13/markov.html?mode=stat&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-markov-chains-converge-to-the-stationary-distribution&quot;&gt;Short video: Markov chains converge to the stationary distribution&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/markov-stationary.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Weather: P = [0.8 0.4; 0.2 0.6]. Starting from certainly sunny or certainly rainy, the probability of sun both tends to 2/3: the stationary distribution π = (2/3; 1/3), an eigenvector for eigenvalue 1. The error shrinks by a factor 0.4 each day. Simulation of 60 days: share of sunny days ≈ 0.67. Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Find the stationary distribution of the store chain $P = \begin{bmatrix} 0.7 &amp;amp; 0.1 \\ 0.3 &amp;amp; 0.9 \end{bmatrix}$ (Exercise 1, Lesson 13-01).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$a = 0.3$, $b = 0.1$: $\pi = (\tfrac{0.1}{0.4}, \tfrac{0.3}{0.4}) = (0.25, 0.75)$. In the long run brand B has a $75\%$ market share.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Find the stationary distribution of $P = \begin{bmatrix} 0.5 &amp;amp; 0.25 &amp;amp; 0 \\ 0.5 &amp;amp; 0.5 &amp;amp; 0.5 \\ 0 &amp;amp; 0.25 &amp;amp; 0.5 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Row 1: $0.5\pi_1 = 0.25\pi_2$, so $\pi_2 = 2\pi_1$; row 3: $0.5\pi_3 = 0.25\pi_2$, so $\pi_3 = \pi_1$. Normalizing: $\pi = (\tfrac14, \tfrac12, \tfrac14)$. (This is the &quot;lazy&quot; random walk on the path $1 - 2 - 3$: $P = \tfrac12(I + P_{\text{path}})$.)

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Take a four-state chain in which $\{1, 2\}$ and $\{3, 4\}$ never communicate. Show that the stationary distribution is not unique.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$P = \begin{bmatrix} A &amp;amp; 0 \\ 0 &amp;amp; B \end{bmatrix}$ with $A$, $B$ stochastic $2 \times 2$. If $\alpha$, $\beta$ are stationary for $A$, $B$, then $(\alpha, 0)$ and $(0, \beta)$ are both stationary, and so is every convex combination $t(\alpha, 0) + (1 - t)(0, \beta)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Is $P = \begin{bmatrix} 0 &amp;amp; 0 &amp;amp; 1 \\ 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 0 \end{bmatrix}$ (the cycle $1 \to 2 \to 3 \to 1$) regular? Find its eigenvalues and stationary distribution.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Not regular: $P^3 = I$, so the powers of $P$ always contain zeros. The eigenvalues are the three cube roots of $1$: $1$, $e^{\pm 2\pi i/3}$, all of modulus $1$. The unique stationary distribution is $(\tfrac13, \tfrac13, \tfrac13)$, but $P^kx_0$ does not converge unless $x_0$ is uniform.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Stationary distribution: $P\pi = \pi$, $\pi \ge 0$, $\sum\pi_i = 1$; an eigenvector for eigenvalue $1$.&lt;/li&gt;
    &lt;li&gt;Every stochastic matrix has eigenvalue $1$ and $\lvert\lambda\rvert \le 1$; there is always at least one stationary distribution.&lt;/li&gt;
    &lt;li&gt;Two states: $\pi = (b, a)/(a + b)$; random walk on an undirected graph: $\pi_i = \deg(i)/2\lvert E\rvert$.&lt;/li&gt;
    &lt;li&gt;Regular chains (Perron–Frobenius): $\pi$ is unique and positive, and $P^kx_0 \to \pi$ for every $x_0$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Markov Chains and Transition Matrices</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter13/13_01_Chuoi_Markov_Va_Ma_Tran_Chuyen/"/>
   <updated>2026-01-13T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter13/13_01_Chuoi_Markov_Va_Ma_Tran_Chuyen</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;define a finite-state Markov chain and its transition matrix (a column-stochastic matrix);&lt;/li&gt;
    &lt;li&gt;build the transition matrix of a simple model from a verbal description or a graph;&lt;/li&gt;
    &lt;li&gt;compute the distribution after $k$ steps, $x_k = P^kx_0$, and read the entries of $P^k$ as $k$-step transition probabilities.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;A simple weather model: each day is either &lt;strong&gt;sunny&lt;/strong&gt; or &lt;strong&gt;rainy&lt;/strong&gt;. If today is sunny, tomorrow is sunny with probability $0.8$ and rainy with probability $0.2$. If today is rainy, tomorrow is sunny with probability $0.4$ and rainy with probability $0.6$. Today (day $0$) is sunny. What is the probability of sun in $3$ days? In $30$ days?&lt;/p&gt;

&lt;p&gt;The key point: tomorrow’s weather depends only on today, not on earlier days. This is the &lt;strong&gt;Markov property&lt;/strong&gt;, and it turns the probability problem into matrix multiplication.&lt;/p&gt;

&lt;h2 id=&quot;transition-matrices&quot;&gt;Transition matrices&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition.&lt;/strong&gt; A &lt;strong&gt;Markov chain&lt;/strong&gt; on $n$ states $1, \dots, n$ is a sequence of random states $S_0, S_1, S_2, \dots$ such that the transition probabilities $p_{ij} = \Pr(S_{k+1} = i \mid S_k = j)$ depend neither on $k$ nor on the states before $S_k$. The &lt;strong&gt;transition matrix&lt;/strong&gt; is $P = [p_{ij}]$: column $j$ lists the probabilities of moving from state $j$ to each state.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Each column of $P$ is a probability distribution, so $p_{ij} \ge 0$ and &lt;strong&gt;every column sums to $1$&lt;/strong&gt;. Such a matrix is called &lt;strong&gt;column-stochastic&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For the motivating example, with state $1$ = sunny, $2$ = rainy:&lt;/p&gt;

\[P = \begin{bmatrix} 0.8 &amp;amp; 0.4 \\ 0.2 &amp;amp; 0.6 \end{bmatrix}.\]

&lt;p&gt;&lt;strong&gt;A note on conventions.&lt;/strong&gt; Many probability books use the &lt;strong&gt;row-stochastic&lt;/strong&gt; matrix $Q = P^T$ (row $i$ is the next-step distribution from state $i$) and write distributions as row vectors: $\pi_{k+1} = \pi_kQ$. This course uses the column convention, matching $x_{k+1} = Mx_k$ in Lesson 09-06. The two conventions differ only by a transpose.&lt;/p&gt;

&lt;h2 id=&quot;the-distribution-after-k-steps&quot;&gt;The distribution after $k$ steps&lt;/h2&gt;

&lt;p&gt;Let $x_k$ be the distribution vector at step $k$: $(x_k)_i = \Pr(S_k = i)$, with $x_k \ge 0$ and entries summing to $1$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; $x_{k+1} = Px_k$, hence $x_k = P^kx_0$. The entry $(P^k)_{ij}$ is the probability of going from state $j$ to state $i$ in exactly $k$ steps.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; By the law of total probability, $\Pr(S_{k+1} = i) = \sum_j\Pr(S_{k+1} = i \mid S_k = j)\Pr(S_k = j) = \sum_jp_{ij}(x_k)_j = (Px_k)_i$. Induction gives $x_k = P^kx_0$. Taking $x_0 = e_j$ (starting surely at $j$): $x_k = P^ke_j$ is column $j$ of $P^k$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Consequently $P^k$ is also column-stochastic, and $(P^{k+l})_{ij} = \sum_m(P^l)_{im}(P^k)_{mj}$: to go from $j$ to $i$ in $k + l$ steps, reach an intermediate state $m$ after $k$ steps and then go from $m$ to $i$ in $l$ steps (the Chapman–Kolmogorov equation).&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (the motivating example).&lt;/strong&gt; $x_0 = (1, 0)$.&lt;/p&gt;

\[x_1 = \begin{bmatrix} 0.8 \\ 0.2 \end{bmatrix}, \quad x_2 = \begin{bmatrix} 0.72 \\ 0.28 \end{bmatrix}, \quad x_3 = \begin{bmatrix} 0.688 \\ 0.312 \end{bmatrix}, \quad \dots, \quad x_{10} \approx \begin{bmatrix} 0.66670 \\ 0.33330 \end{bmatrix}.\]

  &lt;p&gt;The probability of sun in $3$ days is $0.688$. The sequence seems to approach $(\tfrac23, \tfrac13)$; Lessons 13-02 and 13-03 explain why, and how fast.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;random-walks-on-graphs&quot;&gt;Random walks on graphs&lt;/h2&gt;

&lt;p&gt;An important source of Markov chains is the &lt;strong&gt;random walk&lt;/strong&gt; on a graph. At each step, move from the current vertex to a neighbor chosen uniformly at random. On a directed graph, follow an outgoing edge chosen uniformly. Then $p_{ij} = 1/\deg(j)$ if there is an edge $j \to i$, and $0$ otherwise.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; The path with three vertices $1 - 2 - 3$. From $1$ we surely go to $2$; from $3$ surely to $2$; from $2$ to $1$ or $3$ with probability $\tfrac12$ each:&lt;/p&gt;

\[P = \begin{bmatrix} 0 &amp;amp; 0.5 &amp;amp; 0 \\ 1 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 0.5 &amp;amp; 0 \end{bmatrix}.\]

  &lt;p&gt;Starting at $1$: $x_1 = (0, 1, 0)$, $x_2 = (0.5, 0, 0.5)$, $x_3 = (0, 1, 0)$, … The distribution oscillates forever and does not converge; Lesson 13-02 looks at this phenomenon.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-the-simplest-language-model&quot;&gt;Application: the simplest language model&lt;/h2&gt;

&lt;p&gt;Before large language models, the simplest way to generate text was a Markov chain on words: the state is the current word, and $p_{ij}$ is the frequency with which word $i$ follows word $j$ in a corpus (a bigram model). Andrey Markov himself used this idea in 1913 to analyze sequences of vowels and consonants in Pushkin’s &lt;em&gt;Eugene Onegin&lt;/em&gt;. Modern applications include queueing models, biology (DNA sequences), finance (credit rating transitions), and MCMC sampling in Bayesian statistics.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: the transition matrix&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Edit P and drag step k to watch the probability of each state change.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter13/markov.html?mode=chain&amp;amp;lang=en&quot; title=&quot;Interactive: the transition matrix&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter13/markov.html?mode=chain&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; At a store, a customer who buys brand A this week buys A again next week with probability $0.7$ and switches to B with $0.3$; a B customer buys A next week with $0.1$ and B with $0.9$. Build $P$. If $50\%$ buy A this week, find the distribution two weeks later.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$P = \begin{bmatrix} 0.7 &amp;amp; 0.1 \\ 0.3 &amp;amp; 0.9 \end{bmatrix}$. $x_1 = P(0.5, 0.5) = (0.4, 0.6)$, $x_2 = (0.28 + 0.06, 0.12 + 0.54) = (0.34, 0.66)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Prove: if $P$ is column-stochastic and $x \ge 0$ has entries summing to $1$, then so does $Px$. Deduce that $P^k$ is column-stochastic.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$Px \ge 0$ since all entries are nonnegative. With $\mathbf{1} = (1, \dots, 1)$: columns summing to $1$ means $\mathbf{1}^TP = \mathbf{1}^T$, so $\mathbf{1}^T(Px) = \mathbf{1}^Tx = 1$. Each column of $P^k$ is $P^ke_j$; apply this $k$ times.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Build the transition matrix of the random walk on a triangle (three vertices, each joined to the other two) and compute $P^2$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$P = \tfrac12\begin{bmatrix} 0 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 0 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 0 \end{bmatrix}$, $P^2 = \tfrac14\begin{bmatrix} 2 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 2 \end{bmatrix}$: after two steps you are back where you started with probability $\tfrac12$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (programming).&lt;/strong&gt; Simulate $10{,}000$ days of the weather chain from the motivating example and compare the fraction of sunny days with $\tfrac23$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

At each step, use `rng.random() &amp;lt; P[0, s]` to decide whether tomorrow is sunny ($s$ is today&apos;s state). The fraction of sunny days is about $0.667$, off by about $0.01$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Markov chain: the next step depends only on the current state; $p_{ij} = \Pr(\text{to } i \mid \text{from } j)$.&lt;/li&gt;
    &lt;li&gt;A column-stochastic transition matrix: nonnegative entries, $\mathbf{1}^TP = \mathbf{1}^T$.&lt;/li&gt;
    &lt;li&gt;$x_k = P^kx_0$; $(P^k)_{ij}$ is the $k$-step transition probability.&lt;/li&gt;
    &lt;li&gt;Random walk on a graph: $p_{ij} = 1/\deg(j)$ when there is an edge $j \to i$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Chuỗi biến đổi và thứ tự nhân ma trận</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter12/12_04_Chuoi_Bien_Doi_Va_Thu_Tu_Nhan_Ma_Tran/"/>
   <updated>2026-01-12T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter12/12_04_Chuoi_Bien_Doi_Va_Thu_Tu_Nhan_Ma_Tran</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;sắp đúng thứ tự $M = TRS$ cho ma trận mô hình và chuỗi $PVM$ từ toạ độ vật tới màn hình;&lt;/li&gt;
    &lt;li&gt;dựng ma trận nhìn $V$ là nghịch đảo của tư thế camera, dùng $(AB)^{-1} = B^{-1}A^{-1}$;&lt;/li&gt;
    &lt;li&gt;chuyển giữa quy ước vectơ cột và vectơ hàng, và biến đổi pháp tuyến bằng $(M^{-1})^T$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Một lập trình viên muốn phóng to một chiếc ghế gấp đôi, xoay nó $90^\circ$ quanh trục đứng, rồi đặt nó tại vị trí $(3, 0, 0)$ trong phòng. Viết &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;M = S * R * T&lt;/code&gt; thì chiếc ghế bay lơ lửng ở chỗ lạ và to gấp đôi khoảng cách mong muốn. Lỗi không nằm ở từng ma trận mà ở &lt;strong&gt;thứ tự nhân&lt;/strong&gt;. Đây là lỗi phổ biến nhất trong lập trình đồ họa.&lt;/p&gt;

&lt;h2 id=&quot;ma-trận-mô-hình-m--trs&quot;&gt;Ma trận mô hình: $M = TRS$&lt;/h2&gt;

&lt;p&gt;Với quy ước &lt;strong&gt;vectơ cột&lt;/strong&gt; ($p&apos; = Mp$), phép áp dụng trước đứng bên phải. Thứ tự chuẩn cho một vật là: co giãn quanh gốc của vật, rồi quay quanh gốc của vật, rồi dời tới vị trí trong thế giới:&lt;/p&gt;

\[M = T\,R\,S.\]

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; $S = $ co giãn hệ số $2$, $R = R_z(90^\circ)$, $T = $ dời $(3, 0, 0)$, áp dụng cho điểm $p = (1, 0, 0)$ của vật.&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;Đúng, $TRSp$: $S$ cho $(2, 0, 0)$, $R$ cho $(0, 2, 0)$, $T$ cho $(3, 2, 0)$.&lt;/li&gt;
    &lt;li&gt;Sai, $SRTp$: $T$ cho $(4, 0, 0)$, $R$ cho $(0, 4, 0)$, $S$ cho $(0, 8, 0)$: vị trí cũng bị phóng to và quay.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Ma trận $4 \times 4$ của $TRS$:&lt;/p&gt;

\[M = \begin{bmatrix} 0 &amp;amp; -2 &amp;amp; 0 &amp;amp; 3 \\ 2 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 2 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}.\]

  &lt;p&gt;Khối $3 \times 3$ trên trái là $RS$; cột cuối là vị trí của vật.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;chuỗi-mô-hình--nhìn--chiếu&quot;&gt;Chuỗi mô hình – nhìn – chiếu&lt;/h2&gt;

&lt;p&gt;Đường đi của một đỉnh từ dữ liệu của vật tới màn hình:&lt;/p&gt;

\[p_{\text{màn hình}} \sim P\,V\,M\,p_{\text{vật}}.\]

&lt;ul&gt;
  &lt;li&gt;$M$ (model): toạ độ vật $\to$ toạ độ thế giới.&lt;/li&gt;
  &lt;li&gt;$V$ (view): toạ độ thế giới $\to$ toạ độ camera (camera ở gốc, nhìn theo trục quy ước).&lt;/li&gt;
  &lt;li&gt;$P$ (projection): toạ độ camera $\to$ toạ độ ảnh, kèm phép chia phối cảnh (Bài 12-03).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Đọc từ phải sang trái là đi theo thứ tự thực hiện. GPU tính sẵn tích $PVM$ một lần cho mỗi vật rồi nhân với hàng triệu đỉnh.&lt;/p&gt;

&lt;h2 id=&quot;ma-trận-nhìn-là-nghịch-đảo-của-tư-thế-camera&quot;&gt;Ma trận nhìn là nghịch đảo của tư thế camera&lt;/h2&gt;

&lt;p&gt;Nếu camera được đặt vào thế giới bằng phép quay $R_c$ rồi dời tới vị trí $c$, tức tư thế camera là $C = T(c)R_c$, thì ma trận nhìn phải “hoàn tác” phép đặt đó:&lt;/p&gt;

\[V = C^{-1} = (T(c)R_c)^{-1} = R_c^{-1}T(c)^{-1} = R_c^T\,T(-c).\]

&lt;p&gt;Thứ tự đảo lại theo quy tắc $(AB)^{-1} = B^{-1}A^{-1}$ (Bài 03-04): trước hết dời thế giới để camera về gốc, rồi quay ngược.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; Camera ở $c = (0, 0, -5)$, không quay ($R_c = I$), nhìn theo chiều dương trục $z$. Khi đó $V = T(0, 0, 5)$. Điểm thế giới $(3, 2, 0)$ của Ví dụ 1 có toạ độ camera $(3, 2, 5)$, và với tiêu cự $f = 1$ chiếu thành $(0{,}6;\ 0{,}4)$ trên màn hình.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;vectơ-cột-hay-vectơ-hàng&quot;&gt;Vectơ cột hay vectơ hàng&lt;/h2&gt;

&lt;p&gt;Một số thư viện (DirectX cũ, nhiều tài liệu cũ) viết điểm là &lt;strong&gt;vectơ hàng&lt;/strong&gt; và nhân bên phải: $p&apos;^T = p^TM^T$. Chuyển vị hai vế của $p&apos; = TRSp$:&lt;/p&gt;

\[p&apos;^T = p^T\,S^T\,R^T\,T^T.\]

&lt;p&gt;Thứ tự đọc trở thành trái sang phải theo thứ tự thực hiện, và mọi ma trận bị chuyển vị (phần tịnh tiến nằm ở hàng cuối thay vì cột cuối). Hai quy ước cho cùng kết quả hình học; lỗi xảy ra khi trộn chúng. Thêm một bẫy: OpenGL lưu ma trận theo thứ tự cột trong bộ nhớ, nên một mảng 16 số có thể trông như ma trận đã chuyển vị khi in ra.&lt;/p&gt;

&lt;h2 id=&quot;biến-đổi-pháp-tuyến&quot;&gt;Biến đổi pháp tuyến&lt;/h2&gt;

&lt;p&gt;Pháp tuyến của bề mặt (dùng để tính ánh sáng) &lt;strong&gt;không&lt;/strong&gt; biến đổi giống điểm khi $M$ có co giãn không đều.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Nếu các vectơ tiếp tuyến biến đổi theo $A$ (khối $3 \times 3$ của $M$, khả nghịch), thì pháp tuyến phải biến đổi theo $(A^{-1})^T$ để giữ tính vuông góc.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Nếu $n^Tt = 0$ với mọi tiếp tuyến $t$, thì với $n&apos; = (A^{-1})^Tn$ và $t&apos; = At$: $n&apos;^Tt&apos; = n^TA^{-1}At = n^Tt = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Ví dụ: với $A = \operatorname{diag}(2, 1, 1)$, mặt phẳng $x + y = 0$ có pháp tuyến $n = (1, 1, 0)$ và tiếp tuyến $t = (1, -1, 0)$. Sau biến đổi, $t&apos; = (2, -1, 0)$. Nếu biến đổi pháp tuyến “như điểm”, $An = (2, 1, 0)$ và $(2, 1, 0) \cdot (2, -1, 0) = 3 \neq 0$: sai. Còn $(A^{-1})^Tn = (\tfrac12, 1, 0)$ cho tích vô hướng $1 - 1 = 0$. Với phép quay, $(R^{-1})^T = R$ nên không có khác biệt.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-shader-đỉnh&quot;&gt;Ứng dụng: shader đỉnh&lt;/h2&gt;

&lt;p&gt;Trong mọi engine 3D (Unity, Unreal, three.js), chương trình chạy trên GPU cho mỗi đỉnh (vertex shader) về cơ bản chỉ gồm hai dòng: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gl_Position = P * V * M * vec4(pos, 1.0);&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;normal = normalMatrix * n;&lt;/code&gt; với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;normalMatrix&lt;/code&gt; là $((VM)_{3 \times 3}^{-1})^T$. Toàn bộ Chương 12 nằm trong hai dòng đó.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: T·R khác R·T&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Cùng một phép quay và tịnh tiến, đổi thứ tự nhân cho ra hai kết quả khác nhau.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter12/dong_nhat_2d.html?mode=order&quot; title=&quot;Minh hoạ: T·R khác R·T&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter12/dong_nhat_2d.html?mode=order&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Viết ma trận $3 \times 3$ (2D, toạ độ thuần nhất) của chuỗi: co giãn hệ số $3$, quay $90^\circ$, dời tới $(1, 2)$. Ảnh của $(1, 1)$ là gì?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$TRS = \begin{bmatrix} 0 &amp;amp; -3 &amp;amp; 1 \\ 3 &amp;amp; 0 &amp;amp; 2 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$. $(1, 1) \mapsto (-3 + 1, 3 + 2) = (-2, 5)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Camera đặt bằng $R_c = R_y(180^\circ)$ rồi dời tới $c = (0, 0, 5)$ (đứng ở $z = 5$ nhìn về gốc). Viết $V$ và tính toạ độ camera của gốc thế giới.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$V = R_c^TT(-c) = R_y(180^\circ)T(0, 0, -5)$ (vì $R_y(180^\circ)^T = R_y(180^\circ)$). Gốc: $T(0, 0, -5)$ cho $(0, 0, -5)$, rồi $R_y(180^\circ)$ cho $(0, 0, 5)$: gốc nằm trước camera $5$ đơn vị theo trục nhìn.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Với quy ước vectơ hàng, viết lại $p&apos; = PVMp$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$p&apos;^T = p^TM^TV^TP^T$: đọc từ trái sang phải theo thứ tự thực hiện.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Với $A = \operatorname{diag}(1, 3, 1)$, tính pháp tuyến biến đổi của mặt phẳng có pháp tuyến $n = (0, 1, 1)$ và kiểm tra với tiếp tuyến $t = (0, 1, -1)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$n&apos; = (A^{-1})^Tn = (0, \tfrac13, 1)$, $t&apos; = At = (0, 3, -1)$, $n&apos; \cdot t&apos; = 1 - 1 = 0$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Vectơ cột: phép áp dụng trước đứng bên phải; ma trận mô hình $M = TRS$.&lt;/li&gt;
    &lt;li&gt;Chuỗi tới màn hình: $p \sim PVMp_{\text{vật}}$.&lt;/li&gt;
    &lt;li&gt;Ma trận nhìn $V = (T(c)R_c)^{-1} = R_c^TT(-c)$.&lt;/li&gt;
    &lt;li&gt;Vectơ hàng: $p&apos;^T = p^TM^TV^TP^T$, mọi ma trận chuyển vị.&lt;/li&gt;
    &lt;li&gt;Pháp tuyến biến đổi theo $(A^{-1})^T$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Phép chiếu phối cảnh và camera</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter12/12_03_Phep_Chieu_Phoi_Canh_Va_Camera/"/>
   <updated>2026-01-12T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter12/12_03_Phep_Chieu_Phoi_Canh_Va_Camera</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;dựng mô hình camera lỗ kim và công thức chiếu $(x, y, z) \mapsto (fx/z, fy/z)$;&lt;/li&gt;
    &lt;li&gt;viết phép chiếu phối cảnh bằng ma trận $3 \times 4$ trong toạ độ thuần nhất, kèm ma trận nội tại $K$ đổi sang pixel;&lt;/li&gt;
    &lt;li&gt;tìm điểm tụ của một họ đường thẳng song song, và phân biệt chiếu phối cảnh với chiếu trực giao.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Đứng giữa đường ray và nhìn về phía xa: hai thanh ray song song dường như gặp nhau ở chân trời. Vật ở xa trông nhỏ hơn vật ở gần. Cả hai hiện tượng đến từ một phép chia: ảnh của một điểm trên màn hình tỷ lệ với $1/z$, với $z$ là khoảng cách theo hướng nhìn. Phép chia không phải phép tuyến tính, nhưng toạ độ thuần nhất (Bài 12-01) lại biến nó thành phép nhân ma trận.&lt;/p&gt;

&lt;h2 id=&quot;camera-lỗ-kim&quot;&gt;Camera lỗ kim&lt;/h2&gt;

&lt;p&gt;Đặt camera tại gốc toạ độ, nhìn theo chiều dương trục $z$, màn hình (mặt phẳng ảnh) là mặt phẳng $z = f$ với $f &amp;gt; 0$ là &lt;strong&gt;tiêu cự&lt;/strong&gt;. Tia sáng từ điểm $P = (x, y, z)$, $z &amp;gt; 0$, đi qua lỗ kim tại gốc cắt mặt phẳng ảnh tại điểm có toạ độ (theo tam giác đồng dạng)&lt;/p&gt;

\[(x&apos;, y&apos;) = \left(\frac{fx}{z}, \frac{fy}{z}\right).\]

&lt;p&gt;&lt;strong&gt;Ma trận chiếu.&lt;/strong&gt; Trong toạ độ thuần nhất:&lt;/p&gt;

\[\begin{bmatrix} X \\ Y \\ W \end{bmatrix} = \begin{bmatrix} f &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; f &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0 \end{bmatrix}\begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} = \begin{bmatrix} fx \\ fy \\ z \end{bmatrix}, \qquad (x&apos;, y&apos;) = \left(\frac{X}{W}, \frac{Y}{W}\right).\]

&lt;p&gt;Toàn bộ phần phi tuyến nằm trong bước cuối “chia cho $W$” (phép chia phối cảnh). Mọi thứ trước đó là đại số tuyến tính.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Đổi sang pixel.&lt;/strong&gt; Cảm biến có gốc toạ độ ở góc ảnh và đơn vị là pixel. Với tiêu cự $f_x, f_y$ tính bằng pixel và tâm ảnh $(c_x, c_y)$, ma trận &lt;strong&gt;nội tại&lt;/strong&gt; là&lt;/p&gt;

\[K = \begin{bmatrix} f_x &amp;amp; 0 &amp;amp; c_x \\ 0 &amp;amp; f_y &amp;amp; c_y \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}, \qquad \begin{bmatrix} u \\ v \\ 1 \end{bmatrix} \sim K\begin{bmatrix} x \\ y \\ z \end{bmatrix},\]

&lt;p&gt;trong đó $\sim$ nghĩa là bằng nhau sau khi chia cho toạ độ cuối. Nếu camera không ở gốc mà có hướng $R$ và vị trí sao cho điểm thế giới $P_w$ ứng với $P = RP_w + t$ trong hệ camera, &lt;strong&gt;ma trận camera&lt;/strong&gt; đầy đủ là $K[R \mid t]$ cỡ $3 \times 4$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Camera $f_x = f_y = 800$ pixel, tâm ảnh $(640, 360)$ (ảnh $1280 \times 720$). Điểm $P = (0{,}5;\ -0{,}2;\ 4)$ (mét) cho&lt;/p&gt;

\[u = 800 \cdot \frac{0{,}5}{4} + 640 = 740, \qquad v = 800 \cdot \frac{-0{,}2}{4} + 360 = 320.\]

  &lt;p&gt;Dời điểm ra xa gấp đôi, $P = (0{,}5;\ -0{,}2;\ 8)$: $(u, v) = (690, 340)$, gần tâm ảnh hơn.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;khối-hộp-và-điểm-tụ&quot;&gt;Khối hộp và điểm tụ&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; Khối hộp có mặt trước là hình vuông đỉnh $(\pm1, \pm1, 4)$ và mặt sau $(\pm1, \pm1, 6)$, tiêu cự $f = 2$. Mặt trước chiếu thành hình vuông đỉnh $(\pm\tfrac12, \pm\tfrac12)$, mặt sau thành hình vuông nhỏ hơn đỉnh $(\pm\tfrac13, \pm\tfrac13)$. Bốn cạnh nối hai mặt (song song với trục $z$) chiếu thành bốn đoạn thẳng, kéo dài sẽ gặp nhau tại tâm $(0, 0)$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Điểm tụ).&lt;/strong&gt; Các đường thẳng $P + sd$ cùng hướng $d$ với $d_z \neq 0$ có ảnh là các đường thẳng đi qua cùng một điểm, &lt;strong&gt;điểm tụ&lt;/strong&gt; $\left(\dfrac{fd_x}{d_z}, \dfrac{fd_y}{d_z}\right)$, không phụ thuộc $P$. Nếu $d_z = 0$ (đường song song với mặt phẳng ảnh), các ảnh vẫn song song.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Ảnh của $P + sd$ là $\left(\dfrac{f(P_x + sd_x)}{P_z + sd_z}, \dfrac{f(P_y + sd_y)}{P_z + sd_z}\right)$. Khi $s \to \infty$, điểm này tiến tới $\left(\dfrac{fd_x}{d_z}, \dfrac{fd_y}{d_z}\right)$. Trong toạ độ thuần nhất: điểm ở vô cùng theo hướng $d$ là $(d_x, d_y, d_z, 0)$ (vectơ hướng, $w = 0$), và ma trận chiếu đưa nó tới $(fd_x, fd_y, d_z)$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Trong Ví dụ 2, $d = (0, 0, 1)$ cho điểm tụ $(0, 0)$, đúng như đã thấy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chiếu trực giao.&lt;/strong&gt; Khi bỏ phép chia, $(x, y, z) \mapsto (x, y)$ là &lt;strong&gt;chiếu trực giao&lt;/strong&gt; (ma trận $\begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 0 \end{bmatrix}$, tuyến tính). Các đường song song giữ song song và vật không nhỏ đi khi ở xa. Bản vẽ kỹ thuật và nhiều trò chơi chiến thuật dùng chiếu trực giao; ảnh chụp và thị giác con người là phối cảnh.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-thực-tế-tăng-cường-và-đo-độ-sâu&quot;&gt;Ứng dụng: thực tế tăng cường và đo độ sâu&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Thực tế tăng cường (AR).&lt;/strong&gt; Để đặt một vật ảo lên mặt bàn trong video, ứng dụng ước lượng $K$ (hiệu chỉnh camera một lần) và $[R \mid t]$ (mỗi khung hình), rồi chiếu các đỉnh của vật ảo bằng $K[R \mid t]$.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Camera kép.&lt;/strong&gt; Hai camera song song cách nhau $B$ nhìn cùng một điểm ở độ sâu $z$; ảnh của nó lệch nhau $d = fB/z$ pixel (độ chênh). Đo $d$ suy ra $z = fB/d$: đây là cách camera kép trên điện thoại và xe tự lái tính bản đồ độ sâu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: camera và phép chiếu phối cảnh&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Đổi tiêu cự f, khoảng cách d, bật tắt phối cảnh và xem ảnh trên màn chiếu.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter12/khoi_lap_phuong_3d.html?mode=cam&quot; title=&quot;Minh hoạ: camera và phép chiếu phối cảnh&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter12/khoi_lap_phuong_3d.html?mode=cam&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-camera-lỗ-kim-nhìn-khối-lập-phương&quot;&gt;Video ngắn: Camera lỗ kim nhìn khối lập phương&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/perspective-cube.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Màn ảnh ảo z = f = 2. Khối hộp: mặt trước z = 4 chiếu thành hình vuông nửa cạnh 1/2, mặt sau z = 6 thành nửa cạnh 1/3. Bốn cạnh nối hai mặt gặp nhau tại điểm tụ (0; 0). Dời khối ra xa thì ảnh nhỏ dần. Đổi sang pixel: f = 800, tâm (640; 360). Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Với $f = 1$, chiếu các điểm $(2, 1, 5)$ và $(4, 2, 10)$. Nhận xét gì?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Cả hai cho $(0{,}4;\ 0{,}2)$: hai điểm nằm trên cùng một tia qua lỗ kim nên trùng ảnh. Toạ độ thuần nhất $(X, Y, W)$ và $(2X, 2Y, 2W)$ biểu diễn cùng một điểm.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Tìm điểm tụ của các đường thẳng hướng $d = (1, 1, 2)$ khi $f = 2$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\left(\tfrac{2 \cdot 1}{2}, \tfrac{2 \cdot 1}{2}\right) = (1, 1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Chứng minh phép chiếu phối cảnh không bảo toàn trung điểm: xét $A = (0, 0, 2)$, $B = (2, 0, 6)$, $f = 1$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Ảnh: $A&apos; = (0, 0)$, $B&apos; = (\tfrac13, 0)$, trung điểm của $A&apos;B&apos;$ là $(\tfrac16, 0)$. Trung điểm $M = (1, 0, 4)$ có ảnh $(\tfrac14, 0) \neq (\tfrac16, 0)$. Phép chiếu biến đường thẳng thành đường thẳng nhưng không giữ tỷ lệ độ dài.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Hai camera cách nhau $B = 0{,}12$ m, $f = 700$ pixel. Một điểm có độ chênh $d = 21$ pixel. Tính độ sâu.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$z = fB/d = 700 \cdot 0{,}12/21 = 4$ m.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Camera lỗ kim: $(x, y, z) \mapsto (fx/z, fy/z)$; trong toạ độ thuần nhất là ma trận $3 \times 4$ rồi chia cho $W$.&lt;/li&gt;
    &lt;li&gt;Ma trận nội tại $K$ đổi sang pixel; ma trận camera đầy đủ $K[R \mid t]$.&lt;/li&gt;
    &lt;li&gt;Các đường song song hướng $d$ hội tụ về điểm tụ $(fd_x/d_z, fd_y/d_z)$, là ảnh của điểm vô cùng $(d, 0)$.&lt;/li&gt;
    &lt;li&gt;Chiếu trực giao bỏ phép chia: tuyến tính, giữ song song.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Phép quay trong R³</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter12/12_02_Phep_Quay_Trong_R3/"/>
   <updated>2026-01-12T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter12/12_02_Phep_Quay_Trong_R3</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;viết ma trận quay quanh các trục $x$, $y$, $z$;&lt;/li&gt;
    &lt;li&gt;dùng công thức Rodrigues để viết ma trận quay quanh trục bất kỳ, và đọc trục, góc từ một ma trận quay;&lt;/li&gt;
    &lt;li&gt;chứng minh bằng ví dụ rằng các phép quay 3D không giao hoán.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Cầm một cuốn sách nằm ngửa trên bàn. Quay nó $90^\circ$ quanh trục hướng về phía bạn, rồi $90^\circ$ quanh trục thẳng đứng. Lấy cuốn sách thứ hai, làm hai bước đó theo thứ tự ngược lại. Hai cuốn sách kết thúc ở hai tư thế khác nhau. Trong 2D, mọi phép quay quanh gốc giao hoán ($R(\alpha)R(\beta) = R(\alpha + \beta)$); trong 3D thì không. Ma trận giải thích chính xác điều này.&lt;/p&gt;

&lt;h2 id=&quot;quay-quanh-các-trục-toạ-độ&quot;&gt;Quay quanh các trục toạ độ&lt;/h2&gt;

&lt;p&gt;Quay góc $\theta$ quanh một trục toạ độ giữ trục đó cố định và quay mặt phẳng vuông góc như trong 2D (theo quy tắc bàn tay phải: ngón cái theo chiều dương của trục, các ngón còn lại chỉ chiều quay):&lt;/p&gt;

\[R_x(\theta) = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; \cos\theta &amp;amp; -\sin\theta \\ 0 &amp;amp; \sin\theta &amp;amp; \cos\theta \end{bmatrix}, \quad R_y(\theta) = \begin{bmatrix} \cos\theta &amp;amp; 0 &amp;amp; \sin\theta \\ 0 &amp;amp; 1 &amp;amp; 0 \\ -\sin\theta &amp;amp; 0 &amp;amp; \cos\theta \end{bmatrix}, \quad R_z(\theta) = \begin{bmatrix} \cos\theta &amp;amp; -\sin\theta &amp;amp; 0 \\ \sin\theta &amp;amp; \cos\theta &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}.\]

&lt;p&gt;Chú ý dấu trong $R_y$: theo chu trình $x \to y \to z \to x$, mặt phẳng vuông góc với trục $y$ được sắp theo thứ tự $(z, x)$, nên $\sin\theta$ dương nằm ở góc trên phải.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa.&lt;/strong&gt; Ma trận $R$ cỡ $3 \times 3$ là &lt;strong&gt;ma trận quay&lt;/strong&gt; nếu $R^TR = I$ và $\det R = 1$. Tập các ma trận quay ký hiệu là $SO(3)$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Ma trận trực giao có $\det = -1$ là phép quay kèm phản xạ (Bài 07-07). Tích của hai phép quay là phép quay.&lt;/p&gt;

&lt;h2 id=&quot;không-giao-hoán&quot;&gt;Không giao hoán&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Với $A = R_x(90^\circ) = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; -1 \\ 0 &amp;amp; 1 &amp;amp; 0 \end{bmatrix}$ và $B = R_z(90^\circ) = \begin{bmatrix} 0 &amp;amp; -1 &amp;amp; 0 \\ 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$:&lt;/p&gt;

\[AB = \begin{bmatrix} 0 &amp;amp; -1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; -1 \\ 1 &amp;amp; 0 &amp;amp; 0 \end{bmatrix}, \qquad BA = \begin{bmatrix} 0 &amp;amp; 0 &amp;amp; 1 \\ 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 0 \end{bmatrix}.\]

  &lt;p&gt;Xem $e_1$: $ABe_1 = A e_2 = e_3$, còn $BAe_1 = Be_1 = e_2$. Thứ tự khác nhau cho kết quả khác nhau.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;quay-quanh-trục-bất-kỳ-công-thức-rodrigues&quot;&gt;Quay quanh trục bất kỳ: công thức Rodrigues&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Rodrigues).&lt;/strong&gt; Phép quay góc $\theta$ quanh trục có vectơ đơn vị $k = (k_1, k_2, k_3)$ có ma trận&lt;/p&gt;

\[R = I + \sin\theta\,K + (1 - \cos\theta)\,K^2, \qquad K = \begin{bmatrix} 0 &amp;amp; -k_3 &amp;amp; k_2 \\ k_3 &amp;amp; 0 &amp;amp; -k_1 \\ -k_2 &amp;amp; k_1 &amp;amp; 0 \end{bmatrix},\]

  &lt;p&gt;trong đó $Kv = k \times v$ (tích có hướng).&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Phác thảo chứng minh.&lt;/strong&gt; Tách $v = (k \cdot v)k + v_\perp$. Thành phần dọc trục đứng yên. Trong mặt phẳng vuông góc với $k$, hai vectơ vuông góc $v_\perp$ và $k \times v$ có cùng độ dài, và phép quay cho $v_\perp \mapsto \cos\theta\,v_\perp + \sin\theta\,(k \times v)$. Vì $K^2v = k \times (k \times v) = -v_\perp$, ta có $Rv = v + \sin\theta\,Kv + (1 - \cos\theta)K^2v$, đúng là công thức trên.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; Quay $120^\circ$ quanh $k = \tfrac{1}{\sqrt3}(1, 1, 1)$. Ở đây $\sin\theta = \tfrac{\sqrt3}{2}$, $1 - \cos\theta = \tfrac32$, và $K^2 = kk^T - I$. Thay vào công thức được&lt;/p&gt;

\[R = \begin{bmatrix} 0 &amp;amp; 0 &amp;amp; 1 \\ 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 0 \end{bmatrix},\]

  &lt;p&gt;phép hoán vị $e_1 \to e_2 \to e_3 \to e_1$. Đây chính là $BA$ của Ví dụ 1: tích của hai phép quay $90^\circ$ quanh hai trục toạ độ là phép quay $120^\circ$ quanh đường chéo.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Đọc trục và góc từ ma trận.&lt;/strong&gt; Mọi $R \in SO(3)$ là phép quay quanh một trục (định lý Euler): trục là vectơ riêng ứng với trị riêng $1$, và góc thoả $\operatorname{tr} R = 1 + 2\cos\theta$. Với $R$ của Ví dụ 2: $\operatorname{tr} R = 0$, nên $\cos\theta = -\tfrac12$, $\theta = 120^\circ$. Các trị riêng còn lại là $e^{\pm i\theta}$ (Bài 09-05).&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-góc-euler-khoá-gimbal-và-quaternion&quot;&gt;Ứng dụng: góc Euler, khoá gimbal và quaternion&lt;/h2&gt;

&lt;p&gt;Máy bay và camera thường mô tả tư thế bằng ba góc &lt;strong&gt;yaw–pitch–roll&lt;/strong&gt;: $R = R_z(\psi)R_y(\vartheta)R_x(\varphi)$. Cách này trực quan nhưng có điểm kỳ dị: khi $\vartheta = 90^\circ$, hai trục quay còn lại trùng nhau và mất một bậc tự do (&lt;strong&gt;khoá gimbal&lt;/strong&gt;, tình huống mà các phi hành gia chương trình Apollo phải chủ động tránh). Vì vậy các engine đồ họa và hệ điều khiển dùng &lt;strong&gt;quaternion&lt;/strong&gt; đơn vị $q = (\cos\tfrac\theta2, \sin\tfrac\theta2\,k)$ để lưu và nội suy phép quay, rồi chuyển sang ma trận Rodrigues khi cần nhân với điểm.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: quay khối lập phương trong R³&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo α, β, γ, xem ma trận quay R và so sánh hai thứ tự nhân.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter12/khoi_lap_phuong_3d.html?mode=rot&quot; title=&quot;Minh hoạ: quay khối lập phương trong R³&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter12/khoi_lap_phuong_3d.html?mode=rot&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Kiểm tra $R_y(\theta)$ là ma trận quay ($R^TR = I$, $\det R = 1$) và tính $R_y(90^\circ)e_3$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Các cột trực chuẩn, $\det = \cos^2\theta + \sin^2\theta = 1$. $R_y(90^\circ)e_3 = $ cột 3 $= (1, 0, 0) = e_1$: quay quanh $y$ đưa $z$ về $x$, đúng chu trình $z \to x$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Bằng ví dụ số, chứng minh $R_x(90^\circ)R_y(90^\circ) \neq R_y(90^\circ)R_x(90^\circ)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Xét $e_3$: $R_y(90^\circ)e_3 = e_1$, $R_x(90^\circ)e_1 = e_1$, nên $R_xR_ye_3 = e_1$. Còn $R_x(90^\circ)e_3 = -e_2$, $R_y(90^\circ)(-e_2) = -e_2$, nên $R_yR_xe_3 = -e_2 \neq e_1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Tìm trục và góc của phép quay $R = \begin{bmatrix} 0 &amp;amp; -1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; -1 \\ 1 &amp;amp; 0 &amp;amp; 0 \end{bmatrix}$ ($AB$ của Ví dụ 1).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\operatorname{tr} R = 0$, nên $\theta = 120^\circ$. Giải $Rv = v$: $-v_2 = v_1$, $-v_3 = v_2$, $v_1 = v_3$, được $v = (1, -1, 1)$. Trục $\tfrac{1}{\sqrt3}(1, -1, 1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (lập trình).&lt;/strong&gt; Vẽ khối lập phương $[-1, 1]^3$ (12 cạnh) bằng NumPy và Matplotlib, quay bằng $R_z(30^\circ)R_x(20^\circ)$ rồi chiếu trực giao lên mặt phẳng $xy$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Lập mảng $8 \times 3$ các đỉnh $(\pm1, \pm1, \pm1)$; cạnh nối hai đỉnh khác nhau đúng một toạ độ. Tính `P = V @ R.T` (mỗi hàng là một đỉnh, nên nhân với $R^T$ bên phải) và vẽ `plt.plot` cho hai cột đầu của mỗi cặp đỉnh.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$R_x$, $R_y$, $R_z$ giữ một trục và quay mặt phẳng vuông góc; chú ý dấu trong $R_y$.&lt;/li&gt;
    &lt;li&gt;Ma trận quay: $R^TR = I$, $\det R = 1$; tích các phép quay là phép quay.&lt;/li&gt;
    &lt;li&gt;Rodrigues: $R = I + \sin\theta\,K + (1 - \cos\theta)K^2$; trục là vectơ riêng ứng với $1$, $\operatorname{tr} R = 1 + 2\cos\theta$.&lt;/li&gt;
    &lt;li&gt;Phép quay 3D không giao hoán; góc Euler có khoá gimbal, nên thực tế dùng quaternion.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Toạ độ thuần nhất và phép tịnh tiến</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter12/12_01_Toa_Do_Thuan_Nhat_Va_Phep_Tinh_Tien/"/>
   <updated>2026-01-12T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter12/12_01_Toa_Do_Thuan_Nhat_Va_Phep_Tinh_Tien</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;giải thích vì sao phép tịnh tiến không phải ánh xạ tuyến tính trên $\mathbb{R}^2$;&lt;/li&gt;
    &lt;li&gt;viết phép tịnh tiến, quay, co giãn bằng ma trận $3 \times 3$ trong toạ độ thuần nhất;&lt;/li&gt;
    &lt;li&gt;hợp các phép biến đổi, chẳng hạn quay quanh một điểm bất kỳ, và phân biệt điểm ($w = 1$) với vectơ hướng ($w = 0$).&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Trong một trò chơi 2D, nhân vật cần được &lt;strong&gt;quay&lt;/strong&gt; $90^\circ$ quanh tâm của nó rồi &lt;strong&gt;dời&lt;/strong&gt; sang phải $3$ đơn vị. Phép quay là phép nhân ma trận $2 \times 2$ (Bài 06-02). Nhưng phép dời $x \mapsto x + t$ thì không: nó đưa $0$ tới $t \neq 0$, trong khi mọi ánh xạ tuyến tính giữ nguyên gốc. Nếu muốn mọi phép biến đổi là một phép nhân ma trận (để ghép nối, lưu trữ và chạy trên GPU theo cùng một cách), ta cần một mẹo.&lt;/p&gt;

&lt;h2 id=&quot;toạ-độ-thuần-nhất&quot;&gt;Toạ độ thuần nhất&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa.&lt;/strong&gt; Điểm $(x, y) \in \mathbb{R}^2$ có &lt;strong&gt;toạ độ thuần nhất&lt;/strong&gt; $(x, y, 1)$. Tổng quát hơn, $(X, Y, W)$ với $W \neq 0$ biểu diễn điểm $(X/W, Y/W)$. Vectơ hướng (hiệu hai điểm) có toạ độ thuần nhất $(x, y, 0)$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Phép tịnh tiến theo $t = (t_x, t_y)$ giờ là phép nhân ma trận:&lt;/p&gt;

\[T(t) = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; t_x \\ 0 &amp;amp; 1 &amp;amp; t_y \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}, \qquad T(t)\begin{bmatrix} x \\ y \\ 1 \end{bmatrix} = \begin{bmatrix} x + t_x \\ y + t_y \\ 1 \end{bmatrix}.\]

&lt;p&gt;Hình học: đặt mặt phẳng ảnh tại $W = 1$ trong không gian 3 chiều. Ma trận $T(t)$ là một &lt;strong&gt;phép trượt&lt;/strong&gt; tuyến tính của $\mathbb{R}^3$, giữ mặt phẳng $W = 1$ và trượt nó đi $t$. Tịnh tiến không tuyến tính trong 2D nhưng tuyến tính trong 3D.&lt;/p&gt;

&lt;p&gt;Mọi ánh xạ tuyến tính $2 \times 2$ $M$ (quay, co giãn, trượt, phản xạ) được nhúng thành&lt;/p&gt;

\[\begin{bmatrix} M &amp;amp; 0 \\ 0^T &amp;amp; 1 \end{bmatrix}, \qquad\text{ví dụ}\quad R(\theta) = \begin{bmatrix} \cos\theta &amp;amp; -\sin\theta &amp;amp; 0 \\ \sin\theta &amp;amp; \cos\theta &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix},\quad S(s_x, s_y) = \begin{bmatrix} s_x &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; s_y &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}.\]

&lt;p&gt;Phép biến đổi dạng $x \mapsto Mx + t$ gọi là &lt;strong&gt;phép biến đổi affine&lt;/strong&gt;; trong toạ độ thuần nhất nó là ma trận $\begin{bmatrix} M &amp;amp; t \\ 0^T &amp;amp; 1 \end{bmatrix}$.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Điểm và vectơ.&lt;/strong&gt; Với vectơ hướng $(x, y, 0)$, $T(t)$ không làm gì: dời một mũi tên không đổi hướng và độ dài của nó. Còn phép quay vẫn quay nó. Đây là lý do các thư viện đồ họa phân biệt &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vec4(p, 1.0)&lt;/code&gt; cho điểm và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vec4(d, 0.0)&lt;/code&gt; cho hướng (pháp tuyến, vận tốc).&lt;/p&gt;

&lt;h2 id=&quot;hợp-các-phép-biến-đổi&quot;&gt;Hợp các phép biến đổi&lt;/h2&gt;

&lt;p&gt;Vì mọi phép biến đổi giờ là ma trận, hợp các phép biến đổi là &lt;strong&gt;nhân ma trận&lt;/strong&gt;, và phép áp dụng &lt;strong&gt;trước&lt;/strong&gt; đứng &lt;strong&gt;bên phải&lt;/strong&gt;.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (quay quanh một điểm).&lt;/strong&gt; Để quay $90^\circ$ quanh điểm $c = (2, 1)$: dời $c$ về gốc, quay, rồi dời lại:&lt;/p&gt;

\[T(c)\,R(90^\circ)\,T(-c) = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 2 \\ 0 &amp;amp; 1 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}\begin{bmatrix} 0 &amp;amp; -1 &amp;amp; 0 \\ 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}\begin{bmatrix} 1 &amp;amp; 0 &amp;amp; -2 \\ 0 &amp;amp; 1 &amp;amp; -1 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix} = \begin{bmatrix} 0 &amp;amp; -1 &amp;amp; 3 \\ 1 &amp;amp; 0 &amp;amp; -1 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}.\]

  &lt;p&gt;Kiểm tra: $(2, 1, 1) \mapsto (-1 + 3, 2 - 1, 1) = (2, 1, 1)$, tâm đứng yên; $(3, 1, 1) \mapsto (2, 2, 1)$, điểm bên phải tâm quay lên trên tâm, đúng phép quay ngược chiều kim đồng hồ.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (thứ tự quan trọng).&lt;/strong&gt; Với $R = R(90^\circ)$ và $T = T(3, 0)$, xét điểm $p = (1, 0)$. $TRp$: quay được $(0, 1)$, rồi dời được $(3, 1)$. $RTp$: dời được $(4, 0)$, rồi quay được $(0, 4)$. Hai kết quả khác nhau: tịnh tiến và quay không giao hoán.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-đồ-thị-cảnh-trong-trò-chơi-và-cad&quot;&gt;Ứng dụng: đồ thị cảnh trong trò chơi và CAD&lt;/h2&gt;

&lt;p&gt;Một cảnh đồ họa thường là một cây: thế giới chứa chiếc xe, xe chứa bánh xe, bánh xe chứa các con ốc. Mỗi nút lưu một ma trận $3 \times 3$ (hoặc $4 \times 4$ trong 3D) mô tả vị trí so với nút cha. Vị trí thực của một con ốc là tích các ma trận từ gốc xuống nó: $M_{\text{thế giới}}M_{\text{xe}}M_{\text{bánh}}M_{\text{ốc}}$. Khi xe chạy, chỉ cần đổi một ma trận $M_{\text{xe}}$, mọi bộ phận con đi theo. Không có toạ độ thuần nhất, cách tổ chức gọn gàng này không làm được.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: tịnh tiến bằng ma trận 3 × 3&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo tịnh tiến, góc quay, tỉ lệ và xem ma trận thuần nhất M.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter12/dong_nhat_2d.html?mode=one&quot; title=&quot;Minh hoạ: tịnh tiến bằng ma trận 3 × 3&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter12/dong_nhat_2d.html?mode=one&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-tịnh-tiến-trở-thành-tuyến-tính-khi-thêm-một-chiều&quot;&gt;Video ngắn: Tịnh tiến trở thành tuyến tính khi thêm một chiều&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/homogeneous-lift.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Điểm (x; y) ↔ (x; y; 1): đặt mặt phẳng ảnh ở W = 1. T(3; 0) là phép trượt tuyến tính của R³. Quay 90° quanh c = (2; 1): T(c) R T(−c). Thứ tự quan trọng: quay rồi dời đưa (1; 0) tới (3; 1), dời rồi quay đưa nó tới (0; 4). Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Viết ma trận $3 \times 3$ của phép quay $90^\circ$ quanh điểm $(2, 1)$ theo &lt;strong&gt;chiều kim đồng hồ&lt;/strong&gt;, và kiểm tra ảnh của $(3, 1)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$T(2, 1)R(-90^\circ)T(-2, -1) = \begin{bmatrix} 0 &amp;amp; 1 &amp;amp; 1 \\ -1 &amp;amp; 0 &amp;amp; 3 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$. $(3, 1) \mapsto (1 + 1, -3 + 3) = (2, 0)$: điểm bên phải tâm đi xuống dưới tâm.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Viết ma trận co giãn hệ số $2$ quanh điểm $(1, 1)$ (điểm $(1, 1)$ đứng yên).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$T(1, 1)S(2, 2)T(-1, -1) = \begin{bmatrix} 2 &amp;amp; 0 &amp;amp; -1 \\ 0 &amp;amp; 2 &amp;amp; -1 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$. Kiểm tra: $(1, 1) \mapsto (1, 1)$, $(2, 1) \mapsto (3, 1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Tìm nghịch đảo của $\begin{bmatrix} M &amp;amp; t \\ 0^T &amp;amp; 1 \end{bmatrix}$ khi $M$ khả nghịch.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\begin{bmatrix} M^{-1} &amp;amp; -M^{-1}t \\ 0^T &amp;amp; 1 \end{bmatrix}$: từ $y = Mx + t$ suy ra $x = M^{-1}y - M^{-1}t$. Với $M$ là phép quay, $M^{-1} = M^T$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Chứng minh tích của hai ma trận affine $\begin{bmatrix} M_1 &amp;amp; t_1 \\ 0^T &amp;amp; 1 \end{bmatrix}\begin{bmatrix} M_2 &amp;amp; t_2 \\ 0^T &amp;amp; 1 \end{bmatrix}$ là ma trận affine, và viết nó ra.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Nhân khối: $\begin{bmatrix} M_1M_2 &amp;amp; M_1t_2 + t_1 \\ 0^T &amp;amp; 1 \end{bmatrix}$. Hàng cuối vẫn là $(0, 0, 1)$, nên tích vẫn là affine.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Điểm $(x, y) \leftrightarrow (x, y, 1)$; vectơ hướng $\leftrightarrow (x, y, 0)$.&lt;/li&gt;
    &lt;li&gt;Tịnh tiến $T(t) = \begin{bmatrix} I &amp;amp; t \\ 0^T &amp;amp; 1 \end{bmatrix}$ là phép trượt tuyến tính trong 3D; phép affine $x \mapsto Mx + t$ là $\begin{bmatrix} M &amp;amp; t \\ 0^T &amp;amp; 1 \end{bmatrix}$.&lt;/li&gt;
    &lt;li&gt;Hợp phép biến đổi là nhân ma trận, phép áp dụng trước đứng bên phải; quay quanh $c$ là $T(c)RT(-c)$.&lt;/li&gt;
    &lt;li&gt;Tịnh tiến và quay không giao hoán.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Transformation Chains and the Order of Matrix Products</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter12/12_04_Chuoi_Bien_Doi_Va_Thu_Tu_Nhan_Ma_Tran/"/>
   <updated>2026-01-12T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter12/12_04_Chuoi_Bien_Doi_Va_Thu_Tu_Nhan_Ma_Tran</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;order the model matrix as $M = TRS$ and the chain $PVM$ from object coordinates to the screen;&lt;/li&gt;
    &lt;li&gt;build the view matrix $V$ as the inverse of the camera pose, using $(AB)^{-1} = B^{-1}A^{-1}$;&lt;/li&gt;
    &lt;li&gt;switch between the column-vector and row-vector conventions, and transform normals with $(M^{-1})^T$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;A programmer wants to scale a chair by $2$, rotate it $90^\circ$ about the vertical axis, and place it at $(3, 0, 0)$ in a room. Writing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;M = S * R * T&lt;/code&gt; makes the chair float in a strange place, twice as far away as intended. The bug is not in any single matrix but in the &lt;strong&gt;order of multiplication&lt;/strong&gt;. This is the most common bug in graphics programming.&lt;/p&gt;

&lt;h2 id=&quot;the-model-matrix-m--trs&quot;&gt;The model matrix: $M = TRS$&lt;/h2&gt;

&lt;p&gt;With the &lt;strong&gt;column-vector&lt;/strong&gt; convention ($p&apos; = Mp$), the transformation applied first goes on the right. The standard order for an object is: scale about the object’s origin, then rotate about the object’s origin, then move it to its place in the world:&lt;/p&gt;

\[M = T\,R\,S.\]

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; $S = $ scaling by $2$, $R = R_z(90^\circ)$, $T = $ translation by $(3, 0, 0)$, applied to the object point $p = (1, 0, 0)$.&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;Correct, $TRSp$: $S$ gives $(2, 0, 0)$, $R$ gives $(0, 2, 0)$, $T$ gives $(3, 2, 0)$.&lt;/li&gt;
    &lt;li&gt;Wrong, $SRTp$: $T$ gives $(4, 0, 0)$, $R$ gives $(0, 4, 0)$, $S$ gives $(0, 8, 0)$: the position itself gets scaled and rotated.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;The $4 \times 4$ matrix of $TRS$:&lt;/p&gt;

\[M = \begin{bmatrix} 0 &amp;amp; -2 &amp;amp; 0 &amp;amp; 3 \\ 2 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 2 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}.\]

  &lt;p&gt;The upper-left $3 \times 3$ block is $RS$; the last column is the object’s position.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;the-modelviewprojection-chain&quot;&gt;The model–view–projection chain&lt;/h2&gt;

&lt;p&gt;The path of a vertex from the object’s data to the screen:&lt;/p&gt;

\[p_{\text{screen}} \sim P\,V\,M\,p_{\text{object}}.\]

&lt;ul&gt;
  &lt;li&gt;$M$ (model): object coordinates $\to$ world coordinates.&lt;/li&gt;
  &lt;li&gt;$V$ (view): world coordinates $\to$ camera coordinates (camera at the origin, looking along the conventional axis).&lt;/li&gt;
  &lt;li&gt;$P$ (projection): camera coordinates $\to$ image coordinates, followed by the perspective divide (Lesson 12-03).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Reading right to left follows the order of execution. The GPU precomputes the product $PVM$ once per object and multiplies it with millions of vertices.&lt;/p&gt;

&lt;h2 id=&quot;the-view-matrix-is-the-inverse-of-the-camera-pose&quot;&gt;The view matrix is the inverse of the camera pose&lt;/h2&gt;

&lt;p&gt;If the camera is placed in the world by a rotation $R_c$ and then moved to position $c$, so its pose is $C = T(c)R_c$, the view matrix must “undo” that placement:&lt;/p&gt;

\[V = C^{-1} = (T(c)R_c)^{-1} = R_c^{-1}T(c)^{-1} = R_c^T\,T(-c).\]

&lt;p&gt;The order reverses by the rule $(AB)^{-1} = B^{-1}A^{-1}$ (Lesson 03-04): first move the world so the camera sits at the origin, then rotate back.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; A camera at $c = (0, 0, -5)$ with no rotation ($R_c = I$), looking along the positive $z$ axis. Then $V = T(0, 0, 5)$. The world point $(3, 2, 0)$ from Example 1 has camera coordinates $(3, 2, 5)$ and, with focal length $f = 1$, projects to $(0.6, 0.4)$ on the screen.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;column-vectors-or-row-vectors&quot;&gt;Column vectors or row vectors&lt;/h2&gt;

&lt;p&gt;Some libraries (old DirectX, much older literature) write points as &lt;strong&gt;row vectors&lt;/strong&gt; multiplied on the right: $p&apos;^T = p^TM^T$. Transposing both sides of $p&apos; = TRSp$:&lt;/p&gt;

\[p&apos;^T = p^T\,S^T\,R^T\,T^T.\]

&lt;p&gt;The reading order becomes left to right in order of execution, and every matrix is transposed (the translation sits in the last row instead of the last column). Both conventions give the same geometry; bugs come from mixing them. One more trap: OpenGL stores matrices in column-major order in memory, so an array of 16 numbers can look transposed when printed.&lt;/p&gt;

&lt;h2 id=&quot;transforming-normals&quot;&gt;Transforming normals&lt;/h2&gt;

&lt;p&gt;Surface normals (used for lighting) do &lt;strong&gt;not&lt;/strong&gt; transform like points when $M$ contains non-uniform scaling.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; If tangent vectors transform by $A$ (the invertible $3 \times 3$ block of $M$), then normals must transform by $(A^{-1})^T$ to stay perpendicular.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; If $n^Tt = 0$ for every tangent $t$, then with $n&apos; = (A^{-1})^Tn$ and $t&apos; = At$: $n&apos;^Tt&apos; = n^TA^{-1}At = n^Tt = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Example: with $A = \operatorname{diag}(2, 1, 1)$, the plane $x + y = 0$ has normal $n = (1, 1, 0)$ and tangent $t = (1, -1, 0)$. After the transformation, $t&apos; = (2, -1, 0)$. Transforming the normal “like a point” gives $An = (2, 1, 0)$ and $(2, 1, 0) \cdot (2, -1, 0) = 3 \neq 0$: wrong. But $(A^{-1})^Tn = (\tfrac12, 1, 0)$ gives the dot product $1 - 1 = 0$. For a rotation, $(R^{-1})^T = R$, so there is no difference.&lt;/p&gt;

&lt;h2 id=&quot;application-the-vertex-shader&quot;&gt;Application: the vertex shader&lt;/h2&gt;

&lt;p&gt;In every 3D engine (Unity, Unreal, three.js), the program that runs on the GPU for each vertex (the vertex shader) is essentially two lines: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gl_Position = P * V * M * vec4(pos, 1.0);&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;normal = normalMatrix * n;&lt;/code&gt;, where &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;normalMatrix&lt;/code&gt; is $((VM)_{3 \times 3}^{-1})^T$. All of Chapter 12 lives in those two lines.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: T·R differs from R·T&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;The same rotation and translation in two orders give two different results.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter12/dong_nhat_2d.html?mode=order&amp;amp;lang=en&quot; title=&quot;Interactive: T·R differs from R·T&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter12/dong_nhat_2d.html?mode=order&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Write the $3 \times 3$ matrix (2D, homogeneous coordinates) of the chain: scale by $3$, rotate $90^\circ$, move to $(1, 2)$. What is the image of $(1, 1)$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$TRS = \begin{bmatrix} 0 &amp;amp; -3 &amp;amp; 1 \\ 3 &amp;amp; 0 &amp;amp; 2 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$. $(1, 1) \mapsto (-3 + 1, 3 + 2) = (-2, 5)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; A camera is placed by $R_c = R_y(180^\circ)$ and then moved to $c = (0, 0, 5)$ (standing at $z = 5$ looking toward the origin). Write $V$ and compute the camera coordinates of the world origin.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$V = R_c^TT(-c) = R_y(180^\circ)T(0, 0, -5)$ (since $R_y(180^\circ)^T = R_y(180^\circ)$). The origin: $T(0, 0, -5)$ gives $(0, 0, -5)$, then $R_y(180^\circ)$ gives $(0, 0, 5)$: the origin is $5$ units in front of the camera along its viewing axis.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; In the row-vector convention, rewrite $p&apos; = PVMp$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$p&apos;^T = p^TM^TV^TP^T$: read left to right in order of execution.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; For $A = \operatorname{diag}(1, 3, 1)$, compute the transformed normal of the plane with normal $n = (0, 1, 1)$, and check it against the tangent $t = (0, 1, -1)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$n&apos; = (A^{-1})^Tn = (0, \tfrac13, 1)$, $t&apos; = At = (0, 3, -1)$, and $n&apos; \cdot t&apos; = 1 - 1 = 0$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Column vectors: the first transformation goes on the right; the model matrix is $M = TRS$.&lt;/li&gt;
    &lt;li&gt;The chain to the screen: $p \sim PVMp_{\text{object}}$.&lt;/li&gt;
    &lt;li&gt;The view matrix is $V = (T(c)R_c)^{-1} = R_c^TT(-c)$.&lt;/li&gt;
    &lt;li&gt;Row vectors: $p&apos;^T = p^TM^TV^TP^T$, with every matrix transposed.&lt;/li&gt;
    &lt;li&gt;Normals transform by $(A^{-1})^T$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Perspective Projection and the Camera</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter12/12_03_Phep_Chieu_Phoi_Canh_Va_Camera/"/>
   <updated>2026-01-12T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter12/12_03_Phep_Chieu_Phoi_Canh_Va_Camera</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;set up the pinhole camera model and the projection formula $(x, y, z) \mapsto (fx/z, fy/z)$;&lt;/li&gt;
    &lt;li&gt;write perspective projection as a $3 \times 4$ matrix in homogeneous coordinates, with the intrinsic matrix $K$ converting to pixels;&lt;/li&gt;
    &lt;li&gt;find the vanishing point of a family of parallel lines, and distinguish perspective from orthographic projection.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Stand between railway tracks and look into the distance: the two parallel rails seem to meet at the horizon. Distant objects look smaller than near ones. Both effects come from one division: the image of a point on the screen scales like $1/z$, where $z$ is the distance along the viewing direction. Division is not linear, but homogeneous coordinates (Lesson 12-01) turn it into a matrix product.&lt;/p&gt;

&lt;h2 id=&quot;the-pinhole-camera&quot;&gt;The pinhole camera&lt;/h2&gt;

&lt;p&gt;Put the camera at the origin, looking along the positive $z$ axis, with the image plane $z = f$, where $f &amp;gt; 0$ is the &lt;strong&gt;focal length&lt;/strong&gt;. The light ray from $P = (x, y, z)$, $z &amp;gt; 0$, through the pinhole at the origin meets the image plane at (by similar triangles)&lt;/p&gt;

\[(x&apos;, y&apos;) = \left(\frac{fx}{z}, \frac{fy}{z}\right).\]

&lt;p&gt;&lt;strong&gt;The projection matrix.&lt;/strong&gt; In homogeneous coordinates:&lt;/p&gt;

\[\begin{bmatrix} X \\ Y \\ W \end{bmatrix} = \begin{bmatrix} f &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; f &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0 \end{bmatrix}\begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} = \begin{bmatrix} fx \\ fy \\ z \end{bmatrix}, \qquad (x&apos;, y&apos;) = \left(\frac{X}{W}, \frac{Y}{W}\right).\]

&lt;p&gt;All the nonlinearity sits in the final “divide by $W$” step (the perspective divide). Everything before it is linear algebra.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Converting to pixels.&lt;/strong&gt; The sensor has its origin at an image corner and uses pixels. With focal lengths $f_x, f_y$ in pixels and principal point $(c_x, c_y)$, the &lt;strong&gt;intrinsic&lt;/strong&gt; matrix is&lt;/p&gt;

\[K = \begin{bmatrix} f_x &amp;amp; 0 &amp;amp; c_x \\ 0 &amp;amp; f_y &amp;amp; c_y \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}, \qquad \begin{bmatrix} u \\ v \\ 1 \end{bmatrix} \sim K\begin{bmatrix} x \\ y \\ z \end{bmatrix},\]

&lt;p&gt;where $\sim$ means equal after dividing by the last coordinate. If the camera is not at the origin but has orientation $R$ and position such that a world point $P_w$ corresponds to $P = RP_w + t$ in camera coordinates, the full $3 \times 4$ &lt;strong&gt;camera matrix&lt;/strong&gt; is $K[R \mid t]$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; A camera with $f_x = f_y = 800$ pixels and principal point $(640, 360)$ (a $1280 \times 720$ image). The point $P = (0.5, -0.2, 4)$ (meters) gives&lt;/p&gt;

\[u = 800 \cdot \frac{0.5}{4} + 640 = 740, \qquad v = 800 \cdot \frac{-0.2}{4} + 360 = 320.\]

  &lt;p&gt;Move the point twice as far, $P = (0.5, -0.2, 8)$: $(u, v) = (690, 340)$, closer to the image center.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;a-box-and-vanishing-points&quot;&gt;A box and vanishing points&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; A box has front face the square with corners $(\pm1, \pm1, 4)$ and back face $(\pm1, \pm1, 6)$; the focal length is $f = 2$. The front face projects to the square with corners $(\pm\tfrac12, \pm\tfrac12)$, the back face to the smaller square $(\pm\tfrac13, \pm\tfrac13)$. The four edges joining the faces (parallel to the $z$ axis) project to four segments which, extended, meet at the center $(0, 0)$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Vanishing points).&lt;/strong&gt; Lines $P + sd$ with a common direction $d$, $d_z \neq 0$, project to lines through one common point, the &lt;strong&gt;vanishing point&lt;/strong&gt; $\left(\dfrac{fd_x}{d_z}, \dfrac{fd_y}{d_z}\right)$, independent of $P$. If $d_z = 0$ (lines parallel to the image plane), the images stay parallel.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; The image of $P + sd$ is $\left(\dfrac{f(P_x + sd_x)}{P_z + sd_z}, \dfrac{f(P_y + sd_y)}{P_z + sd_z}\right)$. As $s \to \infty$ this tends to $\left(\dfrac{fd_x}{d_z}, \dfrac{fd_y}{d_z}\right)$. In homogeneous coordinates: the point at infinity in direction $d$ is $(d_x, d_y, d_z, 0)$ (a direction vector, $w = 0$), and the projection matrix sends it to $(fd_x, fd_y, d_z)$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;In Example 2, $d = (0, 0, 1)$ gives the vanishing point $(0, 0)$, as observed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Orthographic projection.&lt;/strong&gt; Dropping the division, $(x, y, z) \mapsto (x, y)$ is &lt;strong&gt;orthographic projection&lt;/strong&gt; (the linear matrix $\begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 0 \end{bmatrix}$). Parallel lines stay parallel, and objects do not shrink with distance. Technical drawings and many strategy games use orthographic projection; photographs and human vision are perspective.&lt;/p&gt;

&lt;h2 id=&quot;application-augmented-reality-and-depth-sensing&quot;&gt;Application: augmented reality and depth sensing&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Augmented reality (AR).&lt;/strong&gt; To place a virtual object on a table in a video, an app estimates $K$ (calibrating the camera once) and $[R \mid t]$ (every frame), then projects the virtual object’s vertices with $K[R \mid t]$.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Stereo cameras.&lt;/strong&gt; Two parallel cameras a baseline $B$ apart see a point at depth $z$; its images are shifted by $d = fB/z$ pixels (the disparity). Measuring $d$ gives $z = fB/d$: this is how dual phone cameras and self-driving cars compute depth maps.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: camera and perspective projection&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Change focal length f and distance d, switch perspective on or off and watch the image.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter12/khoi_lap_phuong_3d.html?mode=cam&amp;amp;lang=en&quot; title=&quot;Interactive: camera and perspective projection&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter12/khoi_lap_phuong_3d.html?mode=cam&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-a-pinhole-camera-looks-at-a-cube&quot;&gt;Short video: A pinhole camera looks at a cube&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/perspective-cube.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Virtual image plane z = f = 2. Box: the front face z = 4 projects to a square of half-side 1/2, the back face z = 6 to half-side 1/3. The four edges joining the two faces meet at the vanishing point (0; 0). Moving the box farther makes its image smaller. Pixel conversion: f = 800, center (640; 360). Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; With $f = 1$, project the points $(2, 1, 5)$ and $(4, 2, 10)$. What do you notice?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Both give $(0.4, 0.2)$: the two points lie on the same ray through the pinhole, so they share an image. The homogeneous coordinates $(X, Y, W)$ and $(2X, 2Y, 2W)$ represent the same point.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Find the vanishing point of lines with direction $d = (1, 1, 2)$ when $f = 2$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\left(\tfrac{2 \cdot 1}{2}, \tfrac{2 \cdot 1}{2}\right) = (1, 1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Show that perspective projection does not preserve midpoints: take $A = (0, 0, 2)$, $B = (2, 0, 6)$, $f = 1$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Images: $A&apos; = (0, 0)$, $B&apos; = (\tfrac13, 0)$, with midpoint $(\tfrac16, 0)$. The midpoint $M = (1, 0, 4)$ has image $(\tfrac14, 0) \neq (\tfrac16, 0)$. Projection maps lines to lines but does not preserve length ratios.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Two cameras are $B = 0.12$ m apart with $f = 700$ pixels. A point has disparity $d = 21$ pixels. Find its depth.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$z = fB/d = 700 \cdot 0.12/21 = 4$ m.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Pinhole camera: $(x, y, z) \mapsto (fx/z, fy/z)$; in homogeneous coordinates, a $3 \times 4$ matrix followed by division by $W$.&lt;/li&gt;
    &lt;li&gt;The intrinsic matrix $K$ converts to pixels; the full camera matrix is $K[R \mid t]$.&lt;/li&gt;
    &lt;li&gt;Parallel lines with direction $d$ converge to the vanishing point $(fd_x/d_z, fd_y/d_z)$, the image of the point at infinity $(d, 0)$.&lt;/li&gt;
    &lt;li&gt;Orthographic projection drops the division: it is linear and keeps lines parallel.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Rotations in R³</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter12/12_02_Phep_Quay_Trong_R3/"/>
   <updated>2026-01-12T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter12/12_02_Phep_Quay_Trong_R3</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;write the rotation matrices about the $x$, $y$ and $z$ axes;&lt;/li&gt;
    &lt;li&gt;use Rodrigues’ formula to write the rotation about an arbitrary axis, and read the axis and angle from a rotation matrix;&lt;/li&gt;
    &lt;li&gt;show by example that 3D rotations do not commute.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Lay a book face up on a table. Rotate it $90^\circ$ about the axis pointing toward you, then $90^\circ$ about the vertical axis. Take a second book and do the same two steps in the opposite order. The two books end up in different poses. In 2D, all rotations about the origin commute ($R(\alpha)R(\beta) = R(\alpha + \beta)$); in 3D they do not. Matrices explain exactly why.&lt;/p&gt;

&lt;h2 id=&quot;rotations-about-the-coordinate-axes&quot;&gt;Rotations about the coordinate axes&lt;/h2&gt;

&lt;p&gt;A rotation by $\theta$ about a coordinate axis fixes that axis and rotates the perpendicular plane as in 2D (by the right-hand rule: thumb along the positive axis, fingers show the direction of rotation):&lt;/p&gt;

\[R_x(\theta) = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; \cos\theta &amp;amp; -\sin\theta \\ 0 &amp;amp; \sin\theta &amp;amp; \cos\theta \end{bmatrix}, \quad R_y(\theta) = \begin{bmatrix} \cos\theta &amp;amp; 0 &amp;amp; \sin\theta \\ 0 &amp;amp; 1 &amp;amp; 0 \\ -\sin\theta &amp;amp; 0 &amp;amp; \cos\theta \end{bmatrix}, \quad R_z(\theta) = \begin{bmatrix} \cos\theta &amp;amp; -\sin\theta &amp;amp; 0 \\ \sin\theta &amp;amp; \cos\theta &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}.\]

&lt;p&gt;Note the signs in $R_y$: following the cycle $x \to y \to z \to x$, the plane perpendicular to the $y$ axis is ordered $(z, x)$, so the positive $\sin\theta$ sits in the upper right.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition.&lt;/strong&gt; A $3 \times 3$ matrix $R$ is a &lt;strong&gt;rotation matrix&lt;/strong&gt; if $R^TR = I$ and $\det R = 1$. The set of rotation matrices is denoted $SO(3)$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;An orthogonal matrix with $\det = -1$ is a rotation combined with a reflection (Lesson 07-07). A product of rotations is a rotation.&lt;/p&gt;

&lt;h2 id=&quot;non-commutativity&quot;&gt;Non-commutativity&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; With $A = R_x(90^\circ) = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; -1 \\ 0 &amp;amp; 1 &amp;amp; 0 \end{bmatrix}$ and $B = R_z(90^\circ) = \begin{bmatrix} 0 &amp;amp; -1 &amp;amp; 0 \\ 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$:&lt;/p&gt;

\[AB = \begin{bmatrix} 0 &amp;amp; -1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; -1 \\ 1 &amp;amp; 0 &amp;amp; 0 \end{bmatrix}, \qquad BA = \begin{bmatrix} 0 &amp;amp; 0 &amp;amp; 1 \\ 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 0 \end{bmatrix}.\]

  &lt;p&gt;Look at $e_1$: $ABe_1 = Ae_2 = e_3$, while $BAe_1 = Be_1 = e_2$. Different orders give different results.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;rotation-about-an-arbitrary-axis-rodrigues-formula&quot;&gt;Rotation about an arbitrary axis: Rodrigues’ formula&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Rodrigues).&lt;/strong&gt; The rotation by $\theta$ about the axis with unit vector $k = (k_1, k_2, k_3)$ has matrix&lt;/p&gt;

\[R = I + \sin\theta\,K + (1 - \cos\theta)\,K^2, \qquad K = \begin{bmatrix} 0 &amp;amp; -k_3 &amp;amp; k_2 \\ k_3 &amp;amp; 0 &amp;amp; -k_1 \\ -k_2 &amp;amp; k_1 &amp;amp; 0 \end{bmatrix},\]

  &lt;p&gt;where $Kv = k \times v$ (the cross product).&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof sketch.&lt;/strong&gt; Split $v = (k \cdot v)k + v_\perp$. The component along the axis stays fixed. In the plane perpendicular to $k$, the perpendicular vectors $v_\perp$ and $k \times v$ have the same length, and the rotation gives $v_\perp \mapsto \cos\theta\,v_\perp + \sin\theta\,(k \times v)$. Since $K^2v = k \times (k \times v) = -v_\perp$, we get $Rv = v + \sin\theta\,Kv + (1 - \cos\theta)K^2v$, which is the formula.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; Rotate by $120^\circ$ about $k = \tfrac{1}{\sqrt3}(1, 1, 1)$. Here $\sin\theta = \tfrac{\sqrt3}{2}$, $1 - \cos\theta = \tfrac32$, and $K^2 = kk^T - I$. Substituting gives&lt;/p&gt;

\[R = \begin{bmatrix} 0 &amp;amp; 0 &amp;amp; 1 \\ 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 0 \end{bmatrix},\]

  &lt;p&gt;the permutation $e_1 \to e_2 \to e_3 \to e_1$. This is exactly $BA$ from Example 1: the product of two $90^\circ$ rotations about coordinate axes is a $120^\circ$ rotation about the diagonal.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Reading the axis and angle from a matrix.&lt;/strong&gt; Every $R \in SO(3)$ is a rotation about some axis (Euler’s theorem): the axis is the eigenvector for eigenvalue $1$, and the angle satisfies $\operatorname{tr} R = 1 + 2\cos\theta$. For $R$ in Example 2: $\operatorname{tr} R = 0$, so $\cos\theta = -\tfrac12$, $\theta = 120^\circ$. The other eigenvalues are $e^{\pm i\theta}$ (Lesson 09-05).&lt;/p&gt;

&lt;h2 id=&quot;application-euler-angles-gimbal-lock-and-quaternions&quot;&gt;Application: Euler angles, gimbal lock and quaternions&lt;/h2&gt;

&lt;p&gt;Aircraft and cameras often describe orientation with three &lt;strong&gt;yaw–pitch–roll&lt;/strong&gt; angles: $R = R_z(\psi)R_y(\vartheta)R_x(\varphi)$. This is intuitive but has a singularity: at $\vartheta = 90^\circ$, the other two rotation axes coincide and one degree of freedom is lost (&lt;strong&gt;gimbal lock&lt;/strong&gt;, a situation Apollo astronauts had to actively avoid). That is why graphics engines and control systems store and interpolate rotations as unit &lt;strong&gt;quaternions&lt;/strong&gt; $q = (\cos\tfrac\theta2, \sin\tfrac\theta2\,k)$, converting to the Rodrigues matrix when points must be multiplied.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: rotating a cube in R³&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag α, β, γ, see the rotation matrix R and compare two multiplication orders.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter12/khoi_lap_phuong_3d.html?mode=rot&amp;amp;lang=en&quot; title=&quot;Interactive: rotating a cube in R³&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter12/khoi_lap_phuong_3d.html?mode=rot&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Check that $R_y(\theta)$ is a rotation matrix ($R^TR = I$, $\det R = 1$) and compute $R_y(90^\circ)e_3$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The columns are orthonormal and $\det = \cos^2\theta + \sin^2\theta = 1$. $R_y(90^\circ)e_3 = $ column 3 $= (1, 0, 0) = e_1$: rotating about $y$ takes $z$ to $x$, matching the cycle $z \to x$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Show by a numerical example that $R_x(90^\circ)R_y(90^\circ) \neq R_y(90^\circ)R_x(90^\circ)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Take $e_3$: $R_y(90^\circ)e_3 = e_1$ and $R_x(90^\circ)e_1 = e_1$, so $R_xR_ye_3 = e_1$. But $R_x(90^\circ)e_3 = -e_2$ and $R_y(90^\circ)(-e_2) = -e_2$, so $R_yR_xe_3 = -e_2 \neq e_1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Find the axis and angle of the rotation $R = \begin{bmatrix} 0 &amp;amp; -1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; -1 \\ 1 &amp;amp; 0 &amp;amp; 0 \end{bmatrix}$ ($AB$ from Example 1).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\operatorname{tr} R = 0$, so $\theta = 120^\circ$. Solving $Rv = v$: $-v_2 = v_1$, $-v_3 = v_2$, $v_1 = v_3$, giving $v = (1, -1, 1)$. The axis is $\tfrac{1}{\sqrt3}(1, -1, 1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (programming).&lt;/strong&gt; Draw the cube $[-1, 1]^3$ (12 edges) with NumPy and Matplotlib, rotate it by $R_z(30^\circ)R_x(20^\circ)$ and project it orthographically onto the $xy$ plane.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Build the $8 \times 3$ array of vertices $(\pm1, \pm1, \pm1)$; an edge joins two vertices differing in exactly one coordinate. Compute `P = V @ R.T` (each row is a vertex, so multiply by $R^T$ on the right) and draw `plt.plot` on the first two columns for each pair of vertices.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$R_x$, $R_y$, $R_z$ fix one axis and rotate the perpendicular plane; mind the signs in $R_y$.&lt;/li&gt;
    &lt;li&gt;Rotation matrices: $R^TR = I$, $\det R = 1$; products of rotations are rotations.&lt;/li&gt;
    &lt;li&gt;Rodrigues: $R = I + \sin\theta\,K + (1 - \cos\theta)K^2$; the axis is the eigenvector for $1$, and $\operatorname{tr} R = 1 + 2\cos\theta$.&lt;/li&gt;
    &lt;li&gt;3D rotations do not commute; Euler angles suffer gimbal lock, so practice uses quaternions.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Homogeneous Coordinates and Translations</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter12/12_01_Toa_Do_Thuan_Nhat_Va_Phep_Tinh_Tien/"/>
   <updated>2026-01-12T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter12/12_01_Toa_Do_Thuan_Nhat_Va_Phep_Tinh_Tien</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;explain why a translation is not a linear map of $\mathbb{R}^2$;&lt;/li&gt;
    &lt;li&gt;write translations, rotations and scalings as $3 \times 3$ matrices in homogeneous coordinates;&lt;/li&gt;
    &lt;li&gt;compose transformations, such as a rotation about an arbitrary point, and distinguish points ($w = 1$) from direction vectors ($w = 0$).&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;In a 2D game, a character must be &lt;strong&gt;rotated&lt;/strong&gt; $90^\circ$ about its center and then &lt;strong&gt;moved&lt;/strong&gt; $3$ units to the right. The rotation is a $2 \times 2$ matrix product (Lesson 06-02). But the move $x \mapsto x + t$ is not: it sends $0$ to $t \neq 0$, while every linear map fixes the origin. If we want every transformation to be a matrix product (to chain, store and run them on the GPU in one uniform way), we need a trick.&lt;/p&gt;

&lt;h2 id=&quot;homogeneous-coordinates&quot;&gt;Homogeneous coordinates&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition.&lt;/strong&gt; The point $(x, y) \in \mathbb{R}^2$ has &lt;strong&gt;homogeneous coordinates&lt;/strong&gt; $(x, y, 1)$. More generally, $(X, Y, W)$ with $W \neq 0$ represents the point $(X/W, Y/W)$. A direction vector (a difference of two points) has homogeneous coordinates $(x, y, 0)$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Translation by $t = (t_x, t_y)$ is now a matrix product:&lt;/p&gt;

\[T(t) = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; t_x \\ 0 &amp;amp; 1 &amp;amp; t_y \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}, \qquad T(t)\begin{bmatrix} x \\ y \\ 1 \end{bmatrix} = \begin{bmatrix} x + t_x \\ y + t_y \\ 1 \end{bmatrix}.\]

&lt;p&gt;Geometrically: place the image plane at $W = 1$ in 3D space. The matrix $T(t)$ is a linear &lt;strong&gt;shear&lt;/strong&gt; of $\mathbb{R}^3$ that keeps the plane $W = 1$ and slides it by $t$. A translation is not linear in 2D but is linear in 3D.&lt;/p&gt;

&lt;p&gt;Every $2 \times 2$ linear map $M$ (rotation, scaling, shear, reflection) embeds as&lt;/p&gt;

\[\begin{bmatrix} M &amp;amp; 0 \\ 0^T &amp;amp; 1 \end{bmatrix}, \qquad\text{e.g.}\quad R(\theta) = \begin{bmatrix} \cos\theta &amp;amp; -\sin\theta &amp;amp; 0 \\ \sin\theta &amp;amp; \cos\theta &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix},\quad S(s_x, s_y) = \begin{bmatrix} s_x &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; s_y &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}.\]

&lt;p&gt;A transformation $x \mapsto Mx + t$ is called an &lt;strong&gt;affine transformation&lt;/strong&gt;; in homogeneous coordinates it is the matrix $\begin{bmatrix} M &amp;amp; t \\ 0^T &amp;amp; 1 \end{bmatrix}$.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Points and vectors.&lt;/strong&gt; On a direction vector $(x, y, 0)$, $T(t)$ does nothing: moving an arrow does not change its direction or length. A rotation still rotates it. This is why graphics libraries distinguish &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vec4(p, 1.0)&lt;/code&gt; for points from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vec4(d, 0.0)&lt;/code&gt; for directions (normals, velocities).&lt;/p&gt;

&lt;h2 id=&quot;composing-transformations&quot;&gt;Composing transformations&lt;/h2&gt;

&lt;p&gt;Since every transformation is now a matrix, composing transformations is &lt;strong&gt;matrix multiplication&lt;/strong&gt;, and the transformation applied &lt;strong&gt;first&lt;/strong&gt; goes on the &lt;strong&gt;right&lt;/strong&gt;.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (rotation about a point).&lt;/strong&gt; To rotate $90^\circ$ about $c = (2, 1)$: move $c$ to the origin, rotate, move back:&lt;/p&gt;

\[T(c)\,R(90^\circ)\,T(-c) = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 2 \\ 0 &amp;amp; 1 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}\begin{bmatrix} 0 &amp;amp; -1 &amp;amp; 0 \\ 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}\begin{bmatrix} 1 &amp;amp; 0 &amp;amp; -2 \\ 0 &amp;amp; 1 &amp;amp; -1 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix} = \begin{bmatrix} 0 &amp;amp; -1 &amp;amp; 3 \\ 1 &amp;amp; 0 &amp;amp; -1 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}.\]

  &lt;p&gt;Check: $(2, 1, 1) \mapsto (-1 + 3, 2 - 1, 1) = (2, 1, 1)$, so the center stays fixed; $(3, 1, 1) \mapsto (2, 2, 1)$: the point to the right of the center moves above it, a counterclockwise rotation.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (order matters).&lt;/strong&gt; With $R = R(90^\circ)$ and $T = T(3, 0)$, take $p = (1, 0)$. $TRp$: rotating gives $(0, 1)$, then moving gives $(3, 1)$. $RTp$: moving gives $(4, 0)$, then rotating gives $(0, 4)$. The results differ: translations and rotations do not commute.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-scene-graphs-in-games-and-cad&quot;&gt;Application: scene graphs in games and CAD&lt;/h2&gt;

&lt;p&gt;A graphics scene is usually a tree: the world contains a car, the car contains wheels, the wheels contain bolts. Each node stores a $3 \times 3$ matrix ($4 \times 4$ in 3D) describing its placement relative to its parent. The actual position of a bolt is the product of the matrices from the root down to it: $M_{\text{world}}M_{\text{car}}M_{\text{wheel}}M_{\text{bolt}}$. When the car moves, only $M_{\text{car}}$ changes and every child part follows. Without homogeneous coordinates, this tidy organization would not be possible.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: translation as a 3 × 3 matrix&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag translation, angle and scale and see the homogeneous matrix M.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter12/dong_nhat_2d.html?mode=one&amp;amp;lang=en&quot; title=&quot;Interactive: translation as a 3 × 3 matrix&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter12/dong_nhat_2d.html?mode=one&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-translation-becomes-linear-when-you-add-a-dimension&quot;&gt;Short video: Translation becomes linear when you add a dimension&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/homogeneous-lift.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Point (x; y) ↔ (x; y; 1): place the image plane at W = 1. T(3; 0) is a linear shear of R³. Rotate 90° about c = (2; 1): T(c) R T(−c). Order matters: rotate then translate sends (1; 0) to (3; 1); translate then rotate sends it to (0; 4). Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Write the $3 \times 3$ matrix of the &lt;strong&gt;clockwise&lt;/strong&gt; $90^\circ$ rotation about $(2, 1)$, and check the image of $(3, 1)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$T(2, 1)R(-90^\circ)T(-2, -1) = \begin{bmatrix} 0 &amp;amp; 1 &amp;amp; 1 \\ -1 &amp;amp; 0 &amp;amp; 3 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$. $(3, 1) \mapsto (1 + 1, -3 + 3) = (2, 0)$: the point to the right of the center moves below it.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Write the matrix of scaling by $2$ about the point $(1, 1)$ (so $(1, 1)$ stays fixed).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$T(1, 1)S(2, 2)T(-1, -1) = \begin{bmatrix} 2 &amp;amp; 0 &amp;amp; -1 \\ 0 &amp;amp; 2 &amp;amp; -1 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$. Check: $(1, 1) \mapsto (1, 1)$, $(2, 1) \mapsto (3, 1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Find the inverse of $\begin{bmatrix} M &amp;amp; t \\ 0^T &amp;amp; 1 \end{bmatrix}$ when $M$ is invertible.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\begin{bmatrix} M^{-1} &amp;amp; -M^{-1}t \\ 0^T &amp;amp; 1 \end{bmatrix}$: from $y = Mx + t$ we get $x = M^{-1}y - M^{-1}t$. For a rotation $M$, $M^{-1} = M^T$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Prove that the product of two affine matrices $\begin{bmatrix} M_1 &amp;amp; t_1 \\ 0^T &amp;amp; 1 \end{bmatrix}\begin{bmatrix} M_2 &amp;amp; t_2 \\ 0^T &amp;amp; 1 \end{bmatrix}$ is affine, and write it out.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Block multiplication: $\begin{bmatrix} M_1M_2 &amp;amp; M_1t_2 + t_1 \\ 0^T &amp;amp; 1 \end{bmatrix}$. The last row is still $(0, 0, 1)$, so the product is affine.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Point $(x, y) \leftrightarrow (x, y, 1)$; direction vector $\leftrightarrow (x, y, 0)$.&lt;/li&gt;
    &lt;li&gt;Translation $T(t) = \begin{bmatrix} I &amp;amp; t \\ 0^T &amp;amp; 1 \end{bmatrix}$ is a linear shear in 3D; the affine map $x \mapsto Mx + t$ is $\begin{bmatrix} M &amp;amp; t \\ 0^T &amp;amp; 1 \end{bmatrix}$.&lt;/li&gt;
    &lt;li&gt;Composition is matrix multiplication, with the first transformation on the right; rotation about $c$ is $T(c)RT(-c)$.&lt;/li&gt;
    &lt;li&gt;Translations and rotations do not commute.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Nén ảnh và khử nhiễu bằng SVD</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter11/11_06_Nen_Anh_Va_Khu_Nhieu_Bang_SVD/"/>
   <updated>2026-01-11T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter11/11_06_Nen_Anh_Va_Khu_Nhieu_Bang_SVD</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;nén một ảnh xám bằng xấp xỉ hạng $k$ và tính tỷ lệ nén;&lt;/li&gt;
    &lt;li&gt;đánh giá sai số tái tạo theo $k$ từ các giá trị kỳ dị;&lt;/li&gt;
    &lt;li&gt;giải thích vì sao cắt bỏ các giá trị kỳ dị nhỏ giúp khử nhiễu, và chọn ngưỡng cắt.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;p&gt;Đây là bài &lt;strong&gt;tùy chọn&lt;/strong&gt;, chủ yếu là thực hành lập trình trên kết quả của Bài 11-03.&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Một ảnh xám $512 \times 512$ là một ma trận $A$ gồm $262\,144$ số (độ sáng từ $0$ đến $255$). Ảnh tự nhiên có cấu trúc: các vùng trơn, các cạnh, các mẫu lặp lại. Vì vậy giá trị kỳ dị của $A$ giảm rất nhanh, và xấp xỉ hạng thấp $A_k$ (Bài 11-03) với $k$ vài chục đã nhìn khá giống ảnh gốc.&lt;/p&gt;

&lt;h2 id=&quot;nén-bằng-svd&quot;&gt;Nén bằng SVD&lt;/h2&gt;

&lt;p&gt;Lưu $A_k = \sum_{i \le k}\sigma_iu_iv_i^T$ cần $k$ giá trị kỳ dị, $k$ vectơ $u_i \in \mathbb{R}^m$ và $k$ vectơ $v_i \in \mathbb{R}^n$:&lt;/p&gt;

\[\text{tỷ lệ lưu trữ} = \frac{k(m + n + 1)}{mn}.\]

&lt;p&gt;Với $m = n = 512$, $k = 50$: $50 \cdot 1025 = 51\,250$ số, khoảng $19{,}6\%$ ảnh gốc. Nén chỉ có lợi khi $k(m + n + 1) &amp;lt; mn$, tức $k &amp;lt; 255{,}75$ ở đây.&lt;/p&gt;

&lt;p&gt;Sai số tương đối (Eckart–Young):&lt;/p&gt;

\[\frac{\lVert A - A_k \rVert_F}{\lVert A \rVert_F} = \sqrt{\frac{\sum_{i &amp;gt; k}\sigma_i^2}{\sum_i\sigma_i^2}}.\]

&lt;p&gt;Trong thực tế, JPEG nén tốt hơn SVD nhiều (dùng biến đổi cosin rời rạc trên từng khối $8 \times 8$ và mã hoá entropy). SVD vẫn là ví dụ đẹp nhất để &lt;em&gt;thấy&lt;/em&gt; xấp xỉ hạng thấp, và là nền tảng của nén trong các bối cảnh khác (ma trận trọng số mạng nơ-ron, dữ liệu khoa học).&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (đọc phổ giá trị kỳ dị).&lt;/strong&gt; Giả sử một ảnh có $\sigma_i \approx 10^4 \cdot i^{-1}$ với $i = 1, \dots, 512$. Tổng $\sum\sigma_i^2 \approx 10^8 \cdot \sum i^{-2} \approx 10^8 \cdot 1{,}64$, còn phần bị bỏ khi $k = 50$ là $\sum_{i &amp;gt; 50}\sigma_i^2 \approx 10^8 \cdot 0{,}018$ (gần $\tfrac{1}{50}$). Sai số tương đối $\approx\sqrt{0{,}018/1{,}64} \approx 10\%$. Phổ giảm càng nhanh (ảnh càng trơn), sai số càng nhỏ với cùng $k$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;khử-nhiễu-bằng-cắt-cụt&quot;&gt;Khử nhiễu bằng cắt cụt&lt;/h2&gt;

&lt;p&gt;Giả sử ta quan sát $\tilde A = A + E$, với $A$ là ảnh sạch (hạng thấp hoặc gần hạng thấp) và $E$ là nhiễu ngẫu nhiên độc lập, độ lệch chuẩn $s$ ở mỗi điểm ảnh. Hai sự thật:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Nhiễu &lt;strong&gt;không có cấu trúc&lt;/strong&gt;: năng lượng của $E$ trải đều trên mọi hướng, nên mọi giá trị kỳ dị của $E$ cùng cỡ nhau. Lý thuyết ma trận ngẫu nhiên cho biết giá trị kỳ dị lớn nhất của $E$ (cỡ $m \times n$) xấp xỉ $s(\sqrt m + \sqrt n)$.&lt;/li&gt;
  &lt;li&gt;Tín hiệu &lt;strong&gt;có cấu trúc&lt;/strong&gt;: năng lượng của $A$ tập trung ở vài giá trị kỳ dị lớn.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Vậy các giá trị kỳ dị của $\tilde A$ lớn hơn hẳn $s(\sqrt m + \sqrt n)$ chủ yếu là tín hiệu; các giá trị dưới ngưỡng đó chủ yếu là nhiễu. &lt;strong&gt;Cắt cụt&lt;/strong&gt;, tức chỉ giữ $\tilde A_k$ với $\sigma_k$ trên ngưỡng, bỏ đi phần lớn nhiễu mà giữ lại phần lớn tín hiệu.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Nhận xét (sai số sau cắt cụt).&lt;/strong&gt; Nếu $A$ có hạng $k$, thì $\lVert \tilde A_k - A \rVert_F \le 2\sqrt{2k}\,\lVert E \rVert_2$ (dùng Eckart–Young và bất đẳng thức tam giác). Trong khi đó $\lVert \tilde A - A \rVert_F = \lVert E \rVert_F$, cỡ $s\sqrt{mn}$. Với $k$ nhỏ, $\sqrt{k}\,\lVert E \rVert_2 \approx s\sqrt k(\sqrt m + \sqrt n)$ nhỏ hơn rất nhiều.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Phác thảo.&lt;/strong&gt; $\tilde A_k - A$ có hạng $\le 2k$, nên $\lVert \tilde A_k - A \rVert_F \le \sqrt{2k}\,\lVert \tilde A_k - A \rVert_2$. Mà $\lVert \tilde A_k - A \rVert_2 \le \lVert \tilde A_k - \tilde A \rVert_2 + \lVert \tilde A - A \rVert_2 = \sigma_{k+1}(\tilde A) + \lVert E \rVert_2 \le 2\lVert E \rVert_2$, vì theo Eckart–Young $\sigma_{k+1}(\tilde A) \le \lVert \tilde A - A \rVert_2$ ($A$ có hạng $k$).&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-video-giám-sát-và-dữ-liệu-khoa-học&quot;&gt;Ứng dụng: video giám sát và dữ liệu khoa học&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tách nền trong video.&lt;/strong&gt; Xếp mỗi khung hình của một camera cố định thành một cột của ma trận. Nền tĩnh gần như giống nhau ở mọi khung, nên phần nền là xấp xỉ hạng rất thấp (thường hạng $1$ đến $3$); phần dư $\tilde A - \tilde A_k$ chứa người và xe di chuyển.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khử nhiễu ảnh hiển vi điện tử, MRI, dữ liệu phổ.&lt;/strong&gt; Các phương pháp như ngưỡng cứng tối ưu của Gavish và Donoho (2014) chọn ngưỡng cắt tự động từ kích thước ma trận và mức nhiễu ước lượng.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: nén ảnh và khử nhiễu bằng SVD&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo k để giữ k giá trị kỳ dị lớn nhất, thêm nhiễu để thấy SVD khử nhiễu.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter11/nen_anh.html&quot; title=&quot;Minh hoạ: nén ảnh và khử nhiễu bằng SVD&quot; loading=&quot;lazy&quot; style=&quot;height: 600px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter11/nen_anh.html&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Với ảnh $1200 \times 800$, $k$ lớn nhất là bao nhiêu để nén còn có lợi? Với $k = 100$, tỷ lệ lưu trữ là bao nhiêu?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$k(2001) &amp;lt; 960\,000$, tức $k \le 479$. Với $k = 100$: $200\,100/960\,000 \approx 20{,}8\%$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Ảnh có các giá trị kỳ dị (đã làm tròn) $\sigma_1 = 100$, $\sigma_2 = 40$, $\sigma_3 = 20$, các giá trị còn lại có tổng bình phương $100$. Tính sai số tương đối của $A_1$, $A_2$, $A_3$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\sum\sigma_i^2 = 10\,000 + 1600 + 400 + 100 = 12\,100$, $\lVert A \rVert_F = 110$. $A_1$: $\sqrt{2100}/110 \approx 0{,}42$; $A_2$: $\sqrt{500}/110 \approx 0{,}20$; $A_3$: $\sqrt{100}/110 \approx 0{,}09$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Một ma trận nhiễu $E$ cỡ $400 \times 400$ có các phần tử độc lập, độ lệch chuẩn $s = 2$. Ước lượng $\lVert E \rVert_F$ và $\lVert E \rVert_2$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\lVert E \rVert_F^2 \approx 160\,000 \cdot 4$, nên $\lVert E \rVert_F \approx 800$. $\lVert E \rVert_2 \approx 2(\sqrt{400} + \sqrt{400}) = 80$. Năng lượng nhiễu trải trên $400$ hướng, mỗi hướng chỉ khoảng $\sigma_i \le 80$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (lập trình).&lt;/strong&gt; Lấy một ảnh xám bất kỳ (hoặc dựng ảnh tổng hợp gồm vài hình chữ nhật và một gradient), cộng nhiễu Gauss, rồi so sánh sai số $\lVert \tilde A_k - A \rVert_F$ theo $k$. Giá trị $k$ tốt nhất có gần số giá trị kỳ dị của $\tilde A$ vượt ngưỡng $s(\sqrt m + \sqrt n)$ không?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Dùng `U, s_, Vt = np.linalg.svd(At, full_matrices=False)` và `Ak = (U[:, :k] * s_[:k]) @ Vt[:k]`. Sai số giảm khi $k$ tăng tới khoảng số giá trị kỳ dị vượt ngưỡng, rồi tăng trở lại vì bắt đầu đưa nhiễu vào. Với ảnh tổng hợp hạng thấp, $k$ tốt nhất thường trùng hoặc rất gần số giá trị vượt ngưỡng.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Nén: lưu $A_k$ cần $k(m + n + 1)$ số; sai số tương đối $\sqrt{\sum_{i &amp;gt; k}\sigma_i^2/\sum\sigma_i^2}$.&lt;/li&gt;
    &lt;li&gt;Ảnh tự nhiên có phổ giá trị kỳ dị giảm nhanh, nên $k$ nhỏ đã đủ.&lt;/li&gt;
    &lt;li&gt;Nhiễu trải đều trên mọi hướng, giá trị kỳ dị lớn nhất cỡ $s(\sqrt m + \sqrt n)$; tín hiệu tập trung ở vài hướng.&lt;/li&gt;
    &lt;li&gt;Khử nhiễu: giữ các giá trị kỳ dị vượt ngưỡng nhiễu, bỏ phần còn lại.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Phân tích thành phần chính (PCA)</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter11/11_05_Phan_Tich_Thanh_Phan_Chinh_PCA/"/>
   <updated>2026-01-11T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter11/11_05_Phan_Tich_Thanh_Phan_Chinh_PCA</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;thực hiện PCA: trừ trung bình, tính SVD (hoặc chéo hoá hiệp phương sai), chiếu dữ liệu lên $k$ thành phần chính;&lt;/li&gt;
    &lt;li&gt;giải thích thành phần chính là hướng có phương sai lớn nhất và tính tỷ lệ phương sai giải thích;&lt;/li&gt;
    &lt;li&gt;nhận biết khi nào cần chuẩn hoá các đặc trưng trước khi làm PCA.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Bốn điểm dữ liệu trong mặt phẳng: $(3, 2)$, $(2, 3)$, $(0, -1)$, $(-1, 0)$. Chúng nằm gần đường thẳng hướng $(1, 1)$ qua tâm $(1, 1)$. Nếu chỉ được giữ &lt;strong&gt;một&lt;/strong&gt; số cho mỗi điểm, nên giữ toạ độ theo hướng nào để mất ít thông tin nhất? Bài 10-06 đã trả lời: hướng có phương sai lớn nhất, là vectơ riêng lớn nhất của ma trận hiệp phương sai. PCA là quy trình đầy đủ dựa trên ý đó, và SVD là cách tính nó.&lt;/p&gt;

&lt;h2 id=&quot;quy-trình-pca&quot;&gt;Quy trình PCA&lt;/h2&gt;

&lt;p&gt;Cho $n$ điểm dữ liệu $x_1, \dots, x_n \in \mathbb{R}^d$.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Trừ trung bình&lt;/strong&gt;: $\mu = \tfrac1n\sum x_j$; lập ma trận $X$ cỡ $n \times d$ có hàng thứ $j$ là $(x_j - \mu)^T$.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hiệp phương sai&lt;/strong&gt;: $C = \dfrac{1}{n - 1}X^TX$ (đối xứng, nửa xác định dương).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SVD&lt;/strong&gt;: $X = U\Sigma V^T$. Khi đó $C = V\dfrac{\Sigma^T\Sigma}{n - 1}V^T$: các cột $v_1, \dots, v_d$ của $V$ là &lt;strong&gt;thành phần chính&lt;/strong&gt;, và phương sai dọc $v_i$ là $\lambda_i = \dfrac{\sigma_i^2}{n - 1}$.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chiếu&lt;/strong&gt;: toạ độ mới (điểm số) là $Z_k = XV_k = U_k\Sigma_k$, cỡ $n \times k$.&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Hướng đơn vị $u$ làm cực đại phương sai của các hình chiếu $\tfrac{1}{n-1}\sum_j((x_j - \mu)^Tu)^2 = u^TCu$ là $v_1$; trong các hướng vuông góc với $v_1, \dots, v_{k-1}$, hướng làm cực đại là $v_k$. Không gian $k$ chiều $\operatorname{span}(v_1, \dots, v_k)$ làm cực tiểu tổng bình phương khoảng cách từ các điểm (đã trừ trung bình) tới nó.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Phần đầu là Định lý 1 và 2 của Bài 10-06 áp dụng cho $C$. Phần sau: tổng bình phương khoảng cách tới không gian con $S$ là $\lVert X - XP_S \rVert_F^2$, với $XP_S$ có hạng $\le k$. Theo Eckart–Young (Bài 11-03), giá trị nhỏ nhất đạt khi $XP_S = X_k = XV_kV_k^T$, tức $S = \operatorname{span}(v_1, \dots, v_k)$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Vì vậy PCA vừa là “hướng phương sai lớn nhất” vừa là “mặt phẳng khớp tốt nhất theo khoảng cách vuông góc”, khác với hồi quy (Chương 08) chỉ đo khoảng cách theo phương thẳng đứng.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (ví dụ mở đầu).&lt;/strong&gt; $\mu = (1, 1)$, và&lt;/p&gt;

\[X = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \\ -1 &amp;amp; -2 \\ -2 &amp;amp; -1 \end{bmatrix}, \qquad X^TX = \begin{bmatrix} 10 &amp;amp; 8 \\ 8 &amp;amp; 10 \end{bmatrix}, \qquad C = \frac13\begin{bmatrix} 10 &amp;amp; 8 \\ 8 &amp;amp; 10 \end{bmatrix}.\]

  &lt;p&gt;$X^TX$ có trị riêng $18$ (hướng $(1, 1)$) và $2$ (hướng $(1, -1)$), nên $\sigma_1 = 3\sqrt2$, $\sigma_2 = \sqrt2$, phương sai $\lambda_1 = 6$, $\lambda_2 = \tfrac23$. Thành phần chính thứ nhất $v_1 = \tfrac{1}{\sqrt2}(1, 1)$ giải thích $18/20 = 90\%$ phương sai. Điểm số theo $v_1$: $Xv_1 = \tfrac{1}{\sqrt2}(3, 3, -3, -3)$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;tỷ-lệ-phương-sai-giải-thích-và-chọn-k&quot;&gt;Tỷ lệ phương sai giải thích và chọn $k$&lt;/h2&gt;

&lt;p&gt;Tỷ lệ phương sai giải thích bởi $k$ thành phần đầu là $\dfrac{\sigma_1^2 + \dots + \sigma_k^2}{\sigma_1^2 + \dots + \sigma_d^2}$, đúng bằng tỷ lệ “năng lượng” của Bài 11-03. Chọn $k$ nhỏ nhất đạt ngưỡng (chẳng hạn $90\%$ hoặc $95\%$), hoặc theo khuỷu của đồ thị (scree plot).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chuẩn hoá.&lt;/strong&gt; PCA nhạy với đơn vị đo: một đặc trưng đo bằng mét và một đặc trưng đo bằng milimét sẽ cho kết quả rất khác. Khi các đặc trưng có đơn vị khác nhau, chia mỗi cột của $X$ cho độ lệch chuẩn của nó trước khi làm PCA (tương đương làm PCA trên ma trận tương quan).&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-giảm-chiều-và-trực-quan-hoá&quot;&gt;Ứng dụng: giảm chiều và trực quan hoá&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Trực quan hoá.&lt;/strong&gt; Chiếu dữ liệu nhiều chiều (ảnh, biểu hiện gen, embedding) lên hai thành phần chính đầu để vẽ trên mặt phẳng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khuôn mặt riêng (eigenfaces).&lt;/strong&gt; Mỗi ảnh khuôn mặt $64 \times 64$ là một vectơ trong $\mathbb{R}^{4096}$; vài chục thành phần chính đã đủ để nhận dạng và tái tạo khá tốt.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Liên hệ học sâu.&lt;/strong&gt; PCA là một &lt;em&gt;autoencoder tuyến tính&lt;/em&gt;: mã hoá $z = V_k^T(x - \mu)$, giải mã $\hat x = \mu + V_kz$, và Định lý 1 nói đây là cặp mã hoá–giải mã tuyến tính có sai số tái tạo nhỏ nhất (khoá Học sâu, Chương 12).&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;3.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;2.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;2.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;3.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;Xc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;mean&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;axis&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;U&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vt&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;svd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Xc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;full_matrices&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Vt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;      &lt;span class=&quot;c1&quot;&gt;# ±[0.707, 0.707], [0.9, 0.1]
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: PCA với đám mây điểm&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo các điểm, xem trục chính PC1, PC2 và phần trăm phương sai giữ lại.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter11/pca.html&quot; title=&quot;Minh hoạ: PCA với đám mây điểm&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter11/pca.html&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-pca-hướng-có-phương-sai-lớn-nhất&quot;&gt;Video ngắn: PCA: hướng có phương sai lớn nhất&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/pca-rotating-axis.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Bốn điểm (3; 2), (2; 3), (0; −1), (−1; 0), tâm μ = (1; 1). Quay một trục thử và đo phương sai của hình chiếu: lớn nhất bằng 6 ở 45°, theo v₁ = (1; 1)/√2; nhỏ nhất 2/3 ở 135°. v₁ giải thích 90% phương sai. Điểm số theo v₁: (3; 3; −3; −3)/√2. Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Làm PCA cho ba điểm $(1, 0)$, $(0, 1)$, $(2, 2)$: tìm trung bình, thành phần chính thứ nhất và tỷ lệ phương sai giải thích.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\mu = (1, 1)$, $X = \begin{bmatrix} 0 &amp;amp; -1 \\ -1 &amp;amp; 0 \\ 1 &amp;amp; 1 \end{bmatrix}$, $X^TX = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$ với trị riêng $3$ (hướng $(1, 1)$) và $1$ (hướng $(1, -1)$). $v_1 = \tfrac{1}{\sqrt2}(1, 1)$, giải thích $3/4 = 75\%$ phương sai.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Chứng minh tổng phương sai $\operatorname{tr} C = \sum_i\lambda_i$ không đổi khi xoay hệ trục, và bằng tổng phương sai của từng đặc trưng gốc.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\operatorname{tr} C = \sum_i C_{ii}$ là tổng phương sai của từng đặc trưng. Vết bằng tổng trị riêng, và $\operatorname{tr}(Q^TCQ) = \operatorname{tr}(C)$ với mọi $Q$ trực giao.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Hai đặc trưng: chiều cao (m, phương sai $0{,}01$) và cân nặng (kg, phương sai $100$), tương quan $0{,}7$. PCA không chuẩn hoá cho thành phần chính thứ nhất gần như trùng hướng nào? Vì sao nên chuẩn hoá?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Gần như trùng trục cân nặng, vì phương sai cân nặng lớn hơn $10^4$ lần: kết quả phản ánh đơn vị đo chứ không phản ánh cấu trúc. Sau chuẩn hoá, ma trận tương quan $\begin{bmatrix} 1 &amp;amp; 0{,}7 \\ 0{,}7 &amp;amp; 1 \end{bmatrix}$ cho $v_1 = \tfrac{1}{\sqrt2}(1, 1)$ với tỷ lệ $85\%$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (lập trình).&lt;/strong&gt; Làm PCA trên bộ dữ liệu Iris ($150$ điểm, $4$ đặc trưng, đơn vị cm), vẽ tỷ lệ phương sai giải thích và hình chiếu lên hai thành phần đầu, tô màu theo loài.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Không chuẩn hoá, tỷ lệ phương sai giải thích xấp xỉ $92\%, 5\%, 2\%, 0{,}5\%$: hai thành phần đầu giữ khoảng $98\%$. Trên hình chiếu, loài *setosa* tách hẳn, hai loài còn lại chồng lên nhau một phần.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;PCA: trừ trung bình, $X = U\Sigma V^T$; thành phần chính là các cột của $V$, phương sai là $\sigma_i^2/(n - 1)$.&lt;/li&gt;
    &lt;li&gt;$v_1$ là hướng phương sai lớn nhất; $\operatorname{span}(v_1, \dots, v_k)$ là không gian $k$ chiều khớp tốt nhất theo khoảng cách vuông góc.&lt;/li&gt;
    &lt;li&gt;Tỷ lệ phương sai giải thích $\sum_{i \le k}\sigma_i^2/\sum\sigma_i^2$; chuẩn hoá khi các đặc trưng có đơn vị khác nhau.&lt;/li&gt;
    &lt;li&gt;PCA là autoencoder tuyến tính tối ưu.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Giả nghịch đảo</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter11/11_04_Gia_Nghich_Dao/"/>
   <updated>2026-01-11T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter11/11_04_Gia_Nghich_Dao</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;định nghĩa và tính giả nghịch đảo $A^+ = V\Sigma^+U^T$ qua SVD;&lt;/li&gt;
    &lt;li&gt;chứng minh $x^+ = A^+b$ là nghiệm bình phương tối thiểu có chuẩn nhỏ nhất;&lt;/li&gt;
    &lt;li&gt;nhận ra $A^+ = (A^TA)^{-1}A^T$ khi các cột độc lập và liên hệ $AA^+$, $A^+A$ với các phép chiếu.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Hệ $x_1 + x_2 = 2$, $x_1 + x_2 = 0$ vô nghiệm; hơn nữa ma trận $A = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$ có các cột phụ thuộc, nên phương trình chuẩn $A^TA\hat x = A^Tb$ (Bài 08-02) có &lt;strong&gt;vô số&lt;/strong&gt; nghiệm: mọi $\hat x$ với $\hat x_1 + \hat x_2 = 1$. Chọn nghiệm nào? Một lựa chọn tự nhiên là nghiệm &lt;strong&gt;ngắn nhất&lt;/strong&gt;, ở đây $\hat x = (\tfrac12, \tfrac12)$. Giả nghịch đảo cho đúng nghiệm này, bằng một công thức.&lt;/p&gt;

&lt;h2 id=&quot;định-nghĩa-qua-svd&quot;&gt;Định nghĩa qua SVD&lt;/h2&gt;

&lt;p&gt;Với $A = U\Sigma V^T$ cỡ $m \times n$ hạng $r$, gọi $\Sigma^+$ là ma trận $n \times m$ có $1/\sigma_1, \dots, 1/\sigma_r$ ở vị trí $(i, i)$, còn lại bằng $0$.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa.&lt;/strong&gt; &lt;strong&gt;Giả nghịch đảo&lt;/strong&gt; (Moore–Penrose) của $A$ là&lt;/p&gt;

  &lt;p&gt;\(A^+ = V\Sigma^+U^T = \sum_{i \le r}\frac{1}{\sigma_i}v_iu_i^T.\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Ý nghĩa: $A$ đưa $v_i$ tới $\sigma_iu_i$; $A^+$ đưa $u_i$ ngược về $v_i/\sigma_i$, và đưa $u_{r+1}, \dots, u_m$ (cơ sở của $\operatorname{Null}(A^T)$) về $0$. Nếu $A$ vuông khả nghịch thì $A^+ = A^{-1}$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; $AA^+ = \sum_{i \le r}u_iu_i^T$ là phép chiếu vuông góc lên $\operatorname{Col}(A)$, và $A^+A = \sum_{i \le r}v_iv_i^T$ là phép chiếu vuông góc lên $\operatorname{Row}(A)$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; $AA^+ = U\Sigma V^TV\Sigma^+U^T = U(\Sigma\Sigma^+)U^T$, với $\Sigma\Sigma^+ = \operatorname{diag}(1, \dots, 1, 0, \dots, 0)$ ($r$ số $1$). Vậy $AA^+ = \sum_{i \le r}u_iu_i^T$, là phép chiếu lên $\operatorname{span}(u_1, \dots, u_r) = \operatorname{Col}(A)$. Tương tự cho $A^+A$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;nghiệm-bình-phương-tối-thiểu-có-chuẩn-nhỏ-nhất&quot;&gt;Nghiệm bình phương tối thiểu có chuẩn nhỏ nhất&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2.&lt;/strong&gt; Với mọi $b$, $x^+ = A^+b$ là nghiệm bình phương tối thiểu của $Ax = b$ (tức cực tiểu hoá $\lVert Ax - b \rVert$), và trong mọi nghiệm bình phương tối thiểu, $x^+$ có chuẩn nhỏ nhất.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Theo Định lý 1, $Ax^+ = AA^+b$ là hình chiếu của $b$ lên $\operatorname{Col}(A)$, nên $x^+$ là nghiệm bình phương tối thiểu (Bài 08-01). Mọi nghiệm bình phương tối thiểu khác có dạng $x^+ + z$ với $z \in \operatorname{Null}(A)$. Vì $x^+ = \sum_{i \le r}\tfrac{u_i^Tb}{\sigma_i}v_i \in \operatorname{Row}(A) \perp \operatorname{Null}(A)$, định lý Pythagore cho $\lVert x^+ + z \rVert^2 = \lVert x^+ \rVert^2 + \lVert z \rVert^2 \ge \lVert x^+ \rVert^2$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (ví dụ mở đầu).&lt;/strong&gt; $A = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix} = 2\,uv^T$ với $u = v = \tfrac{1}{\sqrt2}(1, 1)$. Vậy $A^+ = \tfrac12 vu^T = \tfrac14\begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$, và với $b = (2, 0)$: $x^+ = A^+b = (\tfrac12, \tfrac12)$, đúng nghiệm ngắn nhất trên đường $x_1 + x_2 = 1$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Trường hợp cột độc lập.&lt;/strong&gt; Nếu $A$ có hạng $n$ (cột độc lập), $A^TA$ khả nghịch và $A^+ = (A^TA)^{-1}A^T$: nghiệm bình phương tối thiểu là duy nhất, trùng với Bài 08-02. Nếu $A$ có hạng $m$ (hàng độc lập), $A^+ = A^T(AA^T)^{-1}$: hệ có vô số nghiệm và $A^+b$ là nghiệm ngắn nhất.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; $A = \begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix}$ có cột độc lập, $A^TA = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$, nên&lt;/p&gt;

\[A^+ = \frac13\begin{bmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{bmatrix}\begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 0 \end{bmatrix} = \frac13\begin{bmatrix} 1 &amp;amp; -1 &amp;amp; 2 \\ 1 &amp;amp; 2 &amp;amp; -1 \end{bmatrix}.\]

  &lt;p&gt;Kiểm tra: $A^+A = I_2$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-hồi-quy-khi-có-đặc-trưng-trùng-lặp&quot;&gt;Ứng dụng: hồi quy khi có đặc trưng trùng lặp&lt;/h2&gt;

&lt;p&gt;Trong hồi quy tuyến tính, nếu hai cột đặc trưng gần như trùng nhau (ví dụ chiều cao tính bằng cm và bằng inch), $A^TA$ suy biến hoặc gần suy biến, và $(A^TA)^{-1}$ không dùng được. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.lstsq&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.pinv&lt;/code&gt; dùng SVD: bỏ các giá trị kỳ dị nhỏ hơn một ngưỡng (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rcond&lt;/code&gt;) rồi trả về nghiệm chuẩn nhỏ nhất. Đây là phiên bản “cắt cụt” của hồi quy ridge (Bài 08-05): ridge làm mềm $1/\sigma_i$ thành $\sigma_i/(\sigma_i^2 + \lambda)$, còn giả nghịch đảo cắt cụt đặt $1/\sigma_i = 0$ khi $\sigma_i$ quá nhỏ. Một sự thật đáng chú ý: với hồi quy tuyến tính thừa tham số (nhiều ẩn hơn phương trình), gradient descent khởi tạo từ $0$ hội tụ đúng về $A^+b$, vì mọi bước cập nhật $A^T(\cdot)$ đều nằm trong $\operatorname{Row}(A)$.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: giả nghịch đảo A⁺&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo b, xem x⁺ = A⁺b và hình chiếu Ax⁺ lên không gian cột.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter11/svd.html?mode=pinv&amp;amp;preset=rank1&quot; title=&quot;Minh hoạ: giả nghịch đảo A⁺&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter11/svd.html?mode=pinv&amp;amp;preset=rank1&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Tính $A^+$ với $A = \begin{bmatrix} 1 &amp;amp; 0 \\ 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \end{bmatrix}$ (ma trận chữ nhật $3 \times 2$).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A^TA = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$, $A^+ = (A^TA)^{-1}A^T = \tfrac13\begin{bmatrix} 2 &amp;amp; 1 &amp;amp; -1 \\ -1 &amp;amp; 1 &amp;amp; 2 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Tính $A^+$ với vectơ cột $a = (1, 2, 2)$ và với vectơ hàng $a^T$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$a^+ = a^T/(a^Ta) = \tfrac19(1, 2, 2)$ (một vectơ hàng). $(a^T)^+ = a/(a^Ta) = \tfrac19(1, 2, 2)^T$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Tìm nghiệm chuẩn nhỏ nhất của hệ $x_1 + 2x_2 + 2x_3 = 9$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$x^+ = (a^T)^+\cdot 9 = \tfrac{9}{9}(1, 2, 2) = (1, 2, 2)$. Đây là chân đường vuông góc hạ từ gốc xuống mặt phẳng.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Kiểm tra bốn điều kiện Penrose cho $A^+$ của Ví dụ 1: $AA^+A = A$, $A^+AA^+ = A^+$, $AA^+$ và $A^+A$ đối xứng.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$AA^+ = A^+A = \tfrac12\begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$ (đối xứng, là phép chiếu lên $(1, 1)$). $AA^+A = \tfrac12\begin{bmatrix} 2 &amp;amp; 2 \\ 2 &amp;amp; 2 \end{bmatrix} = A$ và $A^+AA^+ = \tfrac12\cdot\tfrac14\begin{bmatrix} 2 &amp;amp; 2 \\ 2 &amp;amp; 2 \end{bmatrix} = A^+$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$A^+ = V\Sigma^+U^T = \sum_{i \le r}\sigma_i^{-1}v_iu_i^T$; $A^+ = A^{-1}$ khi $A$ khả nghịch.&lt;/li&gt;
    &lt;li&gt;$AA^+$ chiếu lên $\operatorname{Col}(A)$, $A^+A$ chiếu lên $\operatorname{Row}(A)$.&lt;/li&gt;
    &lt;li&gt;$A^+b$ là nghiệm bình phương tối thiểu có chuẩn nhỏ nhất.&lt;/li&gt;
    &lt;li&gt;Cột độc lập: $A^+ = (A^TA)^{-1}A^T$; hàng độc lập: $A^+ = A^T(AA^T)^{-1}$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Xấp xỉ hạng thấp và định lý Eckart–Young</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter11/11_03_Xap_Xi_Hang_Thap_Va_Dinh_Ly_Eckart_Young/"/>
   <updated>2026-01-11T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter11/11_03_Xap_Xi_Hang_Thap_Va_Dinh_Ly_Eckart_Young</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;lập xấp xỉ hạng $k$: $A_k = \sum_{i \le k}\sigma_iu_iv_i^T$;&lt;/li&gt;
    &lt;li&gt;phát biểu định lý Eckart–Young và tính sai số $\lVert A - A_k \rVert$ theo chuẩn phổ và chuẩn Frobenius;&lt;/li&gt;
    &lt;li&gt;chọn $k$ dựa trên tỷ lệ “năng lượng” $\sum_{i \le k}\sigma_i^2 / \sum\sigma_i^2$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Một bảng điểm $1000$ người dùng $\times$ $500$ bộ phim có $500\,000$ số. Nếu sở thích của người dùng chỉ phụ thuộc vào khoảng $20$ “yếu tố” (hành động, lãng mạn, hài…), bảng gần như là một ma trận hạng $20$, và chỉ cần $20 \cdot (1000 + 500) = 30\,000$ số để lưu. Câu hỏi: trong mọi ma trận hạng $k$, ma trận nào &lt;strong&gt;gần&lt;/strong&gt; $A$ nhất? SVD trả lời trọn vẹn câu hỏi này.&lt;/p&gt;

&lt;h2 id=&quot;xấp-xỉ-hạng-k&quot;&gt;Xấp xỉ hạng $k$&lt;/h2&gt;

&lt;p&gt;SVD viết $A$ thành tổng các lớp hạng 1 xếp theo độ quan trọng giảm dần:&lt;/p&gt;

\[A = \sigma_1u_1v_1^T + \sigma_2u_2v_2^T + \dots + \sigma_ru_rv_r^T.\]

&lt;p&gt;Giữ $k$ lớp đầu:&lt;/p&gt;

\[A_k = \sigma_1u_1v_1^T + \dots + \sigma_ku_kv_k^T = U_k\Sigma_kV_k^T,\]

&lt;p&gt;với $U_k$, $V_k$ là $k$ cột đầu của $U$, $V$ và $\Sigma_k = \operatorname{diag}(\sigma_1, \dots, \sigma_k)$. Ma trận $A_k$ có hạng $k$, và lưu nó cần $k(m + n + 1)$ số thay vì $mn$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Eckart–Young–Mirsky).&lt;/strong&gt; Với mọi ma trận $B$ có hạng không quá $k$:&lt;/p&gt;

\[\lVert A - B \rVert_2 \ge \lVert A - A_k \rVert_2 = \sigma_{k+1}, \qquad \lVert A - B \rVert_F \ge \lVert A - A_k \rVert_F = \sqrt{\sigma_{k+1}^2 + \dots + \sigma_r^2}.\]

  &lt;p&gt;Ở đây $\lVert M \rVert_2 = \max_{\lVert x \rVert = 1}\lVert Mx \rVert$ là chuẩn phổ.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh (chuẩn phổ).&lt;/strong&gt; $A - A_k = \sum_{i &amp;gt; k}\sigma_iu_iv_i^T$ có giá trị kỳ dị lớn nhất $\sigma_{k+1}$, nên $\lVert A - A_k \rVert_2 = \sigma_{k+1}$. Cho $B$ hạng $\le k$; $\operatorname{Null}(B)$ có số chiều $\ge n - k$, còn $W = \operatorname{span}(v_1, \dots, v_{k+1})$ có số chiều $k + 1$. Tổng số chiều vượt $n$, nên có vectơ đơn vị $x \in \operatorname{Null}(B) \cap W$. Viết $x = \sum_{i \le k+1}c_iv_i$ với $\sum c_i^2 = 1$:&lt;/p&gt;

\[\lVert (A - B)x \rVert^2 = \lVert Ax \rVert^2 = \sum_{i \le k+1}\sigma_i^2c_i^2 \ge \sigma_{k+1}^2.\]

  &lt;p&gt;Vậy $\lVert A - B \rVert_2 \ge \sigma_{k+1}$. Chứng minh cho chuẩn Frobenius dùng ý tương tự cho từng giá trị kỳ dị; ta không trình bày ở đây.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Với $A = \begin{bmatrix} 3 &amp;amp; 0 \\ 4 &amp;amp; 5 \end{bmatrix}$ (Bài 11-01), $\sigma_1 = 3\sqrt5$, $u_1 = \tfrac{1}{\sqrt{10}}(1, 3)$, $v_1 = \tfrac{1}{\sqrt2}(1, 1)$:&lt;/p&gt;

\[A_1 = 3\sqrt5\cdot\frac{1}{\sqrt{20}}\begin{bmatrix} 1 &amp;amp; 1 \\ 3 &amp;amp; 3 \end{bmatrix} = \frac32\begin{bmatrix} 1 &amp;amp; 1 \\ 3 &amp;amp; 3 \end{bmatrix}, \qquad A - A_1 = \frac12\begin{bmatrix} 3 &amp;amp; -3 \\ -1 &amp;amp; 1 \end{bmatrix}.\]

  &lt;p&gt;Sai số $\lVert A - A_1 \rVert_F = \tfrac12\sqrt{9 + 9 + 1 + 1} = \sqrt5 = \sigma_2$. Phần “năng lượng” giữ lại: $\sigma_1^2/(\sigma_1^2 + \sigma_2^2) = 45/50 = 90\%$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;chọn-k&quot;&gt;Chọn $k$&lt;/h2&gt;

&lt;p&gt;Theo Định lý 1, sai số tương đối theo chuẩn Frobenius là&lt;/p&gt;

\[\frac{\lVert A - A_k \rVert_F}{\lVert A \rVert_F} = \sqrt{\frac{\sigma_{k+1}^2 + \dots + \sigma_r^2}{\sigma_1^2 + \dots + \sigma_r^2}}.\]

&lt;p&gt;Trong thực hành, vẽ các $\sigma_i$ (thường theo thang log) và chọn $k$ ở “khuỷu”, nơi đồ thị chuyển từ giảm nhanh sang phẳng; hoặc chọn $k$ nhỏ nhất giữ được, chẳng hạn, $95\%$ năng lượng. Dữ liệu thực thường có giá trị kỳ dị giảm nhanh, nên $k$ nhỏ đã đủ.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-hệ-gợi-ý-và-lora&quot;&gt;Ứng dụng: hệ gợi ý và LoRA&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hệ gợi ý.&lt;/strong&gt; Bảng điểm người dùng $\times$ sản phẩm được xấp xỉ bằng ma trận hạng thấp $A_k = (U_k\Sigma_k^{1/2})(\Sigma_k^{1/2}V_k^T)$: mỗi người dùng và mỗi sản phẩm được gán một vectơ $k$ chiều, và điểm dự đoán là tích vô hướng của chúng. Cuộc thi Netflix Prize (2006–2009) phổ biến cách tiếp cận này (Chương 14).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tinh chỉnh mô hình ngôn ngữ lớn (LoRA).&lt;/strong&gt; Thay vì cập nhật toàn bộ ma trận trọng số $W$ cỡ $d \times d$, ta chỉ học một cập nhật hạng thấp $\Delta W = BA$ với $B$ cỡ $d \times k$, $A$ cỡ $k \times d$, $k \ll d$. Ý tưởng dựa trên quan sát rằng các cập nhật hữu ích có giá trị kỳ dị giảm nhanh.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: xấp xỉ hạng 1&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Giữ σ₁u₁v₁ᵀ: elip dẹt thành đoạn thẳng, sai số bằng σ₂.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter11/svd.html?mode=low&quot; title=&quot;Minh hoạ: xấp xỉ hạng 1&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter11/svd.html?mode=low&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Tìm xấp xỉ hạng 1 tốt nhất của $A = \begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix}$ (Ví dụ 1, Bài 11-02) và sai số Frobenius.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A_1 = \sqrt3\,u_1v_1^T = \sqrt3\cdot\tfrac{1}{\sqrt{12}}\begin{bmatrix} 2 &amp;amp; 2 \\ 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix} = \tfrac12\begin{bmatrix} 2 &amp;amp; 2 \\ 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$. Sai số $\lVert A - A_1 \rVert_F = \sigma_2 = 1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Một ảnh xám $1000 \times 800$ được xấp xỉ bằng $A_{50}$. Tỷ lệ số lượng số cần lưu so với ảnh gốc là bao nhiêu?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$50(1000 + 800 + 1) = 90\,050$ so với $800\,000$, khoảng $11{,}3\%$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Các giá trị kỳ dị của $A$ là $10, 5, 2, 1, 0{,}5$. Tìm $k$ nhỏ nhất để $A_k$ giữ ít nhất $95\%$ năng lượng, và sai số tương đối Frobenius khi đó.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\sum\sigma_i^2 = 100 + 25 + 4 + 1 + 0{,}25 = 130{,}25$. $k = 1$: $76{,}8\%$; $k = 2$: $125/130{,}25 \approx 96{,}0\%$. Vậy $k = 2$, sai số tương đối $\sqrt{5{,}25/130{,}25} \approx 0{,}20$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Chứng minh: nếu $A$ vuông khả nghịch thì khoảng cách (chuẩn phổ) từ $A$ đến tập ma trận suy biến là $\sigma_n$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Ma trận suy biến có hạng $\le n - 1$. Theo Định lý 1 với $k = n - 1$, khoảng cách nhỏ nhất là $\sigma_n$, đạt tại $A_{n-1}$. Hệ quả: $1/\kappa(A) = \sigma_n/\sigma_1$ là khoảng cách tương đối tới suy biến.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$A_k = \sum_{i \le k}\sigma_iu_iv_i^T$ là xấp xỉ hạng $k$; lưu cần $k(m + n + 1)$ số.&lt;/li&gt;
    &lt;li&gt;Eckart–Young: $A_k$ tốt nhất trong mọi ma trận hạng $\le k$; $\lVert A - A_k \rVert_2 = \sigma_{k+1}$, $\lVert A - A_k \rVert_F = \sqrt{\sum_{i &amp;gt; k}\sigma_i^2}$.&lt;/li&gt;
    &lt;li&gt;Chọn $k$ theo khuỷu của đồ thị $\sigma_i$ hoặc theo tỷ lệ năng lượng.&lt;/li&gt;
    &lt;li&gt;Ứng dụng: hệ gợi ý, nén, LoRA.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Tính SVD</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter11/11_02_Tinh_SVD/"/>
   <updated>2026-01-11T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter11/11_02_Tinh_SVD</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;tính SVD của ma trận nhỏ qua trị riêng và vectơ riêng của $A^TA$ (hoặc $AA^T$);&lt;/li&gt;
    &lt;li&gt;giải thích vì sao phải tính $u_i = Av_i/\sigma_i$ thay vì tính $U$ và $V$ độc lập;&lt;/li&gt;
    &lt;li&gt;chứng minh sự tồn tại của SVD và đẳng thức $\lVert A \rVert_F^2 = \sum\sigma_i^2$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Nếu $A = U\Sigma V^T$ thì&lt;/p&gt;

\[A^TA = V\Sigma^TU^TU\Sigma V^T = V(\Sigma^T\Sigma)V^T, \qquad AA^T = U(\Sigma\Sigma^T)U^T.\]

&lt;p&gt;Đây là các chéo hoá trực giao (Bài 10-02) của hai ma trận đối xứng nửa xác định dương $A^TA$ và $AA^T$. Vậy: &lt;strong&gt;$v_i$ là vectơ riêng của $A^TA$, $u_i$ là vectơ riêng của $AA^T$, và $\sigma_i^2$ là các trị riêng chung&lt;/strong&gt;. Điều này cho ngay một thuật toán tính tay.&lt;/p&gt;

&lt;h2 id=&quot;thuật-toán&quot;&gt;Thuật toán&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Tính $A^TA$ ($n \times n$, đối xứng), tìm trị riêng $\lambda_1 \ge \dots \ge \lambda_n \ge 0$ và cơ sở trực chuẩn vectơ riêng $v_1, \dots, v_n$.&lt;/li&gt;
  &lt;li&gt;Đặt $\sigma_i = \sqrt{\lambda_i}$; $r$ là số $\sigma_i &amp;gt; 0$.&lt;/li&gt;
  &lt;li&gt;Với $i \le r$, đặt $u_i = \dfrac{Av_i}{\sigma_i}$.&lt;/li&gt;
  &lt;li&gt;Nếu $r &amp;lt; m$, bổ sung $u_{r+1}, \dots, u_m$ thành cơ sở trực chuẩn của $\mathbb{R}^m$ (chúng là cơ sở trực chuẩn của $\operatorname{Null}(A^T)$).&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Sự tồn tại của SVD).&lt;/strong&gt; Các vectơ $u_1, \dots, u_r$ ở bước 3 trực chuẩn, và $A = U\Sigma V^T$ với $U, \Sigma, V$ dựng như trên.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Với $i, j \le r$: $u_i^Tu_j = \dfrac{v_i^TA^TAv_j}{\sigma_i\sigma_j} = \dfrac{\lambda_jv_i^Tv_j}{\sigma_i\sigma_j}$, bằng $1$ nếu $i = j$ và $0$ nếu $i \neq j$. Với $i &amp;gt; r$: $\lVert Av_i \rVert^2 = v_i^TA^TAv_i = \lambda_i = 0$, nên $Av_i = 0$. Vậy $Av_i = \sigma_iu_i$ với mọi $i$ (với quy ước $\sigma_i = 0$ khi $i &amp;gt; r$), tức $AV = U\Sigma$, và nhân phải với $V^T$ được $A = U\Sigma V^T$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Cảnh báo.&lt;/strong&gt; Đừng tính $U$ từ $AA^T$ và $V$ từ $A^TA$ một cách độc lập: mỗi vectơ riêng chỉ xác định sai khác dấu (hoặc sai khác một phép quay trong không gian riêng bội), nên $U\Sigma V^T$ có thể không bằng $A$. Hãy tính một bên, rồi suy ra bên kia bằng $u_i = Av_i/\sigma_i$. Nếu $m &amp;lt; n$, tính từ $AA^T$ (nhỏ hơn) rồi dùng $v_i = A^Tu_i/\sigma_i$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; $A = \begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix}$ ($3 \times 2$).&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$A^TA = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$, trị riêng $3, 1$, vectơ riêng $v_1 = \tfrac{1}{\sqrt2}(1, 1)$, $v_2 = \tfrac{1}{\sqrt2}(1, -1)$.&lt;/li&gt;
    &lt;li&gt;$\sigma_1 = \sqrt3$, $\sigma_2 = 1$.&lt;/li&gt;
    &lt;li&gt;$u_1 = \dfrac{Av_1}{\sqrt3} = \dfrac{1}{\sqrt3}\cdot\dfrac{1}{\sqrt2}(2, 1, 1) = \tfrac{1}{\sqrt6}(2, 1, 1)$, $u_2 = Av_2 = \tfrac{1}{\sqrt2}(0, -1, 1)$.&lt;/li&gt;
    &lt;li&gt;Bổ sung $u_3 \perp u_1, u_2$: $u_3 = \tfrac{1}{\sqrt3}(1, -1, -1)$.&lt;/li&gt;
  &lt;/ul&gt;

\[A = \begin{bmatrix} 2/\sqrt6 &amp;amp; 0 &amp;amp; 1/\sqrt3 \\ 1/\sqrt6 &amp;amp; -1/\sqrt2 &amp;amp; -1/\sqrt3 \\ 1/\sqrt6 &amp;amp; 1/\sqrt2 &amp;amp; -1/\sqrt3 \end{bmatrix}\begin{bmatrix} \sqrt3 &amp;amp; 0 \\ 0 &amp;amp; 1 \\ 0 &amp;amp; 0 \end{bmatrix}\frac{1}{\sqrt2}\begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix}.\]

  &lt;p&gt;Dạng rút gọn (chỉ giữ $r$ cột): $A = \sqrt3\,u_1v_1^T + u_2v_2^T$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;chuẩn-frobenius&quot;&gt;Chuẩn Frobenius&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2.&lt;/strong&gt; $\lVert A \rVert_F^2 = \sum_{i,j}a_{ij}^2 = \sigma_1^2 + \dots + \sigma_r^2$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; $\lVert A \rVert_F^2 = \operatorname{tr}(A^TA)$, bằng tổng các trị riêng của $A^TA$, tức $\sum\sigma_i^2$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Kiểm tra trên Ví dụ 1: tổng bình phương phần tử là $4$, và $\sigma_1^2 + \sigma_2^2 = 3 + 1 = 4$.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-svd-trên-máy-tính&quot;&gt;Ứng dụng: SVD trên máy tính&lt;/h2&gt;

&lt;p&gt;Trong thực hành, &lt;strong&gt;không&lt;/strong&gt; ai tính SVD bằng cách lập $A^TA$: bình phương làm số điều kiện tăng từ $\kappa$ lên $\kappa^2$ (Bài 08-04), và các giá trị kỳ dị nhỏ bị mất chính xác. Thư viện LAPACK (bên dưới &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.svd&lt;/code&gt;) đưa $A$ về dạng hai đường chéo bằng các phép phản xạ Householder rồi lặp QR trên đó, làm việc trực tiếp với $A$. Thuật toán tay ở trên vẫn là cách đúng để &lt;em&gt;hiểu&lt;/em&gt; SVD và để làm bài trên giấy.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;U&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vt&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;svd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;        &lt;span class=&quot;c1&quot;&gt;# s = [1.732..., 1.0]
&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;allclose&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;U&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;# True
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: tính SVD từ AᵀA&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Sửa A, xem AᵀA, các σ, V, U và kiểm tra UΣVᵀ = A.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter11/svd.html?mode=comp&quot; title=&quot;Minh hoạ: tính SVD từ AᵀA&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter11/svd.html?mode=comp&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Tính lại SVD của $A = \begin{bmatrix} 3 &amp;amp; 0 \\ 4 &amp;amp; 5 \end{bmatrix}$ (Bài 11-01) bằng thuật toán.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A^TA = \begin{bmatrix} 25 &amp;amp; 20 \\ 20 &amp;amp; 25 \end{bmatrix}$, trị riêng $45, 5$, $v_1 = \tfrac{1}{\sqrt2}(1, 1)$, $v_2 = \tfrac{1}{\sqrt2}(1, -1)$. $\sigma_1 = 3\sqrt5$, $\sigma_2 = \sqrt5$. $u_1 = Av_1/\sigma_1 = \tfrac{1}{\sqrt{10}}(1, 3)$, $u_2 = Av_2/\sigma_2 = \tfrac{1}{\sqrt{10}}(3, -1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Tính SVD của $A = \begin{bmatrix} 1 &amp;amp; 0 \\ 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A^TA = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$: $\sigma_1 = \sqrt3$, $v_1 = \tfrac{1}{\sqrt2}(1, 1)$, $u_1 = \tfrac{1}{\sqrt6}(1, 2, 1)$; $\sigma_2 = 1$, $v_2 = \tfrac{1}{\sqrt2}(-1, 1)$, $u_2 = \tfrac{1}{\sqrt2}(-1, 0, 1)$; $u_3 = \tfrac{1}{\sqrt3}(1, -1, 1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Tính SVD của vectơ hàng $A = \begin{bmatrix} 3 &amp;amp; 4 \end{bmatrix}$ (cỡ $1 \times 2$).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$AA^T = [25]$, nên $\sigma_1 = 5$, $u_1 = 1$, $v_1 = A^Tu_1/\sigma_1 = \tfrac15(3, 4)$; $v_2 = \tfrac15(-4, 3)$. $A = 1\cdot\begin{bmatrix} 5 &amp;amp; 0 \end{bmatrix}V^T$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Chứng minh: $A$ và $A^T$ có cùng các giá trị kỳ dị khác $0$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A^T = V\Sigma^TU^T$ là một SVD của $A^T$, với cùng các $\sigma_i$ trên đường chéo. (Cách khác: $A^TA$ và $AA^T$ có cùng các trị riêng khác $0$.)

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$A^TA = V\Sigma^T\Sigma V^T$, $AA^T = U\Sigma\Sigma^TU^T$: $\sigma_i^2$ là trị riêng, $v_i$ và $u_i$ là vectơ riêng.&lt;/li&gt;
    &lt;li&gt;Thuật toán: $v_i$, $\sigma_i$ từ $A^TA$; $u_i = Av_i/\sigma_i$; bổ sung $U$ bằng cơ sở trực chuẩn của $\operatorname{Null}(A^T)$.&lt;/li&gt;
    &lt;li&gt;Không tính $U$ và $V$ độc lập (sai dấu).&lt;/li&gt;
    &lt;li&gt;$\lVert A \rVert_F^2 = \sum\sigma_i^2$. Máy tính không lập $A^TA$ mà dùng Householder và lặp QR.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Phân rã giá trị kỳ dị: góc nhìn hình học</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter11/11_01_Phan_Ra_Gia_Tri_Ky_Di_Goc_Nhin_Hinh_Hoc/"/>
   <updated>2026-01-11T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter11/11_01_Phan_Ra_Gia_Tri_Ky_Di_Goc_Nhin_Hinh_Hoc</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;phát biểu phân rã giá trị kỳ dị (SVD) $A = U\Sigma V^T$ cho mọi ma trận thực;&lt;/li&gt;
    &lt;li&gt;giải thích SVD như ba bước: quay ($V^T$), co giãn theo trục ($\Sigma$), quay ($U$);&lt;/li&gt;
    &lt;li&gt;đọc từ SVD ảnh của hình tròn đơn vị, hạng, và chuẩn $\max_{\lVert x \rVert = 1}\lVert Ax \rVert$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Ma trận $A = \begin{bmatrix} 3 &amp;amp; 0 \\ 4 &amp;amp; 5 \end{bmatrix}$ không đối xứng, nên không có cơ sở trực chuẩn gồm vectơ riêng. Nhưng hãy nhìn ảnh của đường tròn đơn vị: đó là một elip. Elip có hai trục vuông góc. Câu hỏi: vectơ đơn vị nào của đường tròn được đưa tới hai đầu trục của elip?&lt;/p&gt;

&lt;p&gt;Câu trả lời: $v_1 = \tfrac{1}{\sqrt2}(1, 1)$ và $v_2 = \tfrac{1}{\sqrt2}(1, -1)$, hai vectơ &lt;strong&gt;vuông góc&lt;/strong&gt;, được đưa tới&lt;/p&gt;

\[Av_1 = \tfrac{1}{\sqrt2}(3, 9) = 3\sqrt5\cdot\tfrac{1}{\sqrt{10}}(1, 3), \qquad Av_2 = \tfrac{1}{\sqrt2}(3, -1) = \sqrt5\cdot\tfrac{1}{\sqrt{10}}(3, -1),\]

&lt;p&gt;cũng là hai vectơ &lt;strong&gt;vuông góc&lt;/strong&gt;. Như vậy $A$ biến một cặp hướng vuông góc thành một cặp hướng vuông góc, kéo dãn với hệ số $\sigma_1 = 3\sqrt5 \approx 6{,}71$ và $\sigma_2 = \sqrt5 \approx 2{,}24$.&lt;/p&gt;

&lt;h2 id=&quot;phát-biểu-svd&quot;&gt;Phát biểu SVD&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (SVD).&lt;/strong&gt; Mọi ma trận thực $A$ cỡ $m \times n$ có hạng $r$ viết được dưới dạng&lt;/p&gt;

\[A = U\Sigma V^T,\]

  &lt;p&gt;với $U$ ($m \times m$) và $V$ ($n \times n$) trực giao, $\Sigma$ ($m \times n$) có các phần tử $\sigma_1 \ge \sigma_2 \ge \dots \ge \sigma_r &amp;gt; 0$ ở vị trí $(i, i)$, còn lại bằng $0$. Các $\sigma_i$ là &lt;strong&gt;giá trị kỳ dị&lt;/strong&gt;, các cột $v_i$ của $V$ và $u_i$ của $U$ là &lt;strong&gt;vectơ kỳ dị phải&lt;/strong&gt; và &lt;strong&gt;trái&lt;/strong&gt;, thoả&lt;/p&gt;

  &lt;p&gt;\(Av_i = \sigma_iu_i \quad (i \le r), \qquad Av_i = 0 \quad (i &amp;gt; r).\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Chứng minh (và cách tính) ở Bài 11-02: $v_i$ là vectơ riêng của ma trận đối xứng $A^TA$, $\sigma_i^2$ là trị riêng của nó.&lt;/p&gt;

&lt;p&gt;Viết theo cột–hàng, SVD là tổng các ma trận hạng 1:&lt;/p&gt;

\[A = \sigma_1u_1v_1^T + \sigma_2u_2v_2^T + \dots + \sigma_ru_rv_r^T.\]

&lt;h2 id=&quot;ba-bước-quay-co-giãn-quay&quot;&gt;Ba bước: quay, co giãn, quay&lt;/h2&gt;

&lt;p&gt;Đọc $Ax = U(\Sigma(V^Tx))$ từ phải sang trái:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;$V^Tx$: &lt;strong&gt;quay&lt;/strong&gt; (hoặc phản xạ) để các hướng $v_1, \dots, v_n$ trùng với các trục toạ độ $e_1, \dots, e_n$.&lt;/li&gt;
  &lt;li&gt;$\Sigma$: &lt;strong&gt;co giãn&lt;/strong&gt; dọc trục thứ $i$ với hệ số $\sigma_i$ (và xoá các trục $i &amp;gt; r$, đổi số chiều từ $n$ sang $m$).&lt;/li&gt;
  &lt;li&gt;$U$: &lt;strong&gt;quay&lt;/strong&gt; các trục toạ độ $e_i$ về các hướng $u_i$.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Vì vậy ảnh của hình cầu đơn vị qua $A$ là một &lt;strong&gt;elip&lt;/strong&gt; (ellipsoid) với các nửa trục $\sigma_1u_1, \dots, \sigma_ru_r$. Với ma trận hạng $1$, elip dẹt thành một đoạn thẳng.&lt;/p&gt;

&lt;p&gt;So sánh với chéo hoá: $A = PDP^{-1}$ dùng &lt;strong&gt;một&lt;/strong&gt; cơ sở (thường không trực giao) cho cả đầu vào và đầu ra, và không phải lúc nào cũng tồn tại. SVD dùng &lt;strong&gt;hai&lt;/strong&gt; cơ sở trực chuẩn khác nhau, và luôn tồn tại, kể cả với ma trận chữ nhật.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (ví dụ mở đầu).&lt;/strong&gt; Với $A = \begin{bmatrix} 3 &amp;amp; 0 \\ 4 &amp;amp; 5 \end{bmatrix}$:&lt;/p&gt;

\[A = \underbrace{\frac{1}{\sqrt{10}}\begin{bmatrix} 1 &amp;amp; 3 \\ 3 &amp;amp; -1 \end{bmatrix}}_{U}\underbrace{\begin{bmatrix} 3\sqrt5 &amp;amp; 0 \\ 0 &amp;amp; \sqrt5 \end{bmatrix}}_{\Sigma}\underbrace{\frac{1}{\sqrt2}\begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix}}_{V^T}.\]

  &lt;p&gt;Kiểm tra: $\det A = 15 = \sigma_1\sigma_2 \cdot \det U \cdot \det V = 15 \cdot (-1)(-1)$. Elip ảnh có nửa trục dài $3\sqrt5$ theo hướng $(1, 3)$ và nửa trục ngắn $\sqrt5$ theo hướng $(3, -1)$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;những-gì-svd-cho-biết-ngay&quot;&gt;Những gì SVD cho biết ngay&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hạng&lt;/strong&gt;: $r$ = số giá trị kỳ dị khác $0$.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chuẩn&lt;/strong&gt;: $\max_{\lVert x \rVert = 1}\lVert Ax \rVert = \sigma_1$, đạt tại $x = v_1$ (Bài tập 4, Bài 10-06). Kéo dãn nhỏ nhất (với ma trận vuông) là $\sigma_n$.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bốn không gian con&lt;/strong&gt;: $u_1, \dots, u_r$ là cơ sở trực chuẩn của $\operatorname{Col}(A)$; $v_{r+1}, \dots, v_n$ là cơ sở trực chuẩn của $\operatorname{Null}(A)$; tương tự $v_1, \dots, v_r$ cho $\operatorname{Row}(A)$ và $u_{r+1}, \dots, u_m$ cho $\operatorname{Null}(A^T)$.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Định thức&lt;/strong&gt; (ma trận vuông): $\lvert\det A\rvert = \sigma_1\sigma_2\cdots\sigma_n$, diện tích (thể tích) của elip ảnh chia cho của hình tròn đơn vị.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Số điều kiện&lt;/strong&gt;: $\kappa(A) = \sigma_1/\sigma_n$ (Bài 08-05).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;ứng-dụng-biến-dạng-trong-cơ-học-và-đồ-họa&quot;&gt;Ứng dụng: biến dạng trong cơ học và đồ họa&lt;/h2&gt;

&lt;p&gt;Trong cơ học môi trường liên tục, gradient biến dạng $F$ tại một điểm cho biết một hình cầu vật chất nhỏ bị biến thành hình gì. SVD $F = U\Sigma V^T$ tách biến dạng thành phần xoay (không làm thay đổi vật liệu) và phần kéo dãn theo các &lt;strong&gt;hướng chính&lt;/strong&gt; với hệ số $\sigma_i$; chỉ phần kéo dãn sinh ra ứng suất. Các bộ mô phỏng vật mềm trong đồ họa (vải, cơ thể nhân vật) tính SVD của từng phần tử ở mỗi khung hình để làm điều đó.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: SVD là quay, giãn, quay&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo thanh bước để xem Vᵀ, Σ, U lần lượt biến đường tròn thành elip.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter11/svd.html?mode=geo&amp;amp;t=0&quot; title=&quot;Minh hoạ: SVD là quay, giãn, quay&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter11/svd.html?mode=geo&amp;amp;t=0&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-svd-từ-hình-tròn-đến-elip-trong-ba-bước&quot;&gt;Video ngắn: SVD: từ hình tròn đến elip trong ba bước&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/svd-three-steps.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;A = [3 0; 4 5] = U Σ Vᵀ. Bước 1: Vᵀ quay −45°, đưa v₁, v₂ về hai trục toạ độ. Bước 2: Σ co giãn dọc hai trục với hệ số 3√5 và √5. Bước 3: U quay khoảng 71,6°, đưa hai trục elip về hướng u₁, u₂. Nửa trục của elip là các giá trị kỳ dị. Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Viết SVD của $\begin{bmatrix} 3 &amp;amp; 0 \\ 0 &amp;amp; -2 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\sigma_1 = 3$, $\sigma_2 = 2$. Chọn $V = I$, $\Sigma = \operatorname{diag}(3, 2)$, $U = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; -1 \end{bmatrix}$: dấu trừ được đưa vào $U$ vì giá trị kỳ dị luôn không âm.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Viết SVD của ma trận hạng 1 $\begin{bmatrix} 2 &amp;amp; 2 \\ 1 &amp;amp; 1 \end{bmatrix}$ dưới dạng $\sigma_1u_1v_1^T$. Ảnh của đường tròn đơn vị là gì?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A = (2, 1)(1, 1)^T$, nên $\sigma_1 = \lVert(2, 1)\rVert\,\lVert(1, 1)\rVert = \sqrt{10}$, $u_1 = \tfrac{1}{\sqrt5}(2, 1)$, $v_1 = \tfrac{1}{\sqrt2}(1, 1)$, $\sigma_2 = 0$. Ảnh của đường tròn là đoạn thẳng từ $-\sqrt{10}\,u_1$ đến $\sqrt{10}\,u_1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Với $A$ đối xứng xác định dương, chứng minh SVD trùng với chéo hoá trực giao $A = Q\Lambda Q^T$. Nếu $A$ đối xứng nhưng có trị riêng âm thì sao?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Với $\lambda_i &amp;gt; 0$, chọn $U = V = Q$, $\Sigma = \Lambda$. Nếu có $\lambda_i &amp;lt; 0$: $\sigma_i = \lvert\lambda_i\rvert$, và lấy $u_i = -q_i$, $v_i = q_i$ (sau đó sắp xếp lại theo thứ tự giảm dần).

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Chứng minh: với $A$ vuông, $\lvert\det A\rvert = \sigma_1\cdots\sigma_n$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\det A = \det U\det\Sigma\det V^T$, với $\det U, \det V = \pm1$ (ma trận trực giao), nên $\lvert\det A\rvert = \det\Sigma = \prod\sigma_i$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Mọi ma trận: $A = U\Sigma V^T = \sum_{i \le r}\sigma_iu_iv_i^T$, với $U, V$ trực giao và $\sigma_1 \ge \dots \ge \sigma_r &amp;gt; 0$.&lt;/li&gt;
    &lt;li&gt;$Av_i = \sigma_iu_i$: các hướng vuông góc $v_i$ đi tới các hướng vuông góc $u_i$.&lt;/li&gt;
    &lt;li&gt;Hình học: quay, co giãn theo trục, quay; hình tròn đơn vị thành elip với nửa trục $\sigma_iu_i$.&lt;/li&gt;
    &lt;li&gt;SVD cho ngay hạng, chuẩn $\sigma_1$, $\lvert\det A\rvert$, số điều kiện và cơ sở trực chuẩn của bốn không gian con.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Image Compression and Denoising with the SVD</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter11/11_06_Nen_Anh_Va_Khu_Nhieu_Bang_SVD/"/>
   <updated>2026-01-11T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter11/11_06_Nen_Anh_Va_Khu_Nhieu_Bang_SVD</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;compress a grayscale image with a rank-$k$ approximation and compute the compression ratio;&lt;/li&gt;
    &lt;li&gt;estimate the reconstruction error as a function of $k$ from the singular values;&lt;/li&gt;
    &lt;li&gt;explain why discarding small singular values removes noise, and choose a cutoff.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;p&gt;This lesson is &lt;strong&gt;optional&lt;/strong&gt; and is mostly programming practice on the results of Lesson 11-03.&lt;/p&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;A $512 \times 512$ grayscale image is a matrix $A$ of $262{,}144$ numbers (brightness from $0$ to $255$). Natural images have structure: smooth regions, edges, repeated patterns. So the singular values of $A$ decay very fast, and the low-rank approximation $A_k$ (Lesson 11-03) with a few dozen terms already looks close to the original.&lt;/p&gt;

&lt;h2 id=&quot;compression-with-the-svd&quot;&gt;Compression with the SVD&lt;/h2&gt;

&lt;p&gt;Storing $A_k = \sum_{i \le k}\sigma_iu_iv_i^T$ takes $k$ singular values, $k$ vectors $u_i \in \mathbb{R}^m$ and $k$ vectors $v_i \in \mathbb{R}^n$:&lt;/p&gt;

\[\text{storage ratio} = \frac{k(m + n + 1)}{mn}.\]

&lt;p&gt;For $m = n = 512$, $k = 50$: $50 \cdot 1025 = 51{,}250$ numbers, about $19.6\%$ of the original. Compression only pays off when $k(m + n + 1) &amp;lt; mn$, i.e. $k &amp;lt; 255.75$ here.&lt;/p&gt;

&lt;p&gt;The relative error (Eckart–Young):&lt;/p&gt;

\[\frac{\lVert A - A_k \rVert_F}{\lVert A \rVert_F} = \sqrt{\frac{\sum_{i &amp;gt; k}\sigma_i^2}{\sum_i\sigma_i^2}}.\]

&lt;p&gt;In practice JPEG compresses much better than the SVD (it uses the discrete cosine transform on $8 \times 8$ blocks plus entropy coding). The SVD is still the clearest way to &lt;em&gt;see&lt;/em&gt; low-rank approximation, and it underlies compression in other settings (neural network weight matrices, scientific data).&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (reading a singular value spectrum).&lt;/strong&gt; Suppose an image has $\sigma_i \approx 10^4 \cdot i^{-1}$ for $i = 1, \dots, 512$. The total is $\sum\sigma_i^2 \approx 10^8 \cdot \sum i^{-2} \approx 10^8 \cdot 1.64$, and the discarded part for $k = 50$ is $\sum_{i &amp;gt; 50}\sigma_i^2 \approx 10^8 \cdot 0.018$ (close to $\tfrac{1}{50}$). The relative error is $\approx\sqrt{0.018/1.64} \approx 10\%$. The faster the spectrum decays (the smoother the image), the smaller the error for the same $k$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;denoising-by-truncation&quot;&gt;Denoising by truncation&lt;/h2&gt;

&lt;p&gt;Suppose we observe $\tilde A = A + E$, where $A$ is the clean image (low rank or nearly so) and $E$ is independent random noise with standard deviation $s$ per pixel. Two facts:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Noise has &lt;strong&gt;no structure&lt;/strong&gt;: the energy of $E$ is spread evenly over all directions, so all singular values of $E$ are of similar size. Random matrix theory says the largest singular value of an $m \times n$ noise matrix is about $s(\sqrt m + \sqrt n)$.&lt;/li&gt;
  &lt;li&gt;Signal &lt;strong&gt;has structure&lt;/strong&gt;: the energy of $A$ is concentrated in a few large singular values.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So singular values of $\tilde A$ well above $s(\sqrt m + \sqrt n)$ are mostly signal; those below are mostly noise. &lt;strong&gt;Truncation&lt;/strong&gt;, keeping only $\tilde A_k$ with $\sigma_k$ above the threshold, removes most of the noise while keeping most of the signal.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Remark (error after truncation).&lt;/strong&gt; If $A$ has rank $k$, then $\lVert \tilde A_k - A \rVert_F \le 2\sqrt{2k}\,\lVert E \rVert_2$ (by Eckart–Young and the triangle inequality). Meanwhile $\lVert \tilde A - A \rVert_F = \lVert E \rVert_F$, which is about $s\sqrt{mn}$. For small $k$, $\sqrt{k}\,\lVert E \rVert_2 \approx s\sqrt k(\sqrt m + \sqrt n)$ is far smaller.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Sketch.&lt;/strong&gt; $\tilde A_k - A$ has rank $\le 2k$, so $\lVert \tilde A_k - A \rVert_F \le \sqrt{2k}\,\lVert \tilde A_k - A \rVert_2$. And $\lVert \tilde A_k - A \rVert_2 \le \lVert \tilde A_k - \tilde A \rVert_2 + \lVert \tilde A - A \rVert_2 = \sigma_{k+1}(\tilde A) + \lVert E \rVert_2 \le 2\lVert E \rVert_2$, since by Eckart–Young $\sigma_{k+1}(\tilde A) \le \lVert \tilde A - A \rVert_2$ ($A$ has rank $k$).&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-surveillance-video-and-scientific-data&quot;&gt;Application: surveillance video and scientific data&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Background subtraction.&lt;/strong&gt; Stack each frame of a fixed camera as a column of a matrix. The static background is nearly the same in every frame, so it is a very low-rank approximation (often rank $1$ to $3$); the residual $\tilde A - \tilde A_k$ contains the moving people and cars.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Denoising electron microscopy, MRI and spectral data.&lt;/strong&gt; Methods such as the optimal hard threshold of Gavish and Donoho (2014) choose the cutoff automatically from the matrix size and the estimated noise level.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: image compression and denoising with SVD&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag k to keep the k largest singular values; add noise to see SVD denoising.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter11/nen_anh.html?lang=en&quot; title=&quot;Interactive: image compression and denoising with SVD&quot; loading=&quot;lazy&quot; style=&quot;height: 600px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter11/nen_anh.html?lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; For a $1200 \times 800$ image, what is the largest $k$ for which compression pays off? What is the storage ratio for $k = 100$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$k(2001) &amp;lt; 960{,}000$, i.e. $k \le 479$. For $k = 100$: $200{,}100/960{,}000 \approx 20.8\%$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; An image has (rounded) singular values $\sigma_1 = 100$, $\sigma_2 = 40$, $\sigma_3 = 20$, and the rest have squared sum $100$. Compute the relative errors of $A_1$, $A_2$, $A_3$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\sum\sigma_i^2 = 10{,}000 + 1600 + 400 + 100 = 12{,}100$, $\lVert A \rVert_F = 110$. $A_1$: $\sqrt{2100}/110 \approx 0.42$; $A_2$: $\sqrt{500}/110 \approx 0.20$; $A_3$: $\sqrt{100}/110 \approx 0.09$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; A $400 \times 400$ noise matrix $E$ has independent entries with standard deviation $s = 2$. Estimate $\lVert E \rVert_F$ and $\lVert E \rVert_2$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\lVert E \rVert_F^2 \approx 160{,}000 \cdot 4$, so $\lVert E \rVert_F \approx 800$. $\lVert E \rVert_2 \approx 2(\sqrt{400} + \sqrt{400}) = 80$. The noise energy is spread over $400$ directions, each with only $\sigma_i \le 80$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (programming).&lt;/strong&gt; Take any grayscale image (or build a synthetic one from a few rectangles and a gradient), add Gaussian noise, and compare the error $\lVert \tilde A_k - A \rVert_F$ as a function of $k$. Is the best $k$ close to the number of singular values of $\tilde A$ above the threshold $s(\sqrt m + \sqrt n)$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Use `U, s_, Vt = np.linalg.svd(At, full_matrices=False)` and `Ak = (U[:, :k] * s_[:k]) @ Vt[:k]`. The error falls as $k$ grows up to about the number of singular values above the threshold, then rises again as noise starts coming back in. For a low-rank synthetic image, the best $k$ usually equals or is very close to that count.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Compression: storing $A_k$ takes $k(m + n + 1)$ numbers; the relative error is $\sqrt{\sum_{i &amp;gt; k}\sigma_i^2/\sum\sigma_i^2}$.&lt;/li&gt;
    &lt;li&gt;Natural images have fast-decaying singular value spectra, so a small $k$ suffices.&lt;/li&gt;
    &lt;li&gt;Noise is spread over all directions, with largest singular value about $s(\sqrt m + \sqrt n)$; signal is concentrated in a few.&lt;/li&gt;
    &lt;li&gt;Denoising: keep the singular values above the noise threshold and drop the rest.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Principal Component Analysis (PCA)</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter11/11_05_Phan_Tich_Thanh_Phan_Chinh_PCA/"/>
   <updated>2026-01-11T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter11/11_05_Phan_Tich_Thanh_Phan_Chinh_PCA</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;perform PCA: subtract the mean, compute the SVD (or diagonalize the covariance), project the data onto $k$ principal components;&lt;/li&gt;
    &lt;li&gt;explain principal components as directions of largest variance and compute the explained variance ratio;&lt;/li&gt;
    &lt;li&gt;recognize when features must be standardized before PCA.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Four data points in the plane: $(3, 2)$, $(2, 3)$, $(0, -1)$, $(-1, 0)$. They lie near the line in direction $(1, 1)$ through the center $(1, 1)$. If we may keep only &lt;strong&gt;one&lt;/strong&gt; number per point, along which direction should we take coordinates to lose the least information? Lesson 10-06 answered: the direction of largest variance, the top eigenvector of the covariance matrix. PCA is the full procedure built on this idea, and the SVD is how to compute it.&lt;/p&gt;

&lt;h2 id=&quot;the-pca-procedure&quot;&gt;The PCA procedure&lt;/h2&gt;

&lt;p&gt;Given $n$ data points $x_1, \dots, x_n \in \mathbb{R}^d$:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Center&lt;/strong&gt;: $\mu = \tfrac1n\sum x_j$; form the $n \times d$ matrix $X$ whose $j$-th row is $(x_j - \mu)^T$.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Covariance&lt;/strong&gt;: $C = \dfrac{1}{n - 1}X^TX$ (symmetric, positive semidefinite).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SVD&lt;/strong&gt;: $X = U\Sigma V^T$. Then $C = V\dfrac{\Sigma^T\Sigma}{n - 1}V^T$: the columns $v_1, \dots, v_d$ of $V$ are the &lt;strong&gt;principal components&lt;/strong&gt;, and the variance along $v_i$ is $\lambda_i = \dfrac{\sigma_i^2}{n - 1}$.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Project&lt;/strong&gt;: the new coordinates (scores) are $Z_k = XV_k = U_k\Sigma_k$, of size $n \times k$.&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; The unit direction $u$ maximizing the variance of the projections $\tfrac{1}{n-1}\sum_j((x_j - \mu)^Tu)^2 = u^TCu$ is $v_1$; among directions orthogonal to $v_1, \dots, v_{k-1}$, the maximizer is $v_k$. The $k$-dimensional subspace $\operatorname{span}(v_1, \dots, v_k)$ minimizes the sum of squared distances from the (centered) points to it.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; The first part is Theorems 1 and 2 of Lesson 10-06 applied to $C$. For the second: the sum of squared distances to a subspace $S$ is $\lVert X - XP_S \rVert_F^2$, where $XP_S$ has rank $\le k$. By Eckart–Young (Lesson 11-03), the minimum is attained when $XP_S = X_k = XV_kV_k^T$, i.e. $S = \operatorname{span}(v_1, \dots, v_k)$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;So PCA is both “the direction of largest variance” and “the best-fitting plane in perpendicular distance”, unlike regression (Chapter 08), which measures distance only vertically.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (the motivating example).&lt;/strong&gt; $\mu = (1, 1)$, and&lt;/p&gt;

\[X = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \\ -1 &amp;amp; -2 \\ -2 &amp;amp; -1 \end{bmatrix}, \qquad X^TX = \begin{bmatrix} 10 &amp;amp; 8 \\ 8 &amp;amp; 10 \end{bmatrix}, \qquad C = \frac13\begin{bmatrix} 10 &amp;amp; 8 \\ 8 &amp;amp; 10 \end{bmatrix}.\]

  &lt;p&gt;$X^TX$ has eigenvalues $18$ (direction $(1, 1)$) and $2$ (direction $(1, -1)$), so $\sigma_1 = 3\sqrt2$, $\sigma_2 = \sqrt2$, with variances $\lambda_1 = 6$, $\lambda_2 = \tfrac23$. The first principal component $v_1 = \tfrac{1}{\sqrt2}(1, 1)$ explains $18/20 = 90\%$ of the variance. Scores along $v_1$: $Xv_1 = \tfrac{1}{\sqrt2}(3, 3, -3, -3)$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;explained-variance-and-choosing-k&quot;&gt;Explained variance and choosing $k$&lt;/h2&gt;

&lt;p&gt;The fraction of variance explained by the first $k$ components is $\dfrac{\sigma_1^2 + \dots + \sigma_k^2}{\sigma_1^2 + \dots + \sigma_d^2}$, exactly the “energy” ratio of Lesson 11-03. Pick the smallest $k$ reaching a threshold (say $90\%$ or $95\%$), or use the elbow of the scree plot.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Standardization.&lt;/strong&gt; PCA is sensitive to units: a feature in meters and one in millimeters give very different results. When features have different units, divide each column of $X$ by its standard deviation before PCA (equivalent to PCA on the correlation matrix).&lt;/p&gt;

&lt;h2 id=&quot;application-dimensionality-reduction-and-visualization&quot;&gt;Application: dimensionality reduction and visualization&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Visualization.&lt;/strong&gt; Project high-dimensional data (images, gene expression, embeddings) onto the first two principal components to plot it in the plane.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Eigenfaces.&lt;/strong&gt; Each $64 \times 64$ face image is a vector in $\mathbb{R}^{4096}$; a few dozen principal components suffice for recognition and decent reconstruction.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Link to deep learning.&lt;/strong&gt; PCA is a &lt;em&gt;linear autoencoder&lt;/em&gt;: encode $z = V_k^T(x - \mu)$, decode $\hat x = \mu + V_kz$, and Theorem 1 says this is the linear encoder–decoder pair with the smallest reconstruction error (Deep Learning course, Chapter 12).&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;3.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;2.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;2.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;3.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;Xc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;mean&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;axis&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;U&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vt&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;svd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Xc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;full_matrices&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Vt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;      &lt;span class=&quot;c1&quot;&gt;# ±[0.707, 0.707], [0.9, 0.1]
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: PCA on a point cloud&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag the points and see the principal axes PC1, PC2 and the variance kept.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter11/pca.html?lang=en&quot; title=&quot;Interactive: PCA on a point cloud&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter11/pca.html?lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-pca-the-direction-of-largest-variance&quot;&gt;Short video: PCA: the direction of largest variance&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/pca-rotating-axis.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Four points (3; 2), (2; 3), (0; −1), (−1; 0), mean μ = (1; 1). Rotate a trial axis and measure the variance of the projections: largest 6 at 45°, along v₁ = (1; 1)/√2; smallest 2/3 at 135°. v₁ explains 90% of the variance. Scores along v₁: (3; 3; −3; −3)/√2. Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Do PCA on the three points $(1, 0)$, $(0, 1)$, $(2, 2)$: find the mean, the first principal component and the explained variance ratio.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\mu = (1, 1)$, $X = \begin{bmatrix} 0 &amp;amp; -1 \\ -1 &amp;amp; 0 \\ 1 &amp;amp; 1 \end{bmatrix}$, $X^TX = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$ with eigenvalues $3$ (direction $(1, 1)$) and $1$ (direction $(1, -1)$). $v_1 = \tfrac{1}{\sqrt2}(1, 1)$ explains $3/4 = 75\%$ of the variance.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Prove that the total variance $\operatorname{tr} C = \sum_i\lambda_i$ does not change under a rotation of the axes, and equals the sum of the variances of the original features.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\operatorname{tr} C = \sum_i C_{ii}$ is the sum of the feature variances. The trace equals the sum of the eigenvalues, and $\operatorname{tr}(Q^TCQ) = \operatorname{tr}(C)$ for every orthogonal $Q$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Two features: height (m, variance $0.01$) and weight (kg, variance $100$), with correlation $0.7$. Without standardization, which direction does the first principal component nearly match? Why standardize?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Almost the weight axis, because its variance is $10^4$ times larger: the result reflects the units, not the structure. After standardization, the correlation matrix $\begin{bmatrix} 1 &amp;amp; 0.7 \\ 0.7 &amp;amp; 1 \end{bmatrix}$ gives $v_1 = \tfrac{1}{\sqrt2}(1, 1)$ explaining $85\%$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (programming).&lt;/strong&gt; Run PCA on the Iris data set ($150$ points, $4$ features, in cm), plot the explained variance ratios and the projection onto the first two components, colored by species.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Without standardization the explained variance ratios are about $92\%, 5\%, 2\%, 0.5\%$: the first two components keep about $98\%$. In the projection, *setosa* is clearly separated, and the other two species partly overlap.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;PCA: center, $X = U\Sigma V^T$; the principal components are the columns of $V$, with variances $\sigma_i^2/(n - 1)$.&lt;/li&gt;
    &lt;li&gt;$v_1$ is the direction of largest variance; $\operatorname{span}(v_1, \dots, v_k)$ is the best-fitting $k$-dimensional subspace in perpendicular distance.&lt;/li&gt;
    &lt;li&gt;Explained variance ratio $\sum_{i \le k}\sigma_i^2/\sum\sigma_i^2$; standardize when features have different units.&lt;/li&gt;
    &lt;li&gt;PCA is the optimal linear autoencoder.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>The Pseudoinverse</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter11/11_04_Gia_Nghich_Dao/"/>
   <updated>2026-01-11T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter11/11_04_Gia_Nghich_Dao</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;define and compute the pseudoinverse $A^+ = V\Sigma^+U^T$ from the SVD;&lt;/li&gt;
    &lt;li&gt;prove that $x^+ = A^+b$ is the minimum-norm least-squares solution;&lt;/li&gt;
    &lt;li&gt;recognize $A^+ = (A^TA)^{-1}A^T$ when the columns are independent, and relate $AA^+$, $A^+A$ to projections.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;The system $x_1 + x_2 = 2$, $x_1 + x_2 = 0$ has no solution; moreover $A = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$ has dependent columns, so the normal equations $A^TA\hat x = A^Tb$ (Lesson 08-02) have &lt;strong&gt;infinitely many&lt;/strong&gt; solutions: every $\hat x$ with $\hat x_1 + \hat x_2 = 1$. Which one to pick? A natural choice is the &lt;strong&gt;shortest&lt;/strong&gt; one, here $\hat x = (\tfrac12, \tfrac12)$. The pseudoinverse gives exactly this solution, by a formula.&lt;/p&gt;

&lt;h2 id=&quot;definition-via-the-svd&quot;&gt;Definition via the SVD&lt;/h2&gt;

&lt;p&gt;For $A = U\Sigma V^T$ of size $m \times n$ and rank $r$, let $\Sigma^+$ be the $n \times m$ matrix with $1/\sigma_1, \dots, 1/\sigma_r$ in positions $(i, i)$ and zeros elsewhere.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition.&lt;/strong&gt; The (Moore–Penrose) &lt;strong&gt;pseudoinverse&lt;/strong&gt; of $A$ is&lt;/p&gt;

  &lt;p&gt;\(A^+ = V\Sigma^+U^T = \sum_{i \le r}\frac{1}{\sigma_i}v_iu_i^T.\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Meaning: $A$ sends $v_i$ to $\sigma_iu_i$; $A^+$ sends $u_i$ back to $v_i/\sigma_i$, and sends $u_{r+1}, \dots, u_m$ (a basis of $\operatorname{Null}(A^T)$) to $0$. If $A$ is square and invertible, $A^+ = A^{-1}$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; $AA^+ = \sum_{i \le r}u_iu_i^T$ is the orthogonal projection onto $\operatorname{Col}(A)$, and $A^+A = \sum_{i \le r}v_iv_i^T$ is the orthogonal projection onto $\operatorname{Row}(A)$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; $AA^+ = U\Sigma V^TV\Sigma^+U^T = U(\Sigma\Sigma^+)U^T$, where $\Sigma\Sigma^+ = \operatorname{diag}(1, \dots, 1, 0, \dots, 0)$ ($r$ ones). So $AA^+ = \sum_{i \le r}u_iu_i^T$, the projection onto $\operatorname{span}(u_1, \dots, u_r) = \operatorname{Col}(A)$. Similarly for $A^+A$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;the-minimum-norm-least-squares-solution&quot;&gt;The minimum-norm least-squares solution&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2.&lt;/strong&gt; For every $b$, $x^+ = A^+b$ is a least-squares solution of $Ax = b$ (it minimizes $\lVert Ax - b \rVert$), and among all least-squares solutions $x^+$ has the smallest norm.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; By Theorem 1, $Ax^+ = AA^+b$ is the projection of $b$ onto $\operatorname{Col}(A)$, so $x^+$ is a least-squares solution (Lesson 08-01). Every other least-squares solution has the form $x^+ + z$ with $z \in \operatorname{Null}(A)$. Since $x^+ = \sum_{i \le r}\tfrac{u_i^Tb}{\sigma_i}v_i \in \operatorname{Row}(A) \perp \operatorname{Null}(A)$, Pythagoras gives $\lVert x^+ + z \rVert^2 = \lVert x^+ \rVert^2 + \lVert z \rVert^2 \ge \lVert x^+ \rVert^2$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (the motivating example).&lt;/strong&gt; $A = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix} = 2\,uv^T$ with $u = v = \tfrac{1}{\sqrt2}(1, 1)$. So $A^+ = \tfrac12 vu^T = \tfrac14\begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$, and for $b = (2, 0)$: $x^+ = A^+b = (\tfrac12, \tfrac12)$, exactly the shortest solution on the line $x_1 + x_2 = 1$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Independent columns.&lt;/strong&gt; If $A$ has rank $n$ (independent columns), $A^TA$ is invertible and $A^+ = (A^TA)^{-1}A^T$: the least-squares solution is unique and matches Lesson 08-02. If $A$ has rank $m$ (independent rows), $A^+ = A^T(AA^T)^{-1}$: the system has infinitely many solutions and $A^+b$ is the shortest.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; $A = \begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix}$ has independent columns and $A^TA = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$, so&lt;/p&gt;

\[A^+ = \frac13\begin{bmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{bmatrix}\begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 0 \end{bmatrix} = \frac13\begin{bmatrix} 1 &amp;amp; -1 &amp;amp; 2 \\ 1 &amp;amp; 2 &amp;amp; -1 \end{bmatrix}.\]

  &lt;p&gt;Check: $A^+A = I_2$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-regression-with-redundant-features&quot;&gt;Application: regression with redundant features&lt;/h2&gt;

&lt;p&gt;In linear regression, if two feature columns are nearly identical (say height in cm and in inches), $A^TA$ is singular or nearly so and $(A^TA)^{-1}$ is unusable. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.lstsq&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.pinv&lt;/code&gt; use the SVD: they drop singular values below a threshold (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rcond&lt;/code&gt;) and return the minimum-norm solution. This is the “truncated” cousin of ridge regression (Lesson 08-05): ridge softens $1/\sigma_i$ to $\sigma_i/(\sigma_i^2 + \lambda)$, while the truncated pseudoinverse sets $1/\sigma_i = 0$ when $\sigma_i$ is too small. A remarkable fact: for overparameterized linear regression (more unknowns than equations), gradient descent started at $0$ converges exactly to $A^+b$, because every update $A^T(\cdot)$ stays in $\operatorname{Row}(A)$.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: the pseudo-inverse A⁺&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag b and see x⁺ = A⁺b and its projection Ax⁺ onto the column space.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter11/svd.html?mode=pinv&amp;amp;preset=rank1&amp;amp;lang=en&quot; title=&quot;Interactive: the pseudo-inverse A⁺&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter11/svd.html?mode=pinv&amp;amp;preset=rank1&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Compute $A^+$ for $A = \begin{bmatrix} 1 &amp;amp; 0 \\ 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \end{bmatrix}$ (a $3 \times 2$ rectangular matrix).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A^TA = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$, $A^+ = (A^TA)^{-1}A^T = \tfrac13\begin{bmatrix} 2 &amp;amp; 1 &amp;amp; -1 \\ -1 &amp;amp; 1 &amp;amp; 2 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Compute $A^+$ for the column vector $a = (1, 2, 2)$ and for the row vector $a^T$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$a^+ = a^T/(a^Ta) = \tfrac19(1, 2, 2)$ (a row vector). $(a^T)^+ = a/(a^Ta) = \tfrac19(1, 2, 2)^T$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Find the minimum-norm solution of $x_1 + 2x_2 + 2x_3 = 9$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$x^+ = (a^T)^+\cdot 9 = \tfrac{9}{9}(1, 2, 2) = (1, 2, 2)$, the foot of the perpendicular from the origin to the plane.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Check the four Penrose conditions for $A^+$ in Example 1: $AA^+A = A$, $A^+AA^+ = A^+$, and $AA^+$, $A^+A$ symmetric.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$AA^+ = A^+A = \tfrac12\begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$ (symmetric; the projection onto $(1, 1)$). $AA^+A = \tfrac12\begin{bmatrix} 2 &amp;amp; 2 \\ 2 &amp;amp; 2 \end{bmatrix} = A$ and $A^+AA^+ = \tfrac12\cdot\tfrac14\begin{bmatrix} 2 &amp;amp; 2 \\ 2 &amp;amp; 2 \end{bmatrix} = A^+$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$A^+ = V\Sigma^+U^T = \sum_{i \le r}\sigma_i^{-1}v_iu_i^T$; $A^+ = A^{-1}$ when $A$ is invertible.&lt;/li&gt;
    &lt;li&gt;$AA^+$ projects onto $\operatorname{Col}(A)$, $A^+A$ onto $\operatorname{Row}(A)$.&lt;/li&gt;
    &lt;li&gt;$A^+b$ is the minimum-norm least-squares solution.&lt;/li&gt;
    &lt;li&gt;Independent columns: $A^+ = (A^TA)^{-1}A^T$; independent rows: $A^+ = A^T(AA^T)^{-1}$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Low-Rank Approximation and the Eckart–Young Theorem</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter11/11_03_Xap_Xi_Hang_Thap_Va_Dinh_Ly_Eckart_Young/"/>
   <updated>2026-01-11T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter11/11_03_Xap_Xi_Hang_Thap_Va_Dinh_Ly_Eckart_Young</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;form the rank-$k$ approximation $A_k = \sum_{i \le k}\sigma_iu_iv_i^T$;&lt;/li&gt;
    &lt;li&gt;state the Eckart–Young theorem and compute the error $\lVert A - A_k \rVert$ in the spectral and Frobenius norms;&lt;/li&gt;
    &lt;li&gt;choose $k$ from the “energy” ratio $\sum_{i \le k}\sigma_i^2 / \sum\sigma_i^2$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;A ratings table of $1000$ users $\times$ $500$ movies has $500{,}000$ numbers. If users’ tastes depend on only about $20$ “factors” (action, romance, comedy…), the table is nearly a rank-$20$ matrix, and $20 \cdot (1000 + 500) = 30{,}000$ numbers suffice to store it. Question: among all rank-$k$ matrices, which one is &lt;strong&gt;closest&lt;/strong&gt; to $A$? The SVD answers this completely.&lt;/p&gt;

&lt;h2 id=&quot;the-rank-k-approximation&quot;&gt;The rank-$k$ approximation&lt;/h2&gt;

&lt;p&gt;The SVD writes $A$ as a sum of rank-1 layers in decreasing order of importance:&lt;/p&gt;

\[A = \sigma_1u_1v_1^T + \sigma_2u_2v_2^T + \dots + \sigma_ru_rv_r^T.\]

&lt;p&gt;Keep the first $k$ layers:&lt;/p&gt;

\[A_k = \sigma_1u_1v_1^T + \dots + \sigma_ku_kv_k^T = U_k\Sigma_kV_k^T,\]

&lt;p&gt;where $U_k$, $V_k$ are the first $k$ columns of $U$, $V$ and $\Sigma_k = \operatorname{diag}(\sigma_1, \dots, \sigma_k)$. The matrix $A_k$ has rank $k$, and storing it takes $k(m + n + 1)$ numbers instead of $mn$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Eckart–Young–Mirsky).&lt;/strong&gt; For every matrix $B$ of rank at most $k$:&lt;/p&gt;

\[\lVert A - B \rVert_2 \ge \lVert A - A_k \rVert_2 = \sigma_{k+1}, \qquad \lVert A - B \rVert_F \ge \lVert A - A_k \rVert_F = \sqrt{\sigma_{k+1}^2 + \dots + \sigma_r^2}.\]

  &lt;p&gt;Here $\lVert M \rVert_2 = \max_{\lVert x \rVert = 1}\lVert Mx \rVert$ is the spectral norm.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof (spectral norm).&lt;/strong&gt; $A - A_k = \sum_{i &amp;gt; k}\sigma_iu_iv_i^T$ has largest singular value $\sigma_{k+1}$, so $\lVert A - A_k \rVert_2 = \sigma_{k+1}$. Let $B$ have rank $\le k$; $\operatorname{Null}(B)$ has dimension $\ge n - k$, and $W = \operatorname{span}(v_1, \dots, v_{k+1})$ has dimension $k + 1$. The dimensions add up to more than $n$, so there is a unit vector $x \in \operatorname{Null}(B) \cap W$. Write $x = \sum_{i \le k+1}c_iv_i$ with $\sum c_i^2 = 1$:&lt;/p&gt;

\[\lVert (A - B)x \rVert^2 = \lVert Ax \rVert^2 = \sum_{i \le k+1}\sigma_i^2c_i^2 \ge \sigma_{k+1}^2.\]

  &lt;p&gt;So $\lVert A - B \rVert_2 \ge \sigma_{k+1}$. The Frobenius case uses a similar idea for each singular value; we omit it.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; For $A = \begin{bmatrix} 3 &amp;amp; 0 \\ 4 &amp;amp; 5 \end{bmatrix}$ (Lesson 11-01), $\sigma_1 = 3\sqrt5$, $u_1 = \tfrac{1}{\sqrt{10}}(1, 3)$, $v_1 = \tfrac{1}{\sqrt2}(1, 1)$:&lt;/p&gt;

\[A_1 = 3\sqrt5\cdot\frac{1}{\sqrt{20}}\begin{bmatrix} 1 &amp;amp; 1 \\ 3 &amp;amp; 3 \end{bmatrix} = \frac32\begin{bmatrix} 1 &amp;amp; 1 \\ 3 &amp;amp; 3 \end{bmatrix}, \qquad A - A_1 = \frac12\begin{bmatrix} 3 &amp;amp; -3 \\ -1 &amp;amp; 1 \end{bmatrix}.\]

  &lt;p&gt;The error is $\lVert A - A_1 \rVert_F = \tfrac12\sqrt{9 + 9 + 1 + 1} = \sqrt5 = \sigma_2$. The share of “energy” kept: $\sigma_1^2/(\sigma_1^2 + \sigma_2^2) = 45/50 = 90\%$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;choosing-k&quot;&gt;Choosing $k$&lt;/h2&gt;

&lt;p&gt;By Theorem 1, the relative Frobenius error is&lt;/p&gt;

\[\frac{\lVert A - A_k \rVert_F}{\lVert A \rVert_F} = \sqrt{\frac{\sigma_{k+1}^2 + \dots + \sigma_r^2}{\sigma_1^2 + \dots + \sigma_r^2}}.\]

&lt;p&gt;In practice, plot the $\sigma_i$ (often on a log scale) and pick $k$ at the “elbow”, where the plot changes from falling fast to flat; or pick the smallest $k$ that keeps, say, $95\%$ of the energy. Real data usually has fast-decaying singular values, so a small $k$ is enough.&lt;/p&gt;

&lt;h2 id=&quot;application-recommender-systems-and-lora&quot;&gt;Application: recommender systems and LoRA&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Recommender systems.&lt;/strong&gt; A user $\times$ item ratings table is approximated by a low-rank matrix $A_k = (U_k\Sigma_k^{1/2})(\Sigma_k^{1/2}V_k^T)$: each user and each item gets a $k$-dimensional vector, and the predicted rating is their dot product. The Netflix Prize (2006–2009) popularized this approach (Chapter 14).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fine-tuning large language models (LoRA).&lt;/strong&gt; Instead of updating a whole $d \times d$ weight matrix $W$, we learn only a low-rank update $\Delta W = BA$ with $B$ of size $d \times k$, $A$ of size $k \times d$, $k \ll d$. The idea rests on the observation that useful updates have fast-decaying singular values.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: rank-1 approximation&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Keep σ₁u₁v₁ᵀ: the ellipse flattens to a segment and the error is σ₂.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter11/svd.html?mode=low&amp;amp;lang=en&quot; title=&quot;Interactive: rank-1 approximation&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter11/svd.html?mode=low&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Find the best rank-1 approximation of $A = \begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix}$ (Example 1, Lesson 11-02) and its Frobenius error.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A_1 = \sqrt3\,u_1v_1^T = \sqrt3\cdot\tfrac{1}{\sqrt{12}}\begin{bmatrix} 2 &amp;amp; 2 \\ 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix} = \tfrac12\begin{bmatrix} 2 &amp;amp; 2 \\ 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$. The error is $\lVert A - A_1 \rVert_F = \sigma_2 = 1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; A $1000 \times 800$ grayscale image is approximated by $A_{50}$. What fraction of the original numbers must be stored?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$50(1000 + 800 + 1) = 90{,}050$ versus $800{,}000$, about $11.3\%$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; The singular values of $A$ are $10, 5, 2, 1, 0.5$. Find the smallest $k$ for which $A_k$ keeps at least $95\%$ of the energy, and the relative Frobenius error.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\sum\sigma_i^2 = 100 + 25 + 4 + 1 + 0.25 = 130.25$. $k = 1$: $76.8\%$; $k = 2$: $125/130.25 \approx 96.0\%$. So $k = 2$, with relative error $\sqrt{5.25/130.25} \approx 0.20$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Prove: if $A$ is square and invertible, the (spectral-norm) distance from $A$ to the set of singular matrices is $\sigma_n$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Singular matrices have rank $\le n - 1$. By Theorem 1 with $k = n - 1$, the smallest distance is $\sigma_n$, attained at $A_{n-1}$. Consequently $1/\kappa(A) = \sigma_n/\sigma_1$ is the relative distance to singularity.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$A_k = \sum_{i \le k}\sigma_iu_iv_i^T$ is the rank-$k$ approximation; storing it takes $k(m + n + 1)$ numbers.&lt;/li&gt;
    &lt;li&gt;Eckart–Young: $A_k$ is the best among all matrices of rank $\le k$; $\lVert A - A_k \rVert_2 = \sigma_{k+1}$, $\lVert A - A_k \rVert_F = \sqrt{\sum_{i &amp;gt; k}\sigma_i^2}$.&lt;/li&gt;
    &lt;li&gt;Choose $k$ at the elbow of the $\sigma_i$ plot or by the energy ratio.&lt;/li&gt;
    &lt;li&gt;Applications: recommender systems, compression, LoRA.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Computing the SVD</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter11/11_02_Tinh_SVD/"/>
   <updated>2026-01-11T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter11/11_02_Tinh_SVD</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;compute the SVD of a small matrix from the eigenvalues and eigenvectors of $A^TA$ (or $AA^T$);&lt;/li&gt;
    &lt;li&gt;explain why to compute $u_i = Av_i/\sigma_i$ rather than finding $U$ and $V$ independently;&lt;/li&gt;
    &lt;li&gt;prove that the SVD exists and that $\lVert A \rVert_F^2 = \sum\sigma_i^2$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;If $A = U\Sigma V^T$, then&lt;/p&gt;

\[A^TA = V\Sigma^TU^TU\Sigma V^T = V(\Sigma^T\Sigma)V^T, \qquad AA^T = U(\Sigma\Sigma^T)U^T.\]

&lt;p&gt;These are orthogonal diagonalizations (Lesson 10-02) of the two symmetric positive semidefinite matrices $A^TA$ and $AA^T$. So: &lt;strong&gt;the $v_i$ are eigenvectors of $A^TA$, the $u_i$ are eigenvectors of $AA^T$, and the $\sigma_i^2$ are their common eigenvalues&lt;/strong&gt;. This gives a hand algorithm right away.&lt;/p&gt;

&lt;h2 id=&quot;the-algorithm&quot;&gt;The algorithm&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Compute $A^TA$ ($n \times n$, symmetric) and find its eigenvalues $\lambda_1 \ge \dots \ge \lambda_n \ge 0$ and an orthonormal eigenbasis $v_1, \dots, v_n$.&lt;/li&gt;
  &lt;li&gt;Set $\sigma_i = \sqrt{\lambda_i}$; $r$ is the number of $\sigma_i &amp;gt; 0$.&lt;/li&gt;
  &lt;li&gt;For $i \le r$, set $u_i = \dfrac{Av_i}{\sigma_i}$.&lt;/li&gt;
  &lt;li&gt;If $r &amp;lt; m$, extend with $u_{r+1}, \dots, u_m$ to an orthonormal basis of $\mathbb{R}^m$ (they form an orthonormal basis of $\operatorname{Null}(A^T)$).&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Existence of the SVD).&lt;/strong&gt; The vectors $u_1, \dots, u_r$ from step 3 are orthonormal, and $A = U\Sigma V^T$ with $U, \Sigma, V$ built as above.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; For $i, j \le r$: $u_i^Tu_j = \dfrac{v_i^TA^TAv_j}{\sigma_i\sigma_j} = \dfrac{\lambda_jv_i^Tv_j}{\sigma_i\sigma_j}$, which is $1$ if $i = j$ and $0$ if $i \neq j$. For $i &amp;gt; r$: $\lVert Av_i \rVert^2 = v_i^TA^TAv_i = \lambda_i = 0$, so $Av_i = 0$. Hence $Av_i = \sigma_iu_i$ for all $i$ (with $\sigma_i = 0$ for $i &amp;gt; r$), i.e. $AV = U\Sigma$, and multiplying on the right by $V^T$ gives $A = U\Sigma V^T$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Warning.&lt;/strong&gt; Do not compute $U$ from $AA^T$ and $V$ from $A^TA$ independently: each eigenvector is determined only up to sign (or up to a rotation within a repeated eigenspace), so $U\Sigma V^T$ may not equal $A$. Compute one side, then get the other from $u_i = Av_i/\sigma_i$. If $m &amp;lt; n$, start from the smaller $AA^T$ and use $v_i = A^Tu_i/\sigma_i$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; $A = \begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix}$ ($3 \times 2$).&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$A^TA = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$, eigenvalues $3, 1$, eigenvectors $v_1 = \tfrac{1}{\sqrt2}(1, 1)$, $v_2 = \tfrac{1}{\sqrt2}(1, -1)$.&lt;/li&gt;
    &lt;li&gt;$\sigma_1 = \sqrt3$, $\sigma_2 = 1$.&lt;/li&gt;
    &lt;li&gt;$u_1 = \dfrac{Av_1}{\sqrt3} = \dfrac{1}{\sqrt3}\cdot\dfrac{1}{\sqrt2}(2, 1, 1) = \tfrac{1}{\sqrt6}(2, 1, 1)$, $u_2 = Av_2 = \tfrac{1}{\sqrt2}(0, -1, 1)$.&lt;/li&gt;
    &lt;li&gt;Extend with $u_3 \perp u_1, u_2$: $u_3 = \tfrac{1}{\sqrt3}(1, -1, -1)$.&lt;/li&gt;
  &lt;/ul&gt;

\[A = \begin{bmatrix} 2/\sqrt6 &amp;amp; 0 &amp;amp; 1/\sqrt3 \\ 1/\sqrt6 &amp;amp; -1/\sqrt2 &amp;amp; -1/\sqrt3 \\ 1/\sqrt6 &amp;amp; 1/\sqrt2 &amp;amp; -1/\sqrt3 \end{bmatrix}\begin{bmatrix} \sqrt3 &amp;amp; 0 \\ 0 &amp;amp; 1 \\ 0 &amp;amp; 0 \end{bmatrix}\frac{1}{\sqrt2}\begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix}.\]

  &lt;p&gt;The reduced form (keeping only $r$ columns): $A = \sqrt3\,u_1v_1^T + u_2v_2^T$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;the-frobenius-norm&quot;&gt;The Frobenius norm&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2.&lt;/strong&gt; $\lVert A \rVert_F^2 = \sum_{i,j}a_{ij}^2 = \sigma_1^2 + \dots + \sigma_r^2$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; $\lVert A \rVert_F^2 = \operatorname{tr}(A^TA)$, the sum of the eigenvalues of $A^TA$, which is $\sum\sigma_i^2$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Check on Example 1: the sum of squared entries is $4$, and $\sigma_1^2 + \sigma_2^2 = 3 + 1 = 4$.&lt;/p&gt;

&lt;h2 id=&quot;application-the-svd-on-a-computer&quot;&gt;Application: the SVD on a computer&lt;/h2&gt;

&lt;p&gt;In practice, &lt;strong&gt;nobody&lt;/strong&gt; computes the SVD by forming $A^TA$: squaring raises the condition number from $\kappa$ to $\kappa^2$ (Lesson 08-04), and small singular values lose accuracy. LAPACK (underneath &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.svd&lt;/code&gt;) reduces $A$ to bidiagonal form with Householder reflections and then iterates QR on it, working with $A$ directly. The hand algorithm above is still the right way to &lt;em&gt;understand&lt;/em&gt; the SVD and to do it on paper.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;U&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vt&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;svd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;        &lt;span class=&quot;c1&quot;&gt;# s = [1.732..., 1.0]
&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;allclose&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;U&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;# True
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: computing the SVD from AᵀA&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Edit A and see AᵀA, the σ&apos;s, V, U and the check UΣVᵀ = A.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter11/svd.html?mode=comp&amp;amp;lang=en&quot; title=&quot;Interactive: computing the SVD from AᵀA&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter11/svd.html?mode=comp&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Recompute the SVD of $A = \begin{bmatrix} 3 &amp;amp; 0 \\ 4 &amp;amp; 5 \end{bmatrix}$ (Lesson 11-01) with the algorithm.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A^TA = \begin{bmatrix} 25 &amp;amp; 20 \\ 20 &amp;amp; 25 \end{bmatrix}$, eigenvalues $45, 5$, $v_1 = \tfrac{1}{\sqrt2}(1, 1)$, $v_2 = \tfrac{1}{\sqrt2}(1, -1)$. $\sigma_1 = 3\sqrt5$, $\sigma_2 = \sqrt5$. $u_1 = Av_1/\sigma_1 = \tfrac{1}{\sqrt{10}}(1, 3)$, $u_2 = Av_2/\sigma_2 = \tfrac{1}{\sqrt{10}}(3, -1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Compute the SVD of $A = \begin{bmatrix} 1 &amp;amp; 0 \\ 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A^TA = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$: $\sigma_1 = \sqrt3$, $v_1 = \tfrac{1}{\sqrt2}(1, 1)$, $u_1 = \tfrac{1}{\sqrt6}(1, 2, 1)$; $\sigma_2 = 1$, $v_2 = \tfrac{1}{\sqrt2}(-1, 1)$, $u_2 = \tfrac{1}{\sqrt2}(-1, 0, 1)$; $u_3 = \tfrac{1}{\sqrt3}(1, -1, 1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Compute the SVD of the row vector $A = \begin{bmatrix} 3 &amp;amp; 4 \end{bmatrix}$ ($1 \times 2$).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$AA^T = [25]$, so $\sigma_1 = 5$, $u_1 = 1$, $v_1 = A^Tu_1/\sigma_1 = \tfrac15(3, 4)$; $v_2 = \tfrac15(-4, 3)$. $A = 1\cdot\begin{bmatrix} 5 &amp;amp; 0 \end{bmatrix}V^T$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Prove: $A$ and $A^T$ have the same nonzero singular values.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A^T = V\Sigma^TU^T$ is an SVD of $A^T$ with the same $\sigma_i$ on the diagonal. (Alternatively: $A^TA$ and $AA^T$ have the same nonzero eigenvalues.)

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$A^TA = V\Sigma^T\Sigma V^T$, $AA^T = U\Sigma\Sigma^TU^T$: the $\sigma_i^2$ are eigenvalues, the $v_i$ and $u_i$ eigenvectors.&lt;/li&gt;
    &lt;li&gt;Algorithm: $v_i$, $\sigma_i$ from $A^TA$; $u_i = Av_i/\sigma_i$; complete $U$ with an orthonormal basis of $\operatorname{Null}(A^T)$.&lt;/li&gt;
    &lt;li&gt;Do not compute $U$ and $V$ independently (sign mismatches).&lt;/li&gt;
    &lt;li&gt;$\lVert A \rVert_F^2 = \sum\sigma_i^2$. Computers do not form $A^TA$; they use Householder reflections and QR iteration.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>The Singular Value Decomposition: A Geometric View</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter11/11_01_Phan_Ra_Gia_Tri_Ky_Di_Goc_Nhin_Hinh_Hoc/"/>
   <updated>2026-01-11T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter11/11_01_Phan_Ra_Gia_Tri_Ky_Di_Goc_Nhin_Hinh_Hoc</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;state the singular value decomposition (SVD) $A = U\Sigma V^T$ for any real matrix;&lt;/li&gt;
    &lt;li&gt;explain the SVD as three steps: rotate ($V^T$), stretch along the axes ($\Sigma$), rotate ($U$);&lt;/li&gt;
    &lt;li&gt;read off from the SVD the image of the unit circle, the rank, and the norm $\max_{\lVert x \rVert = 1}\lVert Ax \rVert$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;The matrix $A = \begin{bmatrix} 3 &amp;amp; 0 \\ 4 &amp;amp; 5 \end{bmatrix}$ is not symmetric, so it has no orthonormal eigenbasis. But look at the image of the unit circle: it is an ellipse. An ellipse has two perpendicular axes. Question: which unit vectors on the circle are sent to the ends of the ellipse’s axes?&lt;/p&gt;

&lt;p&gt;Answer: $v_1 = \tfrac{1}{\sqrt2}(1, 1)$ and $v_2 = \tfrac{1}{\sqrt2}(1, -1)$, two &lt;strong&gt;perpendicular&lt;/strong&gt; vectors, are sent to&lt;/p&gt;

\[Av_1 = \tfrac{1}{\sqrt2}(3, 9) = 3\sqrt5\cdot\tfrac{1}{\sqrt{10}}(1, 3), \qquad Av_2 = \tfrac{1}{\sqrt2}(3, -1) = \sqrt5\cdot\tfrac{1}{\sqrt{10}}(3, -1),\]

&lt;p&gt;which are also &lt;strong&gt;perpendicular&lt;/strong&gt;. So $A$ maps one pair of perpendicular directions to another pair of perpendicular directions, stretching by $\sigma_1 = 3\sqrt5 \approx 6.71$ and $\sigma_2 = \sqrt5 \approx 2.24$.&lt;/p&gt;

&lt;h2 id=&quot;statement-of-the-svd&quot;&gt;Statement of the SVD&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (SVD).&lt;/strong&gt; Every real $m \times n$ matrix $A$ of rank $r$ can be written as&lt;/p&gt;

\[A = U\Sigma V^T,\]

  &lt;p&gt;where $U$ ($m \times m$) and $V$ ($n \times n$) are orthogonal and $\Sigma$ ($m \times n$) has entries $\sigma_1 \ge \sigma_2 \ge \dots \ge \sigma_r &amp;gt; 0$ in positions $(i, i)$ and zeros elsewhere. The $\sigma_i$ are the &lt;strong&gt;singular values&lt;/strong&gt;; the columns $v_i$ of $V$ and $u_i$ of $U$ are the &lt;strong&gt;right&lt;/strong&gt; and &lt;strong&gt;left singular vectors&lt;/strong&gt;, and&lt;/p&gt;

  &lt;p&gt;\(Av_i = \sigma_iu_i \quad (i \le r), \qquad Av_i = 0 \quad (i &amp;gt; r).\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The proof (and how to compute it) is in Lesson 11-02: the $v_i$ are eigenvectors of the symmetric matrix $A^TA$, and the $\sigma_i^2$ are its eigenvalues.&lt;/p&gt;

&lt;p&gt;Written column by row, the SVD is a sum of rank-1 matrices:&lt;/p&gt;

\[A = \sigma_1u_1v_1^T + \sigma_2u_2v_2^T + \dots + \sigma_ru_rv_r^T.\]

&lt;h2 id=&quot;three-steps-rotate-stretch-rotate&quot;&gt;Three steps: rotate, stretch, rotate&lt;/h2&gt;

&lt;p&gt;Read $Ax = U(\Sigma(V^Tx))$ from right to left:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;$V^Tx$: &lt;strong&gt;rotate&lt;/strong&gt; (or reflect) so that the directions $v_1, \dots, v_n$ line up with the coordinate axes $e_1, \dots, e_n$.&lt;/li&gt;
  &lt;li&gt;$\Sigma$: &lt;strong&gt;stretch&lt;/strong&gt; along the $i$-th axis by $\sigma_i$ (and delete the axes $i &amp;gt; r$, changing dimension from $n$ to $m$).&lt;/li&gt;
  &lt;li&gt;$U$: &lt;strong&gt;rotate&lt;/strong&gt; the coordinate axes $e_i$ to the directions $u_i$.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So the image of the unit sphere under $A$ is an &lt;strong&gt;ellipse&lt;/strong&gt; (ellipsoid) with semi-axes $\sigma_1u_1, \dots, \sigma_ru_r$. For a rank-1 matrix, the ellipse collapses to a line segment.&lt;/p&gt;

&lt;p&gt;Compare with diagonalization: $A = PDP^{-1}$ uses &lt;strong&gt;one&lt;/strong&gt; basis (usually not orthogonal) for both input and output, and does not always exist. The SVD uses &lt;strong&gt;two&lt;/strong&gt; different orthonormal bases, and always exists, even for rectangular matrices.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (the motivating example).&lt;/strong&gt; For $A = \begin{bmatrix} 3 &amp;amp; 0 \\ 4 &amp;amp; 5 \end{bmatrix}$:&lt;/p&gt;

\[A = \underbrace{\frac{1}{\sqrt{10}}\begin{bmatrix} 1 &amp;amp; 3 \\ 3 &amp;amp; -1 \end{bmatrix}}_{U}\underbrace{\begin{bmatrix} 3\sqrt5 &amp;amp; 0 \\ 0 &amp;amp; \sqrt5 \end{bmatrix}}_{\Sigma}\underbrace{\frac{1}{\sqrt2}\begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix}}_{V^T}.\]

  &lt;p&gt;Check: $\det A = 15 = \sigma_1\sigma_2 \cdot \det U \cdot \det V = 15 \cdot (-1)(-1)$. The image ellipse has long semi-axis $3\sqrt5$ along $(1, 3)$ and short semi-axis $\sqrt5$ along $(3, -1)$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;what-the-svd-tells-you-at-once&quot;&gt;What the SVD tells you at once&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Rank&lt;/strong&gt;: $r$ = the number of nonzero singular values.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Norm&lt;/strong&gt;: $\max_{\lVert x \rVert = 1}\lVert Ax \rVert = \sigma_1$, attained at $x = v_1$ (Exercise 4, Lesson 10-06). The smallest stretch (for a square matrix) is $\sigma_n$.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The four subspaces&lt;/strong&gt;: $u_1, \dots, u_r$ is an orthonormal basis of $\operatorname{Col}(A)$; $v_{r+1}, \dots, v_n$ of $\operatorname{Null}(A)$; likewise $v_1, \dots, v_r$ for $\operatorname{Row}(A)$ and $u_{r+1}, \dots, u_m$ for $\operatorname{Null}(A^T)$.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Determinant&lt;/strong&gt; (square matrices): $\lvert\det A\rvert = \sigma_1\sigma_2\cdots\sigma_n$, the area (volume) of the image ellipse divided by that of the unit circle.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Condition number&lt;/strong&gt;: $\kappa(A) = \sigma_1/\sigma_n$ (Lesson 08-05).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;application-deformation-in-mechanics-and-graphics&quot;&gt;Application: deformation in mechanics and graphics&lt;/h2&gt;

&lt;p&gt;In continuum mechanics, the deformation gradient $F$ at a point tells what a tiny ball of material is turned into. The SVD $F = U\Sigma V^T$ separates the deformation into rotations (which do not change the material) and a stretch along the &lt;strong&gt;principal directions&lt;/strong&gt; by the factors $\sigma_i$; only the stretch creates stress. Soft-body simulators in graphics (cloth, character bodies) compute an SVD per element every frame to do this.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: SVD as rotate, stretch, rotate&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag the step slider to watch Vᵀ, Σ and U turn the circle into an ellipse.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter11/svd.html?mode=geo&amp;amp;t=0&amp;amp;lang=en&quot; title=&quot;Interactive: SVD as rotate, stretch, rotate&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter11/svd.html?mode=geo&amp;amp;t=0&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-svd-from-a-circle-to-an-ellipse-in-three-steps&quot;&gt;Short video: SVD: from a circle to an ellipse in three steps&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/svd-three-steps.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;A = [3 0; 4 5] = U Σ Vᵀ. Step 1: Vᵀ rotates by −45°, bringing v₁, v₂ onto the coordinate axes. Step 2: Σ stretches along the two axes by 3√5 and √5. Step 3: U rotates by about 71.6°, bringing the ellipse axes to the directions u₁, u₂. The semi-axes of the ellipse are the singular values. Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Write the SVD of $\begin{bmatrix} 3 &amp;amp; 0 \\ 0 &amp;amp; -2 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\sigma_1 = 3$, $\sigma_2 = 2$. Take $V = I$, $\Sigma = \operatorname{diag}(3, 2)$, $U = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; -1 \end{bmatrix}$: the minus sign goes into $U$ because singular values are always nonnegative.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Write the SVD of the rank-1 matrix $\begin{bmatrix} 2 &amp;amp; 2 \\ 1 &amp;amp; 1 \end{bmatrix}$ as $\sigma_1u_1v_1^T$. What is the image of the unit circle?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A = (2, 1)(1, 1)^T$, so $\sigma_1 = \lVert(2, 1)\rVert\,\lVert(1, 1)\rVert = \sqrt{10}$, $u_1 = \tfrac{1}{\sqrt5}(2, 1)$, $v_1 = \tfrac{1}{\sqrt2}(1, 1)$, $\sigma_2 = 0$. The image of the circle is the segment from $-\sqrt{10}\,u_1$ to $\sqrt{10}\,u_1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; For a symmetric positive definite $A$, show that the SVD coincides with the orthogonal diagonalization $A = Q\Lambda Q^T$. What if $A$ is symmetric with a negative eigenvalue?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

With $\lambda_i &amp;gt; 0$, take $U = V = Q$, $\Sigma = \Lambda$. If some $\lambda_i &amp;lt; 0$: $\sigma_i = \lvert\lambda_i\rvert$, with $u_i = -q_i$, $v_i = q_i$ (then reorder in decreasing order).

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Prove: for square $A$, $\lvert\det A\rvert = \sigma_1\cdots\sigma_n$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\det A = \det U\det\Sigma\det V^T$ with $\det U, \det V = \pm1$ (orthogonal matrices), so $\lvert\det A\rvert = \det\Sigma = \prod\sigma_i$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Every matrix: $A = U\Sigma V^T = \sum_{i \le r}\sigma_iu_iv_i^T$, with $U, V$ orthogonal and $\sigma_1 \ge \dots \ge \sigma_r &amp;gt; 0$.&lt;/li&gt;
    &lt;li&gt;$Av_i = \sigma_iu_i$: perpendicular directions $v_i$ go to perpendicular directions $u_i$.&lt;/li&gt;
    &lt;li&gt;Geometry: rotate, stretch along axes, rotate; the unit circle becomes an ellipse with semi-axes $\sigma_iu_i$.&lt;/li&gt;
    &lt;li&gt;The SVD gives the rank, the norm $\sigma_1$, $\lvert\det A\rvert$, the condition number, and orthonormal bases of the four subspaces.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Thương Rayleigh và cực trị có ràng buộc</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter10/10_06_Thuong_Rayleigh_Va_Cuc_Tri_Co_Rang_Buoc/"/>
   <updated>2026-01-10T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter10/10_06_Thuong_Rayleigh_Va_Cuc_Tri_Co_Rang_Buoc</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;định nghĩa thương Rayleigh $R(x) = \dfrac{x^TAx}{x^Tx}$ và chứng minh $\lambda_{\min} \le R(x) \le \lambda_{\max}$;&lt;/li&gt;
    &lt;li&gt;tìm cực đại, cực tiểu của $x^TAx$ trên $\lVert x \rVert = 1$ và điểm đạt cực trị;&lt;/li&gt;
    &lt;li&gt;mở rộng cho ràng buộc trực giao: trị riêng thứ hai là cực đại trên phần bù trực giao của vectơ riêng thứ nhất.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Trong các vectơ đơn vị $(x, y)$, vectơ nào làm $q = 5x^2 + 4xy + 2y^2$ lớn nhất? Hình học: trên đường tròn đơn vị, tìm điểm mà mặt $z = q(x, y)$ cao nhất. Bài 10-03 cho biết $q = 6y_1^2 + y_2^2$ trong hệ trục chính. Trên đường tròn đơn vị $y_1^2 + y_2^2 = 1$, nên $q = 1 + 5y_1^2$, lớn nhất bằng $6$ khi $y_1 = \pm1$, tức $x = \pm\tfrac{1}{\sqrt5}(2, 1)$, và nhỏ nhất bằng $1$ tại $\pm\tfrac{1}{\sqrt5}(1, -2)$. Cực trị đúng bằng các trị riêng.&lt;/p&gt;

&lt;h2 id=&quot;thương-rayleigh&quot;&gt;Thương Rayleigh&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa.&lt;/strong&gt; Với $A$ đối xứng và $x \neq 0$, &lt;strong&gt;thương Rayleigh&lt;/strong&gt; là $R(x) = \dfrac{x^TAx}{x^Tx}$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;$R(cx) = R(x)$ với mọi $c \neq 0$, nên chỉ cần xét $x$ đơn vị; khi đó $R(x) = x^TAx$. Nếu $Ax = \lambda x$ thì $R(x) = \lambda$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Rayleigh).&lt;/strong&gt; Cho $A$ đối xứng với trị riêng $\lambda_1 \ge \lambda_2 \ge \dots \ge \lambda_n$ và cơ sở trực chuẩn vectơ riêng $q_1, \dots, q_n$. Khi đó&lt;/p&gt;

\[\lambda_n \le R(x) \le \lambda_1 \quad\text{với mọi } x \neq 0,\]

  &lt;p&gt;$\max_{\lVert x \rVert = 1} x^TAx = \lambda_1$ đạt tại $x = q_1$, và $\min_{\lVert x \rVert = 1} x^TAx = \lambda_n$ đạt tại $x = q_n$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Với $\lVert x \rVert = 1$, đặt $y = Q^Tx$, ta có $\lVert y \rVert = 1$ và $x^TAx = \sum\lambda_iy_i^2$. Vì $\sum y_i^2 = 1$, tổng này là trung bình có trọng số không âm của các $\lambda_i$, nên nằm giữa $\lambda_n$ và $\lambda_1$. Giá trị $\lambda_1$ đạt khi $y = e_1$, tức $x = q_1$; tương tự cho $\lambda_n$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Nhìn từ phương pháp nhân tử Lagrange.&lt;/strong&gt; Cực trị của $x^TAx$ với ràng buộc $x^Tx = 1$ thoả $\nabla(x^TAx) = \mu\nabla(x^Tx)$, tức $2Ax = 2\mu x$: điểm dừng chính là vectơ riêng, và giá trị tại đó là $x^TAx = \mu$. Trị riêng lớn nhất cho cực đại.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2 (Cực trị với ràng buộc trực giao).&lt;/strong&gt; Với các ký hiệu trên,&lt;/p&gt;

\[\lambda_2 = \max\{x^TAx : \lVert x \rVert = 1,\ x \perp q_1\},\]

  &lt;p&gt;đạt tại $x = q_2$. Tổng quát, $\lambda_k$ là cực đại của $x^TAx$ trên các vectơ đơn vị trực giao với $q_1, \dots, q_{k-1}$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Nếu $x \perp q_1$ thì $y_1 = q_1^Tx = 0$, nên $x^TAx = \sum_{i \ge 2}\lambda_iy_i^2 \le \lambda_2$, đạt tại $y = e_2$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Tìm cực đại, cực tiểu của $q = 2(x^2 + y^2 + z^2 + xy + yz + zx)$ trên mặt cầu đơn vị. Ma trận là $A = \begin{bmatrix} 2 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 2 \end{bmatrix}$ với trị riêng $4, 1, 1$ (Bài 10-01). Cực đại $4$ tại $\pm\tfrac{1}{\sqrt3}(1, 1, 1)$; cực tiểu $1$ tại mọi vectơ đơn vị trong mặt phẳng $x + y + z = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-hướng-có-phương-sai-lớn-nhất&quot;&gt;Ứng dụng: hướng có phương sai lớn nhất&lt;/h2&gt;

&lt;p&gt;Cho dữ liệu đã trừ trung bình với ma trận hiệp phương sai $C$. Chiếu mọi điểm lên hướng đơn vị $u$; phương sai của các hình chiếu là $u^TCu$. Hướng giữ được nhiều “thông tin” nhất (phương sai lớn nhất) là nghiệm của bài toán $\max_{\lVert u \rVert = 1} u^TCu$: theo Định lý 1, đó là vectơ riêng ứng với trị riêng lớn nhất của $C$. Theo Định lý 2, hướng tốt thứ hai (trực giao với hướng thứ nhất) là vectơ riêng thứ hai. Đó chính là &lt;strong&gt;thành phần chính&lt;/strong&gt; của PCA (Chương 11).&lt;/p&gt;

&lt;p&gt;Thương Rayleigh còn là công cụ ước lượng trị riêng: nếu $x$ gần một vectơ riêng với sai số $\varepsilon$ thì $R(x)$ gần trị riêng với sai số chỉ cỡ $\varepsilon^2$. Phép lặp luỹ thừa kết hợp thương Rayleigh hội tụ rất nhanh.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: Thương Rayleigh trên đường tròn đơn vị&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo x trên đường tròn, xem R(x) nằm giữa hai trị riêng&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter10/dang_toan_phuong.html?mode=ray&quot; title=&quot;Minh hoạ: Thương Rayleigh trên đường tròn đơn vị&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter10/dang_toan_phuong.html?mode=ray&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Tìm $\max x^TAx$ và $\min x^TAx$ với $\lVert x \rVert = 1$, $A = \begin{bmatrix} 3 &amp;amp; 1 \\ 1 &amp;amp; 3 \end{bmatrix}$, và các điểm đạt cực trị.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Trị riêng $4$ (hướng $(1, 1)$) và $2$ (hướng $(1, -1)$). Cực đại $4$ tại $\pm\tfrac{1}{\sqrt2}(1, 1)$, cực tiểu $2$ tại $\pm\tfrac{1}{\sqrt2}(1, -1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Với $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$, tính $R(x)$ tại $x = (1, 0)$ và $x = (1; 0{,}9)$. So sánh với trị riêng lớn nhất.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$R(1, 0) = 2$. Với $x = (1; 0{,}9)$: $x^TAx = 2 + 1{,}8 + 1{,}62 = 5{,}42$, $x^Tx = 1{,}81$, $R \approx 2{,}9945$. Trị riêng lớn nhất là $3$; $x$ đã gần $(1, 1)$ nên $R$ rất gần $3$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Chứng minh: với $A$ đối xứng, $\lambda_{\max} \ge a_{ii} \ge \lambda_{\min}$ với mọi $i$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$a_{ii} = e_i^TAe_i = R(e_i)$, nằm giữa $\lambda_{\min}$ và $\lambda_{\max}$ theo Định lý 1.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Chứng minh: $\max_{\lVert x \rVert = 1}\lVert Ax \rVert = \sqrt{\lambda_{\max}(A^TA)}$ với mọi ma trận $A$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\lVert Ax \rVert^2 = x^T(A^TA)x$, với $A^TA$ đối xứng nửa xác định dương. Theo Định lý 1, cực đại trên $\lVert x \rVert = 1$ là $\lambda_{\max}(A^TA)$; lấy căn. Số này là giá trị kỳ dị lớn nhất của $A$ (Chương 11).

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Thương Rayleigh $R(x) = x^TAx / x^Tx$ thoả $\lambda_{\min} \le R(x) \le \lambda_{\max}$.&lt;/li&gt;
    &lt;li&gt;Trên mặt cầu đơn vị: cực đại $\lambda_{\max}$ tại vectơ riêng $q_1$, cực tiểu $\lambda_{\min}$ tại $q_n$; điểm dừng (Lagrange) là các vectơ riêng.&lt;/li&gt;
    &lt;li&gt;$\lambda_k$ là cực đại trên các vectơ đơn vị trực giao với $q_1, \dots, q_{k-1}$.&lt;/li&gt;
    &lt;li&gt;Ứng dụng: hướng phương sai lớn nhất (PCA), ước lượng trị riêng.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Tiêu chuẩn Sylvester và phân rã Cholesky</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter10/10_05_Tieu_Chuan_Sylvester_Va_Phan_Ra_Cholesky/"/>
   <updated>2026-01-10T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter10/10_05_Tieu_Chuan_Sylvester_Va_Phan_Ra_Cholesky</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;kiểm tra tính xác định dương bằng tiêu chuẩn Sylvester (các định thức con chính đầu dương);&lt;/li&gt;
    &lt;li&gt;tính phân rã Cholesky $A = LL^T$ của ma trận xác định dương;&lt;/li&gt;
    &lt;li&gt;dùng phân rã Cholesky để giải hệ và sinh mẫu Gauss nhiều chiều với hiệp phương sai cho trước.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Tìm trị riêng của ma trận $3 \times 3$ để kiểm tra xác định dương là tốn công: phải giải phương trình bậc ba. Với&lt;/p&gt;

\[A = \begin{bmatrix} 4 &amp;amp; 2 &amp;amp; 2 \\ 2 &amp;amp; 5 &amp;amp; 3 \\ 2 &amp;amp; 3 &amp;amp; 6 \end{bmatrix},\]

&lt;p&gt;có cách nhanh hơn không? Có: chỉ cần ba định thức nhỏ, hoặc chạy khử Gauss một lần.&lt;/p&gt;

&lt;h2 id=&quot;tiêu-chuẩn-sylvester&quot;&gt;Tiêu chuẩn Sylvester&lt;/h2&gt;

&lt;p&gt;Gọi $A_k$ là ma trận con ở góc trên trái cỡ $k \times k$ của $A$, và $D_k = \det A_k$ là &lt;strong&gt;định thức con chính đầu&lt;/strong&gt; thứ $k$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Sylvester).&lt;/strong&gt; Ma trận đối xứng $A$ cỡ $n \times n$ xác định dương khi và chỉ khi $D_1 &amp;gt; 0, D_2 &amp;gt; 0, \dots, D_n &amp;gt; 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Phác thảo chứng minh.&lt;/strong&gt; Chiều “chỉ nếu”: với $x = (x_1, \dots, x_k, 0, \dots, 0)$, $x^TAx$ chính là dạng toàn phương của $A_k$, nên $A_k$ xác định dương, và $D_k$ là tích các trị riêng dương của $A_k$.&lt;/p&gt;

  &lt;p&gt;Chiều “nếu”: khi mọi $D_k &amp;gt; 0$, khử Gauss không cần đổi hàng và các phần tử trụ là $d_1 = D_1$, $d_k = D_k/D_{k-1} &amp;gt; 0$ (vì phép khử không đổi các định thức con chính đầu). Khi đó $A = LDL^T$ với $L$ tam giác dưới có đường chéo bằng $1$ và $D = \operatorname{diag}(d_k)$, nên $x^TAx = \sum d_k(L^Tx)_k^2 &amp;gt; 0$ khi $x \neq 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Với $A$ của ví dụ mở đầu: $D_1 = 4$, $D_2 = 4 \cdot 5 - 2 \cdot 2 = 16$, $D_3 = \det A = 64$. Cả ba dương, nên $A$ xác định dương.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Cảnh báo.&lt;/strong&gt; Tiêu chuẩn tương tự &lt;strong&gt;không&lt;/strong&gt; đúng cho nửa xác định: $\begin{bmatrix} 0 &amp;amp; 0 \\ 0 &amp;amp; -1 \end{bmatrix}$ có $D_1 = D_2 = 0$ nhưng không nửa xác định dương. Với nửa xác định, phải xét mọi định thức con chính (không chỉ các con đầu). Với xác định âm: $A$ xác định âm $\iff$ $(-1)^kD_k &amp;gt; 0$ với mọi $k$.&lt;/p&gt;

&lt;h2 id=&quot;phân-rã-cholesky&quot;&gt;Phân rã Cholesky&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2 (Cholesky).&lt;/strong&gt; Ma trận đối xứng $A$ xác định dương khi và chỉ khi $A = LL^T$ với $L$ tam giác dưới có đường chéo dương. Khi đó $L$ là duy nhất.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Từ chứng minh định lý Sylvester: $A = LDL^T = (LD^{1/2})(LD^{1/2})^T$. Trong thực hành, tính trực tiếp từng cột của $L$ bằng cách so sánh phần tử của $A = LL^T$:&lt;/p&gt;

\[\ell_{jj} = \sqrt{a_{jj} - \textstyle\sum_{k &amp;lt; j}\ell_{jk}^2}, \qquad \ell_{ij} = \frac{1}{\ell_{jj}}\Big(a_{ij} - \textstyle\sum_{k &amp;lt; j}\ell_{ik}\ell_{jk}\Big)\quad (i &amp;gt; j).\]

&lt;p&gt;Nếu một lúc nào đó biểu thức dưới căn không dương, ma trận không xác định dương: thuật toán Cholesky đồng thời là phép &lt;strong&gt;kiểm tra&lt;/strong&gt; xác định dương rẻ nhất trên máy tính.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; Với $A$ của ví dụ mở đầu:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;cột 1: $\ell_{11} = \sqrt4 = 2$, $\ell_{21} = 2/2 = 1$, $\ell_{31} = 2/2 = 1$;&lt;/li&gt;
    &lt;li&gt;cột 2: $\ell_{22} = \sqrt{5 - 1} = 2$, $\ell_{32} = (3 - 1 \cdot 1)/2 = 1$;&lt;/li&gt;
    &lt;li&gt;cột 3: $\ell_{33} = \sqrt{6 - 1 - 1} = 2$.&lt;/li&gt;
  &lt;/ul&gt;

\[L = \begin{bmatrix} 2 &amp;amp; 0 &amp;amp; 0 \\ 1 &amp;amp; 2 &amp;amp; 0 \\ 1 &amp;amp; 1 &amp;amp; 2 \end{bmatrix}, \qquad LL^T = \begin{bmatrix} 4 &amp;amp; 2 &amp;amp; 2 \\ 2 &amp;amp; 5 &amp;amp; 3 \\ 2 &amp;amp; 3 &amp;amp; 6 \end{bmatrix}.\]

  &lt;p&gt;Để ý $D_3 = (\det L)^2 = 8^2 = 64$, khớp với Ví dụ 1.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Giải $Ax = b$: giải $Ly = b$ (thế tiến) rồi $L^Tx = y$ (thế lùi). Chi phí khoảng $n^3/3$ phép tính, bằng một nửa phân rã LU, và ổn định số mà không cần đổi hàng.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-sinh-mẫu-gauss-nhiều-chiều&quot;&gt;Ứng dụng: sinh mẫu Gauss nhiều chiều&lt;/h2&gt;

&lt;p&gt;Muốn sinh vectơ ngẫu nhiên $x \in \mathbb{R}^n$ có phân phối chuẩn với trung bình $\mu$ và hiệp phương sai $\Sigma$ (xác định dương) cho trước. Máy tính dễ dàng sinh $z$ gồm $n$ số chuẩn tắc độc lập, $\operatorname{Cov}(z) = I$. Với $\Sigma = LL^T$, đặt&lt;/p&gt;

\[x = \mu + Lz, \qquad \operatorname{Cov}(x) = L\operatorname{Cov}(z)L^T = LL^T = \Sigma.\]

&lt;p&gt;Đây là cách &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.random.multivariate_normal&lt;/code&gt; và các thư viện mô phỏng Monte Carlo (tài chính, quá trình Gauss) hoạt động.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;Sigma&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;4.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;2.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;2.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;2.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;5.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;3.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;2.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;3.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;6.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;cholesky&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Sigma&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;          &lt;span class=&quot;c1&quot;&gt;# tam giác dưới
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;default_rng&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;standard_normal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100_000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;cov&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;              &lt;span class=&quot;c1&quot;&gt;# xấp xỉ Sigma
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: Tiêu chuẩn Sylvester và Cholesky&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kiểm tra định thức con chính và tính L với A = LLᵀ&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter10/dang_toan_phuong.html?mode=sylv&quot; title=&quot;Minh hoạ: Tiêu chuẩn Sylvester và Cholesky&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter10/dang_toan_phuong.html?mode=sylv&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Dùng tiêu chuẩn Sylvester kiểm tra $\begin{bmatrix} 2 &amp;amp; -1 &amp;amp; 0 \\ -1 &amp;amp; 2 &amp;amp; -1 \\ 0 &amp;amp; -1 &amp;amp; 2 \end{bmatrix}$ xác định dương.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$D_1 = 2$, $D_2 = 3$, $D_3 = 2 \cdot 3 - (-1)(-2) = 4$. Cả ba dương, nên xác định dương.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Ma trận $\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 \\ 2 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$ có xác định dương không?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$D_1 = 1 &amp;gt; 0$ nhưng $D_2 = 1 - 4 = -3 &amp;lt; 0$: không xác định dương (thực ra không xác định, vì trị riêng là $3, -1, 1$).

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Tính phân rã Cholesky của $\begin{bmatrix} 4 &amp;amp; 2 \\ 2 &amp;amp; 5 \end{bmatrix}$ và dùng nó giải $Ax = (2, 7)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$L = \begin{bmatrix} 2 &amp;amp; 0 \\ 1 &amp;amp; 2 \end{bmatrix}$. $Ly = (2, 7)$ cho $y = (1, 3)$; $L^Tx = y$ cho $x_2 = \tfrac32$, $x_1 = \tfrac{1 - 3/2}{2} = -\tfrac14$. Kiểm tra: $4(-\tfrac14) + 2 \cdot \tfrac32 = 2$, $2(-\tfrac14) + 5 \cdot \tfrac32 = 7$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Tìm mọi $a$ để $\begin{bmatrix} a &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; a &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; a \end{bmatrix}$ xác định dương.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$D_1 = a &amp;gt; 0$, $D_2 = a^2 - 1 &amp;gt; 0$, $D_3 = (a - 1)^2(a + 2) &amp;gt; 0$. Kết hợp: $a &amp;gt; 1$. (Cách khác: trị riêng $a + 2$, $a - 1$, $a - 1$.)

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (lập trình).&lt;/strong&gt; Sinh $10^5$ mẫu Gauss 2 chiều với $\mu = (1, -1)$, $\Sigma = \begin{bmatrix} 4 &amp;amp; 2 \\ 2 &amp;amp; 5 \end{bmatrix}$ và kiểm tra trung bình, hiệp phương sai mẫu.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Với $L$ của Bài tập 3: `x = mu[:, None] + L @ z`, `z` là mảng chuẩn tắc cỡ $2 \times 10^5$. `x.mean(axis=1)` xấp xỉ $(1, -1)$ và `np.cov(x)` xấp xỉ $\Sigma$ (sai số cỡ $0{,}02$).

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Sylvester: $A$ đối xứng xác định dương $\iff$ mọi định thức con chính đầu $D_k &amp;gt; 0$; không áp dụng trực tiếp cho nửa xác định.&lt;/li&gt;
    &lt;li&gt;Cholesky: $A$ xác định dương $\iff A = LL^T$, $L$ tam giác dưới có đường chéo dương.&lt;/li&gt;
    &lt;li&gt;Thuật toán Cholesky vừa phân rã vừa kiểm tra xác định dương; giải hệ với chi phí bằng nửa LU.&lt;/li&gt;
    &lt;li&gt;Sinh mẫu Gauss: $x = \mu + Lz$ có hiệp phương sai $LL^T = \Sigma$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Ma trận xác định dương</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter10/10_04_Ma_Tran_Xac_Dinh_Duong/"/>
   <updated>2026-01-10T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter10/10_04_Ma_Tran_Xac_Dinh_Duong</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;định nghĩa ma trận (dạng toàn phương) xác định dương, nửa xác định dương, xác định âm, không xác định;&lt;/li&gt;
    &lt;li&gt;kiểm tra tính xác định dương bằng trị riêng;&lt;/li&gt;
    &lt;li&gt;chứng minh $A^TA$ luôn nửa xác định dương, và xác định dương khi các cột của $A$ độc lập.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Hàm $f(x, y) = 2x^2 - 2xy + 2y^2$ có điểm dừng tại $(0, 0)$. Đó là cực tiểu, cực đại hay điểm yên ngựa? Với một biến, ta xét dấu của $f&apos;&apos;$. Với nhiều biến, câu hỏi trở thành: dạng toàn phương $x^TAx$ có &lt;strong&gt;luôn dương&lt;/strong&gt; khi $x \neq 0$ không? Ở đây $A = \begin{bmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{bmatrix}$.&lt;/p&gt;

&lt;h2 id=&quot;định-nghĩa&quot;&gt;Định nghĩa&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa.&lt;/strong&gt; Ma trận đối xứng $A$ (hoặc dạng toàn phương $q(x) = x^TAx$) là&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;&lt;strong&gt;xác định dương&lt;/strong&gt; nếu $x^TAx &amp;gt; 0$ với mọi $x \neq 0$;&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;nửa xác định dương&lt;/strong&gt; nếu $x^TAx \ge 0$ với mọi $x$;&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;xác định âm&lt;/strong&gt; (tương ứng &lt;strong&gt;nửa xác định âm&lt;/strong&gt;) nếu $-A$ xác định dương (tương ứng nửa xác định dương);&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;không xác định&lt;/strong&gt; nếu $x^TAx$ nhận cả giá trị dương lẫn âm.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;h2 id=&quot;kiểm-tra-bằng-trị-riêng&quot;&gt;Kiểm tra bằng trị riêng&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Ma trận đối xứng $A$ xác định dương khi và chỉ khi mọi trị riêng của $A$ dương; nửa xác định dương khi và chỉ khi mọi trị riêng không âm; không xác định khi và chỉ khi có trị riêng dương và trị riêng âm.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Theo định lý trục chính (Bài 10-03), với $y = Q^Tx$: $x^TAx = \sum\lambda_iy_i^2$, và $x \neq 0 \iff y \neq 0$. Nếu mọi $\lambda_i &amp;gt; 0$ thì tổng dương khi $y \neq 0$. Ngược lại, chọn $x = q_i$ (tức $y = e_i$) được $q_i^TAq_i = \lambda_i$, nên $A$ xác định dương buộc $\lambda_i &amp;gt; 0$. Các trường hợp còn lại tương tự.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (ví dụ mở đầu).&lt;/strong&gt; $A = \begin{bmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{bmatrix}$ có trị riêng $1$ và $3$: xác định dương, nên $(0, 0)$ là cực tiểu chặt của $f$. Cách khác, bằng phương pháp bù bình phương: $2x^2 - 2xy + 2y^2 = 2\big(x - \tfrac{y}{2}\big)^2 + \tfrac32y^2 &amp;gt; 0$ khi $(x, y) \neq 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; $\begin{bmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 1 \end{bmatrix}$ có trị riêng $3$ và $-1$: không xác định (chẳng hạn $q(1, -1) = -2 &amp;lt; 0 &amp;lt; q(1, 1) = 6$). $\begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$ có trị riêng $2$ và $0$: nửa xác định dương, vì $q = (x + y)^2 \ge 0$ nhưng $q(1, -1) = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Với ma trận $2 \times 2$, dùng $\operatorname{tr} A = \lambda_1 + \lambda_2$ và $\det A = \lambda_1\lambda_2$: $A$ xác định dương khi và chỉ khi $\det A &amp;gt; 0$ và $a_{11} &amp;gt; 0$ (hai điều kiện này buộc cả hai trị riêng cùng dấu và tổng dương, vì $\operatorname{tr}A &amp;gt; 0$ khi $a_{11} &amp;gt; 0$ và $a_{11}a_{22} &amp;gt; b^2 \ge 0$).&lt;/p&gt;

&lt;h2 id=&quot;ma-trận-gram-ata&quot;&gt;Ma trận Gram $A^TA$&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2.&lt;/strong&gt; Với mọi ma trận $A$ cỡ $m \times n$, $A^TA$ là nửa xác định dương. Nó xác định dương khi và chỉ khi các cột của $A$ độc lập tuyến tính.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; $x^TA^TAx = (Ax)^T(Ax) = \lVert Ax \rVert^2 \ge 0$. Đẳng thức xảy ra khi và chỉ khi $Ax = 0$. Nếu các cột độc lập, $Ax = 0$ chỉ khi $x = 0$, nên $A^TA$ xác định dương; ngược lại, một $x \neq 0$ với $Ax = 0$ cho $x^TA^TAx = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Định lý này giải thích tại sao phương trình chuẩn $A^TA\hat x = A^Tb$ (Bài 08-02) có nghiệm duy nhất khi các cột của $A$ độc lập: $A^TA$ xác định dương nên khả nghịch. Ngược lại, mọi ma trận xác định dương đều có dạng $R^TR$ (Bài 10-05, phân rã Cholesky).&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-kiểm-tra-cực-trị-bằng-hessian&quot;&gt;Ứng dụng: kiểm tra cực trị bằng Hessian&lt;/h2&gt;

&lt;p&gt;Tại điểm dừng $x^\ast$ ($\nabla f(x^\ast) = 0$) của hàm trơn $f$, gọi $H$ là ma trận Hessian:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;$H$ xác định dương $\Rightarrow$ cực tiểu chặt; $H$ xác định âm $\Rightarrow$ cực đại chặt;&lt;/li&gt;
  &lt;li&gt;$H$ không xác định $\Rightarrow$ điểm yên ngựa;&lt;/li&gt;
  &lt;li&gt;$H$ chỉ nửa xác định: chưa kết luận được.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Trong tối ưu, một hàm có Hessian xác định dương ở mọi nơi là &lt;strong&gt;lồi chặt&lt;/strong&gt;, và có tối đa một cực tiểu; đây là nền tảng của khoá Tối ưu (Chương 02–03). Trong xác suất, ma trận hiệp phương sai $\operatorname{Cov}(X) = \mathbb{E}[(X - \mu)(X - \mu)^T]$ luôn nửa xác định dương, vì $v^T\operatorname{Cov}(X)v = \operatorname{Var}(v^TX) \ge 0$.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: Phân loại dạng toàn phương&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Bát, yên ngựa hay máng: xem dấu của trị riêng và mặt 3D&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter10/dang_toan_phuong.html?mode=def&amp;amp;preset=saddle&quot; title=&quot;Minh hoạ: Phân loại dạng toàn phương&quot; loading=&quot;lazy&quot; style=&quot;height: 900px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter10/dang_toan_phuong.html?mode=def&amp;amp;preset=saddle&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Xét dấu dạng toàn phương $q = 2x^2 + 2xy + 2y^2$ bằng hai cách: trị riêng và bù bình phương.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$, trị riêng $3$ và $1$: xác định dương. Bù bình phương: $q = 2\big(x + \tfrac{y}{2}\big)^2 + \tfrac32y^2 &amp;gt; 0$ khi $(x, y) \neq 0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Với giá trị nào của $k$ thì $\begin{bmatrix} 1 &amp;amp; k \\ k &amp;amp; 4 \end{bmatrix}$ xác định dương?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$a_{11} = 1 &amp;gt; 0$ và $\det = 4 - k^2 &amp;gt; 0$, tức $\lvert k \rvert &amp;lt; 2$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Chứng minh: nếu $A$ xác định dương thì $A$ khả nghịch và $A^{-1}$ cũng xác định dương.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Mọi trị riêng $\lambda_i &amp;gt; 0$, nên $\det A = \prod\lambda_i &amp;gt; 0$ và $A$ khả nghịch. $A^{-1}$ đối xứng với trị riêng $1/\lambda_i &amp;gt; 0$, nên xác định dương.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Phân loại điểm dừng $(0, 0)$ của $f(x, y) = x^2 + 6xy + y^2$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$f = x^TAx$ với $A = \begin{bmatrix} 1 &amp;amp; 3 \\ 3 &amp;amp; 1 \end{bmatrix}$, trị riêng $4$ và $-2$: không xác định, $(0, 0)$ là điểm yên ngựa.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5.&lt;/strong&gt; Chứng minh: nếu $A$ và $B$ xác định dương thì $A + B$ cũng vậy. Tích $AB$ có nhất thiết đối xứng không?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$x^T(A + B)x = x^TAx + x^TBx &amp;gt; 0$ khi $x \neq 0$. $AB$ không nhất thiết đối xứng: với $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$, $B = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{bmatrix}$, $AB = \begin{bmatrix} 2 &amp;amp; 2 \\ 1 &amp;amp; 2 \end{bmatrix}$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Xác định dương: $x^TAx &amp;gt; 0$ với mọi $x \neq 0$ $\iff$ mọi trị riêng dương.&lt;/li&gt;
    &lt;li&gt;Nửa xác định dương: mọi trị riêng $\ge 0$; không xác định: có trị riêng trái dấu.&lt;/li&gt;
    &lt;li&gt;$2 \times 2$: xác định dương $\iff a_{11} &amp;gt; 0$ và $\det A &amp;gt; 0$.&lt;/li&gt;
    &lt;li&gt;$A^TA$ nửa xác định dương, xác định dương khi các cột của $A$ độc lập.&lt;/li&gt;
    &lt;li&gt;Hessian xác định dương tại điểm dừng $\Rightarrow$ cực tiểu chặt.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Dạng toàn phương và đường mức</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter10/10_03_Dang_Toan_Phuong_Va_Duong_Muc/"/>
   <updated>2026-01-10T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter10/10_03_Dang_Toan_Phuong_Va_Duong_Muc</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;viết một dạng toàn phương dưới dạng $q(x) = x^TAx$ với $A$ đối xứng;&lt;/li&gt;
    &lt;li&gt;dùng phép đổi biến $x = Qy$ (định lý trục chính) để đưa $q$ về dạng chính tắc $\sum\lambda_iy_i^2$;&lt;/li&gt;
    &lt;li&gt;nhận biết đường mức $q(x) = 1$ là elip, hyperbol hay suy biến, và tìm trục, nửa trục của nó.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Đường cong $5x^2 + 4xy + 2y^2 = 1$ là gì? Không có số hạng $xy$ thì dễ: $5x^2 + 2y^2 = 1$ là elip có trục nằm trên các trục toạ độ. Số hạng chéo $4xy$ làm elip bị &lt;strong&gt;xoay&lt;/strong&gt;. Bài này chỉ ra rằng các trục của elip là vectơ riêng của một ma trận đối xứng, và chiều dài nửa trục đọc được từ trị riêng.&lt;/p&gt;

&lt;h2 id=&quot;dạng-toàn-phương&quot;&gt;Dạng toàn phương&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa.&lt;/strong&gt; Một &lt;strong&gt;dạng toàn phương&lt;/strong&gt; trên $\mathbb{R}^n$ là hàm $q(x) = x^TAx = \sum_{i,j}a_{ij}x_ix_j$, với $A$ là ma trận đối xứng $n \times n$ (gọi là ma trận của $q$).&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Với $n = 2$: $q(x, y) = ax^2 + 2bxy + cy^2$ ứng với $A = \begin{bmatrix} a &amp;amp; b \\ b &amp;amp; c \end{bmatrix}$. Chú ý hệ số của $xy$ được &lt;strong&gt;chia đôi&lt;/strong&gt; cho hai vị trí ngoài đường chéo. Ví dụ mở đầu: $5x^2 + 4xy + 2y^2$ có $A = \begin{bmatrix} 5 &amp;amp; 2 \\ 2 &amp;amp; 2 \end{bmatrix}$.&lt;/p&gt;

&lt;p&gt;Mọi ma trận vuông $M$ cho một dạng toàn phương $x^TMx$, nhưng $x^TMx = x^T\tfrac{M + M^T}{2}x$, nên luôn có thể giả sử ma trận đối xứng; khi đó nó là duy nhất.&lt;/p&gt;

&lt;h2 id=&quot;định-lý-trục-chính&quot;&gt;Định lý trục chính&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Trục chính).&lt;/strong&gt; Cho $A = Q\Lambda Q^T$ là chéo hoá trực giao của $A$ đối xứng. Với phép đổi biến $x = Qy$ (tức $y = Q^Tx$),&lt;/p&gt;

\[q(x) = x^TAx = y^T\Lambda y = \lambda_1y_1^2 + \dots + \lambda_ny_n^2.\]

  &lt;p&gt;Các cột $q_1, \dots, q_n$ của $Q$ gọi là các &lt;strong&gt;trục chính&lt;/strong&gt; của $q$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; $x^TAx = (Qy)^TQ\Lambda Q^T(Qy) = y^T(Q^TQ)\Lambda(Q^TQ)y = y^T\Lambda y$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Vì $Q$ trực giao, $y = Q^Tx$ chỉ là một phép &lt;strong&gt;xoay&lt;/strong&gt; (có thể kèm phản xạ) của hệ trục: hình dạng đường mức không đổi, chỉ là ta nhìn nó trong hệ trục mới.&lt;/p&gt;

&lt;h2 id=&quot;nhận-biết-đường-mức-với-n--2&quot;&gt;Nhận biết đường mức với $n = 2$&lt;/h2&gt;

&lt;p&gt;Trong toạ độ $y$, đường mức $q = 1$ là $\lambda_1y_1^2 + \lambda_2y_2^2 = 1$:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;$\lambda_1, \lambda_2 &amp;gt; 0$: &lt;strong&gt;elip&lt;/strong&gt; với nửa trục $1/\sqrt{\lambda_1}$ theo hướng $q_1$ và $1/\sqrt{\lambda_2}$ theo hướng $q_2$. Trị riêng lớn ứng với trục ngắn.&lt;/li&gt;
  &lt;li&gt;$\lambda_1 &amp;gt; 0 &amp;gt; \lambda_2$: &lt;strong&gt;hyperbol&lt;/strong&gt;, cắt trục $q_1$ tại $\pm 1/\sqrt{\lambda_1}$.&lt;/li&gt;
  &lt;li&gt;$\lambda_1 &amp;gt; 0 = \lambda_2$: &lt;strong&gt;cặp đường thẳng song song&lt;/strong&gt; $y_1 = \pm1/\sqrt{\lambda_1}$.&lt;/li&gt;
  &lt;li&gt;$\lambda_1, \lambda_2 \le 0$: tập rỗng.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (ví dụ mở đầu).&lt;/strong&gt; $A = \begin{bmatrix} 5 &amp;amp; 2 \\ 2 &amp;amp; 2 \end{bmatrix}$ có $\lambda_1 = 6$ với $q_1 = \tfrac{1}{\sqrt5}(2, 1)$ và $\lambda_2 = 1$ với $q_2 = \tfrac{1}{\sqrt5}(1, -2)$ (Bài tập 1, Bài 10-01). Vậy $5x^2 + 4xy + 2y^2 = 6y_1^2 + y_2^2$, và đường $q = 1$ là elip với nửa trục ngắn $1/\sqrt6 \approx 0{,}41$ theo hướng $(2, 1)$, nửa trục dài $1$ theo hướng $(1, -2)$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; $x^2 + 4xy - 2y^2 = 1$: $A = \begin{bmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; -2 \end{bmatrix}$ có trị riêng $2$ (hướng $(2, 1)$) và $-3$ (hướng $(1, -2)$) (Ví dụ 1, Bài 10-01). Dạng chính tắc $2y_1^2 - 3y_2^2 = 1$: hyperbol, đỉnh tại $y_1 = \pm 1/\sqrt2$ trên trục $(2, 1)$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Bức tranh 3D: mặt $z = q(x)$ là một cái &lt;strong&gt;bát&lt;/strong&gt; (paraboloid elliptic) khi hai trị riêng dương, và một &lt;strong&gt;yên ngựa&lt;/strong&gt; (paraboloid hyperbolic) khi chúng trái dấu. Đường mức là các lát cắt ngang của mặt này.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-xấp-xỉ-bậc-hai-và-hàm-mất-mát&quot;&gt;Ứng dụng: xấp xỉ bậc hai và hàm mất mát&lt;/h2&gt;

&lt;p&gt;Gần điểm cực tiểu $x^\ast$ của hàm trơn $f$, khai triển Taylor bậc hai cho $f(x) \approx f(x^\ast) + \tfrac12(x - x^\ast)^TH(x - x^\ast)$, với $H$ là ma trận Hessian (đối xứng). Vì vậy đường mức của hàm mất mát gần cực tiểu là các elip, trục chính là vectơ riêng của $H$. Khi $\lambda_{\max}/\lambda_{\min}$ lớn, elip rất dẹt, và gradient descent đi zig-zag dọc thung lũng hẹp; đây là lý do các phương pháp tiền điều kiện và Adam cố “làm tròn” các elip này.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: Dạng toàn phương và đường mức&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo a, b, c để xem đường mức và trục chính&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter10/dang_toan_phuong.html?mode=level&quot; title=&quot;Minh hoạ: Dạng toàn phương và đường mức&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter10/dang_toan_phuong.html?mode=level&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-elip-hyperbol-và-hướng-chính-của-dạng-toàn-phương&quot;&gt;Video ngắn: Elip, hyperbol và hướng chính của dạng toàn phương&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/quadratic-form-ellipse.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;5x² + 2y² = 1 là elip trên các trục; thêm 4xy làm elip xoay nghiêng. Trục của elip là vectơ riêng của A = [5 2; 2 2]: trị riêng 6 (hướng (2; 1), nửa trục 1/√6) và 1 (hướng (1; −2), nửa trục 1). Xoay hệ trục: q = 6y₁² + y₂². Đổi dấu một trị riêng thì elip thành hyperbol. Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Viết ma trận của $q(x_1, x_2, x_3) = x_1^2 + 3x_2^2 - x_3^2 + 4x_1x_2 - 6x_2x_3$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 \\ 2 &amp;amp; 3 &amp;amp; -3 \\ 0 &amp;amp; -3 &amp;amp; -1 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Nhận biết và tìm trục chính, nửa trục của $3x^2 + 2xy + 3y^2 = 1$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A = \begin{bmatrix} 3 &amp;amp; 1 \\ 1 &amp;amp; 3 \end{bmatrix}$, trị riêng $4$ (hướng $(1, 1)$) và $2$ (hướng $(1, -1)$). Dạng chính tắc $4y_1^2 + 2y_2^2 = 1$: elip, nửa trục $\tfrac12$ theo $(1, 1)$ và $\tfrac{1}{\sqrt2}$ theo $(1, -1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Nhận biết đường $xy = 1$ bằng định lý trục chính.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A = \begin{bmatrix} 0 &amp;amp; 1/2 \\ 1/2 &amp;amp; 0 \end{bmatrix}$, trị riêng $\tfrac12$ (hướng $(1, 1)$) và $-\tfrac12$ (hướng $(1, -1)$). Dạng chính tắc $\tfrac12y_1^2 - \tfrac12y_2^2 = 1$: hyperbol vuông, đỉnh tại $y_1 = \pm\sqrt2$ trên đường $y = x$, tức các điểm $(1, 1)$ và $(-1, -1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Đường $x^2 + 2xy + y^2 = 1$ là gì?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$ có trị riêng $2$ và $0$. Thực ra $q = (x + y)^2$, nên đường mức là cặp đường thẳng song song $x + y = \pm 1$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$q(x) = x^TAx$ với $A$ đối xứng; hệ số của $x_ix_j$ ($i \neq j$) chia đôi vào $a_{ij}$ và $a_{ji}$.&lt;/li&gt;
    &lt;li&gt;Định lý trục chính: $x = Qy$ biến $q$ thành $\sum\lambda_iy_i^2$; trục chính là vectơ riêng.&lt;/li&gt;
    &lt;li&gt;$q = 1$: elip (hai trị riêng dương, nửa trục $1/\sqrt{\lambda_i}$), hyperbol (trái dấu), suy biến (có trị riêng $0$).&lt;/li&gt;
    &lt;li&gt;Gần cực tiểu, hàm mất mát có đường mức là elip theo Hessian.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Chéo hoá trực giao</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter10/10_02_Cheo_Hoa_Truc_Giao/"/>
   <updated>2026-01-10T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter10/10_02_Cheo_Hoa_Truc_Giao</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;chéo hoá trực giao ma trận đối xứng: $A = Q\Lambda Q^T$;&lt;/li&gt;
    &lt;li&gt;viết phân tích phổ $A = \sum\lambda_iq_iq_i^T$ thành tổng các phép chiếu;&lt;/li&gt;
    &lt;li&gt;tính $A^k$, $A^{-1}$ và $\sqrt{A}$ của ma trận đối xứng.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Chéo hoá thông thường $A = PDP^{-1}$ (Bài 09-04) đòi hỏi tính $P^{-1}$. Với ma trận đối xứng, định lý phổ (Bài 10-01) cho phép chọn $P = Q$ có các cột trực chuẩn, khi đó $Q^{-1} = Q^T$: nghịch đảo đến “miễn phí”.&lt;/p&gt;

&lt;p&gt;Với $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$, $q_1 = \tfrac{1}{\sqrt2}(1, 1)$ (trị riêng $3$), $q_2 = \tfrac{1}{\sqrt2}(1, -1)$ (trị riêng $1$):&lt;/p&gt;

\[A = \underbrace{\frac{1}{\sqrt2}\begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix}}_{Q}\begin{bmatrix} 3 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix}\underbrace{\frac{1}{\sqrt2}\begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix}}_{Q^T}.\]

&lt;h2 id=&quot;chéo-hoá-trực-giao-và-phân-tích-phổ&quot;&gt;Chéo hoá trực giao và phân tích phổ&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa.&lt;/strong&gt; Ma trận $A$ &lt;strong&gt;chéo hoá trực giao được&lt;/strong&gt; nếu $A = Q\Lambda Q^T$ với $Q$ trực giao ($Q^TQ = I$) và $\Lambda$ chéo.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Theo định lý phổ, $A$ chéo hoá trực giao được khi và chỉ khi $A$ đối xứng. Quy trình:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Tìm các trị riêng (thực) của $A$.&lt;/li&gt;
  &lt;li&gt;Với mỗi trị riêng, tìm cơ sở của không gian riêng rồi trực chuẩn hoá bằng Gram–Schmidt.&lt;/li&gt;
  &lt;li&gt;Ghép các vectơ đơn vị thành cột của $Q$, trị riêng tương ứng thành đường chéo của $\Lambda$.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Nhân ra $Q\Lambda Q^T$ theo cột–hàng:&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Phân tích phổ).&lt;/strong&gt; Nếu $A$ đối xứng với cơ sở trực chuẩn vectơ riêng $q_1, \dots, q_n$ và trị riêng $\lambda_1, \dots, \lambda_n$ thì&lt;/p&gt;

\[A = \lambda_1q_1q_1^T + \lambda_2q_2q_2^T + \dots + \lambda_nq_nq_n^T.\]

  &lt;p&gt;Mỗi $q_iq_i^T$ là phép chiếu vuông góc lên đường thẳng $\operatorname{span}(q_i)$ (Bài 07-04).&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Diễn giải hình học: để tính $Ax$, chiếu $x$ lên từng trục chính, kéo dãn mỗi thành phần với hệ số $\lambda_i$, rồi cộng lại.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Với $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$: $q_1q_1^T = \tfrac12\begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$, $q_2q_2^T = \tfrac12\begin{bmatrix} 1 &amp;amp; -1 \\ -1 &amp;amp; 1 \end{bmatrix}$, và $3q_1q_1^T + 1\cdot q_2q_2^T = \tfrac12\begin{bmatrix} 4 &amp;amp; 2 \\ 2 &amp;amp; 4 \end{bmatrix} = A$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;hàm-của-ma-trận-đối-xứng&quot;&gt;Hàm của ma trận đối xứng&lt;/h2&gt;

&lt;p&gt;Vì $q_iq_i^T$ là các phép chiếu trực giao lẫn nhau ($q_i^Tq_j = 0$ khi $i \neq j$), ta có $A^k = \sum\lambda_i^kq_iq_i^T$. Tổng quát, với hàm $f$ xác định trên các trị riêng, định nghĩa&lt;/p&gt;

\[f(A) = Q\,f(\Lambda)\,Q^T = \sum f(\lambda_i)\,q_iq_i^T.\]

&lt;ul&gt;
  &lt;li&gt;$A^{-1} = \sum\lambda_i^{-1}q_iq_i^T$ khi mọi $\lambda_i \neq 0$.&lt;/li&gt;
  &lt;li&gt;$\sqrt{A} = \sum\sqrt{\lambda_i}\,q_iq_i^T$ khi mọi $\lambda_i \ge 0$; đây là ma trận đối xứng duy nhất có trị riêng không âm và bình phương bằng $A$.&lt;/li&gt;
  &lt;li&gt;$e^{tA} = \sum e^{t\lambda_i}q_iq_i^T$ (Bài 09-07).&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; Với $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$:&lt;/p&gt;

\[A^k = \frac{3^k}{2}\begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix} + \frac12\begin{bmatrix} 1 &amp;amp; -1 \\ -1 &amp;amp; 1 \end{bmatrix}, \qquad \sqrt{A} = \frac12\begin{bmatrix} \sqrt3 + 1 &amp;amp; \sqrt3 - 1 \\ \sqrt3 - 1 &amp;amp; \sqrt3 + 1 \end{bmatrix}.\]

  &lt;p&gt;Kiểm tra: phần tử $(1,1)$ của $(\sqrt A)^2$ là $\tfrac14\big[(\sqrt3 + 1)^2 + (\sqrt3 - 1)^2\big] = \tfrac14 \cdot 8 = 2$, phần tử $(1,2)$ là $\tfrac14 \cdot 2(\sqrt3 + 1)(\sqrt3 - 1) = 1$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-làm-trắng-dữ-liệu&quot;&gt;Ứng dụng: làm trắng dữ liệu&lt;/h2&gt;

&lt;p&gt;Trong học máy, dữ liệu có ma trận hiệp phương sai $C$ (đối xứng, trị riêng dương) thường được &lt;strong&gt;làm trắng&lt;/strong&gt; (whitening) trước khi huấn luyện: thay mỗi điểm $x$ bằng $C^{-1/2}x$, với $C^{-1/2} = \sum\lambda_i^{-1/2}q_iq_i^T$. Dữ liệu mới có hiệp phương sai $C^{-1/2}CC^{-1/2} = I$: các đặc trưng không còn tương quan và có cùng phương sai. Hình học: xoay về trục chính, co mỗi trục theo độ lệch chuẩn, rồi xoay lại.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: chéo hoá trực giao A = QΛQᵀ&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Với A đối xứng, P là phép quay (trực giao): quay về trục chính, kéo dãn theo Λ, quay lại.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter09/tri_rieng.html?mode=diag&amp;amp;preset=sym&quot; title=&quot;Minh hoạ: chéo hoá trực giao A = QΛQᵀ&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter09/tri_rieng.html?mode=diag&amp;amp;preset=sym&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Chéo hoá trực giao $A = \begin{bmatrix} 5 &amp;amp; 2 \\ 2 &amp;amp; 2 \end{bmatrix}$ và viết phân tích phổ.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\lambda = 6$ với $q_1 = \tfrac{1}{\sqrt5}(2, 1)$, $\lambda = 1$ với $q_2 = \tfrac{1}{\sqrt5}(1, -2)$. $Q = \tfrac{1}{\sqrt5}\begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; -2 \end{bmatrix}$, $\Lambda = \operatorname{diag}(6, 1)$, $A = \tfrac65\begin{bmatrix} 4 &amp;amp; 2 \\ 2 &amp;amp; 1 \end{bmatrix} + \tfrac15\begin{bmatrix} 1 &amp;amp; -2 \\ -2 &amp;amp; 4 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Dùng phân tích phổ tính $A^{-1}$ với $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A^{-1} = \tfrac13 q_1q_1^T + q_2q_2^T = \tfrac16\begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix} + \tfrac12\begin{bmatrix} 1 &amp;amp; -1 \\ -1 &amp;amp; 1 \end{bmatrix} = \tfrac13\begin{bmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Chéo hoá trực giao $A = \begin{bmatrix} 2 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 2 \end{bmatrix}$ (Ví dụ 2, Bài 10-01) và tính $A^k$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Với $P_1 = \tfrac13\mathbf{1}\mathbf{1}^T$ (chiếu lên $\mathbf{1}$) và $P_2 = I - P_1$ (chiếu lên mặt phẳng): $A = 4P_1 + P_2$, nên $A^k = 4^kP_1 + P_2 = I + \tfrac{4^k - 1}{3}\mathbf{1}\mathbf{1}^T$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Chứng minh: nếu $A$ đối xứng và $A^2 = A$ thì $A$ là phép chiếu vuông góc lên $\operatorname{Col}(A)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Trị riêng thoả $\lambda^2 = \lambda$, nên $\lambda \in \{0, 1\}$. Phân tích phổ cho $A = \sum_{\lambda_i = 1}q_iq_i^T$, là phép chiếu vuông góc lên không gian sinh bởi các $q_i$ ứng với $1$, chính là $\operatorname{Col}(A)$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Ma trận đối xứng: $A = Q\Lambda Q^T$, $Q^{-1} = Q^T$.&lt;/li&gt;
    &lt;li&gt;Phân tích phổ: $A = \sum\lambda_iq_iq_i^T$, tổng các phép chiếu lên trục chính có trọng số.&lt;/li&gt;
    &lt;li&gt;$f(A) = Qf(\Lambda)Q^T$: $A^k$, $A^{-1}$, $\sqrt A$, $e^{tA}$.&lt;/li&gt;
    &lt;li&gt;Ứng dụng: làm trắng dữ liệu bằng $C^{-1/2}$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Định lý phổ cho ma trận đối xứng thực</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter10/10_01_Dinh_Ly_Pho_Cho_Ma_Tran_Doi_Xung_Thuc/"/>
   <updated>2026-01-10T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter10/10_01_Dinh_Ly_Pho_Cho_Ma_Tran_Doi_Xung_Thuc</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;chứng minh trị riêng của ma trận đối xứng thực là số thực;&lt;/li&gt;
    &lt;li&gt;chứng minh vectơ riêng ứng với hai trị riêng khác nhau của ma trận đối xứng thì trực giao;&lt;/li&gt;
    &lt;li&gt;phát biểu định lý phổ và tìm cơ sở trực chuẩn gồm vectơ riêng của ma trận đối xứng $2 \times 2$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Trong Chương 09, ma trận quay $\begin{bmatrix} 0 &amp;amp; -1 \\ 1 &amp;amp; 0 \end{bmatrix}$ không có trị riêng thực, và $\begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \end{bmatrix}$ không chéo hoá được. Còn ma trận $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$ thì sao? Trị riêng là $3$ với $(1, 1)$ và $1$ với $(1, -1)$. Hai vectơ riêng không chỉ độc lập mà còn &lt;strong&gt;vuông góc&lt;/strong&gt;: $(1, 1) \cdot (1, -1) = 0$.&lt;/p&gt;

&lt;p&gt;Điều đó xảy ra với mọi ma trận đối xứng ($A^T = A$). Ma trận đối xứng xuất hiện khắp nơi: ma trận hiệp phương sai, Hessian, ma trận độ cứng, $A^TA$ trong bình phương tối thiểu.&lt;/p&gt;

&lt;h2 id=&quot;trị-riêng-thực-vectơ-riêng-trực-giao&quot;&gt;Trị riêng thực, vectơ riêng trực giao&lt;/h2&gt;

&lt;p&gt;Một tính chất then chốt: với $A$ đối xứng và mọi $x, y$,&lt;/p&gt;

\[(Ax) \cdot y = x^TA^Ty = x^TAy = x \cdot (Ay).\]

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Cho $A$ là ma trận đối xứng thực.&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;Mọi trị riêng của $A$ (kể cả nghiệm phức của đa thức đặc trưng) là số thực.&lt;/li&gt;
    &lt;li&gt;Nếu $Au = \lambda u$, $Av = \mu v$ với $\lambda \neq \mu$ thì $u \cdot v = 0$.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; (1) Giả sử $Av = \lambda v$ với $v \in \mathbb{C}^n$, $v \neq 0$. Ký hiệu $\bar v$ là liên hợp phức. Vì $A$ thực, $A\bar v = \bar\lambda\bar v$. Tính $\bar v^TAv$ theo hai cách: $\bar v^T(Av) = \lambda\,\bar v^Tv$ và $(A\bar v)^Tv = \bar\lambda\,\bar v^Tv$ (dùng $A^T = A$). Vì $\bar v^Tv = \sum\lvert v_i\rvert^2 &amp;gt; 0$, suy ra $\lambda = \bar\lambda$, tức $\lambda$ thực.&lt;/p&gt;

  &lt;p&gt;(2) $\lambda(u \cdot v) = (Au) \cdot v = u \cdot (Av) = \mu(u \cdot v)$, nên $(\lambda - \mu)(u \cdot v) = 0$, và vì $\lambda \neq \mu$ ta có $u \cdot v = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;định-lý-phổ&quot;&gt;Định lý phổ&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2 (Định lý phổ).&lt;/strong&gt; Ma trận thực $A$ cỡ $n \times n$ là đối xứng khi và chỉ khi $\mathbb{R}^n$ có một cơ sở trực chuẩn gồm các vectơ riêng của $A$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Phác thảo chứng minh.&lt;/strong&gt; Chiều “nếu”: nếu $Q$ trực giao có các cột là vectơ riêng thì $A = Q\Lambda Q^T$ và $A^T = Q\Lambda^TQ^T = A$.&lt;/p&gt;

  &lt;p&gt;Chiều “chỉ nếu”, quy nạp theo $n$. Theo Định lý 1, $A$ có một trị riêng thực $\lambda_1$ với vectơ riêng đơn vị $q_1$. Gọi $W = q_1^{\perp}$. Với $w \in W$: $(Aw) \cdot q_1 = w \cdot (Aq_1) = \lambda_1(w \cdot q_1) = 0$, nên $A$ biến $W$ vào $W$. Hạn chế của $A$ lên $W$ (có số chiều $n - 1$) vẫn “đối xứng” theo nghĩa $(Ax) \cdot y = x \cdot (Ay)$, nên theo giả thiết quy nạp $W$ có cơ sở trực chuẩn $q_2, \dots, q_n$ gồm vectơ riêng. Thêm $q_1$ được cơ sở cần tìm.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Điểm đáng chú ý: ma trận đối xứng &lt;strong&gt;luôn&lt;/strong&gt; chéo hoá được, kể cả khi có trị riêng lặp. Khi trị riêng $\lambda$ có bội $m$, không gian riêng của nó có đúng số chiều $m$; ta chọn trong đó một cơ sở trực chuẩn bằng Gram–Schmidt (Bài 07-05).&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; $A = \begin{bmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; -2 \end{bmatrix}$. Đa thức đặc trưng $\lambda^2 + \lambda - 6 = (\lambda - 2)(\lambda + 3)$. Với $\lambda = 2$: $A - 2I = \begin{bmatrix} -1 &amp;amp; 2 \\ 2 &amp;amp; -4 \end{bmatrix}$, vectơ riêng $(2, 1)$. Với $\lambda = -3$: $A + 3I = \begin{bmatrix} 4 &amp;amp; 2 \\ 2 &amp;amp; 1 \end{bmatrix}$, vectơ riêng $(1, -2)$. Kiểm tra $(2, 1) \cdot (1, -2) = 0$. Cơ sở trực chuẩn: $q_1 = \tfrac{1}{\sqrt5}(2, 1)$, $q_2 = \tfrac{1}{\sqrt5}(1, -2)$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (trị riêng lặp).&lt;/strong&gt; $A = \begin{bmatrix} 2 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 2 \end{bmatrix} = I + \mathbf{1}\mathbf{1}^T$. Ta có $A\mathbf{1} = 4\cdot\mathbf{1}$ và $Av = v$ với mọi $v \perp \mathbf{1}$. Vậy trị riêng là $4$ (bội 1) và $1$ (bội 2), không gian riêng của $1$ là mặt phẳng $x_1 + x_2 + x_3 = 0$. Chọn trong đó cơ sở trực chuẩn, chẳng hạn $\tfrac{1}{\sqrt2}(1, -1, 0)$ và $\tfrac{1}{\sqrt6}(1, 1, -2)$, cùng với $\tfrac{1}{\sqrt3}(1, 1, 1)$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-trục-chính-của-một-đám-mây-điểm&quot;&gt;Ứng dụng: trục chính của một đám mây điểm&lt;/h2&gt;

&lt;p&gt;Ma trận hiệp phương sai $C$ của một tập dữ liệu là đối xứng. Theo định lý phổ, $C$ có các hướng riêng vuông góc với nhau; đó là các &lt;strong&gt;trục chính&lt;/strong&gt; của đám mây điểm, và trị riêng là phương sai của dữ liệu dọc theo từng trục. Đây là nền tảng của PCA (Chương 11). Trong cơ học, ma trận quán tính của một vật rắn cũng đối xứng; các hướng riêng của nó là các trục quay “cân bằng” của vật.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: vectơ riêng của ma trận đối xứng vuông góc&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Sửa A sao cho a₁₂ = a₂₁: hai hướng riêng luôn vuông góc, trị riêng luôn thực.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter09/tri_rieng.html?mode=eig&amp;amp;preset=sym&quot; title=&quot;Minh hoạ: vectơ riêng của ma trận đối xứng vuông góc&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter09/tri_rieng.html?mode=eig&amp;amp;preset=sym&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Tìm cơ sở trực chuẩn gồm vectơ riêng của $A = \begin{bmatrix} 5 &amp;amp; 2 \\ 2 &amp;amp; 2 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\lambda^2 - 7\lambda + 6 = 0$, $\lambda = 6, 1$. Với $6$: $(2, 1)$; với $1$: $(1, -2)$. Cơ sở $\tfrac{1}{\sqrt5}(2, 1)$, $\tfrac{1}{\sqrt5}(1, -2)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Chứng minh mọi trị riêng của ma trận $2 \times 2$ đối xứng $\begin{bmatrix} a &amp;amp; b \\ b &amp;amp; c \end{bmatrix}$ là thực bằng cách xét biệt thức.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Đa thức đặc trưng $\lambda^2 - (a + c)\lambda + (ac - b^2)$ có biệt thức $(a + c)^2 - 4(ac - b^2) = (a - c)^2 + 4b^2 \ge 0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Ma trận $\begin{bmatrix} 1 &amp;amp; 2 \\ 0 &amp;amp; 3 \end{bmatrix}$ có hai vectơ riêng trực giao không? Điều này có mâu thuẫn với Định lý 1 không?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Vectơ riêng $(1, 0)$ (ứng với $1$) và $(1, 1)$ (ứng với $3$), không trực giao. Không mâu thuẫn: ma trận không đối xứng.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Cho $A$ đối xứng có trị riêng $\lambda_1, \dots, \lambda_n$. Chứng minh $\operatorname{tr}(A^2) = \sum \lambda_i^2 = \sum_{i,j} a_{ij}^2$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A^2$ có trị riêng $\lambda_i^2$, nên $\operatorname{tr}(A^2) = \sum\lambda_i^2$. Mặt khác $(A^2)_{ii} = \sum_j a_{ij}a_{ji} = \sum_j a_{ij}^2$ (vì $A$ đối xứng), cộng theo $i$ được $\sum_{i,j}a_{ij}^2$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Ma trận đối xứng thực: $(Ax) \cdot y = x \cdot (Ay)$.&lt;/li&gt;
    &lt;li&gt;Trị riêng luôn thực; vectơ riêng ứng với trị riêng khác nhau trực giao.&lt;/li&gt;
    &lt;li&gt;Định lý phổ: $A$ đối xứng $\iff$ có cơ sở trực chuẩn gồm vectơ riêng; ma trận đối xứng luôn chéo hoá được.&lt;/li&gt;
    &lt;li&gt;Ứng dụng: trục chính của dữ liệu (hiệp phương sai), trục quán tính.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>The Rayleigh Quotient and Constrained Extrema</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter10/10_06_Thuong_Rayleigh_Va_Cuc_Tri_Co_Rang_Buoc/"/>
   <updated>2026-01-10T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter10/10_06_Thuong_Rayleigh_Va_Cuc_Tri_Co_Rang_Buoc</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;define the Rayleigh quotient $R(x) = \dfrac{x^TAx}{x^Tx}$ and prove $\lambda_{\min} \le R(x) \le \lambda_{\max}$;&lt;/li&gt;
    &lt;li&gt;find the maximum and minimum of $x^TAx$ on $\lVert x \rVert = 1$ and where they are attained;&lt;/li&gt;
    &lt;li&gt;extend this to orthogonality constraints: the second eigenvalue is the maximum on the orthogonal complement of the first eigenvector.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Among unit vectors $(x, y)$, which one makes $q = 5x^2 + 4xy + 2y^2$ largest? Geometrically: on the unit circle, find where the surface $z = q(x, y)$ is highest. Lesson 10-03 showed that $q = 6y_1^2 + y_2^2$ in the principal axes. On the unit circle $y_1^2 + y_2^2 = 1$, so $q = 1 + 5y_1^2$, which is largest ($6$) when $y_1 = \pm1$, i.e. $x = \pm\tfrac{1}{\sqrt5}(2, 1)$, and smallest ($1$) at $\pm\tfrac{1}{\sqrt5}(1, -2)$. The extreme values are exactly the eigenvalues.&lt;/p&gt;

&lt;h2 id=&quot;the-rayleigh-quotient&quot;&gt;The Rayleigh quotient&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition.&lt;/strong&gt; For symmetric $A$ and $x \neq 0$, the &lt;strong&gt;Rayleigh quotient&lt;/strong&gt; is $R(x) = \dfrac{x^TAx}{x^Tx}$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;$R(cx) = R(x)$ for every $c \neq 0$, so it suffices to consider unit $x$, for which $R(x) = x^TAx$. If $Ax = \lambda x$ then $R(x) = \lambda$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Rayleigh).&lt;/strong&gt; Let $A$ be symmetric with eigenvalues $\lambda_1 \ge \lambda_2 \ge \dots \ge \lambda_n$ and an orthonormal eigenbasis $q_1, \dots, q_n$. Then&lt;/p&gt;

\[\lambda_n \le R(x) \le \lambda_1 \quad\text{for all } x \neq 0,\]

  &lt;p&gt;$\max_{\lVert x \rVert = 1} x^TAx = \lambda_1$ is attained at $x = q_1$, and $\min_{\lVert x \rVert = 1} x^TAx = \lambda_n$ is attained at $x = q_n$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; For $\lVert x \rVert = 1$, let $y = Q^Tx$; then $\lVert y \rVert = 1$ and $x^TAx = \sum\lambda_iy_i^2$. Since $\sum y_i^2 = 1$, this is a weighted average of the $\lambda_i$ with nonnegative weights, so it lies between $\lambda_n$ and $\lambda_1$. The value $\lambda_1$ is attained at $y = e_1$, i.e. $x = q_1$; similarly for $\lambda_n$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;The Lagrange multiplier view.&lt;/strong&gt; Extrema of $x^TAx$ subject to $x^Tx = 1$ satisfy $\nabla(x^TAx) = \mu\nabla(x^Tx)$, i.e. $2Ax = 2\mu x$: the critical points are exactly the eigenvectors, and the value there is $x^TAx = \mu$. The largest eigenvalue gives the maximum.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2 (Extrema with orthogonality constraints).&lt;/strong&gt; With the notation above,&lt;/p&gt;

\[\lambda_2 = \max\{x^TAx : \lVert x \rVert = 1,\ x \perp q_1\},\]

  &lt;p&gt;attained at $x = q_2$. More generally, $\lambda_k$ is the maximum of $x^TAx$ over unit vectors orthogonal to $q_1, \dots, q_{k-1}$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; If $x \perp q_1$ then $y_1 = q_1^Tx = 0$, so $x^TAx = \sum_{i \ge 2}\lambda_iy_i^2 \le \lambda_2$, attained at $y = e_2$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; Find the maximum and minimum of $q = 2(x^2 + y^2 + z^2 + xy + yz + zx)$ on the unit sphere. Its matrix is $A = \begin{bmatrix} 2 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 2 \end{bmatrix}$ with eigenvalues $4, 1, 1$ (Lesson 10-01). The maximum $4$ is attained at $\pm\tfrac{1}{\sqrt3}(1, 1, 1)$; the minimum $1$ at every unit vector in the plane $x + y + z = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-the-direction-of-largest-variance&quot;&gt;Application: the direction of largest variance&lt;/h2&gt;

&lt;p&gt;Take mean-centered data with covariance matrix $C$. Project every point onto a unit direction $u$; the variance of the projections is $u^TCu$. The direction that keeps the most “information” (largest variance) solves $\max_{\lVert u \rVert = 1} u^TCu$: by Theorem 1, it is the eigenvector of $C$ with the largest eigenvalue. By Theorem 2, the second-best direction (orthogonal to the first) is the second eigenvector. These are the &lt;strong&gt;principal components&lt;/strong&gt; of PCA (Chapter 11).&lt;/p&gt;

&lt;p&gt;The Rayleigh quotient is also a tool for estimating eigenvalues: if $x$ is within $\varepsilon$ of an eigenvector, $R(x)$ is within about $\varepsilon^2$ of the eigenvalue. Power iteration combined with the Rayleigh quotient converges very fast.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: Rayleigh quotient on the unit circle&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag x on the circle and watch R(x) stay between the eigenvalues.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter10/dang_toan_phuong.html?mode=ray&amp;amp;lang=en&quot; title=&quot;Interactive: Rayleigh quotient on the unit circle&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter10/dang_toan_phuong.html?mode=ray&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Find $\max x^TAx$ and $\min x^TAx$ over $\lVert x \rVert = 1$ for $A = \begin{bmatrix} 3 &amp;amp; 1 \\ 1 &amp;amp; 3 \end{bmatrix}$, and where they are attained.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Eigenvalues $4$ (direction $(1, 1)$) and $2$ (direction $(1, -1)$). Maximum $4$ at $\pm\tfrac{1}{\sqrt2}(1, 1)$, minimum $2$ at $\pm\tfrac{1}{\sqrt2}(1, -1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; For $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$, compute $R(x)$ at $x = (1, 0)$ and $x = (1, 0.9)$. Compare with the largest eigenvalue.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$R(1, 0) = 2$. For $x = (1, 0.9)$: $x^TAx = 2 + 1.8 + 1.62 = 5.42$, $x^Tx = 1.81$, $R \approx 2.9945$. The largest eigenvalue is $3$; $x$ is already close to $(1, 1)$, so $R$ is very close to $3$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Prove: for symmetric $A$, $\lambda_{\max} \ge a_{ii} \ge \lambda_{\min}$ for every $i$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$a_{ii} = e_i^TAe_i = R(e_i)$, which lies between $\lambda_{\min}$ and $\lambda_{\max}$ by Theorem 1.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Prove: $\max_{\lVert x \rVert = 1}\lVert Ax \rVert = \sqrt{\lambda_{\max}(A^TA)}$ for every matrix $A$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\lVert Ax \rVert^2 = x^T(A^TA)x$, with $A^TA$ symmetric positive semidefinite. By Theorem 1, the maximum over $\lVert x \rVert = 1$ is $\lambda_{\max}(A^TA)$; take the square root. This number is the largest singular value of $A$ (Chapter 11).

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;The Rayleigh quotient $R(x) = x^TAx / x^Tx$ satisfies $\lambda_{\min} \le R(x) \le \lambda_{\max}$.&lt;/li&gt;
    &lt;li&gt;On the unit sphere: maximum $\lambda_{\max}$ at the eigenvector $q_1$, minimum $\lambda_{\min}$ at $q_n$; the (Lagrange) critical points are the eigenvectors.&lt;/li&gt;
    &lt;li&gt;$\lambda_k$ is the maximum over unit vectors orthogonal to $q_1, \dots, q_{k-1}$.&lt;/li&gt;
    &lt;li&gt;Applications: the direction of largest variance (PCA), eigenvalue estimation.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Sylvester's Criterion and the Cholesky Factorization</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter10/10_05_Tieu_Chuan_Sylvester_Va_Phan_Ra_Cholesky/"/>
   <updated>2026-01-10T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter10/10_05_Tieu_Chuan_Sylvester_Va_Phan_Ra_Cholesky</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;test positive definiteness with Sylvester’s criterion (positive leading principal minors);&lt;/li&gt;
    &lt;li&gt;compute the Cholesky factorization $A = LL^T$ of a positive definite matrix;&lt;/li&gt;
    &lt;li&gt;use the Cholesky factorization to solve systems and to sample multivariate Gaussians with a given covariance.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Finding the eigenvalues of a $3 \times 3$ matrix to test positive definiteness is laborious: it means solving a cubic. For&lt;/p&gt;

\[A = \begin{bmatrix} 4 &amp;amp; 2 &amp;amp; 2 \\ 2 &amp;amp; 5 &amp;amp; 3 \\ 2 &amp;amp; 3 &amp;amp; 6 \end{bmatrix},\]

&lt;p&gt;is there a faster way? Yes: three small determinants, or a single pass of Gaussian elimination.&lt;/p&gt;

&lt;h2 id=&quot;sylvesters-criterion&quot;&gt;Sylvester’s criterion&lt;/h2&gt;

&lt;p&gt;Let $A_k$ be the upper-left $k \times k$ submatrix of $A$, and $D_k = \det A_k$ its $k$-th &lt;strong&gt;leading principal minor&lt;/strong&gt;.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Sylvester).&lt;/strong&gt; A symmetric $n \times n$ matrix $A$ is positive definite if and only if $D_1 &amp;gt; 0, D_2 &amp;gt; 0, \dots, D_n &amp;gt; 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof sketch.&lt;/strong&gt; “Only if”: for $x = (x_1, \dots, x_k, 0, \dots, 0)$, $x^TAx$ is exactly the quadratic form of $A_k$, so $A_k$ is positive definite and $D_k$ is the product of its positive eigenvalues.&lt;/p&gt;

  &lt;p&gt;“If”: when every $D_k &amp;gt; 0$, Gaussian elimination needs no row swaps and the pivots are $d_1 = D_1$, $d_k = D_k/D_{k-1} &amp;gt; 0$ (elimination does not change the leading principal minors). Then $A = LDL^T$ with $L$ unit lower triangular and $D = \operatorname{diag}(d_k)$, so $x^TAx = \sum d_k(L^Tx)_k^2 &amp;gt; 0$ for $x \neq 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; For $A$ in the motivating example: $D_1 = 4$, $D_2 = 4 \cdot 5 - 2 \cdot 2 = 16$, $D_3 = \det A = 64$. All three are positive, so $A$ is positive definite.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Warning.&lt;/strong&gt; The analogous test does &lt;strong&gt;not&lt;/strong&gt; work for semidefiniteness: $\begin{bmatrix} 0 &amp;amp; 0 \\ 0 &amp;amp; -1 \end{bmatrix}$ has $D_1 = D_2 = 0$ but is not positive semidefinite. For semidefiniteness you must check all principal minors (not just the leading ones). For negative definiteness: $A$ is negative definite $\iff$ $(-1)^kD_k &amp;gt; 0$ for every $k$.&lt;/p&gt;

&lt;h2 id=&quot;the-cholesky-factorization&quot;&gt;The Cholesky factorization&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2 (Cholesky).&lt;/strong&gt; A symmetric matrix $A$ is positive definite if and only if $A = LL^T$ with $L$ lower triangular with positive diagonal. This $L$ is unique.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;From the proof of Sylvester’s criterion: $A = LDL^T = (LD^{1/2})(LD^{1/2})^T$. In practice, compute $L$ column by column by matching entries of $A = LL^T$:&lt;/p&gt;

\[\ell_{jj} = \sqrt{a_{jj} - \textstyle\sum_{k &amp;lt; j}\ell_{jk}^2}, \qquad \ell_{ij} = \frac{1}{\ell_{jj}}\Big(a_{ij} - \textstyle\sum_{k &amp;lt; j}\ell_{ik}\ell_{jk}\Big)\quad (i &amp;gt; j).\]

&lt;p&gt;If at some step the quantity under the square root is not positive, the matrix is not positive definite: the Cholesky algorithm is also the cheapest positive-definiteness &lt;strong&gt;test&lt;/strong&gt; on a computer.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; For $A$ in the motivating example:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;column 1: $\ell_{11} = \sqrt4 = 2$, $\ell_{21} = 2/2 = 1$, $\ell_{31} = 2/2 = 1$;&lt;/li&gt;
    &lt;li&gt;column 2: $\ell_{22} = \sqrt{5 - 1} = 2$, $\ell_{32} = (3 - 1 \cdot 1)/2 = 1$;&lt;/li&gt;
    &lt;li&gt;column 3: $\ell_{33} = \sqrt{6 - 1 - 1} = 2$.&lt;/li&gt;
  &lt;/ul&gt;

\[L = \begin{bmatrix} 2 &amp;amp; 0 &amp;amp; 0 \\ 1 &amp;amp; 2 &amp;amp; 0 \\ 1 &amp;amp; 1 &amp;amp; 2 \end{bmatrix}, \qquad LL^T = \begin{bmatrix} 4 &amp;amp; 2 &amp;amp; 2 \\ 2 &amp;amp; 5 &amp;amp; 3 \\ 2 &amp;amp; 3 &amp;amp; 6 \end{bmatrix}.\]

  &lt;p&gt;Note that $D_3 = (\det L)^2 = 8^2 = 64$, matching Example 1.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;To solve $Ax = b$: solve $Ly = b$ (forward substitution), then $L^Tx = y$ (back substitution). The cost is about $n^3/3$ operations, half that of LU, and it is numerically stable without row swaps.&lt;/p&gt;

&lt;h2 id=&quot;application-sampling-multivariate-gaussians&quot;&gt;Application: sampling multivariate Gaussians&lt;/h2&gt;

&lt;p&gt;Suppose we want random vectors $x \in \mathbb{R}^n$ that are normally distributed with a given mean $\mu$ and (positive definite) covariance $\Sigma$. A computer easily generates $z$ made of $n$ independent standard normals, with $\operatorname{Cov}(z) = I$. With $\Sigma = LL^T$, set&lt;/p&gt;

\[x = \mu + Lz, \qquad \operatorname{Cov}(x) = L\operatorname{Cov}(z)L^T = LL^T = \Sigma.\]

&lt;p&gt;This is how &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.random.multivariate_normal&lt;/code&gt; and Monte Carlo simulation libraries (finance, Gaussian processes) work.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;Sigma&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;4.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;2.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;2.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;2.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;5.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;3.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;2.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;3.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;6.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;cholesky&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Sigma&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;          &lt;span class=&quot;c1&quot;&gt;# lower triangular
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;default_rng&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;standard_normal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100_000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;cov&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;              &lt;span class=&quot;c1&quot;&gt;# approximately Sigma
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: Sylvester criterion and Cholesky&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Check leading minors and compute L with A = LLᵀ.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter10/dang_toan_phuong.html?mode=sylv&amp;amp;lang=en&quot; title=&quot;Interactive: Sylvester criterion and Cholesky&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter10/dang_toan_phuong.html?mode=sylv&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Use Sylvester’s criterion to check that $\begin{bmatrix} 2 &amp;amp; -1 &amp;amp; 0 \\ -1 &amp;amp; 2 &amp;amp; -1 \\ 0 &amp;amp; -1 &amp;amp; 2 \end{bmatrix}$ is positive definite.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$D_1 = 2$, $D_2 = 3$, $D_3 = 2 \cdot 3 - (-1)(-2) = 4$. All positive, so it is positive definite.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Is $\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 \\ 2 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$ positive definite?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$D_1 = 1 &amp;gt; 0$ but $D_2 = 1 - 4 = -3 &amp;lt; 0$: not positive definite (in fact indefinite, with eigenvalues $3, -1, 1$).

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Compute the Cholesky factorization of $\begin{bmatrix} 4 &amp;amp; 2 \\ 2 &amp;amp; 5 \end{bmatrix}$ and use it to solve $Ax = (2, 7)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$L = \begin{bmatrix} 2 &amp;amp; 0 \\ 1 &amp;amp; 2 \end{bmatrix}$. $Ly = (2, 7)$ gives $y = (1, 3)$; $L^Tx = y$ gives $x_2 = \tfrac32$, $x_1 = \tfrac{1 - 3/2}{2} = -\tfrac14$. Check: $4(-\tfrac14) + 2 \cdot \tfrac32 = 2$, $2(-\tfrac14) + 5 \cdot \tfrac32 = 7$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Find all $a$ for which $\begin{bmatrix} a &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; a &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; a \end{bmatrix}$ is positive definite.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$D_1 = a &amp;gt; 0$, $D_2 = a^2 - 1 &amp;gt; 0$, $D_3 = (a - 1)^2(a + 2) &amp;gt; 0$. Together: $a &amp;gt; 1$. (Alternatively: the eigenvalues are $a + 2$, $a - 1$, $a - 1$.)

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (programming).&lt;/strong&gt; Generate $10^5$ two-dimensional Gaussian samples with $\mu = (1, -1)$, $\Sigma = \begin{bmatrix} 4 &amp;amp; 2 \\ 2 &amp;amp; 5 \end{bmatrix}$ and check the sample mean and covariance.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

With $L$ from Exercise 3: `x = mu[:, None] + L @ z`, where `z` is a $2 \times 10^5$ array of standard normals. `x.mean(axis=1)` is close to $(1, -1)$ and `np.cov(x)` is close to $\Sigma$ (errors of about $0.02$).

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Sylvester: symmetric $A$ is positive definite $\iff$ every leading principal minor $D_k &amp;gt; 0$; this does not directly extend to semidefiniteness.&lt;/li&gt;
    &lt;li&gt;Cholesky: $A$ is positive definite $\iff A = LL^T$ with $L$ lower triangular with positive diagonal.&lt;/li&gt;
    &lt;li&gt;The Cholesky algorithm both factors and tests positive definiteness; it solves systems at half the cost of LU.&lt;/li&gt;
    &lt;li&gt;Gaussian sampling: $x = \mu + Lz$ has covariance $LL^T = \Sigma$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Positive Definite Matrices</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter10/10_04_Ma_Tran_Xac_Dinh_Duong/"/>
   <updated>2026-01-10T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter10/10_04_Ma_Tran_Xac_Dinh_Duong</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;define positive definite, positive semidefinite, negative definite and indefinite matrices (quadratic forms);&lt;/li&gt;
    &lt;li&gt;test positive definiteness with eigenvalues;&lt;/li&gt;
    &lt;li&gt;prove that $A^TA$ is always positive semidefinite, and positive definite when the columns of $A$ are independent.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;The function $f(x, y) = 2x^2 - 2xy + 2y^2$ has a critical point at $(0, 0)$. Is it a minimum, a maximum or a saddle point? In one variable we look at the sign of $f&apos;&apos;$. In several variables the question becomes: is the quadratic form $x^TAx$ &lt;strong&gt;always positive&lt;/strong&gt; for $x \neq 0$? Here $A = \begin{bmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{bmatrix}$.&lt;/p&gt;

&lt;h2 id=&quot;definitions&quot;&gt;Definitions&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition.&lt;/strong&gt; A symmetric matrix $A$ (or the quadratic form $q(x) = x^TAx$) is&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;&lt;strong&gt;positive definite&lt;/strong&gt; if $x^TAx &amp;gt; 0$ for all $x \neq 0$;&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;positive semidefinite&lt;/strong&gt; if $x^TAx \ge 0$ for all $x$;&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;negative definite&lt;/strong&gt; (resp. &lt;strong&gt;negative semidefinite&lt;/strong&gt;) if $-A$ is positive definite (resp. positive semidefinite);&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;indefinite&lt;/strong&gt; if $x^TAx$ takes both positive and negative values.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;h2 id=&quot;the-eigenvalue-test&quot;&gt;The eigenvalue test&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; A symmetric matrix $A$ is positive definite if and only if all its eigenvalues are positive; positive semidefinite if and only if all its eigenvalues are nonnegative; indefinite if and only if it has both a positive and a negative eigenvalue.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; By the principal axes theorem (Lesson 10-03), with $y = Q^Tx$: $x^TAx = \sum\lambda_iy_i^2$, and $x \neq 0 \iff y \neq 0$. If every $\lambda_i &amp;gt; 0$, the sum is positive for $y \neq 0$. Conversely, taking $x = q_i$ (i.e. $y = e_i$) gives $q_i^TAq_i = \lambda_i$, so positive definiteness forces $\lambda_i &amp;gt; 0$. The other cases are similar.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (the motivating example).&lt;/strong&gt; $A = \begin{bmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{bmatrix}$ has eigenvalues $1$ and $3$: positive definite, so $(0, 0)$ is a strict minimum of $f$. Alternatively, by completing the square: $2x^2 - 2xy + 2y^2 = 2\big(x - \tfrac{y}{2}\big)^2 + \tfrac32y^2 &amp;gt; 0$ for $(x, y) \neq 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; $\begin{bmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 1 \end{bmatrix}$ has eigenvalues $3$ and $-1$: indefinite (for instance $q(1, -1) = -2 &amp;lt; 0 &amp;lt; q(1, 1) = 6$). $\begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$ has eigenvalues $2$ and $0$: positive semidefinite, since $q = (x + y)^2 \ge 0$ but $q(1, -1) = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;For $2 \times 2$ matrices, use $\operatorname{tr} A = \lambda_1 + \lambda_2$ and $\det A = \lambda_1\lambda_2$: $A$ is positive definite if and only if $\det A &amp;gt; 0$ and $a_{11} &amp;gt; 0$ (together these force the eigenvalues to have the same sign and a positive sum, since $\operatorname{tr}A &amp;gt; 0$ when $a_{11} &amp;gt; 0$ and $a_{11}a_{22} &amp;gt; b^2 \ge 0$).&lt;/p&gt;

&lt;h2 id=&quot;the-gram-matrix-ata&quot;&gt;The Gram matrix $A^TA$&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2.&lt;/strong&gt; For every $m \times n$ matrix $A$, $A^TA$ is positive semidefinite. It is positive definite if and only if the columns of $A$ are linearly independent.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; $x^TA^TAx = (Ax)^T(Ax) = \lVert Ax \rVert^2 \ge 0$, with equality if and only if $Ax = 0$. If the columns are independent, $Ax = 0$ only for $x = 0$, so $A^TA$ is positive definite; conversely, any $x \neq 0$ with $Ax = 0$ gives $x^TA^TAx = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;This explains why the normal equations $A^TA\hat x = A^Tb$ (Lesson 08-02) have a unique solution when the columns of $A$ are independent: $A^TA$ is positive definite, hence invertible. Conversely, every positive definite matrix has the form $R^TR$ (Lesson 10-05, the Cholesky factorization).&lt;/p&gt;

&lt;h2 id=&quot;application-the-hessian-test-for-extrema&quot;&gt;Application: the Hessian test for extrema&lt;/h2&gt;

&lt;p&gt;At a critical point $x^\ast$ ($\nabla f(x^\ast) = 0$) of a smooth function $f$, let $H$ be the Hessian:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;$H$ positive definite $\Rightarrow$ strict minimum; $H$ negative definite $\Rightarrow$ strict maximum;&lt;/li&gt;
  &lt;li&gt;$H$ indefinite $\Rightarrow$ saddle point;&lt;/li&gt;
  &lt;li&gt;$H$ only semidefinite: inconclusive.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In optimization, a function whose Hessian is positive definite everywhere is &lt;strong&gt;strictly convex&lt;/strong&gt; and has at most one minimum; this is the basis of the Optimization course (Chapters 02–03). In probability, a covariance matrix $\operatorname{Cov}(X) = \mathbb{E}[(X - \mu)(X - \mu)^T]$ is always positive semidefinite, since $v^T\operatorname{Cov}(X)v = \operatorname{Var}(v^TX) \ge 0$.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: Classifying quadratic forms&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Bowl, saddle or trough: eigenvalue signs and the 3D surface.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter10/dang_toan_phuong.html?mode=def&amp;amp;preset=saddle&amp;amp;lang=en&quot; title=&quot;Interactive: Classifying quadratic forms&quot; loading=&quot;lazy&quot; style=&quot;height: 900px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter10/dang_toan_phuong.html?mode=def&amp;amp;preset=saddle&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Determine the sign of the quadratic form $q = 2x^2 + 2xy + 2y^2$ in two ways: eigenvalues and completing the square.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$, eigenvalues $3$ and $1$: positive definite. Completing the square: $q = 2\big(x + \tfrac{y}{2}\big)^2 + \tfrac32y^2 &amp;gt; 0$ for $(x, y) \neq 0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; For which $k$ is $\begin{bmatrix} 1 &amp;amp; k \\ k &amp;amp; 4 \end{bmatrix}$ positive definite?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$a_{11} = 1 &amp;gt; 0$ and $\det = 4 - k^2 &amp;gt; 0$, i.e. $\lvert k \rvert &amp;lt; 2$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Prove: if $A$ is positive definite, then $A$ is invertible and $A^{-1}$ is also positive definite.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

All eigenvalues $\lambda_i &amp;gt; 0$, so $\det A = \prod\lambda_i &amp;gt; 0$ and $A$ is invertible. $A^{-1}$ is symmetric with eigenvalues $1/\lambda_i &amp;gt; 0$, so it is positive definite.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Classify the critical point $(0, 0)$ of $f(x, y) = x^2 + 6xy + y^2$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$f = x^TAx$ with $A = \begin{bmatrix} 1 &amp;amp; 3 \\ 3 &amp;amp; 1 \end{bmatrix}$, eigenvalues $4$ and $-2$: indefinite, so $(0, 0)$ is a saddle point.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5.&lt;/strong&gt; Prove: if $A$ and $B$ are positive definite, so is $A + B$. Is the product $AB$ necessarily symmetric?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$x^T(A + B)x = x^TAx + x^TBx &amp;gt; 0$ for $x \neq 0$. $AB$ need not be symmetric: with $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$, $B = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{bmatrix}$, $AB = \begin{bmatrix} 2 &amp;amp; 2 \\ 1 &amp;amp; 2 \end{bmatrix}$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Positive definite: $x^TAx &amp;gt; 0$ for all $x \neq 0$ $\iff$ all eigenvalues positive.&lt;/li&gt;
    &lt;li&gt;Positive semidefinite: all eigenvalues $\ge 0$; indefinite: eigenvalues of both signs.&lt;/li&gt;
    &lt;li&gt;$2 \times 2$: positive definite $\iff a_{11} &amp;gt; 0$ and $\det A &amp;gt; 0$.&lt;/li&gt;
    &lt;li&gt;$A^TA$ is positive semidefinite, and positive definite when the columns of $A$ are independent.&lt;/li&gt;
    &lt;li&gt;A positive definite Hessian at a critical point $\Rightarrow$ a strict minimum.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Quadratic Forms and Level Curves</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter10/10_03_Dang_Toan_Phuong_Va_Duong_Muc/"/>
   <updated>2026-01-10T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter10/10_03_Dang_Toan_Phuong_Va_Duong_Muc</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;write a quadratic form as $q(x) = x^TAx$ with $A$ symmetric;&lt;/li&gt;
    &lt;li&gt;use the change of variables $x = Qy$ (the principal axes theorem) to bring $q$ to the canonical form $\sum\lambda_iy_i^2$;&lt;/li&gt;
    &lt;li&gt;recognize whether the level curve $q(x) = 1$ is an ellipse, a hyperbola or degenerate, and find its axes and semi-axes.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;What is the curve $5x^2 + 4xy + 2y^2 = 1$? Without the $xy$ term it would be easy: $5x^2 + 2y^2 = 1$ is an ellipse with axes along the coordinate axes. The cross term $4xy$ &lt;strong&gt;rotates&lt;/strong&gt; the ellipse. This lesson shows that the axes of the ellipse are eigenvectors of a symmetric matrix, and the semi-axis lengths can be read off the eigenvalues.&lt;/p&gt;

&lt;h2 id=&quot;quadratic-forms&quot;&gt;Quadratic forms&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition.&lt;/strong&gt; A &lt;strong&gt;quadratic form&lt;/strong&gt; on $\mathbb{R}^n$ is a function $q(x) = x^TAx = \sum_{i,j}a_{ij}x_ix_j$, where $A$ is a symmetric $n \times n$ matrix (the matrix of $q$).&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;For $n = 2$: $q(x, y) = ax^2 + 2bxy + cy^2$ corresponds to $A = \begin{bmatrix} a &amp;amp; b \\ b &amp;amp; c \end{bmatrix}$. Note that the coefficient of $xy$ is &lt;strong&gt;split in half&lt;/strong&gt; between the two off-diagonal positions. The motivating example $5x^2 + 4xy + 2y^2$ has $A = \begin{bmatrix} 5 &amp;amp; 2 \\ 2 &amp;amp; 2 \end{bmatrix}$.&lt;/p&gt;

&lt;p&gt;Any square matrix $M$ gives a quadratic form $x^TMx$, but $x^TMx = x^T\tfrac{M + M^T}{2}x$, so we can always assume the matrix is symmetric; it is then unique.&lt;/p&gt;

&lt;h2 id=&quot;the-principal-axes-theorem&quot;&gt;The principal axes theorem&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Principal axes).&lt;/strong&gt; Let $A = Q\Lambda Q^T$ be an orthogonal diagonalization of symmetric $A$. With the change of variables $x = Qy$ (i.e. $y = Q^Tx$),&lt;/p&gt;

\[q(x) = x^TAx = y^T\Lambda y = \lambda_1y_1^2 + \dots + \lambda_ny_n^2.\]

  &lt;p&gt;The columns $q_1, \dots, q_n$ of $Q$ are called the &lt;strong&gt;principal axes&lt;/strong&gt; of $q$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; $x^TAx = (Qy)^TQ\Lambda Q^T(Qy) = y^T(Q^TQ)\Lambda(Q^TQ)y = y^T\Lambda y$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Since $Q$ is orthogonal, $y = Q^Tx$ is just a &lt;strong&gt;rotation&lt;/strong&gt; (possibly with a reflection) of the axes: the shape of the level curve does not change, we only view it in new coordinates.&lt;/p&gt;

&lt;h2 id=&quot;recognizing-level-curves-for-n--2&quot;&gt;Recognizing level curves for $n = 2$&lt;/h2&gt;

&lt;p&gt;In $y$-coordinates, the level curve $q = 1$ is $\lambda_1y_1^2 + \lambda_2y_2^2 = 1$:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;$\lambda_1, \lambda_2 &amp;gt; 0$: an &lt;strong&gt;ellipse&lt;/strong&gt; with semi-axis $1/\sqrt{\lambda_1}$ along $q_1$ and $1/\sqrt{\lambda_2}$ along $q_2$. A larger eigenvalue gives a shorter axis.&lt;/li&gt;
  &lt;li&gt;$\lambda_1 &amp;gt; 0 &amp;gt; \lambda_2$: a &lt;strong&gt;hyperbola&lt;/strong&gt;, crossing the $q_1$ axis at $\pm 1/\sqrt{\lambda_1}$.&lt;/li&gt;
  &lt;li&gt;$\lambda_1 &amp;gt; 0 = \lambda_2$: a &lt;strong&gt;pair of parallel lines&lt;/strong&gt; $y_1 = \pm1/\sqrt{\lambda_1}$.&lt;/li&gt;
  &lt;li&gt;$\lambda_1, \lambda_2 \le 0$: the empty set.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (the motivating example).&lt;/strong&gt; $A = \begin{bmatrix} 5 &amp;amp; 2 \\ 2 &amp;amp; 2 \end{bmatrix}$ has $\lambda_1 = 6$ with $q_1 = \tfrac{1}{\sqrt5}(2, 1)$ and $\lambda_2 = 1$ with $q_2 = \tfrac{1}{\sqrt5}(1, -2)$ (Exercise 1, Lesson 10-01). So $5x^2 + 4xy + 2y^2 = 6y_1^2 + y_2^2$, and the curve $q = 1$ is an ellipse with short semi-axis $1/\sqrt6 \approx 0.41$ along $(2, 1)$ and long semi-axis $1$ along $(1, -2)$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; $x^2 + 4xy - 2y^2 = 1$: $A = \begin{bmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; -2 \end{bmatrix}$ has eigenvalues $2$ (direction $(2, 1)$) and $-3$ (direction $(1, -2)$) (Example 1, Lesson 10-01). Canonical form $2y_1^2 - 3y_2^2 = 1$: a hyperbola with vertices at $y_1 = \pm 1/\sqrt2$ on the $(2, 1)$ axis.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The 3D picture: the surface $z = q(x)$ is a &lt;strong&gt;bowl&lt;/strong&gt; (elliptic paraboloid) when both eigenvalues are positive, and a &lt;strong&gt;saddle&lt;/strong&gt; (hyperbolic paraboloid) when they have opposite signs. Level curves are horizontal slices of this surface.&lt;/p&gt;

&lt;h2 id=&quot;application-quadratic-approximation-and-loss-functions&quot;&gt;Application: quadratic approximation and loss functions&lt;/h2&gt;

&lt;p&gt;Near a minimum $x^\ast$ of a smooth function $f$, the second-order Taylor expansion gives $f(x) \approx f(x^\ast) + \tfrac12(x - x^\ast)^TH(x - x^\ast)$, where $H$ is the (symmetric) Hessian. So the level curves of a loss function near a minimum are ellipses whose principal axes are the eigenvectors of $H$. When $\lambda_{\max}/\lambda_{\min}$ is large, the ellipses are very flat and gradient descent zig-zags across the narrow valley; this is why preconditioning and Adam try to “round out” these ellipses.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: Quadratic forms and level curves&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag a, b, c to see level curves and principal axes.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter10/dang_toan_phuong.html?mode=level&amp;amp;lang=en&quot; title=&quot;Interactive: Quadratic forms and level curves&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter10/dang_toan_phuong.html?mode=level&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-ellipses-hyperbolas-and-the-principal-directions-of-a-quadratic-form&quot;&gt;Short video: Ellipses, hyperbolas and the principal directions of a quadratic form&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/quadratic-form-ellipse.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;5x² + 2y² = 1 is an ellipse aligned with the axes; adding 4xy tilts it. The axes of the ellipse are eigenvectors of A = [5 2; 2 2]: eigenvalue 6 (direction (2; 1), semi-axis 1/√6) and 1 (direction (1; −2), semi-axis 1). Rotating the axes: q = 6y₁² + y₂². Changing the sign of one eigenvalue turns the ellipse into a hyperbola. Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Write the matrix of $q(x_1, x_2, x_3) = x_1^2 + 3x_2^2 - x_3^2 + 4x_1x_2 - 6x_2x_3$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 \\ 2 &amp;amp; 3 &amp;amp; -3 \\ 0 &amp;amp; -3 &amp;amp; -1 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Identify $3x^2 + 2xy + 3y^2 = 1$ and find its principal axes and semi-axes.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A = \begin{bmatrix} 3 &amp;amp; 1 \\ 1 &amp;amp; 3 \end{bmatrix}$, eigenvalues $4$ (direction $(1, 1)$) and $2$ (direction $(1, -1)$). Canonical form $4y_1^2 + 2y_2^2 = 1$: an ellipse with semi-axes $\tfrac12$ along $(1, 1)$ and $\tfrac{1}{\sqrt2}$ along $(1, -1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Identify the curve $xy = 1$ with the principal axes theorem.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A = \begin{bmatrix} 0 &amp;amp; 1/2 \\ 1/2 &amp;amp; 0 \end{bmatrix}$, eigenvalues $\tfrac12$ (direction $(1, 1)$) and $-\tfrac12$ (direction $(1, -1)$). Canonical form $\tfrac12y_1^2 - \tfrac12y_2^2 = 1$: a rectangular hyperbola with vertices at $y_1 = \pm\sqrt2$ on the line $y = x$, i.e. the points $(1, 1)$ and $(-1, -1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; What is the curve $x^2 + 2xy + y^2 = 1$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$ has eigenvalues $2$ and $0$. In fact $q = (x + y)^2$, so the level curve is the pair of parallel lines $x + y = \pm 1$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$q(x) = x^TAx$ with $A$ symmetric; the coefficient of $x_ix_j$ ($i \neq j$) is split in half between $a_{ij}$ and $a_{ji}$.&lt;/li&gt;
    &lt;li&gt;Principal axes theorem: $x = Qy$ turns $q$ into $\sum\lambda_iy_i^2$; the principal axes are eigenvectors.&lt;/li&gt;
    &lt;li&gt;$q = 1$: an ellipse (both eigenvalues positive, semi-axes $1/\sqrt{\lambda_i}$), a hyperbola (opposite signs), degenerate (a zero eigenvalue).&lt;/li&gt;
    &lt;li&gt;Near a minimum, a loss function has elliptical level curves given by the Hessian.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Orthogonal Diagonalization</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter10/10_02_Cheo_Hoa_Truc_Giao/"/>
   <updated>2026-01-10T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter10/10_02_Cheo_Hoa_Truc_Giao</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;orthogonally diagonalize a symmetric matrix: $A = Q\Lambda Q^T$;&lt;/li&gt;
    &lt;li&gt;write the spectral decomposition $A = \sum\lambda_iq_iq_i^T$ as a sum of projections;&lt;/li&gt;
    &lt;li&gt;compute $A^k$, $A^{-1}$ and $\sqrt{A}$ for a symmetric matrix.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Ordinary diagonalization $A = PDP^{-1}$ (Lesson 09-04) requires computing $P^{-1}$. For a symmetric matrix, the spectral theorem (Lesson 10-01) lets us choose $P = Q$ with orthonormal columns, and then $Q^{-1} = Q^T$: the inverse comes for free.&lt;/p&gt;

&lt;p&gt;For $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$, $q_1 = \tfrac{1}{\sqrt2}(1, 1)$ (eigenvalue $3$), $q_2 = \tfrac{1}{\sqrt2}(1, -1)$ (eigenvalue $1$):&lt;/p&gt;

\[A = \underbrace{\frac{1}{\sqrt2}\begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix}}_{Q}\begin{bmatrix} 3 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix}\underbrace{\frac{1}{\sqrt2}\begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix}}_{Q^T}.\]

&lt;h2 id=&quot;orthogonal-diagonalization-and-the-spectral-decomposition&quot;&gt;Orthogonal diagonalization and the spectral decomposition&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition.&lt;/strong&gt; A matrix $A$ is &lt;strong&gt;orthogonally diagonalizable&lt;/strong&gt; if $A = Q\Lambda Q^T$ with $Q$ orthogonal ($Q^TQ = I$) and $\Lambda$ diagonal.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;By the spectral theorem, $A$ is orthogonally diagonalizable if and only if $A$ is symmetric. The procedure:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Find the (real) eigenvalues of $A$.&lt;/li&gt;
  &lt;li&gt;For each eigenvalue, find a basis of its eigenspace and orthonormalize it with Gram–Schmidt.&lt;/li&gt;
  &lt;li&gt;Put the unit vectors as the columns of $Q$ and the matching eigenvalues on the diagonal of $\Lambda$.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Multiplying out $Q\Lambda Q^T$ column by row:&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Spectral decomposition).&lt;/strong&gt; If $A$ is symmetric with orthonormal eigenvectors $q_1, \dots, q_n$ and eigenvalues $\lambda_1, \dots, \lambda_n$, then&lt;/p&gt;

\[A = \lambda_1q_1q_1^T + \lambda_2q_2q_2^T + \dots + \lambda_nq_nq_n^T.\]

  &lt;p&gt;Each $q_iq_i^T$ is the orthogonal projection onto the line $\operatorname{span}(q_i)$ (Lesson 07-04).&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Geometrically: to compute $Ax$, project $x$ onto each principal axis, stretch each component by $\lambda_i$, and add up.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; For $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$: $q_1q_1^T = \tfrac12\begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$, $q_2q_2^T = \tfrac12\begin{bmatrix} 1 &amp;amp; -1 \\ -1 &amp;amp; 1 \end{bmatrix}$, and $3q_1q_1^T + 1\cdot q_2q_2^T = \tfrac12\begin{bmatrix} 4 &amp;amp; 2 \\ 2 &amp;amp; 4 \end{bmatrix} = A$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;functions-of-a-symmetric-matrix&quot;&gt;Functions of a symmetric matrix&lt;/h2&gt;

&lt;p&gt;Since the $q_iq_i^T$ are mutually orthogonal projections ($q_i^Tq_j = 0$ for $i \neq j$), $A^k = \sum\lambda_i^kq_iq_i^T$. More generally, for a function $f$ defined at the eigenvalues, define&lt;/p&gt;

\[f(A) = Q\,f(\Lambda)\,Q^T = \sum f(\lambda_i)\,q_iq_i^T.\]

&lt;ul&gt;
  &lt;li&gt;$A^{-1} = \sum\lambda_i^{-1}q_iq_i^T$ when every $\lambda_i \neq 0$.&lt;/li&gt;
  &lt;li&gt;$\sqrt{A} = \sum\sqrt{\lambda_i}\,q_iq_i^T$ when every $\lambda_i \ge 0$; it is the unique symmetric matrix with nonnegative eigenvalues whose square is $A$.&lt;/li&gt;
  &lt;li&gt;$e^{tA} = \sum e^{t\lambda_i}q_iq_i^T$ (Lesson 09-07).&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; For $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$:&lt;/p&gt;

\[A^k = \frac{3^k}{2}\begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix} + \frac12\begin{bmatrix} 1 &amp;amp; -1 \\ -1 &amp;amp; 1 \end{bmatrix}, \qquad \sqrt{A} = \frac12\begin{bmatrix} \sqrt3 + 1 &amp;amp; \sqrt3 - 1 \\ \sqrt3 - 1 &amp;amp; \sqrt3 + 1 \end{bmatrix}.\]

  &lt;p&gt;Check: the $(1,1)$ entry of $(\sqrt A)^2$ is $\tfrac14\big[(\sqrt3 + 1)^2 + (\sqrt3 - 1)^2\big] = \tfrac14 \cdot 8 = 2$, and the $(1,2)$ entry is $\tfrac14 \cdot 2(\sqrt3 + 1)(\sqrt3 - 1) = 1$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-whitening-data&quot;&gt;Application: whitening data&lt;/h2&gt;

&lt;p&gt;In machine learning, data with covariance matrix $C$ (symmetric, positive eigenvalues) is often &lt;strong&gt;whitened&lt;/strong&gt; before training: replace each point $x$ with $C^{-1/2}x$, where $C^{-1/2} = \sum\lambda_i^{-1/2}q_iq_i^T$. The new data has covariance $C^{-1/2}CC^{-1/2} = I$: the features are uncorrelated with equal variance. Geometrically: rotate to the principal axes, shrink each axis by its standard deviation, and rotate back.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: orthogonal diagonalization A = QΛQᵀ&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;For symmetric A, P is a rotation (orthogonal): rotate to the principal axes, stretch by Λ, rotate back.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter09/tri_rieng.html?mode=diag&amp;amp;preset=sym&amp;amp;lang=en&quot; title=&quot;Interactive: orthogonal diagonalization A = QΛQᵀ&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter09/tri_rieng.html?mode=diag&amp;amp;preset=sym&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Orthogonally diagonalize $A = \begin{bmatrix} 5 &amp;amp; 2 \\ 2 &amp;amp; 2 \end{bmatrix}$ and write its spectral decomposition.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\lambda = 6$ with $q_1 = \tfrac{1}{\sqrt5}(2, 1)$, $\lambda = 1$ with $q_2 = \tfrac{1}{\sqrt5}(1, -2)$. $Q = \tfrac{1}{\sqrt5}\begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; -2 \end{bmatrix}$, $\Lambda = \operatorname{diag}(6, 1)$, $A = \tfrac65\begin{bmatrix} 4 &amp;amp; 2 \\ 2 &amp;amp; 1 \end{bmatrix} + \tfrac15\begin{bmatrix} 1 &amp;amp; -2 \\ -2 &amp;amp; 4 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Use the spectral decomposition to compute $A^{-1}$ for $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A^{-1} = \tfrac13 q_1q_1^T + q_2q_2^T = \tfrac16\begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix} + \tfrac12\begin{bmatrix} 1 &amp;amp; -1 \\ -1 &amp;amp; 1 \end{bmatrix} = \tfrac13\begin{bmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Orthogonally diagonalize $A = \begin{bmatrix} 2 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 2 \end{bmatrix}$ (Example 2, Lesson 10-01) and compute $A^k$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

With $P_1 = \tfrac13\mathbf{1}\mathbf{1}^T$ (projection onto $\mathbf{1}$) and $P_2 = I - P_1$ (projection onto the plane): $A = 4P_1 + P_2$, so $A^k = 4^kP_1 + P_2 = I + \tfrac{4^k - 1}{3}\mathbf{1}\mathbf{1}^T$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Prove: if $A$ is symmetric and $A^2 = A$, then $A$ is the orthogonal projection onto $\operatorname{Col}(A)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Eigenvalues satisfy $\lambda^2 = \lambda$, so $\lambda \in \{0, 1\}$. The spectral decomposition gives $A = \sum_{\lambda_i = 1}q_iq_i^T$, the orthogonal projection onto the span of the $q_i$ with eigenvalue $1$, which is $\operatorname{Col}(A)$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Symmetric matrices: $A = Q\Lambda Q^T$, $Q^{-1} = Q^T$.&lt;/li&gt;
    &lt;li&gt;Spectral decomposition: $A = \sum\lambda_iq_iq_i^T$, a weighted sum of projections onto the principal axes.&lt;/li&gt;
    &lt;li&gt;$f(A) = Qf(\Lambda)Q^T$: $A^k$, $A^{-1}$, $\sqrt A$, $e^{tA}$.&lt;/li&gt;
    &lt;li&gt;Application: whitening data with $C^{-1/2}$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>The Spectral Theorem for Real Symmetric Matrices</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter10/10_01_Dinh_Ly_Pho_Cho_Ma_Tran_Doi_Xung_Thuc/"/>
   <updated>2026-01-10T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter10/10_01_Dinh_Ly_Pho_Cho_Ma_Tran_Doi_Xung_Thuc</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;prove that the eigenvalues of a real symmetric matrix are real;&lt;/li&gt;
    &lt;li&gt;prove that eigenvectors of a symmetric matrix for distinct eigenvalues are orthogonal;&lt;/li&gt;
    &lt;li&gt;state the spectral theorem and find an orthonormal eigenbasis of a $2 \times 2$ symmetric matrix.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;In Chapter 09, the rotation matrix $\begin{bmatrix} 0 &amp;amp; -1 \\ 1 &amp;amp; 0 \end{bmatrix}$ had no real eigenvalues, and $\begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \end{bmatrix}$ was not diagonalizable. What about $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$? Its eigenvalues are $3$ with $(1, 1)$ and $1$ with $(1, -1)$. The two eigenvectors are not just independent but &lt;strong&gt;perpendicular&lt;/strong&gt;: $(1, 1) \cdot (1, -1) = 0$.&lt;/p&gt;

&lt;p&gt;This happens for every symmetric matrix ($A^T = A$). Symmetric matrices are everywhere: covariance matrices, Hessians, stiffness matrices, $A^TA$ in least squares.&lt;/p&gt;

&lt;h2 id=&quot;real-eigenvalues-orthogonal-eigenvectors&quot;&gt;Real eigenvalues, orthogonal eigenvectors&lt;/h2&gt;

&lt;p&gt;A key property: for symmetric $A$ and all $x, y$,&lt;/p&gt;

\[(Ax) \cdot y = x^TA^Ty = x^TAy = x \cdot (Ay).\]

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; Let $A$ be a real symmetric matrix.&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;Every eigenvalue of $A$ (including complex roots of the characteristic polynomial) is real.&lt;/li&gt;
    &lt;li&gt;If $Au = \lambda u$ and $Av = \mu v$ with $\lambda \neq \mu$, then $u \cdot v = 0$.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; (1) Suppose $Av = \lambda v$ with $v \in \mathbb{C}^n$, $v \neq 0$. Let $\bar v$ be the complex conjugate. Since $A$ is real, $A\bar v = \bar\lambda\bar v$. Compute $\bar v^TAv$ two ways: $\bar v^T(Av) = \lambda\,\bar v^Tv$ and $(A\bar v)^Tv = \bar\lambda\,\bar v^Tv$ (using $A^T = A$). Since $\bar v^Tv = \sum\lvert v_i\rvert^2 &amp;gt; 0$, we get $\lambda = \bar\lambda$, so $\lambda$ is real.&lt;/p&gt;

  &lt;p&gt;(2) $\lambda(u \cdot v) = (Au) \cdot v = u \cdot (Av) = \mu(u \cdot v)$, so $(\lambda - \mu)(u \cdot v) = 0$, and since $\lambda \neq \mu$, $u \cdot v = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;the-spectral-theorem&quot;&gt;The spectral theorem&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2 (Spectral theorem).&lt;/strong&gt; A real $n \times n$ matrix $A$ is symmetric if and only if $\mathbb{R}^n$ has an orthonormal basis of eigenvectors of $A$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof sketch.&lt;/strong&gt; “If”: if $Q$ is orthogonal with eigenvector columns, then $A = Q\Lambda Q^T$ and $A^T = Q\Lambda^TQ^T = A$.&lt;/p&gt;

  &lt;p&gt;“Only if”, by induction on $n$. By Theorem 1, $A$ has a real eigenvalue $\lambda_1$ with a unit eigenvector $q_1$. Let $W = q_1^{\perp}$. For $w \in W$: $(Aw) \cdot q_1 = w \cdot (Aq_1) = \lambda_1(w \cdot q_1) = 0$, so $A$ maps $W$ into $W$. The restriction of $A$ to $W$ (of dimension $n - 1$) is still “symmetric” in the sense $(Ax) \cdot y = x \cdot (Ay)$, so by induction $W$ has an orthonormal eigenbasis $q_2, \dots, q_n$. Adding $q_1$ gives the required basis.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Note: a symmetric matrix is &lt;strong&gt;always&lt;/strong&gt; diagonalizable, even with repeated eigenvalues. When $\lambda$ has multiplicity $m$, its eigenspace has dimension exactly $m$; choose an orthonormal basis of it with Gram–Schmidt (Lesson 07-05).&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; $A = \begin{bmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; -2 \end{bmatrix}$. The characteristic polynomial is $\lambda^2 + \lambda - 6 = (\lambda - 2)(\lambda + 3)$. For $\lambda = 2$: $A - 2I = \begin{bmatrix} -1 &amp;amp; 2 \\ 2 &amp;amp; -4 \end{bmatrix}$, eigenvector $(2, 1)$. For $\lambda = -3$: $A + 3I = \begin{bmatrix} 4 &amp;amp; 2 \\ 2 &amp;amp; 1 \end{bmatrix}$, eigenvector $(1, -2)$. Check $(2, 1) \cdot (1, -2) = 0$. Orthonormal basis: $q_1 = \tfrac{1}{\sqrt5}(2, 1)$, $q_2 = \tfrac{1}{\sqrt5}(1, -2)$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (a repeated eigenvalue).&lt;/strong&gt; $A = \begin{bmatrix} 2 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 2 \end{bmatrix} = I + \mathbf{1}\mathbf{1}^T$. Then $A\mathbf{1} = 4\cdot\mathbf{1}$ and $Av = v$ for every $v \perp \mathbf{1}$. So the eigenvalues are $4$ (multiplicity 1) and $1$ (multiplicity 2), and the eigenspace of $1$ is the plane $x_1 + x_2 + x_3 = 0$. Choose an orthonormal basis of it, for example $\tfrac{1}{\sqrt2}(1, -1, 0)$ and $\tfrac{1}{\sqrt6}(1, 1, -2)$, together with $\tfrac{1}{\sqrt3}(1, 1, 1)$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-principal-axes-of-a-point-cloud&quot;&gt;Application: principal axes of a point cloud&lt;/h2&gt;

&lt;p&gt;The covariance matrix $C$ of a data set is symmetric. By the spectral theorem, $C$ has mutually perpendicular eigendirections; these are the &lt;strong&gt;principal axes&lt;/strong&gt; of the point cloud, and the eigenvalues are the variances of the data along each axis. This is the foundation of PCA (Chapter 11). In mechanics, the inertia matrix of a rigid body is also symmetric; its eigendirections are the body’s “balanced” rotation axes.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: eigenvectors of a symmetric matrix are orthogonal&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Edit A keeping a₁₂ = a₂₁: the two eigen-directions stay perpendicular and the eigenvalues real.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter09/tri_rieng.html?mode=eig&amp;amp;preset=sym&amp;amp;lang=en&quot; title=&quot;Interactive: eigenvectors of a symmetric matrix are orthogonal&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter09/tri_rieng.html?mode=eig&amp;amp;preset=sym&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Find an orthonormal eigenbasis of $A = \begin{bmatrix} 5 &amp;amp; 2 \\ 2 &amp;amp; 2 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\lambda^2 - 7\lambda + 6 = 0$, $\lambda = 6, 1$. For $6$: $(2, 1)$; for $1$: $(1, -2)$. Basis $\tfrac{1}{\sqrt5}(2, 1)$, $\tfrac{1}{\sqrt5}(1, -2)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Prove that the eigenvalues of a $2 \times 2$ symmetric matrix $\begin{bmatrix} a &amp;amp; b \\ b &amp;amp; c \end{bmatrix}$ are real by looking at the discriminant.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The characteristic polynomial $\lambda^2 - (a + c)\lambda + (ac - b^2)$ has discriminant $(a + c)^2 - 4(ac - b^2) = (a - c)^2 + 4b^2 \ge 0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Does $\begin{bmatrix} 1 &amp;amp; 2 \\ 0 &amp;amp; 3 \end{bmatrix}$ have two orthogonal eigenvectors? Does this contradict Theorem 1?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Eigenvectors $(1, 0)$ (for $1$) and $(1, 1)$ (for $3$), not orthogonal. No contradiction: the matrix is not symmetric.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Let $A$ be symmetric with eigenvalues $\lambda_1, \dots, \lambda_n$. Prove $\operatorname{tr}(A^2) = \sum \lambda_i^2 = \sum_{i,j} a_{ij}^2$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A^2$ has eigenvalues $\lambda_i^2$, so $\operatorname{tr}(A^2) = \sum\lambda_i^2$. Also $(A^2)_{ii} = \sum_j a_{ij}a_{ji} = \sum_j a_{ij}^2$ (as $A$ is symmetric); summing over $i$ gives $\sum_{i,j}a_{ij}^2$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Real symmetric matrices satisfy $(Ax) \cdot y = x \cdot (Ay)$.&lt;/li&gt;
    &lt;li&gt;Their eigenvalues are real; eigenvectors for distinct eigenvalues are orthogonal.&lt;/li&gt;
    &lt;li&gt;Spectral theorem: $A$ is symmetric $\iff$ it has an orthonormal eigenbasis; symmetric matrices are always diagonalizable.&lt;/li&gt;
    &lt;li&gt;Applications: principal axes of data (covariance), axes of inertia.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Định lý Cayley–Hamilton và dạng Jordan</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter09/09_08_Dinh_Ly_Cayley_Hamilton_Va_Dang_Jordan/"/>
   <updated>2026-01-09T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter09/09_08_Dinh_Ly_Cayley_Hamilton_Va_Dang_Jordan</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;phát biểu định lý Cayley–Hamilton và dùng nó để tính $A^{-1}$ và luỹ thừa của $A$;&lt;/li&gt;
    &lt;li&gt;nhận ra khối Jordan và tính luỹ thừa, hàm mũ của nó;&lt;/li&gt;
    &lt;li&gt;tìm dạng Jordan của ma trận $2 \times 2$ có trị riêng kép.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;p&gt;Đây là bài &lt;strong&gt;tùy chọn&lt;/strong&gt;: các chương sau không dùng trực tiếp, nhưng bài giải thích điều gì xảy ra khi ma trận &lt;em&gt;không&lt;/em&gt; chéo hoá được (Bài 09-04).&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Với $A = \begin{bmatrix} 4 &amp;amp; 1 \\ 2 &amp;amp; 3 \end{bmatrix}$, đa thức đặc trưng là $p(\lambda) = \lambda^2 - 7\lambda + 10$. Thay $\lambda$ bằng $A$ (và số $10$ bằng $10I$):&lt;/p&gt;

\[A^2 = \begin{bmatrix} 18 &amp;amp; 7 \\ 14 &amp;amp; 11 \end{bmatrix}, \qquad A^2 - 7A + 10I = \begin{bmatrix} 18 - 28 + 10 &amp;amp; 7 - 7 \\ 14 - 14 &amp;amp; 11 - 21 + 10 \end{bmatrix} = 0.\]

&lt;p&gt;Đây không phải trùng hợp.&lt;/p&gt;

&lt;h2 id=&quot;định-lý-cayleyhamilton&quot;&gt;Định lý Cayley–Hamilton&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Cayley–Hamilton).&lt;/strong&gt; Nếu $p(\lambda) = \det(\lambda I - A)$ là đa thức đặc trưng của ma trận vuông $A$ thì $p(A) = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh (trường hợp chéo hoá được).&lt;/strong&gt; Với $A = PDP^{-1}$, ta có $A^k = PD^kP^{-1}$ nên $p(A) = Pp(D)P^{-1}$, với $p(D) = \operatorname{diag}(p(\lambda_1), \dots, p(\lambda_n)) = 0$ vì mỗi $\lambda_i$ là nghiệm của $p$. Trường hợp tổng quát được chứng minh qua dạng Jordan (bên dưới) hoặc qua ma trận phụ hợp; ta không trình bày ở đây.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Hệ quả.&lt;/strong&gt; Với $n = 2$: $A^2 - (\operatorname{tr} A)A + (\det A)I = 0$.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;em&gt;Nghịch đảo.&lt;/em&gt; Nếu $\det A \neq 0$, nhân hai vế với $A^{-1}$: $A^{-1} = \dfrac{(\operatorname{tr} A)I - A}{\det A}$. Với ví dụ mở đầu: $A^{-1} = \tfrac{1}{10}(7I - A) = \tfrac{1}{10}\begin{bmatrix} 3 &amp;amp; -1 \\ -2 &amp;amp; 4 \end{bmatrix}$.&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;Luỹ thừa.&lt;/em&gt; Mọi $A^k$ đều viết được dưới dạng $\alpha_kA + \beta_kI$, vì có thể liên tục thay $A^2$ bằng $7A - 10I$.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;khối-jordan&quot;&gt;Khối Jordan&lt;/h2&gt;

&lt;p&gt;Ma trận $J = \begin{bmatrix} 2 &amp;amp; 1 \\ 0 &amp;amp; 2 \end{bmatrix}$ có trị riêng kép $2$ nhưng chỉ một hướng riêng $(1, 0)$, nên không chéo hoá được. Đó là một &lt;strong&gt;khối Jordan&lt;/strong&gt;: trị riêng trên đường chéo, số $1$ ngay trên đường chéo.&lt;/p&gt;

&lt;p&gt;Viết $J = 2I + N$ với $N = \begin{bmatrix} 0 &amp;amp; 1 \\ 0 &amp;amp; 0 \end{bmatrix}$, $N^2 = 0$. Vì $2I$ giao hoán với $N$, khai triển nhị thức chỉ còn hai số hạng:&lt;/p&gt;

\[J^k = 2^kI + k2^{k-1}N = \begin{bmatrix} 2^k &amp;amp; k2^{k-1} \\ 0 &amp;amp; 2^k \end{bmatrix}, \qquad e^{tJ} = e^{2t}(I + tN) = e^{2t}\begin{bmatrix} 1 &amp;amp; t \\ 0 &amp;amp; 1 \end{bmatrix}.\]

&lt;p&gt;Hệ số $k$ và $t$ là dấu hiệu của ma trận không chéo hoá được, đúng như số hạng $te^{-t}$ trong Bài tập 5 của Bài 09-07.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2 (Dạng Jordan, phát biểu không chứng minh).&lt;/strong&gt; Mọi ma trận vuông phức $A$ đồng dạng với một ma trận khối chéo $J = \operatorname{diag}(J_1, \dots, J_s)$, mỗi $J_i$ là một khối Jordan (trị riêng $\lambda_i$ trên đường chéo, số $1$ ngay trên). Dạng này duy nhất nếu không kể thứ tự các khối. $A$ chéo hoá được khi và chỉ khi mọi khối có cỡ $1 \times 1$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; $A = \begin{bmatrix} 3 &amp;amp; 1 \\ -1 &amp;amp; 1 \end{bmatrix}$ có $\operatorname{tr} A = 4$, $\det A = 4$, nên $p(\lambda) = (\lambda - 2)^2$. Ma trận $A - 2I = \begin{bmatrix} 1 &amp;amp; 1 \\ -1 &amp;amp; -1 \end{bmatrix}$ có hạng $1$, nên chỉ có một hướng riêng $v_1 = (1, -1)$: $A$ không chéo hoá được, và dạng Jordan là $\begin{bmatrix} 2 &amp;amp; 1 \\ 0 &amp;amp; 2 \end{bmatrix}$.&lt;/p&gt;

  &lt;p&gt;Để tìm $P$, giải $(A - 2I)v_2 = v_1$: $v_2 = (1, 0)$. Với $P = [v_1\ v_2] = \begin{bmatrix} 1 &amp;amp; 1 \\ -1 &amp;amp; 0 \end{bmatrix}$ ta có $AP = PJ$, kiểm tra: $Av_1 = 2v_1$, $Av_2 = (3, -1) = v_1 + 2v_2$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-tính-nhanh-luỹ-thừa-trong-thuật-toán&quot;&gt;Ứng dụng: tính nhanh luỹ thừa trong thuật toán&lt;/h2&gt;

&lt;p&gt;Cayley–Hamilton biến một luỹ thừa cao thành đa thức bậc thấp: với $A$ cỡ $n \times n$, $A^k$ là tổ hợp của $I, A, \dots, A^{n-1}$. Các thuật toán tính số hạng thứ $k$ của dãy truy hồi tuyến tính (như Fibonacci, Bài 09-06) dùng ý này: rút gọn $\lambda^k$ theo modulo đa thức đặc trưng, chỉ cần khoảng $\log k$ phép nhân đa thức bậc nhỏ thay vì nhân ma trận.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Dùng Cayley–Hamilton tính $A^{-1}$ với $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\operatorname{tr} A = 3$, $\det A = 1$. $A^{-1} = 3I - A = \begin{bmatrix} 1 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Với $A$ của Ví dụ 1, biểu diễn $A^2$ và $A^3$ dưới dạng $\alpha A + \beta I$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A^2 = 4A - 4I$, $A^3 = 4A^2 - 4A = 4(4A - 4I) - 4A = 12A - 16I$. Kiểm tra: $A^2 = \begin{bmatrix} 8 &amp;amp; 4 \\ -4 &amp;amp; 0 \end{bmatrix} = 4A - 4I$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Tính $J^{10}$ với $J = \begin{bmatrix} 2 &amp;amp; 1 \\ 0 &amp;amp; 2 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$J^{10} = \begin{bmatrix} 1024 &amp;amp; 10 \cdot 512 \\ 0 &amp;amp; 1024 \end{bmatrix} = \begin{bmatrix} 1024 &amp;amp; 5120 \\ 0 &amp;amp; 1024 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Cho $N = \begin{bmatrix} 0 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 0 \end{bmatrix}$. Tính $N^2$, $N^3$ và $e^{tN}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$N^2$ chỉ có số $1$ ở vị trí $(1, 3)$; $N^3 = 0$. Vậy $e^{tN} = I + tN + \tfrac{t^2}{2}N^2 = \begin{bmatrix} 1 &amp;amp; t &amp;amp; t^2/2 \\ 0 &amp;amp; 1 &amp;amp; t \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Cayley–Hamilton: $p(A) = 0$; với $2 \times 2$, $A^2 - (\operatorname{tr} A)A + (\det A)I = 0$ và $A^{-1} = \frac{(\operatorname{tr} A)I - A}{\det A}$.&lt;/li&gt;
    &lt;li&gt;Khối Jordan $J = \lambda I + N$, $N$ luỹ linh: $J^k$ và $e^{tJ}$ chứa các hệ số $k$, $t$.&lt;/li&gt;
    &lt;li&gt;Mọi ma trận phức đồng dạng với dạng Jordan; chéo hoá được $\iff$ mọi khối cỡ $1$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Hệ phương trình vi phân tuyến tính x′ = Ax</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter09/09_07_He_Phuong_Trinh_Vi_Phan_Tuyen_Tinh/"/>
   <updated>2026-01-09T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter09/09_07_He_Phuong_Trinh_Vi_Phan_Tuyen_Tinh</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;giải hệ $x&apos; = Ax$ với $A$ chéo hoá được bằng công thức $x(t) = \sum c_ie^{\lambda_it}v_i$;&lt;/li&gt;
    &lt;li&gt;tìm các hệ số $c_i$ từ điều kiện đầu và viết $e^{At} = Pe^{Dt}P^{-1}$;&lt;/li&gt;
    &lt;li&gt;phân loại điểm cân bằng $x = 0$ của hệ $2 \times 2$ (nút, yên ngựa, xoáy, tâm) và tính ổn định theo trị riêng.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Hai phòng thông nhau, nhiệt độ (so với ngoài trời) là $x_1(t)$ và $x_2(t)$. Mỗi phòng mất nhiệt ra ngoài và trao đổi nhiệt với phòng kia:&lt;/p&gt;

\[x_1&apos; = -2x_1 + x_2, \qquad x_2&apos; = x_1 - 2x_2, \qquad\text{tức}\qquad x&apos; = Ax,\ A = \begin{bmatrix} -2 &amp;amp; 1 \\ 1 &amp;amp; -2 \end{bmatrix}.\]

&lt;p&gt;Hai phương trình ràng buộc nhau. Nhưng với một phương trình $x&apos; = \lambda x$, ta biết nghiệm $x = ce^{\lambda t}$. Nếu chuyển sang toạ độ riêng của $A$ (Bài 09-04), hệ tách thành hai phương trình như vậy.&lt;/p&gt;

&lt;h2 id=&quot;nghiệm-bằng-vectơ-riêng&quot;&gt;Nghiệm bằng vectơ riêng&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Nếu $Av = \lambda v$ thì $x(t) = e^{\lambda t}v$ là nghiệm của $x&apos; = Ax$. Nếu $A$ chéo hoá được với các cặp riêng $(\lambda_i, v_i)$, mọi nghiệm có dạng&lt;/p&gt;

\[x(t) = c_1e^{\lambda_1t}v_1 + \dots + c_ne^{\lambda_nt}v_n,\]

  &lt;p&gt;với các hằng số $c_i$ xác định bởi $x(0) = c_1v_1 + \dots + c_nv_n$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; $\frac{d}{dt}(e^{\lambda t}v) = \lambda e^{\lambda t}v = e^{\lambda t}Av = A(e^{\lambda t}v)$. Tổ hợp tuyến tính của các nghiệm là nghiệm. Ngược lại, cho nghiệm $x(t)$, đặt $y = P^{-1}x$; khi đó $y&apos; = P^{-1}APy = Dy$, tức $y_i&apos; = \lambda_iy_i$, nên $y_i = c_ie^{\lambda_it}$ và $x = Py$ có đúng dạng trên.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (ví dụ mở đầu).&lt;/strong&gt; $A = \begin{bmatrix} -2 &amp;amp; 1 \\ 1 &amp;amp; -2 \end{bmatrix}$ có trị riêng $-1$ với $v_1 = (1, 1)$ và $-3$ với $v_2 = (1, -1)$. Với $x(0) = (3, 1)$: $c_1(1,1) + c_2(1,-1) = (3, 1)$ cho $c_1 = 2$, $c_2 = 1$. Vậy&lt;/p&gt;

\[x(t) = 2e^{-t}\begin{bmatrix} 1 \\ 1 \end{bmatrix} + e^{-3t}\begin{bmatrix} 1 \\ -1 \end{bmatrix}.\]

  &lt;p&gt;Hiệu nhiệt độ hai phòng $x_1 - x_2 = 2e^{-3t}$ tắt nhanh; nhiệt độ trung bình $\tfrac12(x_1 + x_2) = 2e^{-t}$ giảm chậm hơn. Sau ít phút hai phòng gần như cùng nhiệt độ, rồi cùng nguội dần.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;hàm-mũ-ma-trận&quot;&gt;Hàm mũ ma trận&lt;/h2&gt;

&lt;p&gt;Với phương trình vô hướng, nghiệm là $x(t) = e^{at}x(0)$. Với hệ, định nghĩa&lt;/p&gt;

\[e^{At} = I + At + \frac{(At)^2}{2!} + \frac{(At)^3}{3!} + \cdots.\]

&lt;p&gt;Chuỗi này luôn hội tụ, và $x(t) = e^{At}x(0)$ là nghiệm duy nhất của $x&apos; = Ax$ với điều kiện đầu cho trước. Nếu $A = PDP^{-1}$ thì $(At)^k = PD^kt^kP^{-1}$, nên&lt;/p&gt;

\[e^{At} = Pe^{Dt}P^{-1}, \qquad e^{Dt} = \operatorname{diag}(e^{\lambda_1t}, \dots, e^{\lambda_nt}).\]

&lt;h2 id=&quot;phân-loại-điểm-cân-bằng&quot;&gt;Phân loại điểm cân bằng&lt;/h2&gt;

&lt;p&gt;Điểm $x = 0$ luôn là điểm cân bằng của $x&apos; = Ax$. Với $A$ cỡ $2 \times 2$, dáng điệu các quỹ đạo quanh $0$ (bức tranh pha) được quyết định bởi hai trị riêng:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hai trị riêng thực cùng dấu âm&lt;/strong&gt;: &lt;em&gt;nút ổn định&lt;/em&gt;. Mọi quỹ đạo đi vào $0$, cuối cùng tiếp xúc với hướng của trị riêng có $\lvert\lambda\rvert$ nhỏ hơn (Ví dụ 1: hướng $(1, 1)$).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hai trị riêng thực cùng dấu dương&lt;/strong&gt;: &lt;em&gt;nút không ổn định&lt;/em&gt;, các quỹ đạo đi ra xa.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hai trị riêng thực trái dấu&lt;/strong&gt;: &lt;em&gt;điểm yên ngựa&lt;/em&gt;. Quỹ đạo đi vào theo hướng của trị riêng âm và đi ra theo hướng của trị riêng dương; hầu hết nghiệm ra vô cùng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cặp phức $a \pm bi$, $a &amp;lt; 0$&lt;/strong&gt;: &lt;em&gt;xoáy ổn định&lt;/em&gt;, quỹ đạo xoắn ốc vào $0$ (dao động tắt dần, Bài 09-05).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cặp phức $a \pm bi$, $a &amp;gt; 0$&lt;/strong&gt;: &lt;em&gt;xoáy không ổn định&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cặp thuần ảo $\pm bi$&lt;/strong&gt;: &lt;em&gt;tâm&lt;/em&gt;, quỹ đạo là các elip khép kín (dao động không tắt).&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2 (Ổn định).&lt;/strong&gt; Mọi nghiệm của $x&apos; = Ax$ tiến về $0$ khi $t \to \infty$ khi và chỉ khi mọi trị riêng của $A$ có phần thực âm.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh (trường hợp chéo hoá được).&lt;/strong&gt; Với $\lambda = a + bi$, $\lvert e^{\lambda t} \rvert = e^{at}$, tiến về $0$ khi và chỉ khi $a &amp;lt; 0$. Nếu mọi phần thực âm, mọi số hạng $c_ie^{\lambda_it}v_i$ tiến về $0$. Nếu một trị riêng có phần thực $\ge 0$, nghiệm $e^{\lambda t}v$ (hoặc phần thực của nó) không tiến về $0$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;So sánh với Bài 09-06: với hệ rời rạc $x_{k+1} = Ax_k$, điều kiện ổn định là $\lvert\lambda_i\rvert &amp;lt; 1$; với hệ liên tục $x&apos; = Ax$, điều kiện là $\operatorname{Re}\lambda_i &amp;lt; 0$. Liên hệ: $e^{\lambda}$ có môđun nhỏ hơn 1 đúng khi $\operatorname{Re}\lambda &amp;lt; 0$.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-lò-xo-có-giảm-chấn&quot;&gt;Ứng dụng: lò xo có giảm chấn&lt;/h2&gt;

&lt;p&gt;Một vật nặng gắn lò xo có giảm chấn thoả $y&apos;&apos; + 2\zeta y&apos; + y = 0$. Đặt $x = (y, y&apos;)$ được $x&apos; = \begin{bmatrix} 0 &amp;amp; 1 \\ -1 &amp;amp; -2\zeta \end{bmatrix}x$, với trị riêng $-\zeta \pm \sqrt{\zeta^2 - 1}$. Khi $\zeta = 0$: tâm (dao động mãi); $0 &amp;lt; \zeta &amp;lt; 1$: xoáy ổn định (dao động tắt dần, như giảm xóc ô tô hơi mềm); $\zeta &amp;gt; 1$: nút ổn định (trở về cân bằng không dao động, như cánh cửa có tay đẩy hơi). Kỹ sư thiết kế giảm xóc chọn $\zeta$ gần $1$ để vật về cân bằng nhanh nhất mà không nảy.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: bức tranh pha của x′ = Ax&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Chọn nút, yên ngựa, xoáy, tâm; bấm vào hình để thả điểm ban đầu.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter09/pha.html?preset=saddle&quot; title=&quot;Minh hoạ: bức tranh pha của x′ = Ax&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter09/pha.html?preset=saddle&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Giải $x&apos; = \begin{bmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 1 \end{bmatrix}x$, $x(0) = (2, 0)$. Phân loại điểm cân bằng.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Trị riêng $3$ với $(1, 1)$ và $-1$ với $(1, -1)$. $x(0) = (1,1) + (1,-1)$, nên $x(t) = e^{3t}(1, 1) + e^{-t}(1, -1)$. Hai trị riêng trái dấu: điểm yên ngựa, không ổn định.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Phân loại điểm cân bằng của $x&apos; = Ax$ với (a) $A = \begin{bmatrix} 0 &amp;amp; 1 \\ -4 &amp;amp; 0 \end{bmatrix}$; (b) $A = \begin{bmatrix} -1 &amp;amp; -2 \\ 2 &amp;amp; -1 \end{bmatrix}$; (c) $A = \begin{bmatrix} 3 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

(a) $\lambda^2 + 4 = 0$, $\lambda = \pm 2i$: tâm. (b) $\lambda = -1 \pm 2i$: xoáy ổn định. (c) $\lambda = 3, 1$: nút không ổn định.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Tính $e^{At}$ với $A = \begin{bmatrix} -2 &amp;amp; 1 \\ 1 &amp;amp; -2 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$P = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix}$, $P^{-1} = \tfrac12 P$, $e^{At} = \tfrac{1}{2}\begin{bmatrix} e^{-t} + e^{-3t} &amp;amp; e^{-t} - e^{-3t} \\ e^{-t} - e^{-3t} &amp;amp; e^{-t} + e^{-3t} \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Với ma trận $2 \times 2$, chứng minh: $x = 0$ ổn định (mọi nghiệm về $0$) khi và chỉ khi $\operatorname{tr} A &amp;lt; 0$ và $\det A &amp;gt; 0$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Nếu hai trị riêng thực: cả hai âm $\iff$ tổng âm và tích dương. Nếu cặp phức $a \pm bi$: tích $a^2 + b^2 &amp;gt; 0$ luôn đúng, và tổng $2a &amp;lt; 0 \iff a &amp;lt; 0$. Trong cả hai trường hợp, điều kiện là $\operatorname{tr} A &amp;lt; 0$, $\det A &amp;gt; 0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Với $\zeta = 1$ trong phần Ứng dụng, ma trận có trị riêng kép $-1$ và không chéo hoá được. Kiểm tra $y(t) = te^{-t}$ là nghiệm của $y&apos;&apos; + 2y&apos; + y = 0$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$y&apos; = (1 - t)e^{-t}$, $y&apos;&apos; = (t - 2)e^{-t}$. Tổng $y&apos;&apos; + 2y&apos; + y = (t - 2 + 2 - 2t + t)e^{-t} = 0$. Số hạng $te^{-t}$ xuất hiện vì ma trận không chéo hoá được (khối Jordan, Bài 09-08).

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$Av = \lambda v$ cho nghiệm $e^{\lambda t}v$ của $x&apos; = Ax$; với $A$ chéo hoá được, $x(t) = \sum c_ie^{\lambda_it}v_i$, các $c_i$ là toạ độ của $x(0)$ theo cơ sở vectơ riêng.&lt;/li&gt;
    &lt;li&gt;$x(t) = e^{At}x(0)$ với $e^{At} = Pe^{Dt}P^{-1}$.&lt;/li&gt;
    &lt;li&gt;Hệ $2 \times 2$: nút (thực cùng dấu), yên ngựa (thực trái dấu), xoáy (phức), tâm (thuần ảo).&lt;/li&gt;
    &lt;li&gt;Ổn định $\iff$ mọi $\operatorname{Re}\lambda_i &amp;lt; 0$; với $2 \times 2$: $\operatorname{tr} A &amp;lt; 0$ và $\det A &amp;gt; 0$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Lũy thừa ma trận và dãy truy hồi</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter09/09_06_Luy_Thua_Ma_Tran_Va_Day_Truy_Hoi/"/>
   <updated>2026-01-09T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter09/09_06_Luy_Thua_Ma_Tran_Va_Day_Truy_Hoi</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;tính $A^k$ bằng chéo hoá $A^k = PD^kP^{-1}$;&lt;/li&gt;
    &lt;li&gt;viết dãy truy hồi tuyến tính dưới dạng $x_{k+1} = Ax_k$ và tìm công thức tường minh, ví dụ công thức Binet cho dãy Fibonacci;&lt;/li&gt;
    &lt;li&gt;dự đoán hành vi dài hạn của $A^kx_0$ từ trị riêng trội, và cài đặt phép lặp luỹ thừa.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Dãy Fibonacci $0, 1, 1, 2, 3, 5, 8, \dots$ thoả $F_{k+2} = F_{k+1} + F_k$. Tính $F_{100}$ bằng cách cộng lần lượt cần 99 phép cộng; còn có công thức nào trực tiếp không? Viết hai số liên tiếp thành một vectơ:&lt;/p&gt;

\[\begin{bmatrix} F_{k+2} \\ F_{k+1} \end{bmatrix} = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix} \begin{bmatrix} F_{k+1} \\ F_k \end{bmatrix}, \quad\text{nên}\quad \begin{bmatrix} F_{k+1} \\ F_k \end{bmatrix} = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix}^k \begin{bmatrix} 1 \\ 0 \end{bmatrix}.\]

&lt;p&gt;Câu hỏi về dãy số thành câu hỏi về luỹ thừa ma trận. Và luỹ thừa của ma trận chéo hoá được thì dễ.&lt;/p&gt;

&lt;h2 id=&quot;luỹ-thừa-qua-chéo-hoá&quot;&gt;Luỹ thừa qua chéo hoá&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Nếu $A = PDP^{-1}$ với $D = \operatorname{diag}(\lambda_1, \dots, \lambda_n)$ thì với mọi $k \ge 0$,&lt;/p&gt;

\[A^k = PD^kP^{-1}, \qquad D^k = \operatorname{diag}(\lambda_1^k, \dots, \lambda_n^k).\]

  &lt;p&gt;Tương đương: nếu $x_0 = c_1v_1 + \dots + c_nv_n$ theo cơ sở vectơ riêng thì $A^kx_0 = c_1\lambda_1^kv_1 + \dots + c_n\lambda_n^kv_n$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; $A^2 = PDP^{-1}PDP^{-1} = PD^2P^{-1}$, và quy nạp: các cặp $P^{-1}P$ ở giữa triệt tiêu. Dạng thứ hai: $Av_i = \lambda_iv_i$ nên $A^kv_i = \lambda_i^kv_i$, rồi dùng tính tuyến tính.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Với $A = \begin{bmatrix} 4 &amp;amp; 1 \\ 2 &amp;amp; 3 \end{bmatrix} = PDP^{-1}$ ở Bài 09-04:&lt;/p&gt;

\[A^k = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -2 \end{bmatrix}\begin{bmatrix} 5^k &amp;amp; 0 \\ 0 &amp;amp; 2^k \end{bmatrix}\frac{1}{3}\begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix} = \frac{1}{3}\begin{bmatrix} 2 \cdot 5^k + 2^k &amp;amp; 5^k - 2^k \\ 2 \cdot 5^k - 2 \cdot 2^k &amp;amp; 5^k + 2 \cdot 2^k \end{bmatrix}.\]

  &lt;p&gt;Kiểm tra với $k = 2$: $\tfrac{1}{3}\begin{bmatrix} 54 &amp;amp; 21 \\ 42 &amp;amp; 33 \end{bmatrix} = \begin{bmatrix} 18 &amp;amp; 7 \\ 14 &amp;amp; 11 \end{bmatrix} = A^2$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;công-thức-binet&quot;&gt;Công thức Binet&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (Fibonacci).&lt;/strong&gt; Ma trận $F = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix}$ có $p(\lambda) = \lambda^2 - \lambda - 1$, trị riêng&lt;/p&gt;

\[\varphi = \frac{1 + \sqrt{5}}{2} \approx 1{,}618, \qquad \psi = \frac{1 - \sqrt{5}}{2} \approx -0{,}618,\]

  &lt;p&gt;với vectơ riêng $(\varphi, 1)$ và $(\psi, 1)$ (vì $F(\lambda, 1) = (\lambda + 1, \lambda) = \lambda(\lambda, 1)$ khi $\lambda^2 = \lambda + 1$). Viết $(1, 0) = \tfrac{1}{\sqrt{5}}\left[(\varphi, 1) - (\psi, 1)\right]$ (vì $\varphi - \psi = \sqrt{5}$). Theo Định lý 1,&lt;/p&gt;

\[\begin{bmatrix} F_{k+1} \\ F_k \end{bmatrix} = \frac{1}{\sqrt{5}}\left[\varphi^k\begin{bmatrix} \varphi \\ 1 \end{bmatrix} - \psi^k\begin{bmatrix} \psi \\ 1 \end{bmatrix}\right], \quad\text{nên}\quad F_k = \frac{\varphi^k - \psi^k}{\sqrt{5}}.\]

  &lt;p&gt;Vì $\lvert\psi\rvert &amp;lt; 1$, số hạng $\psi^k$ nhanh chóng không đáng kể: $F_k$ là số nguyên gần $\varphi^k/\sqrt{5}$ nhất, và $F_{k+1}/F_k \to \varphi$, tỷ lệ vàng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;hành-vi-dài-hạn-và-trị-riêng-trội&quot;&gt;Hành vi dài hạn và trị riêng trội&lt;/h2&gt;

&lt;p&gt;Giả sử $\lvert\lambda_1\rvert &amp;gt; \lvert\lambda_2\rvert \ge \dots \ge \lvert\lambda_n\rvert$ ($\lambda_1$ là &lt;em&gt;trị riêng trội&lt;/em&gt;) và $c_1 \ne 0$. Khi đó&lt;/p&gt;

\[A^kx_0 = \lambda_1^k\left[c_1v_1 + c_2\left(\tfrac{\lambda_2}{\lambda_1}\right)^kv_2 + \dots\right] \approx c_1\lambda_1^kv_1 \quad (k \text{ lớn}).\]

&lt;p&gt;Mọi vectơ ban đầu (với $c_1 \ne 0$) đều quay dần về hướng $v_1$, và độ dài tăng (hay giảm) theo $\lvert\lambda_1\rvert^k$. Tốc độ hội tụ về hướng $v_1$ phụ thuộc tỷ số $\lvert\lambda_2/\lambda_1\rvert$.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phép lặp luỹ thừa.&lt;/strong&gt; Ý tưởng trên cho một thuật toán tìm trị riêng trội: bắt đầu từ $x_0$ bất kỳ, lặp $x_{k+1} = Ax_k / \lVert Ax_k \rVert$. Khi hội tụ, $x_k \approx v_1$ (đã chuẩn hoá) và $x_k^TAx_k \approx \lambda_1$.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;power_iteration&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rand&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Với $A = \begin{bmatrix} 4 &amp;amp; 1 \\ 2 &amp;amp; 3 \end{bmatrix}$, sáu bước từ $x_0 = e_1$ đã cho ước lượng $\lambda_1 \approx 5{,}003$; sai số giảm theo $(2/5)^k$.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-phân-bố-dài-hạn&quot;&gt;Ứng dụng: phân bố dài hạn&lt;/h2&gt;

&lt;p&gt;Mỗi năm, $10\%$ dân thành phố chuyển về nông thôn và $20\%$ dân nông thôn chuyển lên thành phố. Với $x_k = (\text{thành phố}, \text{nông thôn})$: $x_{k+1} = Mx_k$, $M = \begin{bmatrix} 0{,}9 &amp;amp; 0{,}2 \\ 0{,}1 &amp;amp; 0{,}8 \end{bmatrix}$. Trị riêng $1$ với vectơ riêng $(2, 1)$ và $0{,}7$ với vectơ riêng $(1, -1)$. Vì $0{,}7^k \to 0$, mọi phân bố ban đầu đều tiến về tỷ lệ $2 : 1$: dài hạn, hai phần ba dân số sống ở thành phố, bất kể ban đầu thế nào. Đây là ví dụ về xích Markov (Chương 13).&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: luỹ thừa ma trận hội tụ về vectơ riêng trội&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Bấm +1 nhiều lần: hướng của Aᵏx tiến về vectơ riêng có ∣λ∣ lớn nhất.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter09/tri_rieng.html?mode=power&quot; title=&quot;Minh hoạ: luỹ thừa ma trận hội tụ về vectơ riêng trội&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter09/tri_rieng.html?mode=power&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-lũy-thừa-ma-trận-và-tỷ-lệ-vàng&quot;&gt;Video ngắn: Lũy thừa ma trận và tỷ lệ vàng&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/fibonacci-power.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Dãy Fibonacci ghép thành vectơ (Fₖ₊₁; Fₖ) = Aᵏ (1; 0) với A = [1 1; 1 0]. Các điểm dồn về hướng riêng (φ; 1), nằm xen kẽ hai bên và ngày càng sát; tỷ số Fₖ₊₁/Fₖ → φ ≈ 1,618. Phương trình đặc trưng λ² − λ − 1 = 0; phép lặp luỹ thừa; công thức Binet Fₖ = (φᵏ − ψᵏ)/√5. Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Tính $\begin{bmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 1 \end{bmatrix}^k$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Từ Bài tập 1 Bài 09-04: $A^k = \tfrac{1}{2}\begin{bmatrix} 3^k + (-1)^k &amp;amp; 3^k - (-1)^k \\ 3^k - (-1)^k &amp;amp; 3^k + (-1)^k \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Với $M$ ở phần Ứng dụng, tìm $\lim_{k \to \infty} M^k$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$M^k = P\operatorname{diag}(1, 0{,}7^k)P^{-1}$ với $P = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix}$, nên $M^k \to P\operatorname{diag}(1, 0)P^{-1} = \tfrac{1}{3}\begin{bmatrix} 2 &amp;amp; 2 \\ 1 &amp;amp; 1 \end{bmatrix}$. Mọi cột đều là phân bố dừng $(\tfrac23, \tfrac13)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Tìm công thức tường minh cho dãy $a_0 = 0$, $a_1 = 1$, $a_{k+2} = 5a_{k+1} - 6a_k$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Ma trận $\begin{bmatrix} 5 &amp;amp; -6 \\ 1 &amp;amp; 0 \end{bmatrix}$ có $p(\lambda) = \lambda^2 - 5\lambda + 6$, trị riêng $3$, $2$. Nên $a_k = \alpha 3^k + \beta 2^k$; từ $a_0 = 0$, $a_1 = 1$ được $\alpha = 1$, $\beta = -1$: $a_k = 3^k - 2^k$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (lập trình).&lt;/strong&gt; Cài đặt phép lặp luỹ thừa và so với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.eig&lt;/code&gt; trên $\begin{bmatrix} 2 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 2 \end{bmatrix}$. Thuật toán hội tụ nhanh cỡ nào, và vì sao?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Thuật toán hội tụ về $\lambda_1 = 4$, $v_1 = \tfrac{1}{\sqrt3}(1,1,1)$, cùng kết quả với `eig`. Sai số hướng giảm theo $(1/4)^k$ vì $\lambda_2 = 1$: rất nhanh, khoảng 25 bước cho 15 chữ số.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Chứng minh $F_{k+1}F_{k-1} - F_k^2 = (-1)^k$ (đẳng thức Cassini) bằng định thức.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Bằng quy nạp, $F^k = \begin{bmatrix} F_{k+1} &amp;amp; F_k \\ F_k &amp;amp; F_{k-1} \end{bmatrix}$. Lấy định thức hai vế: $F_{k+1}F_{k-1} - F_k^2 = (\det F)^k = (-1)^k$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$A^k = PD^kP^{-1}$; theo cơ sở vectơ riêng, $A^kx_0 = \sum c_i\lambda_i^kv_i$.&lt;/li&gt;
    &lt;li&gt;Dãy truy hồi tuyến tính viết được thành $x_{k+1} = Ax_k$; Fibonacci cho công thức Binet $F_k = (\varphi^k - \psi^k)/\sqrt5$.&lt;/li&gt;
    &lt;li&gt;Dài hạn, $A^kx_0$ quay về hướng vectơ riêng trội với tốc độ $\lvert\lambda_2/\lambda_1\rvert^k$.&lt;/li&gt;
    &lt;li&gt;Phép lặp luỹ thừa tìm trị riêng trội chỉ bằng phép nhân ma trận với vectơ.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Trị riêng phức và ma trận quay</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter09/09_05_Tri_Rieng_Phuc_Va_Ma_Tran_Quay/"/>
   <updated>2026-01-09T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter09/09_05_Tri_Rieng_Phuc_Va_Ma_Tran_Quay</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;tìm trị riêng và vectơ riêng phức của ma trận thực $2 \times 2$;&lt;/li&gt;
    &lt;li&gt;giải thích vì sao trị riêng phức của ma trận thực đi thành cặp liên hợp;&lt;/li&gt;
    &lt;li&gt;viết $A = PCP^{-1}$ với $C = \begin{bmatrix} a &amp;amp; -b \\ b &amp;amp; a \end{bmatrix}$ là ma trận quay–co giãn, và đọc góc quay, hệ số co giãn.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Ma trận $A = \begin{bmatrix} 1 &amp;amp; -1 \\ 1 &amp;amp; 1 \end{bmatrix}$ biến $e_1$ thành $(1, 1)$ và $e_2$ thành $(-1, 1)$: mọi vectơ quay $45^\circ$ và dài thêm $\sqrt{2}$ lần. Không có hướng thực nào được giữ nguyên, và quả thật $p_A(\lambda) = \lambda^2 - 2\lambda + 2$ có biệt thức $4 - 8 &amp;lt; 0$. Nhưng trong $\mathbb{C}$, $\lambda = 1 \pm i = \sqrt{2}\, e^{\pm i\pi/4}$: môđun $\sqrt{2}$ đúng là hệ số co giãn, argument $\pi/4$ đúng là góc quay. Trị riêng phức không phải “nghiệm vô nghĩa”; chúng mã hoá phép quay.&lt;/p&gt;

&lt;h2 id=&quot;trị-riêng-phức-của-ma-trận-thực&quot;&gt;Trị riêng phức của ma trận thực&lt;/h2&gt;

&lt;p&gt;Mọi định nghĩa và định lý của Bài 09-01 đến 09-04 giữ nguyên khi cho phép số và vectơ phức: $\lambda \in \mathbb{C}$ là trị riêng nếu $Av = \lambda v$ với $v \in \mathbb{C}^n$, $v \ne 0$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Nếu $A$ là ma trận thực và $Av = \lambda v$ với $\lambda \in \mathbb{C}$, $v \in \mathbb{C}^n$, thì $A\bar{v} = \bar{\lambda}\bar{v}$. Vậy trị riêng không thực của ma trận thực đi thành cặp liên hợp $\lambda$, $\bar\lambda$, với vectơ riêng liên hợp.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Lấy liên hợp từng phần tử hai vế của $Av = \lambda v$. Vì $A$ thực, $\bar{A} = A$, nên $A\bar{v} = \bar{\lambda}\bar{v}$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Với ma trận $2 \times 2$ thực, $p_A(\lambda) = \lambda^2 - (\operatorname{tr} A)\lambda + \det A$ có nghiệm phức khi và chỉ khi $(\operatorname{tr} A)^2 &amp;lt; 4\det A$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Cho $A = \begin{bmatrix} 1 &amp;amp; -2 \\ 1 &amp;amp; 3 \end{bmatrix}$: $\operatorname{tr} A = 4$, $\det A = 5$, $p_A(\lambda) = \lambda^2 - 4\lambda + 5$, nên $\lambda = 2 \pm i$. Với $\lambda = 2 - i$:&lt;/p&gt;

\[A - (2 - i)I = \begin{bmatrix} -1 + i &amp;amp; -2 \\ 1 &amp;amp; 1 + i \end{bmatrix}.\]

  &lt;p&gt;Hàng hai cho $v_1 + (1 + i)v_2 = 0$; chọn $v_2 = 1$ được $v = (-1 - i, 1)$. Kiểm tra hàng một: $(-1 + i)(-1 - i) - 2 = (1 + 1) - 2 = 0$. Vectơ riêng của $2 + i$ là $\bar{v} = (-1 + i, 1)$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;dạng-thực-quay-và-co-giãn&quot;&gt;Dạng thực: quay và co giãn&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2.&lt;/strong&gt; Cho $A$ là ma trận thực $2 \times 2$ có trị riêng $\lambda = a - bi$ với $b \ne 0$ và vectơ riêng $v \in \mathbb{C}^2$. Đặt $P = \begin{bmatrix} \operatorname{Re} v &amp;amp; \operatorname{Im} v \end{bmatrix}$ (ma trận thực). Khi đó $P$ khả nghịch và&lt;/p&gt;

\[A = PCP^{-1}, \qquad C = \begin{bmatrix} a &amp;amp; -b \\ b &amp;amp; a \end{bmatrix} = r\begin{bmatrix} \cos\varphi &amp;amp; -\sin\varphi \\ \sin\varphi &amp;amp; \cos\varphi \end{bmatrix},\]

  &lt;p&gt;với $r = \lvert\lambda\rvert = \sqrt{a^2 + b^2}$ và $\varphi$ là argument của $a + bi$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh (phác thảo).&lt;/strong&gt; Viết $v = x + iy$ với $x, y$ thực. Tách phần thực và phần ảo của $A(x + iy) = (a - bi)(x + iy) = (ax + by) + i(-bx + ay)$: $Ax = ax + by$ và $Ay = -bx + ay$. Đây chính là $AP = PC$ đọc theo cột. Nếu $x$, $y$ phụ thuộc tuyến tính thì $v$ là bội phức của một vectơ thực, và $\lambda$ sẽ thực; vậy $P$ khả nghịch.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; Tiếp Ví dụ 1: $\lambda = 2 - i$ ($a = 2$, $b = 1$), $v = (-1 - i, 1)$, nên $\operatorname{Re} v = (-1, 1)$, $\operatorname{Im} v = (-1, 0)$ và&lt;/p&gt;

\[P = \begin{bmatrix} -1 &amp;amp; -1 \\ 1 &amp;amp; 0 \end{bmatrix}, \qquad C = \begin{bmatrix} 2 &amp;amp; -1 \\ 1 &amp;amp; 2 \end{bmatrix} = \sqrt{5}\begin{bmatrix} \cos\varphi &amp;amp; -\sin\varphi \\ \sin\varphi &amp;amp; \cos\varphi \end{bmatrix},\ \varphi = \arctan\tfrac{1}{2} \approx 26{,}6^\circ.\]

  &lt;p&gt;Trong hệ toạ độ cho bởi các cột của $P$, $A$ là phép quay $26{,}6^\circ$ kèm co giãn $\sqrt{5}$ lần. Trong toạ độ chuẩn, các điểm $A^k x$ chạy trên một đường xoắn ốc dạng elip đi ra xa gốc.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Liên hệ Bài 00-02: ma trận $C = \begin{bmatrix} a &amp;amp; -b \\ b &amp;amp; a \end{bmatrix}$ chính là phép nhân với số phức $a + bi$ trên mặt phẳng.&lt;/p&gt;

&lt;h2 id=&quot;hành-vi-dài-hạn&quot;&gt;Hành vi dài hạn&lt;/h2&gt;

&lt;p&gt;Với $x_{k+1} = Ax_k$ và trị riêng $a \pm bi$, $r = \sqrt{a^2 + b^2}$:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;$r &amp;lt; 1$: các điểm xoắn ốc vào gốc;&lt;/li&gt;
  &lt;li&gt;$r = 1$: các điểm chạy trên một elip (quay thuần tuý trong hệ toạ độ $P$);&lt;/li&gt;
  &lt;li&gt;$r &amp;gt; 1$: các điểm xoắn ốc ra xa.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Trị riêng phức cho biết hệ &lt;em&gt;dao động&lt;/em&gt;; môđun của chúng cho biết dao động tắt dần hay tăng dần.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-chu-kỳ-thú-mồi--kẻ-săn-mồi&quot;&gt;Ứng dụng: chu kỳ thú mồi – kẻ săn mồi&lt;/h2&gt;

&lt;p&gt;Mô hình tuyến tính hoá quanh điểm cân bằng của số lượng thỏ và cáo thường có ma trận với trị riêng phức. Số lượng hai loài khi đó dao động lệch pha: thỏ nhiều thì cáo tăng, cáo nhiều thì thỏ giảm. Góc $\varphi$ cho biết mỗi năm hệ đi được bao nhiêu phần của một chu kỳ (chu kỳ khoảng $2\pi/\varphi$ năm), và $r$ cho biết dao động tắt dần về cân bằng hay ngày càng mạnh. Các chu kỳ khoảng 10 năm của linh miêu và thỏ rừng ở Canada là ví dụ nổi tiếng.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: ma trận quay không có hướng riêng thực&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Cho x quay một vòng: Ax không bao giờ cùng phương với x; trị riêng là số phức.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter09/tri_rieng.html?mode=eig&amp;amp;preset=rot&quot; title=&quot;Minh hoạ: ma trận quay không có hướng riêng thực&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter09/tri_rieng.html?mode=eig&amp;amp;preset=rot&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Tìm trị riêng và vectơ riêng phức của $\begin{bmatrix} 0 &amp;amp; -1 \\ 1 &amp;amp; 0 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$p(\lambda) = \lambda^2 + 1$, $\lambda = \pm i$. Với $\lambda = i$: $(A - iI)v = 0$ cho $-iv_1 - v_2 = 0$, nên $v = (i, 1)$; với $\lambda = -i$: $v = (-i, 1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Tìm trị riêng của $A = \begin{bmatrix} 3 &amp;amp; -5 \\ 1 &amp;amp; -1 \end{bmatrix}$ và hệ số co giãn, góc quay tương ứng.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\operatorname{tr} A = 2$, $\det A = -3 + 5 = 2$, $\lambda^2 - 2\lambda + 2 = 0$, $\lambda = 1 \pm i$. Hệ số co giãn $r = \sqrt{2}$, góc $\varphi = 45^\circ$ (trong hệ toạ độ $P$ thích hợp).

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Chứng minh ma trận quay $R_\theta$ có trị riêng $e^{\pm i\theta}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\operatorname{tr} R_\theta = 2\cos\theta$, $\det R_\theta = 1$, nên $\lambda^2 - 2\cos\theta\,\lambda + 1 = 0$ cho $\lambda = \cos\theta \pm i\sin\theta = e^{\pm i\theta}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Chứng minh: ma trận thực cỡ $3 \times 3$ luôn có ít nhất một trị riêng thực. Áp dụng cho phép quay trong $\mathbb{R}^3$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$p_A$ là đa thức thực bậc 3, có ít nhất một nghiệm thực (đa thức bậc lẻ đổi dấu). Với phép quay $Q$ trong $\mathbb{R}^3$ ($\det Q = 1$), các trị riêng có môđun $1$; nếu hai trị riêng là cặp phức $e^{\pm i\theta}$ thì trị riêng thực còn lại bằng $\det Q / 1 = 1$, và vectơ riêng của nó là trục quay (định lý Euler, Bài 07-07).

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Trị riêng không thực của ma trận thực đi thành cặp liên hợp $a \pm bi$, với vectơ riêng liên hợp.&lt;/li&gt;
    &lt;li&gt;Ma trận $2 \times 2$ thực có trị riêng phức khi $(\operatorname{tr} A)^2 &amp;lt; 4\det A$.&lt;/li&gt;
    &lt;li&gt;Với $\lambda = a - bi$ và vectơ riêng $v$: $A = PCP^{-1}$, $P = [\operatorname{Re} v\ \operatorname{Im} v]$, $C = \begin{bmatrix} a &amp;amp; -b \\ b &amp;amp; a \end{bmatrix}$ là quay góc $\arg(a + bi)$ và co giãn $\lvert\lambda\rvert$.&lt;/li&gt;
    &lt;li&gt;$\lvert\lambda\rvert &amp;lt; 1$, $= 1$, $&amp;gt; 1$: xoắn vào, quay quanh, xoắn ra.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Chéo hoá ma trận</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter09/09_04_Cheo_Hoa_Ma_Tran/"/>
   <updated>2026-01-09T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter09/09_04_Cheo_Hoa_Ma_Tran</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;quyết định một ma trận có chéo hoá được không bằng các bội của trị riêng;&lt;/li&gt;
    &lt;li&gt;viết $A = PDP^{-1}$ với $P$ là ma trận các vectơ riêng và $D$ là ma trận chéo các trị riêng;&lt;/li&gt;
    &lt;li&gt;giải thích chéo hoá là đổi sang cơ sở vectơ riêng (Bài 06-05).&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Ma trận chéo là loại dễ nhất: $D = \begin{bmatrix} 5 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{bmatrix}$ chỉ kéo giãn trục $x$ gấp 5 và trục $y$ gấp 2; $D^{100}$ là $\operatorname{diag}(5^{100}, 2^{100})$. Ma trận $A = \begin{bmatrix} 4 &amp;amp; 1 \\ 2 &amp;amp; 3 \end{bmatrix}$ không chéo, nhưng có vectơ riêng $(1, 1)$ với $\lambda = 5$ và $(1, -2)$ với $\lambda = 2$ (Bài 09-02). Nếu ta dùng hai vectơ này làm hệ trục toạ độ, $A$ cũng chỉ kéo giãn trục thứ nhất gấp 5 và trục thứ hai gấp 2: &lt;em&gt;trong hệ toạ độ đúng&lt;/em&gt;, $A$ chính là $D$.&lt;/p&gt;

&lt;h2 id=&quot;định-lý-chéo-hoá&quot;&gt;Định lý chéo hoá&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Chéo hoá được).&lt;/strong&gt; Ma trận vuông $A$ là &lt;em&gt;chéo hoá được&lt;/em&gt; nếu tồn tại ma trận khả nghịch $P$ và ma trận chéo $D$ sao cho&lt;/p&gt;

  &lt;p&gt;\(A = PDP^{-1}, \quad\text{tương đương}\quad P^{-1}AP = D.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Ma trận $A$ cỡ $n \times n$ chéo hoá được khi và chỉ khi $A$ có $n$ vectơ riêng độc lập tuyến tính. Khi đó, nếu $v_1, \dots, v_n$ là các vectơ riêng độc lập với trị riêng $\lambda_1, \dots, \lambda_n$, thì&lt;/p&gt;

  &lt;p&gt;\(P = \begin{bmatrix} v_1 &amp;amp; \cdots &amp;amp; v_n \end{bmatrix}, \qquad D = \operatorname{diag}(\lambda_1, \dots, \lambda_n).\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Theo cột, $AP = \begin{bmatrix} Av_1 &amp;amp; \cdots &amp;amp; Av_n \end{bmatrix}$ và $PD = \begin{bmatrix} \lambda_1 v_1 &amp;amp; \cdots &amp;amp; \lambda_n v_n \end{bmatrix}$. Vậy $AP = PD$ khi và chỉ khi mỗi cột $v_i$ của $P$ thoả $Av_i = \lambda_i v_i$. Nếu các cột độc lập thì $P$ khả nghịch và $A = PDP^{-1}$. Ngược lại, nếu $A = PDP^{-1}$ thì $AP = PD$, nên các cột của $P$ (khác $0$ vì $P$ khả nghịch) là vectơ riêng, và chúng độc lập.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Hệ quả 1.&lt;/strong&gt;&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;Nếu $A$ có $n$ trị riêng phân biệt thì $A$ chéo hoá được.&lt;/li&gt;
    &lt;li&gt;Tổng quát, $A$ chéo hoá được (trên $\mathbb{R}$) khi và chỉ khi đa thức đặc trưng phân tích thành các nhân tử bậc nhất thực và với mọi trị riêng, bội hình học bằng bội đại số.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; (1) Theo Định lý 3 Bài 09-01, $n$ vectơ riêng của $n$ trị riêng phân biệt thì độc lập. (2) Ghép các cơ sở của mọi không gian riêng; họ thu được độc lập (mở rộng của Định lý 3 Bài 09-01) và có số phần tử bằng tổng các bội hình học. Tổng này bằng $n$ khi và chỉ khi mọi bội hình học bằng bội đại số và tổng các bội đại số bằng $n$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Với $A = \begin{bmatrix} 4 &amp;amp; 1 \\ 2 &amp;amp; 3 \end{bmatrix}$:&lt;/p&gt;

\[P = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -2 \end{bmatrix}, \quad D = \begin{bmatrix} 5 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{bmatrix}, \quad P^{-1} = \frac{1}{3}\begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix}.\]

  &lt;p&gt;Kiểm tra $AP = PD$: $AP = \begin{bmatrix} 5 &amp;amp; 2 \\ 5 &amp;amp; -4 \end{bmatrix}$ và $PD = \begin{bmatrix} 5 &amp;amp; 2 \\ 5 &amp;amp; -4 \end{bmatrix}$. Thứ tự các cột của $P$ phải khớp với thứ tự các trị riêng trên đường chéo của $D$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; Với $A = \begin{bmatrix} 2 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 2 \end{bmatrix}$ (Bài 09-03), trị riêng $1$ có bội đại số và hình học cùng bằng $2$, trị riêng $4$ có cả hai bội bằng $1$. Vậy $A$ chéo hoá được:&lt;/p&gt;

\[P = \begin{bmatrix} 1 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; -1 &amp;amp; 0 \\ 1 &amp;amp; 0 &amp;amp; -1 \end{bmatrix}, \qquad D = \operatorname{diag}(4, 1, 1).\]

  &lt;p&gt;Ngược lại, phép trượt $\begin{bmatrix} 2 &amp;amp; 1 \\ 0 &amp;amp; 2 \end{bmatrix}$ và ma trận $C$ ở Ví dụ 2 Bài 09-03 không chéo hoá được: bội hình học nhỏ hơn bội đại số.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ý-nghĩa-đổi-sang-cơ-sở-vectơ-riêng&quot;&gt;Ý nghĩa: đổi sang cơ sở vectơ riêng&lt;/h2&gt;

&lt;p&gt;Theo Bài 06-05, $P^{-1}AP$ là ma trận của ánh xạ $x \mapsto Ax$ trong cơ sở gồm các cột của $P$. Chéo hoá nghĩa là tìm một cơ sở mà trong đó ánh xạ &lt;em&gt;tách rời&lt;/em&gt; thành $n$ phép co giãn độc lập. Đọc $A = PDP^{-1}$ từ phải sang trái khi tác động lên $x$:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;$P^{-1}x$: tính toạ độ của $x$ theo cơ sở vectơ riêng;&lt;/li&gt;
  &lt;li&gt;$D$: nhân toạ độ thứ $i$ với $\lambda_i$;&lt;/li&gt;
  &lt;li&gt;$P$: đổi về toạ độ chuẩn.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Đây là cách tư duy mạnh nhất của chương: mọi câu hỏi về $A$ (luỹ thừa, hàm mũ, hành vi dài hạn) trở thành câu hỏi về $n$ số $\lambda_i$.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-tách-rời-các-biến&quot;&gt;Ứng dụng: tách rời các biến&lt;/h2&gt;

&lt;p&gt;Hai loài cùng sống trong một hệ sinh thái có số lượng $x_k$, $y_k$ mỗi năm thay đổi theo $\begin{bmatrix} x_{k+1} \\ y_{k+1} \end{bmatrix} = A\begin{bmatrix} x_k \\ y_k \end{bmatrix}$, hai biến ràng buộc lẫn nhau. Đổi biến $\begin{bmatrix} u \\ w \end{bmatrix} = P^{-1}\begin{bmatrix} x \\ y \end{bmatrix}$ cho $u_{k+1} = \lambda_1 u_k$, $w_{k+1} = \lambda_2 w_k$: hai phương trình độc lập, giải ngay. Kỹ thuật “chuyển sang toạ độ riêng” này là cách giải tiêu chuẩn cho hệ dao động, mạch điện, và mô hình kinh tế tuyến tính (Bài 09-06, 09-07).&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: chéo hoá A = PDP⁻¹ từng bước&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo thanh bước: P⁻¹ đổi sang toạ độ riêng, D kéo dãn, P đưa về.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter09/tri_rieng.html?mode=diag&amp;amp;preset=gen&quot; title=&quot;Minh hoạ: chéo hoá A = PDP⁻¹ từng bước&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter09/tri_rieng.html?mode=diag&amp;amp;preset=gen&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Chéo hoá $\begin{bmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 1 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Trị riêng $3$, $-1$ với vectơ riêng $(1, 1)$, $(1, -1)$ (Bài tập 1, Bài 09-02). $P = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix}$, $D = \operatorname{diag}(3, -1)$, $P^{-1} = \tfrac{1}{2}\begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Chéo hoá $\begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 2 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Tam giác, trị riêng $1$ và $2$ phân biệt. $\lambda = 1$: $(1, 0)$; $\lambda = 2$: $(1, 1)$. $P = \begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \end{bmatrix}$, $D = \operatorname{diag}(1, 2)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Ma trận nào chéo hoá được? (a) $\begin{bmatrix} 3 &amp;amp; 0 \\ 0 &amp;amp; 3 \end{bmatrix}$; (b) $\begin{bmatrix} 3 &amp;amp; 1 \\ 0 &amp;amp; 3 \end{bmatrix}$; (c) $\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 3 \\ 0 &amp;amp; 4 &amp;amp; 5 \\ 0 &amp;amp; 0 &amp;amp; 6 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

(a) Có, đã chéo. (b) Không: $\lambda = 3$ bội đại số $2$, bội hình học $1$. (c) Có: ba trị riêng phân biệt $1, 4, 6$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Tìm ma trận $A$ có trị riêng $2$ với vectơ riêng $(1, 1)$ và trị riêng $-1$ với vectơ riêng $(1, 2)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A = PDP^{-1}$ với $P = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$, $D = \operatorname{diag}(2, -1)$, $P^{-1} = \begin{bmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 1 \end{bmatrix}$. Tính được $A = \begin{bmatrix} 5 &amp;amp; -3 \\ 6 &amp;amp; -4 \end{bmatrix}$. Kiểm tra: $A(1,1) = (2, 2)$, $A(1,2) = (-1, -2)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Chứng minh: nếu $A$ chéo hoá được và mọi trị riêng bằng $\lambda$ thì $A = \lambda I$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$D = \lambda I$, nên $A = P(\lambda I)P^{-1} = \lambda PP^{-1} = \lambda I$. Hệ quả: một ma trận có trị riêng duy nhất mà khác $\lambda I$ (như phép trượt) thì không chéo hoá được.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$A = PDP^{-1}$: cột của $P$ là vectơ riêng, đường chéo của $D$ là trị riêng theo cùng thứ tự; kiểm tra bằng $AP = PD$.&lt;/li&gt;
    &lt;li&gt;Chéo hoá được $\iff$ có $n$ vectơ riêng độc lập $\iff$ mọi bội hình học bằng bội đại số (và $p_A$ phân tích hoàn toàn).&lt;/li&gt;
    &lt;li&gt;$n$ trị riêng phân biệt thì chắc chắn chéo hoá được.&lt;/li&gt;
    &lt;li&gt;Chéo hoá là đổi sang cơ sở vectơ riêng, nơi $A$ tách thành $n$ phép co giãn độc lập.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Không gian riêng và bội của trị riêng</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter09/09_03_Khong_Gian_Rieng_Va_Boi_Cua_Tri_Rieng/"/>
   <updated>2026-01-09T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter09/09_03_Khong_Gian_Rieng_Va_Boi_Cua_Tri_Rieng</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;tìm cơ sở của không gian riêng $E_\lambda = \operatorname{Null}(A - \lambda I)$;&lt;/li&gt;
    &lt;li&gt;phân biệt bội đại số và bội hình học của một trị riêng;&lt;/li&gt;
    &lt;li&gt;dùng bất đẳng thức $1 \le$ bội hình học $\le$ bội đại số để dự đoán số vectơ riêng độc lập.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Hai ma trận&lt;/p&gt;

\[A = \begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{bmatrix}, \qquad B = \begin{bmatrix} 2 &amp;amp; 1 \\ 0 &amp;amp; 2 \end{bmatrix}\]

&lt;p&gt;có cùng đa thức đặc trưng $(\lambda - 2)^2$, cùng trị riêng kép $\lambda = 2$. Nhưng $A = 2I$ kéo giãn &lt;em&gt;mọi&lt;/em&gt; vectơ gấp đôi: mọi hướng đều là hướng riêng. Còn $B$ là phép trượt kèm co giãn, chỉ giữ nguyên trục $x$: $B - 2I = \begin{bmatrix} 0 &amp;amp; 1 \\ 0 &amp;amp; 0 \end{bmatrix}$ có không gian không một chiều. Cùng “số lần lặp” trong đa thức đặc trưng, nhưng số hướng riêng khác nhau. Bài này đặt tên cho hai đại lượng đó.&lt;/p&gt;

&lt;h2 id=&quot;không-gian-riêng&quot;&gt;Không gian riêng&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Không gian riêng).&lt;/strong&gt; Với trị riêng $\lambda$ của $A$, &lt;em&gt;không gian riêng&lt;/em&gt; là&lt;/p&gt;

\[E_\lambda = \operatorname{Null}(A - \lambda I) = \{v : Av = \lambda v\}.\]

  &lt;p&gt;Nó gồm mọi vectơ riêng ứng với $\lambda$ cùng vectơ $0$, và là một không gian con.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 2 (Bội đại số, bội hình học).&lt;/strong&gt; Với trị riêng $\lambda$ của $A$:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;&lt;em&gt;bội đại số&lt;/em&gt; là số lần $\lambda$ là nghiệm của đa thức đặc trưng (số mũ của $(\lambda - \lambda_0)$ khi phân tích $p_A$);&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;bội hình học&lt;/em&gt; là $\dim E_\lambda$, số vectơ riêng độc lập tuyến tính tối đa ứng với $\lambda$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;p&gt;Ở ví dụ mở đầu, $\lambda = 2$ có bội đại số $2$ trong cả hai ma trận; bội hình học là $2$ với $A$ và $1$ với $B$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Với mọi trị riêng $\lambda$: $1 \le \text{bội hình học} \le \text{bội đại số}$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Bội hình học $\ge 1$ vì $\lambda$ có ít nhất một vectơ riêng. Gọi $g = \dim E_\lambda$ và chọn cơ sở $v_1, \dots, v_g$ của $E_\lambda$, bổ sung thành cơ sở của $\mathbb{R}^n$ và đặt các vectơ đó làm cột của $P$. Khi đó $P^{-1}AP = \begin{bmatrix} \lambda I_g &amp;amp; * \\ 0 &amp;amp; C \end{bmatrix}$, vì $g$ cột đầu được $A$ biến thành $\lambda v_i$. Ma trận đồng dạng có cùng đa thức đặc trưng, và đa thức này là $(\lambda_0 - \lambda)^g \det(C - \lambda I)$ (với $\lambda_0$ là trị riêng đang xét), nên $(\lambda - \lambda_0)^g$ chia hết $p_A$: bội đại số ít nhất là $g$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Với $A = \begin{bmatrix} 2 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 2 \end{bmatrix}$ (Ví dụ 2, Bài 09-02), $p_A(\lambda) = -(\lambda - 4)(\lambda - 1)^2$.&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$\lambda = 1$, bội đại số $2$. $A - I$ là ma trận toàn số $1$, hạng 1, nên $\dim E_1 = 3 - 1 = 2$. Cơ sở: $(1, -1, 0)$, $(1, 0, -1)$. Bội hình học $2$.&lt;/li&gt;
    &lt;li&gt;$\lambda = 4$, bội đại số $1$, nên bội hình học cũng là $1$: $E_4 = \operatorname{span}\{(1, 1, 1)\}$.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Tổng các bội hình học là $3$: $A$ có ba vectơ riêng độc lập, đủ làm một cơ sở của $\mathbb{R}^3$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; Với $C = \begin{bmatrix} 3 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 3 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 5 \end{bmatrix}$ (tam giác trên): trị riêng $3$ (bội đại số $2$) và $5$ (bội đại số $1$). $C - 3I = \begin{bmatrix} 0 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 2 \end{bmatrix}$ có hạng 2, nên $\dim E_3 = 1$, $E_3 = \operatorname{span}\{e_1\}$. Tổng các bội hình học chỉ là $2 &amp;lt; 3$: $C$ không có đủ ba vectơ riêng độc lập.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Hai ví dụ cho thấy một tiêu chí sẽ dùng ở Bài 09-04: ma trận có cơ sở gồm các vectơ riêng khi và chỉ khi với mọi trị riêng, bội hình học bằng bội đại số (và đa thức đặc trưng phân tích hoàn toàn).&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-trạng-thái-suy-biến-trong-cơ-học-lượng-tử&quot;&gt;Ứng dụng: trạng thái suy biến trong cơ học lượng tử&lt;/h2&gt;

&lt;p&gt;Trong cơ học lượng tử, các mức năng lượng của một hệ là trị riêng của một toán tử (ma trận) đối xứng, gọi là Hamiltonian, và các trạng thái là vectơ riêng. Một mức năng lượng có bội hình học lớn hơn 1 gọi là &lt;em&gt;suy biến&lt;/em&gt;: nhiều trạng thái độc lập có cùng năng lượng, thường do đối xứng của hệ (như $A$ ở Ví dụ 1 có đối xứng hoán vị ba toạ độ). Khi đặt hệ vào từ trường, đối xứng bị phá vỡ và mức suy biến tách thành nhiều mức gần nhau (hiệu ứng Zeeman), quan sát được bằng phổ kế.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: không gian riêng và bội của trị riêng&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;So sánh 2I (mọi vectơ đều riêng) với phép trượt (λ kép nhưng chỉ một hướng riêng).&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter09/tri_rieng.html?mode=eig&amp;amp;preset=shear&quot; title=&quot;Minh hoạ: không gian riêng và bội của trị riêng&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter09/tri_rieng.html?mode=eig&amp;amp;preset=shear&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Tìm các trị riêng, bội đại số, bội hình học và cơ sở các không gian riêng của $\begin{bmatrix} 5 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 5 &amp;amp; 0 \\ 1 &amp;amp; 0 &amp;amp; 5 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Tam giác dưới, trị riêng duy nhất $5$ với bội đại số $3$. $A - 5I$ chỉ có phần tử khác $0$ ở vị trí $(3, 1)$, hạng 1, nên $\dim E_5 = 2$, cơ sở $e_2$, $e_3$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Với giá trị nào của $a$ thì $\begin{bmatrix} 1 &amp;amp; a \\ 0 &amp;amp; 1 \end{bmatrix}$ có bội hình học của $\lambda = 1$ bằng $2$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Cần $A - I = \begin{bmatrix} 0 &amp;amp; a \\ 0 &amp;amp; 0 \end{bmatrix}$ có hạng $0$, tức $a = 0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Cho phép chiếu $P$ lên một mặt phẳng $W$ trong $\mathbb{R}^3$. Tìm các không gian riêng và các bội.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$E_1 = W$ (bội $2$) và $E_0 = W^\perp$ (bội $1$). Bội đại số bằng bội hình học vì tổng các bội hình học đã là $3$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (nâng cao).&lt;/strong&gt; Chứng minh: nếu $AB = BA$ và $v \in E_\lambda(A)$ thì $Bv \in E_\lambda(A)$. (Không gian riêng của $A$ bất biến dưới $B$.)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A(Bv) = B(Av) = B(\lambda v) = \lambda (Bv)$. Kết quả này là bước then chốt để chéo hoá đồng thời các ma trận giao hoán.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Không gian riêng $E_\lambda = \operatorname{Null}(A - \lambda I)$ gồm các vectơ riêng của $\lambda$ và vectơ $0$.&lt;/li&gt;
    &lt;li&gt;Bội đại số: số lần nghiệm trong $p_A$; bội hình học: $\dim E_\lambda = n - \operatorname{rank}(A - \lambda I)$.&lt;/li&gt;
    &lt;li&gt;$1 \le$ bội hình học $\le$ bội đại số; cùng đa thức đặc trưng không có nghĩa là cùng số hướng riêng.&lt;/li&gt;
    &lt;li&gt;Đủ $n$ vectơ riêng độc lập khi và chỉ khi mọi bội hình học bằng bội đại số.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Đa thức đặc trưng</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter09/09_02_Da_Thuc_Dac_Trung/"/>
   <updated>2026-01-09T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter09/09_02_Da_Thuc_Dac_Trung</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;lập đa thức đặc trưng $\det(A - \lambda I)$ và tìm trị riêng của ma trận $2 \times 2$, $3 \times 3$;&lt;/li&gt;
    &lt;li&gt;tìm vectơ riêng bằng cách giải $(A - \lambda I)v = 0$;&lt;/li&gt;
    &lt;li&gt;dùng $\operatorname{tr} A = \sum \lambda_i$ và $\det A = \prod \lambda_i$ để kiểm tra kết quả.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Ở Bài 09-01, ta được &lt;em&gt;cho&lt;/em&gt; các vectơ riêng rồi kiểm tra. Nhưng với $A = \begin{bmatrix} 4 &amp;amp; 1 \\ 2 &amp;amp; 3 \end{bmatrix}$, làm sao &lt;em&gt;tìm&lt;/em&gt; chúng? Định lý 1 của Bài 09-01 đổi câu hỏi hình học thành một phương trình: $\lambda$ là trị riêng khi và chỉ khi $\det(A - \lambda I) = 0$. Ở đây&lt;/p&gt;

\[\det\begin{bmatrix} 4 - \lambda &amp;amp; 1 \\ 2 &amp;amp; 3 - \lambda \end{bmatrix} = (4 - \lambda)(3 - \lambda) - 2 = \lambda^2 - 7\lambda + 10 = (\lambda - 5)(\lambda - 2).\]

&lt;p&gt;Hai trị riêng là $5$ và $2$. Một phương trình bậc hai đã thay cho việc dò mọi hướng trong mặt phẳng.&lt;/p&gt;

&lt;h2 id=&quot;đa-thức-đặc-trưng&quot;&gt;Đa thức đặc trưng&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Đa thức đặc trưng).&lt;/strong&gt; &lt;em&gt;Đa thức đặc trưng&lt;/em&gt; của ma trận vuông $A$ cỡ $n \times n$ là&lt;/p&gt;

\[p_A(\lambda) = \det(A - \lambda I).\]

  &lt;p&gt;Đây là đa thức bậc $n$ theo $\lambda$, và các trị riêng của $A$ là các nghiệm của &lt;em&gt;phương trình đặc trưng&lt;/em&gt; $p_A(\lambda) = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Khai triển định thức, mỗi số hạng là tích của $n$ phần tử, mỗi phần tử có dạng $a_{ij}$ hoặc $a_{ii} - \lambda$, nên $p_A$ có bậc $n$, hệ số cao nhất $(-1)^n$. Vì vậy ma trận $n \times n$ có nhiều nhất $n$ trị riêng; theo định lý cơ bản của đại số (Bài 00-02), có đúng $n$ trị riêng phức tính cả bội.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quy trình tìm trị riêng và vectơ riêng.&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Tính $p_A(\lambda) = \det(A - \lambda I)$ và giải $p_A(\lambda) = 0$.&lt;/li&gt;
  &lt;li&gt;Với mỗi trị riêng $\lambda$, giải hệ thuần nhất $(A - \lambda I)v = 0$ bằng khử Gauss.&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (tiếp ví dụ mở đầu).&lt;/strong&gt; Với $\lambda = 5$: $A - 5I = \begin{bmatrix} -1 &amp;amp; 1 \\ 2 &amp;amp; -2 \end{bmatrix}$, hàng hai là $-2$ lần hàng một, nghiệm $v_1 = v_2$: vectơ riêng $(1, 1)$. Với $\lambda = 2$: $A - 2I = \begin{bmatrix} 2 &amp;amp; 1 \\ 2 &amp;amp; 1 \end{bmatrix}$, nghiệm $2v_1 + v_2 = 0$: vectơ riêng $(1, -2)$. Kiểm tra: $A(1, -2) = (2, -4) = 2(1, -2)$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Nhận xét: ở bước 2, ma trận $A - \lambda I$ &lt;em&gt;phải&lt;/em&gt; suy biến. Nếu khử Gauss cho nghiệm duy nhất $v = 0$, thì $\lambda$ đã tính sai.&lt;/p&gt;

&lt;h2 id=&quot;vết-và-định-thức&quot;&gt;Vết và định thức&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Nếu $\lambda_1, \dots, \lambda_n$ là các trị riêng (phức, tính cả bội) của $A$ thì&lt;/p&gt;

\[\lambda_1 + \dots + \lambda_n = \operatorname{tr} A = a_{11} + \dots + a_{nn}, \qquad \lambda_1 \lambda_2 \cdots \lambda_n = \det A.\]

  &lt;p&gt;Với ma trận $2 \times 2$: $p_A(\lambda) = \lambda^2 - (\operatorname{tr} A)\lambda + \det A$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh (phác thảo).&lt;/strong&gt; Viết $p_A(\lambda) = (\lambda_1 - \lambda)\cdots(\lambda_n - \lambda)$. Thay $\lambda = 0$: $\det A = p_A(0) = \lambda_1 \cdots \lambda_n$. Hệ số của $\lambda^{n-1}$ ở vế phải là $(-1)^{n-1}\sum \lambda_i$. Trong khai triển $\det(A - \lambda I)$, chỉ tích các phần tử đường chéo $\prod(a_{ii} - \lambda)$ cho được $\lambda^{n-1}$ (mọi số hạng khác thiếu ít nhất hai phần tử đường chéo), và hệ số của nó là $(-1)^{n-1}\sum a_{ii}$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Kiểm tra Ví dụ 1: $5 + 2 = 7 = 4 + 3$ và $5 \cdot 2 = 10 = 12 - 2$. Hệ quả: $A$ khả nghịch khi và chỉ khi $0$ không phải trị riêng.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (ma trận $3 \times 3$).&lt;/strong&gt; Cho $A = \begin{bmatrix} 2 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 2 \end{bmatrix}$. Thay vì khai triển, quan sát: $A = I + J$ với $J$ là ma trận toàn số $1$. Ta có $J(1,1,1) = 3(1,1,1)$, và $J$ có hạng 1 nên $Jv = 0$ với mọi $v$ trong mặt phẳng $v_1 + v_2 + v_3 = 0$. Vậy trị riêng của $A$ là $1 + 3 = 4$ (vectơ $(1,1,1)$) và $1 + 0 = 1$ (mặt phẳng $v_1 + v_2 + v_3 = 0$, hai chiều). Đa thức đặc trưng $p_A(\lambda) = -(\lambda - 4)(\lambda - 1)^2$. Kiểm tra: $4 + 1 + 1 = 6 = \operatorname{tr} A$ và $4 \cdot 1 \cdot 1 = 4 = \det A$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-tần-số-dao-động&quot;&gt;Ứng dụng: tần số dao động&lt;/h2&gt;

&lt;p&gt;Hai vật nặng nối với nhau và với hai bức tường bằng ba lò xo giống nhau dao động theo phương trình $x&apos;&apos; = -Kx$ với $K = \begin{bmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{bmatrix}$ (đơn vị phù hợp). Tìm nghiệm dạng $x = v\cos(\omega t)$ dẫn đến $Kv = \omega^2 v$: bình phương tần số là trị riêng của $K$. Đa thức đặc trưng $\lambda^2 - 4\lambda + 3$ cho $\lambda = 1$ và $3$: hai &lt;em&gt;mode dao động riêng&lt;/em&gt;, một mode hai vật cùng chiều ($v = (1, 1)$, $\omega = 1$), một mode ngược chiều ($v = (1, -1)$, $\omega = \sqrt{3}$). Kỹ sư tính các trị riêng như vậy để tránh cầu, toà nhà cộng hưởng với gió hay động đất.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: đa thức đặc trưng&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Chọn các ma trận mẫu; vết và định thức cho đa thức đặc trưng và hai trị riêng.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter09/tri_rieng.html?mode=eig&amp;amp;preset=gen&quot; title=&quot;Minh hoạ: đa thức đặc trưng&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter09/tri_rieng.html?mode=eig&amp;amp;preset=gen&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Tìm trị riêng và vectơ riêng của $\begin{bmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 1 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$p(\lambda) = \lambda^2 - 2\lambda - 3 = (\lambda - 3)(\lambda + 1)$. $\lambda = 3$: $(1, 1)$; $\lambda = -1$: $(1, -1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Tìm trị riêng và vectơ riêng của $A = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 \\ 0 &amp;amp; 3 &amp;amp; 0 \\ 2 &amp;amp; -4 &amp;amp; 2 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Khai triển theo cột 3: $p(\lambda) = (2 - \lambda)\left[(1 - \lambda)(3 - \lambda)\right]$, nên $\lambda = 1, 2, 3$. Vectơ riêng: $\lambda = 1$: $(1, 0, -2)$; $\lambda = 2$: $(0, 0, 1)$; $\lambda = 3$: $(1, 1, -2)$. Kiểm tra vết: $1 + 2 + 3 = 6 = 1 + 3 + 2$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Ma trận $2 \times 2$ có vết $6$ và định thức $8$. Tìm các trị riêng.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\lambda^2 - 6\lambda + 8 = 0$, nên $\lambda = 2$ và $4$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Chứng minh: nếu $A^2 = 0$ thì mọi trị riêng của $A$ bằng $0$. Cho một ví dụ $A \ne 0$ như vậy.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Nếu $Av = \lambda v$, $v \ne 0$, thì $0 = A^2v = \lambda^2v$, nên $\lambda = 0$. Ví dụ $A = \begin{bmatrix} 0 &amp;amp; 1 \\ 0 &amp;amp; 0 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Chứng minh hai ma trận đồng dạng $B = P^{-1}AP$ có cùng đa thức đặc trưng.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$B - \lambda I = P^{-1}(A - \lambda I)P$, nên $\det(B - \lambda I) = \det(P^{-1})\det(A - \lambda I)\det P = \det(A - \lambda I)$. Vậy trị riêng, vết và định thức là thuộc tính của ánh xạ tuyến tính, không phụ thuộc cơ sở (Bài 06-05).

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Đa thức đặc trưng $p_A(\lambda) = \det(A - \lambda I)$ có bậc $n$; trị riêng là nghiệm của nó.&lt;/li&gt;
    &lt;li&gt;Vectơ riêng: giải $(A - \lambda I)v = 0$; ma trận này phải suy biến.&lt;/li&gt;
    &lt;li&gt;$\sum \lambda_i = \operatorname{tr} A$, $\prod \lambda_i = \det A$; với $2 \times 2$: $p_A(\lambda) = \lambda^2 - (\operatorname{tr} A)\lambda + \det A$.&lt;/li&gt;
    &lt;li&gt;Ma trận đồng dạng có cùng đa thức đặc trưng.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Trị riêng và vectơ riêng</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter09/09_01_Tri_Rieng_Va_Vecto_Rieng/"/>
   <updated>2026-01-09T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter09/09_01_Tri_Rieng_Va_Vecto_Rieng</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;phát biểu định nghĩa $Av = \lambda v$ và kiểm tra một vectơ cho trước có phải vectơ riêng không;&lt;/li&gt;
    &lt;li&gt;tìm trị riêng, vectơ riêng của các phép biến đổi hình học (chiếu, phản xạ, quay, co giãn) bằng hình học, không cần tính;&lt;/li&gt;
    &lt;li&gt;nhận ra $\lambda$ là trị riêng khi và chỉ khi $A - \lambda I$ suy biến.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Xét $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$ tác động lên các vectơ của mặt phẳng. Hầu hết vectơ bị xoay đi: $Ae_1 = (2, 1)$ không cùng phương với $e_1 = (1, 0)$. Nhưng có hai hướng đặc biệt:&lt;/p&gt;

\[A\begin{bmatrix} 1 \\ 1 \end{bmatrix} = \begin{bmatrix} 3 \\ 3 \end{bmatrix} = 3\begin{bmatrix} 1 \\ 1 \end{bmatrix}, \qquad A\begin{bmatrix} 1 \\ -1 \end{bmatrix} = \begin{bmatrix} 1 \\ -1 \end{bmatrix} = 1 \cdot \begin{bmatrix} 1 \\ -1 \end{bmatrix}.\]

&lt;p&gt;Trên đường chéo $y = x$, $A$ chỉ kéo giãn gấp 3; trên đường $y = -x$, $A$ giữ nguyên. Biết hai hướng này là biết toàn bộ $A$: mọi vectơ là tổ hợp $c_1(1,1) + c_2(1,-1)$, và $A$ biến nó thành $3c_1(1,1) + c_2(1,-1)$. Chương này là về việc tìm những hướng như vậy.&lt;/p&gt;

&lt;h2 id=&quot;định-nghĩa&quot;&gt;Định nghĩa&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Trị riêng, vectơ riêng).&lt;/strong&gt; Cho $A$ là ma trận vuông $n \times n$. Số $\lambda$ là một &lt;em&gt;trị riêng&lt;/em&gt; của $A$ nếu tồn tại vectơ $v \ne 0$ sao cho&lt;/p&gt;

\[Av = \lambda v.\]

  &lt;p&gt;Khi đó $v$ là một &lt;em&gt;vectơ riêng&lt;/em&gt; ứng với $\lambda$. Tổng quát hơn, định nghĩa giống hệt cho ánh xạ tuyến tính $T : V \to V$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Điều kiện $v \ne 0$ là bắt buộc: $A0 = \lambda 0$ đúng với mọi $\lambda$. Nhưng $\lambda = 0$ được phép: $Av = 0v = 0$ với $v \ne 0$ nghĩa là $v \in \operatorname{Null} A$.&lt;/p&gt;

&lt;p&gt;Nếu $v$ là vectơ riêng thì mọi $cv$ ($c \ne 0$) cũng là vectơ riêng với cùng $\lambda$: vectơ riêng là một &lt;em&gt;hướng&lt;/em&gt; (đường thẳng qua gốc) chứ không phải một vectơ.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; $\lambda$ là trị riêng của $A$ khi và chỉ khi $A - \lambda I$ suy biến, khi và chỉ khi $\det(A - \lambda I) = 0$. Các vectơ riêng ứng với $\lambda$ là các vectơ khác $0$ của $\operatorname{Null}(A - \lambda I)$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; $Av = \lambda v \iff (A - \lambda I)v = 0$. Có $v \ne 0$ như vậy khi và chỉ khi $\operatorname{Null}(A - \lambda I) \ne \{0\}$, khi và chỉ khi $A - \lambda I$ không khả nghịch, khi và chỉ khi định thức bằng $0$ (Chương 04).&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;trị-riêng-của-các-phép-biến-đổi-hình-học&quot;&gt;Trị riêng của các phép biến đổi hình học&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;&lt;em&gt;Phép chiếu&lt;/em&gt; $P$ lên đường thẳng $L$ trong $\mathbb{R}^2$: vectơ trên $L$ giữ nguyên ($\lambda = 1$), vectơ vuông góc với $L$ bị biến thành $0$ ($\lambda = 0$).&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;Phép phản xạ&lt;/em&gt; qua $L$: vectơ trên $L$ giữ nguyên ($\lambda = 1$), vectơ vuông góc với $L$ đổi chiều ($\lambda = -1$).&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;Phép co giãn&lt;/em&gt; $\begin{bmatrix} 3 &amp;amp; 0 \\ 0 &amp;amp; 1/2 \end{bmatrix}$: $e_1$ với $\lambda = 3$, $e_2$ với $\lambda = \tfrac{1}{2}$.&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;Phép quay&lt;/em&gt; $90^\circ$: mọi vectơ khác $0$ đều bị quay, không có trị riêng thực (sẽ có trị riêng phức $\pm i$, Bài 09-05).&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;Phép trượt&lt;/em&gt; $\begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \end{bmatrix}$: chỉ có trục $x$ giữ nguyên ($\lambda = 1$); mọi hướng khác bị nghiêng đi.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2.&lt;/strong&gt; Trị riêng của một ma trận tam giác (trên hoặc dưới) là các phần tử trên đường chéo của nó.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; $A - \lambda I$ cũng tam giác, với đường chéo $a_{ii} - \lambda$. Định thức của ma trận tam giác là tích đường chéo, nên $\det(A - \lambda I) = \prod_i (a_{ii} - \lambda)$, bằng $0$ đúng khi $\lambda$ là một $a_{ii}$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 3.&lt;/strong&gt; Các vectơ riêng $v_1, \dots, v_k$ ứng với các trị riêng &lt;em&gt;phân biệt&lt;/em&gt; $\lambda_1, \dots, \lambda_k$ thì độc lập tuyến tính.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Giả sử ngược lại và gọi $j$ là chỉ số nhỏ nhất sao cho $v_j$ là tổ hợp của $v_1, \dots, v_{j-1}$ (độc lập): $v_j = \sum_{i&amp;lt;j} c_i v_i$. Nhân với $A$: $\lambda_j v_j = \sum_{i&amp;lt;j} c_i \lambda_i v_i$. Trừ đi $\lambda_j$ lần đẳng thức đầu: $0 = \sum_{i&amp;lt;j} c_i(\lambda_i - \lambda_j)v_i$. Vì $v_1, \dots, v_{j-1}$ độc lập và $\lambda_i \ne \lambda_j$, mọi $c_i = 0$, nên $v_j = 0$, mâu thuẫn.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-pagerank&quot;&gt;Ứng dụng: PageRank&lt;/h2&gt;

&lt;p&gt;Google xếp hạng trang web bằng cách coi mạng là một ma trận $M$: phần tử $m_{ij}$ là xác suất một người lướt web đi từ trang $j$ sang trang $i$. Vectơ “độ quan trọng” $r$ của các trang thoả $Mr = r$: nó là vectơ riêng ứng với trị riêng $1$. Ma trận có hàng tỷ hàng, nhưng chỉ cần một vectơ riêng, tìm bằng phép lặp luỹ thừa (Bài 09-06). Chương 13 trình bày chi tiết.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: trị riêng và vectơ riêng&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo x quanh đường tròn đơn vị: khi Ax cùng phương với x, đó là vectơ riêng.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter09/tri_rieng.html?mode=eig&quot; title=&quot;Minh hoạ: trị riêng và vectơ riêng&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter09/tri_rieng.html?mode=eig&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-hướng-nào-không-bị-xoay&quot;&gt;Video ngắn: Hướng nào không bị xoay?&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/eigen-directions.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;24 vectơ đơn vị dưới tác động của A = [2 1; 1 2]: hầu hết bị xoay, chỉ hai hướng (1; 1) và (1; −1) giữ nguyên hướng, giãn 3 lần và 1 lần. Tìm trị riêng bằng det(A − λ I) = λ² − 4λ + 3 = 0. Phép trượt chỉ có một hướng riêng; phép quay 60° không có hướng riêng thực. Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Kiểm tra $(1, 2)$ và $(1, -1)$ là vectơ riêng của $A = \begin{bmatrix} 1 &amp;amp; 2 \\ 4 &amp;amp; 3 \end{bmatrix}$ và tìm trị riêng tương ứng. Vectơ $(1, 0)$ có phải vectơ riêng không?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A(1,2) = (5, 10) = 5(1, 2)$ và $A(1,-1) = (-1, 1) = -1 \cdot (1, -1)$: trị riêng $5$ và $-1$. $A(1,0) = (1, 4)$ không cùng phương với $(1, 0)$, nên không phải.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Không tính toán, tìm trị riêng và vectơ riêng của phép phản xạ qua mặt phẳng $z = 0$ trong $\mathbb{R}^3$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Mọi vectơ trong mặt phẳng $z = 0$ giữ nguyên: $\lambda = 1$ với không gian riêng $\operatorname{span}\{e_1, e_2\}$. Trục $z$ đổi chiều: $\lambda = -1$ với vectơ riêng $e_3$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Chứng minh: nếu $Av = \lambda v$ thì $A^2v = \lambda^2v$, và nếu $A$ khả nghịch thì $A^{-1}v = \lambda^{-1}v$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A^2v = A(\lambda v) = \lambda Av = \lambda^2 v$. Nếu $A$ khả nghịch thì $\lambda \ne 0$ (nếu không $Av = 0$ với $v \ne 0$); nhân $Av = \lambda v$ với $\lambda^{-1}A^{-1}$ được $\lambda^{-1}v = A^{-1}v$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Chứng minh $A$ và $A^T$ có cùng trị riêng.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\det(A^T - \lambda I) = \det((A - \lambda I)^T) = \det(A - \lambda I)$. (Vectơ riêng thì nói chung khác nhau.)

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Trên không gian các hàm khả vi vô hạn, tìm mọi “vectơ riêng” của phép đạo hàm $D(f) = f&apos;$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$f&apos; = \lambda f$ có nghiệm $f(x) = ce^{\lambda x}$. Mọi số $\lambda$ đều là trị riêng, với vectơ riêng $e^{\lambda x}$. Đây là lý do hàm mũ xuất hiện khi giải phương trình vi phân tuyến tính (Bài 09-07).

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$Av = \lambda v$, $v \ne 0$: $v$ là hướng được giữ nguyên, $\lambda$ là hệ số co giãn (có thể âm hoặc bằng $0$).&lt;/li&gt;
    &lt;li&gt;$\lambda$ là trị riêng $\iff$ $\det(A - \lambda I) = 0$; vectơ riêng là các vectơ khác $0$ của $\operatorname{Null}(A - \lambda I)$.&lt;/li&gt;
    &lt;li&gt;Ma trận tam giác: trị riêng là đường chéo. Phép chiếu: $1, 0$; phản xạ: $1, -1$; quay: không có trị riêng thực.&lt;/li&gt;
    &lt;li&gt;Vectơ riêng của các trị riêng phân biệt thì độc lập tuyến tính.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>The Cayley–Hamilton Theorem and Jordan Form</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter09/09_08_Dinh_Ly_Cayley_Hamilton_Va_Dang_Jordan/"/>
   <updated>2026-01-09T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter09/09_08_Dinh_Ly_Cayley_Hamilton_Va_Dang_Jordan</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;state the Cayley–Hamilton theorem and use it to compute $A^{-1}$ and powers of $A$;&lt;/li&gt;
    &lt;li&gt;recognize a Jordan block and compute its powers and exponential;&lt;/li&gt;
    &lt;li&gt;find the Jordan form of a $2 \times 2$ matrix with a repeated eigenvalue.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;p&gt;This lesson is &lt;strong&gt;optional&lt;/strong&gt;: later chapters do not use it directly, but it explains what happens when a matrix is &lt;em&gt;not&lt;/em&gt; diagonalizable (Lesson 09-04).&lt;/p&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;For $A = \begin{bmatrix} 4 &amp;amp; 1 \\ 2 &amp;amp; 3 \end{bmatrix}$ the characteristic polynomial is $p(\lambda) = \lambda^2 - 7\lambda + 10$. Substitute $A$ for $\lambda$ (and $10I$ for $10$):&lt;/p&gt;

\[A^2 = \begin{bmatrix} 18 &amp;amp; 7 \\ 14 &amp;amp; 11 \end{bmatrix}, \qquad A^2 - 7A + 10I = \begin{bmatrix} 18 - 28 + 10 &amp;amp; 7 - 7 \\ 14 - 14 &amp;amp; 11 - 21 + 10 \end{bmatrix} = 0.\]

&lt;p&gt;This is no coincidence.&lt;/p&gt;

&lt;h2 id=&quot;the-cayleyhamilton-theorem&quot;&gt;The Cayley–Hamilton theorem&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Cayley–Hamilton).&lt;/strong&gt; If $p(\lambda) = \det(\lambda I - A)$ is the characteristic polynomial of a square matrix $A$, then $p(A) = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof (diagonalizable case).&lt;/strong&gt; With $A = PDP^{-1}$ we have $A^k = PD^kP^{-1}$, so $p(A) = Pp(D)P^{-1}$, where $p(D) = \operatorname{diag}(p(\lambda_1), \dots, p(\lambda_n)) = 0$ because each $\lambda_i$ is a root of $p$. The general case follows from the Jordan form (below) or from the adjugate matrix; we omit it here.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Consequences.&lt;/strong&gt; For $n = 2$: $A^2 - (\operatorname{tr} A)A + (\det A)I = 0$.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;em&gt;Inverse.&lt;/em&gt; If $\det A \neq 0$, multiply by $A^{-1}$: $A^{-1} = \dfrac{(\operatorname{tr} A)I - A}{\det A}$. In the motivating example: $A^{-1} = \tfrac{1}{10}(7I - A) = \tfrac{1}{10}\begin{bmatrix} 3 &amp;amp; -1 \\ -2 &amp;amp; 4 \end{bmatrix}$.&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;Powers.&lt;/em&gt; Every $A^k$ can be written as $\alpha_kA + \beta_kI$, by repeatedly replacing $A^2$ with $7A - 10I$.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;jordan-blocks&quot;&gt;Jordan blocks&lt;/h2&gt;

&lt;p&gt;The matrix $J = \begin{bmatrix} 2 &amp;amp; 1 \\ 0 &amp;amp; 2 \end{bmatrix}$ has the double eigenvalue $2$ but only one eigendirection $(1, 0)$, so it is not diagonalizable. It is a &lt;strong&gt;Jordan block&lt;/strong&gt;: the eigenvalue on the diagonal, $1$s just above it.&lt;/p&gt;

&lt;p&gt;Write $J = 2I + N$ with $N = \begin{bmatrix} 0 &amp;amp; 1 \\ 0 &amp;amp; 0 \end{bmatrix}$, $N^2 = 0$. Since $2I$ commutes with $N$, the binomial expansion has only two terms:&lt;/p&gt;

\[J^k = 2^kI + k2^{k-1}N = \begin{bmatrix} 2^k &amp;amp; k2^{k-1} \\ 0 &amp;amp; 2^k \end{bmatrix}, \qquad e^{tJ} = e^{2t}(I + tN) = e^{2t}\begin{bmatrix} 1 &amp;amp; t \\ 0 &amp;amp; 1 \end{bmatrix}.\]

&lt;p&gt;The factors $k$ and $t$ are the signature of a non-diagonalizable matrix, exactly like the term $te^{-t}$ in Exercise 5 of Lesson 09-07.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2 (Jordan form, stated without proof).&lt;/strong&gt; Every complex square matrix $A$ is similar to a block-diagonal matrix $J = \operatorname{diag}(J_1, \dots, J_s)$, where each $J_i$ is a Jordan block (eigenvalue $\lambda_i$ on the diagonal, $1$s just above). This form is unique up to the order of the blocks. $A$ is diagonalizable if and only if every block is $1 \times 1$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; $A = \begin{bmatrix} 3 &amp;amp; 1 \\ -1 &amp;amp; 1 \end{bmatrix}$ has $\operatorname{tr} A = 4$, $\det A = 4$, so $p(\lambda) = (\lambda - 2)^2$. The matrix $A - 2I = \begin{bmatrix} 1 &amp;amp; 1 \\ -1 &amp;amp; -1 \end{bmatrix}$ has rank $1$, so there is only one eigendirection $v_1 = (1, -1)$: $A$ is not diagonalizable, and its Jordan form is $\begin{bmatrix} 2 &amp;amp; 1 \\ 0 &amp;amp; 2 \end{bmatrix}$.&lt;/p&gt;

  &lt;p&gt;To find $P$, solve $(A - 2I)v_2 = v_1$: $v_2 = (1, 0)$. With $P = [v_1\ v_2] = \begin{bmatrix} 1 &amp;amp; 1 \\ -1 &amp;amp; 0 \end{bmatrix}$ we get $AP = PJ$. Check: $Av_1 = 2v_1$, $Av_2 = (3, -1) = v_1 + 2v_2$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-fast-powers-in-algorithms&quot;&gt;Application: fast powers in algorithms&lt;/h2&gt;

&lt;p&gt;Cayley–Hamilton turns a high power into a low-degree polynomial: for an $n \times n$ matrix $A$, $A^k$ is a combination of $I, A, \dots, A^{n-1}$. Algorithms for the $k$-th term of a linear recurrence (such as Fibonacci, Lesson 09-06) use this idea: reduce $\lambda^k$ modulo the characteristic polynomial, needing about $\log k$ multiplications of small polynomials instead of matrix products.&lt;/p&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Use Cayley–Hamilton to compute $A^{-1}$ for $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\operatorname{tr} A = 3$, $\det A = 1$. $A^{-1} = 3I - A = \begin{bmatrix} 1 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; For $A$ in Example 1, write $A^2$ and $A^3$ in the form $\alpha A + \beta I$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A^2 = 4A - 4I$, $A^3 = 4A^2 - 4A = 4(4A - 4I) - 4A = 12A - 16I$. Check: $A^2 = \begin{bmatrix} 8 &amp;amp; 4 \\ -4 &amp;amp; 0 \end{bmatrix} = 4A - 4I$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Compute $J^{10}$ for $J = \begin{bmatrix} 2 &amp;amp; 1 \\ 0 &amp;amp; 2 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$J^{10} = \begin{bmatrix} 1024 &amp;amp; 10 \cdot 512 \\ 0 &amp;amp; 1024 \end{bmatrix} = \begin{bmatrix} 1024 &amp;amp; 5120 \\ 0 &amp;amp; 1024 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Let $N = \begin{bmatrix} 0 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 0 \end{bmatrix}$. Compute $N^2$, $N^3$ and $e^{tN}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$N^2$ has a single $1$ in position $(1, 3)$; $N^3 = 0$. So $e^{tN} = I + tN + \tfrac{t^2}{2}N^2 = \begin{bmatrix} 1 &amp;amp; t &amp;amp; t^2/2 \\ 0 &amp;amp; 1 &amp;amp; t \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Cayley–Hamilton: $p(A) = 0$; for $2 \times 2$, $A^2 - (\operatorname{tr} A)A + (\det A)I = 0$ and $A^{-1} = \frac{(\operatorname{tr} A)I - A}{\det A}$.&lt;/li&gt;
    &lt;li&gt;A Jordan block is $J = \lambda I + N$ with $N$ nilpotent; $J^k$ and $e^{tJ}$ contain the factors $k$, $t$.&lt;/li&gt;
    &lt;li&gt;Every complex matrix is similar to a Jordan form; diagonalizable $\iff$ every block has size $1$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Linear Systems of Differential Equations x′ = Ax</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter09/09_07_He_Phuong_Trinh_Vi_Phan_Tuyen_Tinh/"/>
   <updated>2026-01-09T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter09/09_07_He_Phuong_Trinh_Vi_Phan_Tuyen_Tinh</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;solve $x&apos; = Ax$ for diagonalizable $A$ with the formula $x(t) = \sum c_ie^{\lambda_it}v_i$;&lt;/li&gt;
    &lt;li&gt;find the coefficients $c_i$ from initial conditions and write $e^{At} = Pe^{Dt}P^{-1}$;&lt;/li&gt;
    &lt;li&gt;classify the equilibrium $x = 0$ of a $2 \times 2$ system (node, saddle, spiral, center) and its stability from the eigenvalues.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Two connected rooms have temperatures (relative to outside) $x_1(t)$ and $x_2(t)$. Each room loses heat outside and exchanges heat with the other:&lt;/p&gt;

\[x_1&apos; = -2x_1 + x_2, \qquad x_2&apos; = x_1 - 2x_2, \qquad\text{i.e.}\qquad x&apos; = Ax,\ A = \begin{bmatrix} -2 &amp;amp; 1 \\ 1 &amp;amp; -2 \end{bmatrix}.\]

&lt;p&gt;The two equations are coupled. But for a single equation $x&apos; = \lambda x$ we know the solution $x = ce^{\lambda t}$. In the eigen-coordinates of $A$ (Lesson 09-04), the system splits into two such equations.&lt;/p&gt;

&lt;h2 id=&quot;solutions-from-eigenvectors&quot;&gt;Solutions from eigenvectors&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; If $Av = \lambda v$, then $x(t) = e^{\lambda t}v$ solves $x&apos; = Ax$. If $A$ is diagonalizable with eigenpairs $(\lambda_i, v_i)$, every solution has the form&lt;/p&gt;

\[x(t) = c_1e^{\lambda_1t}v_1 + \dots + c_ne^{\lambda_nt}v_n,\]

  &lt;p&gt;with constants $c_i$ determined by $x(0) = c_1v_1 + \dots + c_nv_n$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; $\frac{d}{dt}(e^{\lambda t}v) = \lambda e^{\lambda t}v = e^{\lambda t}Av = A(e^{\lambda t}v)$. Linear combinations of solutions are solutions. Conversely, given a solution $x(t)$, let $y = P^{-1}x$; then $y&apos; = P^{-1}APy = Dy$, i.e. $y_i&apos; = \lambda_iy_i$, so $y_i = c_ie^{\lambda_it}$ and $x = Py$ has the stated form.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (the motivating example).&lt;/strong&gt; $A = \begin{bmatrix} -2 &amp;amp; 1 \\ 1 &amp;amp; -2 \end{bmatrix}$ has eigenvalue $-1$ with $v_1 = (1, 1)$ and $-3$ with $v_2 = (1, -1)$. With $x(0) = (3, 1)$: $c_1(1,1) + c_2(1,-1) = (3, 1)$ gives $c_1 = 2$, $c_2 = 1$. So&lt;/p&gt;

\[x(t) = 2e^{-t}\begin{bmatrix} 1 \\ 1 \end{bmatrix} + e^{-3t}\begin{bmatrix} 1 \\ -1 \end{bmatrix}.\]

  &lt;p&gt;The temperature difference $x_1 - x_2 = 2e^{-3t}$ dies quickly; the average $\tfrac12(x_1 + x_2) = 2e^{-t}$ decays more slowly. After a few minutes the rooms are nearly at the same temperature, and then they cool together.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;the-matrix-exponential&quot;&gt;The matrix exponential&lt;/h2&gt;

&lt;p&gt;For a scalar equation the solution is $x(t) = e^{at}x(0)$. For systems, define&lt;/p&gt;

\[e^{At} = I + At + \frac{(At)^2}{2!} + \frac{(At)^3}{3!} + \cdots.\]

&lt;p&gt;This series always converges, and $x(t) = e^{At}x(0)$ is the unique solution of $x&apos; = Ax$ with the given initial condition. If $A = PDP^{-1}$ then $(At)^k = PD^kt^kP^{-1}$, so&lt;/p&gt;

\[e^{At} = Pe^{Dt}P^{-1}, \qquad e^{Dt} = \operatorname{diag}(e^{\lambda_1t}, \dots, e^{\lambda_nt}).\]

&lt;h2 id=&quot;classifying-equilibria&quot;&gt;Classifying equilibria&lt;/h2&gt;

&lt;p&gt;The point $x = 0$ is always an equilibrium of $x&apos; = Ax$. For a $2 \times 2$ matrix $A$, the shape of the trajectories near $0$ (the phase portrait) is determined by the two eigenvalues:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Two negative real eigenvalues&lt;/strong&gt;: &lt;em&gt;stable node&lt;/em&gt;. All trajectories enter $0$, eventually tangent to the eigendirection with the smaller $\lvert\lambda\rvert$ (Example 1: direction $(1, 1)$).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Two positive real eigenvalues&lt;/strong&gt;: &lt;em&gt;unstable node&lt;/em&gt;; trajectories leave.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Real eigenvalues of opposite signs&lt;/strong&gt;: &lt;em&gt;saddle&lt;/em&gt;. Trajectories come in along the negative eigendirection and leave along the positive one; most solutions go to infinity.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Complex pair $a \pm bi$ with $a &amp;lt; 0$&lt;/strong&gt;: &lt;em&gt;stable spiral&lt;/em&gt;; trajectories spiral into $0$ (damped oscillation, Lesson 09-05).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Complex pair $a \pm bi$ with $a &amp;gt; 0$&lt;/strong&gt;: &lt;em&gt;unstable spiral&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Purely imaginary pair $\pm bi$&lt;/strong&gt;: &lt;em&gt;center&lt;/em&gt;; trajectories are closed ellipses (undamped oscillation).&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2 (Stability).&lt;/strong&gt; Every solution of $x&apos; = Ax$ tends to $0$ as $t \to \infty$ if and only if every eigenvalue of $A$ has negative real part.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof (diagonalizable case).&lt;/strong&gt; For $\lambda = a + bi$, $\lvert e^{\lambda t} \rvert = e^{at}$, which tends to $0$ exactly when $a &amp;lt; 0$. If all real parts are negative, every term $c_ie^{\lambda_it}v_i$ tends to $0$. If some eigenvalue has real part $\ge 0$, the solution $e^{\lambda t}v$ (or its real part) does not tend to $0$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Compare with Lesson 09-06: for the discrete system $x_{k+1} = Ax_k$ the stability condition is $\lvert\lambda_i\rvert &amp;lt; 1$; for the continuous system $x&apos; = Ax$ it is $\operatorname{Re}\lambda_i &amp;lt; 0$. The link: $e^{\lambda}$ has modulus less than 1 exactly when $\operatorname{Re}\lambda &amp;lt; 0$.&lt;/p&gt;

&lt;h2 id=&quot;application-a-damped-spring&quot;&gt;Application: a damped spring&lt;/h2&gt;

&lt;p&gt;A mass on a damped spring satisfies $y&apos;&apos; + 2\zeta y&apos; + y = 0$. Setting $x = (y, y&apos;)$ gives $x&apos; = \begin{bmatrix} 0 &amp;amp; 1 \\ -1 &amp;amp; -2\zeta \end{bmatrix}x$, with eigenvalues $-\zeta \pm \sqrt{\zeta^2 - 1}$. For $\zeta = 0$: a center (oscillates forever); $0 &amp;lt; \zeta &amp;lt; 1$: a stable spiral (damped oscillation, like slightly soft car suspension); $\zeta &amp;gt; 1$: a stable node (returns to equilibrium without oscillating, like a door with a pneumatic closer). Suspension engineers choose $\zeta$ near $1$ so the mass returns to rest as fast as possible without bouncing.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: phase portraits of x′ = Ax&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Pick node, saddle, spiral or center; click the plot to drop an initial point.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter09/pha.html?preset=saddle&amp;amp;lang=en&quot; title=&quot;Interactive: phase portraits of x′ = Ax&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter09/pha.html?preset=saddle&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Solve $x&apos; = \begin{bmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 1 \end{bmatrix}x$, $x(0) = (2, 0)$. Classify the equilibrium.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Eigenvalues $3$ with $(1, 1)$ and $-1$ with $(1, -1)$. $x(0) = (1,1) + (1,-1)$, so $x(t) = e^{3t}(1, 1) + e^{-t}(1, -1)$. Opposite signs: a saddle, unstable.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Classify the equilibrium of $x&apos; = Ax$ for (a) $A = \begin{bmatrix} 0 &amp;amp; 1 \\ -4 &amp;amp; 0 \end{bmatrix}$; (b) $A = \begin{bmatrix} -1 &amp;amp; -2 \\ 2 &amp;amp; -1 \end{bmatrix}$; (c) $A = \begin{bmatrix} 3 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

(a) $\lambda^2 + 4 = 0$, $\lambda = \pm 2i$: a center. (b) $\lambda = -1 \pm 2i$: a stable spiral. (c) $\lambda = 3, 1$: an unstable node.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Compute $e^{At}$ for $A = \begin{bmatrix} -2 &amp;amp; 1 \\ 1 &amp;amp; -2 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$P = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix}$, $P^{-1} = \tfrac12 P$, $e^{At} = \tfrac{1}{2}\begin{bmatrix} e^{-t} + e^{-3t} &amp;amp; e^{-t} - e^{-3t} \\ e^{-t} - e^{-3t} &amp;amp; e^{-t} + e^{-3t} \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; For $2 \times 2$ matrices, prove: $x = 0$ is stable (all solutions tend to $0$) if and only if $\operatorname{tr} A &amp;lt; 0$ and $\det A &amp;gt; 0$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

With two real eigenvalues: both negative $\iff$ negative sum and positive product. With a complex pair $a \pm bi$: the product $a^2 + b^2 &amp;gt; 0$ always, and the sum $2a &amp;lt; 0 \iff a &amp;lt; 0$. In both cases the condition is $\operatorname{tr} A &amp;lt; 0$, $\det A &amp;gt; 0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; For $\zeta = 1$ in the Application, the matrix has the double eigenvalue $-1$ and is not diagonalizable. Check that $y(t) = te^{-t}$ solves $y&apos;&apos; + 2y&apos; + y = 0$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$y&apos; = (1 - t)e^{-t}$, $y&apos;&apos; = (t - 2)e^{-t}$. Then $y&apos;&apos; + 2y&apos; + y = (t - 2 + 2 - 2t + t)e^{-t} = 0$. The factor $t$ appears because the matrix is not diagonalizable (a Jordan block, Lesson 09-08).

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$Av = \lambda v$ gives the solution $e^{\lambda t}v$ of $x&apos; = Ax$; for diagonalizable $A$, $x(t) = \sum c_ie^{\lambda_it}v_i$, where the $c_i$ are the coordinates of $x(0)$ in the eigenvector basis.&lt;/li&gt;
    &lt;li&gt;$x(t) = e^{At}x(0)$ with $e^{At} = Pe^{Dt}P^{-1}$.&lt;/li&gt;
    &lt;li&gt;$2 \times 2$ systems: nodes (real, same sign), saddles (real, opposite signs), spirals (complex), centers (purely imaginary).&lt;/li&gt;
    &lt;li&gt;Stable $\iff$ every $\operatorname{Re}\lambda_i &amp;lt; 0$; for $2 \times 2$: $\operatorname{tr} A &amp;lt; 0$ and $\det A &amp;gt; 0$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Matrix Powers and Recurrences</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter09/09_06_Luy_Thua_Ma_Tran_Va_Day_Truy_Hoi/"/>
   <updated>2026-01-09T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter09/09_06_Luy_Thua_Ma_Tran_Va_Day_Truy_Hoi</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;compute $A^k$ by diagonalization, $A^k = PD^kP^{-1}$;&lt;/li&gt;
    &lt;li&gt;write a linear recurrence as $x_{k+1} = Ax_k$ and find an explicit formula, such as Binet’s formula for the Fibonacci numbers;&lt;/li&gt;
    &lt;li&gt;predict the long-term behavior of $A^kx_0$ from the dominant eigenvalue, and implement power iteration.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;The Fibonacci sequence $0, 1, 1, 2, 3, 5, 8, \dots$ satisfies $F_{k+2} = F_{k+1} + F_k$. Computing $F_{100}$ by repeated addition takes 99 additions; is there a direct formula? Stack two consecutive terms into a vector:&lt;/p&gt;

\[\begin{bmatrix} F_{k+2} \\ F_{k+1} \end{bmatrix} = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix} \begin{bmatrix} F_{k+1} \\ F_k \end{bmatrix}, \quad\text{so}\quad \begin{bmatrix} F_{k+1} \\ F_k \end{bmatrix} = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix}^k \begin{bmatrix} 1 \\ 0 \end{bmatrix}.\]

&lt;p&gt;A question about a sequence becomes a question about matrix powers. And powers of diagonalizable matrices are easy.&lt;/p&gt;

&lt;h2 id=&quot;powers-via-diagonalization&quot;&gt;Powers via diagonalization&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; If $A = PDP^{-1}$ with $D = \operatorname{diag}(\lambda_1, \dots, \lambda_n)$, then for every $k \ge 0$,&lt;/p&gt;

\[A^k = PD^kP^{-1}, \qquad D^k = \operatorname{diag}(\lambda_1^k, \dots, \lambda_n^k).\]

  &lt;p&gt;Equivalently: if $x_0 = c_1v_1 + \dots + c_nv_n$ in the eigenvector basis, then $A^kx_0 = c_1\lambda_1^kv_1 + \dots + c_n\lambda_n^kv_n$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; $A^2 = PDP^{-1}PDP^{-1} = PD^2P^{-1}$, and by induction the inner pairs $P^{-1}P$ cancel. Second form: $Av_i = \lambda_iv_i$ gives $A^kv_i = \lambda_i^kv_i$; then use linearity.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; With $A = \begin{bmatrix} 4 &amp;amp; 1 \\ 2 &amp;amp; 3 \end{bmatrix} = PDP^{-1}$ from Lesson 09-04:&lt;/p&gt;

\[A^k = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -2 \end{bmatrix}\begin{bmatrix} 5^k &amp;amp; 0 \\ 0 &amp;amp; 2^k \end{bmatrix}\frac{1}{3}\begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix} = \frac{1}{3}\begin{bmatrix} 2 \cdot 5^k + 2^k &amp;amp; 5^k - 2^k \\ 2 \cdot 5^k - 2 \cdot 2^k &amp;amp; 5^k + 2 \cdot 2^k \end{bmatrix}.\]

  &lt;p&gt;Check at $k = 2$: $\tfrac{1}{3}\begin{bmatrix} 54 &amp;amp; 21 \\ 42 &amp;amp; 33 \end{bmatrix} = \begin{bmatrix} 18 &amp;amp; 7 \\ 14 &amp;amp; 11 \end{bmatrix} = A^2$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;binets-formula&quot;&gt;Binet’s formula&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (Fibonacci).&lt;/strong&gt; The matrix $F = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix}$ has $p(\lambda) = \lambda^2 - \lambda - 1$ and eigenvalues&lt;/p&gt;

\[\varphi = \frac{1 + \sqrt{5}}{2} \approx 1.618, \qquad \psi = \frac{1 - \sqrt{5}}{2} \approx -0.618,\]

  &lt;p&gt;with eigenvectors $(\varphi, 1)$ and $(\psi, 1)$ (since $F(\lambda, 1) = (\lambda + 1, \lambda) = \lambda(\lambda, 1)$ when $\lambda^2 = \lambda + 1$). Write $(1, 0) = \tfrac{1}{\sqrt{5}}\left[(\varphi, 1) - (\psi, 1)\right]$ (since $\varphi - \psi = \sqrt{5}$). By Theorem 1,&lt;/p&gt;

\[\begin{bmatrix} F_{k+1} \\ F_k \end{bmatrix} = \frac{1}{\sqrt{5}}\left[\varphi^k\begin{bmatrix} \varphi \\ 1 \end{bmatrix} - \psi^k\begin{bmatrix} \psi \\ 1 \end{bmatrix}\right], \quad\text{so}\quad F_k = \frac{\varphi^k - \psi^k}{\sqrt{5}}.\]

  &lt;p&gt;Since $\lvert\psi\rvert &amp;lt; 1$, the term $\psi^k$ quickly becomes negligible: $F_k$ is the integer nearest to $\varphi^k/\sqrt{5}$, and $F_{k+1}/F_k \to \varphi$, the golden ratio.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;long-term-behavior-and-the-dominant-eigenvalue&quot;&gt;Long-term behavior and the dominant eigenvalue&lt;/h2&gt;

&lt;p&gt;Suppose $\lvert\lambda_1\rvert &amp;gt; \lvert\lambda_2\rvert \ge \dots \ge \lvert\lambda_n\rvert$ ($\lambda_1$ is the &lt;em&gt;dominant eigenvalue&lt;/em&gt;) and $c_1 \ne 0$. Then&lt;/p&gt;

\[A^kx_0 = \lambda_1^k\left[c_1v_1 + c_2\left(\tfrac{\lambda_2}{\lambda_1}\right)^kv_2 + \dots\right] \approx c_1\lambda_1^kv_1 \quad (k \text{ large}).\]

&lt;p&gt;Every starting vector (with $c_1 \ne 0$) turns toward the direction $v_1$, and its length grows (or shrinks) like $\lvert\lambda_1\rvert^k$. The rate of alignment with $v_1$ depends on the ratio $\lvert\lambda_2/\lambda_1\rvert$.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Power iteration.&lt;/strong&gt; This idea gives an algorithm for the dominant eigenvalue: start from any $x_0$ and iterate $x_{k+1} = Ax_k / \lVert Ax_k \rVert$. At convergence, $x_k \approx v_1$ (normalized) and $x_k^TAx_k \approx \lambda_1$.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;power_iteration&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rand&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For $A = \begin{bmatrix} 4 &amp;amp; 1 \\ 2 &amp;amp; 3 \end{bmatrix}$, six steps from $x_0 = e_1$ already estimate $\lambda_1 \approx 5.003$; the error shrinks like $(2/5)^k$.&lt;/p&gt;

&lt;h2 id=&quot;application-long-term-distribution&quot;&gt;Application: long-term distribution&lt;/h2&gt;

&lt;p&gt;Each year, $10\%$ of city residents move to the countryside and $20\%$ of country residents move to the city. With $x_k = (\text{city}, \text{country})$: $x_{k+1} = Mx_k$, $M = \begin{bmatrix} 0.9 &amp;amp; 0.2 \\ 0.1 &amp;amp; 0.8 \end{bmatrix}$. The eigenvalues are $1$ with eigenvector $(2, 1)$ and $0.7$ with eigenvector $(1, -1)$. Since $0.7^k \to 0$, every initial distribution tends to the ratio $2 : 1$: in the long run, two thirds of the population lives in the city, whatever the start. This is an example of a Markov chain (Chapter 13).&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: matrix powers converge to the dominant eigenvector&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Press +1 repeatedly: the direction of Aᵏx approaches the eigenvector with the largest ∣λ∣.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter09/tri_rieng.html?mode=power&amp;amp;lang=en&quot; title=&quot;Interactive: matrix powers converge to the dominant eigenvector&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter09/tri_rieng.html?mode=power&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-matrix-powers-and-the-golden-ratio&quot;&gt;Short video: Matrix powers and the golden ratio&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/fibonacci-power.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;The Fibonacci sequence packed into vectors (Fₖ₊₁; Fₖ) = Aᵏ (1; 0) with A = [1 1; 1 0]. The points crowd toward the eigendirection (φ; 1), alternating on either side and getting closer; the ratio Fₖ₊₁/Fₖ → φ ≈ 1.618. Characteristic equation λ² − λ − 1 = 0; power iteration; Binet&apos;s formula Fₖ = (φᵏ − ψᵏ)/√5. Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Compute $\begin{bmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 1 \end{bmatrix}^k$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

From Exercise 1 of Lesson 09-04: $A^k = \tfrac{1}{2}\begin{bmatrix} 3^k + (-1)^k &amp;amp; 3^k - (-1)^k \\ 3^k - (-1)^k &amp;amp; 3^k + (-1)^k \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; For $M$ in the Application, find $\lim_{k \to \infty} M^k$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$M^k = P\operatorname{diag}(1, 0.7^k)P^{-1}$ with $P = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix}$, so $M^k \to P\operatorname{diag}(1, 0)P^{-1} = \tfrac{1}{3}\begin{bmatrix} 2 &amp;amp; 2 \\ 1 &amp;amp; 1 \end{bmatrix}$. Every column is the steady state $(\tfrac23, \tfrac13)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Find an explicit formula for $a_0 = 0$, $a_1 = 1$, $a_{k+2} = 5a_{k+1} - 6a_k$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The matrix $\begin{bmatrix} 5 &amp;amp; -6 \\ 1 &amp;amp; 0 \end{bmatrix}$ has $p(\lambda) = \lambda^2 - 5\lambda + 6$, eigenvalues $3$, $2$. So $a_k = \alpha 3^k + \beta 2^k$; $a_0 = 0$, $a_1 = 1$ give $\alpha = 1$, $\beta = -1$: $a_k = 3^k - 2^k$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (programming).&lt;/strong&gt; Implement power iteration and compare with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.eig&lt;/code&gt; on $\begin{bmatrix} 2 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 2 \end{bmatrix}$. How fast does it converge, and why?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

It converges to $\lambda_1 = 4$, $v_1 = \tfrac{1}{\sqrt3}(1,1,1)$, matching `eig`. The direction error shrinks like $(1/4)^k$ because $\lambda_2 = 1$: very fast, about 25 steps for 15 digits.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Prove $F_{k+1}F_{k-1} - F_k^2 = (-1)^k$ (Cassini’s identity) using determinants.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

By induction, $F^k = \begin{bmatrix} F_{k+1} &amp;amp; F_k \\ F_k &amp;amp; F_{k-1} \end{bmatrix}$. Taking determinants: $F_{k+1}F_{k-1} - F_k^2 = (\det F)^k = (-1)^k$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$A^k = PD^kP^{-1}$; in the eigenvector basis, $A^kx_0 = \sum c_i\lambda_i^kv_i$.&lt;/li&gt;
    &lt;li&gt;Linear recurrences can be written as $x_{k+1} = Ax_k$; Fibonacci gives Binet’s formula $F_k = (\varphi^k - \psi^k)/\sqrt5$.&lt;/li&gt;
    &lt;li&gt;In the long run, $A^kx_0$ aligns with the dominant eigenvector at rate $\lvert\lambda_2/\lambda_1\rvert^k$.&lt;/li&gt;
    &lt;li&gt;Power iteration finds the dominant eigenvalue using only matrix–vector products.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Complex Eigenvalues and Rotations</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter09/09_05_Tri_Rieng_Phuc_Va_Ma_Tran_Quay/"/>
   <updated>2026-01-09T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter09/09_05_Tri_Rieng_Phuc_Va_Ma_Tran_Quay</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;find complex eigenvalues and eigenvectors of a real $2 \times 2$ matrix;&lt;/li&gt;
    &lt;li&gt;explain why complex eigenvalues of real matrices come in conjugate pairs;&lt;/li&gt;
    &lt;li&gt;write $A = PCP^{-1}$ with $C = \begin{bmatrix} a &amp;amp; -b \\ b &amp;amp; a \end{bmatrix}$ a rotation–scaling matrix, and read off the angle and scale factor.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;The matrix $A = \begin{bmatrix} 1 &amp;amp; -1 \\ 1 &amp;amp; 1 \end{bmatrix}$ sends $e_1$ to $(1, 1)$ and $e_2$ to $(-1, 1)$: every vector turns by $45^\circ$ and grows by a factor $\sqrt{2}$. No real direction is kept, and indeed $p_A(\lambda) = \lambda^2 - 2\lambda + 2$ has discriminant $4 - 8 &amp;lt; 0$. But in $\mathbb{C}$, $\lambda = 1 \pm i = \sqrt{2}\, e^{\pm i\pi/4}$: the modulus $\sqrt{2}$ is exactly the scale factor, and the argument $\pi/4$ is exactly the rotation angle. Complex eigenvalues are not “meaningless roots”; they encode rotation.&lt;/p&gt;

&lt;h2 id=&quot;complex-eigenvalues-of-real-matrices&quot;&gt;Complex eigenvalues of real matrices&lt;/h2&gt;

&lt;p&gt;All definitions and theorems of Lessons 09-01 to 09-04 carry over when complex numbers and vectors are allowed: $\lambda \in \mathbb{C}$ is an eigenvalue if $Av = \lambda v$ for some $v \in \mathbb{C}^n$, $v \ne 0$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; If $A$ is real and $Av = \lambda v$ with $\lambda \in \mathbb{C}$, $v \in \mathbb{C}^n$, then $A\bar{v} = \bar{\lambda}\bar{v}$. So non-real eigenvalues of a real matrix come in conjugate pairs $\lambda$, $\bar\lambda$, with conjugate eigenvectors.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Take complex conjugates entrywise in $Av = \lambda v$. Since $A$ is real, $\bar{A} = A$, so $A\bar{v} = \bar{\lambda}\bar{v}$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;For a real $2 \times 2$ matrix, $p_A(\lambda) = \lambda^2 - (\operatorname{tr} A)\lambda + \det A$ has complex roots exactly when $(\operatorname{tr} A)^2 &amp;lt; 4\det A$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; Let $A = \begin{bmatrix} 1 &amp;amp; -2 \\ 1 &amp;amp; 3 \end{bmatrix}$: $\operatorname{tr} A = 4$, $\det A = 5$, $p_A(\lambda) = \lambda^2 - 4\lambda + 5$, so $\lambda = 2 \pm i$. For $\lambda = 2 - i$:&lt;/p&gt;

\[A - (2 - i)I = \begin{bmatrix} -1 + i &amp;amp; -2 \\ 1 &amp;amp; 1 + i \end{bmatrix}.\]

  &lt;p&gt;The second row gives $v_1 + (1 + i)v_2 = 0$; taking $v_2 = 1$ gives $v = (-1 - i, 1)$. Check the first row: $(-1 + i)(-1 - i) - 2 = (1 + 1) - 2 = 0$. The eigenvector for $2 + i$ is $\bar{v} = (-1 + i, 1)$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;real-form-rotation-and-scaling&quot;&gt;Real form: rotation and scaling&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2.&lt;/strong&gt; Let $A$ be a real $2 \times 2$ matrix with eigenvalue $\lambda = a - bi$, $b \ne 0$, and eigenvector $v \in \mathbb{C}^2$. Let $P = \begin{bmatrix} \operatorname{Re} v &amp;amp; \operatorname{Im} v \end{bmatrix}$ (a real matrix). Then $P$ is invertible and&lt;/p&gt;

\[A = PCP^{-1}, \qquad C = \begin{bmatrix} a &amp;amp; -b \\ b &amp;amp; a \end{bmatrix} = r\begin{bmatrix} \cos\varphi &amp;amp; -\sin\varphi \\ \sin\varphi &amp;amp; \cos\varphi \end{bmatrix},\]

  &lt;p&gt;where $r = \lvert\lambda\rvert = \sqrt{a^2 + b^2}$ and $\varphi$ is the argument of $a + bi$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof (sketch).&lt;/strong&gt; Write $v = x + iy$ with $x, y$ real. Separating real and imaginary parts of $A(x + iy) = (a - bi)(x + iy) = (ax + by) + i(-bx + ay)$ gives $Ax = ax + by$ and $Ay = -bx + ay$. This is $AP = PC$ read column by column. If $x$, $y$ were dependent, $v$ would be a complex multiple of a real vector and $\lambda$ would be real; so $P$ is invertible.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; Continuing Example 1: $\lambda = 2 - i$ ($a = 2$, $b = 1$), $v = (-1 - i, 1)$, so $\operatorname{Re} v = (-1, 1)$, $\operatorname{Im} v = (-1, 0)$ and&lt;/p&gt;

\[P = \begin{bmatrix} -1 &amp;amp; -1 \\ 1 &amp;amp; 0 \end{bmatrix}, \qquad C = \begin{bmatrix} 2 &amp;amp; -1 \\ 1 &amp;amp; 2 \end{bmatrix} = \sqrt{5}\begin{bmatrix} \cos\varphi &amp;amp; -\sin\varphi \\ \sin\varphi &amp;amp; \cos\varphi \end{bmatrix},\ \varphi = \arctan\tfrac{1}{2} \approx 26.6^\circ.\]

  &lt;p&gt;In the coordinates given by the columns of $P$, $A$ is a rotation by $26.6^\circ$ with scaling by $\sqrt{5}$. In standard coordinates, the points $A^k x$ move along an elliptical spiral away from the origin.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Connection with Lesson 00-02: the matrix $C = \begin{bmatrix} a &amp;amp; -b \\ b &amp;amp; a \end{bmatrix}$ is exactly multiplication by the complex number $a + bi$ on the plane.&lt;/p&gt;

&lt;h2 id=&quot;long-term-behavior&quot;&gt;Long-term behavior&lt;/h2&gt;

&lt;p&gt;For $x_{k+1} = Ax_k$ with eigenvalues $a \pm bi$ and $r = \sqrt{a^2 + b^2}$:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;$r &amp;lt; 1$: points spiral into the origin;&lt;/li&gt;
  &lt;li&gt;$r = 1$: points move around an ellipse (pure rotation in the $P$ coordinates);&lt;/li&gt;
  &lt;li&gt;$r &amp;gt; 1$: points spiral outward.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Complex eigenvalues say the system &lt;em&gt;oscillates&lt;/em&gt;; their modulus says whether the oscillation dies out or grows.&lt;/p&gt;

&lt;h2 id=&quot;application-predatorprey-cycles&quot;&gt;Application: predator–prey cycles&lt;/h2&gt;

&lt;p&gt;The linearized model of rabbit and fox populations near equilibrium often has a matrix with complex eigenvalues. The two populations then oscillate out of phase: more rabbits means more foxes, more foxes means fewer rabbits. The angle $\varphi$ gives the fraction of a cycle completed each year (a period of about $2\pi/\varphi$ years), and $r$ says whether the oscillation decays to equilibrium or grows. The roughly 10-year cycles of lynx and snowshoe hares in Canada are a famous example.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: a rotation has no real eigen-direction&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Spin x around: Ax never lines up with x; the eigenvalues are complex.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter09/tri_rieng.html?mode=eig&amp;amp;preset=rot&amp;amp;lang=en&quot; title=&quot;Interactive: a rotation has no real eigen-direction&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter09/tri_rieng.html?mode=eig&amp;amp;preset=rot&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Find the complex eigenvalues and eigenvectors of $\begin{bmatrix} 0 &amp;amp; -1 \\ 1 &amp;amp; 0 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$p(\lambda) = \lambda^2 + 1$, $\lambda = \pm i$. For $\lambda = i$: $(A - iI)v = 0$ gives $-iv_1 - v_2 = 0$, so $v = (i, 1)$; for $\lambda = -i$: $v = (-i, 1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Find the eigenvalues of $A = \begin{bmatrix} 3 &amp;amp; -5 \\ 1 &amp;amp; -1 \end{bmatrix}$, and the corresponding scale factor and rotation angle.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\operatorname{tr} A = 2$, $\det A = -3 + 5 = 2$, $\lambda^2 - 2\lambda + 2 = 0$, $\lambda = 1 \pm i$. Scale factor $r = \sqrt{2}$, angle $\varphi = 45^\circ$ (in a suitable $P$ coordinate system).

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Prove that the rotation matrix $R_\theta$ has eigenvalues $e^{\pm i\theta}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\operatorname{tr} R_\theta = 2\cos\theta$, $\det R_\theta = 1$, so $\lambda^2 - 2\cos\theta\,\lambda + 1 = 0$ gives $\lambda = \cos\theta \pm i\sin\theta = e^{\pm i\theta}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Prove that a real $3 \times 3$ matrix always has at least one real eigenvalue. Apply this to rotations of $\mathbb{R}^3$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$p_A$ is a real cubic, which has at least one real root (an odd-degree polynomial changes sign). For a rotation $Q$ of $\mathbb{R}^3$ ($\det Q = 1$), the eigenvalues have modulus $1$; if two of them are a complex pair $e^{\pm i\theta}$, the remaining real eigenvalue is $\det Q / 1 = 1$, and its eigenvector is the rotation axis (Euler&apos;s theorem, Lesson 07-07).

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Non-real eigenvalues of a real matrix come in conjugate pairs $a \pm bi$, with conjugate eigenvectors.&lt;/li&gt;
    &lt;li&gt;A real $2 \times 2$ matrix has complex eigenvalues when $(\operatorname{tr} A)^2 &amp;lt; 4\det A$.&lt;/li&gt;
    &lt;li&gt;For $\lambda = a - bi$ with eigenvector $v$: $A = PCP^{-1}$, $P = [\operatorname{Re} v\ \operatorname{Im} v]$, and $C = \begin{bmatrix} a &amp;amp; -b \\ b &amp;amp; a \end{bmatrix}$ rotates by $\arg(a + bi)$ and scales by $\lvert\lambda\rvert$.&lt;/li&gt;
    &lt;li&gt;$\lvert\lambda\rvert &amp;lt; 1$, $= 1$, $&amp;gt; 1$: spiral in, circle around, spiral out.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Diagonalization</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter09/09_04_Cheo_Hoa_Ma_Tran/"/>
   <updated>2026-01-09T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter09/09_04_Cheo_Hoa_Ma_Tran</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;decide whether a matrix is diagonalizable from the multiplicities of its eigenvalues;&lt;/li&gt;
    &lt;li&gt;write $A = PDP^{-1}$ with $P$ the matrix of eigenvectors and $D$ the diagonal matrix of eigenvalues;&lt;/li&gt;
    &lt;li&gt;explain diagonalization as a change to the eigenvector basis (Lesson 06-05).&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Diagonal matrices are the easiest kind: $D = \begin{bmatrix} 5 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{bmatrix}$ just stretches the $x$-axis by 5 and the $y$-axis by 2, and $D^{100} = \operatorname{diag}(5^{100}, 2^{100})$. The matrix $A = \begin{bmatrix} 4 &amp;amp; 1 \\ 2 &amp;amp; 3 \end{bmatrix}$ is not diagonal, but it has eigenvectors $(1, 1)$ with $\lambda = 5$ and $(1, -2)$ with $\lambda = 2$ (Lesson 09-02). If we use these two vectors as coordinate axes, $A$ also just stretches the first axis by 5 and the second by 2: &lt;em&gt;in the right coordinates&lt;/em&gt;, $A$ is $D$.&lt;/p&gt;

&lt;h2 id=&quot;the-diagonalization-theorem&quot;&gt;The diagonalization theorem&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Diagonalizable).&lt;/strong&gt; A square matrix $A$ is &lt;em&gt;diagonalizable&lt;/em&gt; if there are an invertible matrix $P$ and a diagonal matrix $D$ with&lt;/p&gt;

  &lt;p&gt;\(A = PDP^{-1}, \quad\text{equivalently}\quad P^{-1}AP = D.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; An $n \times n$ matrix $A$ is diagonalizable if and only if $A$ has $n$ linearly independent eigenvectors. In that case, if $v_1, \dots, v_n$ are independent eigenvectors with eigenvalues $\lambda_1, \dots, \lambda_n$, then&lt;/p&gt;

  &lt;p&gt;\(P = \begin{bmatrix} v_1 &amp;amp; \cdots &amp;amp; v_n \end{bmatrix}, \qquad D = \operatorname{diag}(\lambda_1, \dots, \lambda_n).\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Column by column, $AP = \begin{bmatrix} Av_1 &amp;amp; \cdots &amp;amp; Av_n \end{bmatrix}$ and $PD = \begin{bmatrix} \lambda_1 v_1 &amp;amp; \cdots &amp;amp; \lambda_n v_n \end{bmatrix}$. So $AP = PD$ exactly when each column $v_i$ of $P$ satisfies $Av_i = \lambda_i v_i$. If the columns are independent, $P$ is invertible and $A = PDP^{-1}$. Conversely, if $A = PDP^{-1}$ then $AP = PD$, so the columns of $P$ (nonzero, since $P$ is invertible) are eigenvectors, and they are independent.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Corollary 1.&lt;/strong&gt;&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;If $A$ has $n$ distinct eigenvalues, $A$ is diagonalizable.&lt;/li&gt;
    &lt;li&gt;In general, $A$ is diagonalizable (over $\mathbb{R}$) if and only if its characteristic polynomial splits into real linear factors and, for every eigenvalue, the geometric multiplicity equals the algebraic multiplicity.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; (1) By Theorem 3 of Lesson 09-01, $n$ eigenvectors for $n$ distinct eigenvalues are independent. (2) Combine bases of all eigenspaces; the resulting set is independent (an extension of Theorem 3, Lesson 09-01) and its size is the sum of the geometric multiplicities. That sum is $n$ exactly when every geometric multiplicity equals the algebraic one and the algebraic multiplicities add up to $n$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; For $A = \begin{bmatrix} 4 &amp;amp; 1 \\ 2 &amp;amp; 3 \end{bmatrix}$:&lt;/p&gt;

\[P = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -2 \end{bmatrix}, \quad D = \begin{bmatrix} 5 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{bmatrix}, \quad P^{-1} = \frac{1}{3}\begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix}.\]

  &lt;p&gt;Check $AP = PD$: $AP = \begin{bmatrix} 5 &amp;amp; 2 \\ 5 &amp;amp; -4 \end{bmatrix}$ and $PD = \begin{bmatrix} 5 &amp;amp; 2 \\ 5 &amp;amp; -4 \end{bmatrix}$. The order of the columns of $P$ must match the order of the eigenvalues on the diagonal of $D$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; For $A = \begin{bmatrix} 2 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 2 \end{bmatrix}$ (Lesson 09-03), the eigenvalue $1$ has algebraic and geometric multiplicity $2$, and the eigenvalue $4$ has both equal to $1$. So $A$ is diagonalizable:&lt;/p&gt;

\[P = \begin{bmatrix} 1 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; -1 &amp;amp; 0 \\ 1 &amp;amp; 0 &amp;amp; -1 \end{bmatrix}, \qquad D = \operatorname{diag}(4, 1, 1).\]

  &lt;p&gt;By contrast, the shear $\begin{bmatrix} 2 &amp;amp; 1 \\ 0 &amp;amp; 2 \end{bmatrix}$ and the matrix $C$ of Example 2 in Lesson 09-03 are not diagonalizable: a geometric multiplicity falls short of the algebraic one.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;meaning-changing-to-the-eigenvector-basis&quot;&gt;Meaning: changing to the eigenvector basis&lt;/h2&gt;

&lt;p&gt;By Lesson 06-05, $P^{-1}AP$ is the matrix of $x \mapsto Ax$ in the basis formed by the columns of $P$. Diagonalizing means finding a basis in which the map &lt;em&gt;decouples&lt;/em&gt; into $n$ independent stretchings. Read $A = PDP^{-1}$ from right to left acting on $x$:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;$P^{-1}x$: compute the coordinates of $x$ in the eigenvector basis;&lt;/li&gt;
  &lt;li&gt;$D$: multiply coordinate $i$ by $\lambda_i$;&lt;/li&gt;
  &lt;li&gt;$P$: convert back to standard coordinates.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is the most powerful way of thinking in the chapter: every question about $A$ (powers, exponentials, long-term behavior) becomes a question about $n$ numbers $\lambda_i$.&lt;/p&gt;

&lt;h2 id=&quot;application-decoupling-variables&quot;&gt;Application: decoupling variables&lt;/h2&gt;

&lt;p&gt;Two species in an ecosystem have populations $x_k$, $y_k$ that change yearly by $\begin{bmatrix} x_{k+1} \\ y_{k+1} \end{bmatrix} = A\begin{bmatrix} x_k \\ y_k \end{bmatrix}$, with the variables coupled. The change of variables $\begin{bmatrix} u \\ w \end{bmatrix} = P^{-1}\begin{bmatrix} x \\ y \end{bmatrix}$ gives $u_{k+1} = \lambda_1 u_k$, $w_{k+1} = \lambda_2 w_k$: two independent equations, solved at once. This “move to eigen-coordinates” technique is the standard method for vibrating systems, circuits, and linear economic models (Lessons 09-06, 09-07).&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: diagonalization A = PDP⁻¹ step by step&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag the step slider: P⁻¹ switches to eigen-coordinates, D stretches, P switches back.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter09/tri_rieng.html?mode=diag&amp;amp;preset=gen&amp;amp;lang=en&quot; title=&quot;Interactive: diagonalization A = PDP⁻¹ step by step&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter09/tri_rieng.html?mode=diag&amp;amp;preset=gen&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Diagonalize $\begin{bmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 1 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Eigenvalues $3$, $-1$ with eigenvectors $(1, 1)$, $(1, -1)$ (Exercise 1, Lesson 09-02). $P = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix}$, $D = \operatorname{diag}(3, -1)$, $P^{-1} = \tfrac{1}{2}\begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Diagonalize $\begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 2 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Triangular, with distinct eigenvalues $1$ and $2$. $\lambda = 1$: $(1, 0)$; $\lambda = 2$: $(1, 1)$. $P = \begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \end{bmatrix}$, $D = \operatorname{diag}(1, 2)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Which are diagonalizable? (a) $\begin{bmatrix} 3 &amp;amp; 0 \\ 0 &amp;amp; 3 \end{bmatrix}$; (b) $\begin{bmatrix} 3 &amp;amp; 1 \\ 0 &amp;amp; 3 \end{bmatrix}$; (c) $\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 3 \\ 0 &amp;amp; 4 &amp;amp; 5 \\ 0 &amp;amp; 0 &amp;amp; 6 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

(a) Yes, it is already diagonal. (b) No: $\lambda = 3$ has algebraic multiplicity $2$ and geometric multiplicity $1$. (c) Yes: three distinct eigenvalues $1, 4, 6$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Find a matrix $A$ with eigenvalue $2$ for eigenvector $(1, 1)$ and eigenvalue $-1$ for eigenvector $(1, 2)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A = PDP^{-1}$ with $P = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$, $D = \operatorname{diag}(2, -1)$, $P^{-1} = \begin{bmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 1 \end{bmatrix}$. This gives $A = \begin{bmatrix} 5 &amp;amp; -3 \\ 6 &amp;amp; -4 \end{bmatrix}$. Check: $A(1,1) = (2, 2)$, $A(1,2) = (-1, -2)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Prove: if $A$ is diagonalizable and every eigenvalue equals $\lambda$, then $A = \lambda I$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$D = \lambda I$, so $A = P(\lambda I)P^{-1} = \lambda PP^{-1} = \lambda I$. Consequence: a matrix with a single eigenvalue that is not $\lambda I$ (such as a shear) is not diagonalizable.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$A = PDP^{-1}$: the columns of $P$ are eigenvectors, the diagonal of $D$ the eigenvalues in the same order; check with $AP = PD$.&lt;/li&gt;
    &lt;li&gt;Diagonalizable $\iff$ $n$ independent eigenvectors $\iff$ every geometric multiplicity equals the algebraic one (and $p_A$ splits).&lt;/li&gt;
    &lt;li&gt;$n$ distinct eigenvalues guarantee diagonalizability.&lt;/li&gt;
    &lt;li&gt;Diagonalizing is changing to the eigenvector basis, where $A$ splits into $n$ independent stretchings.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Eigenspaces and Multiplicities</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter09/09_03_Khong_Gian_Rieng_Va_Boi_Cua_Tri_Rieng/"/>
   <updated>2026-01-09T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter09/09_03_Khong_Gian_Rieng_Va_Boi_Cua_Tri_Rieng</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;find a basis of the eigenspace $E_\lambda = \operatorname{Null}(A - \lambda I)$;&lt;/li&gt;
    &lt;li&gt;distinguish the algebraic and geometric multiplicity of an eigenvalue;&lt;/li&gt;
    &lt;li&gt;use $1 \le$ geometric multiplicity $\le$ algebraic multiplicity to predict how many independent eigenvectors exist.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;The two matrices&lt;/p&gt;

\[A = \begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{bmatrix}, \qquad B = \begin{bmatrix} 2 &amp;amp; 1 \\ 0 &amp;amp; 2 \end{bmatrix}\]

&lt;p&gt;have the same characteristic polynomial $(\lambda - 2)^2$ and the same double eigenvalue $\lambda = 2$. But $A = 2I$ doubles &lt;em&gt;every&lt;/em&gt; vector: every direction is an eigendirection. $B$ is a shear combined with scaling and keeps only the $x$-axis: $B - 2I = \begin{bmatrix} 0 &amp;amp; 1 \\ 0 &amp;amp; 0 \end{bmatrix}$ has a one-dimensional null space. Same “repetition count” in the characteristic polynomial, different numbers of eigendirections. This lesson names the two quantities.&lt;/p&gt;

&lt;h2 id=&quot;eigenspaces&quot;&gt;Eigenspaces&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Eigenspace).&lt;/strong&gt; For an eigenvalue $\lambda$ of $A$, the &lt;em&gt;eigenspace&lt;/em&gt; is&lt;/p&gt;

\[E_\lambda = \operatorname{Null}(A - \lambda I) = \{v : Av = \lambda v\}.\]

  &lt;p&gt;It consists of all eigenvectors for $\lambda$ together with $0$, and it is a subspace.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 2 (Algebraic and geometric multiplicity).&lt;/strong&gt; For an eigenvalue $\lambda$ of $A$:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;the &lt;em&gt;algebraic multiplicity&lt;/em&gt; is the number of times $\lambda$ is a root of the characteristic polynomial (the exponent of $(\lambda - \lambda_0)$ in the factorization of $p_A$);&lt;/li&gt;
    &lt;li&gt;the &lt;em&gt;geometric multiplicity&lt;/em&gt; is $\dim E_\lambda$, the maximum number of independent eigenvectors for $\lambda$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;p&gt;In the motivating example, $\lambda = 2$ has algebraic multiplicity $2$ for both matrices; its geometric multiplicity is $2$ for $A$ and $1$ for $B$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; For every eigenvalue $\lambda$: $1 \le \text{geometric multiplicity} \le \text{algebraic multiplicity}$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; The geometric multiplicity is $\ge 1$ because $\lambda$ has at least one eigenvector. Let $g = \dim E_\lambda$, choose a basis $v_1, \dots, v_g$ of $E_\lambda$, extend it to a basis of $\mathbb{R}^n$, and put these vectors as the columns of $P$. Then $P^{-1}AP = \begin{bmatrix} \lambda I_g &amp;amp; * \\ 0 &amp;amp; C \end{bmatrix}$, since $A$ sends the first $g$ columns to $\lambda v_i$. Similar matrices share the characteristic polynomial, which here is $(\lambda_0 - \lambda)^g \det(C - \lambda I)$ (with $\lambda_0$ the eigenvalue in question), so $(\lambda - \lambda_0)^g$ divides $p_A$: the algebraic multiplicity is at least $g$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; For $A = \begin{bmatrix} 2 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 2 \end{bmatrix}$ (Example 2, Lesson 09-02), $p_A(\lambda) = -(\lambda - 4)(\lambda - 1)^2$.&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$\lambda = 1$, algebraic multiplicity $2$. $A - I$ is the all-ones matrix, of rank 1, so $\dim E_1 = 3 - 1 = 2$. Basis: $(1, -1, 0)$, $(1, 0, -1)$. Geometric multiplicity $2$.&lt;/li&gt;
    &lt;li&gt;$\lambda = 4$, algebraic multiplicity $1$, so the geometric multiplicity is also $1$: $E_4 = \operatorname{span}\{(1, 1, 1)\}$.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;The geometric multiplicities add up to $3$: $A$ has three independent eigenvectors, enough for a basis of $\mathbb{R}^3$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; For $C = \begin{bmatrix} 3 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 3 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 5 \end{bmatrix}$ (upper triangular): eigenvalues $3$ (algebraic multiplicity $2$) and $5$ (algebraic multiplicity $1$). $C - 3I = \begin{bmatrix} 0 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 2 \end{bmatrix}$ has rank 2, so $\dim E_3 = 1$, $E_3 = \operatorname{span}\{e_1\}$. The geometric multiplicities add up to only $2 &amp;lt; 3$: $C$ does not have three independent eigenvectors.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;These two examples point to a criterion used in Lesson 09-04: a matrix has a basis of eigenvectors exactly when, for every eigenvalue, the geometric multiplicity equals the algebraic multiplicity (and the characteristic polynomial factors completely).&lt;/p&gt;

&lt;h2 id=&quot;application-degenerate-states-in-quantum-mechanics&quot;&gt;Application: degenerate states in quantum mechanics&lt;/h2&gt;

&lt;p&gt;In quantum mechanics, the energy levels of a system are the eigenvalues of a symmetric operator (matrix) called the Hamiltonian, and the states are its eigenvectors. An energy level with geometric multiplicity greater than 1 is called &lt;em&gt;degenerate&lt;/em&gt;: several independent states share one energy, usually because of a symmetry of the system (like $A$ in Example 1, which is symmetric under permuting the three coordinates). In a magnetic field the symmetry breaks and the degenerate level splits into several nearby levels (the Zeeman effect), visible in a spectrometer.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: eigenspaces and multiplicity&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Compare 2I (every vector is an eigenvector) with a shear (double λ but only one eigen-direction).&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter09/tri_rieng.html?mode=eig&amp;amp;preset=shear&amp;amp;lang=en&quot; title=&quot;Interactive: eigenspaces and multiplicity&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter09/tri_rieng.html?mode=eig&amp;amp;preset=shear&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Find the eigenvalues, algebraic and geometric multiplicities, and bases of the eigenspaces of $\begin{bmatrix} 5 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 5 &amp;amp; 0 \\ 1 &amp;amp; 0 &amp;amp; 5 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Lower triangular, so the only eigenvalue is $5$, with algebraic multiplicity $3$. $A - 5I$ has a single nonzero entry at position $(3, 1)$, so it has rank 1 and $\dim E_5 = 2$, with basis $e_2$, $e_3$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; For which $a$ does $\begin{bmatrix} 1 &amp;amp; a \\ 0 &amp;amp; 1 \end{bmatrix}$ have geometric multiplicity $2$ for $\lambda = 1$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

We need $A - I = \begin{bmatrix} 0 &amp;amp; a \\ 0 &amp;amp; 0 \end{bmatrix}$ to have rank $0$, i.e. $a = 0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Let $P$ be the projection onto a plane $W$ in $\mathbb{R}^3$. Find its eigenspaces and multiplicities.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$E_1 = W$ (multiplicity $2$) and $E_0 = W^\perp$ (multiplicity $1$). Algebraic and geometric multiplicities agree, since the geometric ones already add up to $3$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (advanced).&lt;/strong&gt; Prove: if $AB = BA$ and $v \in E_\lambda(A)$, then $Bv \in E_\lambda(A)$. (Eigenspaces of $A$ are invariant under $B$.)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A(Bv) = B(Av) = B(\lambda v) = \lambda (Bv)$. This is the key step in simultaneously diagonalizing commuting matrices.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;The eigenspace $E_\lambda = \operatorname{Null}(A - \lambda I)$ consists of the eigenvectors for $\lambda$ and $0$.&lt;/li&gt;
    &lt;li&gt;Algebraic multiplicity: number of times $\lambda$ is a root of $p_A$; geometric multiplicity: $\dim E_\lambda = n - \operatorname{rank}(A - \lambda I)$.&lt;/li&gt;
    &lt;li&gt;$1 \le$ geometric $\le$ algebraic; the same characteristic polynomial does not mean the same number of eigendirections.&lt;/li&gt;
    &lt;li&gt;There are $n$ independent eigenvectors exactly when every geometric multiplicity equals the algebraic one.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>The Characteristic Polynomial</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter09/09_02_Da_Thuc_Dac_Trung/"/>
   <updated>2026-01-09T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter09/09_02_Da_Thuc_Dac_Trung</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;form the characteristic polynomial $\det(A - \lambda I)$ and find the eigenvalues of $2 \times 2$ and $3 \times 3$ matrices;&lt;/li&gt;
    &lt;li&gt;find eigenvectors by solving $(A - \lambda I)v = 0$;&lt;/li&gt;
    &lt;li&gt;use $\operatorname{tr} A = \sum \lambda_i$ and $\det A = \prod \lambda_i$ to check results.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;In Lesson 09-01 we were &lt;em&gt;given&lt;/em&gt; eigenvectors and checked them. But for $A = \begin{bmatrix} 4 &amp;amp; 1 \\ 2 &amp;amp; 3 \end{bmatrix}$, how do we &lt;em&gt;find&lt;/em&gt; them? Theorem 1 of Lesson 09-01 turns the geometric question into an equation: $\lambda$ is an eigenvalue exactly when $\det(A - \lambda I) = 0$. Here&lt;/p&gt;

\[\det\begin{bmatrix} 4 - \lambda &amp;amp; 1 \\ 2 &amp;amp; 3 - \lambda \end{bmatrix} = (4 - \lambda)(3 - \lambda) - 2 = \lambda^2 - 7\lambda + 10 = (\lambda - 5)(\lambda - 2).\]

&lt;p&gt;The eigenvalues are $5$ and $2$. One quadratic equation replaces searching through every direction in the plane.&lt;/p&gt;

&lt;h2 id=&quot;the-characteristic-polynomial&quot;&gt;The characteristic polynomial&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Characteristic polynomial).&lt;/strong&gt; The &lt;em&gt;characteristic polynomial&lt;/em&gt; of an $n \times n$ matrix $A$ is&lt;/p&gt;

\[p_A(\lambda) = \det(A - \lambda I).\]

  &lt;p&gt;It is a polynomial of degree $n$ in $\lambda$, and the eigenvalues of $A$ are the roots of the &lt;em&gt;characteristic equation&lt;/em&gt; $p_A(\lambda) = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Expanding the determinant, each term is a product of $n$ entries, each of the form $a_{ij}$ or $a_{ii} - \lambda$, so $p_A$ has degree $n$ with leading coefficient $(-1)^n$. Hence an $n \times n$ matrix has at most $n$ eigenvalues; by the fundamental theorem of algebra (Lesson 00-02), it has exactly $n$ complex eigenvalues counted with multiplicity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Procedure for eigenvalues and eigenvectors.&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Compute $p_A(\lambda) = \det(A - \lambda I)$ and solve $p_A(\lambda) = 0$.&lt;/li&gt;
  &lt;li&gt;For each eigenvalue $\lambda$, solve the homogeneous system $(A - \lambda I)v = 0$ by elimination.&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (continuing the motivating example).&lt;/strong&gt; For $\lambda = 5$: $A - 5I = \begin{bmatrix} -1 &amp;amp; 1 \\ 2 &amp;amp; -2 \end{bmatrix}$, the second row is $-2$ times the first, and the solutions satisfy $v_1 = v_2$: eigenvector $(1, 1)$. For $\lambda = 2$: $A - 2I = \begin{bmatrix} 2 &amp;amp; 1 \\ 2 &amp;amp; 1 \end{bmatrix}$, solutions $2v_1 + v_2 = 0$: eigenvector $(1, -2)$. Check: $A(1, -2) = (2, -4) = 2(1, -2)$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Remark: in step 2, the matrix $A - \lambda I$ &lt;em&gt;must&lt;/em&gt; be singular. If elimination gives only $v = 0$, the eigenvalue was computed wrongly.&lt;/p&gt;

&lt;h2 id=&quot;trace-and-determinant&quot;&gt;Trace and determinant&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; If $\lambda_1, \dots, \lambda_n$ are the (complex, with multiplicity) eigenvalues of $A$, then&lt;/p&gt;

\[\lambda_1 + \dots + \lambda_n = \operatorname{tr} A = a_{11} + \dots + a_{nn}, \qquad \lambda_1 \lambda_2 \cdots \lambda_n = \det A.\]

  &lt;p&gt;For a $2 \times 2$ matrix: $p_A(\lambda) = \lambda^2 - (\operatorname{tr} A)\lambda + \det A$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof (sketch).&lt;/strong&gt; Write $p_A(\lambda) = (\lambda_1 - \lambda)\cdots(\lambda_n - \lambda)$. Setting $\lambda = 0$: $\det A = p_A(0) = \lambda_1 \cdots \lambda_n$. The coefficient of $\lambda^{n-1}$ on the right is $(-1)^{n-1}\sum \lambda_i$. In the expansion of $\det(A - \lambda I)$, only the diagonal product $\prod(a_{ii} - \lambda)$ contributes to $\lambda^{n-1}$ (every other term misses at least two diagonal entries), with coefficient $(-1)^{n-1}\sum a_{ii}$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Check on Example 1: $5 + 2 = 7 = 4 + 3$ and $5 \cdot 2 = 10 = 12 - 2$. Consequence: $A$ is invertible exactly when $0$ is not an eigenvalue.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (a $3 \times 3$ matrix).&lt;/strong&gt; Let $A = \begin{bmatrix} 2 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 2 \end{bmatrix}$. Instead of expanding, observe that $A = I + J$ where $J$ is the all-ones matrix. Then $J(1,1,1) = 3(1,1,1)$, and $J$ has rank 1, so $Jv = 0$ for every $v$ in the plane $v_1 + v_2 + v_3 = 0$. So the eigenvalues of $A$ are $1 + 3 = 4$ (vector $(1,1,1)$) and $1 + 0 = 1$ (the two-dimensional plane $v_1 + v_2 + v_3 = 0$). The characteristic polynomial is $p_A(\lambda) = -(\lambda - 4)(\lambda - 1)^2$. Check: $4 + 1 + 1 = 6 = \operatorname{tr} A$ and $4 \cdot 1 \cdot 1 = 4 = \det A$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-vibration-frequencies&quot;&gt;Application: vibration frequencies&lt;/h2&gt;

&lt;p&gt;Two masses connected to each other and to two walls by three identical springs vibrate according to $x&apos;&apos; = -Kx$ with $K = \begin{bmatrix} 2 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{bmatrix}$ (in suitable units). Looking for solutions $x = v\cos(\omega t)$ leads to $Kv = \omega^2 v$: squared frequencies are eigenvalues of $K$. The characteristic polynomial $\lambda^2 - 4\lambda + 3$ gives $\lambda = 1$ and $3$: two &lt;em&gt;normal modes&lt;/em&gt;, one with the masses moving together ($v = (1, 1)$, $\omega = 1$) and one with them moving opposite ($v = (1, -1)$, $\omega = \sqrt{3}$). Engineers compute such eigenvalues so that bridges and buildings do not resonate with wind or earthquakes.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: the characteristic polynomial&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Pick sample matrices; the trace and determinant give the characteristic polynomial and the eigenvalues.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter09/tri_rieng.html?mode=eig&amp;amp;preset=gen&amp;amp;lang=en&quot; title=&quot;Interactive: the characteristic polynomial&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter09/tri_rieng.html?mode=eig&amp;amp;preset=gen&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Find the eigenvalues and eigenvectors of $\begin{bmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 1 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$p(\lambda) = \lambda^2 - 2\lambda - 3 = (\lambda - 3)(\lambda + 1)$. $\lambda = 3$: $(1, 1)$; $\lambda = -1$: $(1, -1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Find the eigenvalues and eigenvectors of $A = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 \\ 0 &amp;amp; 3 &amp;amp; 0 \\ 2 &amp;amp; -4 &amp;amp; 2 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Expanding along column 3: $p(\lambda) = (2 - \lambda)\left[(1 - \lambda)(3 - \lambda)\right]$, so $\lambda = 1, 2, 3$. Eigenvectors: $\lambda = 1$: $(1, 0, -2)$; $\lambda = 2$: $(0, 0, 1)$; $\lambda = 3$: $(1, 1, -2)$. Trace check: $1 + 2 + 3 = 6 = 1 + 3 + 2$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; A $2 \times 2$ matrix has trace $6$ and determinant $8$. Find its eigenvalues.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\lambda^2 - 6\lambda + 8 = 0$, so $\lambda = 2$ and $4$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Prove: if $A^2 = 0$, every eigenvalue of $A$ is $0$. Give an example of such an $A \ne 0$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

If $Av = \lambda v$, $v \ne 0$, then $0 = A^2v = \lambda^2v$, so $\lambda = 0$. Example: $A = \begin{bmatrix} 0 &amp;amp; 1 \\ 0 &amp;amp; 0 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Prove that similar matrices $B = P^{-1}AP$ have the same characteristic polynomial.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$B - \lambda I = P^{-1}(A - \lambda I)P$, so $\det(B - \lambda I) = \det(P^{-1})\det(A - \lambda I)\det P = \det(A - \lambda I)$. So eigenvalues, trace and determinant belong to the linear map, independent of the basis (Lesson 06-05).

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;The characteristic polynomial $p_A(\lambda) = \det(A - \lambda I)$ has degree $n$; its roots are the eigenvalues.&lt;/li&gt;
    &lt;li&gt;Eigenvectors: solve $(A - \lambda I)v = 0$; this matrix must be singular.&lt;/li&gt;
    &lt;li&gt;$\sum \lambda_i = \operatorname{tr} A$, $\prod \lambda_i = \det A$; for $2 \times 2$: $p_A(\lambda) = \lambda^2 - (\operatorname{tr} A)\lambda + \det A$.&lt;/li&gt;
    &lt;li&gt;Similar matrices have the same characteristic polynomial.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Eigenvalues and Eigenvectors</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter09/09_01_Tri_Rieng_Va_Vecto_Rieng/"/>
   <updated>2026-01-09T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter09/09_01_Tri_Rieng_Va_Vecto_Rieng</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;state the definition $Av = \lambda v$ and check whether a given vector is an eigenvector;&lt;/li&gt;
    &lt;li&gt;find eigenvalues and eigenvectors of geometric transformations (projections, reflections, rotations, scalings) by geometry, without computation;&lt;/li&gt;
    &lt;li&gt;recognize that $\lambda$ is an eigenvalue exactly when $A - \lambda I$ is singular.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Let $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$ act on vectors in the plane. Most vectors get turned: $Ae_1 = (2, 1)$ is not parallel to $e_1 = (1, 0)$. But two directions are special:&lt;/p&gt;

\[A\begin{bmatrix} 1 \\ 1 \end{bmatrix} = \begin{bmatrix} 3 \\ 3 \end{bmatrix} = 3\begin{bmatrix} 1 \\ 1 \end{bmatrix}, \qquad A\begin{bmatrix} 1 \\ -1 \end{bmatrix} = \begin{bmatrix} 1 \\ -1 \end{bmatrix} = 1 \cdot \begin{bmatrix} 1 \\ -1 \end{bmatrix}.\]

&lt;p&gt;On the diagonal $y = x$, $A$ just stretches by 3; on the line $y = -x$, $A$ does nothing. Knowing these two directions is knowing all of $A$: every vector is a combination $c_1(1,1) + c_2(1,-1)$, and $A$ sends it to $3c_1(1,1) + c_2(1,-1)$. This chapter is about finding such directions.&lt;/p&gt;

&lt;h2 id=&quot;definition&quot;&gt;Definition&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Eigenvalue, eigenvector).&lt;/strong&gt; Let $A$ be a square $n \times n$ matrix. A number $\lambda$ is an &lt;em&gt;eigenvalue&lt;/em&gt; of $A$ if there is a vector $v \ne 0$ with&lt;/p&gt;

\[Av = \lambda v.\]

  &lt;p&gt;Then $v$ is an &lt;em&gt;eigenvector&lt;/em&gt; for $\lambda$. The same definition works for a linear map $T : V \to V$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The condition $v \ne 0$ is essential: $A0 = \lambda 0$ holds for every $\lambda$. But $\lambda = 0$ is allowed: $Av = 0v = 0$ with $v \ne 0$ means $v \in \operatorname{Null} A$.&lt;/p&gt;

&lt;p&gt;If $v$ is an eigenvector, so is every $cv$ ($c \ne 0$), with the same $\lambda$: an eigenvector is really a &lt;em&gt;direction&lt;/em&gt; (a line through the origin), not one vector.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; $\lambda$ is an eigenvalue of $A$ if and only if $A - \lambda I$ is singular, if and only if $\det(A - \lambda I) = 0$. The eigenvectors for $\lambda$ are the nonzero vectors of $\operatorname{Null}(A - \lambda I)$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; $Av = \lambda v \iff (A - \lambda I)v = 0$. Such a $v \ne 0$ exists exactly when $\operatorname{Null}(A - \lambda I) \ne \{0\}$, exactly when $A - \lambda I$ is not invertible, exactly when its determinant is $0$ (Chapter 04).&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;eigenvalues-of-geometric-transformations&quot;&gt;Eigenvalues of geometric transformations&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;&lt;em&gt;Projection&lt;/em&gt; $P$ onto a line $L$ in $\mathbb{R}^2$: vectors on $L$ stay put ($\lambda = 1$); vectors perpendicular to $L$ go to $0$ ($\lambda = 0$).&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;Reflection&lt;/em&gt; across $L$: vectors on $L$ stay put ($\lambda = 1$); vectors perpendicular to $L$ flip ($\lambda = -1$).&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;Scaling&lt;/em&gt; $\begin{bmatrix} 3 &amp;amp; 0 \\ 0 &amp;amp; 1/2 \end{bmatrix}$: $e_1$ with $\lambda = 3$, $e_2$ with $\lambda = \tfrac{1}{2}$.&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;Rotation&lt;/em&gt; by $90^\circ$: every nonzero vector is turned, so there are no real eigenvalues (there will be complex ones, $\pm i$, Lesson 09-05).&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;Shear&lt;/em&gt; $\begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \end{bmatrix}$: only the $x$-axis is kept ($\lambda = 1$); every other direction is tilted.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2.&lt;/strong&gt; The eigenvalues of a triangular matrix (upper or lower) are its diagonal entries.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; $A - \lambda I$ is triangular too, with diagonal $a_{ii} - \lambda$. The determinant of a triangular matrix is the product of its diagonal, so $\det(A - \lambda I) = \prod_i (a_{ii} - \lambda)$, which is $0$ exactly when $\lambda$ equals some $a_{ii}$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 3.&lt;/strong&gt; Eigenvectors $v_1, \dots, v_k$ for &lt;em&gt;distinct&lt;/em&gt; eigenvalues $\lambda_1, \dots, \lambda_k$ are linearly independent.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Suppose not, and let $j$ be the smallest index such that $v_j$ is a combination of the (independent) $v_1, \dots, v_{j-1}$: $v_j = \sum_{i&amp;lt;j} c_i v_i$. Multiply by $A$: $\lambda_j v_j = \sum_{i&amp;lt;j} c_i \lambda_i v_i$. Subtract $\lambda_j$ times the first identity: $0 = \sum_{i&amp;lt;j} c_i(\lambda_i - \lambda_j)v_i$. Since $v_1, \dots, v_{j-1}$ are independent and $\lambda_i \ne \lambda_j$, every $c_i = 0$, so $v_j = 0$, a contradiction.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-pagerank&quot;&gt;Application: PageRank&lt;/h2&gt;

&lt;p&gt;Google ranks web pages by viewing the web as a matrix $M$: the entry $m_{ij}$ is the probability that a surfer goes from page $j$ to page $i$. The “importance” vector $r$ of the pages satisfies $Mr = r$: it is an eigenvector for the eigenvalue $1$. The matrix has billions of rows, but only one eigenvector is needed, found by power iteration (Lesson 09-06). Chapter 13 gives the details.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: eigenvalues and eigenvectors&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag x around the unit circle: when Ax lines up with x, x is an eigenvector.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter09/tri_rieng.html?mode=eig&amp;amp;lang=en&quot; title=&quot;Interactive: eigenvalues and eigenvectors&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter09/tri_rieng.html?mode=eig&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-which-directions-dont-turn&quot;&gt;Short video: Which directions don’t turn?&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/eigen-directions.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;24 unit vectors under A = [2 1; 1 2]: most of them turn, only the directions (1; 1) and (1; −1) keep their direction, stretched by 3 and by 1. Eigenvalues from det(A − λ I) = λ² − 4λ + 3 = 0. A shear has only one eigendirection; a 60° rotation has no real eigendirection. Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Check that $(1, 2)$ and $(1, -1)$ are eigenvectors of $A = \begin{bmatrix} 1 &amp;amp; 2 \\ 4 &amp;amp; 3 \end{bmatrix}$ and find their eigenvalues. Is $(1, 0)$ an eigenvector?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A(1,2) = (5, 10) = 5(1, 2)$ and $A(1,-1) = (-1, 1) = -1 \cdot (1, -1)$: eigenvalues $5$ and $-1$. $A(1,0) = (1, 4)$ is not parallel to $(1, 0)$, so no.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Without computing, find the eigenvalues and eigenvectors of the reflection across the plane $z = 0$ in $\mathbb{R}^3$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Every vector in the plane $z = 0$ stays put: $\lambda = 1$ with eigenspace $\operatorname{span}\{e_1, e_2\}$. The $z$-axis flips: $\lambda = -1$ with eigenvector $e_3$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Prove: if $Av = \lambda v$ then $A^2v = \lambda^2v$, and if $A$ is invertible then $A^{-1}v = \lambda^{-1}v$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A^2v = A(\lambda v) = \lambda Av = \lambda^2 v$. If $A$ is invertible then $\lambda \ne 0$ (otherwise $Av = 0$ with $v \ne 0$); multiplying $Av = \lambda v$ by $\lambda^{-1}A^{-1}$ gives $\lambda^{-1}v = A^{-1}v$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Prove that $A$ and $A^T$ have the same eigenvalues.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\det(A^T - \lambda I) = \det((A - \lambda I)^T) = \det(A - \lambda I)$. (The eigenvectors are generally different.)

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; On the space of infinitely differentiable functions, find all “eigenvectors” of the derivative $D(f) = f&apos;$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$f&apos; = \lambda f$ has solutions $f(x) = ce^{\lambda x}$. Every number $\lambda$ is an eigenvalue, with eigenvector $e^{\lambda x}$. This is why exponentials appear when solving linear differential equations (Lesson 09-07).

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$Av = \lambda v$, $v \ne 0$: $v$ is a direction that is kept, $\lambda$ the stretch factor (possibly negative or $0$).&lt;/li&gt;
    &lt;li&gt;$\lambda$ is an eigenvalue $\iff$ $\det(A - \lambda I) = 0$; eigenvectors are the nonzero vectors of $\operatorname{Null}(A - \lambda I)$.&lt;/li&gt;
    &lt;li&gt;Triangular matrices: eigenvalues on the diagonal. Projection: $1, 0$; reflection: $1, -1$; rotation: no real eigenvalues.&lt;/li&gt;
    &lt;li&gt;Eigenvectors for distinct eigenvalues are linearly independent.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Điều kiện số và hồi quy ridge</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter08/08_05_Dieu_Kien_So_Va_Hoi_Quy_Ridge/"/>
   <updated>2026-01-08T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter08/08_05_Dieu_Kien_So_Va_Hoi_Quy_Ridge</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;nhận ra khi nào các cột của $A$ gần phụ thuộc tuyến tính và vì sao nghiệm khi đó nhạy với nhiễu;&lt;/li&gt;
    &lt;li&gt;phát biểu bài toán ridge $\min_x \lVert Ax - b \rVert^2 + \lambda \lVert x \rVert^2$ và giải nó bằng $(A^TA + \lambda I)x = A^Tb$;&lt;/li&gt;
    &lt;li&gt;giải thích sự đánh đổi giữa sai lệch và độ ổn định khi chọn $\lambda$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Một mô hình dự báo dùng hai biến gần như trùng nhau, ví dụ nhiệt độ đo bởi hai cảm biến đặt cạnh nhau. Ma trận thiết kế&lt;/p&gt;

\[A = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1{,}001 \\ 1 &amp;amp; 0{,}999 \end{bmatrix}\]

&lt;p&gt;có hai cột gần bằng nhau. Với $b = (2;\ 2{,}001;\ 1{,}999)$, nghiệm bình phương tối thiểu là $\hat{x} = (1, 1)$, rất hợp lý. Thay đổi dữ liệu một phần nghìn, $b&apos; = (2{,}001;\ 2{,}001;\ 1{,}998)$, nghiệm nhảy thành $\hat{x}&apos; = (0{,}5;\ 1{,}5)$. Một thay đổi nhỏ cỡ nhiễu đo làm hệ số thay đổi $50\%$. Hệ số như vậy không thể tin được, dù cả hai đường khớp đều có sai số rất nhỏ.&lt;/p&gt;

&lt;h2 id=&quot;vì-sao-nghiệm-nhạy&quot;&gt;Vì sao nghiệm nhạy&lt;/h2&gt;

&lt;p&gt;Khi các cột của $A$ gần phụ thuộc, có một vectơ $z$ với $\lVert z \rVert = 1$ mà $\lVert Az \rVert$ rất nhỏ. Ở ví dụ trên, $z \approx \tfrac{1}{\sqrt{2}}(1, -1)$ và $Az = \tfrac{1}{\sqrt{2}}(0;\ -0{,}001;\ 0{,}001)$. Thêm $tz$ vào nghiệm gần như không đổi $Ax$, nên dữ liệu gần như không “phân biệt” được $\hat{x}$ và $\hat{x} + tz$. Một nhiễu nhỏ trong $b$ đủ để đẩy nghiệm đi xa theo hướng $z$. Về đại số, $A^TA = \begin{bmatrix} 3 &amp;amp; 3 \\ 3 &amp;amp; 3{,}000002 \end{bmatrix}$ có định thức chỉ $6 \times 10^{-6}$; số điều kiện của $A$ khoảng $2{,}4 \times 10^3$, nên nhiễu tương đối $10^{-3}$ trong $b$ có thể thành sai số tương đối cỡ $1$ trong $\hat{x}$.&lt;/p&gt;

&lt;h2 id=&quot;hồi-quy-ridge&quot;&gt;Hồi quy ridge&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Hồi quy ridge).&lt;/strong&gt; Với $\lambda &amp;gt; 0$, &lt;em&gt;nghiệm ridge&lt;/em&gt; của $Ax \approx b$ là vectơ $x_\lambda$ làm nhỏ nhất&lt;/p&gt;

  &lt;p&gt;\(\lVert Ax - b \rVert^2 + \lambda \lVert x \rVert^2.\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Số hạng $\lambda \lVert x \rVert^2$ “phạt” các nghiệm có chuẩn lớn: trong số các nghiệm gần như khớp dữ liệu như nhau, ta ưu tiên nghiệm nhỏ.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Với mọi $\lambda &amp;gt; 0$, ma trận $A^TA + \lambda I$ khả nghịch và nghiệm ridge là duy nhất:&lt;/p&gt;

  &lt;p&gt;\(x_\lambda = (A^TA + \lambda I)^{-1} A^Tb.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Bài toán ridge là bình phương tối thiểu cho hệ mở rộng&lt;/p&gt;

\[\begin{bmatrix} A \\ \sqrt{\lambda}\, I \end{bmatrix} x \approx \begin{bmatrix} b \\ 0 \end{bmatrix},\]

  &lt;p&gt;vì bình phương chuẩn của phần dư là $\lVert Ax - b \rVert^2 + \lambda \lVert x \rVert^2$. Ma trận mở rộng có các cột độc lập (khối $\sqrt{\lambda}\, I$ đã đảm bảo điều này), nên theo Bài 08-02 nghiệm duy nhất, và phương trình chuẩn là $(A^TA + \lambda I)x = A^Tb$. Cũng có thể thấy trực tiếp: $x^T(A^TA + \lambda I)x = \lVert Ax \rVert^2 + \lambda \lVert x \rVert^2 &amp;gt; 0$ với $x \ne 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Hệ mở rộng trong chứng minh cũng là cách tính $x_\lambda$ ổn định: giải nó bằng QR (Bài 08-04) thay vì lập $A^TA + \lambda I$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (ví dụ mở đầu).&lt;/strong&gt; Với $\lambda = 0{,}01$: dữ liệu $b$ cho $x_\lambda \approx (0{,}9983;\ 0{,}9983)$, dữ liệu $b&apos;$ cho $x_\lambda \approx (0{,}9983;\ 0{,}9984)$. Hai nghiệm gần như trùng nhau: ridge đã loại bỏ độ nhạy. Cái giá là $x_\lambda$ hơi nhỏ hơn nghiệm “thật” $(1, 1)$ và phần dư lớn hơn một chút.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2 (Ridge co nghiệm).&lt;/strong&gt; Nếu các cột của $A$ trực chuẩn thì $x_\lambda = \dfrac{1}{1 + \lambda}\, \hat{x}$, với $\hat{x} = A^Tb$ là nghiệm bình phương tối thiểu.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; $A^TA = I$, nên $x_\lambda = ((1 + \lambda)I)^{-1} A^Tb = \tfrac{1}{1 + \lambda} A^Tb$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Trường hợp tổng quát (Chương 11, qua SVD): ridge co mỗi thành phần của nghiệm theo hướng kỳ dị thứ $i$ bởi hệ số $\dfrac{\sigma_i^2}{\sigma_i^2 + \lambda}$. Hướng có $\sigma_i$ lớn (được dữ liệu xác định rõ) gần như không bị ảnh hưởng; hướng có $\sigma_i$ nhỏ (như $z$ ở trên) bị co mạnh về $0$. Ridge chỉ “tắt” đúng những hướng không đáng tin.&lt;/p&gt;

&lt;h2 id=&quot;chọn-lambda&quot;&gt;Chọn $\lambda$&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;$\lambda \to 0$: $x_\lambda$ tiến về nghiệm bình phương tối thiểu, khớp dữ liệu tốt nhất nhưng nhạy với nhiễu.&lt;/li&gt;
  &lt;li&gt;$\lambda \to \infty$: $x_\lambda \to 0$, rất ổn định nhưng bỏ qua dữ liệu.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Đây là sự đánh đổi &lt;em&gt;sai lệch – phương sai&lt;/em&gt;. Trong thực hành, $\lambda$ được chọn bằng &lt;em&gt;kiểm định chéo&lt;/em&gt;: chia dữ liệu thành nhiều phần, khớp trên một số phần, đo sai số dự báo trên phần còn lại, và chọn $\lambda$ cho sai số nhỏ nhất. Nên chuẩn hoá các cột của $A$ trước, để mức phạt $\lambda \lVert x \rVert^2$ công bằng giữa các biến có đơn vị khác nhau.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-học-máy-và-khôi-phục-ảnh&quot;&gt;Ứng dụng: học máy và khôi phục ảnh&lt;/h2&gt;

&lt;p&gt;Trong học máy, ridge (còn gọi là &lt;em&gt;suy giảm trọng số&lt;/em&gt;, weight decay, hay chính quy hoá $L^2$) là cách phổ biến nhất để chống quá khớp khi có nhiều đặc trưng hơn dữ liệu, kể cả khi huấn luyện mạng nơ-ron sâu. Trong xử lý ảnh, khôi phục ảnh bị nhoè là giải $Ax = b$ với $A$ là phép làm nhoè, một ma trận có rất nhiều giá trị kỳ dị gần $0$; nghiệm bình phương tối thiểu thuần tuý khuếch đại nhiễu thành các vệt sọc, còn chính quy hoá Tikhonov (tên gọi khác của ridge) cho ảnh rõ và sạch.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: số điều kiện và hồi quy ridge&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Tăng λ: đường cong mượt hơn, hệ số nhỏ lại và AᵀA + λI dễ giải hơn.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter08/binh_phuong_toi_thieu.html?mode=ridge&quot; title=&quot;Minh hoạ: số điều kiện và hồi quy ridge&quot; loading=&quot;lazy&quot; style=&quot;height: 680px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter08/binh_phuong_toi_thieu.html?mode=ridge&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Tính nghiệm ridge với $A = I_2$, $b = (2, 4)$, $\lambda = 1$. Giải thích bằng Định lý 2.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$(I + I)x = b$ cho $x_\lambda = (1, 2)$, đúng bằng $\tfrac{1}{1 + 1}\hat{x}$ với $\hat{x} = (2, 4)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Với $A = \begin{bmatrix} 1 \\ 1 \end{bmatrix}$ và $b = (b_1, b_2)$, tìm $x_\lambda$. Điều gì xảy ra khi $\lambda \to 0$ và $\lambda \to \infty$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A^TA = 2$, $A^Tb = b_1 + b_2$, nên $x_\lambda = \dfrac{b_1 + b_2}{2 + \lambda}$. Khi $\lambda \to 0$ được trung bình $\tfrac{b_1 + b_2}{2}$; khi $\lambda \to \infty$, $x_\lambda \to 0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Chứng minh $\lVert x_\lambda \rVert$ giảm khi $\lambda$ tăng trong trường hợp các cột của $A$ trực chuẩn.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Theo Định lý 2, $\lVert x_\lambda \rVert = \dfrac{\lVert \hat{x} \rVert}{1 + \lambda}$, hàm giảm theo $\lambda$. (Kết luận đúng cho mọi $A$, chứng minh qua SVD ở Chương 11.)

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Chứng minh ridge với $A$ có các cột &lt;em&gt;phụ thuộc&lt;/em&gt; tuyến tính vẫn cho nghiệm duy nhất, và nghiệm đó nằm trong $\operatorname{Row} A$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Định lý 1 không cần giả thiết độc lập, nên nghiệm duy nhất. Từ $(A^TA + \lambda I)x_\lambda = A^Tb$ được $x_\lambda = \tfrac{1}{\lambda}A^T(b - Ax_\lambda)$, là tổ hợp các cột của $A^T$, tức thuộc $\operatorname{Row} A$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (lập trình).&lt;/strong&gt; Với ví dụ mở đầu, vẽ hai thành phần của $x_\lambda$ theo $\lambda$ trên thang log từ $10^{-8}$ đến $10^{2}$ cho cả $b$ và $b&apos;$. Từ khoảng $\lambda$ nào hai đường gần trùng nhau?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Với $\lambda$ rất nhỏ, nghiệm của $b&apos;$ ở gần $(0{,}5;\ 1{,}5)$. Hai nghiệm bắt đầu gần nhau khi $\lambda$ đạt cỡ bình phương giá trị kỳ dị nhỏ của $A$ (khoảng $10^{-6}$), và gần trùng nhau từ khoảng $\lambda \approx 10^{-4}$. Khi $\lambda$ vượt quá cỡ $1$, cả hai bắt đầu co rõ về $0$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Cột gần phụ thuộc làm $A^TA$ gần suy biến; nghiệm bình phương tối thiểu khi đó nhạy với nhiễu theo hướng $z$ có $\lVert Az \rVert$ nhỏ.&lt;/li&gt;
    &lt;li&gt;Ridge: $\min \lVert Ax - b \rVert^2 + \lambda\lVert x \rVert^2$, nghiệm $x_\lambda = (A^TA + \lambda I)^{-1}A^Tb$, luôn duy nhất.&lt;/li&gt;
    &lt;li&gt;Ridge là bình phương tối thiểu cho hệ mở rộng $\begin{bmatrix} A \\ \sqrt{\lambda} I \end{bmatrix}$; nó co mạnh các hướng không đáng tin, giữ các hướng được dữ liệu xác định rõ.&lt;/li&gt;
    &lt;li&gt;Chọn $\lambda$ bằng kiểm định chéo; chuẩn hoá các cột trước khi dùng ridge.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Bình phương tối thiểu bằng QR</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter08/08_04_Binh_Phuong_Toi_Thieu_Bang_QR/"/>
   <updated>2026-01-08T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter08/08_04_Binh_Phuong_Toi_Thieu_Bang_QR</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;giải bài toán bình phương tối thiểu bằng phân rã $A = QR$ qua hệ tam giác $R\hat{x} = Q^Tb$;&lt;/li&gt;
    &lt;li&gt;giải thích vì sao lập $A^TA$ làm bình phương số điều kiện và mất chữ số chính xác;&lt;/li&gt;
    &lt;li&gt;chọn phương pháp phù hợp (phương trình chuẩn, QR, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lstsq&lt;/code&gt;) cho một bài toán thực tế.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Khớp đa thức bậc 14 vào 30 điểm cách đều trên $[0, 1]$, với dữ liệu được sinh đúng từ đa thức có mọi hệ số bằng $1$. Lý thuyết nói nghiệm bình phương tối thiểu phải là đúng các hệ số đó. Trên máy, giải phương trình chuẩn bằng NumPy cho các hệ số sai tới khoảng $5$, tức là vô dụng; giải bằng QR cho sai số khoảng $10^{-6}$. Cùng một bài toán, cùng một máy, hai kết quả rất khác. Bài này giải thích vì sao.&lt;/p&gt;

&lt;h2 id=&quot;bình-phương-tối-thiểu-bằng-qr&quot;&gt;Bình phương tối thiểu bằng QR&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Cho $A$ cỡ $m \times n$ có các cột độc lập tuyến tính và $A = QR$ là phân rã QR (Bài 07-06). Nghiệm bình phương tối thiểu duy nhất của $Ax = b$ là nghiệm của hệ tam giác trên&lt;/p&gt;

  &lt;p&gt;\(R\hat{x} = Q^Tb.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Thay $A = QR$ vào phương trình chuẩn: $A^TA = R^TQ^TQR = R^TR$ và $A^Tb = R^TQ^Tb$. Phương trình chuẩn thành $R^TR\hat{x} = R^TQ^Tb$. Vì $R$ khả nghịch (đường chéo dương), nhân trái với $(R^T)^{-1}$ được $R\hat{x} = Q^Tb$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Ý nghĩa hình học: $QQ^Tb$ là hình chiếu của $b$ lên $\operatorname{Col} A$, và $Q^Tb$ là toạ độ của hình chiếu đó theo cơ sở trực chuẩn $q_1, \dots, q_n$. Hệ $R\hat{x} = Q^Tb$ chỉ đổi toạ độ từ cơ sở $q$ sang cơ sở các cột của $A$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Giải bình phương tối thiểu $Ax = b$ với $A = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix}$, $b = (1, 0, 0)$. Theo Bài tập 1, Bài 07-06: $q_1 = \tfrac{1}{\sqrt{2}}(1, 1, 0)$, $q_2 = \tfrac{1}{\sqrt{6}}(1, -1, 2)$, $R = \begin{bmatrix} \sqrt{2} &amp;amp; 1/\sqrt{2} \\ 0 &amp;amp; \sqrt{3/2} \end{bmatrix}$. Ta có $Q^Tb = \left(\tfrac{1}{\sqrt{2}}, \tfrac{1}{\sqrt{6}}\right)$. Thế ngược:&lt;/p&gt;

\[\sqrt{\tfrac{3}{2}}\, x_2 = \tfrac{1}{\sqrt{6}} \Rightarrow x_2 = \tfrac{1}{3}, \qquad \sqrt{2}\, x_1 + \tfrac{1}{\sqrt{2}} \cdot \tfrac{1}{3} = \tfrac{1}{\sqrt{2}} \Rightarrow x_1 = \tfrac{1}{3}.\]

  &lt;p&gt;Kiểm tra bằng phương trình chuẩn: $A^TA = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$, $A^Tb = (1, 1)$, nghiệm $(\tfrac13, \tfrac13)$. Hình chiếu $A\hat{x} = \tfrac{1}{3}(2, 1, 1)$, khớp với Bài tập 2, Bài 07-06.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;vì-sao-phương-trình-chuẩn-kém-ổn-định&quot;&gt;Vì sao phương trình chuẩn kém ổn định&lt;/h2&gt;

&lt;p&gt;Độ nhạy của một hệ với sai số được đo bằng &lt;em&gt;số điều kiện&lt;/em&gt; $\kappa(A)$ (định nghĩa chính xác qua giá trị kỳ dị ở Chương 11). Quy tắc thực hành: giải một hệ có số điều kiện $\kappa$ bằng số thực dấu phẩy động (khoảng 16 chữ số) mất khoảng $\log_{10}\kappa$ chữ số chính xác.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2 (phát biểu, chứng minh ở Chương 11).&lt;/strong&gt; Với $A$ có các cột độc lập tuyến tính, $\kappa(A^TA) = \kappa(A)^2$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Lập $A^TA$ &lt;em&gt;bình phương&lt;/em&gt; số điều kiện. Trong ví dụ mở đầu, $\kappa(A) \approx 3 \times 10^{10}$: giải bằng QR mất khoảng 10 chữ số, còn lại khoảng 6, khớp với sai số $10^{-6}$. Nhưng $\kappa(A^TA) \approx 10^{17}$, vượt quá 16 chữ số mà máy có: phương trình chuẩn mất &lt;em&gt;mọi&lt;/em&gt; chữ số chính xác. QR làm việc trực tiếp với $A$ và chỉ nhân với ma trận trực giao, vốn không khuếch đại sai số (Bài 07-07).&lt;/p&gt;

&lt;h2 id=&quot;chọn-phương-pháp-nào&quot;&gt;Chọn phương pháp nào&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phương trình chuẩn&lt;/strong&gt;: nhanh nhất (lập $A^TA$ tốn khoảng $mn^2$ phép tính, sau đó chỉ giải hệ $n \times n$), đủ tốt khi các cột của $A$ “khá độc lập” ($\kappa(A)$ nhỏ, ví dụ dưới $10^4$). Phù hợp khi $m$ rất lớn và $n$ nhỏ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;QR (Householder)&lt;/strong&gt;: chậm hơn khoảng hai lần, nhưng ổn định; là lựa chọn mặc định của các thư viện thống kê.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SVD&lt;/strong&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.lstsq&lt;/code&gt;): chậm nhất, nhưng xử lý được cả trường hợp các cột gần phụ thuộc hoặc phụ thuộc (trả về nghiệm chuẩn nhỏ nhất, Chương 11).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Một biện pháp đơn giản giúp mọi phương pháp: chuẩn hoá dữ liệu (trừ trung bình, chia độ lệch chuẩn từng cột) trước khi khớp. Với đa thức, thay $t \in [0, 1]$ bằng $s = 2t - 1 \in [-1, 1]$ hoặc dùng đa thức trực giao (Legendre, Chebyshev) làm giảm mạnh $\kappa(A)$.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-lọc-kalman-và-bình-phương-tối-thiểu-đệ-quy&quot;&gt;Ứng dụng: lọc Kalman và bình phương tối thiểu đệ quy&lt;/h2&gt;

&lt;p&gt;Trong định vị ô tô tự lái hay máy bay, dữ liệu đến liên tục và nghiệm bình phương tối thiểu phải được cập nhật hàng trăm lần mỗi giây. Các bộ lọc Kalman dạng “căn bậc hai” cập nhật trực tiếp thừa số $R$ của phân rã QR thay vì ma trận $A^TA$, chính vì lý do ổn định ở trên: chạy hàng giờ liền, sai số làm tròn trong $A^TA$ có thể làm ma trận mất tính xác định dương và bộ lọc phân kỳ.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: phương trình chuẩn hay QR&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Làm tròn ít chữ số và tăng bậc: phương trình chuẩn mất chính xác nhanh hơn QR vì cond(AᵀA) = cond(A)².&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter08/binh_phuong_toi_thieu.html?mode=qr&quot; title=&quot;Minh hoạ: phương trình chuẩn hay QR&quot; loading=&quot;lazy&quot; style=&quot;height: 680px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter08/binh_phuong_toi_thieu.html?mode=qr&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Dùng phân rã QR của $A = \begin{bmatrix} 3 &amp;amp; 0 \\ 4 &amp;amp; 5 \\ 0 &amp;amp; 0 \end{bmatrix}$ để giải bình phương tối thiểu $Ax = (3, 9, 2)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$q_1 = (\tfrac35, \tfrac45, 0)$, $q_2 = (-\tfrac45, \tfrac35, 0)$, $R = \begin{bmatrix} 5 &amp;amp; 4 \\ 0 &amp;amp; 3 \end{bmatrix}$ (như Ví dụ 2, Bài 07-06). $Q^Tb = (9, 3)$, nên $\hat{x} = (1, 1)$. Phần dư $(0, 0, 2)$ vuông góc với mặt phẳng toạ độ $x_3 = 0$ chứa $\operatorname{Col} A$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Chứng minh: nếu $A = QR$ thì sai số bình phương tối thiểu là $\lVert b \rVert^2 - \lVert Q^Tb \rVert^2$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A\hat{x} = QQ^Tb$ và $\lVert QQ^Tb \rVert = \lVert Q^Tb \rVert$ vì các cột của $Q$ trực chuẩn. Theo Pythagore, $\lVert b - A\hat{x} \rVert^2 = \lVert b \rVert^2 - \lVert A\hat{x} \rVert^2 = \lVert b \rVert^2 - \lVert Q^Tb \rVert^2$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Với $A = \begin{bmatrix} 1 &amp;amp; 1 \\ \varepsilon &amp;amp; 0 \\ 0 &amp;amp; \varepsilon \end{bmatrix}$ (ma trận Läuchli), tính $A^TA$. Điều gì xảy ra trên máy khi $\varepsilon = 10^{-8}$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A^TA = \begin{bmatrix} 1 + \varepsilon^2 &amp;amp; 1 \\ 1 &amp;amp; 1 + \varepsilon^2 \end{bmatrix}$. Với $\varepsilon = 10^{-8}$, $\varepsilon^2 = 10^{-16}$ nhỏ hơn đơn vị làm tròn, nên máy lưu $1 + \varepsilon^2$ thành $1$, và $A^TA$ thành ma trận suy biến $\begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$, dù các cột của $A$ độc lập. QR không gặp vấn đề này.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (lập trình).&lt;/strong&gt; So sánh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.lstsq&lt;/code&gt;, phương trình chuẩn và QR trên ma trận Vandermonde $30 \times (d+1)$ với $t$ cách đều trên $[0, 1]$, $d = 5, 10, 14$, dữ liệu $b = A\mathbf{1}$. Đo $\max \lvert \hat{x} - \mathbf{1} \rvert$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Với $d = 5$ cả ba gần đúng. Khi $d$ tăng, phương trình chuẩn hỏng trước (với $d = 14$, sai số cỡ $1$ trở lên vì $\kappa(A^TA) \approx 10^{17}$), còn QR và `lstsq` giữ sai số khoảng $10^{-6}$, đúng như $\kappa(A) \approx 3 \times 10^{10}$ dự đoán.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Với $A = QR$, nghiệm bình phương tối thiểu thoả $R\hat{x} = Q^Tb$, giải bằng thế ngược; $Q^Tb$ là toạ độ của hình chiếu theo cơ sở trực chuẩn.&lt;/li&gt;
    &lt;li&gt;$\kappa(A^TA) = \kappa(A)^2$: phương trình chuẩn mất gấp đôi số chữ số chính xác so với QR.&lt;/li&gt;
    &lt;li&gt;Phương trình chuẩn nhanh, dùng khi $A$ có điều kiện tốt; QR là mặc định ổn định; SVD xử lý cột gần phụ thuộc.&lt;/li&gt;
    &lt;li&gt;Chuẩn hoá dữ liệu và dùng cơ sở trực giao làm giảm số điều kiện.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Hồi quy tuyến tính và khớp đa thức</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter08/08_03_Hoi_Quy_Tuyen_Tinh_Va_Khop_Da_Thuc/"/>
   <updated>2026-01-08T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter08/08_03_Hoi_Quy_Tuyen_Tinh_Va_Khop_Da_Thuc</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;dựng ma trận thiết kế cho mọi mô hình &lt;em&gt;tuyến tính theo tham số&lt;/em&gt;: đường thẳng, đa thức, hàm tuần hoàn, nhiều biến;&lt;/li&gt;
    &lt;li&gt;khớp mô hình bằng phương trình chuẩn và đọc phần dư;&lt;/li&gt;
    &lt;li&gt;tính hệ số xác định $R^2$ và nhận ra hiện tượng quá khớp khi bậc đa thức quá cao.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Dữ liệu doanh thu hàng tháng của một quán cà phê tăng dần nhưng cong lên; dữ liệu điện tiêu thụ trong ngày lên xuống theo chu kỳ 24 giờ. Đường thẳng không mô tả được những dữ liệu này. Nhưng $y = a + bt + ct^2$ hay $y = a + b\cos t + c\sin t$ đều &lt;em&gt;tuyến tính theo các tham số&lt;/em&gt; $a, b, c$, dù chúng không tuyến tính theo $t$. Đó là tất cả những gì bình phương tối thiểu cần: mọi mô hình như vậy đưa về $A\hat{x} \approx b$ với một ma trận $A$ thích hợp.&lt;/p&gt;

&lt;h2 id=&quot;ma-trận-thiết-kế&quot;&gt;Ma trận thiết kế&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Mô hình tuyến tính, ma trận thiết kế).&lt;/strong&gt; Một &lt;em&gt;mô hình tuyến tính&lt;/em&gt; (theo tham số) có dạng&lt;/p&gt;

\[y = x_1 f_1(t) + x_2 f_2(t) + \dots + x_n f_n(t),\]

  &lt;p&gt;với các hàm cơ sở $f_1, \dots, f_n$ cho trước và các tham số $x_1, \dots, x_n$ cần tìm. Với dữ liệu $(t_1, y_1), \dots, (t_m, y_m)$, &lt;em&gt;ma trận thiết kế&lt;/em&gt; là ma trận $m \times n$ có phần tử $a_{ij} = f_j(t_i)$. Việc khớp mô hình là giải bài toán bình phương tối thiểu $Ax \approx y$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Một số mô hình thường gặp:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;đường thẳng $y = x_1 + x_2 t$: cột $1$ và cột $t_i$;&lt;/li&gt;
  &lt;li&gt;đa thức bậc $d$: cột $1, t_i, t_i^2, \dots, t_i^d$ (ma trận Vandermonde);&lt;/li&gt;
  &lt;li&gt;hàm tuần hoàn: cột $1, \cos t_i, \sin t_i, \cos 2t_i, \dots$;&lt;/li&gt;
  &lt;li&gt;hồi quy nhiều biến $y = x_0 + x_1 u + x_2 v$: cột $1$, $u_i$, $v_i$, với $u$, $v$ là hai đặc trưng đo được.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mô hình $y = ae^{bt}$ không tuyến tính theo $b$, nhưng lấy logarit được $\ln y = \ln a + bt$, tuyến tính theo $\ln a$ và $b$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (khớp parabol).&lt;/strong&gt; Khớp $y = x_1 + x_2 t + x_3 t^2$ vào các điểm $(-1, 3)$, $(0, 1)$, $(1, 2)$, $(2, 5)$.&lt;/p&gt;

\[A = \begin{bmatrix} 1 &amp;amp; -1 &amp;amp; 1 \\ 1 &amp;amp; 0 &amp;amp; 0 \\ 1 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 4 \end{bmatrix}, \quad A^TA = \begin{bmatrix} 4 &amp;amp; 2 &amp;amp; 6 \\ 2 &amp;amp; 6 &amp;amp; 8 \\ 6 &amp;amp; 8 &amp;amp; 18 \end{bmatrix}, \quad A^Tb = \begin{bmatrix} 11 \\ 9 \\ 25 \end{bmatrix}.\]

  &lt;p&gt;Giải được $\hat{x} = \left(\tfrac{23}{20}, -\tfrac{11}{20}, \tfrac{5}{4}\right)$, tức $y = 1{,}15 - 0{,}55t + 1{,}25t^2$. Phần dư $r = \left(\tfrac{1}{20}, -\tfrac{3}{20}, \tfrac{3}{20}, -\tfrac{1}{20}\right)$, tổng bình phương $\tfrac{1}{20} = 0{,}05$: parabol đi rất sát cả bốn điểm.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;đọc-phần-dư-và-hệ-số-r2&quot;&gt;Đọc phần dư và hệ số $R^2$&lt;/h2&gt;

&lt;p&gt;Phần dư cho biết mô hình đã nắm được gì và bỏ sót gì. Nếu phần dư trông ngẫu nhiên, không có quy luật, mô hình phù hợp. Nếu phần dư có dạng cong hoặc tuần hoàn, mô hình thiếu một hàm cơ sở.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 2 (Hệ số xác định).&lt;/strong&gt; Với mô hình có hệ số tự do, đặt $\bar{y}$ là trung bình của $y_i$. &lt;em&gt;Hệ số xác định&lt;/em&gt; là&lt;/p&gt;

  &lt;p&gt;\(R^2 = 1 - \frac{\lVert y - A\hat{x} \rVert^2}{\lVert y - \bar{y}\mathbf{1} \rVert^2}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Mẫu số là sai số khi chỉ khớp hằng số $\bar{y}$ (Bài tập 2, Bài 08-01). Vậy $R^2$ đo tỷ lệ “biến thiên của $y$” mà mô hình giải thích được: $R^2 = 1$ là khớp hoàn hảo, $R^2 = 0$ là không hơn gì giá trị trung bình. Với Ví dụ 1 Bài 08-02: $\lVert y - \bar{y}\mathbf{1} \rVert^2 = 2{,}6^2 + 0{,}6^2 + 0{,}4^2 + 0{,}4^2 + 2{,}4^2 = 13{,}2$ và $\lVert r \rVert^2 = 1{,}1$, nên $R^2 = 1 - 1{,}1/13{,}2 \approx 0{,}917$.&lt;/p&gt;

&lt;h2 id=&quot;quá-khớp&quot;&gt;Quá khớp&lt;/h2&gt;

&lt;p&gt;Với $m$ điểm có các $t_i$ khác nhau, đa thức bậc $m - 1$ luôn đi qua mọi điểm (ma trận Vandermonde vuông khả nghịch): phần dư bằng $0$ và $R^2 = 1$. Nhưng đa thức như vậy thường dao động mạnh giữa các điểm và dự báo rất tệ cho dữ liệu mới. Đây là &lt;em&gt;quá khớp&lt;/em&gt;: mô hình học cả nhiễu. Tăng số tham số luôn làm $R^2$ tăng (cột mới chỉ làm $\operatorname{Col} A$ lớn lên), nên $R^2$ cao chưa chắc là mô hình tốt. Cách kiểm tra thường dùng: giữ lại một phần dữ liệu không dùng để khớp, rồi đo sai số trên phần đó.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-định-luật-hooke-và-hồi-quy-nhiều-biến&quot;&gt;Ứng dụng: định luật Hooke và hồi quy nhiều biến&lt;/h2&gt;

&lt;p&gt;Một kỹ sư đo độ giãn của lò xo dưới các khối lượng khác nhau, khớp đường thẳng và đọc hệ số góc để có độ cứng. Trong kinh tế, giá nhà được mô hình hoá bằng $y = x_0 + x_1 \cdot \text{diện tích} + x_2 \cdot \text{số phòng} + x_3 \cdot \text{khoảng cách đến trung tâm}$: ma trận thiết kế có bốn cột, mỗi căn nhà là một hàng. Mọi phần mềm thống kê (R, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;statsmodels&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scikit-learn&lt;/code&gt;) giải đúng bài toán bình phương tối thiểu này, thường bằng QR (Bài 08-04).&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: hồi quy tuyến tính và khớp đa thức&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Đổi bậc đa thức để thấy sai số giảm và hiện tượng quá khớp.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter08/binh_phuong_toi_thieu.html?mode=fit&amp;amp;deg=2&quot; title=&quot;Minh hoạ: hồi quy tuyến tính và khớp đa thức&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter08/binh_phuong_toi_thieu.html?mode=fit&amp;amp;deg=2&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Viết ma trận thiết kế để khớp $y = a + bt + ct^2$ vào 5 điểm có $t = -2, -1, 0, 1, 2$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A = \begin{bmatrix} 1 &amp;amp; -2 &amp;amp; 4 \\ 1 &amp;amp; -1 &amp;amp; 1 \\ 1 &amp;amp; 0 &amp;amp; 0 \\ 1 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 4 \end{bmatrix}$. Chú ý cột $t$ trực giao với hai cột còn lại vì các $t_i$ đối xứng quanh $0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Khớp $y = a + b\cos t + c\sin t$ vào dữ liệu $t = 0, \tfrac{\pi}{2}, \pi, \tfrac{3\pi}{2}$ với $y = 4, 2, 0, 1$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Ba cột $(1,1,1,1)$, $(1,0,-1,0)$, $(0,1,0,-1)$ đôi một trực giao, nên mỗi hệ số là một hình chiếu: $a = \tfrac{7}{4}$, $b = \tfrac{4 - 0}{2} = 2$, $c = \tfrac{2 - 1}{2} = \tfrac{1}{2}$. Giá trị khớp $(3{,}75;\ 2{,}25;\ -0{,}25;\ 1{,}25)$, phần dư $(0{,}25;\ -0{,}25;\ 0{,}25;\ -0{,}25)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Dữ liệu tăng trưởng vi khuẩn $(t, N)$: $(0, 2)$, $(1, 5)$, $(2, 15)$. Khớp $N = ae^{bt}$ bằng cách lấy logarit (dùng $\ln 2 \approx 0{,}693$, $\ln 5 \approx 1{,}609$, $\ln 15 \approx 2{,}708$).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Khớp $\ln N = \alpha + bt$ với $\alpha = \ln a$. Với $t = 0, 1, 2$: $b = \tfrac{2{,}708 - 0{,}693}{2} \approx 1{,}008$ và $\alpha = \overline{\ln N} - b\bar{t} \approx 1{,}670 - 1{,}008 \approx 0{,}662$, nên $a \approx 1{,}94$. Mô hình $N \approx 1{,}94\, e^{1{,}008t}$. (Đây là bình phương tối thiểu cho $\ln N$, không phải cho $N$.)

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Giải thích vì sao thêm một cột vào ma trận thiết kế không bao giờ làm tăng tổng bình phương phần dư.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Không gian cột mới chứa không gian cột cũ, nên khoảng cách nhỏ nhất từ $b$ đến nó chỉ có thể giảm hoặc giữ nguyên (đặt hệ số của cột mới bằng $0$ thì được lại nghiệm cũ).

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (lập trình).&lt;/strong&gt; Sinh 10 điểm $y_i = \sin(\pi t_i) + \varepsilon_i$ với $t_i$ cách đều trên $[0, 1]$ và nhiễu nhỏ. Khớp đa thức bậc $1, 3, 9$ bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.polyfit&lt;/code&gt; và vẽ. Bậc nào dự báo tốt nhất tại các điểm mới?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Bậc 1 quá đơn giản (thiếu khớp). Bậc 9 đi qua cả 10 điểm, phần dư $0$, nhưng dao động mạnh giữa các điểm (quá khớp). Bậc 3 thường cho sai số nhỏ nhất trên điểm mới.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Mô hình tuyến tính theo tham số $y = \sum x_j f_j(t)$ cho ma trận thiết kế $a_{ij} = f_j(t_i)$; khớp bằng bình phương tối thiểu.&lt;/li&gt;
    &lt;li&gt;Đa thức: ma trận Vandermonde; hàm tuần hoàn: cột $\cos kt$, $\sin kt$; mũ: lấy logarit.&lt;/li&gt;
    &lt;li&gt;Phần dư có quy luật báo hiệu mô hình thiếu thành phần; $R^2 = 1 - \lVert r \rVert^2 / \lVert y - \bar{y}\mathbf{1} \rVert^2$.&lt;/li&gt;
    &lt;li&gt;Thêm tham số luôn làm phần dư nhỏ đi; quá nhiều tham số dẫn đến quá khớp.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Phương trình chuẩn</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter08/08_02_Phuong_Trinh_Chuan/"/>
   <updated>2026-01-08T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter08/08_02_Phuong_Trinh_Chuan</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;suy ra phương trình chuẩn $A^T A x = A^T b$ bằng hình học và bằng đạo hàm;&lt;/li&gt;
    &lt;li&gt;giải phương trình chuẩn để khớp một đường thẳng vào dữ liệu;&lt;/li&gt;
    &lt;li&gt;biết khi nào nghiệm bình phương tối thiểu duy nhất, và mô tả tập nghiệm khi nó không duy nhất.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Bài 08-01 tìm đường thẳng tốt nhất bằng cách chiếu $b$ lên $\operatorname{Col} A$. Nhưng trong thực tế ta không vẽ hình: ta có $A$ và $b$, và cần một hệ phương trình cụ thể cho $\hat{x}$. Điều kiện “phần dư vuông góc với mọi cột của $A$” viết bằng ma trận chỉ là một dòng: $A^T(b - A\hat{x}) = 0$. Hệ ban đầu có $m$ phương trình và vô nghiệm; hệ mới chỉ có $n$ phương trình và luôn có nghiệm.&lt;/p&gt;

&lt;h2 id=&quot;phương-trình-chuẩn&quot;&gt;Phương trình chuẩn&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Phương trình chuẩn).&lt;/strong&gt; Tập các nghiệm bình phương tối thiểu của $Ax = b$ trùng với tập nghiệm của &lt;em&gt;phương trình chuẩn&lt;/em&gt;&lt;/p&gt;

\[A^T A\, \hat{x} = A^T b.\]

  &lt;p&gt;Phương trình chuẩn luôn có nghiệm.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Theo Định lý 1 của Bài 08-01, $\hat{x}$ là nghiệm bình phương tối thiểu khi và chỉ khi $b - A\hat{x}$ vuông góc với mọi cột của $A$, tức $A^T(b - A\hat{x}) = 0$, tức $A^T A \hat{x} = A^T b$. Phương trình luôn có nghiệm vì hình chiếu $\operatorname{proj}_{\operatorname{Col} A} b$ luôn tồn tại và nằm trong $\operatorname{Col} A$, nên có dạng $A\hat{x}$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Cách nhìn bằng giải tích.&lt;/strong&gt; Đặt $f(x) = \lVert Ax - b \rVert^2 = x^T A^T A x - 2 b^T A x + b^T b$. Gradient là $\nabla f(x) = 2A^TAx - 2A^Tb$. Cho gradient bằng $0$ được đúng phương trình chuẩn. Vì $f$ là hàm bậc hai lồi ($A^TA$ nửa xác định dương), mọi điểm dừng đều là cực tiểu toàn cục.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2 (Khi nào nghiệm duy nhất).&lt;/strong&gt; Các điều sau tương đương:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$Ax = b$ có đúng một nghiệm bình phương tối thiểu với mọi $b$;&lt;/li&gt;
    &lt;li&gt;các cột của $A$ độc lập tuyến tính;&lt;/li&gt;
    &lt;li&gt;$A^T A$ khả nghịch.&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;Khi đó $\hat{x} = (A^T A)^{-1} A^T b$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; (2)⇔(3): $\operatorname{Null}(A^TA) = \operatorname{Null} A$ (Bài tập 5, Bài 07-03), và ma trận vuông $A^TA$ khả nghịch khi và chỉ khi không gian không của nó là $\{0\}$. (3)⇒(1): phương trình chuẩn có nghiệm duy nhất. (1)⇒(2): nếu $Az = 0$ với $z \ne 0$ thì $\hat{x} + z$ cũng là nghiệm bình phương tối thiểu, vì $A(\hat{x} + z) = A\hat{x}$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (khớp đường thẳng qua 5 điểm).&lt;/strong&gt; Khớp $y = C + Dt$ vào các điểm $(0, 1)$, $(1, 3)$, $(2, 4)$, $(3, 4)$, $(4, 6)$. Ta có&lt;/p&gt;

\[A = \begin{bmatrix} 1 &amp;amp; 0 \\ 1 &amp;amp; 1 \\ 1 &amp;amp; 2 \\ 1 &amp;amp; 3 \\ 1 &amp;amp; 4 \end{bmatrix}, \quad b = \begin{bmatrix} 1 \\ 3 \\ 4 \\ 4 \\ 6 \end{bmatrix}, \quad A^TA = \begin{bmatrix} 5 &amp;amp; 10 \\ 10 &amp;amp; 30 \end{bmatrix}, \quad A^Tb = \begin{bmatrix} 18 \\ 47 \end{bmatrix}.\]

  &lt;p&gt;Các phần tử có nghĩa rõ ràng: $5 = $ số điểm, $10 = \sum t_i$, $30 = \sum t_i^2$, $18 = \sum y_i$, $47 = \sum t_i y_i$. Giải $5C + 10D = 18$, $10C + 30D = 47$: nhân phương trình đầu với 2 rồi trừ được $10D = 11$, nên $D = \tfrac{11}{10}$ và $C = \tfrac{18 - 11}{5} = \tfrac{7}{5}$. Đường thẳng tốt nhất là&lt;/p&gt;

\[y = 1{,}4 + 1{,}1\, t.\]

  &lt;p&gt;Phần dư $r = b - A\hat{x} = \left(-\tfrac{2}{5}, \tfrac{1}{2}, \tfrac{2}{5}, -\tfrac{7}{10}, \tfrac{1}{5}\right)$. Kiểm tra: tổng các phần dư bằng $0$ (vuông góc với cột $(1,\dots,1)$), và $\sum t_i r_i = 0 + \tfrac12 + \tfrac45 - \tfrac{21}{10} + \tfrac45 = 0$ (vuông góc với cột $t$). Tổng bình phương sai lệch $\lVert r \rVert^2 = \tfrac{11}{10}$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Từ phương trình đầu $5C + 10D = 18$, chia cho $5$: $C + 2D = 3{,}6$, tức đường thẳng đi qua điểm trung bình $(\bar{t}, \bar{y}) = (2;\ 3{,}6)$. Điều này luôn đúng khi mô hình có hệ số tự do.&lt;/p&gt;

&lt;h2 id=&quot;khi-nghiệm-không-duy-nhất&quot;&gt;Khi nghiệm không duy nhất&lt;/h2&gt;

&lt;p&gt;Nếu các cột của $A$ phụ thuộc tuyến tính, phương trình chuẩn có vô số nghiệm, dạng $\hat{x} + z$ với $z \in \operatorname{Null} A$. Mọi nghiệm cho cùng một hình chiếu $A\hat{x}$ và cùng sai số. Ví dụ: trong một mô hình dự báo giá nhà, nếu dùng cả “diện tích theo m²” và “diện tích theo ft²” làm hai biến, hai cột tỷ lệ với nhau, và chỉ có tổ hợp của hai hệ số được xác định. Người ta thường chọn nghiệm có chuẩn nhỏ nhất, cho bởi &lt;em&gt;giả nghịch đảo&lt;/em&gt; (Chương 11), hoặc dùng hồi quy ridge (Bài 08-05).&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-hiệu-chuẩn-cảm-biến&quot;&gt;Ứng dụng: hiệu chuẩn cảm biến&lt;/h2&gt;

&lt;p&gt;Một cảm biến nhiệt cho điện áp $v$ phụ thuộc gần tuyến tính vào nhiệt độ $T$. Để hiệu chuẩn, kỹ sư đặt cảm biến vào $m$ bể nhiệt đã biết nhiệt độ $T_1, \dots, T_m$, ghi điện áp $v_1, \dots, v_m$, rồi khớp $v = C + DT$ bằng phương trình chuẩn. Hai số $C$, $D$ được nạp vào phần mềm để đổi điện áp đo được thành nhiệt độ. Dùng nhiều bể hơn hai làm giảm ảnh hưởng của nhiễu ở từng lần đo.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: phương trình chuẩn&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo, thêm, bớt điểm: đường thẳng giải từ AᵀAx̂ = Aᵀb và tổng bình phương sai số.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter08/binh_phuong_toi_thieu.html?mode=fit&amp;amp;deg=1&quot; title=&quot;Minh hoạ: phương trình chuẩn&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter08/binh_phuong_toi_thieu.html?mode=fit&amp;amp;deg=1&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Khớp đường thẳng $y = C + Dt$ vào bốn điểm $(-1, 1)$, $(0, 1)$, $(1, 2)$, $(2, 4)$ bằng phương trình chuẩn.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A^TA = \begin{bmatrix} 4 &amp;amp; 2 \\ 2 &amp;amp; 6 \end{bmatrix}$, $A^Tb = (8, 9)$. Giải: $4C + 2D = 8$, $2C + 6D = 9$ cho $D = 1$, $C = 1{,}5$. Đường thẳng $y = 1{,}5 + t$; phần dư $(0{,}5;\ -0{,}5;\ -0{,}5;\ 0{,}5)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Khớp đường thẳng &lt;em&gt;qua gốc&lt;/em&gt; $y = Dt$ vào các điểm $(1, 2)$, $(2, 3)$, $(3, 7)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A = (1, 2, 3)^T$, $A^TA = 14$, $A^Tb = 2 + 6 + 21 = 29$, nên $D = \tfrac{29}{14}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Chứng minh: nếu các cột của $A$ độc lập tuyến tính thì $A^TA$ khả nghịch.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Nếu $A^TAx = 0$ thì $0 = x^TA^TAx = \lVert Ax \rVert^2$, nên $Ax = 0$, và vì các cột độc lập, $x = 0$. Ma trận vuông có không gian không $\{0\}$ thì khả nghịch.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Với $A = \begin{bmatrix} 1 &amp;amp; 2 \\ 1 &amp;amp; 2 \\ 1 &amp;amp; 2 \end{bmatrix}$ và $b = (1, 2, 6)$, tìm mọi nghiệm bình phương tối thiểu.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\operatorname{Col} A = \operatorname{span}\{(1,1,1)\}$, hình chiếu của $b$ là $3(1,1,1)$. Cần $x_1 + 2x_2 = 3$: các nghiệm là $(3 - 2s, s)$, $s \in \mathbb{R}$. Phương trình chuẩn $\begin{bmatrix} 3 &amp;amp; 6 \\ 6 &amp;amp; 12 \end{bmatrix} x = (9, 18)$ cho cùng kết quả.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Với mô hình $y = C + Dt$, chứng minh hệ số góc tối ưu là $\hat{D} = \dfrac{\sum (t_i - \bar{t})(y_i - \bar{y})}{\sum (t_i - \bar{t})^2}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Đổi biến $s_i = t_i - \bar{t}$: mô hình thành $y = C&apos; + Ds$ với cột $(1,\dots,1)$ và $s$ trực giao (vì $\sum s_i = 0$). Khi đó $A^TA$ chéo, và $\hat{D} = \dfrac{s \cdot y}{s \cdot s} = \dfrac{\sum s_i y_i}{\sum s_i^2}$. Vì $\sum s_i \bar{y} = 0$, tử số bằng $\sum s_i (y_i - \bar{y})$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Phương trình chuẩn $A^TA\hat{x} = A^Tb$ là điều kiện “phần dư vuông góc với các cột của $A$”, cũng là điều kiện gradient bằng $0$.&lt;/li&gt;
    &lt;li&gt;Phương trình chuẩn luôn có nghiệm; nghiệm duy nhất khi và chỉ khi các cột của $A$ độc lập tuyến tính, khi đó $\hat{x} = (A^TA)^{-1}A^Tb$.&lt;/li&gt;
    &lt;li&gt;Khi khớp đường thẳng, $A^TA$ và $A^Tb$ chứa các tổng $\sum t_i$, $\sum t_i^2$, $\sum y_i$, $\sum t_iy_i$; đường thẳng đi qua điểm trung bình.&lt;/li&gt;
    &lt;li&gt;Cột phụ thuộc: vô số nghiệm $\hat{x} + \operatorname{Null} A$, cùng hình chiếu.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Bài toán xấp xỉ khi hệ vô nghiệm</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter08/08_01_Bai_Toan_Xap_Xi_Khi_He_Vo_Nghiem/"/>
   <updated>2026-01-08T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter08/08_01_Bai_Toan_Xap_Xi_Khi_He_Vo_Nghiem</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;giải thích vì sao hệ có nhiều phương trình hơn ẩn thường vô nghiệm;&lt;/li&gt;
    &lt;li&gt;phát biểu bài toán bình phương tối thiểu $\min_x \lVert Ax - b \rVert$ và đọc nó theo hai cách: theo dữ liệu và theo hình học;&lt;/li&gt;
    &lt;li&gt;nhận ra $A\hat{x}$ là hình chiếu của $b$ lên $\operatorname{Col} A$ và phần dư vuông góc với $\operatorname{Col} A$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Một cảm biến đo nhiệt độ của một vật đang nguội tại ba thời điểm: $t = 0, 1, 2$ (phút), được $6$, $0$, $0$ (độ, so với nhiệt độ phòng). Ta muốn mô tả dữ liệu bằng một đường thẳng $y = C + Dt$. Ba điểm $(0, 6)$, $(1, 0)$, $(2, 0)$ không thẳng hàng, nên không có đường thẳng nào đi qua cả ba. Viết thành hệ phương trình:&lt;/p&gt;

\[\begin{aligned}
C + 0D &amp;amp;= 6 \\
C + 1D &amp;amp;= 0 \\
C + 2D &amp;amp;= 0
\end{aligned}
\qquad\Longleftrightarrow\qquad
\begin{bmatrix} 1 &amp;amp; 0 \\ 1 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix} \begin{bmatrix} C \\ D \end{bmatrix} = \begin{bmatrix} 6 \\ 0 \\ 0 \end{bmatrix}.\]

&lt;p&gt;Hai phương trình đầu cho $C = 6$, $D = -6$, nhưng khi đó phương trình thứ ba thành $-6 = 0$. Hệ vô nghiệm. Đo đạc luôn có nhiễu, nên đây là tình huống thường gặp chứ không phải ngoại lệ. Câu hỏi đúng không phải “nghiệm là gì” mà là “đường thẳng nào &lt;em&gt;tốt nhất&lt;/em&gt;”.&lt;/p&gt;

&lt;h2 id=&quot;bài-toán-bình-phương-tối-thiểu&quot;&gt;Bài toán bình phương tối thiểu&lt;/h2&gt;

&lt;p&gt;Với $A$ cỡ $m \times n$ và $b \in \mathbb{R}^m$, hệ $Ax = b$ có nghiệm khi và chỉ khi $b \in \operatorname{Col} A$ (Chương 05). Khi $m &amp;gt; n$, $\operatorname{Col} A$ là không gian con có số chiều tối đa $n &amp;lt; m$, một “lát mỏng” trong $\mathbb{R}^m$, nên một $b$ ngẫu nhiên hầu như không bao giờ nằm trong đó.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Nghiệm bình phương tối thiểu).&lt;/strong&gt; Cho $A$ cỡ $m \times n$ và $b \in \mathbb{R}^m$. Một &lt;em&gt;nghiệm bình phương tối thiểu&lt;/em&gt; của $Ax = b$ là vectơ $\hat{x} \in \mathbb{R}^n$ sao cho&lt;/p&gt;

\[\lVert A\hat{x} - b \rVert \le \lVert Ax - b \rVert \quad \text{với mọi } x \in \mathbb{R}^n.\]

  &lt;p&gt;Vectơ $r = b - A\hat{x}$ là &lt;em&gt;phần dư&lt;/em&gt;, và $\lVert r \rVert$ là &lt;em&gt;sai số bình phương tối thiểu&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Tên gọi đến từ việc $\lVert Ax - b \rVert^2 = \sum_{i=1}^m \left((Ax)_i - b_i\right)^2$ là tổng bình phương các sai lệch: ta tìm $x$ làm tổng bình phương này nhỏ nhất.&lt;/p&gt;

&lt;h2 id=&quot;hai-cách-nhìn&quot;&gt;Hai cách nhìn&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Cách nhìn theo dữ liệu&lt;/strong&gt; (trong mặt phẳng $(t, y)$). Với đường thẳng $y = C + Dt$, sai lệch tại điểm thứ $i$ là $e_i = b_i - (C + Dt_i)$, khoảng cách theo phương thẳng đứng từ điểm dữ liệu đến đường thẳng. Bài toán: chọn đường thẳng làm $e_1^2 + e_2^2 + e_3^2$ nhỏ nhất. Hình học: tổng diện tích các hình vuông dựng trên các đoạn sai lệch là nhỏ nhất.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cách nhìn theo hình học&lt;/strong&gt; (trong $\mathbb{R}^m$, ở đây $\mathbb{R}^3$). Khi $x = (C, D)$ chạy khắp $\mathbb{R}^2$, $Ax = C(1,1,1) + D(0,1,2)$ chạy khắp mặt phẳng $\operatorname{Col} A$. Bài toán: tìm điểm của mặt phẳng này gần $b = (6, 0, 0)$ nhất. Theo định lý xấp xỉ tốt nhất (Bài 07-04), đó là hình chiếu vuông góc.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; $\hat{x}$ là nghiệm bình phương tối thiểu của $Ax = b$ khi và chỉ khi $A\hat{x} = \operatorname{proj}_{\operatorname{Col} A} b$, khi và chỉ khi phần dư $b - A\hat{x}$ vuông góc với mọi cột của $A$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Tập các giá trị $Ax$ là $\operatorname{Col} A$. Theo định lý xấp xỉ tốt nhất, điểm duy nhất của $\operatorname{Col} A$ gần $b$ nhất là $\hat{b} = \operatorname{proj}_{\operatorname{Col} A} b$; vậy $\hat{x}$ tối ưu khi và chỉ khi $A\hat{x} = \hat{b}$. Theo phân rã trực giao, $A\hat{x} = \hat{b}$ khi và chỉ khi $b - A\hat{x} \in (\operatorname{Col} A)^\perp$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (ví dụ mở đầu).&lt;/strong&gt; Đây đúng là bài toán ta đã giải ở Ví dụ 2, Bài 07-04: hình chiếu của $b = (6, 0, 0)$ lên $\operatorname{Col} A$ là $\hat{b} = (5, 2, -1) = 5(1,1,1) - 3(0,1,2)$. Vậy $\hat{C} = 5$, $\hat{D} = -3$, và đường thẳng tốt nhất là&lt;/p&gt;

\[y = 5 - 3t.\]

  &lt;p&gt;Phần dư $r = (1, -2, 1)$: đường thẳng thấp hơn điểm đầu $1$, cao hơn điểm giữa $2$, thấp hơn điểm cuối $1$. Tổng bình phương sai lệch $1 + 4 + 1 = 6$, và không đường thẳng nào làm tốt hơn.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Hai cách nhìn mô tả cùng một bài toán: ba sai lệch $e_1, e_2, e_3$ trong mặt phẳng dữ liệu chính là ba thành phần của vectơ phần dư $r$ trong $\mathbb{R}^3$. Tổng diện tích các hình vuông nhỏ nhất tương đương với độ dài $\lVert r \rVert$ nhỏ nhất, xảy ra khi $r$ vuông góc với mặt phẳng.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-định-vị-gps&quot;&gt;Ứng dụng: định vị GPS&lt;/h2&gt;

&lt;p&gt;Máy thu GPS đo khoảng cách đến bốn vệ tinh trở lên để tìm bốn ẩn (ba toạ độ và sai lệch đồng hồ). Sau khi tuyến tính hoá, mỗi vệ tinh cho một phương trình tuyến tính. Với 8 đến 12 vệ tinh nhìn thấy cùng lúc, ta có hệ 8 đến 12 phương trình, 4 ẩn, và do nhiễu nên vô nghiệm. Máy thu giải bài toán bình phương tối thiểu nhiều lần mỗi giây; càng nhiều vệ tinh, nhiễu càng được “trung bình hoá” và vị trí càng chính xác.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: hình chiếu trong không gian cột và đường thẳng khớp&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo ba điểm: đường thẳng khớp (trái) và hình chiếu của b lên Col A trong ℝ³ (phải) thay đổi cùng nhau.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter08/binh_phuong_toi_thieu.html?mode=col&quot; title=&quot;Minh hoạ: hình chiếu trong không gian cột và đường thẳng khớp&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter08/binh_phuong_toi_thieu.html?mode=col&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-bình-phương-tối-thiểu-đường-thẳng-và-hình-chiếu&quot;&gt;Video ngắn: Bình phương tối thiểu: đường thẳng và hình chiếu&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/least-squares-two-views.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Bốn điểm (0; 1), (1; 2), (2; 2), (3; 4). Bình phương khoảng hở dọc thành hình vuông; trượt đường thẳng cho tổng diện tích nhỏ nhất, được y = 0,9 + 0,9 t. Nhìn theo vectơ: bốn số y thành b trong R⁴, mỗi đường thẳng là một điểm Ax trên mặt phẳng C(A), gần nhất khi phần dư vuông góc với mặt phẳng: AᵀA x̂ = Aᵀb. Một điểm ngoại lai kéo cả đường đi. Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Viết hệ $Ax = b$ (chưa giải) cho bài toán khớp đường thẳng $y = C + Dt$ qua bốn điểm $(-1, 1)$, $(0, 1)$, $(1, 2)$, $(2, 4)$. Hệ có nghiệm không?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A = \begin{bmatrix} 1 &amp;amp; -1 \\ 1 &amp;amp; 0 \\ 1 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$, $b = (1, 1, 2, 4)$. Hai phương trình đầu cho $D = 0$, $C = 1$, nhưng phương trình thứ ba cho $1 = 2$: vô nghiệm.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Với $A = \begin{bmatrix} 1 \\ 1 \\ 1 \end{bmatrix}$ và $b = (b_1, b_2, b_3)$, tìm nghiệm bình phương tối thiểu của $Ax = b$. Giải thích bằng thống kê.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Chiếu $b$ lên $a = (1,1,1)$: $\hat{x} = \dfrac{a \cdot b}{a \cdot a} = \dfrac{b_1 + b_2 + b_3}{3}$, trung bình cộng. Khớp một hằng số vào dữ liệu theo bình phương tối thiểu cho giá trị trung bình.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Chứng minh: nếu $b \in \operatorname{Col} A$ thì mọi nghiệm bình phương tối thiểu đều là nghiệm đúng của $Ax = b$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Khi $b \in \operatorname{Col} A$, hình chiếu của $b$ lên $\operatorname{Col} A$ là chính $b$, nên theo Định lý 1, $A\hat{x} = b$. Sai số bình phương tối thiểu bằng $0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Với Ví dụ 1, kiểm tra trực tiếp rằng đường thẳng $y = 5 - 3t$ tốt hơn đường $y = 4 - 3t$ và $y = 6 - 4t$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$y = 4 - 3t$: sai lệch $(2, -1, 2)$, tổng bình phương $9$. $y = 6 - 4t$: sai lệch $(0, -2, 2)$, tổng bình phương $8$. Cả hai lớn hơn $6$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Chứng minh: nếu $\hat{x}$ là nghiệm bình phương tối thiểu thì $\lVert b \rVert^2 = \lVert A\hat{x} \rVert^2 + \lVert b - A\hat{x} \rVert^2$. Kiểm tra với Ví dụ 1.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A\hat{x} \in \operatorname{Col} A$ và $b - A\hat{x} \perp \operatorname{Col} A$, nên theo Pythagore. Kiểm tra: $\lVert (6,0,0) \rVert^2 = 36$, $\lVert (5, 2, -1) \rVert^2 = 30$, $\lVert (1, -2, 1) \rVert^2 = 6$, và $30 + 6 = 36$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Hệ có nhiều phương trình hơn ẩn thường vô nghiệm vì $\operatorname{Col} A$ là một lát mỏng trong $\mathbb{R}^m$.&lt;/li&gt;
    &lt;li&gt;Bình phương tối thiểu: tìm $\hat{x}$ làm $\lVert Ax - b \rVert^2$ (tổng bình phương sai lệch) nhỏ nhất.&lt;/li&gt;
    &lt;li&gt;$A\hat{x}$ là hình chiếu của $b$ lên $\operatorname{Col} A$; phần dư $b - A\hat{x}$ vuông góc với mọi cột của $A$.&lt;/li&gt;
    &lt;li&gt;Hai cách nhìn: các hình vuông sai lệch trong mặt phẳng dữ liệu, và vectơ phần dư vuông góc trong $\mathbb{R}^m$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Conditioning and Ridge Regression</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter08/08_05_Dieu_Kien_So_Va_Hoi_Quy_Ridge/"/>
   <updated>2026-01-08T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter08/08_05_Dieu_Kien_So_Va_Hoi_Quy_Ridge</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;recognize when the columns of $A$ are nearly dependent and why the solution is then sensitive to noise;&lt;/li&gt;
    &lt;li&gt;state the ridge problem $\min_x \lVert Ax - b \rVert^2 + \lambda \lVert x \rVert^2$ and solve it via $(A^TA + \lambda I)x = A^Tb$;&lt;/li&gt;
    &lt;li&gt;explain the trade-off between bias and stability in choosing $\lambda$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;A forecasting model uses two almost identical variables, for example temperatures from two sensors mounted side by side. The design matrix&lt;/p&gt;

\[A = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1.001 \\ 1 &amp;amp; 0.999 \end{bmatrix}\]

&lt;p&gt;has two nearly equal columns. With $b = (2, 2.001, 1.999)$, the least-squares solution is $\hat{x} = (1, 1)$, which is very sensible. Change the data by one part in a thousand, $b&apos; = (2.001, 2.001, 1.998)$, and the solution jumps to $\hat{x}&apos; = (0.5, 1.5)$. A change the size of measurement noise moves the coefficients by $50\%$. Such coefficients cannot be trusted, even though both fits have tiny errors.&lt;/p&gt;

&lt;h2 id=&quot;why-the-solution-is-sensitive&quot;&gt;Why the solution is sensitive&lt;/h2&gt;

&lt;p&gt;When the columns of $A$ are nearly dependent, there is a vector $z$ with $\lVert z \rVert = 1$ and $\lVert Az \rVert$ very small. Here $z \approx \tfrac{1}{\sqrt{2}}(1, -1)$ and $Az = \tfrac{1}{\sqrt{2}}(0, -0.001, 0.001)$. Adding $tz$ to a solution barely changes $Ax$, so the data can hardly “tell apart” $\hat{x}$ and $\hat{x} + tz$. A little noise in $b$ is enough to push the solution far along $z$. Algebraically, $A^TA = \begin{bmatrix} 3 &amp;amp; 3 \\ 3 &amp;amp; 3.000002 \end{bmatrix}$ has determinant only $6 \times 10^{-6}$; the condition number of $A$ is about $2.4 \times 10^3$, so a relative error of $10^{-3}$ in $b$ can become a relative error of order $1$ in $\hat{x}$.&lt;/p&gt;

&lt;h2 id=&quot;ridge-regression&quot;&gt;Ridge regression&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Ridge regression).&lt;/strong&gt; For $\lambda &amp;gt; 0$, the &lt;em&gt;ridge solution&lt;/em&gt; of $Ax \approx b$ is the vector $x_\lambda$ minimizing&lt;/p&gt;

  &lt;p&gt;\(\lVert Ax - b \rVert^2 + \lambda \lVert x \rVert^2.\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The term $\lambda \lVert x \rVert^2$ “penalizes” solutions with large norm: among solutions that fit the data almost equally well, we prefer a small one.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; For every $\lambda &amp;gt; 0$, the matrix $A^TA + \lambda I$ is invertible and the ridge solution is unique:&lt;/p&gt;

  &lt;p&gt;\(x_\lambda = (A^TA + \lambda I)^{-1} A^Tb.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Ridge is least squares for the augmented system&lt;/p&gt;

\[\begin{bmatrix} A \\ \sqrt{\lambda}\, I \end{bmatrix} x \approx \begin{bmatrix} b \\ 0 \end{bmatrix},\]

  &lt;p&gt;since the squared norm of its residual is $\lVert Ax - b \rVert^2 + \lambda \lVert x \rVert^2$. The augmented matrix has independent columns (the block $\sqrt{\lambda}\, I$ guarantees it), so by Lesson 08-02 the solution is unique, and the normal equations are $(A^TA + \lambda I)x = A^Tb$. Directly: $x^T(A^TA + \lambda I)x = \lVert Ax \rVert^2 + \lambda \lVert x \rVert^2 &amp;gt; 0$ for $x \ne 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The augmented system in the proof is also a stable way to compute $x_\lambda$: solve it by QR (Lesson 08-04) instead of forming $A^TA + \lambda I$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (the motivating example).&lt;/strong&gt; With $\lambda = 0.01$: data $b$ gives $x_\lambda \approx (0.9983, 0.9983)$, and data $b&apos;$ gives $x_\lambda \approx (0.9983, 0.9984)$. The two solutions almost coincide: ridge has removed the sensitivity. The price is that $x_\lambda$ is slightly smaller than the “true” $(1, 1)$ and the residual slightly larger.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2 (Ridge shrinks).&lt;/strong&gt; If the columns of $A$ are orthonormal, then $x_\lambda = \dfrac{1}{1 + \lambda}\, \hat{x}$, where $\hat{x} = A^Tb$ is the least-squares solution.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; $A^TA = I$, so $x_\lambda = ((1 + \lambda)I)^{-1} A^Tb = \tfrac{1}{1 + \lambda} A^Tb$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;In general (Chapter 11, via the SVD), ridge shrinks the component of the solution along the $i$th singular direction by the factor $\dfrac{\sigma_i^2}{\sigma_i^2 + \lambda}$. Directions with large $\sigma_i$ (well determined by the data) are barely affected; directions with small $\sigma_i$ (like $z$ above) are shrunk strongly toward $0$. Ridge switches off exactly the untrustworthy directions.&lt;/p&gt;

&lt;h2 id=&quot;choosing-lambda&quot;&gt;Choosing $\lambda$&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;$\lambda \to 0$: $x_\lambda$ tends to the least-squares solution, fitting the data best but sensitive to noise.&lt;/li&gt;
  &lt;li&gt;$\lambda \to \infty$: $x_\lambda \to 0$, very stable but ignoring the data.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is the &lt;em&gt;bias–variance&lt;/em&gt; trade-off. In practice $\lambda$ is chosen by &lt;em&gt;cross-validation&lt;/em&gt;: split the data into parts, fit on some, measure prediction error on the rest, and pick the $\lambda$ with the smallest error. Standardize the columns of $A$ first, so that the penalty $\lambda \lVert x \rVert^2$ treats variables with different units fairly.&lt;/p&gt;

&lt;h2 id=&quot;application-machine-learning-and-image-deblurring&quot;&gt;Application: machine learning and image deblurring&lt;/h2&gt;

&lt;p&gt;In machine learning, ridge (also called &lt;em&gt;weight decay&lt;/em&gt; or $L^2$ regularization) is the most common defense against overfitting when there are more features than data, including when training deep neural networks. In image processing, deblurring means solving $Ax = b$ where $A$ is the blur, a matrix with many singular values near $0$; plain least squares amplifies the noise into streaks, while Tikhonov regularization (another name for ridge) gives a sharp, clean image.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: condition number and ridge regression&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Increase λ: the curve smooths out, coefficients shrink and AᵀA + λI is easier to solve.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter08/binh_phuong_toi_thieu.html?mode=ridge&amp;amp;lang=en&quot; title=&quot;Interactive: condition number and ridge regression&quot; loading=&quot;lazy&quot; style=&quot;height: 680px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter08/binh_phuong_toi_thieu.html?mode=ridge&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Compute the ridge solution for $A = I_2$, $b = (2, 4)$, $\lambda = 1$. Explain with Theorem 2.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$(I + I)x = b$ gives $x_\lambda = (1, 2)$, exactly $\tfrac{1}{1 + 1}\hat{x}$ with $\hat{x} = (2, 4)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; With $A = \begin{bmatrix} 1 \\ 1 \end{bmatrix}$ and $b = (b_1, b_2)$, find $x_\lambda$. What happens as $\lambda \to 0$ and $\lambda \to \infty$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A^TA = 2$, $A^Tb = b_1 + b_2$, so $x_\lambda = \dfrac{b_1 + b_2}{2 + \lambda}$. As $\lambda \to 0$ we get the mean $\tfrac{b_1 + b_2}{2}$; as $\lambda \to \infty$, $x_\lambda \to 0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Prove that $\lVert x_\lambda \rVert$ decreases as $\lambda$ increases when the columns of $A$ are orthonormal.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

By Theorem 2, $\lVert x_\lambda \rVert = \dfrac{\lVert \hat{x} \rVert}{1 + \lambda}$, a decreasing function of $\lambda$. (The conclusion holds for every $A$; the proof via the SVD is in Chapter 11.)

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Prove that ridge with &lt;em&gt;dependent&lt;/em&gt; columns in $A$ still has a unique solution, and that it lies in $\operatorname{Row} A$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Theorem 1 does not assume independence, so the solution is unique. From $(A^TA + \lambda I)x_\lambda = A^Tb$ we get $x_\lambda = \tfrac{1}{\lambda}A^T(b - Ax_\lambda)$, a combination of the columns of $A^T$, i.e. in $\operatorname{Row} A$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (programming).&lt;/strong&gt; For the motivating example, plot both components of $x_\lambda$ against $\lambda$ on a log scale from $10^{-8}$ to $10^{2}$, for both $b$ and $b&apos;$. From roughly which $\lambda$ do the curves nearly coincide?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

For very small $\lambda$, the solution for $b&apos;$ stays near $(0.5, 1.5)$. The two solutions start approaching each other when $\lambda$ reaches the square of the small singular value of $A$ (about $10^{-6}$), and nearly coincide from about $\lambda \approx 10^{-4}$. Once $\lambda$ exceeds about $1$, both shrink visibly toward $0$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Nearly dependent columns make $A^TA$ nearly singular; the least-squares solution is then sensitive to noise along directions $z$ with small $\lVert Az \rVert$.&lt;/li&gt;
    &lt;li&gt;Ridge: $\min \lVert Ax - b \rVert^2 + \lambda\lVert x \rVert^2$, with solution $x_\lambda = (A^TA + \lambda I)^{-1}A^Tb$, always unique.&lt;/li&gt;
    &lt;li&gt;Ridge is least squares for the augmented system $\begin{bmatrix} A \\ \sqrt{\lambda} I \end{bmatrix}$; it strongly shrinks untrustworthy directions and keeps well-determined ones.&lt;/li&gt;
    &lt;li&gt;Choose $\lambda$ by cross-validation; standardize columns before using ridge.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Least Squares via QR</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter08/08_04_Binh_Phuong_Toi_Thieu_Bang_QR/"/>
   <updated>2026-01-08T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter08/08_04_Binh_Phuong_Toi_Thieu_Bang_QR</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;solve a least-squares problem with $A = QR$ via the triangular system $R\hat{x} = Q^Tb$;&lt;/li&gt;
    &lt;li&gt;explain why forming $A^TA$ squares the condition number and loses accurate digits;&lt;/li&gt;
    &lt;li&gt;choose a suitable method (normal equations, QR, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lstsq&lt;/code&gt;) for a practical problem.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Fit a degree-14 polynomial to 30 equally spaced points on $[0, 1]$, with data generated exactly by the polynomial whose coefficients are all $1$. In theory the least-squares solution is exactly those coefficients. On a computer, solving the normal equations with NumPy gives coefficients wrong by about $5$, which is useless; solving with QR gives errors of about $10^{-6}$. Same problem, same machine, very different results. This lesson explains why.&lt;/p&gt;

&lt;h2 id=&quot;least-squares-via-qr&quot;&gt;Least squares via QR&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; Let $A$ be $m \times n$ with linearly independent columns and $A = QR$ its QR factorization (Lesson 07-06). The unique least-squares solution of $Ax = b$ solves the upper triangular system&lt;/p&gt;

  &lt;p&gt;\(R\hat{x} = Q^Tb.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Substitute $A = QR$ into the normal equations: $A^TA = R^TQ^TQR = R^TR$ and $A^Tb = R^TQ^Tb$. The normal equations become $R^TR\hat{x} = R^TQ^Tb$. Since $R$ is invertible (positive diagonal), multiplying on the left by $(R^T)^{-1}$ gives $R\hat{x} = Q^Tb$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Geometric meaning: $QQ^Tb$ is the projection of $b$ onto $\operatorname{Col} A$, and $Q^Tb$ gives its coordinates in the orthonormal basis $q_1, \dots, q_n$. The system $R\hat{x} = Q^Tb$ just converts coordinates from the $q$ basis to the basis of columns of $A$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; Solve the least-squares problem $Ax = b$ with $A = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix}$, $b = (1, 0, 0)$. From Exercise 1 of Lesson 07-06: $q_1 = \tfrac{1}{\sqrt{2}}(1, 1, 0)$, $q_2 = \tfrac{1}{\sqrt{6}}(1, -1, 2)$, $R = \begin{bmatrix} \sqrt{2} &amp;amp; 1/\sqrt{2} \\ 0 &amp;amp; \sqrt{3/2} \end{bmatrix}$. Then $Q^Tb = \left(\tfrac{1}{\sqrt{2}}, \tfrac{1}{\sqrt{6}}\right)$. Back substitution:&lt;/p&gt;

\[\sqrt{\tfrac{3}{2}}\, x_2 = \tfrac{1}{\sqrt{6}} \Rightarrow x_2 = \tfrac{1}{3}, \qquad \sqrt{2}\, x_1 + \tfrac{1}{\sqrt{2}} \cdot \tfrac{1}{3} = \tfrac{1}{\sqrt{2}} \Rightarrow x_1 = \tfrac{1}{3}.\]

  &lt;p&gt;Check with the normal equations: $A^TA = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$, $A^Tb = (1, 1)$, solution $(\tfrac13, \tfrac13)$. The projection is $A\hat{x} = \tfrac{1}{3}(2, 1, 1)$, matching Exercise 2 of Lesson 07-06.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;why-the-normal-equations-are-less-stable&quot;&gt;Why the normal equations are less stable&lt;/h2&gt;

&lt;p&gt;The sensitivity of a system to errors is measured by its &lt;em&gt;condition number&lt;/em&gt; $\kappa(A)$ (defined precisely via singular values in Chapter 11). Rule of thumb: solving a system with condition number $\kappa$ in floating point (about 16 digits) loses about $\log_{10}\kappa$ accurate digits.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2 (stated here, proved in Chapter 11).&lt;/strong&gt; If $A$ has linearly independent columns, then $\kappa(A^TA) = \kappa(A)^2$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Forming $A^TA$ &lt;em&gt;squares&lt;/em&gt; the condition number. In the motivating example, $\kappa(A) \approx 3 \times 10^{10}$: QR loses about 10 digits and keeps about 6, matching the $10^{-6}$ error. But $\kappa(A^TA) \approx 10^{17}$, beyond the 16 digits the machine has: the normal equations lose &lt;em&gt;all&lt;/em&gt; accurate digits. QR works directly with $A$ and only multiplies by orthogonal matrices, which do not amplify errors (Lesson 07-07).&lt;/p&gt;

&lt;h2 id=&quot;which-method-to-choose&quot;&gt;Which method to choose&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Normal equations&lt;/strong&gt;: fastest (forming $A^TA$ costs about $mn^2$ operations, then only an $n \times n$ solve), good enough when the columns of $A$ are “quite independent” ($\kappa(A)$ small, say below $10^4$). Suited to very large $m$ and small $n$.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;QR (Householder)&lt;/strong&gt;: about twice as slow, but stable; the default in statistics libraries.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SVD&lt;/strong&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.lstsq&lt;/code&gt;): slowest, but handles nearly dependent or dependent columns (returning the minimum-norm solution, Chapter 11).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One simple measure helps every method: standardize the data (subtract the mean and divide by the standard deviation of each column) before fitting. For polynomials, replacing $t \in [0, 1]$ by $s = 2t - 1 \in [-1, 1]$, or using orthogonal polynomials (Legendre, Chebyshev), reduces $\kappa(A)$ dramatically.&lt;/p&gt;

&lt;h2 id=&quot;application-kalman-filters-and-recursive-least-squares&quot;&gt;Application: Kalman filters and recursive least squares&lt;/h2&gt;

&lt;p&gt;In navigation for self-driving cars or aircraft, data arrives continuously and the least-squares solution must be updated hundreds of times per second. “Square-root” Kalman filters update the factor $R$ of a QR factorization directly instead of the matrix $A^TA$, precisely for the stability reason above: running for hours, rounding errors in $A^TA$ can destroy its positive definiteness and make the filter diverge.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: normal equations versus QR&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Round to few digits and raise the degree: the normal equations lose accuracy faster than QR because cond(AᵀA) = cond(A)².&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter08/binh_phuong_toi_thieu.html?mode=qr&amp;amp;lang=en&quot; title=&quot;Interactive: normal equations versus QR&quot; loading=&quot;lazy&quot; style=&quot;height: 680px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter08/binh_phuong_toi_thieu.html?mode=qr&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Use the QR factorization of $A = \begin{bmatrix} 3 &amp;amp; 0 \\ 4 &amp;amp; 5 \\ 0 &amp;amp; 0 \end{bmatrix}$ to solve the least-squares problem $Ax = (3, 9, 2)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$q_1 = (\tfrac35, \tfrac45, 0)$, $q_2 = (-\tfrac45, \tfrac35, 0)$, $R = \begin{bmatrix} 5 &amp;amp; 4 \\ 0 &amp;amp; 3 \end{bmatrix}$ (as in Example 2 of Lesson 07-06). $Q^Tb = (9, 3)$, so $\hat{x} = (1, 1)$. The residual $(0, 0, 2)$ is perpendicular to the coordinate plane $x_3 = 0$ that contains $\operatorname{Col} A$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Prove: if $A = QR$, the least-squares error is $\lVert b \rVert^2 - \lVert Q^Tb \rVert^2$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A\hat{x} = QQ^Tb$, and $\lVert QQ^Tb \rVert = \lVert Q^Tb \rVert$ because the columns of $Q$ are orthonormal. By Pythagoras, $\lVert b - A\hat{x} \rVert^2 = \lVert b \rVert^2 - \lVert A\hat{x} \rVert^2 = \lVert b \rVert^2 - \lVert Q^Tb \rVert^2$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; For $A = \begin{bmatrix} 1 &amp;amp; 1 \\ \varepsilon &amp;amp; 0 \\ 0 &amp;amp; \varepsilon \end{bmatrix}$ (the Läuchli matrix), compute $A^TA$. What happens on a computer when $\varepsilon = 10^{-8}$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A^TA = \begin{bmatrix} 1 + \varepsilon^2 &amp;amp; 1 \\ 1 &amp;amp; 1 + \varepsilon^2 \end{bmatrix}$. With $\varepsilon = 10^{-8}$, $\varepsilon^2 = 10^{-16}$ is below the unit roundoff, so the machine stores $1 + \varepsilon^2$ as $1$, and $A^TA$ becomes the singular matrix $\begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$, although the columns of $A$ are independent. QR has no such problem.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (programming).&lt;/strong&gt; Compare &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.lstsq&lt;/code&gt;, the normal equations and QR on the $30 \times (d+1)$ Vandermonde matrix with $t$ equally spaced on $[0, 1]$, $d = 5, 10, 14$, and data $b = A\mathbf{1}$. Measure $\max \lvert \hat{x} - \mathbf{1} \rvert$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

At $d = 5$ all three are close. As $d$ grows, the normal equations fail first (at $d = 14$ the error is of order $1$ or more, since $\kappa(A^TA) \approx 10^{17}$), while QR and `lstsq` keep errors around $10^{-6}$, as $\kappa(A) \approx 3 \times 10^{10}$ predicts.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;With $A = QR$, the least-squares solution satisfies $R\hat{x} = Q^Tb$, solved by back substitution; $Q^Tb$ gives the coordinates of the projection in the orthonormal basis.&lt;/li&gt;
    &lt;li&gt;$\kappa(A^TA) = \kappa(A)^2$: the normal equations lose twice as many digits as QR.&lt;/li&gt;
    &lt;li&gt;Normal equations are fast and fine for well-conditioned $A$; QR is the stable default; the SVD handles nearly dependent columns.&lt;/li&gt;
    &lt;li&gt;Standardizing data and using orthogonal bases reduce the condition number.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Linear Regression and Polynomial Fitting</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter08/08_03_Hoi_Quy_Tuyen_Tinh_Va_Khop_Da_Thuc/"/>
   <updated>2026-01-08T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter08/08_03_Hoi_Quy_Tuyen_Tinh_Va_Khop_Da_Thuc</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;build the design matrix for any model that is &lt;em&gt;linear in its parameters&lt;/em&gt;: lines, polynomials, periodic functions, several variables;&lt;/li&gt;
    &lt;li&gt;fit the model with the normal equations and read the residuals;&lt;/li&gt;
    &lt;li&gt;compute the coefficient of determination $R^2$ and recognize overfitting when the polynomial degree is too high.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;A coffee shop’s monthly revenue grows but curves upward; a city’s electricity use rises and falls on a 24-hour cycle. A line cannot describe such data. But $y = a + bt + ct^2$ and $y = a + b\cos t + c\sin t$ are both &lt;em&gt;linear in the parameters&lt;/em&gt; $a, b, c$, even though they are not linear in $t$. That is all least squares needs: every such model reduces to $A\hat{x} \approx b$ for a suitable matrix $A$.&lt;/p&gt;

&lt;h2 id=&quot;the-design-matrix&quot;&gt;The design matrix&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Linear model, design matrix).&lt;/strong&gt; A &lt;em&gt;linear model&lt;/em&gt; (in the parameters) has the form&lt;/p&gt;

\[y = x_1 f_1(t) + x_2 f_2(t) + \dots + x_n f_n(t),\]

  &lt;p&gt;with given basis functions $f_1, \dots, f_n$ and unknown parameters $x_1, \dots, x_n$. For data $(t_1, y_1), \dots, (t_m, y_m)$, the &lt;em&gt;design matrix&lt;/em&gt; is the $m \times n$ matrix with entries $a_{ij} = f_j(t_i)$. Fitting the model means solving the least-squares problem $Ax \approx y$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Some common models:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;a line $y = x_1 + x_2 t$: columns $1$ and $t_i$;&lt;/li&gt;
  &lt;li&gt;a polynomial of degree $d$: columns $1, t_i, t_i^2, \dots, t_i^d$ (a Vandermonde matrix);&lt;/li&gt;
  &lt;li&gt;a periodic function: columns $1, \cos t_i, \sin t_i, \cos 2t_i, \dots$;&lt;/li&gt;
  &lt;li&gt;multiple regression $y = x_0 + x_1 u + x_2 v$: columns $1$, $u_i$, $v_i$, where $u$, $v$ are two measured features.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The model $y = ae^{bt}$ is not linear in $b$, but taking logarithms gives $\ln y = \ln a + bt$, which is linear in $\ln a$ and $b$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (fitting a parabola).&lt;/strong&gt; Fit $y = x_1 + x_2 t + x_3 t^2$ to the points $(-1, 3)$, $(0, 1)$, $(1, 2)$, $(2, 5)$.&lt;/p&gt;

\[A = \begin{bmatrix} 1 &amp;amp; -1 &amp;amp; 1 \\ 1 &amp;amp; 0 &amp;amp; 0 \\ 1 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 4 \end{bmatrix}, \quad A^TA = \begin{bmatrix} 4 &amp;amp; 2 &amp;amp; 6 \\ 2 &amp;amp; 6 &amp;amp; 8 \\ 6 &amp;amp; 8 &amp;amp; 18 \end{bmatrix}, \quad A^Tb = \begin{bmatrix} 11 \\ 9 \\ 25 \end{bmatrix}.\]

  &lt;p&gt;Solving gives $\hat{x} = \left(\tfrac{23}{20}, -\tfrac{11}{20}, \tfrac{5}{4}\right)$, i.e. $y = 1.15 - 0.55t + 1.25t^2$. The residual is $r = \left(\tfrac{1}{20}, -\tfrac{3}{20}, \tfrac{3}{20}, -\tfrac{1}{20}\right)$, with sum of squares $\tfrac{1}{20} = 0.05$: the parabola passes very close to all four points.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;reading-residuals-and-r2&quot;&gt;Reading residuals and $R^2$&lt;/h2&gt;

&lt;p&gt;Residuals show what the model captured and what it missed. If they look random, with no pattern, the model fits. If they curve or oscillate, the model is missing a basis function.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 2 (Coefficient of determination).&lt;/strong&gt; For a model with an intercept, let $\bar{y}$ be the mean of the $y_i$. The &lt;em&gt;coefficient of determination&lt;/em&gt; is&lt;/p&gt;

  &lt;p&gt;\(R^2 = 1 - \frac{\lVert y - A\hat{x} \rVert^2}{\lVert y - \bar{y}\mathbf{1} \rVert^2}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The denominator is the error of fitting just the constant $\bar{y}$ (Exercise 2, Lesson 08-01). So $R^2$ measures the share of “variation in $y$” explained by the model: $R^2 = 1$ is a perfect fit, $R^2 = 0$ is no better than the mean. For Example 1 of Lesson 08-02: $\lVert y - \bar{y}\mathbf{1} \rVert^2 = 2.6^2 + 0.6^2 + 0.4^2 + 0.4^2 + 2.4^2 = 13.2$ and $\lVert r \rVert^2 = 1.1$, so $R^2 = 1 - 1.1/13.2 \approx 0.917$.&lt;/p&gt;

&lt;h2 id=&quot;overfitting&quot;&gt;Overfitting&lt;/h2&gt;

&lt;p&gt;With $m$ points at distinct $t_i$, a polynomial of degree $m - 1$ always passes through every point (the square Vandermonde matrix is invertible): the residual is $0$ and $R^2 = 1$. But such a polynomial usually oscillates wildly between the points and predicts new data badly. This is &lt;em&gt;overfitting&lt;/em&gt;: the model has learned the noise. Adding parameters always increases $R^2$ (a new column only enlarges $\operatorname{Col} A$), so a high $R^2$ does not by itself mean a good model. A standard check: hold back part of the data from the fit and measure the error on it.&lt;/p&gt;

&lt;h2 id=&quot;application-hookes-law-and-multiple-regression&quot;&gt;Application: Hooke’s law and multiple regression&lt;/h2&gt;

&lt;p&gt;An engineer measures a spring’s extension under different masses, fits a line, and reads off the slope to get the stiffness. In economics, house prices are modeled by $y = x_0 + x_1 \cdot \text{area} + x_2 \cdot \text{rooms} + x_3 \cdot \text{distance to center}$: the design matrix has four columns, one row per house. Every statistics package (R, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;statsmodels&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scikit-learn&lt;/code&gt;) solves exactly this least-squares problem, usually by QR (Lesson 08-04).&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: linear regression and polynomial fitting&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Change the polynomial degree to see the error drop and overfitting appear.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter08/binh_phuong_toi_thieu.html?mode=fit&amp;amp;deg=2&amp;amp;lang=en&quot; title=&quot;Interactive: linear regression and polynomial fitting&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter08/binh_phuong_toi_thieu.html?mode=fit&amp;amp;deg=2&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Write the design matrix for fitting $y = a + bt + ct^2$ to 5 points with $t = -2, -1, 0, 1, 2$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A = \begin{bmatrix} 1 &amp;amp; -2 &amp;amp; 4 \\ 1 &amp;amp; -1 &amp;amp; 1 \\ 1 &amp;amp; 0 &amp;amp; 0 \\ 1 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 4 \end{bmatrix}$. Note that the $t$ column is orthogonal to the other two because the $t_i$ are symmetric about $0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Fit $y = a + b\cos t + c\sin t$ to the data $t = 0, \tfrac{\pi}{2}, \pi, \tfrac{3\pi}{2}$ with $y = 4, 2, 0, 1$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The columns $(1,1,1,1)$, $(1,0,-1,0)$, $(0,1,0,-1)$ are pairwise orthogonal, so each coefficient is a projection: $a = \tfrac{7}{4}$, $b = \tfrac{4 - 0}{2} = 2$, $c = \tfrac{2 - 1}{2} = \tfrac{1}{2}$. Fitted values $(3.75, 2.25, -0.25, 1.25)$, residual $(0.25, -0.25, 0.25, -0.25)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Bacterial growth data $(t, N)$: $(0, 2)$, $(1, 5)$, $(2, 15)$. Fit $N = ae^{bt}$ by taking logarithms (use $\ln 2 \approx 0.693$, $\ln 5 \approx 1.609$, $\ln 15 \approx 2.708$).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Fit $\ln N = \alpha + bt$ with $\alpha = \ln a$. With $t = 0, 1, 2$: $b = \tfrac{2.708 - 0.693}{2} \approx 1.008$ and $\alpha = \overline{\ln N} - b\bar{t} \approx 1.670 - 1.008 \approx 0.662$, so $a \approx 1.94$. The model is $N \approx 1.94\, e^{1.008t}$. (This is least squares for $\ln N$, not for $N$.)

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Explain why adding a column to the design matrix never increases the sum of squared residuals.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The new column space contains the old one, so the smallest distance from $b$ to it can only decrease or stay the same (setting the new coefficient to $0$ recovers the old solution).

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (programming).&lt;/strong&gt; Generate 10 points $y_i = \sin(\pi t_i) + \varepsilon_i$ with $t_i$ equally spaced on $[0, 1]$ and small noise. Fit polynomials of degree $1, 3, 9$ with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.polyfit&lt;/code&gt; and plot them. Which degree predicts new points best?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Degree 1 is too simple (underfitting). Degree 9 passes through all 10 points with zero residual but oscillates between them (overfitting). Degree 3 usually gives the smallest error on new points.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;A model linear in its parameters, $y = \sum x_j f_j(t)$, gives the design matrix $a_{ij} = f_j(t_i)$; fit it by least squares.&lt;/li&gt;
    &lt;li&gt;Polynomials: Vandermonde matrix; periodic functions: columns $\cos kt$, $\sin kt$; exponentials: take logarithms.&lt;/li&gt;
    &lt;li&gt;Patterned residuals signal a missing component; $R^2 = 1 - \lVert r \rVert^2 / \lVert y - \bar{y}\mathbf{1} \rVert^2$.&lt;/li&gt;
    &lt;li&gt;More parameters always shrink the residual; too many lead to overfitting.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>The Normal Equations</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter08/08_02_Phuong_Trinh_Chuan/"/>
   <updated>2026-01-08T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter08/08_02_Phuong_Trinh_Chuan</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;derive the normal equations $A^T A x = A^T b$ geometrically and with derivatives;&lt;/li&gt;
    &lt;li&gt;solve the normal equations to fit a line to data;&lt;/li&gt;
    &lt;li&gt;know when the least-squares solution is unique, and describe the solution set when it is not.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Lesson 08-01 found the best line by projecting $b$ onto $\operatorname{Col} A$. In practice we do not draw pictures: we have $A$ and $b$ and need a concrete system for $\hat{x}$. The condition “the residual is perpendicular to every column of $A$” is one line in matrix form: $A^T(b - A\hat{x}) = 0$. The original system had $m$ equations and no solution; the new one has only $n$ equations and always has a solution.&lt;/p&gt;

&lt;h2 id=&quot;the-normal-equations&quot;&gt;The normal equations&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Normal equations).&lt;/strong&gt; The least-squares solutions of $Ax = b$ are exactly the solutions of the &lt;em&gt;normal equations&lt;/em&gt;&lt;/p&gt;

\[A^T A\, \hat{x} = A^T b.\]

  &lt;p&gt;The normal equations are always consistent.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; By Theorem 1 of Lesson 08-01, $\hat{x}$ is a least-squares solution exactly when $b - A\hat{x}$ is perpendicular to every column of $A$, i.e. $A^T(b - A\hat{x}) = 0$, i.e. $A^T A \hat{x} = A^T b$. The equations are consistent because the projection $\operatorname{proj}_{\operatorname{Col} A} b$ always exists and lies in $\operatorname{Col} A$, so it has the form $A\hat{x}$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;The calculus view.&lt;/strong&gt; Let $f(x) = \lVert Ax - b \rVert^2 = x^T A^T A x - 2 b^T A x + b^T b$. Its gradient is $\nabla f(x) = 2A^TAx - 2A^Tb$. Setting the gradient to $0$ gives exactly the normal equations. Since $f$ is a convex quadratic ($A^TA$ is positive semidefinite), every stationary point is a global minimum.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2 (When the solution is unique).&lt;/strong&gt; The following are equivalent:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$Ax = b$ has exactly one least-squares solution for every $b$;&lt;/li&gt;
    &lt;li&gt;the columns of $A$ are linearly independent;&lt;/li&gt;
    &lt;li&gt;$A^T A$ is invertible.&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;Then $\hat{x} = (A^T A)^{-1} A^T b$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; (2)⇔(3): $\operatorname{Null}(A^TA) = \operatorname{Null} A$ (Exercise 5, Lesson 07-03), and the square matrix $A^TA$ is invertible exactly when its null space is $\{0\}$. (3)⇒(1): the normal equations have a unique solution. (1)⇒(2): if $Az = 0$ with $z \ne 0$, then $\hat{x} + z$ is also a least-squares solution, since $A(\hat{x} + z) = A\hat{x}$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (fitting a line to 5 points).&lt;/strong&gt; Fit $y = C + Dt$ to the points $(0, 1)$, $(1, 3)$, $(2, 4)$, $(3, 4)$, $(4, 6)$. We have&lt;/p&gt;

\[A = \begin{bmatrix} 1 &amp;amp; 0 \\ 1 &amp;amp; 1 \\ 1 &amp;amp; 2 \\ 1 &amp;amp; 3 \\ 1 &amp;amp; 4 \end{bmatrix}, \quad b = \begin{bmatrix} 1 \\ 3 \\ 4 \\ 4 \\ 6 \end{bmatrix}, \quad A^TA = \begin{bmatrix} 5 &amp;amp; 10 \\ 10 &amp;amp; 30 \end{bmatrix}, \quad A^Tb = \begin{bmatrix} 18 \\ 47 \end{bmatrix}.\]

  &lt;p&gt;The entries have clear meanings: $5 = $ number of points, $10 = \sum t_i$, $30 = \sum t_i^2$, $18 = \sum y_i$, $47 = \sum t_i y_i$. Solve $5C + 10D = 18$, $10C + 30D = 47$: doubling the first and subtracting gives $10D = 11$, so $D = \tfrac{11}{10}$ and $C = \tfrac{18 - 11}{5} = \tfrac{7}{5}$. The best line is&lt;/p&gt;

\[y = 1.4 + 1.1\, t.\]

  &lt;p&gt;The residual is $r = b - A\hat{x} = \left(-\tfrac{2}{5}, \tfrac{1}{2}, \tfrac{2}{5}, -\tfrac{7}{10}, \tfrac{1}{5}\right)$. Check: the residuals sum to $0$ (orthogonal to the column $(1,\dots,1)$), and $\sum t_i r_i = 0 + \tfrac12 + \tfrac45 - \tfrac{21}{10} + \tfrac45 = 0$ (orthogonal to the column $t$). The sum of squared errors is $\lVert r \rVert^2 = \tfrac{11}{10}$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Dividing the first equation $5C + 10D = 18$ by $5$ gives $C + 2D = 3.6$: the line passes through the mean point $(\bar{t}, \bar{y}) = (2, 3.6)$. This always holds when the model has an intercept.&lt;/p&gt;

&lt;h2 id=&quot;when-the-solution-is-not-unique&quot;&gt;When the solution is not unique&lt;/h2&gt;

&lt;p&gt;If the columns of $A$ are dependent, the normal equations have infinitely many solutions, of the form $\hat{x} + z$ with $z \in \operatorname{Null} A$. All of them give the same projection $A\hat{x}$ and the same error. Example: in a house-price model that uses both “area in m²” and “area in ft²” as variables, the two columns are proportional, and only a combination of their coefficients is determined. One usually picks the solution of smallest norm, given by the &lt;em&gt;pseudoinverse&lt;/em&gt; (Chapter 11), or uses ridge regression (Lesson 08-05).&lt;/p&gt;

&lt;h2 id=&quot;application-calibrating-a-sensor&quot;&gt;Application: calibrating a sensor&lt;/h2&gt;

&lt;p&gt;A temperature sensor outputs a voltage $v$ that depends almost linearly on the temperature $T$. To calibrate it, an engineer places it in $m$ baths of known temperatures $T_1, \dots, T_m$, records voltages $v_1, \dots, v_m$, and fits $v = C + DT$ with the normal equations. The two numbers $C$, $D$ are loaded into the software that converts measured voltages to temperatures. Using more than two baths reduces the effect of noise in individual readings.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: the normal equations&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag, add or remove points: the line solved from AᵀAx̂ = Aᵀb and the sum of squared errors.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter08/binh_phuong_toi_thieu.html?mode=fit&amp;amp;deg=1&amp;amp;lang=en&quot; title=&quot;Interactive: the normal equations&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter08/binh_phuong_toi_thieu.html?mode=fit&amp;amp;deg=1&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Fit the line $y = C + Dt$ to the four points $(-1, 1)$, $(0, 1)$, $(1, 2)$, $(2, 4)$ using the normal equations.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A^TA = \begin{bmatrix} 4 &amp;amp; 2 \\ 2 &amp;amp; 6 \end{bmatrix}$, $A^Tb = (8, 9)$. Solving $4C + 2D = 8$, $2C + 6D = 9$ gives $D = 1$, $C = 1.5$. The line is $y = 1.5 + t$; residual $(0.5, -0.5, -0.5, 0.5)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Fit a line &lt;em&gt;through the origin&lt;/em&gt; $y = Dt$ to the points $(1, 2)$, $(2, 3)$, $(3, 7)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A = (1, 2, 3)^T$, $A^TA = 14$, $A^Tb = 2 + 6 + 21 = 29$, so $D = \tfrac{29}{14}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Prove: if the columns of $A$ are linearly independent, then $A^TA$ is invertible.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

If $A^TAx = 0$ then $0 = x^TA^TAx = \lVert Ax \rVert^2$, so $Ax = 0$, and since the columns are independent, $x = 0$. A square matrix with null space $\{0\}$ is invertible.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; With $A = \begin{bmatrix} 1 &amp;amp; 2 \\ 1 &amp;amp; 2 \\ 1 &amp;amp; 2 \end{bmatrix}$ and $b = (1, 2, 6)$, find all least-squares solutions.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\operatorname{Col} A = \operatorname{span}\{(1,1,1)\}$, and the projection of $b$ is $3(1,1,1)$. We need $x_1 + 2x_2 = 3$: the solutions are $(3 - 2s, s)$, $s \in \mathbb{R}$. The normal equations $\begin{bmatrix} 3 &amp;amp; 6 \\ 6 &amp;amp; 12 \end{bmatrix} x = (9, 18)$ give the same result.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; For the model $y = C + Dt$, prove that the optimal slope is $\hat{D} = \dfrac{\sum (t_i - \bar{t})(y_i - \bar{y})}{\sum (t_i - \bar{t})^2}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Substitute $s_i = t_i - \bar{t}$: the model becomes $y = C&apos; + Ds$, with columns $(1,\dots,1)$ and $s$ orthogonal (since $\sum s_i = 0$). Then $A^TA$ is diagonal and $\hat{D} = \dfrac{s \cdot y}{s \cdot s} = \dfrac{\sum s_i y_i}{\sum s_i^2}$. Since $\sum s_i \bar{y} = 0$, the numerator equals $\sum s_i (y_i - \bar{y})$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;The normal equations $A^TA\hat{x} = A^Tb$ express “the residual is perpendicular to the columns of $A$”, and also “the gradient is $0$”.&lt;/li&gt;
    &lt;li&gt;They are always consistent; the solution is unique exactly when the columns of $A$ are independent, and then $\hat{x} = (A^TA)^{-1}A^Tb$.&lt;/li&gt;
    &lt;li&gt;For a line fit, $A^TA$ and $A^Tb$ contain $\sum t_i$, $\sum t_i^2$, $\sum y_i$, $\sum t_iy_i$; the line passes through the mean point.&lt;/li&gt;
    &lt;li&gt;Dependent columns: infinitely many solutions $\hat{x} + \operatorname{Null} A$, all with the same projection.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Approximating When a System Has No Solution</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter08/08_01_Bai_Toan_Xap_Xi_Khi_He_Vo_Nghiem/"/>
   <updated>2026-01-08T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter08/08_01_Bai_Toan_Xap_Xi_Khi_He_Vo_Nghiem</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;explain why a system with more equations than unknowns usually has no solution;&lt;/li&gt;
    &lt;li&gt;state the least-squares problem $\min_x \lVert Ax - b \rVert$ and read it in two ways: in terms of data and geometrically;&lt;/li&gt;
    &lt;li&gt;recognize $A\hat{x}$ as the projection of $b$ onto $\operatorname{Col} A$, with residual perpendicular to $\operatorname{Col} A$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;A sensor measures the temperature of a cooling object at three times $t = 0, 1, 2$ (minutes) and gets $6$, $0$, $0$ (degrees above room temperature). We want to describe the data by a line $y = C + Dt$. The points $(0, 6)$, $(1, 0)$, $(2, 0)$ are not collinear, so no line passes through all three. As a system:&lt;/p&gt;

\[\begin{aligned}
C + 0D &amp;amp;= 6 \\
C + 1D &amp;amp;= 0 \\
C + 2D &amp;amp;= 0
\end{aligned}
\qquad\Longleftrightarrow\qquad
\begin{bmatrix} 1 &amp;amp; 0 \\ 1 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix} \begin{bmatrix} C \\ D \end{bmatrix} = \begin{bmatrix} 6 \\ 0 \\ 0 \end{bmatrix}.\]

&lt;p&gt;The first two equations give $C = 6$, $D = -6$, but then the third becomes $-6 = 0$. The system is inconsistent. Measurements always carry noise, so this is the usual situation, not an exception. The right question is not “what is the solution” but “which line is &lt;em&gt;best&lt;/em&gt;”.&lt;/p&gt;

&lt;h2 id=&quot;the-least-squares-problem&quot;&gt;The least-squares problem&lt;/h2&gt;

&lt;p&gt;For $A$ of size $m \times n$ and $b \in \mathbb{R}^m$, the system $Ax = b$ is solvable exactly when $b \in \operatorname{Col} A$ (Chapter 05). When $m &amp;gt; n$, $\operatorname{Col} A$ is a subspace of dimension at most $n &amp;lt; m$, a “thin slice” of $\mathbb{R}^m$, so a random $b$ almost never lies in it.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Least-squares solution).&lt;/strong&gt; Let $A$ be $m \times n$ and $b \in \mathbb{R}^m$. A &lt;em&gt;least-squares solution&lt;/em&gt; of $Ax = b$ is a vector $\hat{x} \in \mathbb{R}^n$ such that&lt;/p&gt;

\[\lVert A\hat{x} - b \rVert \le \lVert Ax - b \rVert \quad \text{for all } x \in \mathbb{R}^n.\]

  &lt;p&gt;The vector $r = b - A\hat{x}$ is the &lt;em&gt;residual&lt;/em&gt;, and $\lVert r \rVert$ is the &lt;em&gt;least-squares error&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The name comes from $\lVert Ax - b \rVert^2 = \sum_{i=1}^m \left((Ax)_i - b_i\right)^2$, the sum of squared errors: we look for the $x$ making this sum smallest.&lt;/p&gt;

&lt;h2 id=&quot;two-views&quot;&gt;Two views&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The data view&lt;/strong&gt; (in the $(t, y)$ plane). For the line $y = C + Dt$, the error at point $i$ is $e_i = b_i - (C + Dt_i)$, the vertical distance from the data point to the line. The problem: choose the line minimizing $e_1^2 + e_2^2 + e_3^2$. Geometrically: the total area of the squares built on the error segments is smallest.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The geometric view&lt;/strong&gt; (in $\mathbb{R}^m$, here $\mathbb{R}^3$). As $x = (C, D)$ ranges over $\mathbb{R}^2$, $Ax = C(1,1,1) + D(0,1,2)$ ranges over the plane $\operatorname{Col} A$. The problem: find the point of this plane closest to $b = (6, 0, 0)$. By the best approximation theorem (Lesson 07-04), it is the orthogonal projection.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; $\hat{x}$ is a least-squares solution of $Ax = b$ if and only if $A\hat{x} = \operatorname{proj}_{\operatorname{Col} A} b$, if and only if the residual $b - A\hat{x}$ is perpendicular to every column of $A$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; The set of values $Ax$ is $\operatorname{Col} A$. By the best approximation theorem, the unique point of $\operatorname{Col} A$ closest to $b$ is $\hat{b} = \operatorname{proj}_{\operatorname{Col} A} b$; so $\hat{x}$ is optimal exactly when $A\hat{x} = \hat{b}$. By the orthogonal decomposition, $A\hat{x} = \hat{b}$ exactly when $b - A\hat{x} \in (\operatorname{Col} A)^\perp$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (the motivating example).&lt;/strong&gt; This is exactly the problem solved in Example 2 of Lesson 07-04: the projection of $b = (6, 0, 0)$ onto $\operatorname{Col} A$ is $\hat{b} = (5, 2, -1) = 5(1,1,1) - 3(0,1,2)$. So $\hat{C} = 5$, $\hat{D} = -3$, and the best line is&lt;/p&gt;

\[y = 5 - 3t.\]

  &lt;p&gt;The residual is $r = (1, -2, 1)$: the line passes $1$ below the first point, $2$ above the middle point, and $1$ below the last. The sum of squared errors is $1 + 4 + 1 = 6$, and no line does better.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The two views describe one problem: the three errors $e_1, e_2, e_3$ in the data plane are the three components of the residual vector $r$ in $\mathbb{R}^3$. Minimizing the total area of the squares is minimizing the length $\lVert r \rVert$, which happens when $r$ is perpendicular to the plane.&lt;/p&gt;

&lt;h2 id=&quot;application-gps-positioning&quot;&gt;Application: GPS positioning&lt;/h2&gt;

&lt;p&gt;A GPS receiver measures distances to four or more satellites to find four unknowns (three coordinates and the clock offset). After linearization, each satellite gives one linear equation. With 8 to 12 satellites in view, there are 8 to 12 equations in 4 unknowns, inconsistent because of noise. The receiver solves a least-squares problem several times per second; more satellites average out more noise and give a more accurate position.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: projection in the column space and the fitted line&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag three points: the fitted line (left) and the projection of b onto Col A in ℝ³ (right) move together.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter08/binh_phuong_toi_thieu.html?mode=col&amp;amp;lang=en&quot; title=&quot;Interactive: projection in the column space and the fitted line&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter08/binh_phuong_toi_thieu.html?mode=col&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-least-squares-the-line-and-the-projection&quot;&gt;Short video: Least squares: the line and the projection&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/least-squares-two-views.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Four points (0; 1), (1; 2), (2; 2), (3; 4). Square each vertical gap into a square; slide the line until the total area is smallest, giving y = 0.9 + 0.9 t. In vector view: the four y-values form b in R⁴, each line is a point Ax on the plane C(A), and the closest one has its residual perpendicular to the plane: AᵀA x̂ = Aᵀb. One outlier pulls the whole line. Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Write (without solving) the system $Ax = b$ for fitting a line $y = C + Dt$ to the four points $(-1, 1)$, $(0, 1)$, $(1, 2)$, $(2, 4)$. Is it solvable?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A = \begin{bmatrix} 1 &amp;amp; -1 \\ 1 &amp;amp; 0 \\ 1 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$, $b = (1, 1, 2, 4)$. The first two equations give $D = 0$, $C = 1$, but then the third gives $1 = 2$: inconsistent.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; With $A = \begin{bmatrix} 1 \\ 1 \\ 1 \end{bmatrix}$ and $b = (b_1, b_2, b_3)$, find the least-squares solution of $Ax = b$. Interpret it statistically.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Project $b$ onto $a = (1,1,1)$: $\hat{x} = \dfrac{a \cdot b}{a \cdot a} = \dfrac{b_1 + b_2 + b_3}{3}$, the mean. Fitting a constant to data by least squares gives the average.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Prove: if $b \in \operatorname{Col} A$, every least-squares solution is an exact solution of $Ax = b$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

When $b \in \operatorname{Col} A$, the projection of $b$ onto $\operatorname{Col} A$ is $b$ itself, so by Theorem 1, $A\hat{x} = b$. The least-squares error is $0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; In Example 1, check directly that the line $y = 5 - 3t$ beats $y = 4 - 3t$ and $y = 6 - 4t$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$y = 4 - 3t$: errors $(2, -1, 2)$, sum of squares $9$. $y = 6 - 4t$: errors $(0, -2, 2)$, sum of squares $8$. Both exceed $6$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Prove that if $\hat{x}$ is a least-squares solution, then $\lVert b \rVert^2 = \lVert A\hat{x} \rVert^2 + \lVert b - A\hat{x} \rVert^2$. Check it on Example 1.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A\hat{x} \in \operatorname{Col} A$ and $b - A\hat{x} \perp \operatorname{Col} A$, so this is Pythagoras. Check: $\lVert (6,0,0) \rVert^2 = 36$, $\lVert (5, 2, -1) \rVert^2 = 30$, $\lVert (1, -2, 1) \rVert^2 = 6$, and $30 + 6 = 36$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;A system with more equations than unknowns is usually inconsistent because $\operatorname{Col} A$ is a thin slice of $\mathbb{R}^m$.&lt;/li&gt;
    &lt;li&gt;Least squares: find $\hat{x}$ minimizing $\lVert Ax - b \rVert^2$ (the sum of squared errors).&lt;/li&gt;
    &lt;li&gt;$A\hat{x}$ is the projection of $b$ onto $\operatorname{Col} A$; the residual $b - A\hat{x}$ is perpendicular to every column of $A$.&lt;/li&gt;
    &lt;li&gt;Two views: squares of errors in the data plane, and a perpendicular residual vector in $\mathbb{R}^m$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Ma trận trực giao, phép quay và phép phản xạ</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter07/07_07_Ma_Tran_Truc_Giao_Phep_Quay_Va_Phan_Xa/"/>
   <updated>2026-01-07T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter07/07_07_Ma_Tran_Truc_Giao_Phep_Quay_Va_Phan_Xa</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;nhận ra ma trận trực giao qua $Q^T Q = I$ và dùng $Q^{-1} = Q^T$;&lt;/li&gt;
    &lt;li&gt;chứng minh ma trận trực giao bảo toàn tích vô hướng, độ dài và góc, và có định thức $\pm 1$;&lt;/li&gt;
    &lt;li&gt;lập ma trận quay trong $\mathbb{R}^2$ và ma trận phản xạ Householder $H = I - 2uu^T$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Một camera trong trò chơi 3D xoay quanh nhân vật. Mỗi khung hình, toạ độ của mọi điểm được nhân với một ma trận quay. Sau hàng nghìn khung hình, nhân vật vẫn phải giữ đúng kích thước và hình dạng: không được co lại, không được méo. Điều kiện để một ma trận “không làm méo” là gì? Câu trả lời: các cột của nó phải trực chuẩn. Ma trận như vậy gọi là ma trận trực giao, và nghịch đảo của nó chỉ là chuyển vị, không cần khử Gauss.&lt;/p&gt;

&lt;h2 id=&quot;định-nghĩa-và-tính-chất&quot;&gt;Định nghĩa và tính chất&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Ma trận trực giao).&lt;/strong&gt; Ma trận vuông $Q$ cỡ $n \times n$ là &lt;em&gt;ma trận trực giao&lt;/em&gt; nếu $Q^T Q = I$, tức các cột của $Q$ là một cơ sở trực chuẩn của $\mathbb{R}^n$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Chú ý tên gọi: ma trận &lt;em&gt;trực giao&lt;/em&gt; có các cột &lt;em&gt;trực chuẩn&lt;/em&gt;. Vì $Q$ vuông, $Q^TQ = I$ kéo theo $Q^{-1} = Q^T$, nên cũng có $QQ^T = I$: các &lt;em&gt;hàng&lt;/em&gt; của $Q$ cũng trực chuẩn.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Với ma trận vuông $Q$, các điều sau tương đương:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$Q$ trực giao;&lt;/li&gt;
    &lt;li&gt;$\langle Qx, Qy \rangle = \langle x, y \rangle$ với mọi $x, y$ (bảo toàn tích vô hướng);&lt;/li&gt;
    &lt;li&gt;$\lVert Qx \rVert = \lVert x \rVert$ với mọi $x$ (bảo toàn độ dài).&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;Khi đó $Q$ bảo toàn cả góc và khoảng cách, và $\det Q = \pm 1$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; (1)⇒(2): $(Qx)^T(Qy) = x^T Q^T Q y = x^T y$. (2)⇒(3): lấy $y = x$. (3)⇒(1): theo Bài 07-01, tích vô hướng khôi phục được từ chuẩn qua $\langle u, v \rangle = \tfrac14(\lVert u + v \rVert^2 - \lVert u - v \rVert^2)$, nên bảo toàn chuẩn kéo theo bảo toàn tích vô hướng; áp dụng cho $x = e_i$, $y = e_j$ được $q_i^T q_j = \delta_{ij}$, tức $Q^TQ = I$. Góc và khoảng cách được định nghĩa qua tích vô hướng và chuẩn nên được bảo toàn. Cuối cùng $1 = \det(Q^TQ) = (\det Q)^2$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2.&lt;/strong&gt; Tích của hai ma trận trực giao là ma trận trực giao; nghịch đảo của ma trận trực giao là ma trận trực giao.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; $(Q_1Q_2)^T(Q_1Q_2) = Q_2^T Q_1^T Q_1 Q_2 = Q_2^T Q_2 = I$, và $(Q^{-1})^T Q^{-1} = (Q^T)^T Q^T = QQ^T = I$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;phép-quay&quot;&gt;Phép quay&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (phép quay trong $\mathbb{R}^2$).&lt;/strong&gt; Ma trận quay góc $\theta$ là&lt;/p&gt;

\[R_\theta = \begin{bmatrix} \cos\theta &amp;amp; -\sin\theta \\ \sin\theta &amp;amp; \cos\theta \end{bmatrix}.\]

  &lt;p&gt;Hai cột có độ dài $1$ và vuông góc, nên $R_\theta$ trực giao, $\det R_\theta = \cos^2\theta + \sin^2\theta = 1$, và $R_\theta^{-1} = R_\theta^T = R_{-\theta}$: quay ngược lại góc $\theta$. Ta có $R_\alpha R_\beta = R_{\alpha + \beta}$, khớp với phép nhân số phức (Bài 00-02).&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Mọi ma trận trực giao $2 \times 2$ có định thức $1$ là một phép quay $R_\theta$. Trong $\mathbb{R}^3$, mọi ma trận trực giao có định thức $1$ là phép quay quanh một trục (định lý Euler, chứng minh ở Chương 09 bằng trị riêng $1$). Các ma trận trực giao có định thức $1$ gọi là &lt;em&gt;phép quay&lt;/em&gt;, có định thức $-1$ thì chứa một phép phản xạ.&lt;/p&gt;

&lt;h2 id=&quot;phép-phản-xạ-householder&quot;&gt;Phép phản xạ Householder&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 2 (Phép phản xạ Householder).&lt;/strong&gt; Cho $u \in \mathbb{R}^n$ là vectơ đơn vị. Ma trận&lt;/p&gt;

\[H = I - 2uu^T\]

  &lt;p&gt;là phép &lt;em&gt;phản xạ&lt;/em&gt; qua siêu phẳng $u^\perp$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 3.&lt;/strong&gt; $H = I - 2uu^T$ đối xứng, trực giao, $H^2 = I$, $Hu = -u$, $Hx = x$ với mọi $x \perp u$, và $\det H = -1$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; $H^T = I - 2(uu^T)^T = H$. $H^2 = I - 4uu^T + 4u(u^Tu)u^T = I$ vì $u^Tu = 1$; đối xứng và $H^2 = I$ cho $H^TH = I$. $Hu = u - 2u(u^Tu) = -u$, và nếu $u^Tx = 0$ thì $Hx = x$. Trong một cơ sở gồm $u$ và $n - 1$ vectơ của $u^\perp$, $H$ có ma trận chéo với các phần tử $-1, 1, \dots, 1$, nên $\det H = -1$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Ý nghĩa: $x = (x - \operatorname{proj}_u x) + \operatorname{proj}_u x$, và $H$ giữ phần thứ nhất, đảo dấu phần thứ hai. Đây là “soi gương” qua mặt phẳng vuông góc với $u$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (đưa một vectơ về trục).&lt;/strong&gt; Tìm phép phản xạ biến $x = (3, 4)$ thành $(5, 0)$ (cùng độ dài $5$). Phép phản xạ biến $x$ thành $y$ khi $u$ cùng hướng với $x - y = (-2, 4)$. Với $w = (-2, 4)$, $w^Tw = 20$:&lt;/p&gt;

\[H = I - \frac{2ww^T}{w^Tw} = I - \frac{1}{10}\begin{bmatrix} 4 &amp;amp; -8 \\ -8 &amp;amp; 16 \end{bmatrix} = \begin{bmatrix} 3/5 &amp;amp; 4/5 \\ 4/5 &amp;amp; -3/5 \end{bmatrix}.\]

  &lt;p&gt;Kiểm tra: $Hx = (\tfrac{9 + 16}{5}, \tfrac{12 - 12}{5}) = (5, 0)$, và $\det H = -\tfrac{9}{25} - \tfrac{16}{25} = -1$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Ví dụ 2 là ý tưởng của &lt;em&gt;phân rã QR bằng Householder&lt;/em&gt;: dùng một phép phản xạ đưa cột thứ nhất của $A$ về dạng $(r_{11}, 0, \dots, 0)$, rồi lặp lại với ma trận con. Tích các phép phản xạ là $Q^T$. Vì chỉ nhân với ma trận trực giao, phương pháp này không khuếch đại sai số; đó là lý do &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.qr&lt;/code&gt; giữ được trực giao tốt hơn Gram–Schmidt (Bài 07-05).&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3 (ma trận hoán vị).&lt;/strong&gt; Ma trận hoán vị $P$ (mỗi hàng, mỗi cột có đúng một số $1$) là ma trận trực giao: các cột là các vectơ $e_i$ theo thứ tự khác. Ví dụ $\begin{bmatrix} 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix}$ là phản xạ qua đường $y = x$, với định thức $-1$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-vì-sao-các-thuật-toán-số-thích-ma-trận-trực-giao&quot;&gt;Ứng dụng: vì sao các thuật toán số thích ma trận trực giao&lt;/h2&gt;

&lt;p&gt;Nếu $x$ có sai số $\delta x$ thì $Q(x + \delta x) = Qx + Q\,\delta x$ và $\lVert Q\,\delta x \rVert = \lVert \delta x \rVert$: nhân với ma trận trực giao không làm sai số lớn lên. Ngược lại, nhân với một ma trận bất kỳ có thể khuếch đại sai số theo số điều kiện của nó (Chương 11). Vì vậy các thuật toán hiện đại (QR bằng Householder, thuật toán QR tìm trị riêng, SVD) đều được xây từ các phép quay và phản xạ. Trong đồ hoạ và robot (Chương 12), ma trận quay được tái trực chuẩn hoá định kỳ để chống tích luỹ sai số qua hàng nghìn phép nhân, đúng như camera ở ví dụ mở đầu.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: phép quay và phản xạ Householder&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo x, u: độ dài và tích vô hướng giữ nguyên; nút Householder đưa x về (‖x‖, 0).&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter07/quay_phan_xa.html&quot; title=&quot;Minh hoạ: phép quay và phản xạ Householder&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter07/quay_phan_xa.html&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Ma trận nào sau đây trực giao? $A = \tfrac{1}{3}\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 2 \\ 2 &amp;amp; 1 &amp;amp; -2 \\ 2 &amp;amp; -2 &amp;amp; 1 \end{bmatrix}$, $B = \begin{bmatrix} 1 &amp;amp; 1 \\ -1 &amp;amp; 1 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A$ trực giao: các cột là $\tfrac13(1,2,2)$, $\tfrac13(2,1,-2)$, $\tfrac13(2,-2,1)$, đôi một vuông góc (Bài tập 1, Bài 07-03) và có độ dài $1$. $B$ không trực giao: các cột vuông góc nhưng có độ dài $\sqrt{2}$; $\tfrac{1}{\sqrt{2}}B$ là ma trận quay góc $-45^\circ$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Tìm phép phản xạ Householder biến $x = (1, 2, 2)$ thành $(3, 0, 0)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$w = x - (3,0,0) = (-2, 2, 2)$, $w^Tw = 12$, $H = I - \tfrac{1}{6}ww^T = \tfrac{1}{3}\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 2 \\ 2 &amp;amp; 1 &amp;amp; -2 \\ 2 &amp;amp; -2 &amp;amp; 1 \end{bmatrix}$. Kiểm tra: $Hx = \tfrac13(1 + 4 + 4,\ 2 + 2 - 4,\ 2 - 4 + 2) = (3, 0, 0)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Chứng minh: nếu $\lambda$ là trị riêng thực của ma trận trực giao $Q$ thì $\lambda = \pm 1$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Nếu $Qx = \lambda x$ với $x \ne 0$ thì $\lVert x \rVert = \lVert Qx \rVert = \lvert \lambda \rvert \lVert x \rVert$, nên $\lvert \lambda \rvert = 1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Chứng minh tích của hai phép phản xạ trong $\mathbb{R}^2$ là một phép quay.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Tích của hai ma trận trực giao là trực giao (Định lý 2), và định thức bằng $(-1)(-1) = 1$. Một ma trận trực giao $2 \times 2$ có định thức $1$ là một phép quay. (Hình học: phản xạ qua hai đường thẳng cách nhau góc $\alpha$ là quay góc $2\alpha$.)

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Chứng minh mọi ma trận trực giao $2 \times 2$ có dạng $R_\theta$ hoặc $\begin{bmatrix} \cos\theta &amp;amp; \sin\theta \\ \sin\theta &amp;amp; -\cos\theta \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Cột thứ nhất là vectơ đơn vị nên có dạng $(\cos\theta, \sin\theta)$. Cột thứ hai là vectơ đơn vị vuông góc với nó, nên là $(-\sin\theta, \cos\theta)$ hoặc $(\sin\theta, -\cos\theta)$. Trường hợp thứ nhất là $R_\theta$ (định thức $1$), trường hợp thứ hai là phản xạ qua đường thẳng góc $\theta/2$ (định thức $-1$).

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$Q$ trực giao khi $Q^TQ = I$ (cột trực chuẩn); khi đó $Q^{-1} = Q^T$ và các hàng cũng trực chuẩn.&lt;/li&gt;
    &lt;li&gt;Ma trận trực giao bảo toàn tích vô hướng, độ dài, góc; $\det Q = \pm 1$; tích và nghịch đảo của ma trận trực giao vẫn trực giao.&lt;/li&gt;
    &lt;li&gt;Phép quay $R_\theta$ có định thức $1$; phản xạ Householder $H = I - 2uu^T$ đối xứng, $H^2 = I$, định thức $-1$.&lt;/li&gt;
    &lt;li&gt;Householder đưa một vectơ về trục toạ độ, là nền của phân rã QR ổn định.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Phân rã QR</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter07/07_06_Phan_Ra_QR/"/>
   <updated>2026-01-07T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter07/07_06_Phan_Ra_QR</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;viết phân rã $A = QR$ của một ma trận có các cột độc lập tuyến tính từ kết quả Gram–Schmidt;&lt;/li&gt;
    &lt;li&gt;giải thích ý nghĩa của từng phần tử của $R$;&lt;/li&gt;
    &lt;li&gt;dùng $QR$ để giải hệ và tính hình chiếu lên $\operatorname{Col} A$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Ở Bài 07-05 ta trực chuẩn hoá $a_1 = (1,1,0)$, $a_2 = (1,0,1)$, $a_3 = (0,1,1)$ thành $q_1, q_2, q_3$. Quá trình đó còn cho nhiều thông tin hơn ba vectơ mới: từ công thức $v_j = a_j - \sum_{i&amp;lt;j} \langle a_j, q_i \rangle q_i$, ta viết ngược lại&lt;/p&gt;

\[a_1 = \sqrt{2}\, q_1, \qquad a_2 = \tfrac{1}{\sqrt{2}} q_1 + \sqrt{\tfrac{3}{2}}\, q_2, \qquad a_3 = \tfrac{1}{\sqrt{2}} q_1 + \tfrac{1}{\sqrt{6}} q_2 + \tfrac{2}{\sqrt{3}}\, q_3.\]

&lt;p&gt;Mỗi $a_j$ chỉ dùng $q_1, \dots, q_j$. Xếp các hệ số thành ma trận, ta được một ma trận &lt;em&gt;tam giác trên&lt;/em&gt;. Đó là phân rã QR.&lt;/p&gt;

&lt;h2 id=&quot;phân-rã-qr&quot;&gt;Phân rã QR&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Phân rã QR).&lt;/strong&gt; Cho $A$ là ma trận $m \times n$ có các cột $a_1, \dots, a_n$ độc lập tuyến tính. Khi đó&lt;/p&gt;

\[A = QR,\]

  &lt;p&gt;trong đó $Q$ là ma trận $m \times n$ có các cột trực chuẩn ($Q^T Q = I_n$) và $R$ là ma trận $n \times n$ tam giác trên với đường chéo dương. Cụ thể, các cột của $Q$ là $q_1, \dots, q_n$ từ Gram–Schmidt, và&lt;/p&gt;

  &lt;p&gt;\(r_{ij} = \langle a_j, q_i \rangle \ (i &amp;lt; j), \qquad r_{jj} = \lVert v_j \rVert, \qquad r_{ij} = 0 \ (i &amp;gt; j).\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Từ Gram–Schmidt, $a_j = v_j + \sum_{i&amp;lt;j} \langle a_j, q_i \rangle q_i = \lVert v_j \rVert q_j + \sum_{i&amp;lt;j} \langle a_j, q_i \rangle q_i$. Đây chính là cột $j$ của đẳng thức $A = QR$ với $R$ như trên. Đường chéo dương vì $v_j \ne 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Vì $Q^T Q = I$, nhân trái hai vế với $Q^T$ cho $R = Q^T A$: có $Q$ rồi thì tính $R$ bằng một phép nhân ma trận.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Với $A = \begin{bmatrix} 1 &amp;amp; 1 &amp;amp; 0 \\ 1 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; 1 \end{bmatrix}$ (các cột là $a_1, a_2, a_3$ ở trên):&lt;/p&gt;

\[Q = \begin{bmatrix} \frac{1}{\sqrt{2}} &amp;amp; \frac{1}{\sqrt{6}} &amp;amp; -\frac{1}{\sqrt{3}} \\ \frac{1}{\sqrt{2}} &amp;amp; -\frac{1}{\sqrt{6}} &amp;amp; \frac{1}{\sqrt{3}} \\ 0 &amp;amp; \frac{2}{\sqrt{6}} &amp;amp; \frac{1}{\sqrt{3}} \end{bmatrix}, \qquad R = \begin{bmatrix} \sqrt{2} &amp;amp; \frac{1}{\sqrt{2}} &amp;amp; \frac{1}{\sqrt{2}} \\ 0 &amp;amp; \sqrt{\frac{3}{2}} &amp;amp; \frac{1}{\sqrt{6}} \\ 0 &amp;amp; 0 &amp;amp; \frac{2}{\sqrt{3}} \end{bmatrix}.\]

  &lt;p&gt;Kiểm tra một phần tử: hàng 3 của $Q$ nhân cột 3 của $R$ là $0 \cdot \tfrac{1}{\sqrt{2}} + \tfrac{2}{\sqrt{6}} \cdot \tfrac{1}{\sqrt{6}} + \tfrac{1}{\sqrt{3}} \cdot \tfrac{2}{\sqrt{3}} = \tfrac{1}{3} + \tfrac{2}{3} = 1 = a_{33}$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; Với $A = \begin{bmatrix} 3 &amp;amp; 0 \\ 4 &amp;amp; 5 \end{bmatrix}$: $r_{11} = \lVert (3, 4) \rVert = 5$, $q_1 = (\tfrac{3}{5}, \tfrac{4}{5})$; $r_{12} = \langle (0, 5), q_1 \rangle = 4$; $v_2 = (0, 5) - 4(\tfrac{3}{5}, \tfrac{4}{5}) = (-\tfrac{12}{5}, \tfrac{9}{5})$, $r_{22} = 3$, $q_2 = (-\tfrac{4}{5}, \tfrac{3}{5})$. Vậy&lt;/p&gt;

  &lt;p&gt;\(\begin{bmatrix} 3 &amp;amp; 0 \\ 4 &amp;amp; 5 \end{bmatrix} = \begin{bmatrix} 3/5 &amp;amp; -4/5 \\ 4/5 &amp;amp; 3/5 \end{bmatrix} \begin{bmatrix} 5 &amp;amp; 4 \\ 0 &amp;amp; 3 \end{bmatrix}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ý-nghĩa-của-hai-thừa-số&quot;&gt;Ý nghĩa của hai thừa số&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;$Q$ chứa &lt;em&gt;hình học&lt;/em&gt; của $\operatorname{Col} A$: một cơ sở trực chuẩn của không gian cột. Ma trận chiếu lên $\operatorname{Col} A$ là $P = QQ^T$, đơn giản hơn nhiều so với $A(A^TA)^{-1}A^T$.&lt;/li&gt;
  &lt;li&gt;$R$ chứa &lt;em&gt;toạ độ&lt;/em&gt;: cột $j$ của $R$ là toạ độ của $a_j$ theo cơ sở $q_1, \dots, q_n$. Phần tử $r_{jj}$ là khoảng cách từ $a_j$ tới không gian căng bởi các cột trước; $r_{jj}$ nhỏ báo hiệu các cột gần phụ thuộc tuyến tính.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Với ma trận vuông, $\lvert \det A \rvert = \lvert \det Q \rvert \det R = r_{11} r_{22} \cdots r_{nn}$, vì $\det Q = \pm 1$ (Bài 07-07). Đây là “thể tích = đáy × chiều cao” lặp lại: $r_{jj}$ là chiều cao của cột $j$ so với “đáy” căng bởi các cột trước.&lt;/p&gt;

&lt;h2 id=&quot;giải-hệ-bằng-qr&quot;&gt;Giải hệ bằng QR&lt;/h2&gt;

&lt;p&gt;Nếu $A$ vuông khả nghịch, hệ $Ax = b$ thành $QRx = b$, tức&lt;/p&gt;

\[Rx = Q^T b.\]

&lt;p&gt;Hệ tam giác trên này giải bằng thế ngược. Với ma trận không vuông, cùng phương trình cho nghiệm bình phương tối thiểu (Chương 08, Bài 08-04), và tránh được việc lập $A^T A$, vốn làm tăng sai số.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3.&lt;/strong&gt; Giải $\begin{bmatrix} 3 &amp;amp; 0 \\ 4 &amp;amp; 5 \end{bmatrix} x = \begin{bmatrix} 3 \\ 9 \end{bmatrix}$. Ta có $Q^T b = (\tfrac{9 + 36}{5}, \tfrac{-12 + 27}{5}) = (9, 3)$. Giải $5x_1 + 4x_2 = 9$, $3x_2 = 3$: $x_2 = 1$, $x_1 = 1$. Kiểm tra: $3 \cdot 1 = 3$, $4 + 5 = 9$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-thuật-toán-qr-tìm-trị-riêng&quot;&gt;Ứng dụng: thuật toán QR tìm trị riêng&lt;/h2&gt;

&lt;p&gt;Thuật toán thông dụng nhất để tính mọi trị riêng của một ma trận (Chương 09) dựa trên QR: bắt đầu từ $A_0 = A$, lặp $A_k = Q_k R_k$ rồi đặt $A_{k+1} = R_k Q_k$. Vì $A_{k+1} = Q_k^T A_k Q_k$ đồng dạng với $A_k$, mọi $A_k$ có cùng trị riêng; với nhiều ma trận, $A_k$ hội tụ về dạng tam giác trên, và đường chéo cho các trị riêng. Các thư viện như LAPACK (mà NumPy dùng) chạy phiên bản cải tiến của thuật toán này.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: phân rã QR từ Gram–Schmidt&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Các hệ số chiếu ghi thành ma trận tam giác trên R, và A = QR.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter07/gram_schmidt.html?last=1&quot; title=&quot;Minh hoạ: phân rã QR từ Gram–Schmidt&quot; loading=&quot;lazy&quot; style=&quot;height: 760px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter07/gram_schmidt.html?last=1&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Tìm phân rã QR của $A = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$q_1 = \tfrac{1}{\sqrt{2}}(1, 1, 0)$, $r_{11} = \sqrt{2}$, $r_{12} = \tfrac{1}{\sqrt{2}}$. $v_2 = (\tfrac12, -\tfrac12, 1)$, $r_{22} = \sqrt{3/2}$, $q_2 = \tfrac{1}{\sqrt{6}}(1, -1, 2)$. Vậy $Q = [q_1\ q_2]$ cỡ $3 \times 2$, $R = \begin{bmatrix} \sqrt{2} &amp;amp; 1/\sqrt{2} \\ 0 &amp;amp; \sqrt{3/2} \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Với $Q$ ở Bài tập 1, tính ma trận chiếu $QQ^T$ lên $\operatorname{Col} A$ và chiếu $b = (1, 0, 0)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$QQ^T = \tfrac{1}{2}(1,1,0)(1,1,0)^T + \tfrac{1}{6}(1,-1,2)(1,-1,2)^T = \tfrac{1}{3}\begin{bmatrix} 2 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; -1 \\ 1 &amp;amp; -1 &amp;amp; 2 \end{bmatrix}$. Vậy $Pb = \tfrac{1}{3}(2, 1, 1)$; phần dư $\tfrac{1}{3}(1, -1, -1)$ vuông góc với cả hai cột của $A$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Chứng minh: nếu $A = QR$ với $A$ vuông khả nghịch thì $A^{-1} = R^{-1} Q^T$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$Q$ vuông có $Q^TQ = I$ nên $Q^{-1} = Q^T$; $R$ tam giác có đường chéo dương nên khả nghịch. Vậy $A^{-1} = R^{-1}Q^{-1} = R^{-1}Q^T$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Nếu các cột của $A$ đã trực giao (nhưng chưa chuẩn hoá), $R$ có dạng gì?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Mọi $r_{ij} = \langle a_j, q_i \rangle = 0$ với $i &amp;lt; j$, nên $R$ chéo với $r_{jj} = \lVert a_j \rVert$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Chứng minh phân rã QR với đường chéo của $R$ dương là duy nhất.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Nếu $Q_1R_1 = Q_2R_2$ thì $Q_2^TQ_1 = R_2R_1^{-1}$. Vế phải tam giác trên. Nhân $R_1^T Q_1^T Q_1 R_1 = A^T A = R_2^T R_2$ cho thấy $M = R_2 R_1^{-1}$ thoả $M^T M = I$. Một ma trận tam giác trên có $M^TM = I$ và đường chéo dương phải là $I$ (so sánh lần lượt từng cột). Vậy $R_1 = R_2$ và $Q_1 = Q_2$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$A = QR$: $Q$ có cột trực chuẩn (từ Gram–Schmidt), $R = Q^TA$ tam giác trên với $r_{ij} = \langle a_j, q_i \rangle$, $r_{jj} = \lVert v_j \rVert &amp;gt; 0$.&lt;/li&gt;
    &lt;li&gt;$Q$ cho cơ sở trực chuẩn của $\operatorname{Col} A$, ma trận chiếu là $QQ^T$; $R$ cho toạ độ các cột theo cơ sở đó.&lt;/li&gt;
    &lt;li&gt;Giải $Ax = b$: $Rx = Q^Tb$ bằng thế ngược.&lt;/li&gt;
    &lt;li&gt;QR là nền của bình phương tối thiểu ổn định (Chương 08) và thuật toán tìm trị riêng (Chương 09).&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Quá trình Gram–Schmidt</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter07/07_05_Qua_Trinh_Gram_Schmidt/"/>
   <updated>2026-01-07T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter07/07_05_Qua_Trinh_Gram_Schmidt</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;áp dụng quá trình Gram–Schmidt để trực chuẩn hoá một cơ sở của $\mathbb{R}^n$ hoặc của một không gian hàm;&lt;/li&gt;
    &lt;li&gt;giải thích vì sao các vectơ thu được căng cùng các không gian con $\operatorname{span}\{a_1, \dots, a_j\}$;&lt;/li&gt;
    &lt;li&gt;phân biệt Gram–Schmidt cổ điển và cải tiến, và biết hiện tượng mất trực giao trên máy.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Bài 07-03 và 07-04 cho thấy cơ sở trực chuẩn làm mọi thứ đơn giản: toạ độ là tích vô hướng, hình chiếu là tổng các hình chiếu lên từng vectơ. Nhưng các không gian con thường được cho bằng một cơ sở &lt;em&gt;không&lt;/em&gt; trực giao, ví dụ mặt phẳng căng bởi $(1, 1, 0)$ và $(1, 0, 1)$. Làm sao “nắn” một cơ sở thành cơ sở trực chuẩn mà vẫn căng cùng không gian? Ý tưởng: giữ vectơ đầu, rồi lấy mỗi vectơ tiếp theo trừ đi phần của nó nằm trên các hướng đã có.&lt;/p&gt;

&lt;h2 id=&quot;thuật-toán&quot;&gt;Thuật toán&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Gram–Schmidt).&lt;/strong&gt; Cho $a_1, \dots, a_k$ độc lập tuyến tính trong không gian tích vô hướng $V$. Đặt&lt;/p&gt;

\[v_1 = a_1, \qquad v_j = a_j - \sum_{i=1}^{j-1} \frac{\langle a_j, v_i \rangle}{\langle v_i, v_i \rangle}\, v_i \quad (j = 2, \dots, k),\]

  &lt;p&gt;và $q_j = v_j / \lVert v_j \rVert$. Khi đó $q_1, \dots, q_k$ là họ trực chuẩn, và với mọi $j$,&lt;/p&gt;

  &lt;p&gt;\(\operatorname{span}\{q_1, \dots, q_j\} = \operatorname{span}\{a_1, \dots, a_j\}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Quy nạp theo $j$. Giả sử $v_1, \dots, v_{j-1}$ trực giao, khác $0$ và căng $W_{j-1} = \operatorname{span}\{a_1, \dots, a_{j-1}\}$. Theo Bài 07-04, tổng trong công thức là $\operatorname{proj}_{W_{j-1}} a_j$, nên $v_j = a_j - \operatorname{proj}_{W_{j-1}} a_j \in W_{j-1}^\perp$: $v_j$ trực giao với mọi $v_i$, $i &amp;lt; j$. Nếu $v_j = 0$ thì $a_j \in W_{j-1}$, trái với giả thiết độc lập. Cuối cùng $v_j$ là $a_j$ cộng một vectơ của $W_{j-1}$, nên $\operatorname{span}\{v_1, \dots, v_j\} = \operatorname{span}\{a_1, \dots, a_j\}$. Chia cho chuẩn không đổi không gian căng.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Hệ quả: mọi không gian tích vô hướng hữu hạn chiều đều có cơ sở trực chuẩn (áp dụng Gram–Schmidt cho một cơ sở bất kỳ).&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Trực chuẩn hoá $a_1 = (1, 1, 0)$, $a_2 = (1, 0, 1)$, $a_3 = (0, 1, 1)$.&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;Bước 1.&lt;/em&gt; $v_1 = (1, 1, 0)$, $q_1 = \tfrac{1}{\sqrt{2}}(1, 1, 0)$.&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;Bước 2.&lt;/em&gt; $\langle a_2, q_1 \rangle = \tfrac{1}{\sqrt{2}}$, nên $v_2 = (1, 0, 1) - \tfrac{1}{2}(1, 1, 0) = \left(\tfrac{1}{2}, -\tfrac{1}{2}, 1\right)$. Chuẩn $\lVert v_2 \rVert = \sqrt{3/2}$, nên $q_2 = \tfrac{1}{\sqrt{6}}(1, -1, 2)$.&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;Bước 3.&lt;/em&gt; $\langle a_3, q_1 \rangle = \tfrac{1}{\sqrt{2}}$ và $\langle a_3, q_2 \rangle = \tfrac{1}{\sqrt{6}}$, nên&lt;/p&gt;

\[v_3 = (0, 1, 1) - \tfrac{1}{2}(1, 1, 0) - \tfrac{1}{6}(1, -1, 2) = \left(-\tfrac{2}{3}, \tfrac{2}{3}, \tfrac{2}{3}\right), \qquad q_3 = \tfrac{1}{\sqrt{3}}(-1, 1, 1).\]

  &lt;p&gt;Kiểm tra: $q_1 \cdot q_2 = \tfrac{1}{\sqrt{12}}(1 - 1 + 0) = 0$, $q_1 \cdot q_3 = \tfrac{1}{\sqrt{6}}(-1 + 1) = 0$, $q_2 \cdot q_3 = \tfrac{1}{\sqrt{18}}(-1 - 1 + 2) = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Mẹo tính tay: có thể nhân $v_j$ với một số khác $0$ trước khi đi tiếp (ví dụ thay $v_2$ bằng $(1, -1, 2)$) để tránh phân số; tính trực giao không đổi.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (đa thức Legendre).&lt;/strong&gt; Trong không gian đa thức với $\langle p, q \rangle = \int_{-1}^1 p(x) q(x)\, dx$, áp dụng Gram–Schmidt cho $1, x, x^2$:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$v_1 = 1$;&lt;/li&gt;
    &lt;li&gt;$v_2 = x - \frac{\langle x, 1 \rangle}{\langle 1, 1 \rangle} \cdot 1 = x$, vì $\int_{-1}^1 x\, dx = 0$;&lt;/li&gt;
    &lt;li&gt;$v_3 = x^2 - \frac{\langle x^2, 1 \rangle}{\langle 1, 1 \rangle} - \frac{\langle x^2, x \rangle}{\langle x, x \rangle} x = x^2 - \frac{2/3}{2} - 0 = x^2 - \tfrac{1}{3}$.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Các đa thức $1$, $x$, $x^2 - \tfrac{1}{3}$ (sai khác hằng số) là ba đa thức Legendre đầu tiên, dùng trong cầu phương Gauss và vật lý.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;gramschmidt-trên-máy-tính&quot;&gt;Gram–Schmidt trên máy tính&lt;/h2&gt;

&lt;p&gt;Công thức ở Định lý 1 (Gram–Schmidt &lt;em&gt;cổ điển&lt;/em&gt;) tính mọi hệ số $\langle a_j, q_i \rangle$ từ vectơ gốc $a_j$. Với số thực dấu phẩy động, khi các $a_j$ gần phụ thuộc tuyến tính, sai số làm tròn khiến các $q_j$ thu được không còn trực giao.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Gram–Schmidt cải tiến&lt;/em&gt; (modified) cho cùng kết quả trong số học chính xác, nhưng trừ từng hình chiếu một và dùng vectơ &lt;em&gt;đã được cập nhật&lt;/em&gt; để tính hệ số tiếp theo:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;mgs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Q&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zeros&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;astype&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;# cổ điển dùng A[:, j] thay cho v
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;Q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Q&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Trên ma trận Hilbert $10 \times 10$, sai lệch $\max \lvert Q^TQ - I \rvert$ của Gram–Schmidt cổ điển xấp xỉ $1$ (mất trực giao hoàn toàn), của bản cải tiến khoảng $10^{-5}$, còn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.qr&lt;/code&gt; (dùng phép phản xạ Householder, Bài 07-07) khoảng $10^{-16}$. Trong thực hành, dùng thư viện; Gram–Schmidt là công cụ để hiểu và để tính tay.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-chuỗi-fourier&quot;&gt;Ứng dụng: chuỗi Fourier&lt;/h2&gt;

&lt;p&gt;Trong $C[-\pi, \pi]$, các hàm $1, \cos x, \sin x, \cos 2x, \sin 2x, \dots$ đã trực giao (Bài tập 4, Bài 07-03), nên không cần Gram–Schmidt. Hình chiếu của $f$ lên không gian căng bởi $N$ hàm đầu là tổng Fourier riêng phần, với hệ số $\langle f, \cos kx \rangle / \langle \cos kx, \cos kx \rangle$. Khi một họ hàm cơ sở &lt;em&gt;không&lt;/em&gt; trực giao (ví dụ $1, x, x^2, \dots$), Gram–Schmidt sinh ra họ trực giao như các đa thức Legendre ở Ví dụ 2.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: Gram–Schmidt từng bước&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Bấm ▶ để trừ hình chiếu và chuẩn hoá từng vectơ; bảng eᵢ·eⱼ kiểm tra tính trực chuẩn.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter07/gram_schmidt.html&quot; title=&quot;Minh hoạ: Gram–Schmidt từng bước&quot; loading=&quot;lazy&quot; style=&quot;height: 760px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter07/gram_schmidt.html&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-gramschmidt-từng-bước&quot;&gt;Video ngắn: Gram–Schmidt từng bước&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/gram-schmidt-steps.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;a₁ = (1; 1; 0), a₂ = (1; 0; 1), a₃ = (0; 1; 1). Co a₁ được q₁; bỏ khỏi a₂ bóng của nó trên q₁ rồi co, được q₂; bỏ khỏi a₃ bóng trên q₁ và q₂ rồi co, được q₃. Các hệ số vừa trừ và độ dài phần dư xếp thành R tam giác trên: A = QR. Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Trực chuẩn hoá $(1, 1, 1)$, $(0, 1, 1)$, $(0, 0, 1)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$q_1 = \tfrac{1}{\sqrt{3}}(1, 1, 1)$. $v_2 = (0,1,1) - \tfrac{2}{3}(1,1,1) = \left(-\tfrac{2}{3}, \tfrac{1}{3}, \tfrac{1}{3}\right)$, $q_2 = \tfrac{1}{\sqrt{6}}(-2, 1, 1)$. $v_3 = (0,0,1) - \tfrac{1}{3}(1,1,1) - \tfrac{1}{6}(-2,1,1) = \left(0, -\tfrac{1}{2}, \tfrac{1}{2}\right)$, $q_3 = \tfrac{1}{\sqrt{2}}(0, -1, 1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Tìm cơ sở trực chuẩn của mặt phẳng $x_1 + x_2 + x_3 = 0$ trong $\mathbb{R}^3$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Bắt đầu từ cơ sở $(1, -1, 0)$, $(1, 0, -1)$. $q_1 = \tfrac{1}{\sqrt{2}}(1, -1, 0)$; $v_2 = (1, 0, -1) - \tfrac{1}{2}(1, -1, 0) = \left(\tfrac{1}{2}, \tfrac{1}{2}, -1\right)$, $q_2 = \tfrac{1}{\sqrt{6}}(1, 1, -2)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Điều gì xảy ra nếu áp dụng Gram–Schmidt cho $(1, 2)$, $(2, 4)$, và vì sao?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$v_2 = (2, 4) - \tfrac{10}{5}(1, 2) = 0$, nên không chia được cho chuẩn. Hai vectơ phụ thuộc tuyến tính. Trong thực hành, gặp $v_j = 0$ (hoặc rất nhỏ) là dấu hiệu $a_j$ thuộc không gian căng bởi các vectơ trước, và ta bỏ $a_j$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Trong $C[0, 1]$ với tích vô hướng tích phân, trực giao hoá $1, x$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$v_1 = 1$, $v_2 = x - \frac{\langle x, 1 \rangle}{\langle 1, 1 \rangle} = x - \tfrac{1}{2}$. Chuẩn hoá: $\lVert x - \tfrac{1}{2} \rVert^2 = \int_0^1 (x - \tfrac12)^2 dx = \tfrac{1}{12}$, nên $q_2 = \sqrt{12}\,(x - \tfrac{1}{2})$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (lập trình).&lt;/strong&gt; So sánh Gram–Schmidt cổ điển, cải tiến và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.qr&lt;/code&gt; trên ma trận Hilbert $n \times n$ với $n = 6, 8, 10, 12$ qua đại lượng $\max \lvert Q^TQ - I \rvert$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Sai lệch của bản cổ điển tăng rất nhanh theo $n$ (đến cỡ $1$ khi $n = 10$), bản cải tiến tăng tỷ lệ với số điều kiện của ma trận (cỡ $10^{-5}$ khi $n = 10$), còn Householder trong `numpy.linalg.qr` giữ ở mức $10^{-16}$ đến $10^{-15}$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Gram–Schmidt: $v_j = a_j - \sum_{i&amp;lt;j} \operatorname{proj}_{v_i} a_j$, $q_j = v_j / \lVert v_j \rVert$; mỗi bước trừ đi hình chiếu lên không gian đã dựng.&lt;/li&gt;
    &lt;li&gt;$\operatorname{span}\{q_1, \dots, q_j\} = \operatorname{span}\{a_1, \dots, a_j\}$ với mọi $j$; mọi không gian hữu hạn chiều có cơ sở trực chuẩn.&lt;/li&gt;
    &lt;li&gt;Gặp $v_j = 0$ nghĩa là $a_j$ phụ thuộc các vectơ trước.&lt;/li&gt;
    &lt;li&gt;Trên máy: bản cổ điển mất trực giao, bản cải tiến tốt hơn, Householder tốt nhất.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Hình chiếu vuông góc</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter07/07_04_Hinh_Chieu_Vuong_Goc/"/>
   <updated>2026-01-07T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter07/07_04_Hinh_Chieu_Vuong_Goc</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;tính hình chiếu của một vectơ lên một đường thẳng và lên một không gian con;&lt;/li&gt;
    &lt;li&gt;phân rã $x = \hat{x} + (x - \hat{x})$ với $\hat{x} \in W$ và $x - \hat{x} \in W^\perp$;&lt;/li&gt;
    &lt;li&gt;lập ma trận chiếu, kiểm tra $P^2 = P$, $P^T = P$, và dùng định lý xấp xỉ tốt nhất.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Một chiếc drone bay tới điểm $b = (6, 0, 0)$, nhưng nó chỉ được phép bay trong một mặt phẳng $W$ qua gốc, căng bởi $a_1 = (1, 1, 1)$ và $a_2 = (0, 1, 2)$. Điểm nào của $W$ gần $b$ nhất? Trực giác hình học: hạ đường vuông góc từ $b$ xuống mặt phẳng. Bài này biến trực giác đó thành công thức, và cho thấy nó đúng trong mọi không gian tích vô hướng. Ta sẽ tìm được điểm gần nhất là $(5, 2, -1)$.&lt;/p&gt;

&lt;h2 id=&quot;hình-chiếu-lên-một-đường-thẳng&quot;&gt;Hình chiếu lên một đường thẳng&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Hình chiếu lên đường thẳng).&lt;/strong&gt; Cho $a \ne 0$. &lt;em&gt;Hình chiếu&lt;/em&gt; của $x$ lên đường thẳng $\operatorname{span}\{a\}$ là&lt;/p&gt;

  &lt;p&gt;\(\operatorname{proj}_a x = \frac{\langle x, a \rangle}{\langle a, a \rangle}\, a.\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Đây là vectơ duy nhất $ta$ trên đường thẳng sao cho $x - ta \perp a$: điều kiện $\langle x - ta, a \rangle = 0$ cho đúng $t = \langle x, a \rangle / \langle a, a \rangle$. Với tích vô hướng thông thường, ma trận của phép chiếu là&lt;/p&gt;

\[P = \frac{a a^T}{a^T a},\]

&lt;p&gt;vì $P x = a\, (a^T x) / (a^T a)$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Chiếu $x = (1, 2, 3)$ lên $a = (1, 1, 1)$: $\operatorname{proj}_a x = \tfrac{6}{3}(1, 1, 1) = (2, 2, 2)$. Phần dư $x - (2, 2, 2) = (-1, 0, 1)$ vuông góc với $a$. Phần dư này chính là hình chiếu của $x$ lên mặt phẳng $x_1 + x_2 + x_3 = 0$, phần bù trực giao của đường thẳng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;hình-chiếu-lên-một-không-gian-con&quot;&gt;Hình chiếu lên một không gian con&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Phân rã trực giao).&lt;/strong&gt; Cho $W$ là không gian con hữu hạn chiều của không gian tích vô hướng $V$. Mọi $x \in V$ viết được duy nhất dưới dạng&lt;/p&gt;

\[x = \hat{x} + z, \qquad \hat{x} \in W,\ z \in W^\perp.\]

  &lt;p&gt;Nếu $u_1, \dots, u_k$ là cơ sở trực giao của $W$ thì&lt;/p&gt;

  &lt;p&gt;\(\hat{x} = \operatorname{proj}_W x = \sum_{i=1}^k \frac{\langle x, u_i \rangle}{\langle u_i, u_i \rangle}\, u_i.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Đặt $\hat{x}$ như công thức và $z = x - \hat{x}$. Với mỗi $j$, do các $u_i$ trực giao, $\langle z, u_j \rangle = \langle x, u_j \rangle - \frac{\langle x, u_j \rangle}{\langle u_j, u_j \rangle} \langle u_j, u_j \rangle = 0$, nên $z \in W^\perp$. Duy nhất: nếu $\hat{x} + z = \hat{x}&apos; + z&apos;$ thì $\hat{x} - \hat{x}&apos; = z&apos; - z$ nằm trong $W \cap W^\perp = \{0\}$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Chú ý: công thức tổng chỉ đúng khi cơ sở &lt;em&gt;trực giao&lt;/em&gt;. Với cơ sở bất kỳ, dùng công thức ma trận dưới đây.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2 (Ma trận chiếu).&lt;/strong&gt; Cho $A$ là ma trận $m \times k$ có các cột độc lập tuyến tính và $W = \operatorname{Col} A \subseteq \mathbb{R}^m$. Khi đó $A^T A$ khả nghịch, và&lt;/p&gt;

\[\operatorname{proj}_W b = A \hat{c}, \quad \text{với } A^T A\, \hat{c} = A^T b, \qquad P = A (A^T A)^{-1} A^T.\]

  &lt;p&gt;Ma trận $P$ thoả $P^2 = P$ và $P^T = P$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; $A^T A$ khả nghịch vì $\operatorname{Null}(A^T A) = \operatorname{Null} A = \{0\}$ (Bài tập 5, Bài 07-03). Hình chiếu có dạng $A\hat{c}$ và phần dư $b - A\hat{c}$ vuông góc với mọi cột của $A$, tức $A^T(b - A\hat{c}) = 0$. Giải ra $\hat{c} = (A^T A)^{-1} A^T b$. Cuối cùng $P^2 = A (A^TA)^{-1} A^T A (A^TA)^{-1} A^T = P$, và $P^T = P$ vì $(A^T A)^{-1}$ đối xứng.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (ví dụ mở đầu).&lt;/strong&gt; Với $A = \begin{bmatrix} 1 &amp;amp; 0 \\ 1 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$ và $b = (6, 0, 0)$:&lt;/p&gt;

\[A^T A = \begin{bmatrix} 3 &amp;amp; 3 \\ 3 &amp;amp; 5 \end{bmatrix}, \qquad A^T b = \begin{bmatrix} 6 \\ 0 \end{bmatrix}.\]

  &lt;p&gt;Giải $3c_1 + 3c_2 = 6$, $3c_1 + 5c_2 = 0$ được $c_2 = -3$, $c_1 = 5$. Hình chiếu $\hat{b} = 5(1,1,1) - 3(0,1,2) = (5, 2, -1)$, phần dư $b - \hat{b} = (1, -2, 1)$. Kiểm tra: $(1,-2,1) \cdot (1,1,1) = 0$ và $(1,-2,1) \cdot (0,1,2) = 0$. Ma trận chiếu là&lt;/p&gt;

  &lt;p&gt;\(P = \frac{1}{6} \begin{bmatrix} 5 &amp;amp; 2 &amp;amp; -1 \\ 2 &amp;amp; 2 &amp;amp; 2 \\ -1 &amp;amp; 2 &amp;amp; 5 \end{bmatrix}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Ta cũng có $I - P$ là ma trận chiếu lên $W^\perp$: ở đây $W^\perp = \operatorname{span}\{(1, -2, 1)\}$ và $I - P = \tfrac{1}{6}(1,-2,1)(1,-2,1)^T$.&lt;/p&gt;

&lt;h2 id=&quot;hình-chiếu-là-điểm-gần-nhất&quot;&gt;Hình chiếu là điểm gần nhất&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 3 (Xấp xỉ tốt nhất).&lt;/strong&gt; Với $W$ và $\hat{x} = \operatorname{proj}_W x$ như Định lý 1, với mọi $w \in W$ khác $\hat{x}$:&lt;/p&gt;

  &lt;p&gt;\(\lVert x - \hat{x} \rVert &amp;lt; \lVert x - w \rVert.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Viết $x - w = (x - \hat{x}) + (\hat{x} - w)$. Số hạng đầu thuộc $W^\perp$, số hạng sau thuộc $W$, nên chúng trực giao. Theo Pythagore, $\lVert x - w \rVert^2 = \lVert x - \hat{x} \rVert^2 + \lVert \hat{x} - w \rVert^2 &amp;gt; \lVert x - \hat{x} \rVert^2$ khi $w \ne \hat{x}$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Định lý 3 là nền của Chương 08: khi $Ax = b$ vô nghiệm, ta thay $b$ bằng điểm gần nhất $\hat{b} \in \operatorname{Col} A$, và phương trình $A^T A \hat{c} = A^T b$ ở Định lý 2 chính là &lt;em&gt;phương trình chuẩn&lt;/em&gt;.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-xấp-xỉ-hàm&quot;&gt;Ứng dụng: xấp xỉ hàm&lt;/h2&gt;

&lt;p&gt;Trong $C[0, 1]$, tìm hàm bậc nhất $a + bx$ gần $f(x) = x^2$ nhất theo chuẩn tích phân, tức hình chiếu của $x^2$ lên $W = \operatorname{span}\{1, x\}$. Điều kiện phần dư vuông góc với $1$ và $x$ cho hệ&lt;/p&gt;

\[\begin{bmatrix} \langle 1, 1 \rangle &amp;amp; \langle x, 1 \rangle \\ \langle 1, x \rangle &amp;amp; \langle x, x \rangle \end{bmatrix} \begin{bmatrix} a \\ b \end{bmatrix} = \begin{bmatrix} \langle x^2, 1 \rangle \\ \langle x^2, x \rangle \end{bmatrix}, \quad\text{tức}\quad \begin{bmatrix} 1 &amp;amp; 1/2 \\ 1/2 &amp;amp; 1/3 \end{bmatrix} \begin{bmatrix} a \\ b \end{bmatrix} = \begin{bmatrix} 1/3 \\ 1/4 \end{bmatrix}.\]

&lt;p&gt;Nghiệm $a = -1/6$, $b = 1$: đường thẳng $x - \tfrac{1}{6}$ là xấp xỉ bình phương trung bình tốt nhất của $x^2$ trên $[0, 1]$. Cùng ý tưởng cho chuỗi Fourier trong giải tích.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: hình chiếu vuông góc trong ℝ³&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo y: ŷ là điểm gần y nhất trong W, phần dư z vuông góc với W.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter07/hinh_chieu_3d.html?mode=plane&quot; title=&quot;Minh hoạ: hình chiếu vuông góc trong ℝ³&quot; loading=&quot;lazy&quot; style=&quot;height: 720px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter07/hinh_chieu_3d.html?mode=plane&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-hình-chiếu-là-điểm-gần-nhất&quot;&gt;Video ngắn: Hình chiếu là điểm gần nhất&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/projection-3d.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Mặt phẳng C(A) với a₁ = (1; 0; 1), a₂ = (0; 1; 0) và điểm b = (0; 1; 2) ở ngoài. Cho p chạy trên mặt phẳng: |b − p| nhỏ nhất bằng √2 ≈ 1,41 tại p = (1; 1; 1), đúng lúc b − p vuông góc với cả hai cột, nên AᵀA x̂ = Aᵀb. Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Tính hình chiếu của $(1, 2, 3)$ lên mặt phẳng $x + y + z = 0$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Mặt phẳng là phần bù trực giao của $n = (1, 1, 1)$. Trừ đi thành phần theo $n$: $(1,2,3) - \tfrac{6}{3}(1,1,1) = (-1, 0, 1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Tìm ma trận chiếu lên đường thẳng qua $a = (1, 2)$ trong $\mathbb{R}^2$ và chiếu $x = (3, 1)$ lên đường thẳng đó.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$P = \tfrac{1}{5}\begin{bmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 4 \end{bmatrix}$ (khớp với Bài 06-05). $Px = \tfrac{1}{5}(5, 10) = (1, 2)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Chiếu $x = (1, 1, 1, 1)$ lên $W = \operatorname{span}\{(1, 1, 0, 0), (0, 0, 1, -1)\}$ trong $\mathbb{R}^4$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Hai vectơ đã trực giao. $\hat{x} = \tfrac{2}{2}(1,1,0,0) + \tfrac{0}{2}(0,0,1,-1) = (1, 1, 0, 0)$. Phần dư $(0, 0, 1, 1)$ vuông góc với cả hai vectơ.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Chứng minh: nếu $P$ là ma trận đối xứng thoả $P^2 = P$ thì $Px \perp x - Px$ với mọi $x$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$(Px)^T (x - Px) = x^T P^T x - x^T P^T P x = x^T P x - x^T P^2 x = x^T P x - x^T P x = 0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Cho $P$ là ma trận chiếu lên không gian con $W$ có $\dim W = k$ trong $\mathbb{R}^n$. Chứng minh $\operatorname{tr} P = k$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Chọn cơ sở trực chuẩn $u_1, \dots, u_k$ của $W$ và đặt $Q = [u_1 \cdots u_k]$. Khi đó $Q^T Q = I_k$ và $P = Q(Q^TQ)^{-1}Q^T = QQ^T$. Vậy $\operatorname{tr} P = \operatorname{tr}(QQ^T) = \operatorname{tr}(Q^TQ) = \operatorname{tr} I_k = k$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Hình chiếu lên đường thẳng: $\operatorname{proj}_a x = \dfrac{\langle x, a \rangle}{\langle a, a \rangle} a$, ma trận $aa^T / a^Ta$.&lt;/li&gt;
    &lt;li&gt;Mọi $x$ phân rã duy nhất $x = \hat{x} + z$ với $\hat{x} \in W$, $z \in W^\perp$; với cơ sở trực giao, $\hat{x}$ là tổng các hình chiếu lên từng vectơ.&lt;/li&gt;
    &lt;li&gt;Lên $\operatorname{Col} A$: giải $A^T A \hat{c} = A^T b$; $P = A(A^TA)^{-1}A^T$, $P^2 = P = P^T$.&lt;/li&gt;
    &lt;li&gt;$\hat{x}$ là điểm của $W$ gần $x$ nhất.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Họ trực giao và phần bù trực giao</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter07/07_03_Ho_Truc_Giao_Va_Phan_Bu_Truc_Giao/"/>
   <updated>2026-01-07T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter07/07_03_Ho_Truc_Giao_Va_Phan_Bu_Truc_Giao</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;chứng minh một họ trực giao gồm các vectơ khác $0$ là độc lập tuyến tính;&lt;/li&gt;
    &lt;li&gt;tìm toạ độ của một vectơ theo cơ sở trực giao bằng tích vô hướng, không cần giải hệ;&lt;/li&gt;
    &lt;li&gt;tìm phần bù trực giao $W^\perp$ của một không gian con và dùng $(\operatorname{Row} A)^\perp = \operatorname{Null} A$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Viết $x = (3, 1, 2)$ theo cơ sở $u_1 = (1, 1, 0)$, $u_2 = (1, -1, 0)$, $u_3 = (0, 0, 1)$. Cách ở Chương 05 là giải hệ $3 \times 3$. Nhưng ba vectơ này đôi một vuông góc, và có một cách nhanh hơn nhiều: lấy tích vô hướng hai vế của $x = c_1 u_1 + c_2 u_2 + c_3 u_3$ với $u_1$. Mọi số hạng chứa $u_2$, $u_3$ biến mất:&lt;/p&gt;

\[x \cdot u_1 = c_1\, u_1 \cdot u_1 \quad\Longrightarrow\quad c_1 = \frac{4}{2} = 2.\]

&lt;p&gt;Tương tự $c_2 = 2/2 = 1$ và $c_3 = 2/1 = 2$. Kiểm tra: $2(1,1,0) + (1,-1,0) + 2(0,0,1) = (3,1,2)$.&lt;/p&gt;

&lt;h2 id=&quot;họ-trực-giao&quot;&gt;Họ trực giao&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Họ trực giao, trực chuẩn).&lt;/strong&gt; Một họ vectơ $u_1, \dots, u_k$ là &lt;em&gt;trực giao&lt;/em&gt; nếu $\langle u_i, u_j \rangle = 0$ với mọi $i \ne j$. Họ là &lt;em&gt;trực chuẩn&lt;/em&gt; nếu thêm vào đó mọi $\lVert u_i \rVert = 1$. Một cơ sở là họ trực giao (trực chuẩn) gọi là &lt;em&gt;cơ sở trực giao&lt;/em&gt; (&lt;em&gt;trực chuẩn&lt;/em&gt;).&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Một họ trực giao gồm các vectơ khác $0$ là độc lập tuyến tính.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Giả sử $c_1 u_1 + \dots + c_k u_k = 0$. Lấy tích vô hướng với $u_j$: mọi số hạng $c_i \langle u_i, u_j \rangle$ với $i \ne j$ bằng $0$, còn lại $c_j \lVert u_j \rVert^2 = 0$. Vì $u_j \ne 0$, $c_j = 0$, với mọi $j$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2 (Toạ độ theo cơ sở trực giao).&lt;/strong&gt; Nếu $u_1, \dots, u_n$ là cơ sở trực giao của $V$ thì với mọi $x \in V$,&lt;/p&gt;

\[x = \sum_{i=1}^n \frac{\langle x, u_i \rangle}{\langle u_i, u_i \rangle}\, u_i.\]

  &lt;p&gt;Nếu cơ sở trực chuẩn thì $x = \sum_i \langle x, u_i \rangle\, u_i$ và $\lVert x \rVert^2 = \sum_i \langle x, u_i \rangle^2$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Viết $x = \sum c_i u_i$ và lấy tích vô hướng với $u_j$ như ví dụ mở đầu: $\langle x, u_j \rangle = c_j \langle u_j, u_j \rangle$. Với cơ sở trực chuẩn, Pythagore áp dụng cho các vectơ trực giao $c_i u_i$ cho $\lVert x \rVert^2 = \sum c_i^2$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Trong cơ sở trực chuẩn, “tìm toạ độ” chỉ là $n$ phép tính tích vô hướng, và độ dài tính như trong $\mathbb{R}^n$ thông thường. Đây là lý do ta muốn có cơ sở trực chuẩn; Bài 07-05 chỉ cách dựng nó từ một cơ sở bất kỳ.&lt;/p&gt;

&lt;h2 id=&quot;phần-bù-trực-giao&quot;&gt;Phần bù trực giao&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 2 (Phần bù trực giao).&lt;/strong&gt; Cho $W$ là không gian con của không gian tích vô hướng $V$. &lt;em&gt;Phần bù trực giao&lt;/em&gt; của $W$ là&lt;/p&gt;

  &lt;p&gt;\(W^\perp = \{v \in V : \langle v, w \rangle = 0 \text{ với mọi } w \in W\}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 3.&lt;/strong&gt; Cho $W$ là không gian con của $V$.&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$W^\perp$ là không gian con của $V$, và $W \cap W^\perp = \{0\}$.&lt;/li&gt;
    &lt;li&gt;Nếu $W = \operatorname{span}\{w_1, \dots, w_k\}$ thì $v \in W^\perp$ khi và chỉ khi $\langle v, w_i \rangle = 0$ với mọi $i$.&lt;/li&gt;
    &lt;li&gt;Nếu $V$ hữu hạn chiều thì $\dim W + \dim W^\perp = \dim V$ và $(W^\perp)^\perp = W$.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh (phác thảo).&lt;/strong&gt; (1) Tích vô hướng tuyến tính theo $v$, nên $W^\perp$ đóng với phép cộng và nhân số. Nếu $v \in W \cap W^\perp$ thì $\langle v, v \rangle = 0$, nên $v = 0$. (2) Mọi $w \in W$ là tổ hợp của các $w_i$, và tích vô hướng tuyến tính. (3) Trong $\mathbb{R}^n$, đặt các $w_i$ làm hàng của ma trận $A$; theo (2), $W^\perp = \operatorname{Null} A$, và định lý hạng–số khuyết cho $\dim W^\perp = n - \operatorname{rank} A = n - \dim W$. Trường hợp tổng quát dùng một cơ sở trực chuẩn (Bài 07-05) để đưa về $\mathbb{R}^n$. Cuối cùng $W \subseteq (W^\perp)^\perp$ và hai không gian cùng số chiều.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 4 (Bốn không gian con cơ bản).&lt;/strong&gt; Với ma trận $A$ cỡ $m \times n$:&lt;/p&gt;

  &lt;p&gt;\((\operatorname{Row} A)^\perp = \operatorname{Null} A \ \text{ trong } \mathbb{R}^n, \qquad (\operatorname{Col} A)^\perp = \operatorname{Null} A^T \ \text{ trong } \mathbb{R}^m.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; $Ax = 0$ nghĩa là tích vô hướng của $x$ với mọi hàng của $A$ bằng $0$, tức $x \perp \operatorname{Row} A$ theo Định lý 3(2). Áp dụng cho $A^T$, có hàng là các cột của $A$, được đẳng thức thứ hai.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Định lý 4 hoàn thiện bức tranh ở Bài 05-04: không chỉ $\dim \operatorname{Row} A + \dim \operatorname{Null} A = n$, mà hai không gian còn &lt;em&gt;vuông góc&lt;/em&gt; với nhau và cùng nhau lấp đầy $\mathbb{R}^n$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Cho $W = \operatorname{span}\{(1, 1, 1)\}$ trong $\mathbb{R}^3$. Khi đó $W^\perp = \{x : x_1 + x_2 + x_3 = 0\}$, một mặt phẳng qua gốc, với cơ sở $(1, -1, 0)$, $(1, 0, -1)$. Ta có $\dim W + \dim W^\perp = 1 + 2 = 3$.&lt;/p&gt;

  &lt;p&gt;Cho $A = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 &amp;amp; 1 \\ 2 &amp;amp; 4 &amp;amp; 1 &amp;amp; 3 \\ 3 &amp;amp; 6 &amp;amp; 1 &amp;amp; 4 \end{bmatrix}$ (Bài 05-04). Không gian không trái là $\operatorname{Null} A^T = \operatorname{span}\{(-1, -1, 1)\}$. Thật vậy, cột 1 là $(1, 2, 3)$ và $-1 - 2 + 3 = 0$; cột 3 là $(0, 1, 1)$ và $0 - 1 + 1 = 0$. Vậy $(-1, -1, 1) \perp \operatorname{Col} A$, và hệ $Ax = b$ có nghiệm khi và chỉ khi $-b_1 - b_2 + b_3 = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-điều-kiện-có-nghiệm&quot;&gt;Ứng dụng: điều kiện có nghiệm&lt;/h2&gt;

&lt;p&gt;Định lý 4 cho một cách kiểm tra $Ax = b$ có nghiệm: $b \in \operatorname{Col} A$ khi và chỉ khi $b \perp \operatorname{Null} A^T$, tức $y^T b = 0$ với mọi $y$ thoả $A^T y = 0$. Trong mạch điện (Bài 05-05), $\operatorname{Null} A^T$ ứng với các vòng kín, và điều kiện này chính là định luật Kirchhoff về điện áp: tổng hiệu điện thế quanh mỗi vòng bằng $0$. Đây là dạng đơn giản của &lt;em&gt;bổ đề Fredholm&lt;/em&gt;.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: phần bù trực giao W⊥&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Xoay hình: W là đường thẳng thì W⊥ là mặt phẳng vuông góc, và ngược lại.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter07/hinh_chieu_3d.html?mode=line&quot; title=&quot;Minh hoạ: phần bù trực giao W⊥&quot; loading=&quot;lazy&quot; style=&quot;height: 720px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter07/hinh_chieu_3d.html?mode=line&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Kiểm tra $u_1 = (1, 2, 2)$, $u_2 = (2, 1, -2)$, $u_3 = (2, -2, 1)$ đôi một trực giao và viết $x = (9, 0, 9)$ theo cơ sở này.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$u_1 \cdot u_2 = 2 + 2 - 4 = 0$, $u_1 \cdot u_3 = 2 - 4 + 2 = 0$, $u_2 \cdot u_3 = 4 - 2 - 2 = 0$, và mọi $\lVert u_i \rVert^2 = 9$. Hệ số: $c_1 = 27/9 = 3$, $c_2 = 0/9 = 0$, $c_3 = 27/9 = 3$. Vậy $x = 3u_1 + 3u_3$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Tìm một cơ sở của $W^\perp$ với $W = \operatorname{span}\{(1, 0, 1, 0), (0, 1, 0, 1)\}$ trong $\mathbb{R}^4$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$W^\perp$ là nghiệm của $x_1 + x_3 = 0$, $x_2 + x_4 = 0$: cơ sở $(-1, 0, 1, 0)$, $(0, -1, 0, 1)$. Số chiều $2 + 2 = 4$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Chứng minh: nếu $W_1 \subseteq W_2$ thì $W_2^\perp \subseteq W_1^\perp$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Nếu $v$ vuông góc với mọi vectơ của $W_2$ thì nó vuông góc với mọi vectơ của tập nhỏ hơn $W_1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Trong $C[-\pi, \pi]$ với $\langle f, g \rangle = \int_{-\pi}^{\pi} fg$, kiểm tra $1, \cos x, \sin x$ đôi một trực giao và tính chuẩn của chúng.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\int_{-\pi}^{\pi} \cos x\, dx = \int_{-\pi}^{\pi} \sin x\, dx = 0$, và $\int_{-\pi}^{\pi} \sin x \cos x\, dx = \tfrac{1}{2}\int_{-\pi}^{\pi} \sin 2x\, dx = 0$. Chuẩn: $\lVert 1 \rVert = \sqrt{2\pi}$, $\lVert \cos x \rVert = \lVert \sin x \rVert = \sqrt{\pi}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Cho $A$ là ma trận $m \times n$. Chứng minh $\operatorname{Null}(A^T A) = \operatorname{Null} A$, rồi suy ra $\operatorname{rank}(A^T A) = \operatorname{rank} A$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Nếu $Ax = 0$ thì $A^T A x = 0$. Ngược lại, nếu $A^T A x = 0$ thì $0 = x^T A^T A x = \lVert Ax \rVert^2$, nên $Ax = 0$. Hai ma trận cùng có $n$ cột và cùng không gian không, nên theo định lý hạng–số khuyết chúng cùng hạng. Kết quả này dùng ở Chương 08.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Họ trực giao các vectơ khác $0$ thì độc lập tuyến tính.&lt;/li&gt;
    &lt;li&gt;Theo cơ sở trực giao: $x = \sum_i \dfrac{\langle x, u_i \rangle}{\langle u_i, u_i \rangle} u_i$; theo cơ sở trực chuẩn, hệ số là $\langle x, u_i \rangle$.&lt;/li&gt;
    &lt;li&gt;$W^\perp$ là không gian con, $\dim W + \dim W^\perp = \dim V$, $(W^\perp)^\perp = W$.&lt;/li&gt;
    &lt;li&gt;$(\operatorname{Row} A)^\perp = \operatorname{Null} A$ và $(\operatorname{Col} A)^\perp = \operatorname{Null} A^T$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Bất đẳng thức Cauchy–Schwarz và góc</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter07/07_02_Bat_Dang_Thuc_Cauchy_Schwarz_Va_Goc/"/>
   <updated>2026-01-07T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter07/07_02_Bat_Dang_Thuc_Cauchy_Schwarz_Va_Goc</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;phát biểu và chứng minh bất đẳng thức Cauchy–Schwarz, kể cả trường hợp dấu bằng;&lt;/li&gt;
    &lt;li&gt;suy ra bất đẳng thức tam giác;&lt;/li&gt;
    &lt;li&gt;định nghĩa và tính góc giữa hai vectơ, giữa hai hàm, và dùng độ tương tự cosin.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Trong $\mathbb{R}^2$, ta biết $u \cdot v = \lVert u \rVert \lVert v \rVert \cos\theta$ (Chương 01), nên $\lvert u \cdot v \rvert \le \lVert u \rVert \lVert v \rVert$ vì $\lvert \cos\theta \rvert \le 1$. Nhưng với tích vô hướng $\langle f, g \rangle = \int_0^1 f g$ trên các hàm, “góc giữa hai hàm” chưa có nghĩa. Ta đi ngược lại: chứng minh bất đẳng thức chỉ từ các tiên đề, rồi &lt;em&gt;dùng&lt;/em&gt; nó để định nghĩa góc.&lt;/p&gt;

&lt;h2 id=&quot;bất-đẳng-thức-cauchyschwarz&quot;&gt;Bất đẳng thức Cauchy–Schwarz&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Cauchy–Schwarz).&lt;/strong&gt; Trong mọi không gian tích vô hướng, với mọi $u, v$:&lt;/p&gt;

\[\lvert \langle u, v \rangle \rvert \le \lVert u \rVert\, \lVert v \rVert.\]

  &lt;p&gt;Dấu bằng xảy ra khi và chỉ khi $u$ và $v$ phụ thuộc tuyến tính.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Nếu $v = 0$, hai vế đều bằng $0$. Giả sử $v \ne 0$. Với mọi $t \in \mathbb{R}$,&lt;/p&gt;

\[0 \le \lVert u - tv \rVert^2 = \lVert u \rVert^2 - 2t\langle u, v \rangle + t^2 \lVert v \rVert^2.\]

  &lt;p&gt;Chọn $t = \langle u, v \rangle / \lVert v \rVert^2$ (giá trị làm vế phải nhỏ nhất) được&lt;/p&gt;

\[0 \le \lVert u \rVert^2 - \frac{\langle u, v \rangle^2}{\lVert v \rVert^2},\]

  &lt;p&gt;tức $\langle u, v \rangle^2 \le \lVert u \rVert^2 \lVert v \rVert^2$. Dấu bằng xảy ra khi và chỉ khi $\lVert u - tv \rVert = 0$, tức $u = tv$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Giá trị $t = \langle u, v \rangle / \lVert v \rVert^2$ trong chứng minh không ngẫu nhiên: $tv$ là hình chiếu của $u$ lên đường thẳng qua $v$ (Bài 07-04), và bất đẳng thức chỉ nói “phần dư $u - tv$ có độ dài không âm”.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Với tích vô hướng thông thường trên $\mathbb{R}^n$, Cauchy–Schwarz là&lt;/p&gt;

\[(u_1 v_1 + \dots + u_n v_n)^2 \le (u_1^2 + \dots + u_n^2)(v_1^2 + \dots + v_n^2).\]

  &lt;p&gt;Với tích vô hướng tích phân trên $C[a, b]$, nó là&lt;/p&gt;

\[\left( \int_a^b f g \right)^2 \le \int_a^b f^2 \cdot \int_a^b g^2.\]

  &lt;p&gt;Cùng một chứng minh cho cả hai bất đẳng thức, dù một cái về tổng hữu hạn và một cái về tích phân.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bất-đẳng-thức-tam-giác&quot;&gt;Bất đẳng thức tam giác&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2 (Bất đẳng thức tam giác).&lt;/strong&gt; Với mọi $u, v$: $\lVert u + v \rVert \le \lVert u \rVert + \lVert v \rVert$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Theo Cauchy–Schwarz,
$\lVert u + v \rVert^2 = \lVert u \rVert^2 + 2\langle u, v \rangle + \lVert v \rVert^2 \le \lVert u \rVert^2 + 2\lVert u \rVert \lVert v \rVert + \lVert v \rVert^2 = (\lVert u \rVert + \lVert v \rVert)^2$.
Lấy căn hai vế.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Hệ quả cho khoảng cách: $d(u, w) \le d(u, v) + d(v, w)$. Đường thẳng là đường ngắn nhất, trong mọi không gian tích vô hướng.&lt;/p&gt;

&lt;h2 id=&quot;góc-và-trực-giao&quot;&gt;Góc và trực giao&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Góc, trực giao).&lt;/strong&gt; Với $u, v \ne 0$, Cauchy–Schwarz cho $-1 \le \dfrac{\langle u, v \rangle}{\lVert u \rVert \lVert v \rVert} \le 1$. &lt;em&gt;Góc&lt;/em&gt; giữa $u$ và $v$ là số $\theta \in [0, \pi]$ với&lt;/p&gt;

\[\cos\theta = \frac{\langle u, v \rangle}{\lVert u \rVert\, \lVert v \rVert}.\]

  &lt;p&gt;Hai vectơ $u, v$ (có thể bằng $0$) &lt;em&gt;trực giao&lt;/em&gt;, viết $u \perp v$, nếu $\langle u, v \rangle = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 3 (Pythagore).&lt;/strong&gt; Nếu $u \perp v$ thì $\lVert u + v \rVert^2 = \lVert u \rVert^2 + \lVert v \rVert^2$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Khai triển $\lVert u + v \rVert^2 = \lVert u \rVert^2 + 2\langle u, v \rangle + \lVert v \rVert^2$ và dùng $\langle u, v \rangle = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; Góc giữa $u = (1, 0, 1)$ và $v = (0, 1, 1)$ trong $\mathbb{R}^3$: $u \cdot v = 1$, $\lVert u \rVert = \lVert v \rVert = \sqrt{2}$, nên $\cos\theta = 1/2$ và $\theta = \pi/3$.&lt;/p&gt;

  &lt;p&gt;Góc giữa $f(x) = 1$ và $g(x) = x$ trong $C[0, 1]$: theo Bài 07-01, $\langle 1, x \rangle = \tfrac{1}{2}$, $\lVert 1 \rVert = 1$, $\lVert x \rVert = 1/\sqrt{3}$. Vậy $\cos\theta = \tfrac{1}{2} \cdot \sqrt{3} = \tfrac{\sqrt{3}}{2}$ và $\theta = \pi/6$.&lt;/p&gt;

  &lt;p&gt;Trên $C[-\pi, \pi]$, $\langle \sin x, \cos x \rangle = \int_{-\pi}^{\pi} \sin x \cos x\, dx = 0$: hai hàm này trực giao. Đây là nền của chuỗi Fourier.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-độ-tương-tự-cosin&quot;&gt;Ứng dụng: độ tương tự cosin&lt;/h2&gt;

&lt;p&gt;Trong tìm kiếm văn bản, mỗi tài liệu được biểu diễn bằng một vectơ đếm từ $d \in \mathbb{R}^N$, với $N$ là số từ trong từ điển. Hai tài liệu cùng chủ đề có vectơ “cùng hướng”, dù một tài liệu dài gấp mười lần tài liệu kia. Vì vậy người ta so sánh bằng &lt;em&gt;độ tương tự cosin&lt;/em&gt; $\cos\theta = \dfrac{d_1 \cdot d_2}{\lVert d_1 \rVert \lVert d_2 \rVert}$ thay vì khoảng cách: nhân một vectơ với số dương không đổi cosin. Các hệ thống tìm kiếm ngữ nghĩa hiện đại làm đúng điều này với các vectơ nhúng (embedding) do mạng nơ-ron sinh ra.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: bất đẳng thức Cauchy–Schwarz&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Tỉ số ∣u·v∣ / (‖u‖‖v‖) không bao giờ vượt quá 1, và bằng 1 khi u, v cùng phương.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter01/vecto_2d.html?mode=cs&quot; title=&quot;Minh hoạ: bất đẳng thức Cauchy–Schwarz&quot; loading=&quot;lazy&quot; style=&quot;height: 620px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter01/vecto_2d.html?mode=cs&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Tính góc giữa $(1, 2, 2)$ và $(2, -1, 2)$, và giữa $(1, 1)$ và $(1, -1)$ theo tích vô hướng ở Ví dụ 2 Bài 07-01.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$(1,2,2) \cdot (2,-1,2) = 2 - 2 + 4 = 4$, hai chuẩn đều bằng 3, nên $\cos\theta = 4/9$, $\theta \approx 63{,}6^\circ$. Với $M = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$: $\langle (1,1), (1,-1) \rangle = 2 - 1 + 1 - 1 = 1$, $\lVert (1,1) \rVert = \sqrt{5}$, $\lVert (1,-1) \rVert^2 = 2 - 1 - 1 + 1 = 1$. Vậy $\cos\theta = 1/\sqrt{5}$, $\theta \approx 63{,}4^\circ$, không phải $90^\circ$ như với tích vô hướng thông thường.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Chứng minh bất đẳng thức Cauchy–Schwarz cho tích vô hướng $\langle f, g \rangle = \int_0^1 f g$, rồi áp dụng để chứng minh $\left(\int_0^1 f\right)^2 \le \int_0^1 f^2$ với mọi $f$ liên tục.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Chứng minh ở Định lý 1 chỉ dùng các tiên đề, nên áp dụng nguyên văn: xét $0 \le \int_0^1 (f - tg)^2$ và chọn $t = \int fg / \int g^2$. Áp dụng với $g = 1$: $\left(\int_0^1 f \cdot 1\right)^2 \le \int_0^1 f^2 \cdot \int_0^1 1 = \int_0^1 f^2$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Với $a, b, c &amp;gt; 0$, chứng minh $(a + b + c)\left(\tfrac{1}{a} + \tfrac{1}{b} + \tfrac{1}{c}\right) \ge 9$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Áp dụng Cauchy–Schwarz cho $u = (\sqrt{a}, \sqrt{b}, \sqrt{c})$ và $v = (1/\sqrt{a}, 1/\sqrt{b}, 1/\sqrt{c})$: $(u \cdot v)^2 = 9 \le \lVert u \rVert^2 \lVert v \rVert^2$, chính là bất đẳng thức cần chứng minh. Dấu bằng khi $a = b = c$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Chứng minh: nếu $u \perp v$ thì $\lVert u - v \rVert = \lVert u + v \rVert$. Giải thích bằng hình chữ nhật.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\lVert u \pm v \rVert^2 = \lVert u \rVert^2 \pm 2\langle u, v \rangle + \lVert v \rVert^2 = \lVert u \rVert^2 + \lVert v \rVert^2$. Hình bình hành dựng trên $u, v$ vuông góc là hình chữ nhật, và hai đường chéo $u + v$, $u - v$ của hình chữ nhật bằng nhau.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Chứng minh $\lvert \lVert u \rVert - \lVert v \rVert \rvert \le \lVert u - v \rVert$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Bất đẳng thức tam giác với $u = (u - v) + v$ cho $\lVert u \rVert - \lVert v \rVert \le \lVert u - v \rVert$. Đổi vai trò $u$, $v$ cho $\lVert v \rVert - \lVert u \rVert \le \lVert u - v \rVert$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Cauchy–Schwarz: $\lvert \langle u, v \rangle \rvert \le \lVert u \rVert \lVert v \rVert$, dấu bằng khi $u$, $v$ cùng phương; chứng minh bằng $\lVert u - tv \rVert^2 \ge 0$.&lt;/li&gt;
    &lt;li&gt;Hệ quả: bất đẳng thức tam giác $\lVert u + v \rVert \le \lVert u \rVert + \lVert v \rVert$.&lt;/li&gt;
    &lt;li&gt;Góc: $\cos\theta = \langle u, v \rangle / (\lVert u \rVert \lVert v \rVert)$; trực giao khi $\langle u, v \rangle = 0$; Pythagore đúng cho vectơ trực giao.&lt;/li&gt;
    &lt;li&gt;Độ tương tự cosin so sánh hướng, bỏ qua độ dài.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Tích vô hướng tổng quát và chuẩn</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter07/07_01_Tich_Vo_Huong_Tong_Quat_Va_Chuan/"/>
   <updated>2026-01-07T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter07/07_01_Tich_Vo_Huong_Tong_Quat_Va_Chuan</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;kiểm tra một dạng $\langle \cdot, \cdot \rangle$ có phải tích vô hướng hay không bằng bốn tiên đề;&lt;/li&gt;
    &lt;li&gt;tính chuẩn và khoảng cách theo một tích vô hướng cho trước, kể cả tích vô hướng có trọng số và tích vô hướng tích phân;&lt;/li&gt;
    &lt;li&gt;viết một tích vô hướng trên $\mathbb{R}^n$ dưới dạng $u^T M v$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Một cửa hàng đo hai đại lượng cho mỗi sản phẩm: giá (triệu đồng) và khối lượng (kg). Hai sản phẩm $u = (2, 10)$ và $v = (3, 10)$ cách nhau $\lVert u - v \rVert = 1$ theo khoảng cách Euclid. Nếu đổi khối lượng sang gam, cùng hai sản phẩm thành $(2, 10000)$ và $(3, 10000)$, khoảng cách vẫn là 1; nhưng nếu hai sản phẩm khác nhau 1 kg, khoảng cách nhảy từ 1 lên 1000. “Khoảng cách” phụ thuộc cách ta cân các thành phần.&lt;/p&gt;

&lt;p&gt;Tích vô hướng tổng quát cho phép chọn cách cân đó, miễn là giữ được các tính chất hình học cơ bản. Nó cũng cho phép đo “góc” và “độ dài” của những đối tượng không phải mũi tên, như hàm số.&lt;/p&gt;

&lt;h2 id=&quot;định-nghĩa&quot;&gt;Định nghĩa&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Tích vô hướng).&lt;/strong&gt; Cho $V$ là không gian vectơ thực. Một &lt;em&gt;tích vô hướng&lt;/em&gt; trên $V$ là một quy tắc gán cho mỗi cặp $u, v \in V$ một số thực $\langle u, v \rangle$ sao cho với mọi $u, v, w \in V$ và $c \in \mathbb{R}$:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;&lt;em&gt;đối xứng&lt;/em&gt;: $\langle u, v \rangle = \langle v, u \rangle$;&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;tuyến tính theo biến thứ nhất&lt;/em&gt;: $\langle u + w, v \rangle = \langle u, v \rangle + \langle w, v \rangle$ và $\langle cu, v \rangle = c\langle u, v \rangle$;&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;xác định dương&lt;/em&gt;: $\langle v, v \rangle \ge 0$, và $\langle v, v \rangle = 0$ chỉ khi $v = 0$.&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;Không gian $V$ cùng một tích vô hướng là một &lt;em&gt;không gian tích vô hướng&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Từ đối xứng và tuyến tính theo biến thứ nhất suy ra tuyến tính theo cả biến thứ hai. Tích vô hướng thông thường $u \cdot v = u_1 v_1 + \dots + u_n v_n$ trên $\mathbb{R}^n$ (Chương 01) thoả cả ba tiên đề.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 2 (Chuẩn và khoảng cách).&lt;/strong&gt; Trong không gian tích vô hướng, &lt;em&gt;chuẩn&lt;/em&gt; (độ dài) của $v$ là $\lVert v \rVert = \sqrt{\langle v, v \rangle}$, và &lt;em&gt;khoảng cách&lt;/em&gt; giữa $u$ và $v$ là $d(u, v) = \lVert u - v \rVert$. Vectơ có chuẩn 1 gọi là &lt;em&gt;vectơ đơn vị&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Chuẩn có các tính chất $\lVert cv \rVert = \lvert c \rvert\, \lVert v \rVert$ và $\lVert v \rVert = 0$ chỉ khi $v = 0$. Bất đẳng thức tam giác $\lVert u + v \rVert \le \lVert u \rVert + \lVert v \rVert$ cần Cauchy–Schwarz và được chứng minh ở Bài 07-02.&lt;/p&gt;

&lt;h2 id=&quot;tích-vô-hướng-trên-mathbbrn-dạng-ut-m-v&quot;&gt;Tích vô hướng trên $\mathbb{R}^n$ dạng $u^T M v$&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (tích vô hướng có trọng số).&lt;/strong&gt; Với các số $w_1, \dots, w_n &amp;gt; 0$, công thức&lt;/p&gt;

\[\langle u, v \rangle = w_1 u_1 v_1 + \dots + w_n u_n v_n\]

  &lt;p&gt;là một tích vô hướng trên $\mathbb{R}^n$: đối xứng và tuyến tính là rõ, và $\langle v, v \rangle = \sum w_i v_i^2 \ge 0$, bằng $0$ chỉ khi mọi $v_i = 0$. Trọng số $w_i$ cho biết thành phần thứ $i$ “quan trọng” đến đâu, đúng như ví dụ mở đầu.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Tổng quát hơn, với ma trận đối xứng $M$ cỡ $n \times n$, đặt $\langle u, v \rangle_M = u^T M v$. Đối xứng và tuyến tính luôn đúng; tiên đề 3 đúng khi và chỉ khi $v^T M v &amp;gt; 0$ với mọi $v \ne 0$. Ma trận như vậy gọi là &lt;em&gt;xác định dương&lt;/em&gt; và được nghiên cứu kỹ ở Chương 10.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; Trên $\mathbb{R}^2$, xét&lt;/p&gt;

\[\langle u, v \rangle = 2u_1 v_1 + u_1 v_2 + u_2 v_1 + u_2 v_2 = u^T \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix} v.\]

  &lt;p&gt;Ta có $\langle v, v \rangle = 2v_1^2 + 2v_1 v_2 + v_2^2 = v_1^2 + (v_1 + v_2)^2$, luôn $\ge 0$ và bằng $0$ chỉ khi $v_1 = 0$ và $v_1 + v_2 = 0$, tức $v = 0$. Vậy đây là tích vô hướng. Theo nó, $\lVert e_1 \rVert = \sqrt{2}$, $\lVert e_2 \rVert = 1$ và $\langle e_1, e_2 \rangle = 1 \ne 0$: hai vectơ chuẩn tắc không còn vuông góc.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3 (không phải tích vô hướng).&lt;/strong&gt; Công thức $\langle u, v \rangle = u_1 v_1 - u_2 v_2$ đối xứng và tuyến tính, nhưng $\langle e_2, e_2 \rangle = -1 &amp;lt; 0$, vi phạm tiên đề 3. Công thức $\langle u, v \rangle = u_1 v_1$ cũng không phải: $\langle e_2, e_2 \rangle = 0$ dù $e_2 \ne 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;tích-vô-hướng-trên-không-gian-hàm&quot;&gt;Tích vô hướng trên không gian hàm&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 4.&lt;/strong&gt; Trên không gian $C[a, b]$ các hàm liên tục trên $[a, b]$, đặt&lt;/p&gt;

\[\langle f, g \rangle = \int_a^b f(x)\, g(x)\, dx.\]

  &lt;p&gt;Đối xứng và tuyến tính suy ra từ tính chất của tích phân. Với tiên đề 3: $\langle f, f \rangle = \int_a^b f(x)^2\, dx \ge 0$, và nếu $f$ liên tục, khác $0$ tại một điểm thì $f^2 &amp;gt; 0$ trên một khoảng nhỏ quanh điểm đó, nên tích phân dương. Đây là tích vô hướng.&lt;/p&gt;

  &lt;p&gt;Trên $[0, 1]$: $\langle 1, x \rangle = \int_0^1 x\, dx = \tfrac{1}{2}$, $\lVert x \rVert^2 = \int_0^1 x^2\, dx = \tfrac{1}{3}$, và khoảng cách giữa $f(x) = 1$ và $g(x) = x$ là&lt;/p&gt;

  &lt;p&gt;\(\lVert 1 - x \rVert = \sqrt{\int_0^1 (1 - x)^2\, dx} = \frac{1}{\sqrt{3}}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Khoảng cách này đo sai lệch “trung bình bình phương” giữa hai hàm, khác với sai lệch lớn nhất $\max \lvert f - g \rvert = 1$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Đồng nhất thức hình bình hành).&lt;/strong&gt; Trong mọi không gian tích vô hướng,&lt;/p&gt;

  &lt;p&gt;\(\lVert u + v \rVert^2 + \lVert u - v \rVert^2 = 2\lVert u \rVert^2 + 2\lVert v \rVert^2.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Khai triển bằng tính tuyến tính: $\lVert u \pm v \rVert^2 = \langle u \pm v, u \pm v \rangle = \lVert u \rVert^2 \pm 2\langle u, v \rangle + \lVert v \rVert^2$. Cộng hai đẳng thức, các số hạng $\pm 2\langle u, v \rangle$ triệt tiêu.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Hệ quả: tích vô hướng được khôi phục từ chuẩn qua $\langle u, v \rangle = \tfrac{1}{4}\left(\lVert u + v \rVert^2 - \lVert u - v \rVert^2\right)$. Chuẩn “max” $\max_i \lvert v_i \rvert$ không thoả đồng nhất thức hình bình hành (thử $u = e_1$, $v = e_2$), nên không sinh bởi tích vô hướng nào.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-khoảng-cách-mahalanobis&quot;&gt;Ứng dụng: khoảng cách Mahalanobis&lt;/h2&gt;

&lt;p&gt;Trong thống kê, khi các đặc trưng có độ lệch chuẩn khác nhau và tương quan với nhau, khoảng cách Euclid đánh giá sai mức “khác thường” của một điểm. Khoảng cách Mahalanobis dùng tích vô hướng $\langle u, v \rangle = u^T \Sigma^{-1} v$, với $\Sigma$ là ma trận hiệp phương sai. Trường hợp các đặc trưng độc lập, nó là tích vô hướng có trọng số $w_i = 1/\sigma_i^2$: mỗi thành phần được đo theo đơn vị độ lệch chuẩn của chính nó, giải quyết vấn đề đơn vị ở ví dụ mở đầu.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: tích vô hướng, chuẩn và góc&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo u, v: u·v, ‖u‖, cos θ và hình chiếu thay đổi theo.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter01/vecto_2d.html?mode=dot&quot; title=&quot;Minh hoạ: tích vô hướng, chuẩn và góc&quot; loading=&quot;lazy&quot; style=&quot;height: 620px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter01/vecto_2d.html?mode=dot&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Với tích vô hướng ở Ví dụ 2, tính $\lVert (1, 1) \rVert$ và $\langle (1, 0), (1, -2) \rangle$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\langle (1,1), (1,1) \rangle = 2 + 1 + 1 + 1 = 5$, nên $\lVert (1, 1) \rVert = \sqrt{5}$. $\langle (1,0), (1,-2) \rangle = 2 \cdot 1 \cdot 1 + 1 \cdot (-2) + 0 + 0 = 0$: hai vectơ này vuông góc theo tích vô hướng mới.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Với giá trị nào của $k$ thì $\langle u, v \rangle = u_1 v_1 + k u_2 v_2$ là tích vô hướng trên $\mathbb{R}^2$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Khi $k &amp;gt; 0$. Nếu $k \le 0$ thì $\langle e_2, e_2 \rangle = k \le 0$ dù $e_2 \ne 0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Trong $C[0, 1]$ với tích vô hướng tích phân, tính $\lVert x^2 \rVert$ và $\langle x, x^2 \rangle$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\lVert x^2 \rVert^2 = \int_0^1 x^4\, dx = \tfrac{1}{5}$, nên $\lVert x^2 \rVert = 1/\sqrt{5}$. $\langle x, x^2 \rangle = \int_0^1 x^3\, dx = \tfrac{1}{4}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Kiểm tra rằng $\langle A, B \rangle = \operatorname{tr}(A^T B)$ là tích vô hướng trên không gian các ma trận $m \times n$, và chuẩn sinh bởi nó là $\sqrt{\sum_{i,j} a_{ij}^2}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\operatorname{tr}(A^T B) = \sum_{i,j} a_{ij} b_{ij}$, chính là tích vô hướng thông thường khi xếp các phần tử thành một vectơ dài $mn$. Vì vậy ba tiên đề đúng, và $\langle A, A \rangle = \sum a_{ij}^2$. Chuẩn này gọi là chuẩn Frobenius.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Chứng minh chuẩn $\lVert v \rVert_1 = \lvert v_1 \rvert + \lvert v_2 \rvert$ trên $\mathbb{R}^2$ không sinh bởi tích vô hướng nào.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Với $u = e_1$, $v = e_2$: $\lVert u + v \rVert_1^2 + \lVert u - v \rVert_1^2 = 4 + 4 = 8$, còn $2\lVert u \rVert_1^2 + 2\lVert v \rVert_1^2 = 4$. Đồng nhất thức hình bình hành sai, nên theo Định lý 1 không có tích vô hướng nào sinh ra chuẩn này.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Tích vô hướng: đối xứng, tuyến tính, xác định dương. Chuẩn $\lVert v \rVert = \sqrt{\langle v, v \rangle}$, khoảng cách $\lVert u - v \rVert$.&lt;/li&gt;
    &lt;li&gt;Trên $\mathbb{R}^n$: $\langle u, v \rangle = u^T M v$ với $M$ đối xứng xác định dương; trường hợp riêng là tích vô hướng có trọng số.&lt;/li&gt;
    &lt;li&gt;Trên hàm liên tục: $\langle f, g \rangle = \int_a^b f g$.&lt;/li&gt;
    &lt;li&gt;Chuẩn sinh bởi tích vô hướng thoả đồng nhất thức hình bình hành.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Orthogonal Matrices, Rotations and Reflections</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter07/07_07_Ma_Tran_Truc_Giao_Phep_Quay_Va_Phan_Xa/"/>
   <updated>2026-01-07T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter07/07_07_Ma_Tran_Truc_Giao_Phep_Quay_Va_Phan_Xa</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;recognize an orthogonal matrix by $Q^T Q = I$ and use $Q^{-1} = Q^T$;&lt;/li&gt;
    &lt;li&gt;prove that orthogonal matrices preserve inner products, lengths and angles, and have determinant $\pm 1$;&lt;/li&gt;
    &lt;li&gt;write rotation matrices in $\mathbb{R}^2$ and Householder reflections $H = I - 2uu^T$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;A camera in a 3D game orbits a character. Every frame, the coordinates of every point are multiplied by a rotation matrix. After thousands of frames the character must keep its size and shape: no shrinking, no distortion. What makes a matrix “distortion-free”? Answer: its columns must be orthonormal. Such a matrix is called orthogonal, and its inverse is just its transpose, with no elimination needed.&lt;/p&gt;

&lt;h2 id=&quot;definition-and-properties&quot;&gt;Definition and properties&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Orthogonal matrix).&lt;/strong&gt; A square $n \times n$ matrix $Q$ is &lt;em&gt;orthogonal&lt;/em&gt; if $Q^T Q = I$, i.e. the columns of $Q$ form an orthonormal basis of $\mathbb{R}^n$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Note the naming: an &lt;em&gt;orthogonal&lt;/em&gt; matrix has &lt;em&gt;orthonormal&lt;/em&gt; columns. Since $Q$ is square, $Q^TQ = I$ implies $Q^{-1} = Q^T$, so also $QQ^T = I$: the &lt;em&gt;rows&lt;/em&gt; of $Q$ are orthonormal too.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; For a square matrix $Q$ the following are equivalent:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$Q$ is orthogonal;&lt;/li&gt;
    &lt;li&gt;$\langle Qx, Qy \rangle = \langle x, y \rangle$ for all $x, y$ (inner products preserved);&lt;/li&gt;
    &lt;li&gt;$\lVert Qx \rVert = \lVert x \rVert$ for all $x$ (lengths preserved).&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;Then $Q$ also preserves angles and distances, and $\det Q = \pm 1$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; (1)⇒(2): $(Qx)^T(Qy) = x^T Q^T Q y = x^T y$. (2)⇒(3): take $y = x$. (3)⇒(1): by Lesson 07-01 the inner product is recovered from the norm via $\langle u, v \rangle = \tfrac14(\lVert u + v \rVert^2 - \lVert u - v \rVert^2)$, so preserving norms implies preserving inner products; applying this to $x = e_i$, $y = e_j$ gives $q_i^T q_j = \delta_{ij}$, i.e. $Q^TQ = I$. Angles and distances are defined through inner products and norms, so they are preserved. Finally $1 = \det(Q^TQ) = (\det Q)^2$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2.&lt;/strong&gt; The product of two orthogonal matrices is orthogonal; the inverse of an orthogonal matrix is orthogonal.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; $(Q_1Q_2)^T(Q_1Q_2) = Q_2^T Q_1^T Q_1 Q_2 = Q_2^T Q_2 = I$, and $(Q^{-1})^T Q^{-1} = (Q^T)^T Q^T = QQ^T = I$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;rotations&quot;&gt;Rotations&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (rotations of $\mathbb{R}^2$).&lt;/strong&gt; The rotation by angle $\theta$ is&lt;/p&gt;

\[R_\theta = \begin{bmatrix} \cos\theta &amp;amp; -\sin\theta \\ \sin\theta &amp;amp; \cos\theta \end{bmatrix}.\]

  &lt;p&gt;Its columns have length $1$ and are perpendicular, so $R_\theta$ is orthogonal, $\det R_\theta = \cos^2\theta + \sin^2\theta = 1$, and $R_\theta^{-1} = R_\theta^T = R_{-\theta}$: rotate back by $\theta$. Also $R_\alpha R_\beta = R_{\alpha + \beta}$, matching multiplication of complex numbers (Lesson 00-02).&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Every $2 \times 2$ orthogonal matrix with determinant $1$ is a rotation $R_\theta$. In $\mathbb{R}^3$, every orthogonal matrix with determinant $1$ is a rotation about an axis (Euler’s theorem, proved in Chapter 09 via the eigenvalue $1$). Orthogonal matrices with determinant $1$ are called &lt;em&gt;rotations&lt;/em&gt;; those with determinant $-1$ involve a reflection.&lt;/p&gt;

&lt;h2 id=&quot;householder-reflections&quot;&gt;Householder reflections&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 2 (Householder reflection).&lt;/strong&gt; Let $u \in \mathbb{R}^n$ be a unit vector. The matrix&lt;/p&gt;

\[H = I - 2uu^T\]

  &lt;p&gt;is the &lt;em&gt;reflection&lt;/em&gt; across the hyperplane $u^\perp$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 3.&lt;/strong&gt; $H = I - 2uu^T$ is symmetric and orthogonal, $H^2 = I$, $Hu = -u$, $Hx = x$ for every $x \perp u$, and $\det H = -1$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; $H^T = I - 2(uu^T)^T = H$. $H^2 = I - 4uu^T + 4u(u^Tu)u^T = I$ since $u^Tu = 1$; symmetry and $H^2 = I$ give $H^TH = I$. $Hu = u - 2u(u^Tu) = -u$, and if $u^Tx = 0$ then $Hx = x$. In a basis consisting of $u$ and $n - 1$ vectors of $u^\perp$, $H$ is diagonal with entries $-1, 1, \dots, 1$, so $\det H = -1$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Meaning: $x = (x - \operatorname{proj}_u x) + \operatorname{proj}_u x$, and $H$ keeps the first part and flips the sign of the second. It is a mirror across the plane perpendicular to $u$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (sending a vector to an axis).&lt;/strong&gt; Find the reflection that sends $x = (3, 4)$ to $(5, 0)$ (same length $5$). A reflection sends $x$ to $y$ when $u$ points along $x - y = (-2, 4)$. With $w = (-2, 4)$, $w^Tw = 20$:&lt;/p&gt;

\[H = I - \frac{2ww^T}{w^Tw} = I - \frac{1}{10}\begin{bmatrix} 4 &amp;amp; -8 \\ -8 &amp;amp; 16 \end{bmatrix} = \begin{bmatrix} 3/5 &amp;amp; 4/5 \\ 4/5 &amp;amp; -3/5 \end{bmatrix}.\]

  &lt;p&gt;Check: $Hx = (\tfrac{9 + 16}{5}, \tfrac{12 - 12}{5}) = (5, 0)$, and $\det H = -\tfrac{9}{25} - \tfrac{16}{25} = -1$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Example 2 is the idea behind &lt;em&gt;Householder QR&lt;/em&gt;: one reflection sends the first column of $A$ to $(r_{11}, 0, \dots, 0)$, then repeat on the submatrix. The product of the reflections is $Q^T$. Because it only multiplies by orthogonal matrices, this method does not amplify errors; that is why &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.qr&lt;/code&gt; keeps orthogonality much better than Gram–Schmidt (Lesson 07-05).&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3 (permutation matrices).&lt;/strong&gt; A permutation matrix $P$ (exactly one $1$ in each row and column) is orthogonal: its columns are the vectors $e_i$ in a different order. For example $\begin{bmatrix} 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix}$ is the reflection across the line $y = x$, with determinant $-1$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-why-numerical-algorithms-love-orthogonal-matrices&quot;&gt;Application: why numerical algorithms love orthogonal matrices&lt;/h2&gt;

&lt;p&gt;If $x$ carries an error $\delta x$, then $Q(x + \delta x) = Qx + Q\,\delta x$ and $\lVert Q\,\delta x \rVert = \lVert \delta x \rVert$: multiplying by an orthogonal matrix does not grow errors. A general matrix, by contrast, can amplify errors by its condition number (Chapter 11). So modern algorithms (Householder QR, the QR eigenvalue algorithm, the SVD) are built from rotations and reflections. In graphics and robotics (Chapter 12), rotation matrices are periodically re-orthonormalized to stop errors piling up over thousands of products, exactly like the camera in the motivating example.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: rotations and Householder reflections&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag x and u: lengths and dot products are preserved; the Householder button sends x to (‖x‖, 0).&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter07/quay_phan_xa.html?lang=en&quot; title=&quot;Interactive: rotations and Householder reflections&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter07/quay_phan_xa.html?lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Which of these matrices are orthogonal? $A = \tfrac{1}{3}\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 2 \\ 2 &amp;amp; 1 &amp;amp; -2 \\ 2 &amp;amp; -2 &amp;amp; 1 \end{bmatrix}$, $B = \begin{bmatrix} 1 &amp;amp; 1 \\ -1 &amp;amp; 1 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A$ is orthogonal: its columns $\tfrac13(1,2,2)$, $\tfrac13(2,1,-2)$, $\tfrac13(2,-2,1)$ are pairwise perpendicular (Exercise 1, Lesson 07-03) and have length $1$. $B$ is not: its columns are perpendicular but have length $\sqrt{2}$; $\tfrac{1}{\sqrt{2}}B$ is the rotation by $-45^\circ$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Find the Householder reflection sending $x = (1, 2, 2)$ to $(3, 0, 0)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$w = x - (3,0,0) = (-2, 2, 2)$, $w^Tw = 12$, $H = I - \tfrac{1}{6}ww^T = \tfrac{1}{3}\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 2 \\ 2 &amp;amp; 1 &amp;amp; -2 \\ 2 &amp;amp; -2 &amp;amp; 1 \end{bmatrix}$. Check: $Hx = \tfrac13(1 + 4 + 4,\ 2 + 2 - 4,\ 2 - 4 + 2) = (3, 0, 0)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Prove: if $\lambda$ is a real eigenvalue of an orthogonal matrix $Q$, then $\lambda = \pm 1$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

If $Qx = \lambda x$ with $x \ne 0$, then $\lVert x \rVert = \lVert Qx \rVert = \lvert \lambda \rvert \lVert x \rVert$, so $\lvert \lambda \rvert = 1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Prove that the product of two reflections of $\mathbb{R}^2$ is a rotation.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The product of orthogonal matrices is orthogonal (Theorem 2), with determinant $(-1)(-1) = 1$. A $2 \times 2$ orthogonal matrix with determinant $1$ is a rotation. (Geometrically: reflecting across two lines at angle $\alpha$ is a rotation by $2\alpha$.)

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Prove that every $2 \times 2$ orthogonal matrix is either $R_\theta$ or $\begin{bmatrix} \cos\theta &amp;amp; \sin\theta \\ \sin\theta &amp;amp; -\cos\theta \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The first column is a unit vector, so it is $(\cos\theta, \sin\theta)$. The second column is a unit vector perpendicular to it, so it is $(-\sin\theta, \cos\theta)$ or $(\sin\theta, -\cos\theta)$. The first case is $R_\theta$ (determinant $1$); the second is the reflection across the line at angle $\theta/2$ (determinant $-1$).

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$Q$ is orthogonal when $Q^TQ = I$ (orthonormal columns); then $Q^{-1} = Q^T$ and the rows are orthonormal too.&lt;/li&gt;
    &lt;li&gt;Orthogonal matrices preserve inner products, lengths and angles; $\det Q = \pm 1$; products and inverses of orthogonal matrices are orthogonal.&lt;/li&gt;
    &lt;li&gt;Rotations $R_\theta$ have determinant $1$; Householder reflections $H = I - 2uu^T$ are symmetric, satisfy $H^2 = I$, and have determinant $-1$.&lt;/li&gt;
    &lt;li&gt;Householder reflections send a vector to a coordinate axis and underlie stable QR.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>The QR Factorization</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter07/07_06_Phan_Ra_QR/"/>
   <updated>2026-01-07T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter07/07_06_Phan_Ra_QR</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;write the factorization $A = QR$ of a matrix with independent columns from the Gram–Schmidt results;&lt;/li&gt;
    &lt;li&gt;explain the meaning of each entry of $R$;&lt;/li&gt;
    &lt;li&gt;use $QR$ to solve systems and to project onto $\operatorname{Col} A$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;In Lesson 07-05 we orthonormalized $a_1 = (1,1,0)$, $a_2 = (1,0,1)$, $a_3 = (0,1,1)$ into $q_1, q_2, q_3$. The process gives more than three new vectors: from $v_j = a_j - \sum_{i&amp;lt;j} \langle a_j, q_i \rangle q_i$ we can write back&lt;/p&gt;

\[a_1 = \sqrt{2}\, q_1, \qquad a_2 = \tfrac{1}{\sqrt{2}} q_1 + \sqrt{\tfrac{3}{2}}\, q_2, \qquad a_3 = \tfrac{1}{\sqrt{2}} q_1 + \tfrac{1}{\sqrt{6}} q_2 + \tfrac{2}{\sqrt{3}}\, q_3.\]

&lt;p&gt;Each $a_j$ uses only $q_1, \dots, q_j$. Arranging the coefficients in a matrix gives an &lt;em&gt;upper triangular&lt;/em&gt; matrix. That is the QR factorization.&lt;/p&gt;

&lt;h2 id=&quot;the-qr-factorization&quot;&gt;The QR factorization&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (QR factorization).&lt;/strong&gt; Let $A$ be an $m \times n$ matrix with linearly independent columns $a_1, \dots, a_n$. Then&lt;/p&gt;

\[A = QR,\]

  &lt;p&gt;where $Q$ is an $m \times n$ matrix with orthonormal columns ($Q^T Q = I_n$) and $R$ is an $n \times n$ upper triangular matrix with positive diagonal. Specifically, the columns of $Q$ are the Gram–Schmidt vectors $q_1, \dots, q_n$, and&lt;/p&gt;

  &lt;p&gt;\(r_{ij} = \langle a_j, q_i \rangle \ (i &amp;lt; j), \qquad r_{jj} = \lVert v_j \rVert, \qquad r_{ij} = 0 \ (i &amp;gt; j).\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; From Gram–Schmidt, $a_j = v_j + \sum_{i&amp;lt;j} \langle a_j, q_i \rangle q_i = \lVert v_j \rVert q_j + \sum_{i&amp;lt;j} \langle a_j, q_i \rangle q_i$. This is column $j$ of $A = QR$ with $R$ as above. The diagonal is positive because $v_j \ne 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Since $Q^T Q = I$, multiplying on the left by $Q^T$ gives $R = Q^T A$: once you have $Q$, $R$ is one matrix product.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; For $A = \begin{bmatrix} 1 &amp;amp; 1 &amp;amp; 0 \\ 1 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; 1 \end{bmatrix}$ (columns $a_1, a_2, a_3$ above):&lt;/p&gt;

\[Q = \begin{bmatrix} \frac{1}{\sqrt{2}} &amp;amp; \frac{1}{\sqrt{6}} &amp;amp; -\frac{1}{\sqrt{3}} \\ \frac{1}{\sqrt{2}} &amp;amp; -\frac{1}{\sqrt{6}} &amp;amp; \frac{1}{\sqrt{3}} \\ 0 &amp;amp; \frac{2}{\sqrt{6}} &amp;amp; \frac{1}{\sqrt{3}} \end{bmatrix}, \qquad R = \begin{bmatrix} \sqrt{2} &amp;amp; \frac{1}{\sqrt{2}} &amp;amp; \frac{1}{\sqrt{2}} \\ 0 &amp;amp; \sqrt{\frac{3}{2}} &amp;amp; \frac{1}{\sqrt{6}} \\ 0 &amp;amp; 0 &amp;amp; \frac{2}{\sqrt{3}} \end{bmatrix}.\]

  &lt;p&gt;Check one entry: row 3 of $Q$ times column 3 of $R$ is $0 \cdot \tfrac{1}{\sqrt{2}} + \tfrac{2}{\sqrt{6}} \cdot \tfrac{1}{\sqrt{6}} + \tfrac{1}{\sqrt{3}} \cdot \tfrac{2}{\sqrt{3}} = \tfrac{1}{3} + \tfrac{2}{3} = 1 = a_{33}$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; For $A = \begin{bmatrix} 3 &amp;amp; 0 \\ 4 &amp;amp; 5 \end{bmatrix}$: $r_{11} = \lVert (3, 4) \rVert = 5$, $q_1 = (\tfrac{3}{5}, \tfrac{4}{5})$; $r_{12} = \langle (0, 5), q_1 \rangle = 4$; $v_2 = (0, 5) - 4(\tfrac{3}{5}, \tfrac{4}{5}) = (-\tfrac{12}{5}, \tfrac{9}{5})$, $r_{22} = 3$, $q_2 = (-\tfrac{4}{5}, \tfrac{3}{5})$. So&lt;/p&gt;

  &lt;p&gt;\(\begin{bmatrix} 3 &amp;amp; 0 \\ 4 &amp;amp; 5 \end{bmatrix} = \begin{bmatrix} 3/5 &amp;amp; -4/5 \\ 4/5 &amp;amp; 3/5 \end{bmatrix} \begin{bmatrix} 5 &amp;amp; 4 \\ 0 &amp;amp; 3 \end{bmatrix}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;what-the-two-factors-mean&quot;&gt;What the two factors mean&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;$Q$ holds the &lt;em&gt;geometry&lt;/em&gt; of $\operatorname{Col} A$: an orthonormal basis of the column space. The projection onto $\operatorname{Col} A$ is $P = QQ^T$, much simpler than $A(A^TA)^{-1}A^T$.&lt;/li&gt;
  &lt;li&gt;$R$ holds the &lt;em&gt;coordinates&lt;/em&gt;: column $j$ of $R$ gives the coordinates of $a_j$ in the basis $q_1, \dots, q_n$. The entry $r_{jj}$ is the distance from $a_j$ to the span of the previous columns; a small $r_{jj}$ signals nearly dependent columns.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For a square matrix, $\lvert \det A \rvert = \lvert \det Q \rvert \det R = r_{11} r_{22} \cdots r_{nn}$, since $\det Q = \pm 1$ (Lesson 07-07). This is “volume = base × height” repeated: $r_{jj}$ is the height of column $j$ above the “base” spanned by the previous columns.&lt;/p&gt;

&lt;h2 id=&quot;solving-systems-with-qr&quot;&gt;Solving systems with QR&lt;/h2&gt;

&lt;p&gt;If $A$ is square and invertible, $Ax = b$ becomes $QRx = b$, i.e.&lt;/p&gt;

\[Rx = Q^T b.\]

&lt;p&gt;This upper triangular system is solved by back substitution. For non-square matrices the same equation gives the least-squares solution (Chapter 08, Lesson 08-04), and it avoids forming $A^T A$, which amplifies errors.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3.&lt;/strong&gt; Solve $\begin{bmatrix} 3 &amp;amp; 0 \\ 4 &amp;amp; 5 \end{bmatrix} x = \begin{bmatrix} 3 \\ 9 \end{bmatrix}$. We have $Q^T b = (\tfrac{9 + 36}{5}, \tfrac{-12 + 27}{5}) = (9, 3)$. Solve $5x_1 + 4x_2 = 9$, $3x_2 = 3$: $x_2 = 1$, $x_1 = 1$. Check: $3 \cdot 1 = 3$, $4 + 5 = 9$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-the-qr-algorithm-for-eigenvalues&quot;&gt;Application: the QR algorithm for eigenvalues&lt;/h2&gt;

&lt;p&gt;The most widely used algorithm for computing all eigenvalues of a matrix (Chapter 09) is built on QR: start from $A_0 = A$, factor $A_k = Q_k R_k$, then set $A_{k+1} = R_k Q_k$. Since $A_{k+1} = Q_k^T A_k Q_k$ is similar to $A_k$, all $A_k$ have the same eigenvalues; for many matrices $A_k$ converges to upper triangular form, and the diagonal gives the eigenvalues. Libraries such as LAPACK (used by NumPy) run refined versions of this algorithm.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: QR from Gram–Schmidt&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;The projection coefficients fill the upper-triangular R, and A = QR.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter07/gram_schmidt.html?last=1&amp;amp;lang=en&quot; title=&quot;Interactive: QR from Gram–Schmidt&quot; loading=&quot;lazy&quot; style=&quot;height: 760px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter07/gram_schmidt.html?last=1&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Find the QR factorization of $A = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$q_1 = \tfrac{1}{\sqrt{2}}(1, 1, 0)$, $r_{11} = \sqrt{2}$, $r_{12} = \tfrac{1}{\sqrt{2}}$. $v_2 = (\tfrac12, -\tfrac12, 1)$, $r_{22} = \sqrt{3/2}$, $q_2 = \tfrac{1}{\sqrt{6}}(1, -1, 2)$. So $Q = [q_1\ q_2]$ is $3 \times 2$ and $R = \begin{bmatrix} \sqrt{2} &amp;amp; 1/\sqrt{2} \\ 0 &amp;amp; \sqrt{3/2} \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; With $Q$ from Exercise 1, compute the projection matrix $QQ^T$ onto $\operatorname{Col} A$ and project $b = (1, 0, 0)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$QQ^T = \tfrac{1}{2}(1,1,0)(1,1,0)^T + \tfrac{1}{6}(1,-1,2)(1,-1,2)^T = \tfrac{1}{3}\begin{bmatrix} 2 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; -1 \\ 1 &amp;amp; -1 &amp;amp; 2 \end{bmatrix}$. So $Pb = \tfrac{1}{3}(2, 1, 1)$; the remainder $\tfrac{1}{3}(1, -1, -1)$ is perpendicular to both columns of $A$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Prove: if $A = QR$ with $A$ square and invertible, then $A^{-1} = R^{-1} Q^T$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$Q$ is square with $Q^TQ = I$, so $Q^{-1} = Q^T$; $R$ is triangular with positive diagonal, so it is invertible. Hence $A^{-1} = R^{-1}Q^{-1} = R^{-1}Q^T$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; If the columns of $A$ are already orthogonal (but not normalized), what does $R$ look like?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Every $r_{ij} = \langle a_j, q_i \rangle = 0$ for $i &amp;lt; j$, so $R$ is diagonal with $r_{jj} = \lVert a_j \rVert$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Prove that the QR factorization with positive diagonal in $R$ is unique.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

If $Q_1R_1 = Q_2R_2$, then $Q_2^TQ_1 = R_2R_1^{-1}$, and the right side is upper triangular. From $R_1^T Q_1^T Q_1 R_1 = A^T A = R_2^T R_2$, the matrix $M = R_2 R_1^{-1}$ satisfies $M^T M = I$. An upper triangular matrix with $M^TM = I$ and positive diagonal must be $I$ (compare columns one at a time). So $R_1 = R_2$ and $Q_1 = Q_2$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$A = QR$: $Q$ has orthonormal columns (from Gram–Schmidt), $R = Q^TA$ is upper triangular with $r_{ij} = \langle a_j, q_i \rangle$, $r_{jj} = \lVert v_j \rVert &amp;gt; 0$.&lt;/li&gt;
    &lt;li&gt;$Q$ gives an orthonormal basis of $\operatorname{Col} A$, with projection matrix $QQ^T$; $R$ gives the coordinates of the columns in that basis.&lt;/li&gt;
    &lt;li&gt;To solve $Ax = b$: $Rx = Q^Tb$ by back substitution.&lt;/li&gt;
    &lt;li&gt;QR underlies stable least squares (Chapter 08) and eigenvalue algorithms (Chapter 09).&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>The Gram–Schmidt Process</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter07/07_05_Qua_Trinh_Gram_Schmidt/"/>
   <updated>2026-01-07T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter07/07_05_Qua_Trinh_Gram_Schmidt</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;apply the Gram–Schmidt process to orthonormalize a basis of $\mathbb{R}^n$ or of a function space;&lt;/li&gt;
    &lt;li&gt;explain why the resulting vectors span the same subspaces $\operatorname{span}\{a_1, \dots, a_j\}$;&lt;/li&gt;
    &lt;li&gt;distinguish classical from modified Gram–Schmidt and know about loss of orthogonality on a computer.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Lessons 07-03 and 07-04 showed that orthonormal bases make everything simple: coordinates are inner products, and projections are sums of projections onto each vector. But subspaces usually come with a basis that is &lt;em&gt;not&lt;/em&gt; orthogonal, such as the plane spanned by $(1, 1, 0)$ and $(1, 0, 1)$. How do we “straighten” a basis into an orthonormal one spanning the same space? The idea: keep the first vector, then strip from each next vector the part lying along the directions already built.&lt;/p&gt;

&lt;h2 id=&quot;the-algorithm&quot;&gt;The algorithm&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Gram–Schmidt).&lt;/strong&gt; Let $a_1, \dots, a_k$ be linearly independent in an inner product space $V$. Set&lt;/p&gt;

\[v_1 = a_1, \qquad v_j = a_j - \sum_{i=1}^{j-1} \frac{\langle a_j, v_i \rangle}{\langle v_i, v_i \rangle}\, v_i \quad (j = 2, \dots, k),\]

  &lt;p&gt;and $q_j = v_j / \lVert v_j \rVert$. Then $q_1, \dots, q_k$ is orthonormal, and for every $j$,&lt;/p&gt;

  &lt;p&gt;\(\operatorname{span}\{q_1, \dots, q_j\} = \operatorname{span}\{a_1, \dots, a_j\}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Induction on $j$. Suppose $v_1, \dots, v_{j-1}$ are orthogonal, nonzero, and span $W_{j-1} = \operatorname{span}\{a_1, \dots, a_{j-1}\}$. By Lesson 07-04 the sum in the formula is $\operatorname{proj}_{W_{j-1}} a_j$, so $v_j = a_j - \operatorname{proj}_{W_{j-1}} a_j \in W_{j-1}^\perp$: $v_j$ is orthogonal to every $v_i$, $i &amp;lt; j$. If $v_j = 0$ then $a_j \in W_{j-1}$, contradicting independence. Finally $v_j$ is $a_j$ plus a vector of $W_{j-1}$, so $\operatorname{span}\{v_1, \dots, v_j\} = \operatorname{span}\{a_1, \dots, a_j\}$. Dividing by norms does not change spans.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Consequence: every finite-dimensional inner product space has an orthonormal basis (apply Gram–Schmidt to any basis).&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; Orthonormalize $a_1 = (1, 1, 0)$, $a_2 = (1, 0, 1)$, $a_3 = (0, 1, 1)$.&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;Step 1.&lt;/em&gt; $v_1 = (1, 1, 0)$, $q_1 = \tfrac{1}{\sqrt{2}}(1, 1, 0)$.&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;Step 2.&lt;/em&gt; $\langle a_2, q_1 \rangle = \tfrac{1}{\sqrt{2}}$, so $v_2 = (1, 0, 1) - \tfrac{1}{2}(1, 1, 0) = \left(\tfrac{1}{2}, -\tfrac{1}{2}, 1\right)$. Its norm is $\lVert v_2 \rVert = \sqrt{3/2}$, so $q_2 = \tfrac{1}{\sqrt{6}}(1, -1, 2)$.&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;Step 3.&lt;/em&gt; $\langle a_3, q_1 \rangle = \tfrac{1}{\sqrt{2}}$ and $\langle a_3, q_2 \rangle = \tfrac{1}{\sqrt{6}}$, so&lt;/p&gt;

\[v_3 = (0, 1, 1) - \tfrac{1}{2}(1, 1, 0) - \tfrac{1}{6}(1, -1, 2) = \left(-\tfrac{2}{3}, \tfrac{2}{3}, \tfrac{2}{3}\right), \qquad q_3 = \tfrac{1}{\sqrt{3}}(-1, 1, 1).\]

  &lt;p&gt;Check: $q_1 \cdot q_2 = \tfrac{1}{\sqrt{12}}(1 - 1 + 0) = 0$, $q_1 \cdot q_3 = \tfrac{1}{\sqrt{6}}(-1 + 1) = 0$, $q_2 \cdot q_3 = \tfrac{1}{\sqrt{18}}(-1 - 1 + 2) = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Hand-computation tip: you may rescale $v_j$ by a nonzero number before continuing (e.g. replace $v_2$ by $(1, -1, 2)$) to avoid fractions; orthogonality is unaffected.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (Legendre polynomials).&lt;/strong&gt; In the space of polynomials with $\langle p, q \rangle = \int_{-1}^1 p(x) q(x)\, dx$, apply Gram–Schmidt to $1, x, x^2$:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$v_1 = 1$;&lt;/li&gt;
    &lt;li&gt;$v_2 = x - \frac{\langle x, 1 \rangle}{\langle 1, 1 \rangle} \cdot 1 = x$, since $\int_{-1}^1 x\, dx = 0$;&lt;/li&gt;
    &lt;li&gt;$v_3 = x^2 - \frac{\langle x^2, 1 \rangle}{\langle 1, 1 \rangle} - \frac{\langle x^2, x \rangle}{\langle x, x \rangle} x = x^2 - \frac{2/3}{2} - 0 = x^2 - \tfrac{1}{3}$.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;The polynomials $1$, $x$, $x^2 - \tfrac{1}{3}$ are (up to scaling) the first three Legendre polynomials, used in Gaussian quadrature and physics.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;gramschmidt-on-a-computer&quot;&gt;Gram–Schmidt on a computer&lt;/h2&gt;

&lt;p&gt;The formula of Theorem 1 (&lt;em&gt;classical&lt;/em&gt; Gram–Schmidt) computes every coefficient $\langle a_j, q_i \rangle$ from the original vector $a_j$. In floating point, when the $a_j$ are nearly dependent, rounding errors make the computed $q_j$ far from orthogonal.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Modified&lt;/em&gt; Gram–Schmidt gives the same result in exact arithmetic, but subtracts one projection at a time and uses the &lt;em&gt;updated&lt;/em&gt; vector to compute the next coefficient:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;mgs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Q&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zeros&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;astype&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;# classical uses A[:, j] instead of v
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;Q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Q&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;On the $10 \times 10$ Hilbert matrix, the deviation $\max \lvert Q^TQ - I \rvert$ is about $1$ for classical Gram–Schmidt (orthogonality completely lost), about $10^{-5}$ for the modified version, and about $10^{-16}$ for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.qr&lt;/code&gt; (which uses Householder reflections, Lesson 07-07). In practice, use the library; Gram–Schmidt is for understanding and for hand computation.&lt;/p&gt;

&lt;h2 id=&quot;application-fourier-series&quot;&gt;Application: Fourier series&lt;/h2&gt;

&lt;p&gt;In $C[-\pi, \pi]$, the functions $1, \cos x, \sin x, \cos 2x, \sin 2x, \dots$ are already orthogonal (Exercise 4, Lesson 07-03), so no Gram–Schmidt is needed. The projection of $f$ onto the span of the first $N$ of them is the partial Fourier sum, with coefficients $\langle f, \cos kx \rangle / \langle \cos kx, \cos kx \rangle$. When a family of basis functions is &lt;em&gt;not&lt;/em&gt; orthogonal (for example $1, x, x^2, \dots$), Gram–Schmidt produces an orthogonal family such as the Legendre polynomials of Example 2.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: Gram–Schmidt step by step&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Press ▶ to subtract projections and normalize one vector at a time; the eᵢ·eⱼ table checks orthonormality.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter07/gram_schmidt.html?lang=en&quot; title=&quot;Interactive: Gram–Schmidt step by step&quot; loading=&quot;lazy&quot; style=&quot;height: 760px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter07/gram_schmidt.html?lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-gramschmidt-step-by-step&quot;&gt;Short video: Gram–Schmidt step by step&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/gram-schmidt-steps.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;a₁ = (1; 1; 0), a₂ = (1; 0; 1), a₃ = (0; 1; 1). Scale a₁ to get q₁; remove from a₂ its shadow on q₁ and scale, giving q₂; remove from a₃ its shadows on q₁ and q₂ and scale, giving q₃. The subtracted coefficients and the residual lengths fill the upper-triangular R: A = QR. Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Orthonormalize $(1, 1, 1)$, $(0, 1, 1)$, $(0, 0, 1)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$q_1 = \tfrac{1}{\sqrt{3}}(1, 1, 1)$. $v_2 = (0,1,1) - \tfrac{2}{3}(1,1,1) = \left(-\tfrac{2}{3}, \tfrac{1}{3}, \tfrac{1}{3}\right)$, $q_2 = \tfrac{1}{\sqrt{6}}(-2, 1, 1)$. $v_3 = (0,0,1) - \tfrac{1}{3}(1,1,1) - \tfrac{1}{6}(-2,1,1) = \left(0, -\tfrac{1}{2}, \tfrac{1}{2}\right)$, $q_3 = \tfrac{1}{\sqrt{2}}(0, -1, 1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Find an orthonormal basis of the plane $x_1 + x_2 + x_3 = 0$ in $\mathbb{R}^3$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Start from the basis $(1, -1, 0)$, $(1, 0, -1)$. $q_1 = \tfrac{1}{\sqrt{2}}(1, -1, 0)$; $v_2 = (1, 0, -1) - \tfrac{1}{2}(1, -1, 0) = \left(\tfrac{1}{2}, \tfrac{1}{2}, -1\right)$, $q_2 = \tfrac{1}{\sqrt{6}}(1, 1, -2)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; What happens if you apply Gram–Schmidt to $(1, 2)$, $(2, 4)$, and why?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$v_2 = (2, 4) - \tfrac{10}{5}(1, 2) = 0$, so you cannot divide by its norm. The vectors are dependent. In practice, $v_j = 0$ (or tiny) signals that $a_j$ lies in the span of the previous vectors, and $a_j$ is dropped.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; In $C[0, 1]$ with the integral inner product, orthogonalize $1, x$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$v_1 = 1$, $v_2 = x - \frac{\langle x, 1 \rangle}{\langle 1, 1 \rangle} = x - \tfrac{1}{2}$. Normalize: $\lVert x - \tfrac{1}{2} \rVert^2 = \int_0^1 (x - \tfrac12)^2 dx = \tfrac{1}{12}$, so $q_2 = \sqrt{12}\,(x - \tfrac{1}{2})$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (programming).&lt;/strong&gt; Compare classical Gram–Schmidt, modified Gram–Schmidt and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.qr&lt;/code&gt; on the $n \times n$ Hilbert matrix for $n = 6, 8, 10, 12$ using $\max \lvert Q^TQ - I \rvert$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The classical deviation grows very fast with $n$ (up to about $1$ at $n = 10$), the modified one grows in proportion to the condition number (about $10^{-5}$ at $n = 10$), and Householder in `numpy.linalg.qr` stays around $10^{-16}$ to $10^{-15}$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Gram–Schmidt: $v_j = a_j - \sum_{i&amp;lt;j} \operatorname{proj}_{v_i} a_j$, $q_j = v_j / \lVert v_j \rVert$; each step subtracts the projection onto the space built so far.&lt;/li&gt;
    &lt;li&gt;$\operatorname{span}\{q_1, \dots, q_j\} = \operatorname{span}\{a_1, \dots, a_j\}$ for every $j$; every finite-dimensional space has an orthonormal basis.&lt;/li&gt;
    &lt;li&gt;Getting $v_j = 0$ means $a_j$ depends on the previous vectors.&lt;/li&gt;
    &lt;li&gt;On a computer: classical loses orthogonality, modified is better, Householder is best.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Orthogonal Projection</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter07/07_04_Hinh_Chieu_Vuong_Goc/"/>
   <updated>2026-01-07T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter07/07_04_Hinh_Chieu_Vuong_Goc</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;compute the projection of a vector onto a line and onto a subspace;&lt;/li&gt;
    &lt;li&gt;decompose $x = \hat{x} + (x - \hat{x})$ with $\hat{x} \in W$ and $x - \hat{x} \in W^\perp$;&lt;/li&gt;
    &lt;li&gt;build a projection matrix, check $P^2 = P$, $P^T = P$, and use the best approximation theorem.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;A drone must reach the point $b = (6, 0, 0)$, but it may only fly in a plane $W$ through the origin spanned by $a_1 = (1, 1, 1)$ and $a_2 = (0, 1, 2)$. Which point of $W$ is closest to $b$? Geometric intuition: drop a perpendicular from $b$ to the plane. This lesson turns that intuition into formulas and shows it works in every inner product space. We will find the closest point to be $(5, 2, -1)$.&lt;/p&gt;

&lt;h2 id=&quot;projection-onto-a-line&quot;&gt;Projection onto a line&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Projection onto a line).&lt;/strong&gt; Let $a \ne 0$. The &lt;em&gt;projection&lt;/em&gt; of $x$ onto the line $\operatorname{span}\{a\}$ is&lt;/p&gt;

  &lt;p&gt;\(\operatorname{proj}_a x = \frac{\langle x, a \rangle}{\langle a, a \rangle}\, a.\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;This is the unique vector $ta$ on the line with $x - ta \perp a$: the condition $\langle x - ta, a \rangle = 0$ gives exactly $t = \langle x, a \rangle / \langle a, a \rangle$. For the dot product, the matrix of the projection is&lt;/p&gt;

\[P = \frac{a a^T}{a^T a},\]

&lt;p&gt;since $P x = a\, (a^T x) / (a^T a)$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; Project $x = (1, 2, 3)$ onto $a = (1, 1, 1)$: $\operatorname{proj}_a x = \tfrac{6}{3}(1, 1, 1) = (2, 2, 2)$. The remainder $x - (2, 2, 2) = (-1, 0, 1)$ is perpendicular to $a$. This remainder is the projection of $x$ onto the plane $x_1 + x_2 + x_3 = 0$, the orthogonal complement of the line.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;projection-onto-a-subspace&quot;&gt;Projection onto a subspace&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Orthogonal decomposition).&lt;/strong&gt; Let $W$ be a finite-dimensional subspace of an inner product space $V$. Every $x \in V$ can be written uniquely as&lt;/p&gt;

\[x = \hat{x} + z, \qquad \hat{x} \in W,\ z \in W^\perp.\]

  &lt;p&gt;If $u_1, \dots, u_k$ is an orthogonal basis of $W$, then&lt;/p&gt;

  &lt;p&gt;\(\hat{x} = \operatorname{proj}_W x = \sum_{i=1}^k \frac{\langle x, u_i \rangle}{\langle u_i, u_i \rangle}\, u_i.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Define $\hat{x}$ by the formula and $z = x - \hat{x}$. For each $j$, since the $u_i$ are orthogonal, $\langle z, u_j \rangle = \langle x, u_j \rangle - \frac{\langle x, u_j \rangle}{\langle u_j, u_j \rangle} \langle u_j, u_j \rangle = 0$, so $z \in W^\perp$. Uniqueness: if $\hat{x} + z = \hat{x}&apos; + z&apos;$, then $\hat{x} - \hat{x}&apos; = z&apos; - z$ lies in $W \cap W^\perp = \{0\}$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Caution: the sum formula holds only for an &lt;em&gt;orthogonal&lt;/em&gt; basis. For a general basis, use the matrix formula below.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2 (Projection matrix).&lt;/strong&gt; Let $A$ be an $m \times k$ matrix with linearly independent columns and $W = \operatorname{Col} A \subseteq \mathbb{R}^m$. Then $A^T A$ is invertible, and&lt;/p&gt;

\[\operatorname{proj}_W b = A \hat{c}, \quad \text{where } A^T A\, \hat{c} = A^T b, \qquad P = A (A^T A)^{-1} A^T.\]

  &lt;p&gt;The matrix $P$ satisfies $P^2 = P$ and $P^T = P$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; $A^T A$ is invertible because $\operatorname{Null}(A^T A) = \operatorname{Null} A = \{0\}$ (Exercise 5, Lesson 07-03). The projection has the form $A\hat{c}$, and the remainder $b - A\hat{c}$ is perpendicular to every column of $A$, i.e. $A^T(b - A\hat{c}) = 0$. Solving gives $\hat{c} = (A^T A)^{-1} A^T b$. Finally $P^2 = A (A^TA)^{-1} A^T A (A^TA)^{-1} A^T = P$, and $P^T = P$ because $(A^T A)^{-1}$ is symmetric.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (the motivating example).&lt;/strong&gt; With $A = \begin{bmatrix} 1 &amp;amp; 0 \\ 1 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$ and $b = (6, 0, 0)$:&lt;/p&gt;

\[A^T A = \begin{bmatrix} 3 &amp;amp; 3 \\ 3 &amp;amp; 5 \end{bmatrix}, \qquad A^T b = \begin{bmatrix} 6 \\ 0 \end{bmatrix}.\]

  &lt;p&gt;Solving $3c_1 + 3c_2 = 6$, $3c_1 + 5c_2 = 0$ gives $c_2 = -3$, $c_1 = 5$. The projection is $\hat{b} = 5(1,1,1) - 3(0,1,2) = (5, 2, -1)$, with remainder $b - \hat{b} = (1, -2, 1)$. Check: $(1,-2,1) \cdot (1,1,1) = 0$ and $(1,-2,1) \cdot (0,1,2) = 0$. The projection matrix is&lt;/p&gt;

  &lt;p&gt;\(P = \frac{1}{6} \begin{bmatrix} 5 &amp;amp; 2 &amp;amp; -1 \\ 2 &amp;amp; 2 &amp;amp; 2 \\ -1 &amp;amp; 2 &amp;amp; 5 \end{bmatrix}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Also, $I - P$ is the projection onto $W^\perp$: here $W^\perp = \operatorname{span}\{(1, -2, 1)\}$ and $I - P = \tfrac{1}{6}(1,-2,1)(1,-2,1)^T$.&lt;/p&gt;

&lt;h2 id=&quot;the-projection-is-the-closest-point&quot;&gt;The projection is the closest point&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 3 (Best approximation).&lt;/strong&gt; With $W$ and $\hat{x} = \operatorname{proj}_W x$ as in Theorem 1, for every $w \in W$ other than $\hat{x}$:&lt;/p&gt;

  &lt;p&gt;\(\lVert x - \hat{x} \rVert &amp;lt; \lVert x - w \rVert.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Write $x - w = (x - \hat{x}) + (\hat{x} - w)$. The first term lies in $W^\perp$ and the second in $W$, so they are orthogonal. By Pythagoras, $\lVert x - w \rVert^2 = \lVert x - \hat{x} \rVert^2 + \lVert \hat{x} - w \rVert^2 &amp;gt; \lVert x - \hat{x} \rVert^2$ when $w \ne \hat{x}$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Theorem 3 is the basis of Chapter 08: when $Ax = b$ has no solution, we replace $b$ by the closest point $\hat{b} \in \operatorname{Col} A$, and the equation $A^T A \hat{c} = A^T b$ of Theorem 2 is exactly the &lt;em&gt;normal equation&lt;/em&gt;.&lt;/p&gt;

&lt;h2 id=&quot;application-approximating-functions&quot;&gt;Application: approximating functions&lt;/h2&gt;

&lt;p&gt;In $C[0, 1]$, find the linear function $a + bx$ closest to $f(x) = x^2$ in the integral norm, i.e. the projection of $x^2$ onto $W = \operatorname{span}\{1, x\}$. Requiring the remainder to be orthogonal to $1$ and $x$ gives&lt;/p&gt;

\[\begin{bmatrix} \langle 1, 1 \rangle &amp;amp; \langle x, 1 \rangle \\ \langle 1, x \rangle &amp;amp; \langle x, x \rangle \end{bmatrix} \begin{bmatrix} a \\ b \end{bmatrix} = \begin{bmatrix} \langle x^2, 1 \rangle \\ \langle x^2, x \rangle \end{bmatrix}, \quad\text{i.e.}\quad \begin{bmatrix} 1 &amp;amp; 1/2 \\ 1/2 &amp;amp; 1/3 \end{bmatrix} \begin{bmatrix} a \\ b \end{bmatrix} = \begin{bmatrix} 1/3 \\ 1/4 \end{bmatrix}.\]

&lt;p&gt;The solution is $a = -1/6$, $b = 1$: the line $x - \tfrac{1}{6}$ is the best mean-square approximation of $x^2$ on $[0, 1]$. The same idea gives Fourier series in analysis.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: orthogonal projection in ℝ³&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag y: ŷ is the closest point of W to y, and the residual z is perpendicular to W.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter07/hinh_chieu_3d.html?mode=plane&amp;amp;lang=en&quot; title=&quot;Interactive: orthogonal projection in ℝ³&quot; loading=&quot;lazy&quot; style=&quot;height: 720px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter07/hinh_chieu_3d.html?mode=plane&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-the-projection-is-the-closest-point&quot;&gt;Short video: The projection is the closest point&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/projection-3d.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;The plane C(A) with a₁ = (1; 0; 1), a₂ = (0; 1; 0), and the point b = (0; 1; 2) off it. Let p run over the plane: |b − p| is smallest, √2 ≈ 1.41, at p = (1; 1; 1), exactly where b − p is perpendicular to both columns, so AᵀA x̂ = Aᵀb. Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Compute the projection of $(1, 2, 3)$ onto the plane $x + y + z = 0$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The plane is the orthogonal complement of $n = (1, 1, 1)$. Subtract the component along $n$: $(1,2,3) - \tfrac{6}{3}(1,1,1) = (-1, 0, 1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Find the matrix of projection onto the line through $a = (1, 2)$ in $\mathbb{R}^2$, and project $x = (3, 1)$ onto it.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$P = \tfrac{1}{5}\begin{bmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 4 \end{bmatrix}$ (matching Lesson 06-05). $Px = \tfrac{1}{5}(5, 10) = (1, 2)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Project $x = (1, 1, 1, 1)$ onto $W = \operatorname{span}\{(1, 1, 0, 0), (0, 0, 1, -1)\}$ in $\mathbb{R}^4$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The two vectors are already orthogonal. $\hat{x} = \tfrac{2}{2}(1,1,0,0) + \tfrac{0}{2}(0,0,1,-1) = (1, 1, 0, 0)$. The remainder $(0, 0, 1, 1)$ is perpendicular to both.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Prove: if $P$ is a symmetric matrix with $P^2 = P$, then $Px \perp x - Px$ for every $x$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$(Px)^T (x - Px) = x^T P^T x - x^T P^T P x = x^T P x - x^T P^2 x = x^T P x - x^T P x = 0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Let $P$ be the projection matrix onto a subspace $W$ with $\dim W = k$ in $\mathbb{R}^n$. Prove $\operatorname{tr} P = k$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Choose an orthonormal basis $u_1, \dots, u_k$ of $W$ and let $Q = [u_1 \cdots u_k]$. Then $Q^T Q = I_k$ and $P = Q(Q^TQ)^{-1}Q^T = QQ^T$. So $\operatorname{tr} P = \operatorname{tr}(QQ^T) = \operatorname{tr}(Q^TQ) = \operatorname{tr} I_k = k$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Projection onto a line: $\operatorname{proj}_a x = \dfrac{\langle x, a \rangle}{\langle a, a \rangle} a$, with matrix $aa^T / a^Ta$.&lt;/li&gt;
    &lt;li&gt;Every $x$ decomposes uniquely as $x = \hat{x} + z$ with $\hat{x} \in W$, $z \in W^\perp$; in an orthogonal basis, $\hat{x}$ is the sum of the projections onto each vector.&lt;/li&gt;
    &lt;li&gt;Onto $\operatorname{Col} A$: solve $A^T A \hat{c} = A^T b$; $P = A(A^TA)^{-1}A^T$, $P^2 = P = P^T$.&lt;/li&gt;
    &lt;li&gt;$\hat{x}$ is the point of $W$ closest to $x$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Orthogonal Sets and Orthogonal Complements</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter07/07_03_Ho_Truc_Giao_Va_Phan_Bu_Truc_Giao/"/>
   <updated>2026-01-07T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter07/07_03_Ho_Truc_Giao_Va_Phan_Bu_Truc_Giao</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;prove that an orthogonal set of nonzero vectors is linearly independent;&lt;/li&gt;
    &lt;li&gt;find coordinates in an orthogonal basis by inner products, without solving a system;&lt;/li&gt;
    &lt;li&gt;find the orthogonal complement $W^\perp$ of a subspace and use $(\operatorname{Row} A)^\perp = \operatorname{Null} A$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Write $x = (3, 1, 2)$ in the basis $u_1 = (1, 1, 0)$, $u_2 = (1, -1, 0)$, $u_3 = (0, 0, 1)$. The Chapter 05 method is to solve a $3 \times 3$ system. But these vectors are pairwise perpendicular, and there is a much faster way: dot both sides of $x = c_1 u_1 + c_2 u_2 + c_3 u_3$ with $u_1$. Every term containing $u_2$ or $u_3$ vanishes:&lt;/p&gt;

\[x \cdot u_1 = c_1\, u_1 \cdot u_1 \quad\Longrightarrow\quad c_1 = \frac{4}{2} = 2.\]

&lt;p&gt;Likewise $c_2 = 2/2 = 1$ and $c_3 = 2/1 = 2$. Check: $2(1,1,0) + (1,-1,0) + 2(0,0,1) = (3,1,2)$.&lt;/p&gt;

&lt;h2 id=&quot;orthogonal-sets&quot;&gt;Orthogonal sets&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Orthogonal, orthonormal).&lt;/strong&gt; A set of vectors $u_1, \dots, u_k$ is &lt;em&gt;orthogonal&lt;/em&gt; if $\langle u_i, u_j \rangle = 0$ for all $i \ne j$. It is &lt;em&gt;orthonormal&lt;/em&gt; if in addition every $\lVert u_i \rVert = 1$. A basis that is an orthogonal (orthonormal) set is an &lt;em&gt;orthogonal&lt;/em&gt; (&lt;em&gt;orthonormal&lt;/em&gt;) &lt;em&gt;basis&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; An orthogonal set of nonzero vectors is linearly independent.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Suppose $c_1 u_1 + \dots + c_k u_k = 0$. Take the inner product with $u_j$: every term $c_i \langle u_i, u_j \rangle$ with $i \ne j$ is $0$, leaving $c_j \lVert u_j \rVert^2 = 0$. Since $u_j \ne 0$, $c_j = 0$, for every $j$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2 (Coordinates in an orthogonal basis).&lt;/strong&gt; If $u_1, \dots, u_n$ is an orthogonal basis of $V$, then for every $x \in V$,&lt;/p&gt;

\[x = \sum_{i=1}^n \frac{\langle x, u_i \rangle}{\langle u_i, u_i \rangle}\, u_i.\]

  &lt;p&gt;If the basis is orthonormal, $x = \sum_i \langle x, u_i \rangle\, u_i$ and $\lVert x \rVert^2 = \sum_i \langle x, u_i \rangle^2$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Write $x = \sum c_i u_i$ and take the inner product with $u_j$ as in the motivating example: $\langle x, u_j \rangle = c_j \langle u_j, u_j \rangle$. For an orthonormal basis, Pythagoras applied to the orthogonal vectors $c_i u_i$ gives $\lVert x \rVert^2 = \sum c_i^2$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;In an orthonormal basis, “finding coordinates” is just $n$ inner products, and lengths are computed as in ordinary $\mathbb{R}^n$. That is why we want orthonormal bases; Lesson 07-05 shows how to build one from any basis.&lt;/p&gt;

&lt;h2 id=&quot;orthogonal-complements&quot;&gt;Orthogonal complements&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 2 (Orthogonal complement).&lt;/strong&gt; Let $W$ be a subspace of an inner product space $V$. The &lt;em&gt;orthogonal complement&lt;/em&gt; of $W$ is&lt;/p&gt;

  &lt;p&gt;\(W^\perp = \{v \in V : \langle v, w \rangle = 0 \text{ for all } w \in W\}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 3.&lt;/strong&gt; Let $W$ be a subspace of $V$.&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$W^\perp$ is a subspace of $V$, and $W \cap W^\perp = \{0\}$.&lt;/li&gt;
    &lt;li&gt;If $W = \operatorname{span}\{w_1, \dots, w_k\}$, then $v \in W^\perp$ if and only if $\langle v, w_i \rangle = 0$ for all $i$.&lt;/li&gt;
    &lt;li&gt;If $V$ is finite-dimensional, $\dim W + \dim W^\perp = \dim V$ and $(W^\perp)^\perp = W$.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof (sketch).&lt;/strong&gt; (1) The inner product is linear in $v$, so $W^\perp$ is closed under addition and scaling. If $v \in W \cap W^\perp$ then $\langle v, v \rangle = 0$, so $v = 0$. (2) Every $w \in W$ is a combination of the $w_i$, and the inner product is linear. (3) In $\mathbb{R}^n$, put the $w_i$ as rows of a matrix $A$; by (2), $W^\perp = \operatorname{Null} A$, and rank–nullity gives $\dim W^\perp = n - \operatorname{rank} A = n - \dim W$. The general case reduces to $\mathbb{R}^n$ via an orthonormal basis (Lesson 07-05). Finally $W \subseteq (W^\perp)^\perp$ and both have the same dimension.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 4 (The four fundamental subspaces).&lt;/strong&gt; For an $m \times n$ matrix $A$:&lt;/p&gt;

  &lt;p&gt;\((\operatorname{Row} A)^\perp = \operatorname{Null} A \ \text{ in } \mathbb{R}^n, \qquad (\operatorname{Col} A)^\perp = \operatorname{Null} A^T \ \text{ in } \mathbb{R}^m.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; $Ax = 0$ means that the dot product of $x$ with every row of $A$ is $0$, i.e. $x \perp \operatorname{Row} A$ by Theorem 3(2). Applying this to $A^T$, whose rows are the columns of $A$, gives the second identity.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Theorem 4 completes the picture of Lesson 05-04: not only is $\dim \operatorname{Row} A + \dim \operatorname{Null} A = n$, the two subspaces are &lt;em&gt;perpendicular&lt;/em&gt; and together fill $\mathbb{R}^n$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; Let $W = \operatorname{span}\{(1, 1, 1)\}$ in $\mathbb{R}^3$. Then $W^\perp = \{x : x_1 + x_2 + x_3 = 0\}$, a plane through the origin with basis $(1, -1, 0)$, $(1, 0, -1)$. And $\dim W + \dim W^\perp = 1 + 2 = 3$.&lt;/p&gt;

  &lt;p&gt;Let $A = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 &amp;amp; 1 \\ 2 &amp;amp; 4 &amp;amp; 1 &amp;amp; 3 \\ 3 &amp;amp; 6 &amp;amp; 1 &amp;amp; 4 \end{bmatrix}$ (Lesson 05-04). Its left null space is $\operatorname{Null} A^T = \operatorname{span}\{(-1, -1, 1)\}$. Indeed, column 1 is $(1, 2, 3)$ and $-1 - 2 + 3 = 0$; column 3 is $(0, 1, 1)$ and $0 - 1 + 1 = 0$. So $(-1, -1, 1) \perp \operatorname{Col} A$, and $Ax = b$ is solvable if and only if $-b_1 - b_2 + b_3 = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-solvability-conditions&quot;&gt;Application: solvability conditions&lt;/h2&gt;

&lt;p&gt;Theorem 4 gives a test for solvability of $Ax = b$: $b \in \operatorname{Col} A$ if and only if $b \perp \operatorname{Null} A^T$, i.e. $y^T b = 0$ for every $y$ with $A^T y = 0$. In an electrical network (Lesson 05-05), $\operatorname{Null} A^T$ corresponds to closed loops, and this condition is Kirchhoff’s voltage law: the voltage drops around each loop sum to $0$. This is a simple form of the &lt;em&gt;Fredholm alternative&lt;/em&gt;.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: the orthogonal complement W⊥&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Orbit the view: if W is a line then W⊥ is the perpendicular plane, and vice versa.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter07/hinh_chieu_3d.html?mode=line&amp;amp;lang=en&quot; title=&quot;Interactive: the orthogonal complement W⊥&quot; loading=&quot;lazy&quot; style=&quot;height: 720px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter07/hinh_chieu_3d.html?mode=line&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Check that $u_1 = (1, 2, 2)$, $u_2 = (2, 1, -2)$, $u_3 = (2, -2, 1)$ are pairwise orthogonal, and write $x = (9, 0, 9)$ in this basis.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$u_1 \cdot u_2 = 2 + 2 - 4 = 0$, $u_1 \cdot u_3 = 2 - 4 + 2 = 0$, $u_2 \cdot u_3 = 4 - 2 - 2 = 0$, and every $\lVert u_i \rVert^2 = 9$. Coefficients: $c_1 = 27/9 = 3$, $c_2 = 0/9 = 0$, $c_3 = 27/9 = 3$. So $x = 3u_1 + 3u_3$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Find a basis of $W^\perp$ for $W = \operatorname{span}\{(1, 0, 1, 0), (0, 1, 0, 1)\}$ in $\mathbb{R}^4$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$W^\perp$ is the solution set of $x_1 + x_3 = 0$, $x_2 + x_4 = 0$: basis $(-1, 0, 1, 0)$, $(0, -1, 0, 1)$. Dimensions $2 + 2 = 4$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Prove: if $W_1 \subseteq W_2$ then $W_2^\perp \subseteq W_1^\perp$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

If $v$ is orthogonal to every vector of $W_2$, it is orthogonal to every vector of the smaller set $W_1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; In $C[-\pi, \pi]$ with $\langle f, g \rangle = \int_{-\pi}^{\pi} fg$, check that $1, \cos x, \sin x$ are pairwise orthogonal and compute their norms.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\int_{-\pi}^{\pi} \cos x\, dx = \int_{-\pi}^{\pi} \sin x\, dx = 0$, and $\int_{-\pi}^{\pi} \sin x \cos x\, dx = \tfrac{1}{2}\int_{-\pi}^{\pi} \sin 2x\, dx = 0$. Norms: $\lVert 1 \rVert = \sqrt{2\pi}$, $\lVert \cos x \rVert = \lVert \sin x \rVert = \sqrt{\pi}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Let $A$ be $m \times n$. Prove $\operatorname{Null}(A^T A) = \operatorname{Null} A$, and deduce $\operatorname{rank}(A^T A) = \operatorname{rank} A$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

If $Ax = 0$ then $A^T A x = 0$. Conversely, if $A^T A x = 0$ then $0 = x^T A^T A x = \lVert Ax \rVert^2$, so $Ax = 0$. Both matrices have $n$ columns and the same null space, so by rank–nullity they have the same rank. This is used in Chapter 08.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;An orthogonal set of nonzero vectors is linearly independent.&lt;/li&gt;
    &lt;li&gt;In an orthogonal basis: $x = \sum_i \dfrac{\langle x, u_i \rangle}{\langle u_i, u_i \rangle} u_i$; in an orthonormal basis the coefficients are $\langle x, u_i \rangle$.&lt;/li&gt;
    &lt;li&gt;$W^\perp$ is a subspace, $\dim W + \dim W^\perp = \dim V$, $(W^\perp)^\perp = W$.&lt;/li&gt;
    &lt;li&gt;$(\operatorname{Row} A)^\perp = \operatorname{Null} A$ and $(\operatorname{Col} A)^\perp = \operatorname{Null} A^T$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>The Cauchy–Schwarz Inequality and Angles</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter07/07_02_Bat_Dang_Thuc_Cauchy_Schwarz_Va_Goc/"/>
   <updated>2026-01-07T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter07/07_02_Bat_Dang_Thuc_Cauchy_Schwarz_Va_Goc</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;state and prove the Cauchy–Schwarz inequality, including the equality case;&lt;/li&gt;
    &lt;li&gt;derive the triangle inequality;&lt;/li&gt;
    &lt;li&gt;define and compute the angle between two vectors or two functions, and use cosine similarity.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;In $\mathbb{R}^2$ we know $u \cdot v = \lVert u \rVert \lVert v \rVert \cos\theta$ (Chapter 01), so $\lvert u \cdot v \rvert \le \lVert u \rVert \lVert v \rVert$ because $\lvert \cos\theta \rvert \le 1$. But for the inner product $\langle f, g \rangle = \int_0^1 f g$ on functions, “the angle between two functions” has no meaning yet. We go the other way: prove the inequality from the axioms alone, then &lt;em&gt;use&lt;/em&gt; it to define angles.&lt;/p&gt;

&lt;h2 id=&quot;the-cauchyschwarz-inequality&quot;&gt;The Cauchy–Schwarz inequality&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Cauchy–Schwarz).&lt;/strong&gt; In every inner product space, for all $u, v$:&lt;/p&gt;

\[\lvert \langle u, v \rangle \rvert \le \lVert u \rVert\, \lVert v \rVert.\]

  &lt;p&gt;Equality holds if and only if $u$ and $v$ are linearly dependent.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; If $v = 0$ both sides are $0$. Assume $v \ne 0$. For every $t \in \mathbb{R}$,&lt;/p&gt;

\[0 \le \lVert u - tv \rVert^2 = \lVert u \rVert^2 - 2t\langle u, v \rangle + t^2 \lVert v \rVert^2.\]

  &lt;p&gt;Choosing $t = \langle u, v \rangle / \lVert v \rVert^2$ (the minimizer of the right side) gives&lt;/p&gt;

\[0 \le \lVert u \rVert^2 - \frac{\langle u, v \rangle^2}{\lVert v \rVert^2},\]

  &lt;p&gt;that is, $\langle u, v \rangle^2 \le \lVert u \rVert^2 \lVert v \rVert^2$. Equality holds exactly when $\lVert u - tv \rVert = 0$, i.e. $u = tv$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The value $t = \langle u, v \rangle / \lVert v \rVert^2$ in the proof is no accident: $tv$ is the projection of $u$ onto the line through $v$ (Lesson 07-04), and the inequality just says “the remainder $u - tv$ has nonnegative length”.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; For the dot product on $\mathbb{R}^n$, Cauchy–Schwarz reads&lt;/p&gt;

\[(u_1 v_1 + \dots + u_n v_n)^2 \le (u_1^2 + \dots + u_n^2)(v_1^2 + \dots + v_n^2).\]

  &lt;p&gt;For the integral inner product on $C[a, b]$ it reads&lt;/p&gt;

\[\left( \int_a^b f g \right)^2 \le \int_a^b f^2 \cdot \int_a^b g^2.\]

  &lt;p&gt;One proof gives both inequalities, although one is about finite sums and the other about integrals.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;the-triangle-inequality&quot;&gt;The triangle inequality&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2 (Triangle inequality).&lt;/strong&gt; For all $u, v$: $\lVert u + v \rVert \le \lVert u \rVert + \lVert v \rVert$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; By Cauchy–Schwarz,
$\lVert u + v \rVert^2 = \lVert u \rVert^2 + 2\langle u, v \rangle + \lVert v \rVert^2 \le \lVert u \rVert^2 + 2\lVert u \rVert \lVert v \rVert + \lVert v \rVert^2 = (\lVert u \rVert + \lVert v \rVert)^2$.
Take square roots.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;For distances: $d(u, w) \le d(u, v) + d(v, w)$. The straight path is the shortest, in every inner product space.&lt;/p&gt;

&lt;h2 id=&quot;angles-and-orthogonality&quot;&gt;Angles and orthogonality&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Angle, orthogonality).&lt;/strong&gt; For $u, v \ne 0$, Cauchy–Schwarz gives $-1 \le \dfrac{\langle u, v \rangle}{\lVert u \rVert \lVert v \rVert} \le 1$. The &lt;em&gt;angle&lt;/em&gt; between $u$ and $v$ is the number $\theta \in [0, \pi]$ with&lt;/p&gt;

\[\cos\theta = \frac{\langle u, v \rangle}{\lVert u \rVert\, \lVert v \rVert}.\]

  &lt;p&gt;Vectors $u, v$ (possibly zero) are &lt;em&gt;orthogonal&lt;/em&gt;, written $u \perp v$, if $\langle u, v \rangle = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 3 (Pythagoras).&lt;/strong&gt; If $u \perp v$ then $\lVert u + v \rVert^2 = \lVert u \rVert^2 + \lVert v \rVert^2$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Expand $\lVert u + v \rVert^2 = \lVert u \rVert^2 + 2\langle u, v \rangle + \lVert v \rVert^2$ and use $\langle u, v \rangle = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; The angle between $u = (1, 0, 1)$ and $v = (0, 1, 1)$ in $\mathbb{R}^3$: $u \cdot v = 1$, $\lVert u \rVert = \lVert v \rVert = \sqrt{2}$, so $\cos\theta = 1/2$ and $\theta = \pi/3$.&lt;/p&gt;

  &lt;p&gt;The angle between $f(x) = 1$ and $g(x) = x$ in $C[0, 1]$: by Lesson 07-01, $\langle 1, x \rangle = \tfrac{1}{2}$, $\lVert 1 \rVert = 1$, $\lVert x \rVert = 1/\sqrt{3}$. So $\cos\theta = \tfrac{1}{2} \cdot \sqrt{3} = \tfrac{\sqrt{3}}{2}$ and $\theta = \pi/6$.&lt;/p&gt;

  &lt;p&gt;On $C[-\pi, \pi]$, $\langle \sin x, \cos x \rangle = \int_{-\pi}^{\pi} \sin x \cos x\, dx = 0$: these functions are orthogonal. This is the basis of Fourier series.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-cosine-similarity&quot;&gt;Application: cosine similarity&lt;/h2&gt;

&lt;p&gt;In text search, each document is represented by a word-count vector $d \in \mathbb{R}^N$, where $N$ is the vocabulary size. Two documents on the same topic have vectors pointing “the same way”, even if one is ten times longer. So they are compared by &lt;em&gt;cosine similarity&lt;/em&gt; $\cos\theta = \dfrac{d_1 \cdot d_2}{\lVert d_1 \rVert \lVert d_2 \rVert}$ rather than distance: scaling a vector by a positive number does not change the cosine. Modern semantic search does exactly this with embedding vectors produced by neural networks.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: the Cauchy–Schwarz inequality&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;The ratio ∣u·v∣ / (‖u‖‖v‖) never exceeds 1, and equals 1 exactly when u, v are parallel.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter01/vecto_2d.html?mode=cs&amp;amp;lang=en&quot; title=&quot;Interactive: the Cauchy–Schwarz inequality&quot; loading=&quot;lazy&quot; style=&quot;height: 620px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter01/vecto_2d.html?mode=cs&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Compute the angle between $(1, 2, 2)$ and $(2, -1, 2)$, and between $(1, 1)$ and $(1, -1)$ for the inner product of Example 2 in Lesson 07-01.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$(1,2,2) \cdot (2,-1,2) = 2 - 2 + 4 = 4$ and both norms are 3, so $\cos\theta = 4/9$, $\theta \approx 63.6^\circ$. With $M = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$: $\langle (1,1), (1,-1) \rangle = 2 - 1 + 1 - 1 = 1$, $\lVert (1,1) \rVert = \sqrt{5}$, $\lVert (1,-1) \rVert^2 = 2 - 1 - 1 + 1 = 1$. So $\cos\theta = 1/\sqrt{5}$, $\theta \approx 63.4^\circ$, not $90^\circ$ as with the dot product.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Prove the Cauchy–Schwarz inequality for $\langle f, g \rangle = \int_0^1 f g$, then use it to show $\left(\int_0^1 f\right)^2 \le \int_0^1 f^2$ for every continuous $f$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The proof of Theorem 1 uses only the axioms, so it applies verbatim: consider $0 \le \int_0^1 (f - tg)^2$ and choose $t = \int fg / \int g^2$. With $g = 1$: $\left(\int_0^1 f \cdot 1\right)^2 \le \int_0^1 f^2 \cdot \int_0^1 1 = \int_0^1 f^2$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; For $a, b, c &amp;gt; 0$, prove $(a + b + c)\left(\tfrac{1}{a} + \tfrac{1}{b} + \tfrac{1}{c}\right) \ge 9$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Apply Cauchy–Schwarz to $u = (\sqrt{a}, \sqrt{b}, \sqrt{c})$ and $v = (1/\sqrt{a}, 1/\sqrt{b}, 1/\sqrt{c})$: $(u \cdot v)^2 = 9 \le \lVert u \rVert^2 \lVert v \rVert^2$, which is the claim. Equality when $a = b = c$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Prove: if $u \perp v$ then $\lVert u - v \rVert = \lVert u + v \rVert$. Explain with a rectangle.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\lVert u \pm v \rVert^2 = \lVert u \rVert^2 \pm 2\langle u, v \rangle + \lVert v \rVert^2 = \lVert u \rVert^2 + \lVert v \rVert^2$. The parallelogram on perpendicular $u, v$ is a rectangle, and the diagonals $u + v$, $u - v$ of a rectangle are equal.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Prove $\lvert \lVert u \rVert - \lVert v \rVert \rvert \le \lVert u - v \rVert$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The triangle inequality for $u = (u - v) + v$ gives $\lVert u \rVert - \lVert v \rVert \le \lVert u - v \rVert$. Swapping $u$ and $v$ gives $\lVert v \rVert - \lVert u \rVert \le \lVert u - v \rVert$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Cauchy–Schwarz: $\lvert \langle u, v \rangle \rvert \le \lVert u \rVert \lVert v \rVert$, with equality when $u$, $v$ are parallel; proved from $\lVert u - tv \rVert^2 \ge 0$.&lt;/li&gt;
    &lt;li&gt;Consequence: the triangle inequality $\lVert u + v \rVert \le \lVert u \rVert + \lVert v \rVert$.&lt;/li&gt;
    &lt;li&gt;Angle: $\cos\theta = \langle u, v \rangle / (\lVert u \rVert \lVert v \rVert)$; orthogonal when $\langle u, v \rangle = 0$; Pythagoras holds for orthogonal vectors.&lt;/li&gt;
    &lt;li&gt;Cosine similarity compares directions and ignores lengths.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>General Inner Products and Norms</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter07/07_01_Tich_Vo_Huong_Tong_Quat_Va_Chuan/"/>
   <updated>2026-01-07T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter07/07_01_Tich_Vo_Huong_Tong_Quat_Va_Chuan</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;check whether a form $\langle \cdot, \cdot \rangle$ is an inner product using the axioms;&lt;/li&gt;
    &lt;li&gt;compute norms and distances for a given inner product, including weighted and integral inner products;&lt;/li&gt;
    &lt;li&gt;write an inner product on $\mathbb{R}^n$ in the form $u^T M v$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;A shop records two quantities per product: price (millions of dong) and mass (kg). Products $u = (2, 10)$ and $v = (3, 10)$ are at Euclidean distance $\lVert u - v \rVert = 1$. If mass is recorded in grams instead, the same products become $(2, 10000)$ and $(3, 10000)$ and the distance is still 1; but two products differing by 1 kg now have distance 1000 instead of 1. “Distance” depends on how we weigh the components.&lt;/p&gt;

&lt;p&gt;A general inner product lets us choose that weighting while keeping the basic geometric properties. It also lets us measure “angles” and “lengths” of objects that are not arrows, such as functions.&lt;/p&gt;

&lt;h2 id=&quot;definition&quot;&gt;Definition&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Inner product).&lt;/strong&gt; Let $V$ be a real vector space. An &lt;em&gt;inner product&lt;/em&gt; on $V$ assigns to each pair $u, v \in V$ a real number $\langle u, v \rangle$ such that for all $u, v, w \in V$ and $c \in \mathbb{R}$:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;&lt;em&gt;symmetry&lt;/em&gt;: $\langle u, v \rangle = \langle v, u \rangle$;&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;linearity in the first argument&lt;/em&gt;: $\langle u + w, v \rangle = \langle u, v \rangle + \langle w, v \rangle$ and $\langle cu, v \rangle = c\langle u, v \rangle$;&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;positive definiteness&lt;/em&gt;: $\langle v, v \rangle \ge 0$, and $\langle v, v \rangle = 0$ only when $v = 0$.&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;A space $V$ with an inner product is an &lt;em&gt;inner product space&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Symmetry plus linearity in the first argument give linearity in the second as well. The usual dot product $u \cdot v = u_1 v_1 + \dots + u_n v_n$ on $\mathbb{R}^n$ (Chapter 01) satisfies all three axioms.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 2 (Norm and distance).&lt;/strong&gt; In an inner product space, the &lt;em&gt;norm&lt;/em&gt; (length) of $v$ is $\lVert v \rVert = \sqrt{\langle v, v \rangle}$, and the &lt;em&gt;distance&lt;/em&gt; between $u$ and $v$ is $d(u, v) = \lVert u - v \rVert$. A vector of norm 1 is a &lt;em&gt;unit vector&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The norm satisfies $\lVert cv \rVert = \lvert c \rvert\, \lVert v \rVert$, and $\lVert v \rVert = 0$ only when $v = 0$. The triangle inequality $\lVert u + v \rVert \le \lVert u \rVert + \lVert v \rVert$ needs Cauchy–Schwarz and is proved in Lesson 07-02.&lt;/p&gt;

&lt;h2 id=&quot;inner-products-on-mathbbrn-of-the-form-ut-m-v&quot;&gt;Inner products on $\mathbb{R}^n$ of the form $u^T M v$&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (weighted inner product).&lt;/strong&gt; For numbers $w_1, \dots, w_n &amp;gt; 0$,&lt;/p&gt;

\[\langle u, v \rangle = w_1 u_1 v_1 + \dots + w_n u_n v_n\]

  &lt;p&gt;is an inner product on $\mathbb{R}^n$: symmetry and linearity are clear, and $\langle v, v \rangle = \sum w_i v_i^2 \ge 0$, with equality only when every $v_i = 0$. The weight $w_i$ says how much component $i$ “matters”, just as in the motivating example.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;More generally, for a symmetric $n \times n$ matrix $M$, set $\langle u, v \rangle_M = u^T M v$. Symmetry and linearity always hold; axiom 3 holds exactly when $v^T M v &amp;gt; 0$ for every $v \ne 0$. Such a matrix is called &lt;em&gt;positive definite&lt;/em&gt; and is studied in Chapter 10.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; On $\mathbb{R}^2$, consider&lt;/p&gt;

\[\langle u, v \rangle = 2u_1 v_1 + u_1 v_2 + u_2 v_1 + u_2 v_2 = u^T \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix} v.\]

  &lt;p&gt;Then $\langle v, v \rangle = 2v_1^2 + 2v_1 v_2 + v_2^2 = v_1^2 + (v_1 + v_2)^2$, which is $\ge 0$ and equals $0$ only when $v_1 = 0$ and $v_1 + v_2 = 0$, i.e. $v = 0$. So this is an inner product. Under it, $\lVert e_1 \rVert = \sqrt{2}$, $\lVert e_2 \rVert = 1$ and $\langle e_1, e_2 \rangle = 1 \ne 0$: the standard basis vectors are no longer perpendicular.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3 (not inner products).&lt;/strong&gt; The formula $\langle u, v \rangle = u_1 v_1 - u_2 v_2$ is symmetric and linear, but $\langle e_2, e_2 \rangle = -1 &amp;lt; 0$, violating axiom 3. Nor is $\langle u, v \rangle = u_1 v_1$: $\langle e_2, e_2 \rangle = 0$ although $e_2 \ne 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;inner-products-on-function-spaces&quot;&gt;Inner products on function spaces&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 4.&lt;/strong&gt; On the space $C[a, b]$ of continuous functions on $[a, b]$, set&lt;/p&gt;

\[\langle f, g \rangle = \int_a^b f(x)\, g(x)\, dx.\]

  &lt;p&gt;Symmetry and linearity follow from properties of the integral. For axiom 3: $\langle f, f \rangle = \int_a^b f(x)^2\, dx \ge 0$, and if a continuous $f$ is nonzero at some point, then $f^2 &amp;gt; 0$ on a small interval around it, so the integral is positive. This is an inner product.&lt;/p&gt;

  &lt;p&gt;On $[0, 1]$: $\langle 1, x \rangle = \int_0^1 x\, dx = \tfrac{1}{2}$, $\lVert x \rVert^2 = \int_0^1 x^2\, dx = \tfrac{1}{3}$, and the distance between $f(x) = 1$ and $g(x) = x$ is&lt;/p&gt;

  &lt;p&gt;\(\lVert 1 - x \rVert = \sqrt{\int_0^1 (1 - x)^2\, dx} = \frac{1}{\sqrt{3}}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;This distance measures the “root mean square” discrepancy between the functions, unlike the maximum discrepancy $\max \lvert f - g \rvert = 1$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Parallelogram law).&lt;/strong&gt; In every inner product space,&lt;/p&gt;

  &lt;p&gt;\(\lVert u + v \rVert^2 + \lVert u - v \rVert^2 = 2\lVert u \rVert^2 + 2\lVert v \rVert^2.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Expand by linearity: $\lVert u \pm v \rVert^2 = \langle u \pm v, u \pm v \rangle = \lVert u \rVert^2 \pm 2\langle u, v \rangle + \lVert v \rVert^2$. Adding the two identities cancels the terms $\pm 2\langle u, v \rangle$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Consequently the inner product can be recovered from the norm via $\langle u, v \rangle = \tfrac{1}{4}\left(\lVert u + v \rVert^2 - \lVert u - v \rVert^2\right)$. The “max” norm $\max_i \lvert v_i \rvert$ fails the parallelogram law (try $u = e_1$, $v = e_2$), so it does not come from any inner product.&lt;/p&gt;

&lt;h2 id=&quot;application-mahalanobis-distance&quot;&gt;Application: Mahalanobis distance&lt;/h2&gt;

&lt;p&gt;In statistics, when features have different standard deviations and are correlated, Euclidean distance misjudges how “unusual” a point is. The Mahalanobis distance uses the inner product $\langle u, v \rangle = u^T \Sigma^{-1} v$, where $\Sigma$ is the covariance matrix. When the features are independent it is the weighted inner product with $w_i = 1/\sigma_i^2$: each component is measured in units of its own standard deviation, which resolves the units problem of the motivating example.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: inner product, norm and angle&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag u and v: u·v, ‖u‖, cos θ and the projection update live.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter01/vecto_2d.html?mode=dot&amp;amp;lang=en&quot; title=&quot;Interactive: inner product, norm and angle&quot; loading=&quot;lazy&quot; style=&quot;height: 620px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter01/vecto_2d.html?mode=dot&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; With the inner product of Example 2, compute $\lVert (1, 1) \rVert$ and $\langle (1, 0), (1, -2) \rangle$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\langle (1,1), (1,1) \rangle = 2 + 1 + 1 + 1 = 5$, so $\lVert (1, 1) \rVert = \sqrt{5}$. $\langle (1,0), (1,-2) \rangle = 2 \cdot 1 \cdot 1 + 1 \cdot (-2) + 0 + 0 = 0$: these two vectors are perpendicular for the new inner product.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; For which $k$ is $\langle u, v \rangle = u_1 v_1 + k u_2 v_2$ an inner product on $\mathbb{R}^2$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

For $k &amp;gt; 0$. If $k \le 0$ then $\langle e_2, e_2 \rangle = k \le 0$ although $e_2 \ne 0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; In $C[0, 1]$ with the integral inner product, compute $\lVert x^2 \rVert$ and $\langle x, x^2 \rangle$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\lVert x^2 \rVert^2 = \int_0^1 x^4\, dx = \tfrac{1}{5}$, so $\lVert x^2 \rVert = 1/\sqrt{5}$. $\langle x, x^2 \rangle = \int_0^1 x^3\, dx = \tfrac{1}{4}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Check that $\langle A, B \rangle = \operatorname{tr}(A^T B)$ is an inner product on the space of $m \times n$ matrices, and that its norm is $\sqrt{\sum_{i,j} a_{ij}^2}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\operatorname{tr}(A^T B) = \sum_{i,j} a_{ij} b_{ij}$, which is the dot product after stacking the entries into one long vector of length $mn$. So the axioms hold, and $\langle A, A \rangle = \sum a_{ij}^2$. This norm is the Frobenius norm.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Prove that the norm $\lVert v \rVert_1 = \lvert v_1 \rvert + \lvert v_2 \rvert$ on $\mathbb{R}^2$ does not come from any inner product.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

With $u = e_1$, $v = e_2$: $\lVert u + v \rVert_1^2 + \lVert u - v \rVert_1^2 = 4 + 4 = 8$, while $2\lVert u \rVert_1^2 + 2\lVert v \rVert_1^2 = 4$. The parallelogram law fails, so by Theorem 1 no inner product produces this norm.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Inner product: symmetric, linear, positive definite. Norm $\lVert v \rVert = \sqrt{\langle v, v \rangle}$, distance $\lVert u - v \rVert$.&lt;/li&gt;
    &lt;li&gt;On $\mathbb{R}^n$: $\langle u, v \rangle = u^T M v$ with $M$ symmetric positive definite; weighted inner products are a special case.&lt;/li&gt;
    &lt;li&gt;On continuous functions: $\langle f, g \rangle = \int_a^b f g$.&lt;/li&gt;
    &lt;li&gt;A norm coming from an inner product satisfies the parallelogram law.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Các phép biến đổi hình học trong ℝ² và ℝ³</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter06/06_06_Cac_Phep_Bien_Doi_Hinh_Hoc/"/>
   <updated>2026-01-06T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter06/06_06_Cac_Phep_Bien_Doi_Hinh_Hoc</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;viết ma trận của phép quay, phản xạ qua đường thẳng, co giãn, trượt và chiếu trong $\mathbb{R}^2$;&lt;/li&gt;
    &lt;li&gt;viết ma trận của phép quay quanh trục toạ độ, phép chiếu và phản xạ qua mặt phẳng trong $\mathbb{R}^3$;&lt;/li&gt;
    &lt;li&gt;nhận ra loại phép biến đổi từ định thức và từ $A^2$;&lt;/li&gt;
    &lt;li&gt;dùng toạ độ thuần nhất để biểu diễn phép tịnh tiến bằng ma trận.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Ở Bài 6.2, phép “quay $60^\circ$ rồi phản xạ qua $y = x$” có ma trận $\begin{bmatrix} \sqrt3/2 &amp;amp; 1/2 \\ 1/2 &amp;amp; -\sqrt3/2 \end{bmatrix}$ với định thức $-1$. Nó giữ độ dài và lật hình. Có phải nó là một phép phản xạ qua đường thẳng nào đó? Bài này cho công thức chung của phép phản xạ qua đường thẳng làm góc $\theta$ với trục $x$, và ta sẽ thấy câu trả lời là có, với $\theta = 15^\circ$.&lt;/p&gt;

&lt;h2 id=&quot;trong-mặt-phẳng&quot;&gt;Trong mặt phẳng&lt;/h2&gt;

&lt;p&gt;Mỗi ma trận dưới đây được viết bằng cách hỏi: $e_1$ và $e_2$ đi đâu (Bài 6.2).&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Các phép biến đổi cơ bản của $\mathbb{R}^2$).&lt;/strong&gt;&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;
      &lt;p&gt;Quay góc $\theta$:&lt;/p&gt;

\[R_\theta = \begin{bmatrix} \cos\theta &amp;amp; -\sin\theta \\ \sin\theta &amp;amp; \cos\theta \end{bmatrix}, \qquad \det R_\theta = 1\]
    &lt;/li&gt;
    &lt;li&gt;
      &lt;p&gt;Phản xạ qua đường thẳng qua gốc làm góc $\theta$ với trục $x$:&lt;/p&gt;

\[H_\theta = \begin{bmatrix} \cos 2\theta &amp;amp; \sin 2\theta \\ \sin 2\theta &amp;amp; -\cos 2\theta \end{bmatrix}, \qquad \det H_\theta = -1\]
    &lt;/li&gt;
    &lt;li&gt;
      &lt;p&gt;Co giãn theo hai trục:&lt;/p&gt;

\[\begin{bmatrix} a &amp;amp; 0 \\ 0 &amp;amp; b \end{bmatrix}, \qquad \det = ab\]
    &lt;/li&gt;
    &lt;li&gt;
      &lt;p&gt;Trượt ngang hệ số $k$:&lt;/p&gt;

\[\begin{bmatrix} 1 &amp;amp; k \\ 0 &amp;amp; 1 \end{bmatrix}, \qquad \det = 1\]
    &lt;/li&gt;
    &lt;li&gt;
      &lt;p&gt;Chiếu vuông góc lên đường thẳng theo vectơ đơn vị $u$:&lt;/p&gt;

\[uu^T, \qquad \det = 0\]
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Quay: $e_1 \mapsto (\cos\theta, \sin\theta)$, $e_2$ đi tới vectơ vuông góc tiếp theo $(-\sin\theta, \cos\theta)$. Chiếu: hình chiếu của $x$ lên hướng $u$ là $(u \cdot x) u = u(u^T x) = (uu^T) x$ (Bài 1.2). Phản xạ: điểm phản xạ $x&apos;$ thoả $x&apos; = 2p - x$ với $p = uu^T x$ là hình chiếu, nên $H = 2uu^T - I$. Với $u = (\cos\theta, \sin\theta)$:&lt;/p&gt;

\[2uu^T - I = \begin{bmatrix} 2\cos^2\theta - 1 &amp;amp; 2\sin\theta\cos\theta \\ 2\sin\theta\cos\theta &amp;amp; 2\sin^2\theta - 1 \end{bmatrix} = \begin{bmatrix} \cos 2\theta &amp;amp; \sin 2\theta \\ \sin 2\theta &amp;amp; -\cos 2\theta \end{bmatrix} .\]

  &lt;p&gt;Co giãn và trượt: đọc trực tiếp ảnh của $e_1, e_2$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Trả lời ví dụ mở đầu: cần $\cos 2\theta = \tfrac{\sqrt3}{2}$, $\sin 2\theta = \tfrac12$, tức $2\theta = 30^\circ$. Vậy “quay $60^\circ$ rồi phản xạ qua $y = x$” chính là phản xạ qua đường thẳng làm góc $15^\circ$ với trục $x$. Tổng quát hơn, $H_\beta H_\alpha = R_{2(\beta - \alpha)}$: hai lần phản xạ cho một phép quay (Bài tập 4), và $H_\beta R_\alpha$ lại là một phép phản xạ.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; Chiếu lên đường $y = 2x$: $u = \tfrac{1}{\sqrt5}(1, 2)$, $uu^T = \tfrac15 \begin{bmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 4 \end{bmatrix}$, khớp với Ví dụ 2 Bài 6.5. Phản xạ: $2uu^T - I = \tfrac15 \begin{bmatrix} -3 &amp;amp; 4 \\ 4 &amp;amp; 3 \end{bmatrix}$, khớp với Ví dụ 3 Bài 6.5. Hai cách (công thức và đổi cơ sở) cho cùng kết quả.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Nhận biết nhanh: phép chiếu có $A^2 = A$ (chiếu hai lần như một lần); phép phản xạ có $A^2 = I$; phép quay và phản xạ có $A^TA = I$ (giữ độ dài), phân biệt bằng dấu định thức.&lt;/p&gt;

&lt;h2 id=&quot;trong-không-gian&quot;&gt;Trong không gian&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3 (quay quanh trục $z$).&lt;/strong&gt; Quay góc $\theta$ quanh trục $z$ giữ nguyên $e_3$ và quay mặt phẳng $xy$:&lt;/p&gt;

\[R_z(\theta) = \begin{bmatrix} \cos\theta &amp;amp; -\sin\theta &amp;amp; 0 \\ \sin\theta &amp;amp; \cos\theta &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix} .\]

  &lt;p&gt;Quay quanh trục $x$ hay $y$ viết tương tự, đặt khối $2 \times 2$ vào hai toạ độ còn lại.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Với mặt phẳng qua gốc có pháp tuyến đơn vị $n$, phần của $x$ dọc theo $n$ là $(nn^T)x$. Bỏ phần đó đi được phép chiếu lên mặt phẳng, $I - nn^T$; trừ hai lần được phép phản xạ, $I - 2nn^T$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 4.&lt;/strong&gt; Mặt phẳng $x + y + z = 0$, $n = \tfrac{1}{\sqrt3}(1, 1, 1)$, $nn^T = \tfrac13 J$ với $J$ là ma trận toàn số 1:&lt;/p&gt;

\[\text{Chiếu: } I - \tfrac13 J = \frac13 \begin{bmatrix} 2 &amp;amp; -1 &amp;amp; -1 \\ -1 &amp;amp; 2 &amp;amp; -1 \\ -1 &amp;amp; -1 &amp;amp; 2 \end{bmatrix}, \qquad \text{Phản xạ: } I - \tfrac23 J = \frac13 \begin{bmatrix} 1 &amp;amp; -2 &amp;amp; -2 \\ -2 &amp;amp; 1 &amp;amp; -2 \\ -2 &amp;amp; -2 &amp;amp; 1 \end{bmatrix} .\]

  &lt;p&gt;Kiểm tra: phép chiếu đưa $(1, 1, 1)$ về 0 và giữ $(1, -1, 0)$. Hạng của phép chiếu là 2: ảnh là mặt phẳng, hạt nhân là đường pháp tuyến.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-toạ-độ-thuần-nhất-trong-đồ-hoạ&quot;&gt;Ứng dụng: toạ độ thuần nhất trong đồ hoạ&lt;/h2&gt;

&lt;p&gt;Tịnh tiến $x \mapsto x + t$ không tuyến tính (Bài 6.1), nhưng đồ hoạ máy tính cần nó liên tục. Mẹo: ghi điểm $(x, y)$ thành $(x, y, 1)$ trong $\mathbb{R}^3$. Khi đó&lt;/p&gt;

\[\begin{bmatrix} 1 &amp;amp; 0 &amp;amp; t_1 \\ 0 &amp;amp; 1 &amp;amp; t_2 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} = \begin{bmatrix} x + t_1 \\ y + t_2 \\ 1 \end{bmatrix} .\]

&lt;p&gt;Tịnh tiến $(2, 5)$ theo $(3, -1)$ cho $(5, 4)$. Giờ quay, co giãn và tịnh tiến đều là ma trận $3 \times 3$, ghép với nhau bằng phép nhân. Trong 3D người ta dùng ma trận $4 \times 4$ theo cùng cách; đây là nền tảng của mọi engine đồ hoạ (Chương 12).&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: các phép biến đổi hình học&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Chọn ma trận mẫu và kéo t từ 0 tới 1 để xem quay, đối xứng, trượt, chiếu, co giãn.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=map&quot; title=&quot;Minh hoạ: các phép biến đổi hình học&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=map&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-quay-phản-xạ-trượt-chiếu-qua-ảnh-của-cơ-sở&quot;&gt;Video ngắn: Quay, phản xạ, trượt, chiếu qua ảnh của cơ sở&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/basis-images-columns.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Phần các phép biến đổi hình học, xem từ 0:30: quay 30° cho cột (cos 30°; sin 30°) và (−sin 30°; cos 30°), phản xạ qua y = x đổi chỗ e₁ và e₂, trượt ngang đưa e₂ tới (1; 1), chiếu lên trục x ép e₂ về 0. Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Viết ma trận phép quay $60^\circ$ rồi phản xạ qua đường $y = x$, tìm hạt nhân và ảnh của nó.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\begin{bmatrix} \sqrt3/2 &amp;amp; 1/2 \\ 1/2 &amp;amp; -\sqrt3/2 \end{bmatrix}$ (phản xạ qua đường góc $15^\circ$). Hạt nhân $\{0\}$, ảnh $\mathbb{R}^2$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Viết ma trận phép quay $90^\circ$ quanh trục $x$ trong $\mathbb{R}^3$ và tính ảnh của $(1, 2, 3)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; -1 \\ 0 &amp;amp; 1 &amp;amp; 0 \end{bmatrix}$; ảnh $(1, -3, 2)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Tìm ma trận của phép chiếu vuông góc lên mặt phẳng $x + y + z = 0$ và kiểm tra $A^2 = A$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\tfrac13 \begin{bmatrix} 2 &amp;amp; -1 &amp;amp; -1 \\ -1 &amp;amp; 2 &amp;amp; -1 \\ -1 &amp;amp; -1 &amp;amp; 2 \end{bmatrix}$ (Ví dụ 4). $(I - nn^T)^2 = I - 2nn^T + n(n^Tn)n^T = I - nn^T$ vì $n^Tn = 1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Chứng minh $H_\beta H_\alpha = R_{2(\beta - \alpha)}$. Cho ví dụ hình học.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Nhân hai ma trận và dùng công thức cộng: phần tử $(1, 1)$ là $\cos 2\beta \cos 2\alpha + \sin 2\beta \sin 2\alpha = \cos 2(\beta - \alpha)$, tương tự cho các phần tử khác. Phản xạ qua trục $x$ rồi qua đường $y = x$ là quay $90^\circ$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (lập trình).&lt;/strong&gt; Viết hàm Python trả về ma trận $3 \times 3$ thuần nhất của “quay góc $\theta$ quanh điểm $c$” (tịnh tiến $c$ về gốc, quay, tịnh tiến lại). Kiểm tra: điểm $c$ đứng yên.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$M = T(c)\, R(\theta)\, T(-c)$ với $T(c)$ là ma trận tịnh tiến. $M(c_1, c_2, 1) = (c_1, c_2, 1)$ vì $T(-c)$ đưa $c$ về gốc, phép quay giữ gốc.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$\mathbb{R}^2$: quay $R_\theta$ ($\det 1$), phản xạ $H_\theta = 2uu^T - I$ ($\det -1$), co giãn, trượt ($\det 1$), chiếu $uu^T$ ($\det 0$).&lt;/li&gt;
    &lt;li&gt;$\mathbb{R}^3$: quay quanh trục toạ độ là khối $2 \times 2$ cộng một số 1; chiếu và phản xạ qua mặt phẳng: $I - nn^T$, $I - 2nn^T$.&lt;/li&gt;
    &lt;li&gt;Chiếu: $A^2 = A$; phản xạ: $A^2 = I$; quay và phản xạ giữ độ dài.&lt;/li&gt;
    &lt;li&gt;Toạ độ thuần nhất biến tịnh tiến thành phép nhân ma trận.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Ma trận trong các cơ sở khác nhau và ma trận đồng dạng</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter06/06_05_Ma_Tran_Dong_Dang/"/>
   <updated>2026-01-06T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter06/06_05_Ma_Tran_Dong_Dang</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;tính ma trận của một toán tử trong cơ sở mới bằng công thức $[T]_B = P^{-1} A P$;&lt;/li&gt;
    &lt;li&gt;đi ngược lại: dựng ma trận chính tắc từ ma trận trong một cơ sở “tốt”;&lt;/li&gt;
    &lt;li&gt;chứng minh ma trận đồng dạng có cùng định thức, vết và hạng;&lt;/li&gt;
    &lt;li&gt;giải thích vì sao chọn cơ sở hợp lý làm ma trận đơn giản hơn.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Ma trận $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$ làm gì với mặt phẳng? Nhìn các cột thì khó nói. Nhưng thử với hai vectơ đặc biệt: $A(1, 1) = (3, 3) = 3(1, 1)$ và $A(1, -1) = (1, -1)$. Vậy $A$ kéo giãn gấp 3 theo đường chéo $y = x$ và giữ nguyên đường chéo $y = -x$. Trong cơ sở $B = \{(1, 1), (1, -1)\}$, ánh xạ này chỉ là&lt;/p&gt;

\[[T]_B = \begin{bmatrix} 3 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix} .\]

&lt;p&gt;Cùng một phép biến đổi, nhưng chọn đúng hệ trục thì ma trận gần như không còn gì để tính.&lt;/p&gt;

&lt;h2 id=&quot;công-thức-đổi-cơ-sở-cho-toán-tử&quot;&gt;Công thức đổi cơ sở cho toán tử&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Cho $T : \mathbb{R}^n \to \mathbb{R}^n$ có ma trận chính tắc $A$, và $B = \{b_1, \dots, b_n\}$ là một cơ sở. Đặt $P = [b_1\ \cdots\ b_n]$. Khi đó&lt;/p&gt;

\[[T]_B = P^{-1} A P, \qquad A = P\, [T]_B\, P^{-1} .\]

  &lt;p&gt;Tổng quát hơn, với toán tử $T$ trên $V$ và hai cơ sở $B, C$: $[T]_B = P^{-1} [T]_C P$ với $P = P_{C \leftarrow B}$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Viết $T = \operatorname{id} \circ T \circ \operatorname{id}$ và áp dụng Định lý 1 Bài 6.4 với các cơ sở $B \to C \to C \to B$:&lt;/p&gt;

\[[T]_{B \leftarrow B} = [\operatorname{id}]_{B \leftarrow C}\, [T]_{C \leftarrow C}\, [\operatorname{id}]_{C \leftarrow B} = P_{B \leftarrow C}\, [T]_C\, P_{C \leftarrow B} = P^{-1} [T]_C P,\]

  &lt;p&gt;vì $P_{B \leftarrow C} = (P_{C \leftarrow B})^{-1}$ (Bài 5.6). Với $C$ là cơ sở chuẩn, $P_{C \leftarrow B}$ là ma trận có cột $b_i$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Đọc từ phải sang trái: $P$ đổi toạ độ theo $B$ sang toạ độ chuẩn, $A$ thực hiện phép biến đổi, $P^{-1}$ đổi về toạ độ theo $B$.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Ma trận đồng dạng).&lt;/strong&gt; Hai ma trận vuông $A$, $A&apos;$ cùng cấp gọi là &lt;em&gt;đồng dạng&lt;/em&gt; nếu có $P$ khả nghịch với $A&apos; = P^{-1} A P$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Theo Định lý 1, hai ma trận đồng dạng là hai ma trận của &lt;em&gt;cùng một&lt;/em&gt; toán tử trong hai cơ sở.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2.&lt;/strong&gt; Nếu $A$ và $A&apos;$ đồng dạng thì $\det A&apos; = \det A$, $\operatorname{tr} A&apos; = \operatorname{tr} A$ và $\operatorname{rank} A&apos; = \operatorname{rank} A$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Định thức: Hệ quả 1 Bài 4.5. Vết: với mọi $X, Y$ cùng cấp, $\operatorname{tr}(XY) = \sum_{i,k} x_{ik} y_{ki} = \operatorname{tr}(YX)$; lấy $X = P^{-1}$, $Y = AP$ được $\operatorname{tr}(P^{-1}AP) = \operatorname{tr}(APP^{-1}) = \operatorname{tr} A$. Hạng: $A$ và $A&apos;$ là ma trận của cùng một toán tử $T$, và hạng bằng $\dim \operatorname{im} T$, không phụ thuộc cơ sở.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Những đại lượng không đổi khi đổi cơ sở là thuộc tính của &lt;em&gt;phép biến đổi&lt;/em&gt;, không phải của cách ghi toạ độ. Định thức là hệ số co giãn thể tích, nên đương nhiên không phụ thuộc hệ trục.&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ&quot;&gt;Ví dụ&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Với $A$ ở ví dụ mở đầu và $P = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix}$, $P^{-1} = \tfrac12 \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix}$:&lt;/p&gt;

\[P^{-1} A P = \tfrac12 \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix} \begin{bmatrix} 3 &amp;amp; 1 \\ 3 &amp;amp; -1 \end{bmatrix} = \begin{bmatrix} 3 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix} .\]

  &lt;p&gt;Kiểm tra Định lý 2: $\det = 3$ và $\operatorname{tr} = 4$ ở cả hai ma trận.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (phép chiếu lên đường thẳng).&lt;/strong&gt; Tìm ma trận chính tắc của phép chiếu vuông góc lên đường $y = 2x$. Chọn cơ sở tốt: $b_1 = (1, 2)$ nằm trên đường (giữ nguyên), $b_2 = (-2, 1)$ vuông góc với đường (bị đưa về 0). Vậy $[T]_B = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix}$ và, với $P = \begin{bmatrix} 1 &amp;amp; -2 \\ 2 &amp;amp; 1 \end{bmatrix}$, $P^{-1} = \tfrac15 \begin{bmatrix} 1 &amp;amp; 2 \\ -2 &amp;amp; 1 \end{bmatrix}$:&lt;/p&gt;

\[A = P \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix} P^{-1} = \frac15 \begin{bmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 4 \end{bmatrix} .\]

  &lt;p&gt;Kiểm tra: $A(1, 2) = (1, 2)$, $A(-2, 1) = (0, 0)$, $\det A = 0$, $\operatorname{tr} A = 1$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3 (phép phản xạ).&lt;/strong&gt; Phản xạ qua cùng đường $y = 2x$: giữ $b_1$, đổi dấu $b_2$, nên $[T]_B = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; -1 \end{bmatrix}$ và&lt;/p&gt;

\[A = P \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; -1 \end{bmatrix} P^{-1} = \frac15 \begin{bmatrix} -3 &amp;amp; 4 \\ 4 &amp;amp; 3 \end{bmatrix} .\]

  &lt;p&gt;$\det A = -1$ (lật định hướng), $\operatorname{tr} A = 0$, đúng với $\operatorname{diag}(1, -1)$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-chọn-hệ-trục-phù-hợp-với-bài-toán&quot;&gt;Ứng dụng: chọn hệ trục phù hợp với bài toán&lt;/h2&gt;

&lt;p&gt;Kỹ sư phân tích ứng suất trong một tấm thép không dùng trục $x, y$ cố định, mà tìm các &lt;em&gt;trục chính&lt;/em&gt;, nơi ma trận ứng suất có dạng đường chéo: theo các hướng đó vật liệu chỉ bị kéo hoặc nén, không bị cắt. Trong thống kê, PCA (Chương 11) chọn hệ trục theo các hướng dữ liệu biến thiên nhiều nhất. Cả hai đều là bài toán tìm cơ sở $B$ sao cho $P^{-1}AP$ là ma trận đường chéo, như ví dụ mở đầu. Các vectơ $(1, 1)$ và $(1, -1)$ ở đó gọi là &lt;em&gt;vectơ riêng&lt;/em&gt;, các số 3 và 1 là &lt;em&gt;trị riêng&lt;/em&gt;; Chương 9 dạy cách tìm chúng một cách hệ thống.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: ma trận đồng dạng P⁻¹AP&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Cùng một phép biến đổi viết trong cơ sở {p₁, p₂}; vết và định thức không đổi.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=similar&quot; title=&quot;Minh hoạ: ma trận đồng dạng P⁻¹AP&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=similar&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Cho $A = \begin{bmatrix} 4 &amp;amp; 1 \\ 2 &amp;amp; 3 \end{bmatrix}$ và $B = \{(1, 1), (1, -2)\}$. Tính $[T]_B = P^{-1}AP$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A(1, 1) = (5, 5)$, $A(1, -2) = (2, -4)$. Vậy $[T]_B = \begin{bmatrix} 5 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Hai ma trận $\begin{bmatrix} 1 &amp;amp; 2 \\ 0 &amp;amp; 3 \end{bmatrix}$ và $\begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{bmatrix}$ có đồng dạng không?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Không: vết đều bằng 4 nhưng định thức là 3 và 4. (Ngoài ra $P^{-1}(2I)P = 2I$ với mọi $P$.)

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Tìm ma trận chính tắc của phép chiếu vuông góc lên đường $y = x$ và của phép phản xạ qua đường đó.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Chiếu: $\tfrac12 \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$. Phản xạ: $\begin{bmatrix} 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix}$ (khớp Bài 6.2).

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Chứng minh: nếu $A&apos; = P^{-1} A P$ thì $A&apos;^k = P^{-1} A^k P$. Dùng Ví dụ 1 để tính $A^{5}$ với $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Các cặp $PP^{-1}$ ở giữa triệt tiêu. $A^5 = P \operatorname{diag}(243, 1) P^{-1} = \begin{bmatrix} 122 &amp;amp; 121 \\ 121 &amp;amp; 122 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Chứng minh ma trận phép chiếu ở Ví dụ 2 thoả $A^2 = A$, còn ma trận phản xạ ở Ví dụ 3 thoả $A^2 = I$, chỉ bằng cách nhìn $[T]_B$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\operatorname{diag}(1, 0)^2 = \operatorname{diag}(1, 0)$ và $\operatorname{diag}(1, -1)^2 = I$; dùng Bài tập 4 với $k = 2$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Trong cơ sở $B$ (cột của $P$): $[T]_B = P^{-1} A P$, và $A = P [T]_B P^{-1}$.&lt;/li&gt;
    &lt;li&gt;Ma trận đồng dạng là ma trận của cùng một toán tử trong hai cơ sở; chúng có cùng định thức, vết, hạng.&lt;/li&gt;
    &lt;li&gt;Chọn cơ sở phù hợp (hướng được giữ, hướng bị triệt tiêu) làm ma trận thành đường chéo; đây là ý tưởng của chéo hoá ở Chương 9.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Hợp, nghịch đảo và đẳng cấu</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter06/06_04_Hop_Nghich_Dao_Va_Dang_Cau/"/>
   <updated>2026-01-06T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter06/06_04_Hop_Nghich_Dao_Va_Dang_Cau</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;tính ma trận của hợp hai ánh xạ tuyến tính bằng tích ma trận;&lt;/li&gt;
    &lt;li&gt;kiểm tra một ánh xạ tuyến tính có khả nghịch và tìm ánh xạ ngược;&lt;/li&gt;
    &lt;li&gt;định nghĩa đẳng cấu và chứng minh hai không gian hữu hạn chiều đẳng cấu khi và chỉ khi cùng số chiều;&lt;/li&gt;
    &lt;li&gt;dùng đẳng cấu toạ độ để chuyển bài toán về $\mathbb{R}^n$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Quay mặt phẳng góc $\alpha$ rồi quay tiếp góc $\beta$ thì được phép quay góc $\alpha + \beta$. Viết bằng ma trận:&lt;/p&gt;

\[R_\beta R_\alpha = \begin{bmatrix} \cos\beta &amp;amp; -\sin\beta \\ \sin\beta &amp;amp; \cos\beta \end{bmatrix} \begin{bmatrix} \cos\alpha &amp;amp; -\sin\alpha \\ \sin\alpha &amp;amp; \cos\alpha \end{bmatrix} = \begin{bmatrix} \cos(\alpha + \beta) &amp;amp; -\sin(\alpha + \beta) \\ \sin(\alpha + \beta) &amp;amp; \cos(\alpha + \beta) \end{bmatrix} .\]

&lt;p&gt;So sánh phần tử góc trên trái: $\cos(\alpha + \beta) = \cos\beta\cos\alpha - \sin\beta\sin\alpha$. Công thức cộng lượng giác hoá ra chỉ là phép nhân hai ma trận quay. Và quay góc $-\alpha$ thì hoàn tác phép quay góc $\alpha$: $R_{-\alpha} = R_\alpha^{-1}$.&lt;/p&gt;

&lt;h2 id=&quot;hợp-của-hai-ánh-xạ&quot;&gt;Hợp của hai ánh xạ&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Nếu $T : U \to V$ và $S : V \to W$ tuyến tính thì $S \circ T$ tuyến tính, và với các cơ sở $B, C, D$ của $U, V, W$:&lt;/p&gt;

  &lt;p&gt;\([S \circ T]_{D \leftarrow B} = [S]_{D \leftarrow C}\, [T]_{C \leftarrow B} .\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; $S(T(au + bv)) = S(aT(u) + bT(v)) = aS(T(u)) + bS(T(v))$. Với mọi $u$, theo Định lý 2 Bài 6.2: $[S(T(u))]_D = [S]_{D \leftarrow C} [T(u)]_C = [S]_{D \leftarrow C} [T]_{C \leftarrow B} [u]_B$. Ma trận của $S \circ T$ được xác định duy nhất bởi đẳng thức này với mọi $[u]_B$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Đây là lý do phép nhân ma trận được định nghĩa như ở Bài 3.1: nó mã hoá phép hợp ánh xạ. Tính kết hợp $(AB)C = A(BC)$ cũng là hiển nhiên khi nhìn bằng hợp ánh xạ.&lt;/p&gt;

&lt;h2 id=&quot;ánh-xạ-khả-nghịch-và-đẳng-cấu&quot;&gt;Ánh xạ khả nghịch và đẳng cấu&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1.&lt;/strong&gt; Ánh xạ tuyến tính $T : V \to W$ là &lt;em&gt;khả nghịch&lt;/em&gt; nếu có ánh xạ $T^{-1} : W \to V$ với $T^{-1} \circ T = \operatorname{id}_V$ và $T \circ T^{-1} = \operatorname{id}_W$. Một ánh xạ tuyến tính khả nghịch gọi là một &lt;em&gt;đẳng cấu&lt;/em&gt;. Nếu có đẳng cấu từ $V$ sang $W$, ta nói $V$ và $W$ &lt;em&gt;đẳng cấu&lt;/em&gt;, viết $V \cong W$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2.&lt;/strong&gt;&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$T$ khả nghịch khi và chỉ khi $T$ là song ánh; khi đó $T^{-1}$ cũng tuyến tính.&lt;/li&gt;
    &lt;li&gt;Với $\dim V = \dim W = n$ và các cơ sở $B, C$: $T$ khả nghịch $\iff [T]_{C \leftarrow B}$ khả nghịch, và $[T^{-1}]_{B \leftarrow C} = ([T]_{C \leftarrow B})^{-1}$.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; (1) Song ánh thì có ánh xạ ngược (theo nghĩa tập hợp). Nó tuyến tính: với $w_1 = T(v_1)$, $w_2 = T(v_2)$, ta có $T(av_1 + bv_2) = aw_1 + bw_2$, nên $T^{-1}(aw_1 + bw_2) = av_1 + bv_2 = aT^{-1}(w_1) + bT^{-1}(w_2)$. (2) Nếu $T$ khả nghịch, theo Định lý 1, $[T^{-1}][T] = [\operatorname{id}_V]_{B \leftarrow B} = I$ và tương tự theo thứ tự kia. Ngược lại, nếu $A = [T]$ khả nghịch thì $\operatorname{Nul} A = \{0\}$, nên $\ker T = \{0\}$, $T$ đơn ánh, và theo Hệ quả 1 Bài 6.3 cũng toàn ánh.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 3.&lt;/strong&gt; Hai không gian vectơ hữu hạn chiều đẳng cấu khi và chỉ khi chúng có cùng số chiều. Đặc biệt, mọi không gian $n$ chiều đẳng cấu với $\mathbb{R}^n$ qua ánh xạ toạ độ $v \mapsto [v]_B$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Nếu $T : V \to W$ là đẳng cấu thì $\ker T = \{0\}$ và $\operatorname{im} T = W$, nên theo Định lý 2 Bài 6.3, $\dim V = 0 + \dim W$. Ngược lại, nếu $\dim V = \dim W = n$ với cơ sở $b_1, \dots, b_n$ và $c_1, \dots, c_n$, ánh xạ tuyến tính $T(b_i) = c_i$ (Định lý 2 Bài 6.1) có ma trận $I$ trong hai cơ sở này, nên khả nghịch.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Ý nghĩa: về mặt đại số tuyến tính, $P_3$, $M_{2 \times 2}$ và $\mathbb{R}^4$ là “cùng một không gian” với ba cách đặt tên khác nhau. Mọi câu hỏi về độc lập, span, cơ sở trên $P_3$ có thể giải bằng ma trận trong $\mathbb{R}^4$, như ta đã làm ở Bài 5.6 và 5.7.&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ&quot;&gt;Ví dụ&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; $T(x, y) = (x + y,\ x - y)$, ma trận $A = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix}$, $\det A = -2 \ne 0$. Nghịch đảo $A^{-1} = \tfrac12 \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix}$, tức $T^{-1}(u, v) = \big(\tfrac{u + v}{2}, \tfrac{u - v}{2}\big)$. Kiểm tra: $T^{-1}(T(3, 1)) = T^{-1}(4, 2) = (3, 1)$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; $T : P_2 \to \mathbb{R}^3$, $T(p) = (p(0), p(1), p(2))$ là đẳng cấu (Bài tập 5, Bài 6.3). Ánh xạ ngược cho đa thức nội suy: $T^{-1}(a, b, c) = aL_0 + bL_1 + cL_2$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3 (không khả nghịch).&lt;/strong&gt; Phép chiếu $P(x, y) = (x, 0)$ không khả nghịch: $\det = 0$, và về hình học, ta không thể biết một điểm trên trục $x$ đến từ điểm nào trên đường thẳng đứng đi qua nó. Hợp $P \circ P = P$: chiếu hai lần cũng như chiếu một lần.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-thao-tác-hoàn-tác-undo-và-mã-hoá&quot;&gt;Ứng dụng: thao tác hoàn tác (undo) và mã hoá&lt;/h2&gt;

&lt;p&gt;Trong phần mềm chỉnh ảnh, các phép quay, lật, co giãn đều là đẳng cấu, nên có thể hoàn tác chính xác bằng ma trận nghịch đảo. Phép “làm phẳng” ảnh về một đường (phép chiếu) thì không: thông tin đã mất ở hạt nhân. Trong mật mã Hill (Bài 3.3, 4.3), khoá $K$ phải là một đẳng cấu trên $(\mathbb{Z}_{26})^n$ để người nhận giải mã được; khoá có $\det K$ không khả nghịch modulo 26 sẽ biến hai bản rõ khác nhau thành cùng một bản mã.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: ánh xạ ngược&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo t để A⁻¹ đưa lưới về chỗ cũ; với det A = 0 thì không có ánh xạ ngược.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=inverse&quot; title=&quot;Minh hoạ: ánh xạ ngược&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=inverse&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Cho $T(x, y) = (2x + y,\ x + y)$. Tìm $T^{-1}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\det = 1$, $A^{-1} = \begin{bmatrix} 1 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{bmatrix}$: $T^{-1}(u, v) = (u - v,\ -u + 2v)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Dùng $R_\alpha R_\alpha = R_{2\alpha}$ để suy ra công thức $\sin 2\alpha$ và $\cos 2\alpha$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Bình phương ma trận quay: $\cos 2\alpha = \cos^2\alpha - \sin^2\alpha$, $\sin 2\alpha = 2\sin\alpha\cos\alpha$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Các không gian nào đẳng cấu với nhau: $\mathbb{R}^6$, $P_5$, $M_{2 \times 3}$, các ma trận đối xứng $3 \times 3$, $P_6$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Bốn không gian đầu đều có chiều 6, nên đẳng cấu với nhau. $P_6$ có chiều 7.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Cho $T : P_2 \to P_2$, $T(p) = p + p&apos;$. Chứng minh $T$ là đẳng cấu và tìm $T^{-1}(x^2)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Ma trận theo $\{1, x, x^2\}$: $\begin{bmatrix} 1 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 2 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$, tam giác với đường chéo 1, khả nghịch. Giải $p + p&apos; = x^2$: $p = x^2 - 2x + 2$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Cho $S, T$ là toán tử trên $V$ hữu hạn chiều với $S \circ T = \operatorname{id}$. Chứng minh $T \circ S = \operatorname{id}$. Điều này có đúng trên $F(\mathbb{R})$ hay không gian các đa thức (mọi bậc) không?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$S \circ T = \operatorname{id}$ cho $T$ đơn ánh, nên (cùng số chiều) $T$ là đẳng cấu, và $S = T^{-1}$. Trên không gian vô hạn chiều thì sai: với mọi đa thức, $D \circ J = \operatorname{id}$ với $J(p) = \int_0^x p$, nhưng $J \circ D \ne \operatorname{id}$ vì $J(D(1)) = 0$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Ma trận của $S \circ T$ là $[S][T]$; phép nhân ma trận mã hoá phép hợp ánh xạ.&lt;/li&gt;
    &lt;li&gt;$T$ khả nghịch $\iff$ song ánh $\iff$ (khi cùng số chiều) ma trận khả nghịch; $[T^{-1}] = [T]^{-1}$.&lt;/li&gt;
    &lt;li&gt;$V \cong W \iff \dim V = \dim W$; mọi không gian $n$ chiều đẳng cấu với $\mathbb{R}^n$ qua toạ độ.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Hạt nhân và ảnh</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter06/06_03_Hat_Nhan_Va_Anh/"/>
   <updated>2026-01-06T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter06/06_03_Hat_Nhan_Va_Anh</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;tìm hạt nhân và ảnh của một ánh xạ tuyến tính, cùng cơ sở của chúng;&lt;/li&gt;
    &lt;li&gt;dùng hạt nhân để kiểm tra đơn ánh, dùng ảnh để kiểm tra toàn ánh;&lt;/li&gt;
    &lt;li&gt;áp dụng $\dim V = \dim \ker T + \dim \operatorname{im} T$;&lt;/li&gt;
    &lt;li&gt;giải thích vì sao ánh xạ từ không gian lớn sang không gian nhỏ không thể đơn ánh.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Một camera chụp cảnh 3 chiều thành ảnh 2 chiều. Mô hình đơn giản nhất là chiếu song song: $T(x, y, z) = (x, y)$, bỏ đi độ sâu $z$. Mọi điểm trên một tia nhìn thẳng đứng $(x_0, y_0, z)$ đều cho cùng một điểm ảnh; riêng các điểm $(0, 0, z)$ bị đưa về gốc. Đường thẳng đó, trục $z$, là phần thông tin bị mất: &lt;em&gt;hạt nhân&lt;/em&gt;. Trong khi đó mọi điểm của mặt phẳng ảnh đều có điểm 3 chiều chụp ra nó: &lt;em&gt;ảnh&lt;/em&gt; là cả $\mathbb{R}^2$. Một chiều mất, hai chiều còn: $1 + 2 = 3$.&lt;/p&gt;

&lt;h2 id=&quot;định-nghĩa&quot;&gt;Định nghĩa&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1.&lt;/strong&gt; Cho $T : V \to W$ tuyến tính.&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;&lt;em&gt;Hạt nhân&lt;/em&gt;: $\ker T = \{v \in V : T(v) = 0\}$.&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;Ảnh&lt;/em&gt;: $\operatorname{im} T = \{T(v) : v \in V\}$.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Với $T(x) = Ax$: $\ker T = \operatorname{Nul} A$ và $\operatorname{im} T = \operatorname{Col} A$ (Bài 5.4).&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; $\ker T$ là không gian con của $V$ và $\operatorname{im} T$ là không gian con của $W$. Hơn nữa, $T$ đơn ánh khi và chỉ khi $\ker T = \{0\}$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; $T(0) = 0$ nên $0$ thuộc cả hai. Nếu $T(u) = T(v) = 0$ thì $T(au + bv) = 0$. Nếu $w_1 = T(v_1)$, $w_2 = T(v_2)$ thì $aw_1 + bw_2 = T(av_1 + bv_2) \in \operatorname{im} T$.&lt;/p&gt;

  &lt;p&gt;Nếu $T$ đơn ánh và $T(v) = 0 = T(0)$ thì $v = 0$. Ngược lại, nếu $\ker T = \{0\}$ và $T(u) = T(v)$ thì $T(u - v) = 0$, nên $u - v = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Ý nghĩa: với ánh xạ tuyến tính, chỉ cần kiểm tra xem có vectơ khác 0 nào bị đưa về 0 không. Hai điểm $u, v$ có cùng ảnh khi và chỉ khi $u - v \in \ker T$: mỗi “thớ” $\{v : T(v) = w\}$ là một bản sao tịnh tiến của hạt nhân, giống nghiệm tổng quát $x_p + \operatorname{Nul} A$ ở Bài 2.5.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2 (Hạng – số khuyết cho ánh xạ).&lt;/strong&gt; Nếu $V$ hữu hạn chiều thì&lt;/p&gt;

  &lt;p&gt;\(\dim V = \dim \ker T + \dim \operatorname{im} T .\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Lấy cơ sở $B$ của $V$ ($\dim V = n$) và cơ sở $C$ của $\operatorname{im} T$ hay của $W$ (hữu hạn chiều, vì $\operatorname{im} T$ sinh bởi $T(b_1), \dots, T(b_n)$). Đặt $A = [T]_{C \leftarrow B}$. Theo Định lý 2 Bài 6.2, $v \in \ker T \iff [v]_B \in \operatorname{Nul} A$ và $w \in \operatorname{im} T \iff [w]_C \in \operatorname{Col} A$. Phép lấy toạ độ giữ nguyên số chiều (Định lý 1 Bài 5.6), nên áp dụng Định lý 1 của Bài 5.5 cho $A$ (có $n$ cột).&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Hệ quả 1.&lt;/strong&gt; Cho $\dim V = n$, $\dim W = m$.&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;Nếu $n &amp;gt; m$ thì $T$ không đơn ánh. Nếu $n &amp;lt; m$ thì $T$ không toàn ánh.&lt;/li&gt;
    &lt;li&gt;Nếu $n = m$ thì $T$ đơn ánh $\iff$ $T$ toàn ánh.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; (1) $\dim \operatorname{im} T \le m &amp;lt; n$ cho $\dim \ker T \ge 1$; $\dim \operatorname{im} T \le n &amp;lt; m$ nên $\operatorname{im} T \ne W$. (2) $\ker T = \{0\} \iff \dim \operatorname{im} T = n = m \iff \operatorname{im} T = W$ (Định lý 3(4) Bài 5.3).&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ&quot;&gt;Ví dụ&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; $T : \mathbb{R}^3 \to \mathbb{R}^2$, $T(x, y, z) = (x + y,\ y + z)$, ma trận $\begin{bmatrix} 1 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 1 \end{bmatrix}$. Giải $T(x) = 0$: $z = t$, $y = -t$, $x = t$, nên $\ker T = \operatorname{span}\{(1, -1, 1)\}$, chiều 1. Theo Định lý 2, $\dim \operatorname{im} T = 2$, nên $\operatorname{im} T = \mathbb{R}^2$. $T$ toàn ánh nhưng không đơn ánh: $(0, 0, 0)$ và $(1, -1, 1)$ cùng đi về $(0, 0)$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (phép chiếu).&lt;/strong&gt; $P(x, y) = (x, 0)$ trên $\mathbb{R}^2$. $\ker P$ là trục $y$, $\operatorname{im} P$ là trục $x$, $1 + 1 = 2$. Mỗi đường thẳng đứng (song song với hạt nhân) bị ép thành một điểm trên trục $x$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3 (đạo hàm).&lt;/strong&gt; $D : P_3 \to P_3$. $\ker D$ là các hằng số (chiều 1), $\operatorname{im} D = P_2$ (chiều 3), $1 + 3 = 4 = \dim P_3$. $D$ không đơn ánh, và vì cùng số chiều nên cũng không toàn ánh: $x^3$ không phải đạo hàm của đa thức bậc $\le 3$ nào.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-mất-thông-tin-khi-nén-và-đo-đạc&quot;&gt;Ứng dụng: mất thông tin khi nén và đo đạc&lt;/h2&gt;

&lt;p&gt;Mỗi phép đo tuyến tính, như cảm biến cho biết tổng hoặc trung bình của nhiều đại lượng, là một ánh xạ $T$. Hạt nhân là những thay đổi mà cảm biến không thấy được. Ví dụ ảnh chụp X-quang là tổng mật độ dọc mỗi tia: hai cơ thể khác nhau một vectơ thuộc hạt nhân cho cùng một ảnh. Vì vậy chụp cắt lớp CT phải chụp từ nhiều góc: ghép nhiều phép chiếu thành một ánh xạ có hạt nhân $\{0\}$ để dựng lại được vật thể. Trong nén dữ liệu có mất mát, ta cố tình chọn $T$ có hạt nhân chứa những thành phần ít quan trọng.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: hạt nhân và ảnh của ánh xạ ℝ³ → ℝ²&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Xoay miền ℝ³ để thấy ker T; dời x dọc ker T thì T(x) không đổi.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter06/hat_nhan_anh.html&quot; title=&quot;Minh hoạ: hạt nhân và ảnh của ánh xạ ℝ³ → ℝ²&quot; loading=&quot;lazy&quot; style=&quot;height: 700px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter06/hat_nhan_anh.html&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-ép-khối-xuống-mặt-phẳng&quot;&gt;Video ngắn: Ép khối xuống mặt phẳng&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/rank-nullity-3d.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;T(x, y, z) = (x − z; y − z) đẩy mỗi điểm dọc hướng (1; 1; 1) xuống mặt sàn. Hạt nhân là đường t(1; 1; 1) bị ép về gốc, mỗi đường song song với nó thành một điểm, khối lập phương thành một lục giác phẳng: dim ker T + dim im T = 1 + 2 = 3. Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Tìm hạt nhân và ảnh của phép quay $60^\circ$ rồi phản xạ qua $y = x$ (Bài 6.2).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Định thức $-1 \ne 0$, nên $\ker = \{0\}$ và $\operatorname{im} = \mathbb{R}^2$: song ánh.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Tìm cơ sở của hạt nhân và ảnh của $T(x, y, z) = (x - y,\ 2x - 2y,\ z)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\ker$: $(1, 1, 0)$. $\operatorname{im}$: $\operatorname{span}\{(1, 2, 0), (0, 0, 1)\}$. $1 + 2 = 3$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Tìm hạt nhân và ảnh của $\operatorname{tr} : M_{2 \times 2} \to \mathbb{R}$ và số chiều của chúng.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Ảnh là $\mathbb{R}$ (vì $\operatorname{tr}(cE_{11}) = c$), chiều 1. Hạt nhân là các ma trận vết 0, chiều $4 - 1 = 3$, cơ sở $E_{12}, E_{21}, E_{11} - E_{22}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Có ánh xạ tuyến tính $T : \mathbb{R}^4 \to \mathbb{R}^3$ nào đơn ánh không? Có ánh xạ nào với $\ker T = \operatorname{im} T$ trên $\mathbb{R}^3$ không?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Không đơn ánh được, vì $4 &amp;gt; 3$. Không: nếu $\dim \ker = \dim \operatorname{im} = k$ thì $2k = 3$, vô lý. (Trên $\mathbb{R}^2$ thì có, ví dụ $T(x, y) = (y, 0)$.)

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Cho $T : P_2 \to \mathbb{R}^3$, $T(p) = (p(0), p(1), p(2))$. Chứng minh $T$ là song ánh và giải thích liên hệ với Bài 5.7.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Nếu $T(p) = 0$ thì đa thức bậc $\le 2$ có ba nghiệm, nên $p = 0$. Cùng số chiều 3, nên $T$ toàn ánh. $T^{-1}(a, b, c) = aL_0 + bL_1 + cL_2$ với cơ sở Lagrange.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$\ker T = \{v : T(v) = 0\}$ và $\operatorname{im} T$ là các không gian con; với ma trận: $\operatorname{Nul} A$, $\operatorname{Col} A$.&lt;/li&gt;
    &lt;li&gt;$T$ đơn ánh $\iff \ker T = \{0\}$; $T$ toàn ánh $\iff \operatorname{im} T = W$.&lt;/li&gt;
    &lt;li&gt;$\dim V = \dim \ker T + \dim \operatorname{im} T$.&lt;/li&gt;
    &lt;li&gt;Cùng số chiều: đơn ánh $\iff$ toàn ánh. Từ không gian lớn sang nhỏ hơn: không đơn ánh.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Ma trận của ánh xạ tuyến tính</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter06/06_02_Ma_Tran_Cua_Anh_Xa_Tuyen_Tinh/"/>
   <updated>2026-01-06T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter06/06_02_Ma_Tran_Cua_Anh_Xa_Tuyen_Tinh</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;viết ma trận chính tắc của một ánh xạ tuyến tính $\mathbb{R}^n \to \mathbb{R}^m$ từ ảnh của $e_1, \dots, e_n$;&lt;/li&gt;
    &lt;li&gt;viết ma trận của ánh xạ tuyến tính theo một cặp cơ sở bất kỳ;&lt;/li&gt;
    &lt;li&gt;dùng ma trận để tính ảnh của một vectơ;&lt;/li&gt;
    &lt;li&gt;đọc hình học của phép biến đổi từ các cột của ma trận.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Phép quay $60^\circ$ biến $e_1 = (1, 0)$ thành $(\cos 60^\circ, \sin 60^\circ) = (\tfrac12, \tfrac{\sqrt3}{2})$ và $e_2 = (0, 1)$ thành $(-\sin 60^\circ, \cos 60^\circ) = (-\tfrac{\sqrt3}{2}, \tfrac12)$. Một vectơ bất kỳ $(x, y) = x e_1 + y e_2$ đi tới $x T(e_1) + y T(e_2)$ (Bài 6.1). Viết dưới dạng ma trận:&lt;/p&gt;

\[T(x, y) = \begin{bmatrix} 1/2 &amp;amp; -\sqrt3/2 \\ \sqrt3/2 &amp;amp; 1/2 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} .\]

&lt;p&gt;Hai cột của ma trận chính là hai vectơ ảnh $T(e_1)$, $T(e_2)$. Biết hai mũi tên đó đi đâu là biết cả lưới đi đâu.&lt;/p&gt;

&lt;h2 id=&quot;ma-trận-chính-tắc&quot;&gt;Ma trận chính tắc&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Ma trận chính tắc).&lt;/strong&gt; Mọi ánh xạ tuyến tính $T : \mathbb{R}^n \to \mathbb{R}^m$ có dạng $T(x) = Ax$ với đúng một ma trận $A$ cỡ $m \times n$, là&lt;/p&gt;

  &lt;p&gt;\(A = \big[\, T(e_1) \ \ T(e_2) \ \ \cdots \ \ T(e_n) \,\big] .\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Với $x = \sum x_j e_j$, $T(x) = \sum x_j T(e_j)$, và đây là $Ax$ theo cách nhìn “tổ hợp các cột” của Bài 3.2. Nếu $Bx = T(x)$ với mọi $x$ thì $Be_j = T(e_j)$, tức cột $j$ của $B$ trùng cột $j$ của $A$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Phản xạ qua đường $y = x$ đổi chỗ hai toạ độ: $e_1 \mapsto e_2$, $e_2 \mapsto e_1$, nên ma trận là $F = \begin{bmatrix} 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix}$. Phép “quay $60^\circ$ rồi phản xạ” có ma trận $FR$ (làm $R$ trước, nên $R$ đứng bên phải):&lt;/p&gt;

\[FR = \begin{bmatrix} \sqrt3/2 &amp;amp; 1/2 \\ 1/2 &amp;amp; -\sqrt3/2 \end{bmatrix} .\]

  &lt;p&gt;Định thức bằng $-1$: diện tích giữ nguyên, định hướng bị lật (Bài 4.5). Thực ra đây là phản xạ qua một đường thẳng khác (Bài 6.6).&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; Với $T$ ở Ví dụ 3 Bài 6.1 ($T(1, 1) = (2, 0, 1)$, $T(1, -1) = (0, 2, 1)$): $e_1 = \tfrac12[(1, 1) + (1, -1)]$ nên $T(e_1) = (1, 1, 1)$; $e_2 = \tfrac12[(1, 1) - (1, -1)]$ nên $T(e_2) = (1, -1, 0)$. Vậy&lt;/p&gt;

\[A = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \\ 1 &amp;amp; 0 \end{bmatrix}, \qquad A \begin{bmatrix} 5 \\ 1 \end{bmatrix} = \begin{bmatrix} 6 \\ 4 \\ 5 \end{bmatrix},\]

  &lt;p&gt;khớp với kết quả của Bài 6.1.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ma-trận-theo-cặp-cơ-sở&quot;&gt;Ma trận theo cặp cơ sở&lt;/h2&gt;

&lt;p&gt;Với không gian bất kỳ, ta không có “toạ độ chuẩn”, nên cần chọn cơ sở.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1.&lt;/strong&gt; Cho $T : V \to W$ tuyến tính, $B = \{b_1, \dots, b_n\}$ là cơ sở của $V$ và $C$ là cơ sở của $W$. &lt;em&gt;Ma trận của $T$ theo $B$ và $C$&lt;/em&gt; là&lt;/p&gt;

  &lt;p&gt;\([T]_{C \leftarrow B} = \big[\, [T(b_1)]_C \ \ \cdots \ \ [T(b_n)]_C \,\big] .\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2.&lt;/strong&gt; $[T(v)]_C = [T]_{C \leftarrow B}\, [v]_B$ với mọi $v \in V$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Nếu $[v]_B = (c_1, \dots, c_n)$ thì $T(v) = \sum c_j T(b_j)$, nên theo Định lý 1 Bài 5.6, $[T(v)]_C = \sum c_j [T(b_j)]_C$, chính là tích ma trận - vectơ ở vế phải.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Sơ đồ: đi từ $v$ sang $T(v)$ trong không gian gốc tương ứng với đi từ $[v]_B$ sang $[T(v)]_C$ bằng phép nhân ma trận. Ma trận chuyển cơ sở của Bài 5.6 là trường hợp riêng: $P_{C \leftarrow B} = [\operatorname{id}]_{C \leftarrow B}$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3.&lt;/strong&gt; $D : P_2 \to P_1$, $D(p) = p&apos;$, với $B = \{1, x, x^2\}$, $C = \{1, x\}$. $D(1) = 0$, $D(x) = 1$, $D(x^2) = 2x$:&lt;/p&gt;

\[[D]_{C \leftarrow B} = \begin{bmatrix} 0 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 2 \end{bmatrix} .\]

  &lt;p&gt;Với $p = 5 - 3x + 4x^2$: $[D]\,(5, -3, 4) = (-3, 8)$, tức $p&apos; = -3 + 8x$. Ma trận cỡ $2 \times 3$ vì $\dim P_1 = 2$, $\dim P_2 = 3$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-đồ-hoạ-máy-tính&quot;&gt;Ứng dụng: đồ hoạ máy tính&lt;/h2&gt;

&lt;p&gt;Một trò chơi 2D vẽ hàng nghìn đỉnh của nhân vật mỗi khung hình. Muốn xoay, phóng to hay lật nhân vật, chương trình không tính lại từng đỉnh bằng công thức hình học, mà nhân mọi đỉnh với một ma trận $2 \times 2$. Ghép nhiều phép (quay rồi phóng to rồi lật) chỉ là nhân các ma trận trước một lần, rồi áp dụng ma trận tích cho mọi đỉnh. Card đồ hoạ được thiết kế để làm đúng việc này cực nhanh. Định lý 1 đảm bảo mọi phép biến đổi tuyến tính đều đưa được về dạng này, chỉ cần biết ảnh của $e_1, e_2$.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: ma trận của ánh xạ tuyến tính&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Hai cột của ma trận là ảnh của e₁, e₂; chọn ma trận mẫu: co giãn, quay, trượt, đối xứng, chiếu.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=map&quot; title=&quot;Minh hoạ: ma trận của ánh xạ tuyến tính&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=map&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-ảnh-của-cơ-sở-cho-ta-các-cột&quot;&gt;Video ngắn: Ảnh của cơ sở cho ta các cột&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/basis-images-columns.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Kéo e₁ thì cột 1 của ma trận đổi theo, kéo e₂ thì cột 2 đổi theo, cả lưới đi cùng: M = [T(e₁) T(e₂)]. Sau đó lần lượt quay 30°, phản xạ qua y = x, trượt ngang và chiếu lên trục x. Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Viết ma trận chính tắc của $T(x, y, z) = (x - 2z,\ 3y + z)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\begin{bmatrix} 1 &amp;amp; 0 &amp;amp; -2 \\ 0 &amp;amp; 3 &amp;amp; 1 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Viết ma trận của phép quay $60^\circ$ rồi phản xạ qua đường $y = x$, và của phép phản xạ trước rồi quay. Hai ma trận có bằng nhau không?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$FR = \begin{bmatrix} \sqrt3/2 &amp;amp; 1/2 \\ 1/2 &amp;amp; -\sqrt3/2 \end{bmatrix}$, $RF = \begin{bmatrix} -\sqrt3/2 &amp;amp; 1/2 \\ 1/2 &amp;amp; \sqrt3/2 \end{bmatrix}$. Khác nhau.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Tìm ma trận của $T : M_{2 \times 2} \to M_{2 \times 2}$, $T(A) = A^T$, theo cơ sở $\{E_{11}, E_{12}, E_{21}, E_{22}\}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$E_{12} \leftrightarrow E_{21}$, $E_{11}, E_{22}$ giữ nguyên: $\begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Tìm ma trận của $I : P_2 \to \mathbb{R}$, $I(p) = \int_0^1 p(x)\,dx$, theo cơ sở $\{1, x, x^2\}$ và $\{1\}$. Tính $I(3 - 6x + x^2)$ bằng ma trận.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$[1\ \ \tfrac12\ \ \tfrac13]$. $3 - 3 + \tfrac13 = \tfrac13$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (lập trình).&lt;/strong&gt; Với Matplotlib, vẽ hình vuông đơn vị và ảnh của nó qua năm ma trận: quay $60^\circ$, phản xạ qua $y = x$, co giãn $\operatorname{diag}(2, \tfrac12)$, trượt $\begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \end{bmatrix}$, chiếu lên trục $x$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Lưu bốn đỉnh thành ma trận $2 \times 4$ `S`, vẽ `A @ S` cho từng `A`. Ảnh qua phép chiếu là đoạn $[0, 1]$ trên trục $x$ (diện tích 0, đúng với $\det = 0$).

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Ma trận chính tắc: cột $j$ là $T(e_j)$; $T(x) = Ax$.&lt;/li&gt;
    &lt;li&gt;Theo cặp cơ sở $B, C$: cột $j$ của $[T]_{C \leftarrow B}$ là $[T(b_j)]_C$, và $[T(v)]_C = [T]_{C \leftarrow B} [v]_B$.&lt;/li&gt;
    &lt;li&gt;Ghép phép biến đổi là nhân ma trận, phép làm trước đứng bên phải.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Ánh xạ tuyến tính: định nghĩa và ví dụ</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter06/06_01_Dinh_Nghia_Va_Vi_Du/"/>
   <updated>2026-01-06T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter06/06_01_Dinh_Nghia_Va_Vi_Du</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;phát biểu định nghĩa ánh xạ tuyến tính và kiểm tra một ánh xạ có tuyến tính không;&lt;/li&gt;
    &lt;li&gt;đưa ví dụ ánh xạ tuyến tính trên $\mathbb{R}^n$, đa thức, ma trận và các ví dụ phi tuyến;&lt;/li&gt;
    &lt;li&gt;dùng tính chất $T(0) = 0$ để loại nhanh ánh xạ không tuyến tính;&lt;/li&gt;
    &lt;li&gt;tính $T(v)$ từ ảnh của các vectơ cơ sở.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Phép quay mặt phẳng $90^\circ$ quanh gốc biến $(x, y)$ thành $(-y, x)$. Quay tổng hai vectơ cũng như quay từng vectơ rồi cộng: hình bình hành tạo bởi $u, v$ quay nguyên khối, nên đường chéo $u + v$ quay theo. Kéo dài một vectơ gấp đôi rồi quay cũng như quay rồi kéo dài. Lưới toạ độ sau khi quay vẫn là lưới: các đường thẳng song song và cách đều vẫn song song và cách đều.&lt;/p&gt;

&lt;p&gt;Ngược lại, phép $f(x, y) = (x^2, y)$ bẻ cong lưới: đường thẳng đứng $x = 1$ và $x = 2$ đi tới $x = 1$ và $x = 4$, không còn cách đều. Bài này tách tính chất “giữ lưới” ra thành định nghĩa.&lt;/p&gt;

&lt;h2 id=&quot;định-nghĩa&quot;&gt;Định nghĩa&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Ánh xạ tuyến tính).&lt;/strong&gt; Cho $V, W$ là các không gian vectơ. Ánh xạ $T : V \to W$ gọi là &lt;em&gt;tuyến tính&lt;/em&gt; nếu với mọi $u, v \in V$ và mọi $c \in \mathbb{R}$:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$T(u + v) = T(u) + T(v)$;&lt;/li&gt;
    &lt;li&gt;$T(cv) = c\,T(v)$.&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;Khi $V = W$, $T$ còn gọi là một &lt;em&gt;toán tử tuyến tính&lt;/em&gt; (hay phép biến đổi tuyến tính) trên $V$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Nếu $T$ tuyến tính thì $T(0) = 0$, $T(-v) = -T(v)$, và&lt;/p&gt;

\[T(c_1 v_1 + \dots + c_k v_k) = c_1 T(v_1) + \dots + c_k T(v_k) .\]

  &lt;p&gt;Ngược lại, nếu $T(au + bv) = aT(u) + bT(v)$ với mọi $a, b, u, v$ thì $T$ tuyến tính.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; $T(0) = T(0 \cdot 0) = 0 \cdot T(0) = 0$ (Bài 5.1). $T(-v) = T((-1)v) = -T(v)$. Đẳng thức với $k$ vectơ chứng minh bằng quy nạp: $T(\sum_{i&amp;lt;k} c_i v_i + c_k v_k) = T(\sum_{i&amp;lt;k} c_i v_i) + c_k T(v_k)$. Chiều ngược lại: lấy $a = b = 1$ được điều kiện 1, lấy $b = 0$ được điều kiện 2.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;“Ánh xạ tuyến tính biến tổ hợp tuyến tính thành tổ hợp tuyến tính với cùng hệ số” là cách nhớ ngắn nhất.&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ&quot;&gt;Ví dụ&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (tuyến tính).&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;Mọi ma trận $A$ cỡ $m \times n$ cho ánh xạ $T(x) = Ax$ từ $\mathbb{R}^n$ vào $\mathbb{R}^m$: $A(u + v) = Au + Av$, $A(cv) = cAv$ (Bài 3.1).&lt;/li&gt;
    &lt;li&gt;Đạo hàm $D : P_3 \to P_2$, $D(p) = p&apos;$.&lt;/li&gt;
    &lt;li&gt;Tích phân $I : P_2 \to \mathbb{R}$, $I(p) = \int_0^1 p(x)\,dx$.&lt;/li&gt;
    &lt;li&gt;Vết $\operatorname{tr} : M_{n \times n} \to \mathbb{R}$ và chuyển vị $A \mapsto A^T$ trên $M_{m \times n}$.&lt;/li&gt;
    &lt;li&gt;Phép tính giá trị $p \mapsto p(2)$ từ $P_n$ vào $\mathbb{R}$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (không tuyến tính).&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;Tịnh tiến $T(x, y) = (x + 1, y)$: $T(0, 0) = (1, 0) \ne 0$. Loại ngay.&lt;/li&gt;
    &lt;li&gt;$f(x, y) = (x^2, y)$: $f(0) = 0$ nhưng $f(2 \cdot (1, 0)) = (4, 0) \ne 2 f(1, 0) = (2, 0)$.&lt;/li&gt;
    &lt;li&gt;$g(x, y) = (xy, x)$: $g(1, 1) + g(1, 1) = (2, 2)$ nhưng $g(2, 2) = (4, 2)$.&lt;/li&gt;
    &lt;li&gt;Định thức $\det : M_{2 \times 2} \to \mathbb{R}$: $\det(2I) = 4 \ne 2 \det I$. Định thức tuyến tính theo từng hàng (Bài 4.2) nhưng không tuyến tính theo cả ma trận.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Điều kiện $T(0) = 0$ là cần nhưng không đủ: $f$ và $g$ đều giữ gốc.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;xác-định-bởi-ảnh-của-cơ-sở&quot;&gt;Xác định bởi ảnh của cơ sở&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2.&lt;/strong&gt; Cho $\{b_1, \dots, b_n\}$ là cơ sở của $V$ và $w_1, \dots, w_n$ là các vectơ bất kỳ của $W$. Có đúng một ánh xạ tuyến tính $T : V \to W$ với $T(b_i) = w_i$ với mọi $i$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; &lt;em&gt;Duy nhất:&lt;/em&gt; mỗi $v = \sum c_i b_i$, nên theo Định lý 1 buộc phải có $T(v) = \sum c_i w_i$. &lt;em&gt;Tồn tại:&lt;/em&gt; định nghĩa $T(v) = \sum c_i w_i$ với $(c_i) = [v]_B$. Vì $[u + v]_B = [u]_B + [v]_B$ và $[cv]_B = c[v]_B$ (Bài 5.6), $T$ tuyến tính, và $T(b_i) = w_i$ vì $[b_i]_B = e_i$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3.&lt;/strong&gt; Ánh xạ tuyến tính $T : \mathbb{R}^2 \to \mathbb{R}^3$ có $T(1, 1) = (2, 0, 1)$ và $T(1, -1) = (0, 2, 1)$. Tính $T(5, 1)$.&lt;/p&gt;

  &lt;p&gt;Theo Bài 5.6, $(5, 1) = 3(1, 1) + 2(1, -1)$. Vậy&lt;/p&gt;

\[T(5, 1) = 3(2, 0, 1) + 2(0, 2, 1) = (6, 4, 5) .\]

  &lt;p&gt;Chỉ hai vectơ ảnh đã quyết định toàn bộ $T$ trên cả mặt phẳng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-nguyên-lý-chồng-chất&quot;&gt;Ứng dụng: nguyên lý chồng chất&lt;/h2&gt;

&lt;p&gt;Một hệ vật lý tuyến tính (mạch RLC, dầm đàn hồi biến dạng nhỏ, bộ lọc âm thanh) là một ánh xạ tuyến tính từ “đầu vào” sang “đầu ra”. Tính tuyến tính chính là &lt;em&gt;nguyên lý chồng chất&lt;/em&gt;: đáp ứng với tổng hai tín hiệu bằng tổng hai đáp ứng; tăng gấp đôi lực thì độ võng tăng gấp đôi. Nhờ đó kỹ sư chỉ cần đo đáp ứng với vài tín hiệu cơ bản (một cơ sở, như các sóng sin hoặc xung đơn vị) rồi suy ra đáp ứng với mọi tín hiệu, đúng như Định lý 2. Khi hệ bị đẩy quá xa (dầm võng lớn, loa bị méo tiếng), tính tuyến tính mất đi; khi đó người ta xấp xỉ hệ gần một điểm làm việc bằng ma trận Jacobi (khoá Giải tích).&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: ánh xạ tuyến tính và phi tuyến&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Chọn T, kéo u, v để kiểm tra T(u + v) = T(u) + T(v); xem ma trận Jacobi của ánh xạ phi tuyến.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter06/tuyen_tinh_hay_khong.html&quot; title=&quot;Minh hoạ: ánh xạ tuyến tính và phi tuyến&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter06/tuyen_tinh_hay_khong.html&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Ánh xạ nào tuyến tính? (a) $T(x, y) = (2x - y, 3y)$; (b) $T(x, y) = (x, y + 2)$; (c) $T(x, y) = (\lvert x \rvert, y)$; (d) $T(x, y, z) = x + y + z$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

(a) Có. (b) Không, $T(0) \ne 0$. (c) Không: $T(-1, 0) = (1, 0) \ne -T(1, 0)$. (d) Có.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Chứng minh $T(p) = p(0) + p&apos;(0)$ là ánh xạ tuyến tính từ $P_2$ vào $\mathbb{R}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$(ap + bq)(0) = ap(0) + bq(0)$ và $(ap + bq)&apos;(0) = ap&apos;(0) + bq&apos;(0)$; cộng lại.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; $T : \mathbb{R}^2 \to \mathbb{R}^2$ tuyến tính, $T(1, 2) = (3, 1)$, $T(0, 1) = (1, 1)$. Tìm $T(1, 0)$ và $T(x, y)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$(1, 0) = (1, 2) - 2(0, 1)$, nên $T(1, 0) = (1, -1)$. $T(x, y) = xT(1,0) + yT(0,1) = (x + y,\ -x + y)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Có ánh xạ tuyến tính $T : \mathbb{R}^2 \to \mathbb{R}^2$ nào với $T(1, 1) = (1, 0)$, $T(2, 2) = (0, 1)$ không?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Không: phải có $T(2, 2) = 2T(1, 1) = (2, 0)$. Định lý 2 cần các vectơ $b_i$ là cơ sở.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Chứng minh: nếu $T$ tuyến tính và $v_1, \dots, v_k$ phụ thuộc tuyến tính thì $T(v_1), \dots, T(v_k)$ phụ thuộc tuyến tính. Điều ngược lại có đúng không?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Áp dụng $T$ vào một quan hệ $\sum c_i v_i = 0$ không tầm thường được $\sum c_i T(v_i) = 0$. Ngược lại sai: với $T = 0$, ảnh của mọi họ đều phụ thuộc.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$T$ tuyến tính khi $T(au + bv) = aT(u) + bT(v)$; khi đó $T(0) = 0$.&lt;/li&gt;
    &lt;li&gt;Ví dụ: $x \mapsto Ax$, đạo hàm, tích phân, vết, chuyển vị. Phản ví dụ: tịnh tiến, bình phương, định thức.&lt;/li&gt;
    &lt;li&gt;Một ánh xạ tuyến tính được xác định duy nhất bởi ảnh của một cơ sở, và các ảnh đó chọn tuỳ ý được.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Geometric transformations in ℝ² and ℝ³</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter06/06_06_Cac_Phep_Bien_Doi_Hinh_Hoc/"/>
   <updated>2026-01-06T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter06/06_06_Cac_Phep_Bien_Doi_Hinh_Hoc</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;write the matrices of rotations, reflections in a line, scalings, shears and projections in $\mathbb{R}^2$;&lt;/li&gt;
    &lt;li&gt;write the matrices of rotations about coordinate axes and of projection and reflection in a plane in $\mathbb{R}^3$;&lt;/li&gt;
    &lt;li&gt;recognise the type of transformation from its determinant and from $A^2$;&lt;/li&gt;
    &lt;li&gt;use homogeneous coordinates to represent translations by matrices.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;In Lesson 6.2, “rotate by $60^\circ$ then reflect in $y = x$” had matrix $\begin{bmatrix} \sqrt3/2 &amp;amp; 1/2 \\ 1/2 &amp;amp; -\sqrt3/2 \end{bmatrix}$ with determinant $-1$. It keeps lengths and flips the picture. Is it a reflection in some line? This lesson gives the general formula for reflection in the line at angle $\theta$ to the $x$-axis, and we will see that the answer is yes, with $\theta = 15^\circ$.&lt;/p&gt;

&lt;h2 id=&quot;in-the-plane&quot;&gt;In the plane&lt;/h2&gt;

&lt;p&gt;Each matrix below is found by asking where $e_1$ and $e_2$ go (Lesson 6.2).&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Basic transformations of $\mathbb{R}^2$).&lt;/strong&gt;&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;
      &lt;p&gt;Rotation by $\theta$:&lt;/p&gt;

\[R_\theta = \begin{bmatrix} \cos\theta &amp;amp; -\sin\theta \\ \sin\theta &amp;amp; \cos\theta \end{bmatrix}, \qquad \det R_\theta = 1\]
    &lt;/li&gt;
    &lt;li&gt;
      &lt;p&gt;Reflection in the line through the origin at angle $\theta$ to the $x$-axis:&lt;/p&gt;

\[H_\theta = \begin{bmatrix} \cos 2\theta &amp;amp; \sin 2\theta \\ \sin 2\theta &amp;amp; -\cos 2\theta \end{bmatrix}, \qquad \det H_\theta = -1\]
    &lt;/li&gt;
    &lt;li&gt;
      &lt;p&gt;Scaling along the axes:&lt;/p&gt;

\[\begin{bmatrix} a &amp;amp; 0 \\ 0 &amp;amp; b \end{bmatrix}, \qquad \det = ab\]
    &lt;/li&gt;
    &lt;li&gt;
      &lt;p&gt;Horizontal shear by $k$:&lt;/p&gt;

\[\begin{bmatrix} 1 &amp;amp; k \\ 0 &amp;amp; 1 \end{bmatrix}, \qquad \det = 1\]
    &lt;/li&gt;
    &lt;li&gt;
      &lt;p&gt;Orthogonal projection onto the line along a unit vector $u$:&lt;/p&gt;

\[uu^T, \qquad \det = 0\]
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Rotation: $e_1 \mapsto (\cos\theta, \sin\theta)$ and $e_2$ goes to the next perpendicular vector $(-\sin\theta, \cos\theta)$. Projection: the projection of $x$ onto the direction $u$ is $(u \cdot x) u = u(u^T x) = (uu^T) x$ (Lesson 1.2). Reflection: the mirror point is $x&apos; = 2p - x$ with $p = uu^T x$ the projection, so $H = 2uu^T - I$. With $u = (\cos\theta, \sin\theta)$:&lt;/p&gt;

\[2uu^T - I = \begin{bmatrix} 2\cos^2\theta - 1 &amp;amp; 2\sin\theta\cos\theta \\ 2\sin\theta\cos\theta &amp;amp; 2\sin^2\theta - 1 \end{bmatrix} = \begin{bmatrix} \cos 2\theta &amp;amp; \sin 2\theta \\ \sin 2\theta &amp;amp; -\cos 2\theta \end{bmatrix} .\]

  &lt;p&gt;Scaling and shear: read off the images of $e_1, e_2$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; Answering the motivating example: we need $\cos 2\theta = \tfrac{\sqrt3}{2}$, $\sin 2\theta = \tfrac12$, i.e. $2\theta = 30^\circ$. So “rotate by $60^\circ$ then reflect in $y = x$” is reflection in the line at $15^\circ$ to the $x$-axis. More generally, $H_\beta H_\alpha = R_{2(\beta - \alpha)}$: two reflections give a rotation (Exercise 4), and $H_\beta R_\alpha$ is again a reflection.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; Projection onto the line $y = 2x$: $u = \tfrac{1}{\sqrt5}(1, 2)$, $uu^T = \tfrac15 \begin{bmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 4 \end{bmatrix}$, matching Example 2 of Lesson 6.5. Reflection: $2uu^T - I = \tfrac15 \begin{bmatrix} -3 &amp;amp; 4 \\ 4 &amp;amp; 3 \end{bmatrix}$, matching Example 3 of Lesson 6.5. The two methods (formula and change of basis) agree.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Quick recognition: a projection has $A^2 = A$ (projecting twice is projecting once); a reflection has $A^2 = I$; rotations and reflections have $A^TA = I$ (they keep lengths), told apart by the sign of the determinant.&lt;/p&gt;

&lt;h2 id=&quot;in-space&quot;&gt;In space&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3 (rotation about the $z$-axis).&lt;/strong&gt; Rotation by $\theta$ about the $z$-axis fixes $e_3$ and rotates the $xy$-plane:&lt;/p&gt;

\[R_z(\theta) = \begin{bmatrix} \cos\theta &amp;amp; -\sin\theta &amp;amp; 0 \\ \sin\theta &amp;amp; \cos\theta &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix} .\]

  &lt;p&gt;Rotations about the $x$- or $y$-axis are written the same way, with the $2 \times 2$ block in the other two coordinates.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;For a plane through the origin with unit normal $n$, the part of $x$ along $n$ is $(nn^T)x$. Removing it gives the projection onto the plane, $I - nn^T$; removing it twice gives the reflection, $I - 2nn^T$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 4.&lt;/strong&gt; For the plane $x + y + z = 0$, $n = \tfrac{1}{\sqrt3}(1, 1, 1)$ and $nn^T = \tfrac13 J$, where $J$ is the all-ones matrix:&lt;/p&gt;

\[\text{Projection: } I - \tfrac13 J = \frac13 \begin{bmatrix} 2 &amp;amp; -1 &amp;amp; -1 \\ -1 &amp;amp; 2 &amp;amp; -1 \\ -1 &amp;amp; -1 &amp;amp; 2 \end{bmatrix}, \qquad \text{Reflection: } I - \tfrac23 J = \frac13 \begin{bmatrix} 1 &amp;amp; -2 &amp;amp; -2 \\ -2 &amp;amp; 1 &amp;amp; -2 \\ -2 &amp;amp; -2 &amp;amp; 1 \end{bmatrix} .\]

  &lt;p&gt;Check: the projection sends $(1, 1, 1)$ to 0 and keeps $(1, -1, 0)$. Its rank is 2: the image is the plane, the kernel is the normal line.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-homogeneous-coordinates-in-graphics&quot;&gt;Application: homogeneous coordinates in graphics&lt;/h2&gt;

&lt;p&gt;A translation $x \mapsto x + t$ is not linear (Lesson 6.1), yet computer graphics needs it constantly. The trick: write the point $(x, y)$ as $(x, y, 1)$ in $\mathbb{R}^3$. Then&lt;/p&gt;

\[\begin{bmatrix} 1 &amp;amp; 0 &amp;amp; t_1 \\ 0 &amp;amp; 1 &amp;amp; t_2 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} = \begin{bmatrix} x + t_1 \\ y + t_2 \\ 1 \end{bmatrix} .\]

&lt;p&gt;Translating $(2, 5)$ by $(3, -1)$ gives $(5, 4)$. Now rotations, scalings and translations are all $3 \times 3$ matrices, composed by multiplication. In 3D one uses $4 \times 4$ matrices the same way; this is the basis of every graphics engine (Chapter 12).&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: geometric transformations&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Pick a sample matrix and drag t from 0 to 1 to see rotation, reflection, shear, projection and scaling.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=map&amp;amp;lang=en&quot; title=&quot;Interactive: geometric transformations&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=map&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-rotation-reflection-shear-projection-through-the-basis-images&quot;&gt;Short video: Rotation, reflection, shear, projection through the basis images&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/basis-images-columns.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;The geometric maps start at 0:30: a 30° rotation gives columns (cos 30°; sin 30°) and (−sin 30°; cos 30°), the reflection across y = x swaps e₁ and e₂, the shear sends e₂ to (1; 1), and the projection onto the x-axis squashes e₂ to 0. Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Write the matrix of rotating by $60^\circ$ then reflecting in $y = x$, and find its kernel and image.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\begin{bmatrix} \sqrt3/2 &amp;amp; 1/2 \\ 1/2 &amp;amp; -\sqrt3/2 \end{bmatrix}$ (reflection in the line at $15^\circ$). Kernel $\{0\}$, image $\mathbb{R}^2$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Write the matrix of rotation by $90^\circ$ about the $x$-axis in $\mathbb{R}^3$ and find the image of $(1, 2, 3)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; -1 \\ 0 &amp;amp; 1 &amp;amp; 0 \end{bmatrix}$; image $(1, -3, 2)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Find the matrix of orthogonal projection onto the plane $x + y + z = 0$ and check $A^2 = A$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\tfrac13 \begin{bmatrix} 2 &amp;amp; -1 &amp;amp; -1 \\ -1 &amp;amp; 2 &amp;amp; -1 \\ -1 &amp;amp; -1 &amp;amp; 2 \end{bmatrix}$ (Example 4). $(I - nn^T)^2 = I - 2nn^T + n(n^Tn)n^T = I - nn^T$ since $n^Tn = 1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; Prove $H_\beta H_\alpha = R_{2(\beta - \alpha)}$. Give a geometric example.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Multiply the matrices and use the addition formulas: the $(1, 1)$ entry is $\cos 2\beta \cos 2\alpha + \sin 2\beta \sin 2\alpha = \cos 2(\beta - \alpha)$, and similarly for the others. Reflecting in the $x$-axis and then in the line $y = x$ is rotation by $90^\circ$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (programming).&lt;/strong&gt; Write a Python function returning the $3 \times 3$ homogeneous matrix of “rotate by $\theta$ about the point $c$” (translate $c$ to the origin, rotate, translate back). Check that $c$ stays fixed.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$M = T(c)\, R(\theta)\, T(-c)$, where $T(c)$ is the translation matrix. $M(c_1, c_2, 1) = (c_1, c_2, 1)$ because $T(-c)$ moves $c$ to the origin and the rotation fixes the origin.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$\mathbb{R}^2$: rotation $R_\theta$ ($\det 1$), reflection $H_\theta = 2uu^T - I$ ($\det -1$), scaling, shear ($\det 1$), projection $uu^T$ ($\det 0$).&lt;/li&gt;
    &lt;li&gt;$\mathbb{R}^3$: rotation about a coordinate axis is a $2 \times 2$ block plus a 1; projection and reflection in a plane: $I - nn^T$, $I - 2nn^T$.&lt;/li&gt;
    &lt;li&gt;Projection: $A^2 = A$; reflection: $A^2 = I$; rotations and reflections keep lengths.&lt;/li&gt;
    &lt;li&gt;Homogeneous coordinates turn translations into matrix multiplication.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Matrices in different bases and similar matrices</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter06/06_05_Ma_Tran_Dong_Dang/"/>
   <updated>2026-01-06T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter06/06_05_Ma_Tran_Dong_Dang</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;compute the matrix of an operator in a new basis with $[T]_B = P^{-1} A P$;&lt;/li&gt;
    &lt;li&gt;go the other way: build the standard matrix from the matrix in a “good” basis;&lt;/li&gt;
    &lt;li&gt;prove that similar matrices have the same determinant, trace and rank;&lt;/li&gt;
    &lt;li&gt;explain why a well-chosen basis makes a matrix simpler.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;What does $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$ do to the plane? The columns do not say much. But try two special vectors: $A(1, 1) = (3, 3) = 3(1, 1)$ and $A(1, -1) = (1, -1)$. So $A$ stretches by 3 along the diagonal $y = x$ and leaves the diagonal $y = -x$ unchanged. In the basis $B = \{(1, 1), (1, -1)\}$ the map is just&lt;/p&gt;

\[[T]_B = \begin{bmatrix} 3 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix} .\]

&lt;p&gt;Same transformation, but with the right axes the matrix leaves almost nothing to compute.&lt;/p&gt;

&lt;h2 id=&quot;change-of-basis-for-operators&quot;&gt;Change of basis for operators&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; Let $T : \mathbb{R}^n \to \mathbb{R}^n$ have standard matrix $A$, and let $B = \{b_1, \dots, b_n\}$ be a basis. Put $P = [b_1\ \cdots\ b_n]$. Then&lt;/p&gt;

\[[T]_B = P^{-1} A P, \qquad A = P\, [T]_B\, P^{-1} .\]

  &lt;p&gt;More generally, for an operator $T$ on $V$ and bases $B, C$: $[T]_B = P^{-1} [T]_C P$ with $P = P_{C \leftarrow B}$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Write $T = \operatorname{id} \circ T \circ \operatorname{id}$ and apply Theorem 1 of Lesson 6.4 with bases $B \to C \to C \to B$:&lt;/p&gt;

\[[T]_{B \leftarrow B} = [\operatorname{id}]_{B \leftarrow C}\, [T]_{C \leftarrow C}\, [\operatorname{id}]_{C \leftarrow B} = P_{B \leftarrow C}\, [T]_C\, P_{C \leftarrow B} = P^{-1} [T]_C P,\]

  &lt;p&gt;since $P_{B \leftarrow C} = (P_{C \leftarrow B})^{-1}$ (Lesson 5.6). With $C$ the standard basis, $P_{C \leftarrow B}$ is the matrix with columns $b_i$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Read right to left: $P$ converts $B$-coordinates to standard coordinates, $A$ performs the transformation, $P^{-1}$ converts back to $B$-coordinates.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Similar matrices).&lt;/strong&gt; Two square matrices $A$, $A&apos;$ of the same size are &lt;em&gt;similar&lt;/em&gt; if $A&apos; = P^{-1} A P$ for some invertible $P$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;By Theorem 1, two similar matrices are the matrices of &lt;em&gt;the same&lt;/em&gt; operator in two bases.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2.&lt;/strong&gt; If $A$ and $A&apos;$ are similar, then $\det A&apos; = \det A$, $\operatorname{tr} A&apos; = \operatorname{tr} A$ and $\operatorname{rank} A&apos; = \operatorname{rank} A$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Determinant: Corollary 1 of Lesson 4.5. Trace: for any $X, Y$ of the same size, $\operatorname{tr}(XY) = \sum_{i,k} x_{ik} y_{ki} = \operatorname{tr}(YX)$; with $X = P^{-1}$, $Y = AP$ we get $\operatorname{tr}(P^{-1}AP) = \operatorname{tr}(APP^{-1}) = \operatorname{tr} A$. Rank: $A$ and $A&apos;$ are matrices of the same operator $T$, and the rank is $\dim \operatorname{im} T$, which does not depend on the basis.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Quantities that do not change under a change of basis are properties of the &lt;em&gt;transformation&lt;/em&gt;, not of the coordinates. The determinant is the volume scaling factor, so of course it does not depend on the axes.&lt;/p&gt;

&lt;h2 id=&quot;examples&quot;&gt;Examples&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; For $A$ in the motivating example and $P = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix}$, $P^{-1} = \tfrac12 \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix}$:&lt;/p&gt;

\[P^{-1} A P = \tfrac12 \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix} \begin{bmatrix} 3 &amp;amp; 1 \\ 3 &amp;amp; -1 \end{bmatrix} = \begin{bmatrix} 3 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix} .\]

  &lt;p&gt;Checking Theorem 2: $\det = 3$ and $\operatorname{tr} = 4$ for both matrices.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (projection onto a line).&lt;/strong&gt; Find the standard matrix of orthogonal projection onto the line $y = 2x$. Choose a good basis: $b_1 = (1, 2)$ on the line (kept), $b_2 = (-2, 1)$ perpendicular to it (sent to 0). So $[T]_B = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix}$ and, with $P = \begin{bmatrix} 1 &amp;amp; -2 \\ 2 &amp;amp; 1 \end{bmatrix}$, $P^{-1} = \tfrac15 \begin{bmatrix} 1 &amp;amp; 2 \\ -2 &amp;amp; 1 \end{bmatrix}$:&lt;/p&gt;

\[A = P \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix} P^{-1} = \frac15 \begin{bmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 4 \end{bmatrix} .\]

  &lt;p&gt;Check: $A(1, 2) = (1, 2)$, $A(-2, 1) = (0, 0)$, $\det A = 0$, $\operatorname{tr} A = 1$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3 (reflection).&lt;/strong&gt; Reflection in the same line $y = 2x$ keeps $b_1$ and negates $b_2$, so $[T]_B = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; -1 \end{bmatrix}$ and&lt;/p&gt;

\[A = P \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; -1 \end{bmatrix} P^{-1} = \frac15 \begin{bmatrix} -3 &amp;amp; 4 \\ 4 &amp;amp; 3 \end{bmatrix} .\]

  &lt;p&gt;$\det A = -1$ (orientation flipped), $\operatorname{tr} A = 0$, as for $\operatorname{diag}(1, -1)$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-choosing-axes-that-fit-the-problem&quot;&gt;Application: choosing axes that fit the problem&lt;/h2&gt;

&lt;p&gt;An engineer analysing stress in a steel plate does not use fixed $x, y$ axes, but looks for the &lt;em&gt;principal axes&lt;/em&gt;, where the stress matrix is diagonal: along those directions the material is only stretched or compressed, not sheared. In statistics, PCA (Chapter 11) chooses axes along the directions in which the data vary most. Both are the problem of finding a basis $B$ in which $P^{-1}AP$ is diagonal, as in the motivating example. The vectors $(1, 1)$ and $(1, -1)$ there are &lt;em&gt;eigenvectors&lt;/em&gt; and the numbers 3 and 1 are &lt;em&gt;eigenvalues&lt;/em&gt;; Chapter 9 shows how to find them systematically.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: similar matrices P⁻¹AP&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;The same map written in the basis {p₁, p₂}; trace and determinant stay the same.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=similar&amp;amp;lang=en&quot; title=&quot;Interactive: similar matrices P⁻¹AP&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=similar&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Let $A = \begin{bmatrix} 4 &amp;amp; 1 \\ 2 &amp;amp; 3 \end{bmatrix}$ and $B = \{(1, 1), (1, -2)\}$. Compute $[T]_B = P^{-1}AP$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A(1, 1) = (5, 5)$, $A(1, -2) = (2, -4)$. So $[T]_B = \begin{bmatrix} 5 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Are $\begin{bmatrix} 1 &amp;amp; 2 \\ 0 &amp;amp; 3 \end{bmatrix}$ and $\begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 2 \end{bmatrix}$ similar?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

No: both traces are 4 but the determinants are 3 and 4. (Also $P^{-1}(2I)P = 2I$ for every $P$.)

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Find the standard matrices of orthogonal projection onto the line $y = x$ and of reflection in that line.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Projection: $\tfrac12 \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$. Reflection: $\begin{bmatrix} 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix}$ (matching Lesson 6.2).

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; Prove: if $A&apos; = P^{-1} A P$ then $A&apos;^k = P^{-1} A^k P$. Use Example 1 to compute $A^5$ for $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The inner pairs $PP^{-1}$ cancel. $A^5 = P \operatorname{diag}(243, 1) P^{-1} = \begin{bmatrix} 122 &amp;amp; 121 \\ 121 &amp;amp; 122 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Show that the projection matrix of Example 2 satisfies $A^2 = A$ and the reflection matrix of Example 3 satisfies $A^2 = I$, just by looking at $[T]_B$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\operatorname{diag}(1, 0)^2 = \operatorname{diag}(1, 0)$ and $\operatorname{diag}(1, -1)^2 = I$; use Exercise 4 with $k = 2$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;In the basis $B$ (columns of $P$): $[T]_B = P^{-1} A P$ and $A = P [T]_B P^{-1}$.&lt;/li&gt;
    &lt;li&gt;Similar matrices are matrices of the same operator in two bases; they share determinant, trace and rank.&lt;/li&gt;
    &lt;li&gt;A suitable basis (directions kept, directions killed) makes the matrix diagonal; this is the idea behind diagonalisation in Chapter 9.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Composition, inverses and isomorphisms</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter06/06_04_Hop_Nghich_Dao_Va_Dang_Cau/"/>
   <updated>2026-01-06T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter06/06_04_Hop_Nghich_Dao_Va_Dang_Cau</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;compute the matrix of a composition of linear maps as a matrix product;&lt;/li&gt;
    &lt;li&gt;check whether a linear map is invertible and find its inverse;&lt;/li&gt;
    &lt;li&gt;define isomorphism and prove that two finite-dimensional spaces are isomorphic exactly when they have the same dimension;&lt;/li&gt;
    &lt;li&gt;use the coordinate isomorphism to move problems to $\mathbb{R}^n$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Rotating the plane by $\alpha$ and then by $\beta$ is rotating by $\alpha + \beta$. In matrices:&lt;/p&gt;

\[R_\beta R_\alpha = \begin{bmatrix} \cos\beta &amp;amp; -\sin\beta \\ \sin\beta &amp;amp; \cos\beta \end{bmatrix} \begin{bmatrix} \cos\alpha &amp;amp; -\sin\alpha \\ \sin\alpha &amp;amp; \cos\alpha \end{bmatrix} = \begin{bmatrix} \cos(\alpha + \beta) &amp;amp; -\sin(\alpha + \beta) \\ \sin(\alpha + \beta) &amp;amp; \cos(\alpha + \beta) \end{bmatrix} .\]

&lt;p&gt;Comparing the top-left entries: $\cos(\alpha + \beta) = \cos\beta\cos\alpha - \sin\beta\sin\alpha$. The trigonometric addition formula is just a product of two rotation matrices. And rotating by $-\alpha$ undoes rotating by $\alpha$: $R_{-\alpha} = R_\alpha^{-1}$.&lt;/p&gt;

&lt;h2 id=&quot;composition&quot;&gt;Composition&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; If $T : U \to V$ and $S : V \to W$ are linear, then $S \circ T$ is linear, and for bases $B, C, D$ of $U, V, W$:&lt;/p&gt;

  &lt;p&gt;\([S \circ T]_{D \leftarrow B} = [S]_{D \leftarrow C}\, [T]_{C \leftarrow B} .\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; $S(T(au + bv)) = S(aT(u) + bT(v)) = aS(T(u)) + bS(T(v))$. For every $u$, by Theorem 2 of Lesson 6.2: $[S(T(u))]_D = [S]_{D \leftarrow C} [T(u)]_C = [S]_{D \leftarrow C} [T]_{C \leftarrow B} [u]_B$. The matrix of $S \circ T$ is uniquely determined by this identity for all $[u]_B$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;This is why matrix multiplication was defined as in Lesson 3.1: it encodes composition of maps. Associativity $(AB)C = A(BC)$ also becomes obvious when viewed as composition.&lt;/p&gt;

&lt;h2 id=&quot;invertible-maps-and-isomorphisms&quot;&gt;Invertible maps and isomorphisms&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1.&lt;/strong&gt; A linear map $T : V \to W$ is &lt;em&gt;invertible&lt;/em&gt; if there is a map $T^{-1} : W \to V$ with $T^{-1} \circ T = \operatorname{id}_V$ and $T \circ T^{-1} = \operatorname{id}_W$. An invertible linear map is an &lt;em&gt;isomorphism&lt;/em&gt;. If there is an isomorphism from $V$ to $W$, we say $V$ and $W$ are &lt;em&gt;isomorphic&lt;/em&gt; and write $V \cong W$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2.&lt;/strong&gt;&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$T$ is invertible if and only if it is a bijection; then $T^{-1}$ is also linear.&lt;/li&gt;
    &lt;li&gt;If $\dim V = \dim W = n$ with bases $B, C$: $T$ is invertible $\iff [T]_{C \leftarrow B}$ is invertible, and $[T^{-1}]_{B \leftarrow C} = ([T]_{C \leftarrow B})^{-1}$.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; (1) A bijection has an inverse map (as sets). It is linear: with $w_1 = T(v_1)$, $w_2 = T(v_2)$ we have $T(av_1 + bv_2) = aw_1 + bw_2$, so $T^{-1}(aw_1 + bw_2) = av_1 + bv_2 = aT^{-1}(w_1) + bT^{-1}(w_2)$. (2) If $T$ is invertible, Theorem 1 gives $[T^{-1}][T] = [\operatorname{id}_V]_{B \leftarrow B} = I$, and similarly in the other order. Conversely, if $A = [T]$ is invertible then $\operatorname{Nul} A = \{0\}$, so $\ker T = \{0\}$, $T$ is one-to-one, and by Corollary 1 of Lesson 6.3 also onto.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 3.&lt;/strong&gt; Two finite-dimensional vector spaces are isomorphic if and only if they have the same dimension. In particular, every $n$-dimensional space is isomorphic to $\mathbb{R}^n$ via the coordinate map $v \mapsto [v]_B$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; If $T : V \to W$ is an isomorphism, then $\ker T = \{0\}$ and $\operatorname{im} T = W$, so by Theorem 2 of Lesson 6.3, $\dim V = 0 + \dim W$. Conversely, if $\dim V = \dim W = n$ with bases $b_1, \dots, b_n$ and $c_1, \dots, c_n$, the linear map with $T(b_i) = c_i$ (Theorem 2 of Lesson 6.1) has matrix $I$ in these bases, so it is invertible.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Meaning: as far as linear algebra is concerned, $P_3$, $M_{2 \times 2}$ and $\mathbb{R}^4$ are “the same space” under three names. Every question about independence, span or bases in $P_3$ can be solved with matrices in $\mathbb{R}^4$, as we did in Lessons 5.6 and 5.7.&lt;/p&gt;

&lt;h2 id=&quot;examples&quot;&gt;Examples&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; $T(x, y) = (x + y,\ x - y)$ with matrix $A = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix}$, $\det A = -2 \ne 0$. The inverse is $A^{-1} = \tfrac12 \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix}$, i.e. $T^{-1}(u, v) = \big(\tfrac{u + v}{2}, \tfrac{u - v}{2}\big)$. Check: $T^{-1}(T(3, 1)) = T^{-1}(4, 2) = (3, 1)$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; $T : P_2 \to \mathbb{R}^3$, $T(p) = (p(0), p(1), p(2))$ is an isomorphism (Exercise 5, Lesson 6.3). Its inverse gives the interpolating polynomial: $T^{-1}(a, b, c) = aL_0 + bL_1 + cL_2$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3 (not invertible).&lt;/strong&gt; The projection $P(x, y) = (x, 0)$ is not invertible: $\det = 0$, and geometrically we cannot tell which point of the vertical line through a point of the $x$-axis it came from. The composition $P \circ P = P$: projecting twice is the same as projecting once.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-undo-and-encryption&quot;&gt;Application: undo and encryption&lt;/h2&gt;

&lt;p&gt;In image editing software, rotations, flips and scalings are isomorphisms, so they can be undone exactly with the inverse matrix. “Flattening” an image onto a line (a projection) cannot: the information is gone into the kernel. In the Hill cipher (Lessons 3.3, 4.3) the key $K$ must be an isomorphism of $(\mathbb{Z}_{26})^n$ for the receiver to decrypt; a key whose $\det K$ is not invertible modulo 26 sends two different plaintexts to the same ciphertext.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: the inverse map&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag t to let A⁻¹ undo the warp; when det A = 0 there is no inverse.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=inverse&amp;amp;lang=en&quot; title=&quot;Interactive: the inverse map&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=inverse&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Let $T(x, y) = (2x + y,\ x + y)$. Find $T^{-1}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\det = 1$, $A^{-1} = \begin{bmatrix} 1 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{bmatrix}$: $T^{-1}(u, v) = (u - v,\ -u + 2v)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Use $R_\alpha R_\alpha = R_{2\alpha}$ to derive the formulas for $\sin 2\alpha$ and $\cos 2\alpha$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Squaring the rotation matrix: $\cos 2\alpha = \cos^2\alpha - \sin^2\alpha$, $\sin 2\alpha = 2\sin\alpha\cos\alpha$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Which of these are isomorphic: $\mathbb{R}^6$, $P_5$, $M_{2 \times 3}$, the symmetric $3 \times 3$ matrices, $P_6$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The first four all have dimension 6, so they are isomorphic to each other. $P_6$ has dimension 7.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; Let $T : P_2 \to P_2$, $T(p) = p + p&apos;$. Prove $T$ is an isomorphism and find $T^{-1}(x^2)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Its matrix in $\{1, x, x^2\}$ is $\begin{bmatrix} 1 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 2 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$, triangular with ones on the diagonal, hence invertible. Solving $p + p&apos; = x^2$: $p = x^2 - 2x + 2$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Let $S, T$ be operators on a finite-dimensional $V$ with $S \circ T = \operatorname{id}$. Prove $T \circ S = \operatorname{id}$. Does this hold on $F(\mathbb{R})$ or on the space of all polynomials?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$S \circ T = \operatorname{id}$ makes $T$ one-to-one, so (equal dimensions) $T$ is an isomorphism and $S = T^{-1}$. In infinite dimensions it fails: on all polynomials, $D \circ J = \operatorname{id}$ with $J(p) = \int_0^x p$, but $J \circ D \ne \operatorname{id}$ since $J(D(1)) = 0$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;The matrix of $S \circ T$ is $[S][T]$; matrix multiplication encodes composition.&lt;/li&gt;
    &lt;li&gt;$T$ is invertible $\iff$ bijective $\iff$ (with equal dimensions) its matrix is invertible; $[T^{-1}] = [T]^{-1}$.&lt;/li&gt;
    &lt;li&gt;$V \cong W \iff \dim V = \dim W$; every $n$-dimensional space is isomorphic to $\mathbb{R}^n$ via coordinates.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Kernel and image</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter06/06_03_Hat_Nhan_Va_Anh/"/>
   <updated>2026-01-06T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter06/06_03_Hat_Nhan_Va_Anh</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;find the kernel and image of a linear map and bases for them;&lt;/li&gt;
    &lt;li&gt;use the kernel to test one-to-one and the image to test onto;&lt;/li&gt;
    &lt;li&gt;apply $\dim V = \dim \ker T + \dim \operatorname{im} T$;&lt;/li&gt;
    &lt;li&gt;explain why a map from a larger space to a smaller one cannot be one-to-one.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;A camera turns a 3D scene into a 2D picture. The simplest model is parallel projection: $T(x, y, z) = (x, y)$, dropping the depth $z$. All points on a vertical line of sight $(x_0, y_0, z)$ give the same image point; in particular the points $(0, 0, z)$ go to the origin. That line, the $z$-axis, is the information lost: the &lt;em&gt;kernel&lt;/em&gt;. Meanwhile every point of the image plane comes from some 3D point: the &lt;em&gt;image&lt;/em&gt; is all of $\mathbb{R}^2$. One dimension lost, two kept: $1 + 2 = 3$.&lt;/p&gt;

&lt;h2 id=&quot;definition&quot;&gt;Definition&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1.&lt;/strong&gt; Let $T : V \to W$ be linear.&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;&lt;em&gt;Kernel&lt;/em&gt;: $\ker T = \{v \in V : T(v) = 0\}$.&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;Image&lt;/em&gt;: $\operatorname{im} T = \{T(v) : v \in V\}$.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;For $T(x) = Ax$: $\ker T = \operatorname{Nul} A$ and $\operatorname{im} T = \operatorname{Col} A$ (Lesson 5.4).&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; $\ker T$ is a subspace of $V$ and $\operatorname{im} T$ is a subspace of $W$. Moreover, $T$ is one-to-one if and only if $\ker T = \{0\}$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; $T(0) = 0$, so $0$ is in both. If $T(u) = T(v) = 0$ then $T(au + bv) = 0$. If $w_1 = T(v_1)$ and $w_2 = T(v_2)$ then $aw_1 + bw_2 = T(av_1 + bv_2) \in \operatorname{im} T$.&lt;/p&gt;

  &lt;p&gt;If $T$ is one-to-one and $T(v) = 0 = T(0)$, then $v = 0$. Conversely, if $\ker T = \{0\}$ and $T(u) = T(v)$, then $T(u - v) = 0$, so $u - v = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Meaning: for a linear map it is enough to check whether some nonzero vector goes to 0. Two points $u, v$ have the same image exactly when $u - v \in \ker T$: each “fibre” $\{v : T(v) = w\}$ is a translated copy of the kernel, like the general solution $x_p + \operatorname{Nul} A$ in Lesson 2.5.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2 (Rank–nullity for maps).&lt;/strong&gt; If $V$ is finite-dimensional, then&lt;/p&gt;

  &lt;p&gt;\(\dim V = \dim \ker T + \dim \operatorname{im} T .\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Take a basis $B$ of $V$ ($\dim V = n$) and a basis $C$ of $\operatorname{im} T$ or of $W$ (finite-dimensional, since $\operatorname{im} T$ is spanned by $T(b_1), \dots, T(b_n)$). Let $A = [T]_{C \leftarrow B}$. By Theorem 2 of Lesson 6.2, $v \in \ker T \iff [v]_B \in \operatorname{Nul} A$ and $w \in \operatorname{im} T \iff [w]_C \in \operatorname{Col} A$. Taking coordinates preserves dimension (Theorem 1 of Lesson 5.6), so apply Theorem 1 of Lesson 5.5 to $A$ (which has $n$ columns).&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Corollary 1.&lt;/strong&gt; Let $\dim V = n$, $\dim W = m$.&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;If $n &amp;gt; m$, $T$ is not one-to-one. If $n &amp;lt; m$, $T$ is not onto.&lt;/li&gt;
    &lt;li&gt;If $n = m$, $T$ is one-to-one $\iff$ $T$ is onto.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; (1) $\dim \operatorname{im} T \le m &amp;lt; n$ gives $\dim \ker T \ge 1$; $\dim \operatorname{im} T \le n &amp;lt; m$ gives $\operatorname{im} T \ne W$. (2) $\ker T = \{0\} \iff \dim \operatorname{im} T = n = m \iff \operatorname{im} T = W$ (Theorem 3(4), Lesson 5.3).&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;examples&quot;&gt;Examples&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; $T : \mathbb{R}^3 \to \mathbb{R}^2$, $T(x, y, z) = (x + y,\ y + z)$, with matrix $\begin{bmatrix} 1 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 1 \end{bmatrix}$. Solve $T(x) = 0$: $z = t$, $y = -t$, $x = t$, so $\ker T = \operatorname{span}\{(1, -1, 1)\}$, of dimension 1. By Theorem 2, $\dim \operatorname{im} T = 2$, so $\operatorname{im} T = \mathbb{R}^2$. $T$ is onto but not one-to-one: $(0, 0, 0)$ and $(1, -1, 1)$ both go to $(0, 0)$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (a projection).&lt;/strong&gt; $P(x, y) = (x, 0)$ on $\mathbb{R}^2$. $\ker P$ is the $y$-axis, $\operatorname{im} P$ the $x$-axis, $1 + 1 = 2$. Each vertical line (parallel to the kernel) is squashed to one point of the $x$-axis.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3 (differentiation).&lt;/strong&gt; $D : P_3 \to P_3$. $\ker D$ is the constants (dimension 1), $\operatorname{im} D = P_2$ (dimension 3), $1 + 3 = 4 = \dim P_3$. $D$ is not one-to-one, and since the dimensions agree it is not onto either: $x^3$ is not the derivative of any polynomial of degree $\le 3$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-information-lost-in-compression-and-measurement&quot;&gt;Application: information lost in compression and measurement&lt;/h2&gt;

&lt;p&gt;Every linear measurement, such as a sensor reporting the sum or average of several quantities, is a map $T$. The kernel is the set of changes the sensor cannot see. For example, an X-ray picture records the total density along each ray: two bodies that differ by a vector in the kernel give the same picture. That is why CT scanning takes pictures from many angles: combining many projections gives a map with kernel $\{0\}$, so the object can be reconstructed. In lossy compression we deliberately choose $T$ whose kernel contains the less important components.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: kernel and image of a map ℝ³ → ℝ²&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Orbit ℝ³ to see ker T; moving x along ker T leaves T(x) unchanged.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter06/hat_nhan_anh.html?lang=en&quot; title=&quot;Interactive: kernel and image of a map ℝ³ → ℝ²&quot; loading=&quot;lazy&quot; style=&quot;height: 700px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter06/hat_nhan_anh.html?lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-squashing-a-cube-onto-a-plane&quot;&gt;Short video: Squashing a cube onto a plane&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/rank-nullity-3d.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;T(x, y, z) = (x − z; y − z) pushes every point along the direction (1; 1; 1) down to the floor. The kernel is the line t(1; 1; 1), squashed to the origin; each parallel line becomes one point, and the cube becomes a flat hexagon: dim ker T + dim im T = 1 + 2 = 3. Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Find the kernel and image of rotating by $60^\circ$ then reflecting in $y = x$ (Lesson 6.2).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The determinant is $-1 \ne 0$, so $\ker = \{0\}$ and $\operatorname{im} = \mathbb{R}^2$: a bijection.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Find bases of the kernel and image of $T(x, y, z) = (x - y,\ 2x - 2y,\ z)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\ker$: $(1, 1, 0)$. $\operatorname{im}$: $\operatorname{span}\{(1, 2, 0), (0, 0, 1)\}$. $1 + 2 = 3$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Find the kernel and image of $\operatorname{tr} : M_{2 \times 2} \to \mathbb{R}$ and their dimensions.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The image is $\mathbb{R}$ (since $\operatorname{tr}(cE_{11}) = c$), dimension 1. The kernel is the trace-zero matrices, dimension $4 - 1 = 3$, with basis $E_{12}, E_{21}, E_{11} - E_{22}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; Is there a one-to-one linear map $T : \mathbb{R}^4 \to \mathbb{R}^3$? Is there a linear map on $\mathbb{R}^3$ with $\ker T = \operatorname{im} T$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

No one-to-one map, since $4 &amp;gt; 3$. No: if $\dim \ker = \dim \operatorname{im} = k$ then $2k = 3$, impossible. (On $\mathbb{R}^2$ there is one, e.g. $T(x, y) = (y, 0)$.)

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Let $T : P_2 \to \mathbb{R}^3$, $T(p) = (p(0), p(1), p(2))$. Prove that $T$ is a bijection and explain the link with Lesson 5.7.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

If $T(p) = 0$, a polynomial of degree $\le 2$ has three roots, so $p = 0$. The dimensions are both 3, so $T$ is onto. $T^{-1}(a, b, c) = aL_0 + bL_1 + cL_2$ with the Lagrange basis.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$\ker T = \{v : T(v) = 0\}$ and $\operatorname{im} T$ are subspaces; for a matrix: $\operatorname{Nul} A$, $\operatorname{Col} A$.&lt;/li&gt;
    &lt;li&gt;$T$ is one-to-one $\iff \ker T = \{0\}$; $T$ is onto $\iff \operatorname{im} T = W$.&lt;/li&gt;
    &lt;li&gt;$\dim V = \dim \ker T + \dim \operatorname{im} T$.&lt;/li&gt;
    &lt;li&gt;Equal dimensions: one-to-one $\iff$ onto. From a larger space to a smaller one: never one-to-one.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>The matrix of a linear map</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter06/06_02_Ma_Tran_Cua_Anh_Xa_Tuyen_Tinh/"/>
   <updated>2026-01-06T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter06/06_02_Ma_Tran_Cua_Anh_Xa_Tuyen_Tinh</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;write the standard matrix of a linear map $\mathbb{R}^n \to \mathbb{R}^m$ from the images of $e_1, \dots, e_n$;&lt;/li&gt;
    &lt;li&gt;write the matrix of a linear map relative to any pair of bases;&lt;/li&gt;
    &lt;li&gt;use the matrix to compute the image of a vector;&lt;/li&gt;
    &lt;li&gt;read the geometry of a transformation from the columns of its matrix.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Rotation by $60^\circ$ sends $e_1 = (1, 0)$ to $(\cos 60^\circ, \sin 60^\circ) = (\tfrac12, \tfrac{\sqrt3}{2})$ and $e_2 = (0, 1)$ to $(-\sin 60^\circ, \cos 60^\circ) = (-\tfrac{\sqrt3}{2}, \tfrac12)$. Any vector $(x, y) = x e_1 + y e_2$ goes to $x T(e_1) + y T(e_2)$ (Lesson 6.1). In matrix form:&lt;/p&gt;

\[T(x, y) = \begin{bmatrix} 1/2 &amp;amp; -\sqrt3/2 \\ \sqrt3/2 &amp;amp; 1/2 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} .\]

&lt;p&gt;The two columns of the matrix are exactly the image vectors $T(e_1)$, $T(e_2)$. Knowing where those two arrows go means knowing where the whole grid goes.&lt;/p&gt;

&lt;h2 id=&quot;the-standard-matrix&quot;&gt;The standard matrix&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Standard matrix).&lt;/strong&gt; Every linear map $T : \mathbb{R}^n \to \mathbb{R}^m$ has the form $T(x) = Ax$ for exactly one $m \times n$ matrix $A$, namely&lt;/p&gt;

  &lt;p&gt;\(A = \big[\, T(e_1) \ \ T(e_2) \ \ \cdots \ \ T(e_n) \,\big] .\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; For $x = \sum x_j e_j$, $T(x) = \sum x_j T(e_j)$, which is $Ax$ in the “combination of columns” view of Lesson 3.2. If $Bx = T(x)$ for all $x$, then $Be_j = T(e_j)$, so column $j$ of $B$ equals column $j$ of $A$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; Reflection in the line $y = x$ swaps the coordinates: $e_1 \mapsto e_2$, $e_2 \mapsto e_1$, so its matrix is $F = \begin{bmatrix} 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix}$. “Rotate by $60^\circ$, then reflect” has matrix $FR$ (R is applied first, so it stands on the right):&lt;/p&gt;

\[FR = \begin{bmatrix} \sqrt3/2 &amp;amp; 1/2 \\ 1/2 &amp;amp; -\sqrt3/2 \end{bmatrix} .\]

  &lt;p&gt;Its determinant is $-1$: area is kept and orientation is flipped (Lesson 4.5). In fact it is a reflection in another line (Lesson 6.6).&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; For $T$ from Example 3 of Lesson 6.1 ($T(1, 1) = (2, 0, 1)$, $T(1, -1) = (0, 2, 1)$): $e_1 = \tfrac12[(1, 1) + (1, -1)]$, so $T(e_1) = (1, 1, 1)$; $e_2 = \tfrac12[(1, 1) - (1, -1)]$, so $T(e_2) = (1, -1, 0)$. Hence&lt;/p&gt;

\[A = \begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; -1 \\ 1 &amp;amp; 0 \end{bmatrix}, \qquad A \begin{bmatrix} 5 \\ 1 \end{bmatrix} = \begin{bmatrix} 6 \\ 4 \\ 5 \end{bmatrix},\]

  &lt;p&gt;matching Lesson 6.1.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;the-matrix-relative-to-a-pair-of-bases&quot;&gt;The matrix relative to a pair of bases&lt;/h2&gt;

&lt;p&gt;A general space has no “standard coordinates”, so we must choose bases.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1.&lt;/strong&gt; Let $T : V \to W$ be linear, $B = \{b_1, \dots, b_n\}$ a basis of $V$ and $C$ a basis of $W$. The &lt;em&gt;matrix of $T$ relative to $B$ and $C$&lt;/em&gt; is&lt;/p&gt;

  &lt;p&gt;\([T]_{C \leftarrow B} = \big[\, [T(b_1)]_C \ \ \cdots \ \ [T(b_n)]_C \,\big] .\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2.&lt;/strong&gt; $[T(v)]_C = [T]_{C \leftarrow B}\, [v]_B$ for every $v \in V$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; If $[v]_B = (c_1, \dots, c_n)$ then $T(v) = \sum c_j T(b_j)$, so by Theorem 1 of Lesson 5.6, $[T(v)]_C = \sum c_j [T(b_j)]_C$, which is the matrix–vector product on the right.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The picture: going from $v$ to $T(v)$ in the original spaces corresponds to going from $[v]_B$ to $[T(v)]_C$ by matrix multiplication. The change-of-basis matrix of Lesson 5.6 is the special case $P_{C \leftarrow B} = [\operatorname{id}]_{C \leftarrow B}$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3.&lt;/strong&gt; $D : P_2 \to P_1$, $D(p) = p&apos;$, with $B = \{1, x, x^2\}$, $C = \{1, x\}$. $D(1) = 0$, $D(x) = 1$, $D(x^2) = 2x$:&lt;/p&gt;

\[[D]_{C \leftarrow B} = \begin{bmatrix} 0 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 2 \end{bmatrix} .\]

  &lt;p&gt;For $p = 5 - 3x + 4x^2$: $[D]\,(5, -3, 4) = (-3, 8)$, i.e. $p&apos; = -3 + 8x$. The matrix is $2 \times 3$ because $\dim P_1 = 2$ and $\dim P_2 = 3$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-computer-graphics&quot;&gt;Application: computer graphics&lt;/h2&gt;

&lt;p&gt;A 2D game draws thousands of vertices of a character every frame. To rotate, scale or flip the character, the program does not recompute each vertex with geometric formulas; it multiplies every vertex by a $2 \times 2$ matrix. Chaining several operations (rotate, then scale, then flip) means multiplying the matrices once in advance and applying the product to every vertex. Graphics cards are built to do exactly this very fast. Theorem 1 guarantees that every linear transformation can be handled this way, given only the images of $e_1, e_2$.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: the matrix of a linear map&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;The two columns are the images of e₁, e₂; try the samples: scaling, rotation, shear, reflection, projection.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=map&amp;amp;lang=en&quot; title=&quot;Interactive: the matrix of a linear map&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=map&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-the-images-of-the-basis-give-the-columns&quot;&gt;Short video: The images of the basis give the columns&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/basis-images-columns.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Drag e₁ and column 1 of the matrix follows, drag e₂ and column 2 follows, with the whole grid along: M = [T(e₁) T(e₂)]. Then a 30° rotation, the reflection across y = x, a shear and the projection onto the x-axis in turn. Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Write the standard matrix of $T(x, y, z) = (x - 2z,\ 3y + z)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\begin{bmatrix} 1 &amp;amp; 0 &amp;amp; -2 \\ 0 &amp;amp; 3 &amp;amp; 1 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Write the matrix of rotating by $60^\circ$ then reflecting in $y = x$, and of reflecting first then rotating. Are they equal?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$FR = \begin{bmatrix} \sqrt3/2 &amp;amp; 1/2 \\ 1/2 &amp;amp; -\sqrt3/2 \end{bmatrix}$, $RF = \begin{bmatrix} -\sqrt3/2 &amp;amp; 1/2 \\ 1/2 &amp;amp; \sqrt3/2 \end{bmatrix}$. They differ.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Find the matrix of $T : M_{2 \times 2} \to M_{2 \times 2}$, $T(A) = A^T$, in the basis $\{E_{11}, E_{12}, E_{21}, E_{22}\}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$E_{12} \leftrightarrow E_{21}$ and $E_{11}, E_{22}$ stay: $\begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; Find the matrix of $I : P_2 \to \mathbb{R}$, $I(p) = \int_0^1 p(x)\,dx$, relative to $\{1, x, x^2\}$ and $\{1\}$. Compute $I(3 - 6x + x^2)$ with the matrix.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$[1\ \ \tfrac12\ \ \tfrac13]$. $3 - 3 + \tfrac13 = \tfrac13$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (programming).&lt;/strong&gt; With Matplotlib, draw the unit square and its images under five matrices: rotation by $60^\circ$, reflection in $y = x$, scaling $\operatorname{diag}(2, \tfrac12)$, the shear $\begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \end{bmatrix}$, projection onto the $x$-axis.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Store the four corners as a $2 \times 4$ matrix `S` and plot `A @ S` for each `A`. The image under the projection is the segment $[0, 1]$ on the $x$-axis (area 0, matching $\det = 0$).

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Standard matrix: column $j$ is $T(e_j)$; $T(x) = Ax$.&lt;/li&gt;
    &lt;li&gt;Relative to bases $B, C$: column $j$ of $[T]_{C \leftarrow B}$ is $[T(b_j)]_C$, and $[T(v)]_C = [T]_{C \leftarrow B} [v]_B$.&lt;/li&gt;
    &lt;li&gt;Composing transformations is multiplying matrices, with the map applied first on the right.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Linear maps: definition and examples</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter06/06_01_Dinh_Nghia_Va_Vi_Du/"/>
   <updated>2026-01-06T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter06/06_01_Dinh_Nghia_Va_Vi_Du</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;state the definition of a linear map and check whether a map is linear;&lt;/li&gt;
    &lt;li&gt;give examples of linear maps on $\mathbb{R}^n$, polynomials and matrices, and nonlinear examples;&lt;/li&gt;
    &lt;li&gt;use $T(0) = 0$ to rule out non-linear maps quickly;&lt;/li&gt;
    &lt;li&gt;compute $T(v)$ from the images of basis vectors.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Rotating the plane by $90^\circ$ about the origin sends $(x, y)$ to $(-y, x)$. Rotating a sum of two vectors is the same as rotating each and adding: the parallelogram spanned by $u, v$ rotates as a whole, so its diagonal $u + v$ goes with it. Doubling a vector and then rotating is the same as rotating and then doubling. After the rotation the coordinate grid is still a grid: parallel, evenly spaced lines stay parallel and evenly spaced.&lt;/p&gt;

&lt;p&gt;By contrast, $f(x, y) = (x^2, y)$ bends the grid: the vertical lines $x = 1$ and $x = 2$ go to $x = 1$ and $x = 4$, no longer evenly spaced. This lesson turns the “keeps the grid” property into a definition.&lt;/p&gt;

&lt;h2 id=&quot;definition&quot;&gt;Definition&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Linear map).&lt;/strong&gt; Let $V, W$ be vector spaces. A map $T : V \to W$ is &lt;em&gt;linear&lt;/em&gt; if for all $u, v \in V$ and all $c \in \mathbb{R}$:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$T(u + v) = T(u) + T(v)$;&lt;/li&gt;
    &lt;li&gt;$T(cv) = c\,T(v)$.&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;When $V = W$, $T$ is also called a &lt;em&gt;linear operator&lt;/em&gt; (or linear transformation) on $V$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; If $T$ is linear, then $T(0) = 0$, $T(-v) = -T(v)$, and&lt;/p&gt;

\[T(c_1 v_1 + \dots + c_k v_k) = c_1 T(v_1) + \dots + c_k T(v_k) .\]

  &lt;p&gt;Conversely, if $T(au + bv) = aT(u) + bT(v)$ for all $a, b, u, v$, then $T$ is linear.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; $T(0) = T(0 \cdot 0) = 0 \cdot T(0) = 0$ (Lesson 5.1). $T(-v) = T((-1)v) = -T(v)$. The identity for $k$ vectors follows by induction: $T(\sum_{i&amp;lt;k} c_i v_i + c_k v_k) = T(\sum_{i&amp;lt;k} c_i v_i) + c_k T(v_k)$. Conversely, $a = b = 1$ gives condition 1 and $b = 0$ gives condition 2.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;“A linear map sends linear combinations to linear combinations with the same coefficients” is the shortest way to remember it.&lt;/p&gt;

&lt;h2 id=&quot;examples&quot;&gt;Examples&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (linear).&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;Every $m \times n$ matrix $A$ gives a map $T(x) = Ax$ from $\mathbb{R}^n$ to $\mathbb{R}^m$: $A(u + v) = Au + Av$, $A(cv) = cAv$ (Lesson 3.1).&lt;/li&gt;
    &lt;li&gt;Differentiation $D : P_3 \to P_2$, $D(p) = p&apos;$.&lt;/li&gt;
    &lt;li&gt;Integration $I : P_2 \to \mathbb{R}$, $I(p) = \int_0^1 p(x)\,dx$.&lt;/li&gt;
    &lt;li&gt;The trace $\operatorname{tr} : M_{n \times n} \to \mathbb{R}$ and the transpose $A \mapsto A^T$ on $M_{m \times n}$.&lt;/li&gt;
    &lt;li&gt;Evaluation $p \mapsto p(2)$ from $P_n$ to $\mathbb{R}$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (not linear).&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;The translation $T(x, y) = (x + 1, y)$: $T(0, 0) = (1, 0) \ne 0$. Ruled out at once.&lt;/li&gt;
    &lt;li&gt;$f(x, y) = (x^2, y)$: $f(0) = 0$ but $f(2 \cdot (1, 0)) = (4, 0) \ne 2 f(1, 0) = (2, 0)$.&lt;/li&gt;
    &lt;li&gt;$g(x, y) = (xy, x)$: $g(1, 1) + g(1, 1) = (2, 2)$ but $g(2, 2) = (4, 2)$.&lt;/li&gt;
    &lt;li&gt;The determinant $\det : M_{2 \times 2} \to \mathbb{R}$: $\det(2I) = 4 \ne 2 \det I$. The determinant is linear in each row (Lesson 4.2) but not in the whole matrix.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;The condition $T(0) = 0$ is necessary but not sufficient: $f$ and $g$ both fix the origin.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;determined-by-the-images-of-a-basis&quot;&gt;Determined by the images of a basis&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2.&lt;/strong&gt; Let $\{b_1, \dots, b_n\}$ be a basis of $V$ and $w_1, \dots, w_n$ any vectors of $W$. There is exactly one linear map $T : V \to W$ with $T(b_i) = w_i$ for all $i$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; &lt;em&gt;Uniqueness:&lt;/em&gt; each $v = \sum c_i b_i$, so by Theorem 1 we must have $T(v) = \sum c_i w_i$. &lt;em&gt;Existence:&lt;/em&gt; define $T(v) = \sum c_i w_i$ with $(c_i) = [v]_B$. Since $[u + v]_B = [u]_B + [v]_B$ and $[cv]_B = c[v]_B$ (Lesson 5.6), $T$ is linear, and $T(b_i) = w_i$ because $[b_i]_B = e_i$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3.&lt;/strong&gt; A linear map $T : \mathbb{R}^2 \to \mathbb{R}^3$ has $T(1, 1) = (2, 0, 1)$ and $T(1, -1) = (0, 2, 1)$. Find $T(5, 1)$.&lt;/p&gt;

  &lt;p&gt;By Lesson 5.6, $(5, 1) = 3(1, 1) + 2(1, -1)$. So&lt;/p&gt;

\[T(5, 1) = 3(2, 0, 1) + 2(0, 2, 1) = (6, 4, 5) .\]

  &lt;p&gt;Just two image vectors determine $T$ on the whole plane.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-the-superposition-principle&quot;&gt;Application: the superposition principle&lt;/h2&gt;

&lt;p&gt;A linear physical system (an RLC circuit, an elastic beam under small deflections, an audio filter) is a linear map from “input” to “output”. Linearity is exactly the &lt;em&gt;superposition principle&lt;/em&gt;: the response to a sum of two signals is the sum of the responses; doubling the load doubles the deflection. So an engineer only needs to measure the response to a few basic signals (a basis, such as sine waves or unit impulses) to know the response to every signal, just as in Theorem 2. When the system is pushed too far (a beam bends a lot, a speaker distorts), linearity is lost; one then approximates the system near an operating point by its Jacobian matrix (Calculus course).&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: linear and nonlinear maps&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Pick T, drag u and v to test T(u + v) = T(u) + T(v); see the Jacobian of a nonlinear map.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter06/tuyen_tinh_hay_khong.html?lang=en&quot; title=&quot;Interactive: linear and nonlinear maps&quot; loading=&quot;lazy&quot; style=&quot;height: 660px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter06/tuyen_tinh_hay_khong.html?lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Which maps are linear? (a) $T(x, y) = (2x - y, 3y)$; (b) $T(x, y) = (x, y + 2)$; (c) $T(x, y) = (\lvert x \rvert, y)$; (d) $T(x, y, z) = x + y + z$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

(a) Yes. (b) No, $T(0) \ne 0$. (c) No: $T(-1, 0) = (1, 0) \ne -T(1, 0)$. (d) Yes.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Prove that $T(p) = p(0) + p&apos;(0)$ is a linear map from $P_2$ to $\mathbb{R}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$(ap + bq)(0) = ap(0) + bq(0)$ and $(ap + bq)&apos;(0) = ap&apos;(0) + bq&apos;(0)$; add them.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; $T : \mathbb{R}^2 \to \mathbb{R}^2$ is linear with $T(1, 2) = (3, 1)$, $T(0, 1) = (1, 1)$. Find $T(1, 0)$ and $T(x, y)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$(1, 0) = (1, 2) - 2(0, 1)$, so $T(1, 0) = (1, -1)$. $T(x, y) = xT(1,0) + yT(0,1) = (x + y,\ -x + y)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; Is there a linear map $T : \mathbb{R}^2 \to \mathbb{R}^2$ with $T(1, 1) = (1, 0)$ and $T(2, 2) = (0, 1)$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

No: we would need $T(2, 2) = 2T(1, 1) = (2, 0)$. Theorem 2 requires the $b_i$ to be a basis.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Prove: if $T$ is linear and $v_1, \dots, v_k$ are dependent, then $T(v_1), \dots, T(v_k)$ are dependent. Is the converse true?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Apply $T$ to a nontrivial relation $\sum c_i v_i = 0$ to get $\sum c_i T(v_i) = 0$. The converse is false: for $T = 0$ the image of every family is dependent.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$T$ is linear when $T(au + bv) = aT(u) + bT(v)$; then $T(0) = 0$.&lt;/li&gt;
    &lt;li&gt;Examples: $x \mapsto Ax$, differentiation, integration, trace, transpose. Non-examples: translation, squaring, the determinant.&lt;/li&gt;
    &lt;li&gt;A linear map is uniquely determined by the images of a basis, and those images can be chosen freely.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Không gian đa thức và không gian hàm</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter05/05_07_Khong_Gian_Da_Thuc_Va_Khong_Gian_Ham/"/>
   <updated>2026-01-05T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter05/05_07_Khong_Gian_Da_Thuc_Va_Khong_Gian_Ham</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;kiểm tra một họ hàm có độc lập tuyến tính không bằng cách thế điểm;&lt;/li&gt;
    &lt;li&gt;dùng cơ sở Lagrange để viết đa thức nội suy;&lt;/li&gt;
    &lt;li&gt;viết ma trận của phép đạo hàm trên $P_n$ và trên span của vài hàm mũ;&lt;/li&gt;
    &lt;li&gt;dùng ma trận đó để tính đạo hàm và nguyên hàm.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Phép đạo hàm biến $p(x) = 2 - x + 4x^2 + x^3$ thành $p&apos;(x) = -1 + 8x + 3x^2$. Ghi toạ độ trong cơ sở $\{1, x, x^2, x^3\}$: $(2, -1, 4, 1) \mapsto (-1, 8, 3, 0)$. Phép đạo hàm có tính chất $(ap + bq)&apos; = ap&apos; + bq&apos;$, giống hệt phép nhân ma trận. Vậy có ma trận $D$ cỡ $4 \times 4$ sao cho $D(2, -1, 4, 1) = (-1, 8, 3, 0)$, và một bài toán giải tích trở thành phép nhân ma trận.&lt;/p&gt;

&lt;h2 id=&quot;độc-lập-tuyến-tính-của-hàm&quot;&gt;Độc lập tuyến tính của hàm&lt;/h2&gt;

&lt;p&gt;Trong $F(\mathbb{R})$, đẳng thức $c_1 f_1 + \dots + c_k f_k = 0$ nghĩa là bằng 0 &lt;em&gt;tại mọi&lt;/em&gt; $x$. Để chứng minh độc lập, chỉ cần chọn $k$ điểm $x_1, \dots, x_k$ sao cho hệ $\sum_j c_j f_j(x_i) = 0$ chỉ có nghiệm tầm thường.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Nếu có các điểm $x_1, \dots, x_k$ sao cho ma trận $M = [f_j(x_i)]$ cỡ $k \times k$ khả nghịch, thì $f_1, \dots, f_k$ độc lập tuyến tính.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Nếu $\sum c_j f_j = 0$ thì tại riêng các điểm $x_i$ ta có $Mc = 0$, nên $c = 0$ vì $M$ khả nghịch.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Chiều ngược lại không đúng nếu chọn điểm kém: $\sin x$ và $\sin 2x$ độc lập, nhưng tại $x = 0$ và $x = \pi$ cả hai đều bằng 0.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; $e^x$ và $e^{2x}$ độc lập: tại $x = 0$ và $x = 1$, $M = \begin{bmatrix} 1 &amp;amp; 1 \\ e &amp;amp; e^2 \end{bmatrix}$ có $\det M = e^2 - e \ne 0$. Tương tự $\{1, \cos x, \sin x\}$ độc lập: tại $x = 0, \pi/2, \pi$ ma trận là $\begin{bmatrix} 1 &amp;amp; 1 &amp;amp; 0 \\ 1 &amp;amp; 0 &amp;amp; 1 \\ 1 &amp;amp; -1 &amp;amp; 0 \end{bmatrix}$, có định thức $2 \ne 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;cơ-sở-lagrange&quot;&gt;Cơ sở Lagrange&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; Với ba điểm $0, 1, 2$, đặt&lt;/p&gt;

\[L_0 = \tfrac12 (x - 1)(x - 2), \qquad L_1 = -x(x - 2), \qquad L_2 = \tfrac12 x(x - 1) .\]

  &lt;p&gt;Mỗi $L_i$ bằng 1 tại điểm $i$ và bằng 0 tại hai điểm còn lại. Theo Định lý 1 (ma trận $M = I$), ba đa thức này độc lập, nên là cơ sở của $P_2$. Toạ độ của $p$ trong cơ sở này chính là $(p(0), p(1), p(2))$. Ví dụ parabol qua $(0, 1)$, $(1, 2)$, $(2, 5)$ là $L_0 + 2L_1 + 5L_2 = 1 + x^2$, khớp với Bài tập 4 Bài 4.3, nhưng không cần giải hệ.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ma-trận-của-phép-đạo-hàm&quot;&gt;Ma trận của phép đạo hàm&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3.&lt;/strong&gt; Trên $P_3$ với cơ sở $\{1, x, x^2, x^3\}$: $D(1) = 0$, $D(x) = 1$, $D(x^2) = 2x$, $D(x^3) = 3x^2$. Ghi toạ độ các ảnh làm cột:&lt;/p&gt;

\[D = \begin{bmatrix} 0 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 2 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 3 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \end{bmatrix} .\]

  &lt;p&gt;Kiểm tra: $D(2, -1, 4, 1) = (-1, 8, 3, 0)$. Các tính chất của phép đạo hàm đọc được từ ma trận: $D$ có hạng 3, hạt nhân 1 chiều là các hằng số (đạo hàm bằng 0); $D^4 = 0$, đúng vì đạo hàm bốn lần đa thức bậc 3 cho 0; $D$ không khả nghịch, phản ánh việc nguyên hàm chỉ xác định sai khác một hằng số.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Trên span của $\{e^x, xe^x\}$: $D(e^x) = e^x$, $D(xe^x) = e^x + xe^x$, nên ma trận là $\begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \end{bmatrix}$, khả nghịch. Nghịch đảo $\begin{bmatrix} 1 &amp;amp; -1 \\ 0 &amp;amp; 1 \end{bmatrix}$ cho nguyên hàm: toạ độ $(0, 1)$ của $xe^x$ biến thành $(-1, 1)$, tức $\int x e^x\,dx = xe^x - e^x + C$. Không cần tích phân từng phần.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-chuỗi-fourier-và-xấp-xỉ-tín-hiệu&quot;&gt;Ứng dụng: chuỗi Fourier và xấp xỉ tín hiệu&lt;/h2&gt;

&lt;p&gt;Không gian các đa thức lượng giác $\operatorname{span}\{1, \cos x, \sin x, \dots, \cos Nx, \sin Nx\}$ có chiều $2N + 1$. Xấp xỉ một tín hiệu tuần hoàn (âm thanh, nhịp tim) bằng một phần tử của không gian này là ý tưởng của chuỗi Fourier: mỗi tín hiệu được mô tả bằng $2N + 1$ toạ độ. Trên không gian này, đạo hàm biến $\cos kx \mapsto -k \sin kx$ và $\sin kx \mapsto k \cos kx$, nên ma trận của nó gồm các khối $2 \times 2$ trên đường chéo. Chương 7 sẽ thêm tích vô hướng để tính các toạ độ đó bằng tích phân.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: cơ sở Lagrange của P₂&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo p(0), p(1), p(2); xem đa thức nội suy và toạ độ của nó theo hai cơ sở.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter05/lagrange.html&quot; title=&quot;Minh hoạ: cơ sở Lagrange của P₂&quot; loading=&quot;lazy&quot; style=&quot;height: 620px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter05/lagrange.html&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Chứng minh $1, x, x^2$ độc lập bằng cách thế ba điểm.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Tại $0, 1, 2$, ma trận là ma trận Vandermonde $\begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 \\ 1 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 4 \end{bmatrix}$ có định thức $2 \ne 0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Viết ma trận của phép đạo hàm trên $P_2$ với cơ sở $\{1, x, x^2\}$ và tìm hạng của nó.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\begin{bmatrix} 0 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 2 \\ 0 &amp;amp; 0 &amp;amp; 0 \end{bmatrix}$, hạng 2.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Họ $\{1, \cos^2 x, \sin^2 x\}$ có độc lập không?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Không: $\cos^2 x + \sin^2 x - 1 = 0$ với mọi $x$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Trên span của $\{e^{2x}, xe^{2x}\}$, viết ma trận của $D$ và dùng nghịch đảo để tìm $\int x e^{2x}\,dx$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$D = \begin{bmatrix} 2 &amp;amp; 1 \\ 0 &amp;amp; 2 \end{bmatrix}$, $D^{-1} = \tfrac14 \begin{bmatrix} 2 &amp;amp; -1 \\ 0 &amp;amp; 2 \end{bmatrix}$. Toạ độ $(0, 1) \mapsto (-\tfrac14, \tfrac12)$: $\int x e^{2x}\,dx = \tfrac12 x e^{2x} - \tfrac14 e^{2x} + C$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (lập trình).&lt;/strong&gt; Dùng SymPy, viết hàm nhận một danh sách đa thức trong $P_n$, trả về ma trận toạ độ và hạng của họ. Thử với $\{1 + x, x + x^2, 1 - x^2\}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Dùng `Poly(p, x).all_coeffs()` (đảo thứ tự) để lấy toạ độ. Họ này phụ thuộc: $(1 + x) - (x + x^2) = 1 - x^2$, hạng 2.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Hàm số là vectơ; để chứng minh độc lập, thế điểm và kiểm tra ma trận $[f_j(x_i)]$ khả nghịch.&lt;/li&gt;
    &lt;li&gt;Cơ sở Lagrange có toạ độ là giá trị tại các nút, cho đa thức nội suy ngay.&lt;/li&gt;
    &lt;li&gt;Phép đạo hàm có ma trận trên $P_n$ (hạng $n$, luỹ linh) và trên span các hàm mũ (khả nghịch, cho nguyên hàm).&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Toạ độ và đổi cơ sở</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter05/05_06_Toa_Do_Va_Doi_Co_So/"/>
   <updated>2026-01-05T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter05/05_06_Toa_Do_Va_Doi_Co_So</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;tính toạ độ $[v]_B$ của một vectơ trong cơ sở $B$;&lt;/li&gt;
    &lt;li&gt;lập ma trận chuyển cơ sở $P_{C \leftarrow B}$ và dùng nó để đổi toạ độ;&lt;/li&gt;
    &lt;li&gt;giải thích vì sao $P_{B \leftarrow C} = (P_{C \leftarrow B})^{-1}$;&lt;/li&gt;
    &lt;li&gt;áp dụng toạ độ cho không gian đa thức.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Điểm $v = (5, 1)$ trên mặt phẳng. Trong lưới chuẩn, ta đi 5 bước theo $e_1$ và 1 bước theo $e_2$. Giờ vẽ một lưới khác, với hai vectơ $b_1 = (1, 1)$ và $b_2 = (1, -1)$ (lưới xoay $45^\circ$ và giãn ra). Để tới cùng điểm $v$ theo lưới mới, ta giải $c_1 (1, 1) + c_2 (1, -1) = (5, 1)$: $c_1 + c_2 = 5$, $c_1 - c_2 = 1$, nên $c_1 = 3$, $c_2 = 2$. Điểm không đổi, chỉ có cách ghi địa chỉ thay đổi: $(5, 1)$ trong lưới chuẩn, $(3, 2)$ trong lưới mới.&lt;/p&gt;

&lt;h2 id=&quot;toạ-độ&quot;&gt;Toạ độ&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Toạ độ).&lt;/strong&gt; Cho $B = \{b_1, \dots, b_n\}$ là một cơ sở có thứ tự của $V$. Với $v = c_1 b_1 + \dots + c_n b_n$ (biểu diễn duy nhất, Bài 5.3), vectơ&lt;/p&gt;

\[[v]_B = (c_1, \dots, c_n) \in \mathbb{R}^n\]

  &lt;p&gt;gọi là &lt;em&gt;toạ độ&lt;/em&gt; của $v$ trong cơ sở $B$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Trong $\mathbb{R}^n$, gọi $B$ cũng là ma trận có các cột $b_1, \dots, b_n$. Khi đó $v = B[v]_B$, nên $[v]_B = B^{-1} v$. Ma trận $B$ khả nghịch vì các cột là cơ sở.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Ánh xạ $v \mapsto [v]_B$ bảo toàn phép toán: $[u + v]_B = [u]_B + [v]_B$ và $[cv]_B = c[v]_B$. Họ $v_1, \dots, v_k$ độc lập trong $V$ khi và chỉ khi $[v_1]_B, \dots, [v_k]_B$ độc lập trong $\mathbb{R}^n$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Nếu $u = \sum a_i b_i$, $v = \sum c_i b_i$ thì $u + v = \sum (a_i + c_i) b_i$ và $cv = \sum (c c_i) b_i$; theo tính duy nhất, đó là toạ độ của $u + v$ và $cv$. Từ đó $\sum x_j v_j = 0 \iff \sum x_j [v_j]_B = [0]_B = 0$, nên hai họ có cùng các quan hệ tuyến tính.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Định lý 1 cho phép chuyển mọi câu hỏi về không gian $n$ chiều bất kỳ (đa thức, ma trận) về $\mathbb{R}^n$ và khử Gauss.&lt;/p&gt;

&lt;h2 id=&quot;ma-trận-chuyển-cơ-sở&quot;&gt;Ma trận chuyển cơ sở&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2 (Đổi cơ sở).&lt;/strong&gt; Cho hai cơ sở $B = \{b_1, \dots, b_n\}$ và $C$ của $V$. Đặt&lt;/p&gt;

\[P_{C \leftarrow B} = \big[\, [b_1]_C \ \ [b_2]_C \ \ \cdots \ \ [b_n]_C \,\big] .\]

  &lt;p&gt;Khi đó $[v]_C = P_{C \leftarrow B}\, [v]_B$ với mọi $v$. Ma trận $P_{C \leftarrow B}$ khả nghịch và $(P_{C \leftarrow B})^{-1} = P_{B \leftarrow C}$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Nếu $[v]_B = (c_1, \dots, c_n)$ thì $v = \sum c_i b_i$, nên theo Định lý 1, $[v]_C = \sum c_i [b_i]_C = P_{C \leftarrow B} [v]_B$. Áp dụng hai lần: $[v]_B = P_{B \leftarrow C} P_{C \leftarrow B} [v]_B$ với mọi $v$, và $[v]_B$ chạy khắp $\mathbb{R}^n$, nên $P_{B \leftarrow C} P_{C \leftarrow B} = I$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Trong $\mathbb{R}^n$: $v = B[v]_B = C[v]_C$, nên $P_{C \leftarrow B} = C^{-1} B$. Cách nhớ: cột của ma trận chuyển là &lt;em&gt;vectơ cơ sở cũ viết trong cơ sở mới&lt;/em&gt;.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; $B = \{(1, 1), (1, -1)\}$, $C = \{(1, 0), (1, 1)\}$. Viết các vectơ của $B$ theo $C$: $(1, 1) = 0 \cdot (1, 0) + 1 \cdot (1, 1)$ và $(1, -1) = 2(1, 0) - 1(1, 1)$. Vậy&lt;/p&gt;

\[P_{C \leftarrow B} = \begin{bmatrix} 0 &amp;amp; 2 \\ 1 &amp;amp; -1 \end{bmatrix} .\]

  &lt;p&gt;Với $v = (5, 1)$, $[v]_B = (3, 2)$ nên $[v]_C = (0 \cdot 3 + 2 \cdot 2,\ 3 - 2) = (4, 1)$. Kiểm tra: $4(1, 0) + 1(1, 1) = (5, 1)$. Chiều ngược lại: $P_{B \leftarrow C} = \begin{bmatrix} 1/2 &amp;amp; 1 \\ 1/2 &amp;amp; 0 \end{bmatrix}$, và nhân với $(4, 1)$ cho lại $(3, 2)$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (cơ sở trực chuẩn).&lt;/strong&gt; $u_1 = \tfrac{1}{\sqrt2}(1, 1)$, $u_2 = \tfrac{1}{\sqrt2}(-1, 1)$ là cơ sở chuẩn xoay $45^\circ$. Ma trận $Q = [u_1\ u_2]$ có $Q^{-1} = Q^T$ (Bài 4.5, Ví dụ 2), nên $[v]_U = Q^T v = (u_1 \cdot v, u_2 \cdot v)$: toạ độ chỉ là các tích vô hướng. Với $v = (2, 0)$: $[v]_U = (\sqrt2, -\sqrt2)$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3 (đa thức).&lt;/strong&gt; Trong $P_2$, tìm toạ độ của $p(x) = 3 + 2x + x^2$ theo cơ sở $\{1,\ x - 1,\ (x - 1)^2\}$. Khai triển Taylor tại $x = 1$: $p(1) = 6$, $p&apos;(1) = 4$, $p&apos;&apos;(1)/2 = 1$, nên $p = 6 + 4(x - 1) + (x - 1)^2$ và toạ độ là $(6, 4, 1)$. Kiểm tra: $6 + 4x - 4 + x^2 - 2x + 1 = 3 + 2x + x^2$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-hệ-toạ-độ-trong-robot-và-đồ-hoạ&quot;&gt;Ứng dụng: hệ toạ độ trong robot và đồ hoạ&lt;/h2&gt;

&lt;p&gt;Một cánh tay robot có nhiều khớp, mỗi khớp mang một hệ toạ độ riêng. Camera thấy vật ở toạ độ $[v]_{\text{camera}}$; để điều khiển tay gắp, bộ điều khiển cần $[v]_{\text{đế}}$ và nhân với ma trận chuyển cơ sở (kèm một phép tịnh tiến). Trong đồ hoạ 3D, mỗi vật có “toạ độ địa phương”; các ma trận model, view chuyển chúng lần lượt sang toạ độ thế giới và toạ độ camera. Trong xử lý ảnh, đổi từ RGB sang YCbCr (độ sáng và hai thành phần màu) là một phép đổi cơ sở trong $\mathbb{R}^3$, giúp nén ảnh JPEG bỏ bớt thông tin màu mà mắt ít nhận ra.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: toạ độ và đổi cơ sở trong ℝ²&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo b₁ = a, b₂ = b và điểm w; đọc toạ độ chính tắc và toạ độ theo cơ sở mới.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter01/to_hop_tuyen_tinh.html?mode=coords&quot; title=&quot;Minh hoạ: toạ độ và đổi cơ sở trong ℝ²&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter01/to_hop_tuyen_tinh.html?mode=coords&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-một-điểm-hai-bộ-toạ-độ&quot;&gt;Video ngắn: Một điểm, hai bộ toạ độ&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/change-of-basis.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Điểm x đứng yên; theo e₁, e₂ nó là (3; 3), theo b₁, b₂ nó là (2; 1). Kéo vectơ cơ sở thì toạ độ đổi theo, còn x = B [x]_B và [x]_B = B⁻¹ x. Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Tìm $[v]_B$ với $v = (7, 4)$, $B = \{(2, 1), (1, 1)\}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$2c_1 + c_2 = 7$, $c_1 + c_2 = 4$: $(3, 1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Biết $[v]_B = (2, -1)$ với $B$ ở Bài tập 1. Tìm $v$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$2(2, 1) - (1, 1) = (3, 1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Với $B$ ở Bài tập 1 và $C = \{(1, 0), (1, 1)\}$, tính $P_{C \leftarrow B}$ và kiểm tra trên $v = (7, 4)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$(2, 1) = 1(1, 0) + 1(1, 1)$, $(1, 1) = 0(1, 0) + 1(1, 1)$, nên $P_{C \leftarrow B} = \begin{bmatrix} 1 &amp;amp; 0 \\ 1 &amp;amp; 1 \end{bmatrix}$. $[v]_C = (3, 4)$, và $3(1, 0) + 4(1, 1) = (7, 4)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Trong $P_2$, viết ma trận chuyển từ cơ sở $B = \{1, x - 1, (x - 1)^2\}$ sang cơ sở chuẩn $E = \{1, x, x^2\}$, và dùng nó kiểm tra Ví dụ 3.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$P_{E \leftarrow B} = \begin{bmatrix} 1 &amp;amp; -1 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; -2 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$. Nhân với $(6, 4, 1)$ được $(3, 2, 1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Cho ba cơ sở $B, C, D$. Chứng minh $P_{D \leftarrow B} = P_{D \leftarrow C}\, P_{C \leftarrow B}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$P_{D \leftarrow C} P_{C \leftarrow B} [v]_B = P_{D \leftarrow C} [v]_C = [v]_D$ với mọi $v$, và ma trận được xác định bởi tác động lên mọi vectơ của $\mathbb{R}^n$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$[v]_B$: các hệ số khi viết $v$ theo cơ sở $B$; trong $\mathbb{R}^n$, $[v]_B = B^{-1} v$.&lt;/li&gt;
    &lt;li&gt;$P_{C \leftarrow B}$ có cột là $[b_i]_C$; $[v]_C = P_{C \leftarrow B} [v]_B$; trong $\mathbb{R}^n$, $P_{C \leftarrow B} = C^{-1} B$.&lt;/li&gt;
    &lt;li&gt;$P_{B \leftarrow C} = (P_{C \leftarrow B})^{-1}$; ma trận chuyển ghép được theo chuỗi.&lt;/li&gt;
    &lt;li&gt;Toạ độ đưa mọi không gian $n$ chiều về $\mathbb{R}^n$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Hạng và định lý hạng – số khuyết</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter05/05_05_Hang_Va_Dinh_Ly_Hang_So_Khuyet/"/>
   <updated>2026-01-05T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter05/05_05_Hang_Va_Dinh_Ly_Hang_So_Khuyet</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;phát biểu và chứng minh định lý hạng – số khuyết $\operatorname{rank} A + \dim \operatorname{Nul} A = n$;&lt;/li&gt;
    &lt;li&gt;suy ra số chiều của cả bốn không gian con cơ bản từ hạng;&lt;/li&gt;
    &lt;li&gt;dùng định lý để biết số tham số của nghiệm mà không cần giải hệ;&lt;/li&gt;
    &lt;li&gt;giải thích vì sao với ma trận vuông, “có nghiệm với mọi $b$” tương đương “nghiệm duy nhất”.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Ma trận&lt;/p&gt;

\[A = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 3 \\ 2 &amp;amp; 4 &amp;amp; 6 \\ 1 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}\]

&lt;p&gt;biến $\mathbb{R}^3$ vào $\mathbb{R}^3$. Hàng 2 gấp đôi hàng 1, nên hạng bằng 2: không gian cột là một mặt phẳng, là mặt phẳng $b_2 = 2b_1$. Một không gian 3 chiều bị ép xuống một mặt phẳng 2 chiều, vậy “mất” một chiều. Chiều bị mất đi đâu? Nó là hạt nhân: đường thẳng qua $(-1, -1, 1)$, mọi điểm trên đó bị ép về gốc. Đếm: $2 + 1 = 3$.&lt;/p&gt;

&lt;h2 id=&quot;định-lý&quot;&gt;Định lý&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1.&lt;/strong&gt; &lt;em&gt;Hạng&lt;/em&gt; của $A$ là $\operatorname{rank} A = \dim \operatorname{Col} A$. &lt;em&gt;Số khuyết&lt;/em&gt; của $A$ là $\dim \operatorname{Nul} A$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Theo Bài 5.4, hạng cũng bằng số cột chốt và bằng $\dim \operatorname{Row} A$, khớp với định nghĩa hạng ở Bài 2.4.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Định lý hạng – số khuyết).&lt;/strong&gt; Với $A$ cỡ $m \times n$,&lt;/p&gt;

  &lt;p&gt;\(\operatorname{rank} A + \dim \operatorname{Nul} A = n .\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Khử $A$ về dạng bậc thang. Mỗi trong $n$ cột hoặc là cột chốt, hoặc ứng với một biến tự do. Số cột chốt là $\operatorname{rank} A$; số biến tự do là số nghiệm đặc biệt, bằng $\dim \operatorname{Nul} A$ theo Định lý 1 của Bài 5.4. Cộng lại được $n$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Hệ quả 1 (Số chiều bốn không gian con).&lt;/strong&gt; Với $A$ cỡ $m \times n$ có hạng $r$:&lt;/p&gt;

\[\dim \operatorname{Col} A = \dim \operatorname{Row} A = r, \qquad \dim \operatorname{Nul} A = n - r, \qquad \dim \operatorname{Nul} A^T = m - r .\]

  &lt;p&gt;Đặc biệt $\operatorname{rank} A^T = \operatorname{rank} A$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Hai đẳng thức đầu là Bài 5.4. Áp dụng Định lý 1 cho $A^T$ cỡ $n \times m$: $\operatorname{rank} A^T + \dim \operatorname{Nul} A^T = m$, và $\operatorname{rank} A^T = \dim \operatorname{Col} A^T = \dim \operatorname{Row} A = r$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Ý nghĩa hình học: hạt nhân đo số chiều bị “ép mất”, ảnh đo số chiều còn lại, tổng luôn bằng số chiều ban đầu.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Với $A$ ở ví dụ mở đầu, $r = 2$, $\dim \operatorname{Nul} A = 3 - 2 = 1$ và $\dim \operatorname{Nul} A^T = 3 - 2 = 1$: hạt nhân trái sinh bởi $(-2, 1, 0)$, ứng với “hàng 2 trừ hai lần hàng 1 bằng 0”. Hệ $Ax = (1, 2, 5)$ có nghiệm vì $b_2 = 2b_1$; tập nghiệm là một đường thẳng song song với $(-1, -1, 1)$. Hệ $Ax = (1, 3, 0)$ vô nghiệm vì $b$ nằm ngoài mặt phẳng cột.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (không cần giải).&lt;/strong&gt; Ma trận $5 \times 7$ có hạng 3. Khi đó $Ax = 0$ có không gian nghiệm 4 chiều; $\operatorname{Col} A$ là không gian con 3 chiều của $\mathbb{R}^5$, nên $Ax = b$ không có nghiệm với mọi $b$; và $\dim \operatorname{Nul} A^T = 2$, tức có hai điều kiện độc lập để $Ax = b$ có nghiệm.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3 (ma trận vuông).&lt;/strong&gt; Với $A$ vuông cấp $n$: $Ax = b$ có nghiệm với mọi $b$ $\iff \operatorname{rank} A = n \iff \dim \operatorname{Nul} A = 0 \iff$ nghiệm duy nhất. Hai tính chất “toàn ánh” và “đơn ánh” (Chương 6) trùng nhau cho ma trận vuông, đó là nội dung của Định lý 3 Bài 3.3 nhìn bằng số chiều.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-đếm-số-vòng-độc-lập-trong-mạng&quot;&gt;Ứng dụng: đếm số vòng độc lập trong mạng&lt;/h2&gt;

&lt;p&gt;Xét mạng có $n$ nút và $m$ dây nối, liên thông. Ma trận liên thuộc $A$ cỡ $m \times n$ (mỗi hàng có $-1$ ở nút đầu, $+1$ ở nút cuối). $Av = 0$ khi và chỉ khi điện thế bằng nhau tại hai đầu mọi dây, tức $v$ là hằng trên mạng liên thông, nên $\dim \operatorname{Nul} A = 1$ và $\operatorname{rank} A = n - 1$. Số vòng độc lập (Bài 5.4) là&lt;/p&gt;

\[\dim \operatorname{Nul} A^T = m - (n - 1) = m - n + 1 .\]

&lt;p&gt;Ví dụ: hình vuông 4 nút, 4 cạnh, thêm một đường chéo: $5 - 4 + 1 = 2$ vòng độc lập, là hai tam giác. Vòng quanh cả hình vuông là tổng của hai vòng đó. Đây là công thức Euler cho đồ thị, và là số phương trình điện áp Kirchhoff độc lập cần viết khi giải mạch.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: hạng và định lý hạng – số khuyết&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Chọn ma trận hạng 3, 2, 1, 0 và xem dim Col A + dim Nul A = 3.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter05/cot_nhan_3d.html&quot; title=&quot;Minh hoạ: hạng và định lý hạng – số khuyết&quot; loading=&quot;lazy&quot; style=&quot;height: 760px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter05/cot_nhan_3d.html&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; $A$ cỡ $4 \times 6$ có $\dim \operatorname{Nul} A = 3$. Tìm hạng và số chiều của bốn không gian con.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$r = 3$; $\dim \operatorname{Col} = \dim \operatorname{Row} = 3$, $\dim \operatorname{Nul} A = 3$, $\dim \operatorname{Nul} A^T = 1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Có ma trận $3 \times 5$ nào có hạt nhân 1 chiều không?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Không: hạng tối đa 3, nên $\dim \operatorname{Nul} A \ge 5 - 3 = 2$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Cho $u \in \mathbb{R}^m$, $v \in \mathbb{R}^n$ khác 0. Tìm hạng của $A = uv^T$ và mô tả $\operatorname{Nul} A$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Mọi cột là bội của $u$, nên $r = 1$. $Ax = u(v^T x) = 0 \iff v \cdot x = 0$: siêu phẳng vuông góc với $v$, chiều $n - 1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Một hệ 10 phương trình, 12 ẩn có nghiệm tổng quát gồm đúng 2 tham số. Hệ có nghiệm với mọi vế phải không?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\dim \operatorname{Nul} A = 2$ nên $r = 10 = m$, $\operatorname{Col} A = \mathbb{R}^{10}$: có nghiệm với mọi vế phải.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Chứng minh $\operatorname{rank}(A^T A) = \operatorname{rank} A$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Nếu $A^T A x = 0$ thì $x^T A^T A x = \lVert Ax \rVert^2 = 0$, nên $Ax = 0$. Vậy $\operatorname{Nul}(A^T A) = \operatorname{Nul} A$; hai ma trận cùng $n$ cột, nên cùng hạng theo Định lý 1.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$\operatorname{rank} A + \dim \operatorname{Nul} A = n$ (số cột).&lt;/li&gt;
    &lt;li&gt;Số chiều: $\operatorname{Col}$, $\operatorname{Row}$: $r$; $\operatorname{Nul} A$: $n - r$; $\operatorname{Nul} A^T$: $m - r$.&lt;/li&gt;
    &lt;li&gt;Số tham số của nghiệm $= n - r$; số điều kiện có nghiệm $= m - r$.&lt;/li&gt;
    &lt;li&gt;Với ma trận vuông, có nghiệm với mọi $b$ $\iff$ nghiệm duy nhất $\iff$ hạng đầy đủ.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Bốn không gian con cơ bản</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter05/05_04_Bon_Khong_Gian_Con_Co_Ban/"/>
   <updated>2026-01-05T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter05/05_04_Bon_Khong_Gian_Con_Co_Ban</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;định nghĩa không gian cột, không gian hàng, hạt nhân và hạt nhân của $A^T$;&lt;/li&gt;
    &lt;li&gt;tìm cơ sở của cả bốn không gian từ dạng bậc thang của $A$;&lt;/li&gt;
    &lt;li&gt;giải thích vì sao $\dim \operatorname{Col} A = \dim \operatorname{Row} A$;&lt;/li&gt;
    &lt;li&gt;dùng hạt nhân trái để viết điều kiện có nghiệm của $Ax = b$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Cho&lt;/p&gt;

\[A = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 &amp;amp; 1 \\ 2 &amp;amp; 4 &amp;amp; 1 &amp;amp; 3 \\ 3 &amp;amp; 6 &amp;amp; 1 &amp;amp; 4 \end{bmatrix} .\]

&lt;p&gt;Với vế phải $b$ nào thì $Ax = b$ có nghiệm? $Ax$ là tổ hợp các cột của $A$ (Bài 3.2), nên câu hỏi là: $b$ có thuộc span các cột không. Để ý hàng 3 bằng hàng 1 cộng hàng 2. Vậy với mọi $x$, thành phần thứ ba của $Ax$ bằng tổng hai thành phần đầu, và điều kiện cần là $b_3 = b_1 + b_2$. Bài này cho thấy đó cũng là điều kiện đủ, và cho cách tìm những điều kiện như vậy một cách hệ thống.&lt;/p&gt;

&lt;h2 id=&quot;bốn-không-gian&quot;&gt;Bốn không gian&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1.&lt;/strong&gt; Cho $A$ cỡ $m \times n$.&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;&lt;em&gt;Không gian cột&lt;/em&gt; $\operatorname{Col} A$: span các cột của $A$, là không gian con của $\mathbb{R}^m$. Đó là tập các $b$ để $Ax = b$ có nghiệm.&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;Không gian hàng&lt;/em&gt; $\operatorname{Row} A$: span các hàng của $A$ (xem như vectơ trong $\mathbb{R}^n$); $\operatorname{Row} A = \operatorname{Col} A^T$.&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;Hạt nhân&lt;/em&gt; $\operatorname{Nul} A = \{x \in \mathbb{R}^n : Ax = 0\}$.&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;Hạt nhân trái&lt;/em&gt; $\operatorname{Nul} A^T = \{y \in \mathbb{R}^m : A^T y = 0\}$, tức các $y$ với $y^T A = 0$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;p&gt;Hai không gian nằm trong $\mathbb{R}^n$ (hàng và hạt nhân), hai không gian nằm trong $\mathbb{R}^m$ (cột và hạt nhân trái).&lt;/p&gt;

&lt;h2 id=&quot;tìm-cơ-sở-từ-dạng-bậc-thang&quot;&gt;Tìm cơ sở từ dạng bậc thang&lt;/h2&gt;

&lt;div class=&quot;textbook-lemma&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Bổ đề 1.&lt;/strong&gt; Nếu $A$ biến thành $U$ bằng các phép biến đổi hàng thì:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$\operatorname{Row} A = \operatorname{Row} U$;&lt;/li&gt;
    &lt;li&gt;$\operatorname{Nul} A = \operatorname{Nul} U$;&lt;/li&gt;
    &lt;li&gt;các cột của $A$ và các cột của $U$ có cùng quan hệ tuyến tính: $\sum c_j a_j = 0 \iff \sum c_j u_j = 0$.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; (1) Mỗi hàng mới là tổ hợp của các hàng cũ, nên $\operatorname{Row} U \subseteq \operatorname{Row} A$; các phép biến đổi đảo ngược được nên có chiều ngược lại. (2) Hệ tương đương có cùng tập nghiệm (Bài 2.2). (3) $\sum c_j a_j = 0$ nghĩa là $c \in \operatorname{Nul} A$, và $\sum c_j u_j = 0$ nghĩa là $c \in \operatorname{Nul} U$; dùng (2).&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Gọi $U$ là dạng bậc thang của $A$, có $r$ cột chốt.&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;Các hàng khác 0 của $U$ là cơ sở của $\operatorname{Row} A$.&lt;/li&gt;
    &lt;li&gt;Các cột của $A$ (không phải của $U$) ở vị trí cột chốt là cơ sở của $\operatorname{Col} A$.&lt;/li&gt;
    &lt;li&gt;Các vectơ nghiệm đặc biệt (mỗi biến tự do cho một vectơ) là cơ sở của $\operatorname{Nul} A$.&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;Do đó $\dim \operatorname{Row} A = \dim \operatorname{Col} A = r = \operatorname{rank} A$, và $\dim \operatorname{Nul} A = n - r$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; (1) Các hàng khác 0 sinh ra $\operatorname{Row} U = \operatorname{Row} A$. Chúng độc lập: mỗi hàng có chốt ở một cột mà các hàng dưới đều bằng 0 ở đó, nên trong một tổ hợp bằng 0, hệ số của hàng trên cùng phải bằng 0, rồi tới hàng tiếp theo. (2) Trong $U$, các cột chốt độc lập và mọi cột khác là tổ hợp của chúng (đọc từ dạng bậc thang rút gọn). Theo Bổ đề 1(3), các quan hệ này giữ nguyên với cột của $A$. (3) Nghiệm tổng quát của $Ax = 0$ là tổ hợp của các nghiệm đặc biệt (Bài 2.5), và chúng độc lập vì nghiệm đặc biệt thứ $k$ có số 1 ở vị trí biến tự do thứ $k$, còn các nghiệm đặc biệt khác có số 0 ở đó.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Chú ý: các cột của $U$ thường &lt;em&gt;không&lt;/em&gt; nằm trong $\operatorname{Col} A$. Phép biến đổi hàng làm thay đổi không gian cột, chỉ giữ nguyên quan hệ giữa các cột.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Với $A$ ở ví dụ mở đầu, $R_2 - 2R_1$, $R_3 - 3R_1$, rồi $R_3 - R_2$:&lt;/p&gt;

\[U = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \end{bmatrix} .\]

  &lt;p&gt;Chốt ở cột 1 và 3, $r = 2$, biến tự do $x_2 = s$, $x_4 = t$.&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$\operatorname{Row} A$: cơ sở $(1, 2, 0, 1)$, $(0, 0, 1, 1)$. Chiều 2.&lt;/li&gt;
    &lt;li&gt;$\operatorname{Col} A$: cột 1 và cột 3 của $A$, tức $(1, 2, 3)$ và $(0, 1, 1)$. Chiều 2: một mặt phẳng trong $\mathbb{R}^3$.&lt;/li&gt;
    &lt;li&gt;$\operatorname{Nul} A$: $x_3 = -t$, $x_1 = -2s - t$, nên cơ sở $(-2, 1, 0, 0)$ và $(-1, 0, -1, 1)$. Chiều $4 - 2 = 2$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (hạt nhân trái).&lt;/strong&gt; Tìm $y$ với $A^T y = 0$. Quan hệ “hàng 3 = hàng 1 + hàng 2” viết là $-r_1 - r_2 + r_3 = 0$, tức $y = (-1, -1, 1)$. Vì $m - r = 3 - 2 = 1$ (Bài 5.5), đây là cơ sở của $\operatorname{Nul} A^T$.&lt;/p&gt;

  &lt;p&gt;Một cách tìm tổng quát: khử trên $[A \mid I]$; các hàng của phần bên phải đứng cạnh hàng 0 của $U$ cho cơ sở của $\operatorname{Nul} A^T$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3 (điều kiện có nghiệm).&lt;/strong&gt; Nếu $Ax = b$ thì $y^T b = y^T A x = 0$ với mọi $y \in \operatorname{Nul} A^T$. Với $y = (-1, -1, 1)$: $b_3 = b_1 + b_2$. Ngược lại, khử $[A \mid b]$ cho hàng cuối $[0\ 0\ 0\ 0 \mid b_3 - b_1 - b_2]$, nên điều kiện này cũng đủ. Ví dụ $b = (1, 1, 2)$ có nghiệm, $b&apos; = (1, 1, 3)$ không. Về hình học: $\operatorname{Col} A$ là mặt phẳng $-b_1 - b_2 + b_3 = 0$ với pháp tuyến $y$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-kiểm-tra-dữ-liệu-và-định-luật-kirchhoff&quot;&gt;Ứng dụng: kiểm tra dữ liệu và định luật Kirchhoff&lt;/h2&gt;

&lt;p&gt;Trong một mạch điện, ma trận liên thuộc $A$ (hàng là dây, cột là nút) cho hiệu điện thế trên các dây: $e = Av$, với $v$ là điện thế tại các nút. Một vectơ hiệu điện thế đo được $e$ hợp lệ khi và chỉ khi $e \in \operatorname{Col} A$, tức $y^T e = 0$ với mọi $y \in \operatorname{Nul} A^T$. Mỗi $y$ như vậy ứng với một vòng kín trong mạch, và điều kiện $y^T e = 0$ chính là định luật Kirchhoff về điện áp: tổng hiệu điện thế quanh một vòng bằng 0. Hạt nhân trái cho ta đúng những “phép kiểm tra” mà dữ liệu phải thoả.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: bốn không gian con cơ bản (phần ℝ³)&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Xoay hình: Row A vuông góc với Nul A; Col A là tập mọi Ax.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter05/cot_nhan_3d.html?show=row&quot; title=&quot;Minh hoạ: bốn không gian con cơ bản (phần ℝ³)&quot; loading=&quot;lazy&quot; style=&quot;height: 760px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter05/cot_nhan_3d.html?show=row&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-không-gian-cột-một-mặt-phẳng&quot;&gt;Video ngắn: Không gian cột: một mặt phẳng&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/column-space-3d.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;A có ba cột (1; 0; 1), (0; 1; 1), (1; 1; 2) nhưng cột ba = cột một + cột hai, nên mọi Ax nằm trên mặt phẳng z = x + y. b = (2; 1; 3) nằm trên đó nên Ax = b có nghiệm, b&apos; = (1; 1; 0) thì không. Hạng 2, không gian null là đường t(1; 1; −1). Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Tìm cơ sở của bốn không gian con của $\begin{bmatrix} 1 &amp;amp; 3 \\ 2 &amp;amp; 6 \end{bmatrix}$ và vẽ chúng.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\operatorname{Col}$: $(1, 2)$. $\operatorname{Row}$: $(1, 3)$. $\operatorname{Nul}$: $(-3, 1)$. $\operatorname{Nul} A^T$: $(-2, 1)$. Bốn đường thẳng qua gốc; $\operatorname{Nul} A \perp \operatorname{Row} A$ và $\operatorname{Nul} A^T \perp \operatorname{Col} A$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Với $A$ ở Ví dụ 1, kiểm tra $(1, 2, 3) \cdot (-1, -1, 1) = 0$ và $(1, 2, 0, 1) \cdot (-2, 1, 0, 0) = 0$. Bạn nhận xét gì?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Cả hai bằng 0. Mỗi vectơ của $\operatorname{Nul} A$ vuông góc với mọi hàng của $A$ (vì $Ax = 0$ nghĩa là từng hàng nhân vô hướng với $x$ bằng 0). Chương 7 phát triển điều này.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Tìm điều kiện trên $b$ để hệ $x_1 + x_2 = b_1$, $x_2 + x_3 = b_2$, $x_1 - x_3 = b_3$ có nghiệm.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Hàng 1 trừ hàng 2 bằng hàng 3, nên $b_1 - b_2 - b_3 = 0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Chứng minh $\operatorname{Col}(AB) \subseteq \operatorname{Col} A$ và $\operatorname{Nul} B \subseteq \operatorname{Nul}(AB)$. Suy ra $\operatorname{rank}(AB) \le \operatorname{rank} A$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$ABx = A(Bx)$ là tổ hợp các cột của $A$. Nếu $Bx = 0$ thì $ABx = 0$. Không gian con có chiều không quá không gian chứa nó (Định lý 3, Bài 5.3).

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (lập trình).&lt;/strong&gt; Dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A.columnspace()&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A.rowspace()&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A.nullspace()&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A.T.nullspace()&lt;/code&gt; của SymPy để kiểm tra Ví dụ 1 và 2.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

SymPy trả về $(1, 2, 3)$, $(0, 1, 1)$; $(1, 2, 0, 1)$, $(0, 0, 1, 1)$; $(-2, 1, 0, 0)$, $(-1, 0, -1, 1)$; $(-1, -1, 1)$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$\operatorname{Col} A, \operatorname{Nul} A^T \subseteq \mathbb{R}^m$; $\operatorname{Row} A, \operatorname{Nul} A \subseteq \mathbb{R}^n$.&lt;/li&gt;
    &lt;li&gt;Hàng khác 0 của $U$: cơ sở của $\operatorname{Row} A$. Cột chốt &lt;em&gt;của $A$&lt;/em&gt;: cơ sở của $\operatorname{Col} A$. Nghiệm đặc biệt: cơ sở của $\operatorname{Nul} A$.&lt;/li&gt;
    &lt;li&gt;$\dim \operatorname{Col} A = \dim \operatorname{Row} A = \operatorname{rank} A$.&lt;/li&gt;
    &lt;li&gt;$Ax = b$ có nghiệm $\iff y^T b = 0$ với mọi $y \in \operatorname{Nul} A^T$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Cơ sở và số chiều</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter05/05_03_Co_So_Va_So_Chieu/"/>
   <updated>2026-01-05T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter05/05_03_Co_So_Va_So_Chieu</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;kiểm tra một họ vectơ có là cơ sở hay không;&lt;/li&gt;
    &lt;li&gt;giải thích vì sao mọi cơ sở của cùng một không gian có cùng số phần tử;&lt;/li&gt;
    &lt;li&gt;tìm cơ sở và số chiều của không gian con cho bởi hệ sinh, hoặc cho bởi hệ phương trình thuần nhất;&lt;/li&gt;
    &lt;li&gt;rút gọn hệ sinh thành cơ sở và bổ sung họ độc lập thành cơ sở.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Cho bốn vectơ trong $\mathbb{R}^3$:&lt;/p&gt;

\[v_1 = (1, 2, 1),\quad v_2 = (2, 4, 2),\quad v_3 = (1, 0, 1),\quad v_4 = (0, 1, 0).\]

&lt;p&gt;Span của chúng là gì? Ta thấy ngay $v_2 = 2v_1$, và $v_4 = \tfrac12(v_1 - v_3)$. Vậy hai vectơ $v_1, v_3$ đã đủ sinh ra cả span, và chúng không cùng phương. Span là một mặt phẳng qua gốc: pháp tuyến $v_1 \times v_3 = (2, 0, -2)$, tức mặt phẳng $x = z$. Bốn vectơ ban đầu có hai vectơ thừa. Hai vectơ $v_1, v_3$ là một &lt;em&gt;cơ sở&lt;/em&gt; của mặt phẳng, và con số 2 là &lt;em&gt;số chiều&lt;/em&gt;.&lt;/p&gt;

&lt;h2 id=&quot;cơ-sở&quot;&gt;Cơ sở&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Cơ sở).&lt;/strong&gt; Họ $\{b_1, \dots, b_n\}$ trong không gian vectơ $V$ là một &lt;em&gt;cơ sở&lt;/em&gt; của $V$ nếu nó độc lập tuyến tính và sinh ra $V$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Biểu diễn duy nhất).&lt;/strong&gt; $\{b_1, \dots, b_n\}$ là cơ sở của $V$ khi và chỉ khi mỗi $v \in V$ viết được &lt;em&gt;duy nhất&lt;/em&gt; dưới dạng $v = c_1 b_1 + \dots + c_n b_n$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; “Viết được” là tính sinh. Nếu $v = \sum c_i b_i = \sum d_i b_i$ thì $\sum (c_i - d_i) b_i = 0$; độc lập tuyến tính cho $c_i = d_i$. Ngược lại, nếu biểu diễn luôn duy nhất thì riêng $0 = \sum 0 \cdot b_i$ là biểu diễn duy nhất của 0, đó là độc lập tuyến tính.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Ví dụ: $\{e_1, \dots, e_n\}$ là &lt;em&gt;cơ sở chuẩn&lt;/em&gt; của $\mathbb{R}^n$; $\{1, x, \dots, x^n\}$ là cơ sở của $P_n$; bốn ma trận $E_{11}, E_{12}, E_{21}, E_{22}$ (một số 1, còn lại 0) là cơ sở của $M_{2 \times 2}$.&lt;/p&gt;

&lt;h2 id=&quot;số-chiều&quot;&gt;Số chiều&lt;/h2&gt;

&lt;div class=&quot;textbook-lemma&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Bổ đề 1 (Bổ đề thay thế).&lt;/strong&gt; Nếu $V$ được sinh bởi $m$ vectơ $w_1, \dots, w_m$ thì mọi họ độc lập tuyến tính trong $V$ có không quá $m$ vectơ.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Giả sử $u_1, \dots, u_k \in V$ với $k &amp;gt; m$. Mỗi $u_j = \sum_i a_{ij} w_i$. Lập ma trận $A = [a_{ij}]$ cỡ $m \times k$. Hệ thuần nhất $Ac = 0$ có nhiều ẩn hơn phương trình nên có nghiệm $c \ne 0$ (Bài 2.5). Khi đó&lt;/p&gt;

\[\sum_j c_j u_j = \sum_j c_j \sum_i a_{ij} w_i = \sum_i \Big( \sum_j a_{ij} c_j \Big) w_i = \sum_i 0 \cdot w_i = 0,\]

  &lt;p&gt;nên $u_1, \dots, u_k$ phụ thuộc tuyến tính.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2.&lt;/strong&gt; Nếu $V$ có một cơ sở gồm $n$ vectơ thì mọi cơ sở của $V$ đều có đúng $n$ vectơ. Số $n$ gọi là &lt;em&gt;số chiều&lt;/em&gt; của $V$, ký hiệu $\dim V$. Quy ước $\dim\{0\} = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Cho hai cơ sở có $n$ và $k$ vectơ. Cơ sở thứ hai độc lập và cơ sở thứ nhất sinh ra $V$, nên $k \le n$ theo Bổ đề 1. Đổi vai trò được $n \le k$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Vậy $\dim \mathbb{R}^n = n$, $\dim P_n = n + 1$, $\dim M_{m \times n} = mn$. Không gian $F(\mathbb{R})$ không có cơ sở hữu hạn: các hàm $1, x, x^2, \dots$ độc lập với số lượng bất kỳ. Ta gọi nó là &lt;em&gt;vô hạn chiều&lt;/em&gt;.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 3.&lt;/strong&gt; Cho $\dim V = n$.&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;Mọi hệ sinh của $V$ chứa một cơ sở (bỏ dần các vectơ là tổ hợp của các vectơ còn lại).&lt;/li&gt;
    &lt;li&gt;Mọi họ độc lập trong $V$ bổ sung được thành một cơ sở.&lt;/li&gt;
    &lt;li&gt;Một họ gồm đúng $n$ vectơ là cơ sở nếu nó độc lập, hoặc nếu nó sinh ra $V$; chỉ cần kiểm tra một điều kiện.&lt;/li&gt;
    &lt;li&gt;Nếu $W$ là không gian con của $V$ thì $\dim W \le n$, dấu bằng khi và chỉ khi $W = V$.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; (1) Nếu hệ sinh phụ thuộc, có một vectơ là tổ hợp của các vectơ khác (Bài 1.5); bỏ nó đi span không đổi. Lặp lại tới khi độc lập. (2) Nếu họ độc lập $S$ chưa sinh ra $V$, lấy $v \notin \operatorname{span} S$; khi đó $S \cup \{v\}$ vẫn độc lập (nếu không, $v$ là tổ hợp của $S$). Theo Bổ đề 1 quá trình dừng sau không quá $n$ vectơ. (3) Họ độc lập $n$ vectơ: nếu bổ sung thêm được thì có cơ sở hơn $n$ vectơ, mâu thuẫn Định lý 2. Họ sinh $n$ vectơ: theo (1) chứa một cơ sở, cơ sở đó phải có $n$ vectơ, tức là chính nó. (4) Cơ sở của $W$ là họ độc lập trong $V$, nên có không quá $n$ vectơ; nếu đúng $n$ thì theo (3) nó là cơ sở của $V$, nên $W = V$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;tìm-cơ-sở-trong-thực-hành&quot;&gt;Tìm cơ sở trong thực hành&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (từ hệ sinh).&lt;/strong&gt; Với bốn vectơ ở ví dụ mở đầu, xếp chúng làm cột và khử:&lt;/p&gt;

\[\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 1 &amp;amp; 0 \\ 2 &amp;amp; 4 &amp;amp; 0 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 1 &amp;amp; 0 \end{bmatrix} \to \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; -2 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \end{bmatrix} .\]

  &lt;p&gt;Cột chốt là cột 1 và cột 3. Các &lt;em&gt;cột tương ứng của ma trận ban đầu&lt;/em&gt;, $v_1$ và $v_3$, là một cơ sở của span; số chiều là 2. (Bài 5.4 giải thích vì sao lấy cột của ma trận ban đầu chứ không phải của dạng bậc thang.)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (từ hệ phương trình).&lt;/strong&gt; Tìm cơ sở của $W = \{x \in \mathbb{R}^4 : x_1 + x_2 - x_3 = 0,\ x_2 + x_4 = 0\}$.&lt;/p&gt;

  &lt;p&gt;Ma trận đã ở dạng bậc thang, chốt ở cột 1 và 2, biến tự do $x_3 = s$, $x_4 = t$. Từ phương trình hai $x_2 = -t$, từ phương trình một $x_1 = s + t$:&lt;/p&gt;

\[x = s\,(1, 0, 1, 0) + t\,(1, -1, 0, 1) .\]

  &lt;p&gt;Hai vectơ này độc lập (nhìn thành phần 3 và 4), nên là cơ sở của $W$ và $\dim W = 2$: bốn ẩn trừ hai phương trình độc lập.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3 (bổ sung thành cơ sở).&lt;/strong&gt; Bổ sung $u = (1, 1, 0)$ thành cơ sở của $\mathbb{R}^3$. Thử thêm $e_1$: $\{u, e_1\}$ độc lập. Thêm $e_3$: $\det[u\ e_1\ e_3] = \begin{vmatrix} 1 &amp;amp; 1 &amp;amp; 0 \\ 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{vmatrix} = -1 \ne 0$. Vậy $\{u, e_1, e_3\}$ là cơ sở; theo Định lý 3(3), không cần kiểm tra tính sinh.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-số-bậc-tự-do&quot;&gt;Ứng dụng: số bậc tự do&lt;/h2&gt;

&lt;p&gt;Số chiều là số tham số độc lập cần để mô tả một phần tử. Ma trận đối xứng $3 \times 3$ có 6 phần tử tự do (3 trên đường chéo, 3 phía trên), nên không gian của chúng có chiều 6, không phải 9. Trong cơ học, vị trí và hướng của một vật rắn mô tả bằng 6 số; trong xử lý ảnh, một phép biến đổi affine của mặt phẳng có 6 tham số. Khi một thuật toán cần “ước lượng mô hình”, số chiều cho biết cần tối thiểu bao nhiêu phương trình (điểm đo) độc lập.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: cơ sở và toạ độ duy nhất&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo a, b, w: khi {a, b} là cơ sở, w có đúng một cặp toạ độ; khi a, b cùng phương thì không.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter01/to_hop_tuyen_tinh.html?mode=coords&quot; title=&quot;Minh hoạ: cơ sở và toạ độ duy nhất&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter01/to_hop_tuyen_tinh.html?mode=coords&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Tìm một cơ sở và số chiều của nghiệm của $x_1 - 2x_2 + x_3 - x_4 = 0$ trong $\mathbb{R}^4$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$x_1 = 2x_2 - x_3 + x_4$: cơ sở $(2, 1, 0, 0)$, $(-1, 0, 1, 0)$, $(1, 0, 0, 1)$; số chiều 3.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Họ $\{1 + x,\ 1 - x,\ x^2\}$ có là cơ sở của $P_2$ không?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Có. Ba vectơ trong không gian chiều 3; chúng độc lập vì $a(1 + x) + b(1 - x) + cx^2 = 0$ cho $a + b = 0$, $a - b = 0$, $c = 0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Tìm số chiều của không gian các ma trận $3 \times 3$ đối xứng và của không gian các ma trận $3 \times 3$ phản đối xứng.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

6 và 3. Tổng $6 + 3 = 9 = \dim M_{3 \times 3}$, khớp với phân tích $A = \tfrac12(A + A^T) + \tfrac12(A - A^T)$ ở Bài 3.5.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Chứng minh $\dim(U + W) = \dim U + \dim W - \dim(U \cap W)$ (gợi ý: bắt đầu từ một cơ sở của $U \cap W$).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Lấy cơ sở $z_1, \dots, z_k$ của $U \cap W$, bổ sung thành cơ sở $z, u_1, \dots, u_p$ của $U$ và $z, w_1, \dots, w_q$ của $W$. Họ $z, u, w$ sinh ra $U + W$. Nếu $\sum a z + \sum b u + \sum c w = 0$ thì $\sum c w = -(\sum a z + \sum b u) \in U \cap W$, nên là tổ hợp của các $z$; độc lập của $z, w$ cho $c = 0$, rồi độc lập của $z, u$ cho $a = b = 0$. Vậy $\dim(U + W) = k + p + q$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (lập trình).&lt;/strong&gt; Dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sympy.Matrix(...).columnspace()&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.nullspace()&lt;/code&gt; kiểm tra Ví dụ 1 và Ví dụ 2.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

`columnspace()` trả về $v_1, v_3$; `nullspace()` của $\begin{bmatrix} 1 &amp;amp; 1 &amp;amp; -1 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$ trả về $(1, 0, 1, 0)$ và $(1, -1, 0, 1)$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Cơ sở = độc lập tuyến tính + sinh ra $V$; mỗi vectơ có biểu diễn duy nhất theo cơ sở.&lt;/li&gt;
    &lt;li&gt;Mọi cơ sở có cùng số phần tử, gọi là $\dim V$. $\dim \mathbb{R}^n = n$, $\dim P_n = n + 1$, $\dim M_{m \times n} = mn$.&lt;/li&gt;
    &lt;li&gt;Hệ sinh rút gọn được thành cơ sở; họ độc lập bổ sung được thành cơ sở; với đúng $n$ vectơ chỉ cần kiểm tra một điều kiện.&lt;/li&gt;
    &lt;li&gt;Từ hệ sinh: lấy các cột chốt của ma trận ban đầu. Từ hệ thuần nhất: mỗi biến tự do cho một vectơ cơ sở.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Không gian con</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter05/05_02_Khong_Gian_Con/"/>
   <updated>2026-01-05T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter05/05_02_Khong_Gian_Con</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;dùng ba điều kiện để kiểm tra một tập con có là không gian con;&lt;/li&gt;
    &lt;li&gt;nhận ra tập nghiệm của hệ thuần nhất và span của một họ vectơ luôn là không gian con;&lt;/li&gt;
    &lt;li&gt;chỉ ra vì sao tập nghiệm của hệ không thuần nhất, hay hợp của hai không gian con, thường không là không gian con;&lt;/li&gt;
    &lt;li&gt;mô tả hình học các không gian con của $\mathbb{R}^2$ và $\mathbb{R}^3$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Mặt phẳng $W = \{(x, y, z) : x + y + z = 0\}$ đi qua gốc toạ độ. Lấy hai điểm $u = (1, -1, 0)$ và $v = (2, 0, -2)$ trong $W$. Tổng $u + v = (3, -1, -2)$ có $3 - 1 - 2 = 0$, vẫn thuộc $W$. Bội $5u = (5, -5, 0)$ cũng thuộc $W$. Đi trong mặt phẳng bằng cộng và co giãn không bao giờ rời khỏi mặt phẳng: $W$ tự nó là một không gian vectơ nằm trong $\mathbb{R}^3$.&lt;/p&gt;

&lt;p&gt;Mặt phẳng $x + y + z = 1$ thì khác: $(1, 0, 0)$ và $(0, 1, 0)$ thuộc nó nhưng tổng $(1, 1, 0)$ có tổng toạ độ bằng 2. Mặt phẳng này không qua gốc.&lt;/p&gt;

&lt;h2 id=&quot;định-nghĩa-và-tiêu-chuẩn&quot;&gt;Định nghĩa và tiêu chuẩn&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Không gian con).&lt;/strong&gt; Tập con $W$ của không gian vectơ $V$ gọi là &lt;em&gt;không gian con&lt;/em&gt; nếu $W$ là một không gian vectơ với chính phép cộng và nhân số của $V$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Tiêu chuẩn không gian con).&lt;/strong&gt; Tập con $W \subseteq V$ là không gian con khi và chỉ khi:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$0 \in W$;&lt;/li&gt;
    &lt;li&gt;$u, v \in W \Rightarrow u + v \in W$;&lt;/li&gt;
    &lt;li&gt;$v \in W,\ c \in \mathbb{R} \Rightarrow cv \in W$.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Nếu $W$ là không gian con thì nó đóng với hai phép toán, và vectơ 0 của $W$ thoả $0_W + 0_W = 0_W$ trong $V$, nên $0_W = 0_V$. Ngược lại, giả sử có ba điều kiện. Hai phép toán đóng trong $W$. Các tiên đề 1, 2, 5, 6, 7, 8 là đẳng thức đúng với mọi vectơ của $V$, nên đúng trong $W$. Tiên đề 3 có nhờ điều kiện 1. Tiên đề 4: với $v \in W$, $-v = (-1)v \in W$ theo điều kiện 3 và Định lý 1 của Bài 5.1.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Hai điều kiện 2 và 3 có thể gộp thành một: $u, v \in W \Rightarrow au + bv \in W$ với mọi $a, b$. Nói gọn: $W$ đóng với tổ hợp tuyến tính.&lt;/p&gt;

&lt;h2 id=&quot;các-nguồn-không-gian-con-quan-trọng&quot;&gt;Các nguồn không gian con quan trọng&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2.&lt;/strong&gt;&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;Với $A$ cỡ $m \times n$, tập nghiệm $\operatorname{Nul} A = \{x \in \mathbb{R}^n : Ax = 0\}$ là không gian con của $\mathbb{R}^n$.&lt;/li&gt;
    &lt;li&gt;Với mọi $v_1, \dots, v_k \in V$, $\operatorname{span}\{v_1, \dots, v_k\}$ là không gian con của $V$.&lt;/li&gt;
    &lt;li&gt;Giao của hai không gian con là không gian con.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; (1) $A0 = 0$; nếu $Ax = Ay = 0$ thì $A(ax + by) = aAx + bAy = 0$. (2) Đã chứng minh ở Bài 1.4: $0 = \sum 0 \cdot v_i$, và tổ hợp tuyến tính của hai tổ hợp tuyến tính lại là tổ hợp tuyến tính. (3) Nếu $U, W$ là không gian con thì $0$ thuộc cả hai; nếu $u, v \in U \cap W$ thì $au + bv$ thuộc $U$ và thuộc $W$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Vậy mặt phẳng $x + y + z = 0$ là $\operatorname{Nul} \begin{bmatrix} 1 &amp;amp; 1 &amp;amp; 1 \end{bmatrix}$. Mọi không gian con của $\mathbb{R}^3$ là một trong bốn loại: $\{0\}$, một đường thẳng qua gốc, một mặt phẳng qua gốc, hoặc cả $\mathbb{R}^3$ (Bài 5.3 sẽ giải thích bằng số chiều).&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (ma trận đối xứng).&lt;/strong&gt; $S = \{A \in M_{2 \times 2} : A^T = A\}$ là không gian con: $0^T = 0$; $(A + B)^T = A^T + B^T = A + B$; $(cA)^T = cA^T = cA$. Mỗi phần tử có dạng $\begin{bmatrix} a &amp;amp; b \\ b &amp;amp; d \end{bmatrix} = a \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix} + b \begin{bmatrix} 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix} + d \begin{bmatrix} 0 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix}$, nên $S$ cũng là span của ba ma trận này.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (hợp của hai đường thẳng).&lt;/strong&gt; Trục $x$ và trục $y$ đều là không gian con của $\mathbb{R}^2$, nhưng hợp của chúng thì không: $(1, 0) + (0, 1) = (1, 1)$ không nằm trên trục nào. Không gian con nhỏ nhất chứa cả hai trục là $\mathbb{R}^2$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3 (trong không gian hàm).&lt;/strong&gt; Trong $P_3$, tập $W = \{p : p(1) = 0\}$ là không gian con: đa thức 0 có $0(1) = 0$, và $(ap + bq)(1) = a\,p(1) + b\,q(1) = 0$. Tập $\{p : p(1) = 2\}$ thì không, vì không chứa đa thức 0.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-luồng-giao-thông-trong-mạng-đường&quot;&gt;Ứng dụng: luồng giao thông trong mạng đường&lt;/h2&gt;

&lt;p&gt;Một nút giao có ba đường vào với lưu lượng $x_1, x_2$ (xe vào) và $x_3$ (xe ra). Bảo toàn lưu lượng cho $x_1 + x_2 - x_3 = 0$. Với cả mạng đường, các ràng buộc bảo toàn là một hệ thuần nhất $Ax = 0$, nên tập các luồng hợp lệ là không gian con $\operatorname{Nul} A$. Hệ quả thực tế: chồng hai phương án luồng hợp lệ (cộng) hay tăng đều lưu lượng (nhân số) vẫn cho một phương án hợp lệ. Khi thêm luồng vào từ bên ngoài, hệ thành $Ax = b$ và tập nghiệm chỉ còn là một không gian con tịnh tiến (Bài 2.5).&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: không gian con của ℝ³&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Col A và Nul A luôn là điểm gốc, đường thẳng hoặc mặt phẳng qua gốc, hoặc cả ℝ³.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter05/cot_nhan_3d.html&quot; title=&quot;Minh hoạ: không gian con của ℝ³&quot; loading=&quot;lazy&quot; style=&quot;height: 760px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter05/cot_nhan_3d.html&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Tập nào là không gian con của $\mathbb{R}^3$? (a) $\{(x, y, z) : x = 2y\}$; (b) $\{(x, y, z) : x = y^2\}$; (c) $\{(t, 2t, -t) : t \in \mathbb{R}\}$; (d) $\{(x, y, z) : x + y = 1\}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

(a) Có (hạt nhân của $[1\ \ {-2}\ \ 0]$). (b) Không: $(1, 1, 0)$ thuộc nhưng $2(1, 1, 0) = (2, 2, 0)$ không thuộc. (c) Có (đường thẳng qua gốc). (d) Không, không chứa 0.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Chứng minh tập các ma trận tam giác trên $3 \times 3$ là không gian con của $M_{3 \times 3}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Ma trận 0 là tam giác trên; tổng và bội của ma trận có phần dưới đường chéo bằng 0 vẫn có phần đó bằng 0.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Cho $U, W$ là không gian con. Chứng minh $U + W = \{u + w : u \in U, w \in W\}$ là không gian con, và là không gian con nhỏ nhất chứa $U \cup W$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$0 = 0 + 0$; $(u + w) + (u&apos; + w&apos;) = (u + u&apos;) + (w + w&apos;)$; $c(u + w) = cu + cw$. Mọi không gian con chứa $U$ và $W$ đều chứa mọi tổng $u + w$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Tập các hàm $f \in F(\mathbb{R})$ thoả $f&apos;&apos; + f = 0$ (giả sử khả vi hai lần) có là không gian con không? Cho hai phần tử của nó.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Có, vì phương trình tuyến tính thuần nhất: $(af + bg)&apos;&apos; + (af + bg) = a(f&apos;&apos; + f) + b(g&apos;&apos; + g) = 0$. Ví dụ $\sin x$, $\cos x$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Chứng minh: $U \cup W$ là không gian con khi và chỉ khi $U \subseteq W$ hoặc $W \subseteq U$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Nếu không, lấy $u \in U \setminus W$ và $w \in W \setminus U$. Nếu $u + w \in U$ thì $w = (u + w) - u \in U$, vô lý; tương tự $u + w \notin W$. Vậy $u + w \notin U \cup W$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$W$ là không gian con khi chứa 0 và đóng với tổ hợp tuyến tính.&lt;/li&gt;
    &lt;li&gt;$\operatorname{Nul} A$, span của một họ vectơ, giao của các không gian con đều là không gian con.&lt;/li&gt;
    &lt;li&gt;Tập nghiệm của hệ không thuần nhất và hợp của hai không gian con thường không phải.&lt;/li&gt;
    &lt;li&gt;Không gian con của $\mathbb{R}^3$: $\{0\}$, đường thẳng qua gốc, mặt phẳng qua gốc, $\mathbb{R}^3$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Không gian vectơ: định nghĩa và ví dụ</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter05/05_01_Dinh_Nghia_Va_Vi_Du/"/>
   <updated>2026-01-05T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter05/05_01_Dinh_Nghia_Va_Vi_Du</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;phát biểu định nghĩa không gian vectơ với tám tiên đề;&lt;/li&gt;
    &lt;li&gt;kiểm tra các tiên đề trên những ví dụ quen thuộc: $\mathbb{R}^n$, ma trận, đa thức, hàm số;&lt;/li&gt;
    &lt;li&gt;chỉ ra tiên đề bị vi phạm trong một phản ví dụ;&lt;/li&gt;
    &lt;li&gt;chứng minh các hệ quả đơn giản như $0 \cdot v = 0$ và $(-1)v = -v$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Ở Chương 1, vectơ là bộ số $(x_1, \dots, x_n)$. Nhưng hãy xem hai đa thức $p(x) = 1 + 2x$ và $q(x) = 3 - x + x^2$. Ta cộng được: $p + q = 4 + x + x^2$. Ta nhân được với số: $2p = 2 + 4x$. Và các quy tắc tính toán y hệt như với vectơ trong $\mathbb{R}^3$: thực ra, ghi hệ số của $1, x, x^2$ thì $p \leftrightarrow (1, 2, 0)$, $q \leftrightarrow (3, -1, 1)$, và phép cộng đa thức chính là cộng từng thành phần.&lt;/p&gt;

&lt;p&gt;Mọi điều ta đã học về tổ hợp tuyến tính, độc lập, span chỉ dùng hai phép toán này và vài quy tắc của chúng. Vậy nên ta tách các quy tắc ra thành định nghĩa, và áp dụng được cho đa thức, ma trận, hàm số, tín hiệu, ảnh số.&lt;/p&gt;

&lt;h2 id=&quot;định-nghĩa&quot;&gt;Định nghĩa&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Không gian vectơ).&lt;/strong&gt; Một &lt;em&gt;không gian vectơ&lt;/em&gt; (trên $\mathbb{R}$) là một tập $V$ cùng hai phép toán: phép cộng $u + v \in V$ và phép nhân với số $c\,v \in V$ (với $u, v \in V$, $c \in \mathbb{R}$), thoả mãn tám tiên đề sau với mọi $u, v, w \in V$ và mọi $a, b \in \mathbb{R}$:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$u + v = v + u$;&lt;/li&gt;
    &lt;li&gt;$(u + v) + w = u + (v + w)$;&lt;/li&gt;
    &lt;li&gt;có phần tử $0 \in V$ với $v + 0 = v$;&lt;/li&gt;
    &lt;li&gt;với mỗi $v$ có $-v \in V$ với $v + (-v) = 0$;&lt;/li&gt;
    &lt;li&gt;$1 \cdot v = v$;&lt;/li&gt;
    &lt;li&gt;$a(bv) = (ab)v$;&lt;/li&gt;
    &lt;li&gt;$a(u + v) = au + av$;&lt;/li&gt;
    &lt;li&gt;$(a + b)v = av + bv$.&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;Các phần tử của $V$ gọi là &lt;em&gt;vectơ&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Điều kiện “$u + v \in V$ và $cv \in V$” gọi là tính &lt;em&gt;đóng&lt;/em&gt;: cộng hay nhân số không đưa ta ra khỏi $V$. Đây thường là chỗ cần kiểm tra nhất.&lt;/p&gt;

&lt;h2 id=&quot;các-ví-dụ&quot;&gt;Các ví dụ&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (bốn không gian quen thuộc).&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$\mathbb{R}^n$ với phép cộng và nhân số theo từng thành phần. Tám tiên đề suy ra từ tính chất của số thực (Bài 1.1).&lt;/li&gt;
    &lt;li&gt;$M_{m \times n}$, tập các ma trận cỡ $m \times n$, với phép cộng ma trận và nhân số (Bài 3.1). Vectơ 0 là ma trận 0.&lt;/li&gt;
    &lt;li&gt;$P_n$, tập các đa thức bậc không quá $n$. Tổng hai đa thức bậc $\le n$ vẫn có bậc $\le n$, nên phép cộng đóng.&lt;/li&gt;
    &lt;li&gt;$F(\mathbb{R})$, tập mọi hàm $f : \mathbb{R} \to \mathbb{R}$, với $(f + g)(x) = f(x) + g(x)$ và $(cf)(x) = c f(x)$. Vectơ 0 là hàm hằng 0. Mỗi tiên đề kiểm tra tại từng điểm $x$, nên lại quy về số thực.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (phản ví dụ).&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;Tập đa thức có bậc &lt;em&gt;đúng bằng&lt;/em&gt; 2 không phải không gian vectơ: $(x^2 + 1) + (-x^2) = 1$ có bậc 0. Phép cộng không đóng, và tập cũng không chứa đa thức 0.&lt;/li&gt;
    &lt;li&gt;Nửa mặt phẳng $H = \{(x, y) : x \ge 0\}$ đóng với phép cộng nhưng không đóng với nhân số: $(-1)(1, 0) = (-1, 0) \notin H$. Tiên đề 4 bị vi phạm: $(1, 0)$ không có phần tử đối trong $H$.&lt;/li&gt;
    &lt;li&gt;Đường thẳng $x + y = 1$ không chứa $(0, 0)$, nên không có vectơ 0 (với phép toán thông thường).&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3 (phép toán lạ nhưng vẫn đúng).&lt;/strong&gt; Lấy $V = \{x \in \mathbb{R} : x &amp;gt; 0\}$ với “phép cộng” $x \oplus y = xy$ và “nhân số” $c \odot x = x^c$. Kiểm tra vài tiên đề:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;Vectơ 0 là số $1$: $x \oplus 1 = x$.&lt;/li&gt;
    &lt;li&gt;Phần tử đối của $x$ là $1/x$: $x \oplus (1/x) = 1$.&lt;/li&gt;
    &lt;li&gt;Tiên đề 8: $(a + b) \odot x = x^{a+b} = x^a x^b = (a \odot x) \oplus (b \odot x)$.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Cả tám tiên đề đều đúng, nên $V$ là một không gian vectơ. Lý do sâu xa: hàm $\ln$ biến $\oplus$ thành phép cộng thường và $\odot$ thành phép nhân thường, nên $V$ “giống hệt” $\mathbb{R}$ (Chương 6 gọi là đẳng cấu).&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;hệ-quả-đầu-tiên&quot;&gt;Hệ quả đầu tiên&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Trong mọi không gian vectơ $V$:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;vectơ 0 là duy nhất, và mỗi $v$ có đúng một phần tử đối;&lt;/li&gt;
    &lt;li&gt;$0 \cdot v = 0$ với mọi $v$;&lt;/li&gt;
    &lt;li&gt;$c \cdot 0 = 0$ với mọi $c$;&lt;/li&gt;
    &lt;li&gt;$(-1) v = -v$.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; (1) Nếu $0$ và $0&apos;$ đều là vectơ không thì $0 = 0 + 0&apos; = 0&apos;$. Nếu $w$ và $w&apos;$ đều là đối của $v$ thì $w = w + (v + w&apos;) = (w + v) + w&apos; = w&apos;$.&lt;/p&gt;

  &lt;p&gt;(2) Theo tiên đề 8, $0 \cdot v = (0 + 0) v = 0 \cdot v + 0 \cdot v$. Cộng hai vế với $-(0 \cdot v)$ được $0 = 0 \cdot v$.&lt;/p&gt;

  &lt;p&gt;(3) Tương tự, $c \cdot 0 = c(0 + 0) = c \cdot 0 + c \cdot 0$ theo tiên đề 7.&lt;/p&gt;

  &lt;p&gt;(4) $v + (-1)v = 1 \cdot v + (-1) v = (1 - 1) v = 0 \cdot v = 0$, nên $(-1)v$ là đối của $v$, và theo (1) nó chính là $-v$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Các hệ quả này trông hiển nhiên, nhưng ở Ví dụ 3 chúng có nội dung: $0 \odot x = x^0 = 1$ đúng là “vectơ không” của $V$.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-tín-hiệu-và-ảnh-số-là-vectơ&quot;&gt;Ứng dụng: tín hiệu và ảnh số là vectơ&lt;/h2&gt;

&lt;p&gt;Một đoạn âm thanh 1 giây lấy mẫu 44 100 lần là một vectơ trong $\mathbb{R}^{44100}$. Trộn hai bản nhạc là cộng hai vectơ, chỉnh âm lượng là nhân với số. Một ảnh xám $640 \times 480$ là một phần tử của $M_{480 \times 640}$; làm mờ dần giữa hai ảnh (cross-fade) là tổ hợp $(1 - t) A + t B$ với $t$ chạy từ 0 tới 1. Vì đây là các không gian vectơ, mọi công cụ của các chương sau (cơ sở, chiếu, phân rã) dùng được ngay, ví dụ nén ảnh bằng SVD ở Chương 11.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: hai phép toán của không gian vectơ ℝ²&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Phép cộng và phép nhân với số luôn cho kết quả nằm lại trong ℝ²; thử các thẻ u + v và k·u.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter01/vecto_2d.html?mode=add&quot; title=&quot;Minh hoạ: hai phép toán của không gian vectơ ℝ²&quot; loading=&quot;lazy&quot; style=&quot;height: 620px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter01/vecto_2d.html?mode=add&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Tập nào sau đây là không gian vectơ với phép toán thông thường? (a) $\{(x, y, z) : z = 0\}$; (b) $\{(x, y) : xy \ge 0\}$; (c) tập các ma trận $2 \times 2$ có vết bằng 0.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

(a) Có. (b) Không: $(1, 0) + (0, -1) = (1, -1)$ có $xy &amp;lt; 0$. (c) Có: vết của tổng là tổng các vết, vết của $cA$ là $c$ lần vết.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Trong $F(\mathbb{R})$, vectơ $-f$ là hàm nào? Tập các hàm liên tục có là không gian vectơ không?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$(-f)(x) = -f(x)$. Có: tổng và bội của hàm liên tục là hàm liên tục, và hàm 0 liên tục.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Kiểm tra đủ tám tiên đề cho Ví dụ 3.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Ví dụ: tiên đề 6: $a \odot (b \odot x) = (x^b)^a = x^{ab}$; tiên đề 7: $a \odot (x \oplus y) = (xy)^a = x^a y^a$; tiên đề 5: $x^1 = x$. Các tiên đề 1, 2 là tính giao hoán, kết hợp của phép nhân số dương.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Trên $\mathbb{R}^2$ định nghĩa cộng thông thường nhưng $c \odot (x, y) = (cx, 0)$. Tiên đề nào sai?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Tiên đề 5: $1 \odot (x, y) = (x, 0) \ne (x, y)$ khi $y \ne 0$. Các tiên đề còn lại vẫn đúng, nên tiên đề 5 không thừa.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Chứng minh: nếu $cv = 0$ thì $c = 0$ hoặc $v = 0$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Nếu $c \ne 0$, nhân hai vế với $1/c$: $v = 1 \cdot v = (\tfrac1c c) v = \tfrac1c (cv) = \tfrac1c \cdot 0 = 0$, dùng tiên đề 5, 6 và Định lý 1(3).

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Không gian vectơ là tập có phép cộng và nhân số, đóng, và thoả tám tiên đề.&lt;/li&gt;
    &lt;li&gt;Ví dụ: $\mathbb{R}^n$, $M_{m \times n}$, $P_n$, $F(\mathbb{R})$; phản ví dụ thường vi phạm tính đóng hoặc thiếu vectơ 0.&lt;/li&gt;
    &lt;li&gt;Từ tiên đề suy ra: vectơ 0 và phần tử đối là duy nhất, $0 \cdot v = 0$, $(-1)v = -v$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Polynomial and function spaces</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter05/05_07_Khong_Gian_Da_Thuc_Va_Khong_Gian_Ham/"/>
   <updated>2026-01-05T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter05/05_07_Khong_Gian_Da_Thuc_Va_Khong_Gian_Ham</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;test whether a family of functions is independent by plugging in points;&lt;/li&gt;
    &lt;li&gt;use the Lagrange basis to write an interpolating polynomial;&lt;/li&gt;
    &lt;li&gt;write the matrix of differentiation on $P_n$ and on the span of a few exponential functions;&lt;/li&gt;
    &lt;li&gt;use that matrix to compute derivatives and antiderivatives.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Differentiation sends $p(x) = 2 - x + 4x^2 + x^3$ to $p&apos;(x) = -1 + 8x + 3x^2$. In coordinates for the basis $\{1, x, x^2, x^3\}$: $(2, -1, 4, 1) \mapsto (-1, 8, 3, 0)$. Differentiation satisfies $(ap + bq)&apos; = ap&apos; + bq&apos;$, just like matrix multiplication. So there is a $4 \times 4$ matrix $D$ with $D(2, -1, 4, 1) = (-1, 8, 3, 0)$, and a calculus problem becomes a matrix product.&lt;/p&gt;

&lt;h2 id=&quot;independence-of-functions&quot;&gt;Independence of functions&lt;/h2&gt;

&lt;p&gt;In $F(\mathbb{R})$, the equation $c_1 f_1 + \dots + c_k f_k = 0$ means zero &lt;em&gt;at every&lt;/em&gt; $x$. To prove independence it is enough to choose $k$ points $x_1, \dots, x_k$ for which the system $\sum_j c_j f_j(x_i) = 0$ has only the trivial solution.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; If there are points $x_1, \dots, x_k$ such that the $k \times k$ matrix $M = [f_j(x_i)]$ is invertible, then $f_1, \dots, f_k$ are linearly independent.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; If $\sum c_j f_j = 0$, then in particular at the points $x_i$ we get $Mc = 0$, so $c = 0$ since $M$ is invertible.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The converse fails for badly chosen points: $\sin x$ and $\sin 2x$ are independent, but at $x = 0$ and $x = \pi$ both vanish.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; $e^x$ and $e^{2x}$ are independent: at $x = 0$ and $x = 1$, $M = \begin{bmatrix} 1 &amp;amp; 1 \\ e &amp;amp; e^2 \end{bmatrix}$ has $\det M = e^2 - e \ne 0$. Likewise $\{1, \cos x, \sin x\}$ is independent: at $x = 0, \pi/2, \pi$ the matrix is $\begin{bmatrix} 1 &amp;amp; 1 &amp;amp; 0 \\ 1 &amp;amp; 0 &amp;amp; 1 \\ 1 &amp;amp; -1 &amp;amp; 0 \end{bmatrix}$, with determinant $2 \ne 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;the-lagrange-basis&quot;&gt;The Lagrange basis&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; For the three nodes $0, 1, 2$, set&lt;/p&gt;

\[L_0 = \tfrac12 (x - 1)(x - 2), \qquad L_1 = -x(x - 2), \qquad L_2 = \tfrac12 x(x - 1) .\]

  &lt;p&gt;Each $L_i$ equals 1 at node $i$ and 0 at the other two. By Theorem 1 (with $M = I$) the three polynomials are independent, hence a basis of $P_2$. The coordinates of $p$ in this basis are exactly $(p(0), p(1), p(2))$. For instance, the parabola through $(0, 1)$, $(1, 2)$, $(2, 5)$ is $L_0 + 2L_1 + 5L_2 = 1 + x^2$, matching Exercise 4 of Lesson 4.3, with no system to solve.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;the-matrix-of-differentiation&quot;&gt;The matrix of differentiation&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3.&lt;/strong&gt; On $P_3$ with basis $\{1, x, x^2, x^3\}$: $D(1) = 0$, $D(x) = 1$, $D(x^2) = 2x$, $D(x^3) = 3x^2$. Put the coordinates of the images in columns:&lt;/p&gt;

\[D = \begin{bmatrix} 0 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 2 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 3 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \end{bmatrix} .\]

  &lt;p&gt;Check: $D(2, -1, 4, 1) = (-1, 8, 3, 0)$. Properties of differentiation can be read from the matrix: $D$ has rank 3, its 1-dimensional null space is the constants (derivative 0); $D^4 = 0$, since differentiating a cubic four times gives 0; $D$ is not invertible, reflecting that antiderivatives are only determined up to a constant.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;On the span of $\{e^x, xe^x\}$: $D(e^x) = e^x$, $D(xe^x) = e^x + xe^x$, so the matrix is $\begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \end{bmatrix}$, which is invertible. Its inverse $\begin{bmatrix} 1 &amp;amp; -1 \\ 0 &amp;amp; 1 \end{bmatrix}$ gives antiderivatives: the coordinates $(0, 1)$ of $xe^x$ go to $(-1, 1)$, i.e. $\int x e^x\,dx = xe^x - e^x + C$. No integration by parts needed.&lt;/p&gt;

&lt;h2 id=&quot;application-fourier-series-and-signal-approximation&quot;&gt;Application: Fourier series and signal approximation&lt;/h2&gt;

&lt;p&gt;The space of trigonometric polynomials $\operatorname{span}\{1, \cos x, \sin x, \dots, \cos Nx, \sin Nx\}$ has dimension $2N + 1$. Approximating a periodic signal (sound, a heartbeat) by an element of this space is the idea behind Fourier series: each signal is described by $2N + 1$ coordinates. On this space differentiation sends $\cos kx \mapsto -k \sin kx$ and $\sin kx \mapsto k \cos kx$, so its matrix consists of $2 \times 2$ blocks on the diagonal. Chapter 7 adds an inner product so that these coordinates can be computed by integrals.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: the Lagrange basis of P₂&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag p(0), p(1), p(2); see the interpolating polynomial and its coordinates in two bases.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter05/lagrange.html?lang=en&quot; title=&quot;Interactive: the Lagrange basis of P₂&quot; loading=&quot;lazy&quot; style=&quot;height: 620px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter05/lagrange.html?lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Prove that $1, x, x^2$ are independent by plugging in three points.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

At $0, 1, 2$ the matrix is the Vandermonde matrix $\begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 \\ 1 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 4 \end{bmatrix}$ with determinant $2 \ne 0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Write the matrix of differentiation on $P_2$ with basis $\{1, x, x^2\}$ and find its rank.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\begin{bmatrix} 0 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 2 \\ 0 &amp;amp; 0 &amp;amp; 0 \end{bmatrix}$, rank 2.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Is $\{1, \cos^2 x, \sin^2 x\}$ independent?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

No: $\cos^2 x + \sin^2 x - 1 = 0$ for all $x$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; On the span of $\{e^{2x}, xe^{2x}\}$, write the matrix of $D$ and use its inverse to find $\int x e^{2x}\,dx$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$D = \begin{bmatrix} 2 &amp;amp; 1 \\ 0 &amp;amp; 2 \end{bmatrix}$, $D^{-1} = \tfrac14 \begin{bmatrix} 2 &amp;amp; -1 \\ 0 &amp;amp; 2 \end{bmatrix}$. Coordinates $(0, 1) \mapsto (-\tfrac14, \tfrac12)$: $\int x e^{2x}\,dx = \tfrac12 x e^{2x} - \tfrac14 e^{2x} + C$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (programming).&lt;/strong&gt; With SymPy, write a function that takes a list of polynomials in $P_n$ and returns their coordinate matrix and rank. Try $\{1 + x, x + x^2, 1 - x^2\}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Use `Poly(p, x).all_coeffs()` (reversed) to get coordinates. This family is dependent: $(1 + x) - (x + x^2) = 1 - x^2$, rank 2.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Functions are vectors; to prove independence, plug in points and check that $[f_j(x_i)]$ is invertible.&lt;/li&gt;
    &lt;li&gt;The Lagrange basis has the values at the nodes as coordinates, giving the interpolating polynomial at once.&lt;/li&gt;
    &lt;li&gt;Differentiation has a matrix on $P_n$ (rank $n$, nilpotent) and on spans of exponentials (invertible, giving antiderivatives).&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Coordinates and change of basis</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter05/05_06_Toa_Do_Va_Doi_Co_So/"/>
   <updated>2026-01-05T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter05/05_06_Toa_Do_Va_Doi_Co_So</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;compute the coordinates $[v]_B$ of a vector in a basis $B$;&lt;/li&gt;
    &lt;li&gt;build the change-of-basis matrix $P_{C \leftarrow B}$ and use it to convert coordinates;&lt;/li&gt;
    &lt;li&gt;explain why $P_{B \leftarrow C} = (P_{C \leftarrow B})^{-1}$;&lt;/li&gt;
    &lt;li&gt;use coordinates in polynomial spaces.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Take the point $v = (5, 1)$ in the plane. On the standard grid we walk 5 steps along $e_1$ and 1 step along $e_2$. Now draw another grid with the vectors $b_1 = (1, 1)$ and $b_2 = (1, -1)$ (rotated by $45^\circ$ and stretched). To reach the same point $v$ on the new grid we solve $c_1 (1, 1) + c_2 (1, -1) = (5, 1)$: $c_1 + c_2 = 5$, $c_1 - c_2 = 1$, so $c_1 = 3$, $c_2 = 2$. The point does not move; only its address changes: $(5, 1)$ on the standard grid, $(3, 2)$ on the new one.&lt;/p&gt;

&lt;h2 id=&quot;coordinates&quot;&gt;Coordinates&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Coordinates).&lt;/strong&gt; Let $B = \{b_1, \dots, b_n\}$ be an ordered basis of $V$. For $v = c_1 b_1 + \dots + c_n b_n$ (a unique representation, Lesson 5.3), the vector&lt;/p&gt;

\[[v]_B = (c_1, \dots, c_n) \in \mathbb{R}^n\]

  &lt;p&gt;is the &lt;em&gt;coordinate vector&lt;/em&gt; of $v$ in the basis $B$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;In $\mathbb{R}^n$, let $B$ also denote the matrix with columns $b_1, \dots, b_n$. Then $v = B[v]_B$, so $[v]_B = B^{-1} v$. The matrix $B$ is invertible because its columns form a basis.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; The map $v \mapsto [v]_B$ preserves the operations: $[u + v]_B = [u]_B + [v]_B$ and $[cv]_B = c[v]_B$. The family $v_1, \dots, v_k$ is independent in $V$ if and only if $[v_1]_B, \dots, [v_k]_B$ are independent in $\mathbb{R}^n$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; If $u = \sum a_i b_i$ and $v = \sum c_i b_i$, then $u + v = \sum (a_i + c_i) b_i$ and $cv = \sum (c c_i) b_i$; by uniqueness these are the coordinates of $u + v$ and $cv$. Hence $\sum x_j v_j = 0 \iff \sum x_j [v_j]_B = [0]_B = 0$, so the two families satisfy the same linear relations.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Theorem 1 lets us move any question about an $n$-dimensional space (polynomials, matrices) to $\mathbb{R}^n$ and use elimination.&lt;/p&gt;

&lt;h2 id=&quot;the-change-of-basis-matrix&quot;&gt;The change-of-basis matrix&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2 (Change of basis).&lt;/strong&gt; Let $B = \{b_1, \dots, b_n\}$ and $C$ be bases of $V$. Set&lt;/p&gt;

\[P_{C \leftarrow B} = \big[\, [b_1]_C \ \ [b_2]_C \ \ \cdots \ \ [b_n]_C \,\big] .\]

  &lt;p&gt;Then $[v]_C = P_{C \leftarrow B}\, [v]_B$ for every $v$. The matrix $P_{C \leftarrow B}$ is invertible and $(P_{C \leftarrow B})^{-1} = P_{B \leftarrow C}$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; If $[v]_B = (c_1, \dots, c_n)$ then $v = \sum c_i b_i$, so by Theorem 1, $[v]_C = \sum c_i [b_i]_C = P_{C \leftarrow B} [v]_B$. Applying this twice: $[v]_B = P_{B \leftarrow C} P_{C \leftarrow B} [v]_B$ for all $v$, and $[v]_B$ ranges over all of $\mathbb{R}^n$, so $P_{B \leftarrow C} P_{C \leftarrow B} = I$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;In $\mathbb{R}^n$: $v = B[v]_B = C[v]_C$, so $P_{C \leftarrow B} = C^{-1} B$. A way to remember: the columns of the change-of-basis matrix are the &lt;em&gt;old basis vectors written in the new basis&lt;/em&gt;.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; $B = \{(1, 1), (1, -1)\}$, $C = \{(1, 0), (1, 1)\}$. Write the vectors of $B$ in terms of $C$: $(1, 1) = 0 \cdot (1, 0) + 1 \cdot (1, 1)$ and $(1, -1) = 2(1, 0) - 1(1, 1)$. So&lt;/p&gt;

\[P_{C \leftarrow B} = \begin{bmatrix} 0 &amp;amp; 2 \\ 1 &amp;amp; -1 \end{bmatrix} .\]

  &lt;p&gt;For $v = (5, 1)$, $[v]_B = (3, 2)$, hence $[v]_C = (0 \cdot 3 + 2 \cdot 2,\ 3 - 2) = (4, 1)$. Check: $4(1, 0) + 1(1, 1) = (5, 1)$. The other way: $P_{B \leftarrow C} = \begin{bmatrix} 1/2 &amp;amp; 1 \\ 1/2 &amp;amp; 0 \end{bmatrix}$, and multiplying by $(4, 1)$ gives back $(3, 2)$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (orthonormal basis).&lt;/strong&gt; $u_1 = \tfrac{1}{\sqrt2}(1, 1)$, $u_2 = \tfrac{1}{\sqrt2}(-1, 1)$ is the standard basis rotated by $45^\circ$. The matrix $Q = [u_1\ u_2]$ has $Q^{-1} = Q^T$ (Lesson 4.5, Example 2), so $[v]_U = Q^T v = (u_1 \cdot v, u_2 \cdot v)$: coordinates are just dot products. For $v = (2, 0)$: $[v]_U = (\sqrt2, -\sqrt2)$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3 (polynomials).&lt;/strong&gt; In $P_2$, find the coordinates of $p(x) = 3 + 2x + x^2$ in the basis $\{1,\ x - 1,\ (x - 1)^2\}$. Taylor expansion at $x = 1$: $p(1) = 6$, $p&apos;(1) = 4$, $p&apos;&apos;(1)/2 = 1$, so $p = 6 + 4(x - 1) + (x - 1)^2$ and the coordinates are $(6, 4, 1)$. Check: $6 + 4x - 4 + x^2 - 2x + 1 = 3 + 2x + x^2$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-coordinate-frames-in-robotics-and-graphics&quot;&gt;Application: coordinate frames in robotics and graphics&lt;/h2&gt;

&lt;p&gt;A robot arm has several joints, each with its own coordinate frame. The camera sees an object at $[v]_{\text{camera}}$; to steer the gripper, the controller needs $[v]_{\text{base}}$ and multiplies by a change-of-basis matrix (plus a translation). In 3D graphics each object has “local coordinates”; the model and view matrices convert them to world coordinates and then to camera coordinates. In image processing, converting RGB to YCbCr (brightness and two colour components) is a change of basis in $\mathbb{R}^3$, which lets JPEG discard colour detail the eye barely notices.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: coordinates and change of basis in ℝ²&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag b₁ = a, b₂ = b and the point w; read the standard and the new coordinates.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter01/to_hop_tuyen_tinh.html?mode=coords&amp;amp;lang=en&quot; title=&quot;Interactive: coordinates and change of basis in ℝ²&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter01/to_hop_tuyen_tinh.html?mode=coords&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-one-point-two-sets-of-coordinates&quot;&gt;Short video: One point, two sets of coordinates&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/change-of-basis.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;The point x stays put: in e₁, e₂ it is (3; 3), in b₁, b₂ it is (2; 1). Drag the basis vectors and only the coordinates change; x = B [x]_B and [x]_B = B⁻¹ x. Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Find $[v]_B$ for $v = (7, 4)$, $B = \{(2, 1), (1, 1)\}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$2c_1 + c_2 = 7$, $c_1 + c_2 = 4$: $(3, 1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Given $[v]_B = (2, -1)$ with $B$ from Exercise 1, find $v$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$2(2, 1) - (1, 1) = (3, 1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; With $B$ from Exercise 1 and $C = \{(1, 0), (1, 1)\}$, compute $P_{C \leftarrow B}$ and check it on $v = (7, 4)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$(2, 1) = 1(1, 0) + 1(1, 1)$, $(1, 1) = 0(1, 0) + 1(1, 1)$, so $P_{C \leftarrow B} = \begin{bmatrix} 1 &amp;amp; 0 \\ 1 &amp;amp; 1 \end{bmatrix}$. $[v]_C = (3, 4)$, and $3(1, 0) + 4(1, 1) = (7, 4)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; In $P_2$, write the change-of-basis matrix from $B = \{1, x - 1, (x - 1)^2\}$ to the standard basis $E = \{1, x, x^2\}$, and use it to check Example 3.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$P_{E \leftarrow B} = \begin{bmatrix} 1 &amp;amp; -1 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; -2 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$. Multiplying by $(6, 4, 1)$ gives $(3, 2, 1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; For three bases $B, C, D$, prove $P_{D \leftarrow B} = P_{D \leftarrow C}\, P_{C \leftarrow B}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$P_{D \leftarrow C} P_{C \leftarrow B} [v]_B = P_{D \leftarrow C} [v]_C = [v]_D$ for every $v$, and a matrix is determined by its action on every vector of $\mathbb{R}^n$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$[v]_B$: the coefficients of $v$ in the basis $B$; in $\mathbb{R}^n$, $[v]_B = B^{-1} v$.&lt;/li&gt;
    &lt;li&gt;$P_{C \leftarrow B}$ has columns $[b_i]_C$; $[v]_C = P_{C \leftarrow B} [v]_B$; in $\mathbb{R}^n$, $P_{C \leftarrow B} = C^{-1} B$.&lt;/li&gt;
    &lt;li&gt;$P_{B \leftarrow C} = (P_{C \leftarrow B})^{-1}$; change-of-basis matrices compose along a chain.&lt;/li&gt;
    &lt;li&gt;Coordinates turn every $n$-dimensional space into $\mathbb{R}^n$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Rank and the rank–nullity theorem</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter05/05_05_Hang_Va_Dinh_Ly_Hang_So_Khuyet/"/>
   <updated>2026-01-05T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter05/05_05_Hang_Va_Dinh_Ly_Hang_So_Khuyet</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;state and prove the rank–nullity theorem $\operatorname{rank} A + \dim \operatorname{Nul} A = n$;&lt;/li&gt;
    &lt;li&gt;get the dimensions of all four fundamental subspaces from the rank;&lt;/li&gt;
    &lt;li&gt;use the theorem to know the number of parameters in a solution without solving;&lt;/li&gt;
    &lt;li&gt;explain why, for a square matrix, “solvable for every $b$” is the same as “unique solution”.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;The matrix&lt;/p&gt;

\[A = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 3 \\ 2 &amp;amp; 4 &amp;amp; 6 \\ 1 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}\]

&lt;p&gt;maps $\mathbb{R}^3$ to $\mathbb{R}^3$. Row 2 is twice row 1, so the rank is 2: the column space is a plane, the plane $b_2 = 2b_1$. A 3-dimensional space is squashed onto a 2-dimensional plane, so one dimension is “lost”. Where did it go? It is the null space: the line through $(-1, -1, 1)$, all of whose points are squashed to the origin. Count: $2 + 1 = 3$.&lt;/p&gt;

&lt;h2 id=&quot;the-theorem&quot;&gt;The theorem&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1.&lt;/strong&gt; The &lt;em&gt;rank&lt;/em&gt; of $A$ is $\operatorname{rank} A = \dim \operatorname{Col} A$. The &lt;em&gt;nullity&lt;/em&gt; of $A$ is $\dim \operatorname{Nul} A$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;By Lesson 5.4 the rank also equals the number of pivot columns and $\dim \operatorname{Row} A$, matching the definition of rank in Lesson 2.4.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Rank–nullity theorem).&lt;/strong&gt; For an $m \times n$ matrix $A$,&lt;/p&gt;

  &lt;p&gt;\(\operatorname{rank} A + \dim \operatorname{Nul} A = n .\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Reduce $A$ to echelon form. Each of the $n$ columns is either a pivot column or corresponds to a free variable. The number of pivot columns is $\operatorname{rank} A$; the number of free variables is the number of special solutions, which is $\dim \operatorname{Nul} A$ by Theorem 1 of Lesson 5.4. Together they make $n$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Corollary 1 (Dimensions of the four subspaces).&lt;/strong&gt; For an $m \times n$ matrix $A$ of rank $r$:&lt;/p&gt;

\[\dim \operatorname{Col} A = \dim \operatorname{Row} A = r, \qquad \dim \operatorname{Nul} A = n - r, \qquad \dim \operatorname{Nul} A^T = m - r .\]

  &lt;p&gt;In particular $\operatorname{rank} A^T = \operatorname{rank} A$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; The first two equalities are Lesson 5.4. Apply Theorem 1 to the $n \times m$ matrix $A^T$: $\operatorname{rank} A^T + \dim \operatorname{Nul} A^T = m$, and $\operatorname{rank} A^T = \dim \operatorname{Col} A^T = \dim \operatorname{Row} A = r$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Geometrically: the null space measures the dimensions that get “squashed away”, the image measures what remains, and together they always make up the original dimension.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; For $A$ in the motivating example, $r = 2$, $\dim \operatorname{Nul} A = 3 - 2 = 1$ and $\dim \operatorname{Nul} A^T = 3 - 2 = 1$: the left null space is spanned by $(-2, 1, 0)$, recording “row 2 minus twice row 1 is 0”. The system $Ax = (1, 2, 5)$ is solvable since $b_2 = 2b_1$; its solution set is a line parallel to $(-1, -1, 1)$. The system $Ax = (1, 3, 0)$ has no solution because $b$ lies off the column plane.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (without solving).&lt;/strong&gt; A $5 \times 7$ matrix has rank 3. Then $Ax = 0$ has a 4-dimensional solution space; $\operatorname{Col} A$ is a 3-dimensional subspace of $\mathbb{R}^5$, so $Ax = b$ is not solvable for every $b$; and $\dim \operatorname{Nul} A^T = 2$, so there are two independent conditions for $Ax = b$ to be solvable.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3 (square matrices).&lt;/strong&gt; For a square $n \times n$ matrix $A$: $Ax = b$ is solvable for every $b$ $\iff \operatorname{rank} A = n \iff \dim \operatorname{Nul} A = 0 \iff$ the solution is unique. The properties “onto” and “one-to-one” (Chapter 6) coincide for square matrices; this is Theorem 3 of Lesson 3.3 seen through dimension.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-counting-independent-loops-in-a-network&quot;&gt;Application: counting independent loops in a network&lt;/h2&gt;

&lt;p&gt;Take a connected network with $n$ nodes and $m$ wires. Its $m \times n$ incidence matrix $A$ has $-1$ at the start node and $+1$ at the end node of each wire. $Av = 0$ exactly when the potentials at both ends of every wire agree, i.e. $v$ is constant on the connected network, so $\dim \operatorname{Nul} A = 1$ and $\operatorname{rank} A = n - 1$. The number of independent loops (Lesson 5.4) is&lt;/p&gt;

\[\dim \operatorname{Nul} A^T = m - (n - 1) = m - n + 1 .\]

&lt;p&gt;For example, a square with 4 nodes and 4 edges plus one diagonal has $5 - 4 + 1 = 2$ independent loops, the two triangles. The loop around the whole square is the sum of those two. This is Euler’s formula for graphs, and it is the number of independent Kirchhoff voltage equations needed to solve a circuit.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: rank and the rank–nullity theorem&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Pick matrices of rank 3, 2, 1, 0 and check dim Col A + dim Nul A = 3.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter05/cot_nhan_3d.html?lang=en&quot; title=&quot;Interactive: rank and the rank–nullity theorem&quot; loading=&quot;lazy&quot; style=&quot;height: 760px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter05/cot_nhan_3d.html?lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; A $4 \times 6$ matrix $A$ has $\dim \operatorname{Nul} A = 3$. Find the rank and the dimensions of the four subspaces.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$r = 3$; $\dim \operatorname{Col} = \dim \operatorname{Row} = 3$, $\dim \operatorname{Nul} A = 3$, $\dim \operatorname{Nul} A^T = 1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Is there a $3 \times 5$ matrix with a 1-dimensional null space?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

No: the rank is at most 3, so $\dim \operatorname{Nul} A \ge 5 - 3 = 2$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Let $u \in \mathbb{R}^m$, $v \in \mathbb{R}^n$ be nonzero. Find the rank of $A = uv^T$ and describe $\operatorname{Nul} A$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Every column is a multiple of $u$, so $r = 1$. $Ax = u(v^T x) = 0 \iff v \cdot x = 0$: the hyperplane orthogonal to $v$, of dimension $n - 1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; A system of 10 equations in 12 unknowns has a general solution with exactly 2 parameters. Is it solvable for every right-hand side?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\dim \operatorname{Nul} A = 2$, so $r = 10 = m$ and $\operatorname{Col} A = \mathbb{R}^{10}$: solvable for every right-hand side.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Prove $\operatorname{rank}(A^T A) = \operatorname{rank} A$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

If $A^T A x = 0$ then $x^T A^T A x = \lVert Ax \rVert^2 = 0$, so $Ax = 0$. Thus $\operatorname{Nul}(A^T A) = \operatorname{Nul} A$; both matrices have $n$ columns, so they have the same rank by Theorem 1.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$\operatorname{rank} A + \dim \operatorname{Nul} A = n$ (the number of columns).&lt;/li&gt;
    &lt;li&gt;Dimensions: $\operatorname{Col}$, $\operatorname{Row}$: $r$; $\operatorname{Nul} A$: $n - r$; $\operatorname{Nul} A^T$: $m - r$.&lt;/li&gt;
    &lt;li&gt;Number of solution parameters $= n - r$; number of solvability conditions $= m - r$.&lt;/li&gt;
    &lt;li&gt;For a square matrix, solvable for every $b$ $\iff$ unique solution $\iff$ full rank.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>The four fundamental subspaces</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter05/05_04_Bon_Khong_Gian_Con_Co_Ban/"/>
   <updated>2026-01-05T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter05/05_04_Bon_Khong_Gian_Con_Co_Ban</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;define the column space, row space, null space and the null space of $A^T$;&lt;/li&gt;
    &lt;li&gt;find bases of all four spaces from the echelon form of $A$;&lt;/li&gt;
    &lt;li&gt;explain why $\dim \operatorname{Col} A = \dim \operatorname{Row} A$;&lt;/li&gt;
    &lt;li&gt;use the left null space to write the solvability condition for $Ax = b$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Let&lt;/p&gt;

\[A = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 &amp;amp; 1 \\ 2 &amp;amp; 4 &amp;amp; 1 &amp;amp; 3 \\ 3 &amp;amp; 6 &amp;amp; 1 &amp;amp; 4 \end{bmatrix} .\]

&lt;p&gt;For which right-hand sides $b$ does $Ax = b$ have a solution? $Ax$ is a combination of the columns of $A$ (Lesson 3.2), so the question is whether $b$ lies in the span of the columns. Notice that row 3 is row 1 plus row 2. So for every $x$ the third entry of $Ax$ is the sum of the first two, and a necessary condition is $b_3 = b_1 + b_2$. This lesson shows the condition is also sufficient, and gives a systematic way to find such conditions.&lt;/p&gt;

&lt;h2 id=&quot;the-four-spaces&quot;&gt;The four spaces&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1.&lt;/strong&gt; Let $A$ be $m \times n$.&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;The &lt;em&gt;column space&lt;/em&gt; $\operatorname{Col} A$: the span of the columns of $A$, a subspace of $\mathbb{R}^m$. It is the set of $b$ for which $Ax = b$ is solvable.&lt;/li&gt;
    &lt;li&gt;The &lt;em&gt;row space&lt;/em&gt; $\operatorname{Row} A$: the span of the rows of $A$ (as vectors in $\mathbb{R}^n$); $\operatorname{Row} A = \operatorname{Col} A^T$.&lt;/li&gt;
    &lt;li&gt;The &lt;em&gt;null space&lt;/em&gt; $\operatorname{Nul} A = \{x \in \mathbb{R}^n : Ax = 0\}$.&lt;/li&gt;
    &lt;li&gt;The &lt;em&gt;left null space&lt;/em&gt; $\operatorname{Nul} A^T = \{y \in \mathbb{R}^m : A^T y = 0\}$, i.e. the $y$ with $y^T A = 0$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;p&gt;Two spaces live in $\mathbb{R}^n$ (row space and null space) and two in $\mathbb{R}^m$ (column space and left null space).&lt;/p&gt;

&lt;h2 id=&quot;bases-from-the-echelon-form&quot;&gt;Bases from the echelon form&lt;/h2&gt;

&lt;div class=&quot;textbook-lemma&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Lemma 1.&lt;/strong&gt; If row operations turn $A$ into $U$, then:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$\operatorname{Row} A = \operatorname{Row} U$;&lt;/li&gt;
    &lt;li&gt;$\operatorname{Nul} A = \operatorname{Nul} U$;&lt;/li&gt;
    &lt;li&gt;the columns of $A$ and of $U$ satisfy the same linear relations: $\sum c_j a_j = 0 \iff \sum c_j u_j = 0$.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; (1) Each new row is a combination of old rows, so $\operatorname{Row} U \subseteq \operatorname{Row} A$; the operations are reversible, giving the other inclusion. (2) Equivalent systems have the same solutions (Lesson 2.2). (3) $\sum c_j a_j = 0$ means $c \in \operatorname{Nul} A$, and $\sum c_j u_j = 0$ means $c \in \operatorname{Nul} U$; use (2).&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; Let $U$ be an echelon form of $A$ with $r$ pivot columns.&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;The nonzero rows of $U$ form a basis of $\operatorname{Row} A$.&lt;/li&gt;
    &lt;li&gt;The columns of $A$ (not of $U$) in the pivot positions form a basis of $\operatorname{Col} A$.&lt;/li&gt;
    &lt;li&gt;The special solutions (one for each free variable) form a basis of $\operatorname{Nul} A$.&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;Hence $\dim \operatorname{Row} A = \dim \operatorname{Col} A = r = \operatorname{rank} A$ and $\dim \operatorname{Nul} A = n - r$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; (1) The nonzero rows span $\operatorname{Row} U = \operatorname{Row} A$. They are independent: each row has its pivot in a column where all lower rows are 0, so in a combination equal to 0 the coefficient of the top row must be 0, then that of the next row, and so on. (2) In $U$ the pivot columns are independent and every other column is a combination of them (read off the reduced echelon form). By Lemma 1(3) these relations hold for the columns of $A$ too. (3) The general solution of $Ax = 0$ is a combination of the special solutions (Lesson 2.5), and they are independent because the $k$-th special solution has a 1 in the position of the $k$-th free variable, where the others have 0.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Note: the columns of $U$ are usually &lt;em&gt;not&lt;/em&gt; in $\operatorname{Col} A$. Row operations change the column space; they only preserve the relations between columns.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; For $A$ from the motivating example, $R_2 - 2R_1$, $R_3 - 3R_1$, then $R_3 - R_2$:&lt;/p&gt;

\[U = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \end{bmatrix} .\]

  &lt;p&gt;Pivots in columns 1 and 3, $r = 2$, free variables $x_2 = s$, $x_4 = t$.&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$\operatorname{Row} A$: basis $(1, 2, 0, 1)$, $(0, 0, 1, 1)$. Dimension 2.&lt;/li&gt;
    &lt;li&gt;$\operatorname{Col} A$: columns 1 and 3 of $A$, namely $(1, 2, 3)$ and $(0, 1, 1)$. Dimension 2: a plane in $\mathbb{R}^3$.&lt;/li&gt;
    &lt;li&gt;$\operatorname{Nul} A$: $x_3 = -t$, $x_1 = -2s - t$, so a basis is $(-2, 1, 0, 0)$ and $(-1, 0, -1, 1)$. Dimension $4 - 2 = 2$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (left null space).&lt;/strong&gt; Find $y$ with $A^T y = 0$. The relation “row 3 = row 1 + row 2” reads $-r_1 - r_2 + r_3 = 0$, i.e. $y = (-1, -1, 1)$. Since $m - r = 3 - 2 = 1$ (Lesson 5.5), this is a basis of $\operatorname{Nul} A^T$.&lt;/p&gt;

  &lt;p&gt;A general method: eliminate on $[A \mid I]$; the rows of the right part next to the zero rows of $U$ give a basis of $\operatorname{Nul} A^T$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3 (solvability condition).&lt;/strong&gt; If $Ax = b$ then $y^T b = y^T A x = 0$ for every $y \in \operatorname{Nul} A^T$. With $y = (-1, -1, 1)$: $b_3 = b_1 + b_2$. Conversely, eliminating $[A \mid b]$ gives the last row $[0\ 0\ 0\ 0 \mid b_3 - b_1 - b_2]$, so the condition is also sufficient. For instance $b = (1, 1, 2)$ is solvable and $b&apos; = (1, 1, 3)$ is not. Geometrically, $\operatorname{Col} A$ is the plane $-b_1 - b_2 + b_3 = 0$ with normal $y$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-checking-data-and-kirchhoffs-law&quot;&gt;Application: checking data and Kirchhoff’s law&lt;/h2&gt;

&lt;p&gt;In an electrical circuit, the incidence matrix $A$ (rows are wires, columns are nodes) gives the voltage drops along wires: $e = Av$, where $v$ holds the node potentials. A measured voltage vector $e$ is consistent exactly when $e \in \operatorname{Col} A$, that is, $y^T e = 0$ for every $y \in \operatorname{Nul} A^T$. Each such $y$ corresponds to a closed loop in the circuit, and $y^T e = 0$ is Kirchhoff’s voltage law: the voltage drops around a loop sum to 0. The left null space gives exactly the “checks” the data must pass.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: the fundamental subspaces (the ℝ³ part)&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Orbit the view: Row A is perpendicular to Nul A; Col A is the set of all Ax.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter05/cot_nhan_3d.html?show=row&amp;amp;lang=en&quot; title=&quot;Interactive: the fundamental subspaces (the ℝ³ part)&quot; loading=&quot;lazy&quot; style=&quot;height: 760px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter05/cot_nhan_3d.html?show=row&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-the-column-space-is-a-plane&quot;&gt;Short video: The column space is a plane&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/column-space-3d.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;A has three columns (1; 0; 1), (0; 1; 1), (1; 1; 2), but column 3 = column 1 + column 2, so every Ax lies on the plane z = x + y. b = (2; 1; 3) is on it, so Ax = b has a solution; b&apos; = (1; 1; 0) is not. Rank 2, and the null space is the line t(1; 1; −1). Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Find bases of the four subspaces of $\begin{bmatrix} 1 &amp;amp; 3 \\ 2 &amp;amp; 6 \end{bmatrix}$ and sketch them.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\operatorname{Col}$: $(1, 2)$. $\operatorname{Row}$: $(1, 3)$. $\operatorname{Nul}$: $(-3, 1)$. $\operatorname{Nul} A^T$: $(-2, 1)$. Four lines through the origin; $\operatorname{Nul} A \perp \operatorname{Row} A$ and $\operatorname{Nul} A^T \perp \operatorname{Col} A$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; For $A$ in Example 1, check that $(1, 2, 3) \cdot (-1, -1, 1) = 0$ and $(1, 2, 0, 1) \cdot (-2, 1, 0, 0) = 0$. What do you notice?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Both are 0. Every vector of $\operatorname{Nul} A$ is orthogonal to every row of $A$ (since $Ax = 0$ says each row dotted with $x$ is 0). Chapter 7 develops this.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Find the condition on $b$ for $x_1 + x_2 = b_1$, $x_2 + x_3 = b_2$, $x_1 - x_3 = b_3$ to be solvable.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Row 1 minus row 2 equals row 3, so $b_1 - b_2 - b_3 = 0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; Prove $\operatorname{Col}(AB) \subseteq \operatorname{Col} A$ and $\operatorname{Nul} B \subseteq \operatorname{Nul}(AB)$. Deduce $\operatorname{rank}(AB) \le \operatorname{rank} A$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$ABx = A(Bx)$ is a combination of the columns of $A$. If $Bx = 0$ then $ABx = 0$. A subspace has dimension at most that of the space containing it (Theorem 3, Lesson 5.3).

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (programming).&lt;/strong&gt; Use SymPy’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A.columnspace()&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A.rowspace()&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A.nullspace()&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A.T.nullspace()&lt;/code&gt; to check Examples 1 and 2.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

SymPy returns $(1, 2, 3)$, $(0, 1, 1)$; $(1, 2, 0, 1)$, $(0, 0, 1, 1)$; $(-2, 1, 0, 0)$, $(-1, 0, -1, 1)$; $(-1, -1, 1)$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$\operatorname{Col} A, \operatorname{Nul} A^T \subseteq \mathbb{R}^m$; $\operatorname{Row} A, \operatorname{Nul} A \subseteq \mathbb{R}^n$.&lt;/li&gt;
    &lt;li&gt;Nonzero rows of $U$: basis of $\operatorname{Row} A$. Pivot columns &lt;em&gt;of $A$&lt;/em&gt;: basis of $\operatorname{Col} A$. Special solutions: basis of $\operatorname{Nul} A$.&lt;/li&gt;
    &lt;li&gt;$\dim \operatorname{Col} A = \dim \operatorname{Row} A = \operatorname{rank} A$.&lt;/li&gt;
    &lt;li&gt;$Ax = b$ is solvable $\iff y^T b = 0$ for every $y \in \operatorname{Nul} A^T$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Basis and dimension</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter05/05_03_Co_So_Va_So_Chieu/"/>
   <updated>2026-01-05T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter05/05_03_Co_So_Va_So_Chieu</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;check whether a family of vectors is a basis;&lt;/li&gt;
    &lt;li&gt;explain why all bases of a space have the same number of vectors;&lt;/li&gt;
    &lt;li&gt;find a basis and the dimension of a subspace given by a spanning set or by a homogeneous system;&lt;/li&gt;
    &lt;li&gt;shrink a spanning set to a basis and extend an independent set to a basis.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Take four vectors in $\mathbb{R}^3$:&lt;/p&gt;

\[v_1 = (1, 2, 1),\quad v_2 = (2, 4, 2),\quad v_3 = (1, 0, 1),\quad v_4 = (0, 1, 0).\]

&lt;p&gt;What is their span? We see $v_2 = 2v_1$ and $v_4 = \tfrac12(v_1 - v_3)$. So $v_1, v_3$ alone already span everything, and they are not parallel. The span is a plane through the origin with normal $v_1 \times v_3 = (2, 0, -2)$, i.e. the plane $x = z$. Two of the four vectors were redundant. The pair $v_1, v_3$ is a &lt;em&gt;basis&lt;/em&gt; of the plane, and the number 2 is its &lt;em&gt;dimension&lt;/em&gt;.&lt;/p&gt;

&lt;h2 id=&quot;bases&quot;&gt;Bases&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Basis).&lt;/strong&gt; A family $\{b_1, \dots, b_n\}$ in a vector space $V$ is a &lt;em&gt;basis&lt;/em&gt; of $V$ if it is linearly independent and spans $V$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Unique representation).&lt;/strong&gt; $\{b_1, \dots, b_n\}$ is a basis of $V$ if and only if every $v \in V$ can be written &lt;em&gt;uniquely&lt;/em&gt; as $v = c_1 b_1 + \dots + c_n b_n$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; “Can be written” is spanning. If $v = \sum c_i b_i = \sum d_i b_i$ then $\sum (c_i - d_i) b_i = 0$, and independence gives $c_i = d_i$. Conversely, if representations are always unique, then $0 = \sum 0 \cdot b_i$ is the only representation of 0, which is independence.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Examples: $\{e_1, \dots, e_n\}$ is the &lt;em&gt;standard basis&lt;/em&gt; of $\mathbb{R}^n$; $\{1, x, \dots, x^n\}$ is a basis of $P_n$; the four matrices $E_{11}, E_{12}, E_{21}, E_{22}$ (a single 1, zeros elsewhere) form a basis of $M_{2 \times 2}$.&lt;/p&gt;

&lt;h2 id=&quot;dimension&quot;&gt;Dimension&lt;/h2&gt;

&lt;div class=&quot;textbook-lemma&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Lemma 1 (Exchange lemma).&lt;/strong&gt; If $V$ is spanned by $m$ vectors $w_1, \dots, w_m$, then every linearly independent family in $V$ has at most $m$ vectors.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Suppose $u_1, \dots, u_k \in V$ with $k &amp;gt; m$. Each $u_j = \sum_i a_{ij} w_i$. Form the $m \times k$ matrix $A = [a_{ij}]$. The homogeneous system $Ac = 0$ has more unknowns than equations, so it has a solution $c \ne 0$ (Lesson 2.5). Then&lt;/p&gt;

\[\sum_j c_j u_j = \sum_j c_j \sum_i a_{ij} w_i = \sum_i \Big( \sum_j a_{ij} c_j \Big) w_i = \sum_i 0 \cdot w_i = 0,\]

  &lt;p&gt;so $u_1, \dots, u_k$ are dependent.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2.&lt;/strong&gt; If $V$ has a basis of $n$ vectors, every basis of $V$ has exactly $n$ vectors. The number $n$ is the &lt;em&gt;dimension&lt;/em&gt; of $V$, written $\dim V$. By convention $\dim\{0\} = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Take two bases with $n$ and $k$ vectors. The second is independent and the first spans $V$, so $k \le n$ by Lemma 1. Swapping roles gives $n \le k$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;So $\dim \mathbb{R}^n = n$, $\dim P_n = n + 1$, $\dim M_{m \times n} = mn$. The space $F(\mathbb{R})$ has no finite basis: the functions $1, x, x^2, \dots$ give independent families of any size. We call it &lt;em&gt;infinite-dimensional&lt;/em&gt;.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 3.&lt;/strong&gt; Let $\dim V = n$.&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;Every spanning set of $V$ contains a basis (remove vectors that are combinations of the others).&lt;/li&gt;
    &lt;li&gt;Every independent family in $V$ can be extended to a basis.&lt;/li&gt;
    &lt;li&gt;A family of exactly $n$ vectors is a basis if it is independent, or if it spans $V$; only one condition needs checking.&lt;/li&gt;
    &lt;li&gt;If $W$ is a subspace of $V$, then $\dim W \le n$, with equality exactly when $W = V$.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; (1) If a spanning set is dependent, one vector is a combination of the others (Lesson 1.5); removing it keeps the span. Repeat until independent. (2) If an independent family $S$ does not span $V$, take $v \notin \operatorname{span} S$; then $S \cup \{v\}$ is still independent (otherwise $v$ would be a combination of $S$). By Lemma 1 this stops after at most $n$ vectors. (3) An independent family of $n$ vectors: if it could be extended, there would be a basis with more than $n$ vectors, contradicting Theorem 2. A spanning family of $n$ vectors: by (1) it contains a basis, which must have $n$ vectors, so it is the family itself. (4) A basis of $W$ is independent in $V$, so it has at most $n$ vectors; if exactly $n$, by (3) it is a basis of $V$, so $W = V$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;finding-bases-in-practice&quot;&gt;Finding bases in practice&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (from a spanning set).&lt;/strong&gt; For the four vectors of the motivating example, put them in columns and eliminate:&lt;/p&gt;

\[\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 1 &amp;amp; 0 \\ 2 &amp;amp; 4 &amp;amp; 0 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 1 &amp;amp; 0 \end{bmatrix} \to \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; -2 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \end{bmatrix} .\]

  &lt;p&gt;The pivot columns are 1 and 3. The &lt;em&gt;corresponding columns of the original matrix&lt;/em&gt;, $v_1$ and $v_3$, form a basis of the span; the dimension is 2. (Lesson 5.4 explains why we take columns of the original matrix rather than of the echelon form.)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (from a system).&lt;/strong&gt; Find a basis of $W = \{x \in \mathbb{R}^4 : x_1 + x_2 - x_3 = 0,\ x_2 + x_4 = 0\}$.&lt;/p&gt;

  &lt;p&gt;The matrix is already in echelon form, with pivots in columns 1 and 2 and free variables $x_3 = s$, $x_4 = t$. The second equation gives $x_2 = -t$, the first $x_1 = s + t$:&lt;/p&gt;

\[x = s\,(1, 0, 1, 0) + t\,(1, -1, 0, 1) .\]

  &lt;p&gt;These two vectors are independent (look at entries 3 and 4), so they form a basis of $W$ and $\dim W = 2$: four unknowns minus two independent equations.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3 (extending to a basis).&lt;/strong&gt; Extend $u = (1, 1, 0)$ to a basis of $\mathbb{R}^3$. Try adding $e_1$: $\{u, e_1\}$ is independent. Add $e_3$: $\det[u\ e_1\ e_3] = \begin{vmatrix} 1 &amp;amp; 1 &amp;amp; 0 \\ 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{vmatrix} = -1 \ne 0$. So $\{u, e_1, e_3\}$ is a basis; by Theorem 3(3) there is no need to check spanning.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-degrees-of-freedom&quot;&gt;Application: degrees of freedom&lt;/h2&gt;

&lt;p&gt;Dimension is the number of independent parameters needed to describe an element. A symmetric $3 \times 3$ matrix has 6 free entries (3 on the diagonal, 3 above it), so the space of such matrices has dimension 6, not 9. In mechanics, the position and orientation of a rigid body take 6 numbers; in image processing, an affine map of the plane has 6 parameters. When an algorithm must “fit a model”, the dimension tells how many independent equations (measurements) are needed at minimum.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: a basis gives unique coordinates&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag a, b, w: when {a, b} is a basis, w has exactly one pair of coordinates; when a, b are parallel it does not.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter01/to_hop_tuyen_tinh.html?mode=coords&amp;amp;lang=en&quot; title=&quot;Interactive: a basis gives unique coordinates&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter01/to_hop_tuyen_tinh.html?mode=coords&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Find a basis and the dimension of the solutions of $x_1 - 2x_2 + x_3 - x_4 = 0$ in $\mathbb{R}^4$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$x_1 = 2x_2 - x_3 + x_4$: basis $(2, 1, 0, 0)$, $(-1, 0, 1, 0)$, $(1, 0, 0, 1)$; dimension 3.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Is $\{1 + x,\ 1 - x,\ x^2\}$ a basis of $P_2$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Yes. Three vectors in a 3-dimensional space; they are independent since $a(1 + x) + b(1 - x) + cx^2 = 0$ gives $a + b = 0$, $a - b = 0$, $c = 0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Find the dimension of the space of symmetric $3 \times 3$ matrices and of the space of skew-symmetric $3 \times 3$ matrices.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

6 and 3. The sum $6 + 3 = 9 = \dim M_{3 \times 3}$ matches the splitting $A = \tfrac12(A + A^T) + \tfrac12(A - A^T)$ of Lesson 3.5.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; Prove $\dim(U + W) = \dim U + \dim W - \dim(U \cap W)$ (hint: start from a basis of $U \cap W$).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Take a basis $z_1, \dots, z_k$ of $U \cap W$, extend it to bases $z, u_1, \dots, u_p$ of $U$ and $z, w_1, \dots, w_q$ of $W$. The family $z, u, w$ spans $U + W$. If $\sum a z + \sum b u + \sum c w = 0$, then $\sum c w = -(\sum a z + \sum b u) \in U \cap W$, so it is a combination of the $z$&apos;s; independence of $z, w$ gives $c = 0$, then independence of $z, u$ gives $a = b = 0$. So $\dim(U + W) = k + p + q$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (programming).&lt;/strong&gt; Use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sympy.Matrix(...).columnspace()&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.nullspace()&lt;/code&gt; to check Examples 1 and 2.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

`columnspace()` returns $v_1, v_3$; `nullspace()` of $\begin{bmatrix} 1 &amp;amp; 1 &amp;amp; -1 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$ returns $(1, 0, 1, 0)$ and $(1, -1, 0, 1)$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Basis = linearly independent + spans $V$; every vector has a unique representation in a basis.&lt;/li&gt;
    &lt;li&gt;All bases have the same size, $\dim V$. $\dim \mathbb{R}^n = n$, $\dim P_n = n + 1$, $\dim M_{m \times n} = mn$.&lt;/li&gt;
    &lt;li&gt;Spanning sets shrink to bases; independent sets extend to bases; with exactly $n$ vectors, check only one condition.&lt;/li&gt;
    &lt;li&gt;From a spanning set: take the pivot columns of the original matrix. From a homogeneous system: each free variable gives one basis vector.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Subspaces</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter05/05_02_Khong_Gian_Con/"/>
   <updated>2026-01-05T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter05/05_02_Khong_Gian_Con</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;use three conditions to test whether a subset is a subspace;&lt;/li&gt;
    &lt;li&gt;recognise that the solution set of a homogeneous system and the span of a family are always subspaces;&lt;/li&gt;
    &lt;li&gt;explain why the solution set of a non-homogeneous system, or a union of two subspaces, is usually not a subspace;&lt;/li&gt;
    &lt;li&gt;describe the subspaces of $\mathbb{R}^2$ and $\mathbb{R}^3$ geometrically.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;The plane $W = \{(x, y, z) : x + y + z = 0\}$ passes through the origin. Take two points $u = (1, -1, 0)$ and $v = (2, 0, -2)$ of $W$. The sum $u + v = (3, -1, -2)$ has $3 - 1 - 2 = 0$, so it is still in $W$. The multiple $5u = (5, -5, 0)$ is in $W$ too. Moving inside the plane by adding and scaling never leaves the plane: $W$ is itself a vector space sitting inside $\mathbb{R}^3$.&lt;/p&gt;

&lt;p&gt;The plane $x + y + z = 1$ is different: $(1, 0, 0)$ and $(0, 1, 0)$ lie on it but their sum $(1, 1, 0)$ has coordinate sum 2. This plane misses the origin.&lt;/p&gt;

&lt;h2 id=&quot;definition-and-test&quot;&gt;Definition and test&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Subspace).&lt;/strong&gt; A subset $W$ of a vector space $V$ is a &lt;em&gt;subspace&lt;/em&gt; if $W$ is a vector space with the addition and scaling of $V$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Subspace test).&lt;/strong&gt; A subset $W \subseteq V$ is a subspace if and only if:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$0 \in W$;&lt;/li&gt;
    &lt;li&gt;$u, v \in W \Rightarrow u + v \in W$;&lt;/li&gt;
    &lt;li&gt;$v \in W,\ c \in \mathbb{R} \Rightarrow cv \in W$.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; If $W$ is a subspace, it is closed under both operations, and its zero vector satisfies $0_W + 0_W = 0_W$ in $V$, so $0_W = 0_V$. Conversely, assume the three conditions. Both operations are closed in $W$. Axioms 1, 2, 5, 6, 7, 8 are identities that hold for all vectors of $V$, hence in $W$. Axiom 3 holds by condition 1. Axiom 4: for $v \in W$, $-v = (-1)v \in W$ by condition 3 and Theorem 1 of Lesson 5.1.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Conditions 2 and 3 can be merged: $u, v \in W \Rightarrow au + bv \in W$ for all $a, b$. In short, $W$ is closed under linear combinations.&lt;/p&gt;

&lt;h2 id=&quot;important-sources-of-subspaces&quot;&gt;Important sources of subspaces&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2.&lt;/strong&gt;&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;For an $m \times n$ matrix $A$, the solution set $\operatorname{Nul} A = \{x \in \mathbb{R}^n : Ax = 0\}$ is a subspace of $\mathbb{R}^n$.&lt;/li&gt;
    &lt;li&gt;For any $v_1, \dots, v_k \in V$, $\operatorname{span}\{v_1, \dots, v_k\}$ is a subspace of $V$.&lt;/li&gt;
    &lt;li&gt;The intersection of two subspaces is a subspace.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; (1) $A0 = 0$; if $Ax = Ay = 0$ then $A(ax + by) = aAx + bAy = 0$. (2) Shown in Lesson 1.4: $0 = \sum 0 \cdot v_i$, and a linear combination of two linear combinations is again one. (3) If $U, W$ are subspaces, $0$ is in both; if $u, v \in U \cap W$ then $au + bv$ is in $U$ and in $W$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;So the plane $x + y + z = 0$ is $\operatorname{Nul} \begin{bmatrix} 1 &amp;amp; 1 &amp;amp; 1 \end{bmatrix}$. Every subspace of $\mathbb{R}^3$ is one of four kinds: $\{0\}$, a line through the origin, a plane through the origin, or all of $\mathbb{R}^3$ (Lesson 5.3 explains this with dimension).&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (symmetric matrices).&lt;/strong&gt; $S = \{A \in M_{2 \times 2} : A^T = A\}$ is a subspace: $0^T = 0$; $(A + B)^T = A^T + B^T = A + B$; $(cA)^T = cA^T = cA$. Each element has the form $\begin{bmatrix} a &amp;amp; b \\ b &amp;amp; d \end{bmatrix} = a \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 0 \end{bmatrix} + b \begin{bmatrix} 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix} + d \begin{bmatrix} 0 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix}$, so $S$ is also the span of these three matrices.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (a union of two lines).&lt;/strong&gt; The $x$-axis and the $y$-axis are subspaces of $\mathbb{R}^2$, but their union is not: $(1, 0) + (0, 1) = (1, 1)$ lies on neither axis. The smallest subspace containing both axes is $\mathbb{R}^2$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3 (in a function space).&lt;/strong&gt; In $P_3$, the set $W = \{p : p(1) = 0\}$ is a subspace: the zero polynomial vanishes at 1, and $(ap + bq)(1) = a\,p(1) + b\,q(1) = 0$. The set $\{p : p(1) = 2\}$ is not, since it does not contain the zero polynomial.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-traffic-flow-in-a-road-network&quot;&gt;Application: traffic flow in a road network&lt;/h2&gt;

&lt;p&gt;An intersection has flows $x_1, x_2$ (cars in) and $x_3$ (cars out). Conservation gives $x_1 + x_2 - x_3 = 0$. For a whole network the conservation constraints form a homogeneous system $Ax = 0$, so the set of valid flows is the subspace $\operatorname{Nul} A$. In practice: superposing two valid flow plans (adding) or scaling all flows evenly (multiplying by a number) still gives a valid plan. When outside traffic enters, the system becomes $Ax = b$ and the solution set is only a translated subspace (Lesson 2.5).&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: subspaces of ℝ³&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Col A and Nul A are always the origin, a line or plane through the origin, or all of ℝ³.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter05/cot_nhan_3d.html?lang=en&quot; title=&quot;Interactive: subspaces of ℝ³&quot; loading=&quot;lazy&quot; style=&quot;height: 760px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter05/cot_nhan_3d.html?lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Which are subspaces of $\mathbb{R}^3$? (a) $\{(x, y, z) : x = 2y\}$; (b) $\{(x, y, z) : x = y^2\}$; (c) $\{(t, 2t, -t) : t \in \mathbb{R}\}$; (d) $\{(x, y, z) : x + y = 1\}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

(a) Yes (the null space of $[1\ \ {-2}\ \ 0]$). (b) No: $(1, 1, 0)$ is in it but $2(1, 1, 0) = (2, 2, 0)$ is not. (c) Yes (a line through the origin). (d) No, it does not contain 0.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Prove that the $3 \times 3$ upper triangular matrices form a subspace of $M_{3 \times 3}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The zero matrix is upper triangular; sums and multiples of matrices whose below-diagonal part is 0 still have that part equal to 0.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Let $U, W$ be subspaces. Prove that $U + W = \{u + w : u \in U, w \in W\}$ is a subspace, and the smallest subspace containing $U \cup W$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$0 = 0 + 0$; $(u + w) + (u&apos; + w&apos;) = (u + u&apos;) + (w + w&apos;)$; $c(u + w) = cu + cw$. Any subspace containing $U$ and $W$ contains every sum $u + w$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; Do the (twice differentiable) functions with $f&apos;&apos; + f = 0$ form a subspace? Give two of them.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Yes, since the equation is linear and homogeneous: $(af + bg)&apos;&apos; + (af + bg) = a(f&apos;&apos; + f) + b(g&apos;&apos; + g) = 0$. For example $\sin x$, $\cos x$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Prove: $U \cup W$ is a subspace if and only if $U \subseteq W$ or $W \subseteq U$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Otherwise take $u \in U \setminus W$ and $w \in W \setminus U$. If $u + w \in U$ then $w = (u + w) - u \in U$, a contradiction; similarly $u + w \notin W$. So $u + w \notin U \cup W$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$W$ is a subspace when it contains 0 and is closed under linear combinations.&lt;/li&gt;
    &lt;li&gt;$\operatorname{Nul} A$, the span of a family, and intersections of subspaces are subspaces.&lt;/li&gt;
    &lt;li&gt;Solution sets of non-homogeneous systems and unions of two subspaces usually are not.&lt;/li&gt;
    &lt;li&gt;Subspaces of $\mathbb{R}^3$: $\{0\}$, lines through the origin, planes through the origin, $\mathbb{R}^3$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Vector spaces: definition and examples</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter05/05_01_Dinh_Nghia_Va_Vi_Du/"/>
   <updated>2026-01-05T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter05/05_01_Dinh_Nghia_Va_Vi_Du</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;state the definition of a vector space with its eight axioms;&lt;/li&gt;
    &lt;li&gt;check the axioms on familiar examples: $\mathbb{R}^n$, matrices, polynomials, functions;&lt;/li&gt;
    &lt;li&gt;point out which axiom fails in a counterexample;&lt;/li&gt;
    &lt;li&gt;prove simple consequences such as $0 \cdot v = 0$ and $(-1)v = -v$.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;In Chapter 1 a vector was a list of numbers $(x_1, \dots, x_n)$. Now look at two polynomials $p(x) = 1 + 2x$ and $q(x) = 3 - x + x^2$. We can add them: $p + q = 4 + x + x^2$. We can multiply by a number: $2p = 2 + 4x$. And the rules are exactly those for vectors in $\mathbb{R}^3$: recording the coefficients of $1, x, x^2$ gives $p \leftrightarrow (1, 2, 0)$, $q \leftrightarrow (3, -1, 1)$, and adding polynomials is adding entries.&lt;/p&gt;

&lt;p&gt;Everything we learned about linear combinations, independence and span uses only these two operations and a few rules. So we make the rules into a definition, and it then applies to polynomials, matrices, functions, signals and images.&lt;/p&gt;

&lt;h2 id=&quot;definition&quot;&gt;Definition&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Vector space).&lt;/strong&gt; A &lt;em&gt;vector space&lt;/em&gt; (over $\mathbb{R}$) is a set $V$ with two operations, addition $u + v \in V$ and scalar multiplication $c\,v \in V$ (for $u, v \in V$, $c \in \mathbb{R}$), satisfying these eight axioms for all $u, v, w \in V$ and all $a, b \in \mathbb{R}$:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$u + v = v + u$;&lt;/li&gt;
    &lt;li&gt;$(u + v) + w = u + (v + w)$;&lt;/li&gt;
    &lt;li&gt;there is an element $0 \in V$ with $v + 0 = v$;&lt;/li&gt;
    &lt;li&gt;for each $v$ there is $-v \in V$ with $v + (-v) = 0$;&lt;/li&gt;
    &lt;li&gt;$1 \cdot v = v$;&lt;/li&gt;
    &lt;li&gt;$a(bv) = (ab)v$;&lt;/li&gt;
    &lt;li&gt;$a(u + v) = au + av$;&lt;/li&gt;
    &lt;li&gt;$(a + b)v = av + bv$.&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;The elements of $V$ are called &lt;em&gt;vectors&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The condition “$u + v \in V$ and $cv \in V$” is called &lt;em&gt;closure&lt;/em&gt;: adding or scaling never takes us outside $V$. This is usually the part that needs checking.&lt;/p&gt;

&lt;h2 id=&quot;examples&quot;&gt;Examples&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (four familiar spaces).&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$\mathbb{R}^n$ with entrywise addition and scaling. The eight axioms follow from properties of real numbers (Lesson 1.1).&lt;/li&gt;
    &lt;li&gt;$M_{m \times n}$, the $m \times n$ matrices, with matrix addition and scaling (Lesson 3.1). The zero vector is the zero matrix.&lt;/li&gt;
    &lt;li&gt;$P_n$, the polynomials of degree at most $n$. The sum of two polynomials of degree $\le n$ still has degree $\le n$, so addition is closed.&lt;/li&gt;
    &lt;li&gt;$F(\mathbb{R})$, all functions $f : \mathbb{R} \to \mathbb{R}$, with $(f + g)(x) = f(x) + g(x)$ and $(cf)(x) = c f(x)$. The zero vector is the constant function 0. Each axiom is checked at each point $x$, which again reduces to real numbers.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (counterexamples).&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;Polynomials of degree &lt;em&gt;exactly&lt;/em&gt; 2 do not form a vector space: $(x^2 + 1) + (-x^2) = 1$ has degree 0. Addition is not closed, and the zero polynomial is missing.&lt;/li&gt;
    &lt;li&gt;The half-plane $H = \{(x, y) : x \ge 0\}$ is closed under addition but not under scaling: $(-1)(1, 0) = (-1, 0) \notin H$. Axiom 4 fails: $(1, 0)$ has no negative in $H$.&lt;/li&gt;
    &lt;li&gt;The line $x + y = 1$ does not contain $(0, 0)$, so it has no zero vector (with the usual operations).&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3 (strange operations that still work).&lt;/strong&gt; Let $V = \{x \in \mathbb{R} : x &amp;gt; 0\}$ with “addition” $x \oplus y = xy$ and “scaling” $c \odot x = x^c$. Check some axioms:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;The zero vector is the number $1$: $x \oplus 1 = x$.&lt;/li&gt;
    &lt;li&gt;The negative of $x$ is $1/x$: $x \oplus (1/x) = 1$.&lt;/li&gt;
    &lt;li&gt;Axiom 8: $(a + b) \odot x = x^{a+b} = x^a x^b = (a \odot x) \oplus (b \odot x)$.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;All eight axioms hold, so $V$ is a vector space. The underlying reason: $\ln$ turns $\oplus$ into ordinary addition and $\odot$ into ordinary multiplication, so $V$ is “the same as” $\mathbb{R}$ (Chapter 6 calls this an isomorphism).&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;first-consequences&quot;&gt;First consequences&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; In every vector space $V$:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;the zero vector is unique, and each $v$ has exactly one negative;&lt;/li&gt;
    &lt;li&gt;$0 \cdot v = 0$ for every $v$;&lt;/li&gt;
    &lt;li&gt;$c \cdot 0 = 0$ for every $c$;&lt;/li&gt;
    &lt;li&gt;$(-1) v = -v$.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; (1) If $0$ and $0&apos;$ are both zero vectors, then $0 = 0 + 0&apos; = 0&apos;$. If $w$ and $w&apos;$ are both negatives of $v$, then $w = w + (v + w&apos;) = (w + v) + w&apos; = w&apos;$.&lt;/p&gt;

  &lt;p&gt;(2) By axiom 8, $0 \cdot v = (0 + 0) v = 0 \cdot v + 0 \cdot v$. Adding $-(0 \cdot v)$ to both sides gives $0 = 0 \cdot v$.&lt;/p&gt;

  &lt;p&gt;(3) Similarly, $c \cdot 0 = c(0 + 0) = c \cdot 0 + c \cdot 0$ by axiom 7.&lt;/p&gt;

  &lt;p&gt;(4) $v + (-1)v = 1 \cdot v + (-1) v = (1 - 1) v = 0 \cdot v = 0$, so $(-1)v$ is a negative of $v$, and by (1) it is $-v$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;These look obvious, but in Example 3 they have content: $0 \odot x = x^0 = 1$ is indeed the “zero vector” of $V$.&lt;/p&gt;

&lt;h2 id=&quot;application-signals-and-images-are-vectors&quot;&gt;Application: signals and images are vectors&lt;/h2&gt;

&lt;p&gt;One second of audio sampled 44,100 times is a vector in $\mathbb{R}^{44100}$. Mixing two tracks is adding vectors; changing the volume is scaling. A $640 \times 480$ grayscale image is an element of $M_{480 \times 640}$; a cross-fade between two images is the combination $(1 - t) A + t B$ as $t$ goes from 0 to 1. Because these are vector spaces, all the tools of later chapters (bases, projections, factorisations) apply at once, for example image compression by SVD in Chapter 11.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: the two operations of the vector space ℝ²&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Addition and scalar multiplication always stay inside ℝ²; try the u + v and k·u tabs.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter01/vecto_2d.html?mode=add&amp;amp;lang=en&quot; title=&quot;Interactive: the two operations of the vector space ℝ²&quot; loading=&quot;lazy&quot; style=&quot;height: 620px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter01/vecto_2d.html?mode=add&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Which of these are vector spaces with the usual operations? (a) $\{(x, y, z) : z = 0\}$; (b) $\{(x, y) : xy \ge 0\}$; (c) the $2 \times 2$ matrices with trace 0.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

(a) Yes. (b) No: $(1, 0) + (0, -1) = (1, -1)$ has $xy &amp;lt; 0$. (c) Yes: the trace of a sum is the sum of the traces, and the trace of $cA$ is $c$ times the trace.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; In $F(\mathbb{R})$, which function is $-f$? Do the continuous functions form a vector space?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$(-f)(x) = -f(x)$. Yes: sums and multiples of continuous functions are continuous, and the zero function is continuous.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Check all eight axioms for Example 3.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

For instance, axiom 6: $a \odot (b \odot x) = (x^b)^a = x^{ab}$; axiom 7: $a \odot (x \oplus y) = (xy)^a = x^a y^a$; axiom 5: $x^1 = x$. Axioms 1 and 2 are commutativity and associativity of multiplication of positive numbers.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; On $\mathbb{R}^2$ use the usual addition but $c \odot (x, y) = (cx, 0)$. Which axiom fails?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Axiom 5: $1 \odot (x, y) = (x, 0) \ne (x, y)$ when $y \ne 0$. The other axioms still hold, so axiom 5 is not redundant.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Prove: if $cv = 0$ then $c = 0$ or $v = 0$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

If $c \ne 0$, multiply by $1/c$: $v = 1 \cdot v = (\tfrac1c c) v = \tfrac1c (cv) = \tfrac1c \cdot 0 = 0$, using axioms 5, 6 and Theorem 1(3).

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;A vector space is a set with addition and scaling that is closed and satisfies eight axioms.&lt;/li&gt;
    &lt;li&gt;Examples: $\mathbb{R}^n$, $M_{m \times n}$, $P_n$, $F(\mathbb{R})$; counterexamples usually fail closure or lack a zero vector.&lt;/li&gt;
    &lt;li&gt;From the axioms: the zero vector and negatives are unique, $0 \cdot v = 0$, $(-1)v = -v$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Định thức của tích và ý nghĩa hình học</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter04/04_05_Dinh_Thuc_Cua_Tich_Va_Y_Nghia_Hinh_Hoc/"/>
   <updated>2026-01-04T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter04/04_05_Dinh_Thuc_Cua_Tich_Va_Y_Nghia_Hinh_Hoc</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;dùng $\det(AB) = \det A \det B$, $\det A^T = \det A$ và $\det A^{-1} = 1/\det A$;&lt;/li&gt;
    &lt;li&gt;giải thích các công thức trên bằng hệ số co giãn thể tích;&lt;/li&gt;
    &lt;li&gt;tính diện tích ảnh của một hình qua phép biến đổi tuyến tính;&lt;/li&gt;
    &lt;li&gt;liên hệ dấu định thức với việc giữ hay đảo định hướng.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Lấy $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$ và $B = \begin{bmatrix} 1 &amp;amp; 3 \\ 0 &amp;amp; 2 \end{bmatrix}$. $\det A = 1$, $\det B = 2$. Phép $x \mapsto ABx$ là làm $B$ trước, rồi $A$. $B$ nhân mọi diện tích lên 2 lần, $A$ giữ nguyên diện tích, nên $AB$ phải nhân diện tích lên $2 \cdot 1 = 2$ lần. Tính trực tiếp: $AB = \begin{bmatrix} 2 &amp;amp; 8 \\ 1 &amp;amp; 5 \end{bmatrix}$, $\det(AB) = 10 - 8 = 2$. Không phải trùng hợp.&lt;/p&gt;

&lt;h2 id=&quot;định-thức-của-tích&quot;&gt;Định thức của tích&lt;/h2&gt;

&lt;div class=&quot;textbook-lemma&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Bổ đề 1.&lt;/strong&gt; Nếu $E$ là ma trận sơ cấp (Bài 3.4) thì $\det(EM) = \det E \cdot \det M$ với mọi $M$ cùng cấp.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; $EM$ là $M$ sau một phép biến đổi hàng. Theo Định lý 2 Bài 4.2, $\det(EM) = c \det M$, với $c = -1$ (đổi chỗ hàng), $c$ (nhân hàng với $c$) hoặc $1$ (cộng bội hàng). Lấy $M = I$ thấy $\det E = c$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Với $A, B$ vuông cùng cấp, $\det(AB) = \det A \cdot \det B$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Nếu $A$ không khả nghịch thì $AB$ cũng không khả nghịch (nếu $AB$ khả nghịch thì $A \cdot B(AB)^{-1} = I$, nên $A$ khả nghịch theo Định lý 3 Bài 3.3), nên cả hai vế bằng 0. Nếu $A$ khả nghịch thì $A = E_1 E_2 \cdots E_k$ là tích các ma trận sơ cấp: Gauss–Jordan cho $F_k \cdots F_1 A = I$ (Bài 3.3), nên $A = F_1^{-1} \cdots F_k^{-1}$, và nghịch đảo của ma trận sơ cấp lại là ma trận sơ cấp (Bài 3.4). Áp dụng Bổ đề 1 nhiều lần:&lt;/p&gt;

\[\det(AB) = \det E_1 \det(E_2 \cdots E_k B) = \dots = \det E_1 \cdots \det E_k \det B,\]

  &lt;p&gt;và cũng theo cách đó $\det A = \det E_1 \cdots \det E_k$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Hệ quả 1.&lt;/strong&gt; Nếu $A$ khả nghịch thì $\det(A^{-1}) = 1 / \det A$. Với mọi $P$ khả nghịch, $\det(P^{-1} A P) = \det A$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; $\det A \det A^{-1} = \det I = 1$. Và $\det(P^{-1}AP) = \det P^{-1} \det A \det P = \det A$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2.&lt;/strong&gt; $\det A^T = \det A$. Do đó mọi tính chất theo hàng ở Bài 4.2 cũng đúng theo cột.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Nếu $A$ không khả nghịch thì $A^T$ cũng vậy, hai vế bằng 0. Nếu $A = E_1 \cdots E_k$ thì $A^T = E_k^T \cdots E_1^T$. Với từng loại ma trận sơ cấp: ma trận đổi chỗ và ma trận nhân hàng là đối xứng; ma trận cộng bội hàng là tam giác có đường chéo toàn 1, chuyển vị vẫn là tam giác với đường chéo toàn 1. Vậy $\det E^T = \det E$, và theo Định lý 1, $\det A^T = \det A$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ý-nghĩa-hình-học&quot;&gt;Ý nghĩa hình học&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 3 (Hệ số co giãn).&lt;/strong&gt; Với mọi hình $R$ trong $\mathbb{R}^2$ có diện tích, ảnh $A(R) = \{Ax : x \in R\}$ có diện tích $\lvert \det A \rvert \cdot \operatorname{dt}(R)$. Tương tự với thể tích trong $\mathbb{R}^3$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh (phác thảo).&lt;/strong&gt; Với hình vuông cạnh $h$ đặt tại điểm $p$, ảnh là hình bình hành dựng trên $hAe_1, hAe_2$ (tịnh tiến theo $Ap$), có diện tích $h^2 \lvert \det A \rvert$ theo Bài 4.1. Phủ $R$ bằng lưới ô vuông nhỏ, ảnh của lưới phủ $A(R)$, và cho $h \to 0$. Định nghĩa chặt chẽ của diện tích thuộc về Giải tích (tích phân bội).&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Bây giờ Định lý 1 có nghĩa rõ ràng: co giãn hai lần liên tiếp thì hệ số nhân với nhau. Định lý về $\det A^{-1}$ nói: phép ngược phải “trả lại” diện tích. Dấu cũng nhân với nhau: hai lần lật (hai phép phản xạ) cho một phép giữ định hướng, đúng như quay là tích của hai phản xạ.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (diện tích elip).&lt;/strong&gt; Elip $\dfrac{x^2}{a^2} + \dfrac{y^2}{b^2} \le 1$ là ảnh của hình tròn đơn vị qua $D = \begin{bmatrix} a &amp;amp; 0 \\ 0 &amp;amp; b \end{bmatrix}$: nếu $u^2 + v^2 \le 1$ thì $(x, y) = (au, bv)$ thuộc elip. Theo Định lý 3, diện tích elip là $ab \cdot \pi$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (ma trận trực giao).&lt;/strong&gt; Nếu $Q^T Q = I$ thì $\det Q^T \det Q = (\det Q)^2 = 1$, nên $\det Q = \pm 1$. Phép quay có $\det = 1$; phép phản xạ qua đường thẳng có $\det = -1$. Cả hai giữ nguyên diện tích, chỉ khác về định hướng.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3 (lũy thừa).&lt;/strong&gt; Với $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$ ở trên, $\det A^{10} = 1^{10} = 1$, không cần tính $A^{10}$. Phép biến đổi này kéo dài theo một hướng và nén theo hướng khác nhưng diện tích giữ nguyên, nên lặp bao nhiêu lần cũng vậy. Còn với $B$, $\det B^{10} = 2^{10} = 1024$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-định-thức-jacobi-và-đổi-biến-tích-phân&quot;&gt;Ứng dụng: định thức Jacobi và đổi biến tích phân&lt;/h2&gt;

&lt;p&gt;Một ánh xạ trơn $F : \mathbb{R}^2 \to \mathbb{R}^2$ gần một điểm thì giống phép biến đổi tuyến tính $x \mapsto J x$, với $J$ là ma trận Jacobi (ma trận các đạo hàm riêng). Theo Định lý 3, một ô nhỏ có diện tích $dA$ bị biến thành ô có diện tích xấp xỉ $\lvert \det J \rvert\, dA$. Đó là lý do có thừa số $\lvert \det J \rvert$ trong công thức đổi biến tích phân bội ở khoá Giải tích.&lt;/p&gt;

&lt;p&gt;Với toạ độ cực $x = r\cos\theta$, $y = r\sin\theta$:&lt;/p&gt;

\[\det J = \begin{vmatrix} \cos\theta &amp;amp; -r\sin\theta \\ \sin\theta &amp;amp; r\cos\theta \end{vmatrix} = r,\]

&lt;p&gt;nên $dx\,dy = r\, dr\, d\theta$: một ô nhỏ $dr \times d\theta$ ở xa gốc thì to hơn ô gần gốc, tỉ lệ với $r$.&lt;/p&gt;

&lt;p&gt;Trong xác suất, mật độ chuẩn nhiều chiều có thừa số $1/\sqrt{\det \Sigma}$, với $\Sigma$ là ma trận hiệp phương sai: $\sqrt{\det \Sigma}$ đo “thể tích” của đám mây dữ liệu (Chương 10).&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: định thức của tích&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Ghép B rồi A: diện tích nhân det B rồi nhân det A, nên det(AB) = det A · det B.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=compose&quot; title=&quot;Minh hoạ: định thức của tích&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=compose&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-định-thức-là-hệ-số-co-giãn-diện-tích&quot;&gt;Video ngắn: Định thức là hệ số co giãn diện tích&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/determinant-area.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Phần hai phép biến đổi liên tiếp, xem từ 1:13: làm B thì diện tích thành 2, làm tiếp A thì nhân thêm 1,5, nên det(AB) = det A · det B. Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Cho $\det A = 3$, $\det B = -2$, cấp 3. Tính $\det(AB)$, $\det(A^T B^2)$, $\det(A^{-1} B)$, $\det(2AB^T)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$-6$; $3 \cdot 4 = 12$; $-2/3$; $8 \cdot 3 \cdot (-2) = -48$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Hình vuông đơn vị biến thành hình gì qua $\begin{bmatrix} 1 &amp;amp; 2 \\ 3 &amp;amp; 4 \end{bmatrix}$? Diện tích bao nhiêu, định hướng có bị đảo không?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Hình bình hành dựng trên $(1, 3)$ và $(2, 4)$. $\det = -2$: diện tích 2, định hướng bị đảo.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Chứng minh: nếu $A$ cấp $n$ lẻ và $A^T = -A$ thì $\det A = 0$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\det A = \det A^T = \det(-A) = (-1)^n \det A = -\det A$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Có ma trận thực $A$ cấp 3 nào với $A^2 = -I$ không?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Không: $(\det A)^2 = \det(-I) = -1$ là vô lý với số thực. (Với cấp 2 thì có, ví dụ phép quay $90^\circ$.)

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Dùng Định lý 3 để tính thể tích khối elipxoit $\dfrac{x^2}{a^2} + \dfrac{y^2}{b^2} + \dfrac{z^2}{c^2} \le 1$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Ảnh của quả cầu đơn vị (thể tích $\tfrac43 \pi$) qua $\operatorname{diag}(a, b, c)$: thể tích $\tfrac43 \pi abc$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$\det(AB) = \det A \det B$, $\det A^T = \det A$, $\det A^{-1} = 1/\det A$, $\det(P^{-1}AP) = \det A$.&lt;/li&gt;
    &lt;li&gt;$x \mapsto Ax$ nhân mọi diện tích (thể tích) với $\lvert \det A \rvert$; dấu cho biết có đảo định hướng hay không.&lt;/li&gt;
    &lt;li&gt;Ghép phép biến đổi thì hệ số nhân nhau. Ma trận trực giao có $\det = \pm 1$.&lt;/li&gt;
    &lt;li&gt;Định thức Jacobi là hệ số co giãn cục bộ, dùng khi đổi biến tích phân.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Quy tắc Cramer</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter04/04_04_Quy_Tac_Cramer/"/>
   <updated>2026-01-04T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter04/04_04_Quy_Tac_Cramer</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;phát biểu và chứng minh quy tắc Cramer;&lt;/li&gt;
    &lt;li&gt;giải hệ $2 \times 2$, $3 \times 3$ bằng quy tắc Cramer;&lt;/li&gt;
    &lt;li&gt;biện luận hệ có tham số bằng định thức;&lt;/li&gt;
    &lt;li&gt;giải thích vì sao không dùng quy tắc Cramer cho hệ lớn.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Giải hệ $3x + 2y = 7$, $x - y = -1$ bằng cách khử $y$: nhân phương trình hai với 2 rồi cộng, được $5x = 5$. Làm điều này với hệ tổng quát $ax + by = e$, $cx + dy = f$:&lt;/p&gt;

\[(ad - bc)\, x = ed - bf, \qquad (ad - bc)\, y = af - ec .\]

&lt;p&gt;Cả ba biểu thức đều là định thức cấp 2: $ad - bc = \det A$, $ed - bf$ là định thức khi thay cột 1 của $A$ bằng vế phải, $af - ec$ là định thức khi thay cột 2. Với hệ trên, $\det A = -3 - 2 = -5$, $D_x = \begin{vmatrix} 7 &amp;amp; 2 \\ -1 &amp;amp; -1 \end{vmatrix} = -5$, $D_y = \begin{vmatrix} 3 &amp;amp; 7 \\ 1 &amp;amp; -1 \end{vmatrix} = -10$, nên $x = 1$, $y = 2$.&lt;/p&gt;

&lt;h2 id=&quot;quy-tắc-cramer&quot;&gt;Quy tắc Cramer&lt;/h2&gt;

&lt;p&gt;Ký hiệu $A_i(b)$ là ma trận thu được từ $A$ khi thay cột $i$ bằng vectơ $b$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Quy tắc Cramer).&lt;/strong&gt; Nếu $A$ vuông cấp $n$ và $\det A \ne 0$ thì hệ $Ax = b$ có nghiệm duy nhất, cho bởi&lt;/p&gt;

  &lt;p&gt;\(x_i = \frac{\det A_i(b)}{\det A}, \qquad i = 1, \dots, n .\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Vì $\det A \ne 0$, $A$ khả nghịch (Bài 4.2) và nghiệm duy nhất là $x = A^{-1} b = \frac{1}{\det A} \operatorname{adj}(A)\, b$ (Bài 4.3). Thành phần thứ $i$:&lt;/p&gt;

\[x_i = \frac{1}{\det A} \sum_{k=1}^n C_{ki}\, b_k .\]

  &lt;p&gt;Tổng $\sum_k b_k C_{ki}$ là khai triển Laplace theo cột $i$ của $A_i(b)$: cột $i$ của nó là $b$, còn các phần bù đại số theo cột $i$ không phụ thuộc cột $i$, nên trùng với $C_{ki}$ của $A$. Vậy tổng bằng $\det A_i(b)$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Có một cách nhìn hình học cho $n = 2$: $\det A_1(b)$ là diện tích hình bình hành dựng trên $b$ và $a_2$. Vì $b = x_1 a_1 + x_2 a_2$ và thành phần $x_2 a_2$ song song với $a_2$ không làm đổi diện tích (phép trượt), diện tích này bằng $x_1$ lần diện tích dựng trên $a_1, a_2$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (hệ $3 \times 3$).&lt;/strong&gt;&lt;/p&gt;

\[\begin{cases} 2x_1 + x_2 + x_3 = 7 \\ x_1 - x_2 + 2x_3 = 5 \\ 3x_1 + 2x_2 - x_3 = 4 \end{cases}\]

  &lt;p&gt;$\det A = 2(1 - 4) - 1(-1 - 6) + 1(2 + 3) = -6 + 7 + 5 = 6$. Thay từng cột bằng $b = (7, 5, 4)$:&lt;/p&gt;

\[\det A_1(b) = \begin{vmatrix} 7 &amp;amp; 1 &amp;amp; 1 \\ 5 &amp;amp; -1 &amp;amp; 2 \\ 4 &amp;amp; 2 &amp;amp; -1 \end{vmatrix} = 6, \quad
\det A_2(b) = \begin{vmatrix} 2 &amp;amp; 7 &amp;amp; 1 \\ 1 &amp;amp; 5 &amp;amp; 2 \\ 3 &amp;amp; 4 &amp;amp; -1 \end{vmatrix} = 12, \quad
\det A_3(b) = \begin{vmatrix} 2 &amp;amp; 1 &amp;amp; 7 \\ 1 &amp;amp; -1 &amp;amp; 5 \\ 3 &amp;amp; 2 &amp;amp; 4 \end{vmatrix} = 18 .\]

  &lt;p&gt;Vậy $x = (1, 2, 3)$. Thay lại: $2 + 2 + 3 = 7$, $1 - 2 + 6 = 5$, $3 + 4 - 3 = 4$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (hệ có tham số).&lt;/strong&gt; Biện luận $mx + y = 1$, $x + my = 1$.&lt;/p&gt;

  &lt;p&gt;$\det A = m^2 - 1$, $D_x = \begin{vmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; m \end{vmatrix} = m - 1$, $D_y = \begin{vmatrix} m &amp;amp; 1 \\ 1 &amp;amp; 1 \end{vmatrix} = m - 1$.&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$m \ne \pm 1$: nghiệm duy nhất $x = y = \dfrac{m - 1}{m^2 - 1} = \dfrac{1}{m + 1}$.&lt;/li&gt;
    &lt;li&gt;$m = -1$: $\det A = 0$ nhưng $D_x = -2 \ne 0$, hệ vô nghiệm (hai đường thẳng $-x + y = 1$, $x - y = 1$ song song).&lt;/li&gt;
    &lt;li&gt;$m = 1$: mọi định thức đều bằng 0. Cramer không kết luận được; phải khử Gauss: hai phương trình trùng nhau, hệ có vô số nghiệm.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;p&gt;Ví dụ 2 cho thấy một điểm hay nhầm: khi $\det A = 0$ và mọi $D_i = 0$, hệ &lt;em&gt;có thể&lt;/em&gt; vô số nghiệm nhưng cũng &lt;em&gt;có thể&lt;/em&gt; vô nghiệm (với $n \ge 3$). Khi $\det A = 0$, hãy luôn quay về khử Gauss (Bài 2.4).&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3 (nghiệm phụ thuộc dữ liệu thế nào).&lt;/strong&gt; Với hệ $2 \times 2$ tổng quát, $x = \dfrac{ed - bf}{ad - bc}$. Công thức cho thấy ngay: nghiệm là hàm hữu tỉ của các hệ số, và khi $ad - bc$ gần 0, một thay đổi nhỏ của $e, f$ làm $x$ thay đổi lớn. Chẳng hạn với $a = 1, b = 1, c = 1, d = 1{,}01$, ta có $\det A = 0{,}01$, nên thay $f$ thêm $0{,}01$ làm $x$ đổi $\dfrac{-b \cdot 0{,}01}{0{,}01} = -1$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-tĩnh-học-so-sánh-trong-kinh-tế&quot;&gt;Ứng dụng: tĩnh học so sánh trong kinh tế&lt;/h2&gt;

&lt;p&gt;Trong mô hình cân bằng thị trường tuyến tính, các biến nội sinh (giá, sản lượng) là nghiệm của một hệ $Ax = b$, còn $b$ chứa các biến ngoại sinh (thuế, thu nhập). Nhà kinh tế muốn biết: tăng thu nhập một đơn vị thì giá cân bằng thay đổi bao nhiêu? Quy tắc Cramer cho công thức tường minh $x_i = \det A_i(b) / \det A$, nên đạo hàm theo $b_k$ là $C_{ki} / \det A$, và dấu của nó đọc được từ dấu các định thức. Đây là cách dùng Cramer phổ biến trong giáo trình kinh tế vĩ mô và vi mô.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Khi nào không nên dùng.&lt;/strong&gt; Giải hệ $n \times n$ bằng Cramer cần $n + 1$ định thức. Dù mỗi định thức tính bằng khử Gauss, tổng chi phí cỡ $n^4$, so với $\tfrac23 n^3$ khi khử Gauss một lần. Cramer cũng kém ổn định số hơn. Vì vậy phần mềm không bao giờ giải hệ lớn bằng Cramer.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: quy tắc Cramer bằng diện tích&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo b: diện tích det A₁(b) luôn bằng x₁ lần det A.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=cramer&quot; title=&quot;Minh hoạ: quy tắc Cramer bằng diện tích&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=cramer&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Giải bằng Cramer: $2x - y = 3$, $x + 3y = 5$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\det A = 7$, $D_x = 9 + 5 = 14$, $D_y = 10 - 3 = 7$. $x = 2$, $y = 1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Giải bằng Cramer: $x_1 + x_2 + x_3 = 6$, $x_1 + 2x_2 + 3x_3 = 14$, $x_1 + 4x_2 + 9x_3 = 36$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Ma trận hệ số là Vandermonde với $1, 2, 3$ (theo cột): $\det A = 2$. $D_1 = 2$, $D_2 = 4$, $D_3 = 6$, nên $x = (1, 2, 3)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Biện luận theo $m$: $x + y + z = 1$, $x + my + z = 1$, $x + y + mz = 1$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\det A = (m - 1)^2$ (Bài tập 4, Bài 4.2). Với $m \ne 1$: $D_x = (m-1)^2$, $D_y = D_z = 0$, nghiệm $(1, 0, 0)$. Với $m = 1$: ba phương trình trùng nhau, vô số nghiệm $x + y + z = 1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Chứng minh: nếu $A$ và $b$ có các phần tử nguyên và $\det A = \pm 1$, thì nghiệm của $Ax = b$ có các thành phần nguyên.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\det A_i(b)$ là số nguyên (chỉ cộng, trừ, nhân số nguyên), chia cho $\pm 1$ vẫn là số nguyên.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Tìm ví dụ hệ $3 \times 3$ có $\det A = 0$, $D_1 = D_2 = D_3 = 0$ nhưng vô nghiệm.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$x + y + z = 1$, $x + y + z = 2$, $x + y + z = 3$. Mọi ma trận $A_i(b)$ đều có hai cột bằng nhau (hai cột còn lại của $A$ đều là $(1,1,1)$), nên mọi định thức bằng 0, nhưng hệ mâu thuẫn.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Nếu $\det A \ne 0$: $x_i = \det A_i(b) / \det A$, với $A_i(b)$ là $A$ thay cột $i$ bằng $b$.&lt;/li&gt;
    &lt;li&gt;Chứng minh từ $A^{-1} = \operatorname{adj}(A)/\det A$ và khai triển Laplace theo cột $i$.&lt;/li&gt;
    &lt;li&gt;Khi $\det A = 0$, Cramer không kết luận được đầy đủ; dùng khử Gauss.&lt;/li&gt;
    &lt;li&gt;Cramer tiện cho hệ nhỏ, hệ có tham số và khi cần công thức tường minh; không dùng cho hệ lớn.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Khai triển Laplace và ma trận phụ hợp</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter04/04_03_Khai_Trien_Laplace_Va_Ma_Tran_Phu_Hop/"/>
   <updated>2026-01-04T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter04/04_03_Khai_Trien_Laplace_Va_Ma_Tran_Phu_Hop</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;tính định thức con và phần bù đại số, nhớ bảng dấu kiểu bàn cờ;&lt;/li&gt;
    &lt;li&gt;khai triển định thức theo một hàng hoặc một cột, chọn hàng/cột có nhiều số 0;&lt;/li&gt;
    &lt;li&gt;lập ma trận phụ hợp và tính nghịch đảo của ma trận cấp 2, cấp 3;&lt;/li&gt;
    &lt;li&gt;biết khi nào nên dùng khai triển Laplace và khi nào nên khử Gauss.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Công thức cấp 3 ở Bài 4.1 có dạng&lt;/p&gt;

\[\det A = a_{11} \begin{vmatrix} a_{22} &amp;amp; a_{23} \\ a_{32} &amp;amp; a_{33} \end{vmatrix} - a_{12} \begin{vmatrix} a_{21} &amp;amp; a_{23} \\ a_{31} &amp;amp; a_{33} \end{vmatrix} + a_{13} \begin{vmatrix} a_{21} &amp;amp; a_{22} \\ a_{31} &amp;amp; a_{32} \end{vmatrix} .\]

&lt;p&gt;Mỗi phần tử ở hàng 1 nhân với định thức cấp 2 thu được khi xoá hàng và cột của nó, với dấu luân phiên $+, -, +$. Bài này cho thấy làm vậy được với bất kỳ hàng hay cột nào, ở mọi cấp.&lt;/p&gt;

&lt;h2 id=&quot;định-thức-con-và-phần-bù-đại-số&quot;&gt;Định thức con và phần bù đại số&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1.&lt;/strong&gt; Cho $A$ vuông cấp $n$.&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;&lt;em&gt;Định thức con&lt;/em&gt; $M_{ij}$ là định thức cấp $n-1$ của ma trận thu được khi xoá hàng $i$ và cột $j$ của $A$.&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;Phần bù đại số&lt;/em&gt; (cofactor) của $a_{ij}$ là $C_{ij} = (-1)^{i+j} M_{ij}$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;p&gt;Dấu $(-1)^{i+j}$ xếp theo kiểu bàn cờ, góc trên trái luôn là dấu cộng:&lt;/p&gt;

\[\begin{bmatrix} + &amp;amp; - &amp;amp; + &amp;amp; - \\ - &amp;amp; + &amp;amp; - &amp;amp; + \\ + &amp;amp; - &amp;amp; + &amp;amp; - \\ - &amp;amp; + &amp;amp; - &amp;amp; + \end{bmatrix} .\]

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Khai triển Laplace).&lt;/strong&gt; Với mọi hàng $i$,&lt;/p&gt;

\[\det A = a_{i1} C_{i1} + a_{i2} C_{i2} + \dots + a_{in} C_{in},\]

  &lt;p&gt;và với mọi cột $j$, $\det A = a_{1j} C_{1j} + a_{2j} C_{2j} + \dots + a_{nj} C_{nj}$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh (phác thảo, cho hàng 1).&lt;/strong&gt; Viết hàng 1 là $\sum_j a_{1j} e_j^T$. Theo tính chất tuyến tính (Bài 4.2), $\det A = \sum_j a_{1j} \det A^{(j)}$, trong đó $A^{(j)}$ có hàng 1 là $e_j^T$. Trong $A^{(j)}$, trừ bội của hàng 1 khỏi các hàng khác để làm 0 cột $j$ ở dưới (định thức không đổi). Đổi chỗ cột $j$ lần lượt với các cột $j-1, \dots, 1$: mất $j - 1$ lần đổi chỗ cột, mỗi lần đổi dấu (đổi cột cũng đổi dấu, vì $\det A^T = \det A$, Bài 4.5). Ta được ma trận khối $\begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; A_{1j} \end{bmatrix}$ với $A_{1j}$ là ma trận xoá hàng 1 cột $j$; định thức của nó là $M_{1j}$ (khử theo hàng như Định lý 3 Bài 4.2). Vậy $\det A^{(j)} = (-1)^{j-1} M_{1j} = (-1)^{1+j} M_{1j} = C_{1j}$. Với hàng $i$, trước hết đưa hàng $i$ lên đầu bằng $i - 1$ lần đổi chỗ hàng liền kề; với cột, áp dụng cho $A^T$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (chọn hàng có số 0).&lt;/strong&gt;&lt;/p&gt;

\[A = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 3 \\ 4 &amp;amp; 0 &amp;amp; 1 \\ 2 &amp;amp; 1 &amp;amp; 5 \end{bmatrix} .\]

  &lt;p&gt;Hàng 2 có một số 0, dấu hàng 2 là $-, +, -$:&lt;/p&gt;

  &lt;p&gt;\(\det A = -4 \begin{vmatrix} 2 &amp;amp; 3 \\ 1 &amp;amp; 5 \end{vmatrix} + 0 - 1 \begin{vmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 1 \end{vmatrix} = -4 \cdot 7 - 1 \cdot (-3) = -25 .\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (định thức Vandermonde cấp 3).&lt;/strong&gt;&lt;/p&gt;

\[V = \begin{vmatrix} 1 &amp;amp; a &amp;amp; a^2 \\ 1 &amp;amp; b &amp;amp; b^2 \\ 1 &amp;amp; c &amp;amp; c^2 \end{vmatrix} .\]

  &lt;p&gt;Trừ hàng 1 khỏi hàng 2 và 3: các hàng mới là $(0, b - a, b^2 - a^2)$ và $(0, c - a, c^2 - a^2)$. Khai triển theo cột 1:&lt;/p&gt;

\[V = \begin{vmatrix} b - a &amp;amp; (b-a)(b+a) \\ c - a &amp;amp; (c-a)(c+a) \end{vmatrix} = (b - a)(c - a) \begin{vmatrix} 1 &amp;amp; b + a \\ 1 &amp;amp; c + a \end{vmatrix} = (b - a)(c - a)(c - b) .\]

  &lt;p&gt;Vậy $V \ne 0$ khi và chỉ khi $a, b, c$ đôi một khác nhau. Đây là lý do có đúng một parabol $y = p_0 + p_1 x + p_2 x^2$ đi qua ba điểm có hoành độ khác nhau: ma trận hệ số của hệ tìm $p_0, p_1, p_2$ chính là ma trận Vandermonde.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ma-trận-phụ-hợp-và-công-thức-nghịch-đảo&quot;&gt;Ma trận phụ hợp và công thức nghịch đảo&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 2 (Ma trận phụ hợp).&lt;/strong&gt; &lt;em&gt;Ma trận phụ hợp&lt;/em&gt; của $A$ là chuyển vị của ma trận các phần bù đại số:&lt;/p&gt;

  &lt;p&gt;\(\operatorname{adj}(A) = [C_{ij}]^T, \qquad \text{tức là phần tử } (i, j) \text{ của } \operatorname{adj}(A) \text{ là } C_{ji} .\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2.&lt;/strong&gt; $A \operatorname{adj}(A) = \operatorname{adj}(A) A = (\det A) I$. Do đó nếu $\det A \ne 0$ thì&lt;/p&gt;

  &lt;p&gt;\(A^{-1} = \frac{1}{\det A} \operatorname{adj}(A) .\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Phần tử $(i, k)$ của $A \operatorname{adj}(A)$ là $\sum_j a_{ij} C_{kj}$. Khi $k = i$, đây là khai triển Laplace theo hàng $i$, bằng $\det A$. Khi $k \ne i$, đây là khai triển theo hàng $k$ của ma trận $A&apos;$ thu được từ $A$ bằng cách thay hàng $k$ bởi hàng $i$ (các phần bù $C_{kj}$ không phụ thuộc hàng $k$ nên không đổi). $A&apos;$ có hai hàng bằng nhau nên $\det A&apos; = 0$ (Bổ đề 1, Bài 4.2). Đẳng thức $\operatorname{adj}(A) A = (\det A) I$ chứng minh tương tự bằng khai triển theo cột.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Với cấp 2, $\operatorname{adj} \begin{bmatrix} a &amp;amp; b \\ c &amp;amp; d \end{bmatrix} = \begin{bmatrix} d &amp;amp; -b \\ -c &amp;amp; a \end{bmatrix}$, và ta thu lại công thức của Bài 3.3.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3.&lt;/strong&gt; $C = \begin{bmatrix} 2 &amp;amp; 1 &amp;amp; 0 \\ 1 &amp;amp; 3 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; 2 \end{bmatrix}$. Khai triển theo hàng 1: $\det C = 2(6 - 1) - 1(2 - 0) = 8$. Các phần bù đại số:&lt;/p&gt;

\[C_{11} = 5,\ C_{12} = -2,\ C_{13} = 1,\quad C_{21} = -2,\ C_{22} = 4,\ C_{23} = -2,\quad C_{31} = 1,\ C_{32} = -2,\ C_{33} = 5 .\]

  &lt;p&gt;Ma trận đối xứng nên chuyển vị không đổi gì:&lt;/p&gt;

\[C^{-1} = \frac18 \begin{bmatrix} 5 &amp;amp; -2 &amp;amp; 1 \\ -2 &amp;amp; 4 &amp;amp; -2 \\ 1 &amp;amp; -2 &amp;amp; 5 \end{bmatrix} .\]

  &lt;p&gt;Kiểm tra hàng 1 nhân cột 1: $\tfrac18(2 \cdot 5 + 1 \cdot (-2) + 0) = 1$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-nghịch-đảo-ma-trận-số-nguyên-trong-mật-mã-hill&quot;&gt;Ứng dụng: nghịch đảo ma trận số nguyên trong mật mã Hill&lt;/h2&gt;

&lt;p&gt;Ở Bài 3.3 ta giải mã Hill $2 \times 2$ modulo 26. Với khoá $3 \times 3$, công thức $K^{-1} = (\det K)^{-1} \operatorname{adj}(K)$ vẫn đúng khi làm modulo 26, vì $\operatorname{adj}(K)$ chỉ gồm các phép nhân và cộng số nguyên, không có phép chia. Điều kiện để giải mã được là $\det K$ nguyên tố cùng nhau với 26, tức $\det K$ lẻ và không chia hết cho 13. Khử Gauss thông thường thì cần chia ở mỗi bước, nên công thức phụ hợp tiện hơn trong trường hợp này.&lt;/p&gt;

&lt;p&gt;Ngoài trường hợp đó, khai triển Laplace tốn khoảng $n!$ phép tính, nên chỉ dùng cho $n \le 3$, cho ma trận có nhiều số 0, hoặc cho ma trận có tham số chữ như Ví dụ 2.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: khai triển Laplace từng số hạng&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Chọn hàng hoặc cột, xem bảng dấu, các định thức con và tổng.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter04/laplace.html&quot; title=&quot;Minh hoạ: khai triển Laplace từng số hạng&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter04/laplace.html&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Tính $\begin{vmatrix} 2 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0 \\ 1 &amp;amp; 3 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 2 &amp;amp; 0 \\ 4 &amp;amp; 2 &amp;amp; 1 &amp;amp; 5 \end{vmatrix}$ bằng khai triển theo cột 4.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Chỉ có phần tử $5$ ở vị trí $(4, 4)$, dấu $+$: $5 \begin{vmatrix} 2 &amp;amp; 0 &amp;amp; 1 \\ 1 &amp;amp; 3 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 2 \end{vmatrix} = 5(2 \cdot 6 - 0 + 1 \cdot 1) = 65$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Tìm nghịch đảo của $\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 3 \\ 2 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$ (định thức bằng 13, Ví dụ 1 Bài 4.1) bằng ma trận phụ hợp.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\dfrac{1}{13} \begin{bmatrix} 1 &amp;amp; -2 &amp;amp; 6 \\ 6 &amp;amp; 1 &amp;amp; -3 \\ -2 &amp;amp; 4 &amp;amp; 1 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Chứng minh $\det(\operatorname{adj} A) = (\det A)^{n-1}$ khi $\det A \ne 0$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Lấy định thức hai vế $A \operatorname{adj}(A) = (\det A) I$ và dùng $\det(AB) = \det A \det B$ (Bài 4.5): $\det A \cdot \det(\operatorname{adj} A) = (\det A)^n$, rồi chia cho $\det A$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Tìm parabol $y = p_0 + p_1 x + p_2 x^2$ đi qua $(0, 1)$, $(1, 2)$, $(2, 5)$, và tính định thức Vandermonde của hệ.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$y = 1 + x^2$. Với $a, b, c = 0, 1, 2$: $V = (1)(2)(1) = 2$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (lập trình).&lt;/strong&gt; Cài đặt định thức bằng khai triển Laplace đệ quy, đo thời gian với $n = 5, 6, \dots, 10$ và so với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.det&lt;/code&gt;.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Thời gian Laplace tăng khoảng $n$ lần mỗi khi $n$ tăng 1 (tăng như $n!$); tới $n = 10$ đã mất cỡ giây trong Python, còn `numpy.linalg.det` vẫn dưới một phần nghìn giây.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$C_{ij} = (-1)^{i+j} M_{ij}$; dấu theo kiểu bàn cờ.&lt;/li&gt;
    &lt;li&gt;$\det A = \sum_j a_{ij} C_{ij}$ với mọi hàng $i$, và tương tự với mọi cột. Nên chọn hàng/cột nhiều số 0.&lt;/li&gt;
    &lt;li&gt;$\operatorname{adj}(A) = [C_{ij}]^T$ và $A^{-1} = \operatorname{adj}(A) / \det A$.&lt;/li&gt;
    &lt;li&gt;Khai triển Laplace tốn cỡ $n!$ phép tính; với $n$ lớn hãy khử Gauss.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Tính chất của định thức</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter04/04_02_Tinh_Chat_Cua_Dinh_Thuc/"/>
   <updated>2026-01-04T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter04/04_02_Tinh_Chat_Cua_Dinh_Thuc</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;phát biểu ba tính chất cơ bản của định thức theo hàng;&lt;/li&gt;
    &lt;li&gt;suy ra tác động của từng phép biến đổi sơ cấp lên định thức;&lt;/li&gt;
    &lt;li&gt;tính định thức cấp 4 trở lên bằng khử Gauss;&lt;/li&gt;
    &lt;li&gt;dùng định thức để kiểm tra một ma trận có khả nghịch hay không.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Công thức cấp 3 có 6 số hạng. Viết tương tự cho cấp 4 sẽ có $4! = 24$ số hạng, cấp 10 có hơn 3,6 triệu. Không ai tính như vậy. Hãy nhìn vào ma trận tam giác trên&lt;/p&gt;

\[U = \begin{bmatrix} 2 &amp;amp; 5 &amp;amp; -1 \\ 0 &amp;amp; 3 &amp;amp; 4 \\ 0 &amp;amp; 0 &amp;amp; -1 \end{bmatrix} .\]

&lt;p&gt;Theo công thức cấp 3, chỉ có số hạng $2 \cdot 3 \cdot (-1) = -6$ còn lại, các số hạng khác đều chứa một số 0 dưới đường chéo. Bài này chứng minh điều đó đúng với mọi cấp: định thức của ma trận tam giác là tích các phần tử trên đường chéo. Vậy nếu biết các phép biến đổi hàng làm định thức thay đổi thế nào, ta chỉ cần khử Gauss đưa về dạng tam giác.&lt;/p&gt;

&lt;h2 id=&quot;ba-tính-chất-cơ-bản&quot;&gt;Ba tính chất cơ bản&lt;/h2&gt;

&lt;p&gt;Ta ký hiệu $r_1, \dots, r_n$ là các hàng của $A$ và viết $\det A = D(r_1, \dots, r_n)$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Tính chất xác định định thức).&lt;/strong&gt; Với mọi $n$, có duy nhất một hàm $D$ trên các ma trận vuông cấp $n$ thoả mãn:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;&lt;strong&gt;Tuyến tính theo từng hàng.&lt;/strong&gt; Khi giữ cố định các hàng khác, $D(\dots, \alpha r + \beta r&apos;, \dots) = \alpha D(\dots, r, \dots) + \beta D(\dots, r&apos;, \dots)$.&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Đổi dấu khi đổi chỗ.&lt;/strong&gt; Đổi chỗ hai hàng thì $D$ đổi dấu.&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Chuẩn hoá.&lt;/strong&gt; $D(I) = 1$.&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;Hàm này gọi là &lt;em&gt;định thức&lt;/em&gt;. Với $n = 2, 3$, nó trùng với công thức ở Bài 4.1.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Ta công nhận sự tồn tại và duy nhất (một cách chứng minh dùng công thức theo hoán vị; Bài 4.3 cho một công thức tường minh khác). Với $n = 2$, bạn có thể kiểm tra trực tiếp ba tính chất cho $ad - bc$. Về hình học, tính chất 1 nói: kéo dài một cạnh gấp $\alpha$ lần thì thể tích gấp $\alpha$ lần; tính chất 3 nói khối lập phương đơn vị có thể tích 1.&lt;/p&gt;

&lt;h2 id=&quot;các-hệ-quả&quot;&gt;Các hệ quả&lt;/h2&gt;

&lt;div class=&quot;textbook-lemma&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Bổ đề 1.&lt;/strong&gt; Nếu $A$ có hai hàng bằng nhau thì $\det A = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Đổi chỗ hai hàng bằng nhau, ma trận không đổi nhưng theo tính chất 2 định thức đổi dấu. Vậy $\det A = -\det A$, nên $\det A = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2 (Định thức và phép biến đổi hàng).&lt;/strong&gt;&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;Đổi chỗ hai hàng: định thức đổi dấu.&lt;/li&gt;
    &lt;li&gt;Nhân một hàng với $c$: định thức nhân với $c$.&lt;/li&gt;
    &lt;li&gt;Cộng $k$ lần hàng $j$ vào hàng $i$ ($i \ne j$): định thức không đổi.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; (1) là tính chất 2, (2) là tính chất 1 với $\beta = 0$. Với (3), theo tính chất 1,&lt;/p&gt;

\[D(\dots, r_i + k r_j, \dots, r_j, \dots) = D(\dots, r_i, \dots, r_j, \dots) + k\, D(\dots, r_j, \dots, r_j, \dots),\]

  &lt;p&gt;và số hạng sau bằng 0 theo Bổ đề 1.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Phép biến đổi (3) là phép dùng nhiều nhất khi khử Gauss, và nó &lt;em&gt;không&lt;/em&gt; làm thay đổi định thức. Về hình học, nó là một phép trượt: đẩy một cạnh theo hướng song song với cạnh khác, giữ nguyên đáy và chiều cao.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 3 (Ma trận tam giác).&lt;/strong&gt; Nếu $U$ là ma trận tam giác (trên hoặc dưới) thì $\det U = u_{11} u_{22} \cdots u_{nn}$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Xét $U$ tam giác trên. Nếu mọi $u_{ii} \ne 0$: dùng phép (3) với hàng cuối để khử các phần tử phía trên $u_{nn}$, rồi với hàng $n-1$, … cho tới khi được ma trận đường chéo, định thức không đổi. Theo tính chất 1, rút $u_{11}, \dots, u_{nn}$ ra khỏi từng hàng được $u_{11} \cdots u_{nn} \det I$. Nếu có $u_{ii} = 0$, lấy $i$ lớn nhất như vậy; khử ngược bằng các hàng $i+1, \dots, n$ làm hàng $i$ thành hàng 0, và định thức có hàng 0 bằng 0 (tính chất 1 với $\alpha = 0$). Cả hai vế đều bằng 0. Trường hợp tam giác dưới làm tương tự.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 4.&lt;/strong&gt; Ma trận vuông $A$ khả nghịch khi và chỉ khi $\det A \ne 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Khử Gauss đưa $A$ về dạng bậc thang $U$. Mỗi bước chỉ nhân định thức với một số khác 0 (đổi dấu, hoặc nhân với $c \ne 0$, hoặc giữ nguyên), nên $\det A \ne 0 \iff \det U \ne 0$. $U$ là tam giác trên, nên $\det U \ne 0 \iff$ mọi phần tử đường chéo khác 0 $\iff$ có $n$ phần tử chốt $\iff A$ khả nghịch (Định lý 3 của Bài 3.3).&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;tính-định-thức-bằng-khử-gauss&quot;&gt;Tính định thức bằng khử Gauss&lt;/h2&gt;

&lt;p&gt;Quy trình: khử Gauss, ghi lại số lần đổi chỗ hàng $s$ (và các hệ số nếu có nhân hàng), rồi&lt;/p&gt;

\[\det A = (-1)^s \times (\text{tích các phần tử chốt}).\]

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt;&lt;/p&gt;

\[A = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 1 &amp;amp; 0 \\ 2 &amp;amp; 5 &amp;amp; 3 &amp;amp; 1 \\ 1 &amp;amp; 3 &amp;amp; 4 &amp;amp; 2 \\ 0 &amp;amp; 1 &amp;amp; 2 &amp;amp; 5 \end{bmatrix} .\]

  &lt;p&gt;$R_2 - 2R_1$, $R_3 - R_1$:&lt;/p&gt;

\[\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 1 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; 3 &amp;amp; 2 \\ 0 &amp;amp; 1 &amp;amp; 2 &amp;amp; 5 \end{bmatrix}
\xrightarrow{R_3 - R_2,\ R_4 - R_2}
\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 1 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 2 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 4 \end{bmatrix}
\xrightarrow{R_4 - \frac12 R_3}
\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 1 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 2 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 7/2 \end{bmatrix} .\]

  &lt;p&gt;Chỉ dùng phép (3), không đổi chỗ hàng: $\det A = 1 \cdot 1 \cdot 2 \cdot \tfrac72 = 7$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (có đổi chỗ hàng).&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;\(\begin{vmatrix} 0 &amp;amp; 2 &amp;amp; 1 \\ 1 &amp;amp; 3 &amp;amp; 2 \\ 2 &amp;amp; 4 &amp;amp; 1 \end{vmatrix}
= -\begin{vmatrix} 1 &amp;amp; 3 &amp;amp; 2 \\ 0 &amp;amp; 2 &amp;amp; 1 \\ 2 &amp;amp; 4 &amp;amp; 1 \end{vmatrix}
= -\begin{vmatrix} 1 &amp;amp; 3 &amp;amp; 2 \\ 0 &amp;amp; 2 &amp;amp; 1 \\ 0 &amp;amp; -2 &amp;amp; -3 \end{vmatrix}
= -\begin{vmatrix} 1 &amp;amp; 3 &amp;amp; 2 \\ 0 &amp;amp; 2 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; -2 \end{vmatrix}
= -(1 \cdot 2 \cdot (-2)) = 4 .\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3 (rút nhân tử).&lt;/strong&gt; $\begin{vmatrix} 3 &amp;amp; 6 &amp;amp; 9 \\ 1 &amp;amp; 0 &amp;amp; 2 \\ 2 &amp;amp; 1 &amp;amp; 1 \end{vmatrix} = 3 \begin{vmatrix} 1 &amp;amp; 2 &amp;amp; 3 \\ 1 &amp;amp; 0 &amp;amp; 2 \\ 2 &amp;amp; 1 &amp;amp; 1 \end{vmatrix}$. Khử: $R_2 - R_1 = (0, -2, -1)$, $R_3 - 2R_1 = (0, -3, -5)$, rồi $R_3 - \tfrac32 R_2 = (0, 0, -\tfrac72)$. Định thức bằng $3 \cdot 1 \cdot (-2) \cdot (-\tfrac72) = 21$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-chi-phí-tính-toán&quot;&gt;Ứng dụng: chi phí tính toán&lt;/h2&gt;

&lt;p&gt;Khử Gauss cần khoảng $\tfrac23 n^3$ phép tính, trong khi công thức khai triển đầy đủ có $n!$ số hạng. Với $n = 20$: $\tfrac23 \cdot 8000 \approx 5300$ phép tính so với $20! \approx 2{,}4 \cdot 10^{18}$ số hạng. Hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.det&lt;/code&gt; thực chất làm đúng việc này: phân rã $PA = LU$ (Bài 3.4) rồi nhân các phần tử đường chéo của $U$, kèm dấu của $P$.&lt;/p&gt;

&lt;p&gt;Một lưu ý thực tế: định thức không phải thước đo tốt cho “gần suy biến”. Ma trận $0{,}1 I$ cấp 20 có định thức $10^{-20}$ nhưng rất dễ nghịch đảo. Muốn đo mức độ gần suy biến, người ta dùng số điều kiện (Chương 11).&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: cộng bội cột không đổi định thức&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo k: hình bình hành bị trượt nhưng diện tích giữ nguyên.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=shear&quot; title=&quot;Minh hoạ: cộng bội cột không đổi định thức&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=shear&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Tính bằng khử Gauss: $\begin{vmatrix} 1 &amp;amp; 1 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 2 &amp;amp; 2 \\ 1 &amp;amp; 2 &amp;amp; 3 &amp;amp; 3 \\ 1 &amp;amp; 2 &amp;amp; 3 &amp;amp; 4 \end{vmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Trừ mỗi hàng cho hàng ngay trên nó (từ dưới lên) được ma trận tam giác trên có đường chéo toàn 1. Định thức bằng 1.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Biết $\det A = 5$ với $A$ cấp 3. Tính $\det(2A)$, $\det(-A)$, và định thức của ma trận thu được khi đổi chỗ hàng 1 và hàng 3 của $A$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$2^3 \cdot 5 = 40$; $(-1)^3 \cdot 5 = -5$; $-5$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Chứng minh: nếu một hàng của $A$ là tổ hợp tuyến tính của các hàng khác thì $\det A = 0$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Nếu $r_i = \sum_{j \ne i} c_j r_j$, trừ dần $c_j r_j$ khỏi hàng $i$ (phép (3), định thức không đổi) được hàng 0, nên định thức bằng 0.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Với giá trị nào của $x$ thì $\begin{bmatrix} 1 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; x &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; x \end{bmatrix}$ không khả nghịch?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Trừ hàng 1 khỏi hai hàng còn lại: đường chéo $1, x - 1, x - 1$. Định thức $(x-1)^2 = 0$ khi $x = 1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (lập trình).&lt;/strong&gt; Viết hàm tính định thức bằng khử Gauss có chọn phần tử chốt theo cột (Bài 2.6) và so với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.det&lt;/code&gt; trên ma trận ngẫu nhiên $100 \times 100$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Mỗi lần đổi hàng thì đổi dấu một biến `sign`; kết quả là `sign * prod(diag(U))`. Hai kết quả khớp tới khoảng $10^{-12}$ sai số tương đối. Với $n$ lớn, tích có thể tràn số; khi đó dùng tổng logarit, như `numpy.linalg.slogdet`.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Định thức là hàm duy nhất tuyến tính theo từng hàng, đổi dấu khi đổi chỗ hai hàng, và bằng 1 tại $I$.&lt;/li&gt;
    &lt;li&gt;Đổi chỗ hàng: đổi dấu; nhân hàng với $c$: nhân với $c$; cộng bội hàng khác: không đổi.&lt;/li&gt;
    &lt;li&gt;Ma trận tam giác: định thức là tích đường chéo. Tính định thức bằng khử Gauss, khoảng $\tfrac23 n^3$ phép tính.&lt;/li&gt;
    &lt;li&gt;$A$ khả nghịch $\iff \det A \ne 0$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Định thức cấp 2 và cấp 3 qua diện tích và thể tích</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter04/04_01_Dinh_Thuc_Qua_Dien_Tich_Va_The_Tich/"/>
   <updated>2026-01-04T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter04/04_01_Dinh_Thuc_Qua_Dien_Tich_Va_The_Tich</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;tính định thức cấp 2 và cấp 3;&lt;/li&gt;
    &lt;li&gt;giải thích $\lvert \det A \rvert$ là diện tích hình bình hành (thể tích khối hộp) dựng trên các cột của $A$;&lt;/li&gt;
    &lt;li&gt;giải thích dấu của định thức qua định hướng: có lật hình hay không;&lt;/li&gt;
    &lt;li&gt;dùng định thức để tính diện tích tam giác và kiểm tra ba vectơ đồng phẳng.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Ma trận $A = \begin{bmatrix} 3 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$ biến hình vuông đơn vị (cạnh $e_1, e_2$) thành hình bình hành có cạnh là hai cột $(3, 1)$ và $(1, 2)$. Diện tích hình bình hành là bao nhiêu?&lt;/p&gt;

&lt;p&gt;Vẽ hình chữ nhật $4 \times 3$ bao quanh nó (các đỉnh $(0,0)$, $(3,1)$, $(4,3)$, $(1,2)$). Phần thừa gồm hai tam giác vuông $3 \times 1$, hai tam giác vuông $1 \times 2$, và hai hình vuông $1 \times 1$ ở góc: tổng $3 + 2 + 2 = 7$. Diện tích hình bình hành là $12 - 7 = 5$. Con số $3 \cdot 2 - 1 \cdot 1 = 5$ chính là định thức của $A$. Vì mọi ô vuông nhỏ trên lưới đều biến thành hình bình hành cùng hình dạng, &lt;em&gt;mọi&lt;/em&gt; hình bị $A$ phóng to diện tích đúng 5 lần.&lt;/p&gt;

&lt;h2 id=&quot;định-thức-cấp-2&quot;&gt;Định thức cấp 2&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Định thức cấp 2).&lt;/strong&gt; Với $A = \begin{bmatrix} a &amp;amp; b \\ c &amp;amp; d \end{bmatrix}$,&lt;/p&gt;

  &lt;p&gt;\(\det A = \begin{vmatrix} a &amp;amp; b \\ c &amp;amp; d \end{vmatrix} = ad - bc .\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Diện tích).&lt;/strong&gt; Diện tích hình bình hành dựng trên hai cột $u = (a, c)$ và $v = (b, d)$ của $A$ bằng $\lvert \det A \rvert$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Diện tích bằng đáy nhân chiều cao: $\lVert u \rVert \cdot \lVert v \rVert \sin\theta$, với $\theta$ là góc giữa $u$ và $v$. Bình phương và dùng $\sin^2\theta = 1 - \cos^2\theta$ cùng $u \cdot v = \lVert u \rVert \lVert v \rVert \cos\theta$:&lt;/p&gt;

\[S^2 = \lVert u \rVert^2 \lVert v \rVert^2 - (u \cdot v)^2 = (a^2 + c^2)(b^2 + d^2) - (ab + cd)^2 .\]

  &lt;p&gt;Khai triển, các số hạng $a^2b^2$ và $c^2d^2$ triệt tiêu, còn lại $a^2 d^2 + b^2 c^2 - 2abcd = (ad - bc)^2$. Vậy $S = \lvert ad - bc \rvert$.&lt;/p&gt;
&lt;/div&gt;

&lt;h3 id=&quot;dấu-của-định-thức&quot;&gt;Dấu của định thức&lt;/h3&gt;

&lt;p&gt;Dấu cho biết &lt;em&gt;định hướng&lt;/em&gt;. Nếu đi từ $u$ tới $v$ theo góc nhỏ hơn $180^\circ$ là ngược chiều kim đồng hồ (như từ $e_1$ tới $e_2$), thì $\det A &amp;gt; 0$: phép biến đổi giữ nguyên định hướng. Nếu là cùng chiều kim đồng hồ thì $\det A &amp;lt; 0$: hình bị lật như soi gương. Đổi chỗ hai cột làm đổi dấu: $\begin{vmatrix} 1 &amp;amp; 3 \\ 2 &amp;amp; 1 \end{vmatrix} = -5$.&lt;/p&gt;

&lt;p&gt;Khi $\det A = 0$, hai cột cùng phương, hình bình hành dẹt thành đoạn thẳng, và $A$ ép cả mặt phẳng xuống một đường thẳng. Đúng như Bài 3.3: $A$ khả nghịch khi và chỉ khi $\det A \ne 0$.&lt;/p&gt;

&lt;h2 id=&quot;định-thức-cấp-3&quot;&gt;Định thức cấp 3&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 2 (Định thức cấp 3).&lt;/strong&gt; Với $A = [a_{ij}]$ cấp 3,&lt;/p&gt;

  &lt;p&gt;\(\det A = a_{11}(a_{22}a_{33} - a_{23}a_{32}) - a_{12}(a_{21}a_{33} - a_{23}a_{31}) + a_{13}(a_{21}a_{32} - a_{22}a_{31}) .\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Khai triển ra được sáu số hạng: ba tích theo các “đường chéo xuống” mang dấu cộng, ba tích theo “đường chéo lên” mang dấu trừ (quy tắc Sarrus). Quy tắc Sarrus chỉ đúng cho cấp 3; Bài 4.3 cho cách tổng quát.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2 (Thể tích và tích hỗn tạp).&lt;/strong&gt; Gọi $u, v, w$ là ba cột của $A$. Khi đó&lt;/p&gt;

\[\det A = u \cdot (v \times w),\]

  &lt;p&gt;và $\lvert \det A \rvert$ là thể tích khối hộp (hình hộp xiên) dựng trên $u, v, w$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Viết $v \times w$ theo Định nghĩa 4 của Bài 1.3 rồi nhân vô hướng với $u = (a_{11}, a_{21}, a_{31})$; so sánh với khai triển của $\det A$ (đã sắp lại theo cột đầu) thấy hai biểu thức trùng nhau. Về thể tích: đáy là hình bình hành dựng trên $v, w$, có diện tích $\lVert v \times w \rVert$ (công nhận, sẽ thấy lại ở Bài 4.5). Vectơ $v \times w$ vuông góc với đáy, nên chiều cao là độ dài hình chiếu của $u$ lên hướng đó, bằng $\lvert u \cdot (v \times w) \rvert / \lVert v \times w \rVert$. Nhân đáy với chiều cao được $\lvert u \cdot (v \times w) \rvert$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; $B = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 3 \\ 2 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$:&lt;/p&gt;

\[\det B = 1(1 \cdot 1 - 3 \cdot 0) - 2(0 \cdot 1 - 3 \cdot 2) + 0 = 1 + 12 = 13 .\]

  &lt;p&gt;Phép biến đổi $x \mapsto Bx$ biến khối lập phương đơn vị thành khối hộp có thể tích 13 và giữ nguyên định hướng.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (ba vectơ đồng phẳng).&lt;/strong&gt; Ba vectơ $(1, 2, 3)$, $(4, 5, 6)$, $(7, 8, 9)$ ở Bài 1.5 cho&lt;/p&gt;

\[\begin{vmatrix} 1 &amp;amp; 4 &amp;amp; 7 \\ 2 &amp;amp; 5 &amp;amp; 8 \\ 3 &amp;amp; 6 &amp;amp; 9 \end{vmatrix} = 1(45 - 48) - 4(18 - 24) + 7(12 - 15) = -3 + 24 - 21 = 0 .\]

  &lt;p&gt;Khối hộp dẹt, thể tích 0: ba vectơ nằm trên cùng một mặt phẳng qua gốc, tức phụ thuộc tuyến tính.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3 (diện tích tam giác).&lt;/strong&gt; Tam giác có đỉnh $P = (1, 1)$, $Q = (4, 2)$, $R = (2, 5)$. Hai cạnh từ $P$ là $Q - P = (3, 1)$ và $R - P = (1, 4)$. Tam giác bằng nửa hình bình hành, nên&lt;/p&gt;

\[S = \tfrac12 \left\lvert \begin{vmatrix} 3 &amp;amp; 1 \\ 1 &amp;amp; 4 \end{vmatrix} \right\rvert = \tfrac12 \cdot 11 = 5.5 .\]

  &lt;p&gt;Định thức dương: đi $P \to Q \to R$ là ngược chiều kim đồng hồ.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-diện-tích-đa-giác-và-kiểm-tra-hướng-trong-đồ-hoạ&quot;&gt;Ứng dụng: diện tích đa giác và kiểm tra hướng trong đồ hoạ&lt;/h2&gt;

&lt;p&gt;Cắt một đa giác thành các tam giác chung đỉnh $P$ và cộng diện tích có dấu, ta được &lt;em&gt;công thức dây giày&lt;/em&gt; (shoelace) tính diện tích của đa giác từ toạ độ các đỉnh. Phần mềm bản đồ dùng công thức này để tính diện tích thửa đất.&lt;/p&gt;

&lt;p&gt;Dấu của định thức $2 \times 2$ là phép kiểm tra cơ bản trong hình học tính toán: điểm $R$ nằm bên trái hay bên phải đường đi $P \to Q$. Các thuật toán bao lồi, kiểm tra hai đoạn thẳng có cắt nhau, và việc loại bỏ các mặt quay lưng lại camera trong đồ hoạ 3D (back-face culling) đều dựa trên dấu này.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: định thức là hệ số phóng diện tích&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo hai cột của A: ô vuông đơn vị thành hình bình hành có diện tích ∣det A∣; chữ F bị lật khi det A &amp;lt; 0.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=det&quot; title=&quot;Minh hoạ: định thức là hệ số phóng diện tích&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=det&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-định-thức-là-hệ-số-co-giãn-diện-tích&quot;&gt;Video ngắn: Định thức là hệ số co giãn diện tích&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/determinant-area.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Ô vuông đơn vị biến thành hình bình hành dựng từ hai cột; diện tích có dấu chính là det. Hai cột thẳng hàng thì det = 0, đổi chỗ hai cột thì hình lật và det đổi dấu. Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Tính $\begin{vmatrix} 2 &amp;amp; -3 \\ 4 &amp;amp; 5 \end{vmatrix}$ và $\begin{vmatrix} 1 &amp;amp; 2 &amp;amp; 3 \\ 4 &amp;amp; 5 &amp;amp; 6 \\ 7 &amp;amp; 8 &amp;amp; 10 \end{vmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$10 + 12 = 22$. Định thức cấp 3 bằng $1(50 - 48) - 2(40 - 42) + 3(32 - 35) = 2 + 4 - 9 = -3$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Tính diện tích tam giác có đỉnh $(0, 0)$, $(5, 1)$, $(2, 4)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\tfrac12 \lvert 5 \cdot 4 - 1 \cdot 2 \rvert = 9$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Tìm $t$ để $(1, 1, 0)$, $(1, 0, 1)$, $(0, 1, t)$ đồng phẳng. So với Ví dụ 3 của Bài 1.5.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Định thức bằng $-1 - t$, bằng 0 khi $t = -1$, khớp với Bài 1.5.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Phép quay góc $\theta$ và phép phản xạ qua trục $x$ có định thức bao nhiêu? Giải thích bằng hình học.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Quay: $\cos^2\theta + \sin^2\theta = 1$, giữ diện tích và định hướng. Phản xạ $\begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; -1 \end{bmatrix}$: $-1$, giữ diện tích nhưng lật hình.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Chứng minh ba điểm $(x_1, y_1)$, $(x_2, y_2)$, $(x_3, y_3)$ thẳng hàng khi và chỉ khi $\begin{vmatrix} 1 &amp;amp; x_1 &amp;amp; y_1 \\ 1 &amp;amp; x_2 &amp;amp; y_2 \\ 1 &amp;amp; x_3 &amp;amp; y_3 \end{vmatrix} = 0$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Khai triển (hoặc trừ hàng 1 khỏi hai hàng còn lại) cho định thức bằng $(x_2 - x_1)(y_3 - y_1) - (x_3 - x_1)(y_2 - y_1)$, tức hai lần diện tích có dấu của tam giác. Tam giác suy biến khi và chỉ khi ba điểm thẳng hàng.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$\det \begin{bmatrix} a &amp;amp; b \\ c &amp;amp; d \end{bmatrix} = ad - bc$; cấp 3 có công thức sáu số hạng, $\det[u\ v\ w] = u \cdot (v \times w)$.&lt;/li&gt;
    &lt;li&gt;$\lvert \det A \rvert$ là diện tích (thể tích) của hình dựng trên các cột, và là hệ số co giãn diện tích của $x \mapsto Ax$.&lt;/li&gt;
    &lt;li&gt;Dấu cho biết phép biến đổi giữ hay lật định hướng; $\det A = 0$ khi các cột phụ thuộc tuyến tính.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>The determinant of a product and its geometric meaning</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter04/04_05_Dinh_Thuc_Cua_Tich_Va_Y_Nghia_Hinh_Hoc/"/>
   <updated>2026-01-04T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter04/04_05_Dinh_Thuc_Cua_Tich_Va_Y_Nghia_Hinh_Hoc</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;use $\det(AB) = \det A \det B$, $\det A^T = \det A$ and $\det A^{-1} = 1/\det A$;&lt;/li&gt;
    &lt;li&gt;explain these formulas through volume scaling;&lt;/li&gt;
    &lt;li&gt;compute the area of the image of a region under a linear map;&lt;/li&gt;
    &lt;li&gt;relate the sign of the determinant to keeping or reversing orientation.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Take $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$ and $B = \begin{bmatrix} 1 &amp;amp; 3 \\ 0 &amp;amp; 2 \end{bmatrix}$, with $\det A = 1$, $\det B = 2$. The map $x \mapsto ABx$ applies $B$ first, then $A$. $B$ doubles every area and $A$ keeps areas, so $AB$ must multiply areas by $2 \cdot 1 = 2$. Directly: $AB = \begin{bmatrix} 2 &amp;amp; 8 \\ 1 &amp;amp; 5 \end{bmatrix}$, $\det(AB) = 10 - 8 = 2$. This is no coincidence.&lt;/p&gt;

&lt;h2 id=&quot;the-determinant-of-a-product&quot;&gt;The determinant of a product&lt;/h2&gt;

&lt;div class=&quot;textbook-lemma&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Lemma 1.&lt;/strong&gt; If $E$ is an elementary matrix (Lesson 3.4), then $\det(EM) = \det E \cdot \det M$ for every $M$ of the same size.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; $EM$ is $M$ after one row operation. By Theorem 2 of Lesson 4.2, $\det(EM) = c \det M$ with $c = -1$ (swap), $c$ (scaling a row by $c$) or $1$ (adding a multiple of a row). Taking $M = I$ shows $\det E = c$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; For square matrices $A, B$ of the same size, $\det(AB) = \det A \cdot \det B$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; If $A$ is not invertible, neither is $AB$ (if $AB$ were invertible, $A \cdot B(AB)^{-1} = I$ would make $A$ invertible by Theorem 3 of Lesson 3.3), so both sides are 0. If $A$ is invertible, it is a product of elementary matrices: Gauss–Jordan gives $F_k \cdots F_1 A = I$ (Lesson 3.3), so $A = F_1^{-1} \cdots F_k^{-1}$, and the inverse of an elementary matrix is elementary (Lesson 3.4). Write $A = E_1 E_2 \cdots E_k$ and apply Lemma 1 repeatedly:&lt;/p&gt;

\[\det(AB) = \det E_1 \det(E_2 \cdots E_k B) = \dots = \det E_1 \cdots \det E_k \det B,\]

  &lt;p&gt;and in the same way $\det A = \det E_1 \cdots \det E_k$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Corollary 1.&lt;/strong&gt; If $A$ is invertible, then $\det(A^{-1}) = 1 / \det A$. For every invertible $P$, $\det(P^{-1} A P) = \det A$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; $\det A \det A^{-1} = \det I = 1$. And $\det(P^{-1}AP) = \det P^{-1} \det A \det P = \det A$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2.&lt;/strong&gt; $\det A^T = \det A$. Hence every row property of Lesson 4.2 also holds for columns.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; If $A$ is not invertible, neither is $A^T$, and both sides are 0. If $A = E_1 \cdots E_k$, then $A^T = E_k^T \cdots E_1^T$. For each type of elementary matrix: swap and scaling matrices are symmetric; a row-addition matrix is triangular with ones on the diagonal, and so is its transpose. So $\det E^T = \det E$, and by Theorem 1, $\det A^T = \det A$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;geometric-meaning&quot;&gt;Geometric meaning&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 3 (Scaling factor).&lt;/strong&gt; For every region $R$ in $\mathbb{R}^2$ with an area, the image $A(R) = \{Ax : x \in R\}$ has area $\lvert \det A \rvert \cdot \operatorname{area}(R)$. The same holds for volumes in $\mathbb{R}^3$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof (sketch).&lt;/strong&gt; A square of side $h$ at a point $p$ goes to the parallelogram spanned by $hAe_1, hAe_2$ (translated by $Ap$), with area $h^2 \lvert \det A \rvert$ by Lesson 4.1. Cover $R$ by a fine grid of squares; the images of the squares cover $A(R)$; let $h \to 0$. A rigorous definition of area belongs to Calculus (multiple integrals).&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Now Theorem 1 has a clear meaning: scaling twice multiplies the factors. The formula for $\det A^{-1}$ says the inverse map must “give back” the area. Signs multiply too: two flips (two reflections) give an orientation-preserving map, just as a rotation is a product of two reflections.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (area of an ellipse).&lt;/strong&gt; The ellipse $\dfrac{x^2}{a^2} + \dfrac{y^2}{b^2} \le 1$ is the image of the unit disk under $D = \begin{bmatrix} a &amp;amp; 0 \\ 0 &amp;amp; b \end{bmatrix}$: if $u^2 + v^2 \le 1$ then $(x, y) = (au, bv)$ lies in the ellipse. By Theorem 3, the ellipse has area $ab \cdot \pi$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (orthogonal matrices).&lt;/strong&gt; If $Q^T Q = I$, then $\det Q^T \det Q = (\det Q)^2 = 1$, so $\det Q = \pm 1$. Rotations have $\det = 1$; a reflection in a line has $\det = -1$. Both keep area and differ only in orientation.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3 (powers).&lt;/strong&gt; For $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$ above, $\det A^{10} = 1^{10} = 1$ without computing $A^{10}$. This map stretches along one direction and compresses along another but keeps area, so any number of repetitions does too. For $B$, $\det B^{10} = 2^{10} = 1024$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-the-jacobian-and-change-of-variables&quot;&gt;Application: the Jacobian and change of variables&lt;/h2&gt;

&lt;p&gt;Near a point, a smooth map $F : \mathbb{R}^2 \to \mathbb{R}^2$ looks like the linear map $x \mapsto J x$, where $J$ is the Jacobian matrix (the matrix of partial derivatives). By Theorem 3, a small cell of area $dA$ goes to a cell of area about $\lvert \det J \rvert\, dA$. This is why the factor $\lvert \det J \rvert$ appears in the change-of-variables formula for multiple integrals in the Calculus course.&lt;/p&gt;

&lt;p&gt;For polar coordinates $x = r\cos\theta$, $y = r\sin\theta$:&lt;/p&gt;

\[\det J = \begin{vmatrix} \cos\theta &amp;amp; -r\sin\theta \\ \sin\theta &amp;amp; r\cos\theta \end{vmatrix} = r,\]

&lt;p&gt;so $dx\,dy = r\, dr\, d\theta$: a small $dr \times d\theta$ cell far from the origin is larger than one near it, in proportion to $r$.&lt;/p&gt;

&lt;p&gt;In probability, the multivariate normal density has a factor $1/\sqrt{\det \Sigma}$, where $\Sigma$ is the covariance matrix: $\sqrt{\det \Sigma}$ measures the “volume” of the data cloud (Chapter 10).&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: the determinant of a product&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Apply B then A: areas scale by det B, then by det A, so det(AB) = det A · det B.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=compose&amp;amp;lang=en&quot; title=&quot;Interactive: the determinant of a product&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=compose&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-the-determinant-is-the-area-scaling-factor&quot;&gt;Short video: The determinant is the area scaling factor&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/determinant-area.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;The two-maps part starts at 1:13: B doubles the area, then A multiplies it by 1.5, so det(AB) = det A · det B. Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Given $\det A = 3$, $\det B = -2$, both $3 \times 3$. Find $\det(AB)$, $\det(A^T B^2)$, $\det(A^{-1} B)$, $\det(2AB^T)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$-6$; $3 \cdot 4 = 12$; $-2/3$; $8 \cdot 3 \cdot (-2) = -48$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; What does $\begin{bmatrix} 1 &amp;amp; 2 \\ 3 &amp;amp; 4 \end{bmatrix}$ do to the unit square? What is the area, and is orientation reversed?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

It becomes the parallelogram spanned by $(1, 3)$ and $(2, 4)$. $\det = -2$: area 2, orientation reversed.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Prove: if $A$ has odd size $n$ and $A^T = -A$, then $\det A = 0$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\det A = \det A^T = \det(-A) = (-1)^n \det A = -\det A$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; Is there a real $3 \times 3$ matrix $A$ with $A^2 = -I$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

No: $(\det A)^2 = \det(-I) = -1$ is impossible for real numbers. (For $2 \times 2$ there is one, e.g. the $90^\circ$ rotation.)

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Use Theorem 3 to find the volume of the solid ellipsoid $\dfrac{x^2}{a^2} + \dfrac{y^2}{b^2} + \dfrac{z^2}{c^2} \le 1$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

It is the image of the unit ball (volume $\tfrac43 \pi$) under $\operatorname{diag}(a, b, c)$: volume $\tfrac43 \pi abc$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$\det(AB) = \det A \det B$, $\det A^T = \det A$, $\det A^{-1} = 1/\det A$, $\det(P^{-1}AP) = \det A$.&lt;/li&gt;
    &lt;li&gt;$x \mapsto Ax$ multiplies every area (volume) by $\lvert \det A \rvert$; the sign tells whether orientation is reversed.&lt;/li&gt;
    &lt;li&gt;Composing maps multiplies the factors. Orthogonal matrices have $\det = \pm 1$.&lt;/li&gt;
    &lt;li&gt;The Jacobian determinant is the local scaling factor used in change of variables.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Cramer's rule</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter04/04_04_Quy_Tac_Cramer/"/>
   <updated>2026-01-04T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter04/04_04_Quy_Tac_Cramer</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;state and prove Cramer’s rule;&lt;/li&gt;
    &lt;li&gt;solve $2 \times 2$ and $3 \times 3$ systems with Cramer’s rule;&lt;/li&gt;
    &lt;li&gt;discuss systems with a parameter using determinants;&lt;/li&gt;
    &lt;li&gt;explain why Cramer’s rule is not used for large systems.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Solve $3x + 2y = 7$, $x - y = -1$ by eliminating $y$: multiply the second equation by 2 and add, giving $5x = 5$. Doing the same for the general system $ax + by = e$, $cx + dy = f$:&lt;/p&gt;

\[(ad - bc)\, x = ed - bf, \qquad (ad - bc)\, y = af - ec .\]

&lt;p&gt;All three expressions are $2 \times 2$ determinants: $ad - bc = \det A$, $ed - bf$ is the determinant with column 1 of $A$ replaced by the right-hand side, and $af - ec$ is the one with column 2 replaced. For the system above, $\det A = -3 - 2 = -5$, $D_x = \begin{vmatrix} 7 &amp;amp; 2 \\ -1 &amp;amp; -1 \end{vmatrix} = -5$, $D_y = \begin{vmatrix} 3 &amp;amp; 7 \\ 1 &amp;amp; -1 \end{vmatrix} = -10$, so $x = 1$, $y = 2$.&lt;/p&gt;

&lt;h2 id=&quot;cramers-rule&quot;&gt;Cramer’s rule&lt;/h2&gt;

&lt;p&gt;Write $A_i(b)$ for the matrix obtained from $A$ by replacing column $i$ with the vector $b$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Cramer’s rule).&lt;/strong&gt; If $A$ is $n \times n$ with $\det A \ne 0$, the system $Ax = b$ has a unique solution, given by&lt;/p&gt;

  &lt;p&gt;\(x_i = \frac{\det A_i(b)}{\det A}, \qquad i = 1, \dots, n .\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Since $\det A \ne 0$, $A$ is invertible (Lesson 4.2) and the unique solution is $x = A^{-1} b = \frac{1}{\det A} \operatorname{adj}(A)\, b$ (Lesson 4.3). Its $i$-th entry is&lt;/p&gt;

\[x_i = \frac{1}{\det A} \sum_{k=1}^n C_{ki}\, b_k .\]

  &lt;p&gt;The sum $\sum_k b_k C_{ki}$ is the Laplace expansion of $A_i(b)$ along column $i$: that column is $b$, and the cofactors along column $i$ do not involve column $i$, so they equal the $C_{ki}$ of $A$. Hence the sum is $\det A_i(b)$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;There is a geometric picture for $n = 2$: $\det A_1(b)$ is the area spanned by $b$ and $a_2$. Since $b = x_1 a_1 + x_2 a_2$ and the part $x_2 a_2$, parallel to $a_2$, does not change the area (a shear), this area is $x_1$ times the area spanned by $a_1, a_2$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (a 3×3 system).&lt;/strong&gt;&lt;/p&gt;

\[\begin{cases} 2x_1 + x_2 + x_3 = 7 \\ x_1 - x_2 + 2x_3 = 5 \\ 3x_1 + 2x_2 - x_3 = 4 \end{cases}\]

  &lt;p&gt;$\det A = 2(1 - 4) - 1(-1 - 6) + 1(2 + 3) = -6 + 7 + 5 = 6$. Replace each column with $b = (7, 5, 4)$:&lt;/p&gt;

\[\det A_1(b) = \begin{vmatrix} 7 &amp;amp; 1 &amp;amp; 1 \\ 5 &amp;amp; -1 &amp;amp; 2 \\ 4 &amp;amp; 2 &amp;amp; -1 \end{vmatrix} = 6, \quad
\det A_2(b) = \begin{vmatrix} 2 &amp;amp; 7 &amp;amp; 1 \\ 1 &amp;amp; 5 &amp;amp; 2 \\ 3 &amp;amp; 4 &amp;amp; -1 \end{vmatrix} = 12, \quad
\det A_3(b) = \begin{vmatrix} 2 &amp;amp; 1 &amp;amp; 7 \\ 1 &amp;amp; -1 &amp;amp; 5 \\ 3 &amp;amp; 2 &amp;amp; 4 \end{vmatrix} = 18 .\]

  &lt;p&gt;So $x = (1, 2, 3)$. Check: $2 + 2 + 3 = 7$, $1 - 2 + 6 = 5$, $3 + 4 - 3 = 4$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (a system with a parameter).&lt;/strong&gt; Discuss $mx + y = 1$, $x + my = 1$.&lt;/p&gt;

  &lt;p&gt;$\det A = m^2 - 1$, $D_x = \begin{vmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; m \end{vmatrix} = m - 1$, $D_y = \begin{vmatrix} m &amp;amp; 1 \\ 1 &amp;amp; 1 \end{vmatrix} = m - 1$.&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$m \ne \pm 1$: unique solution $x = y = \dfrac{m - 1}{m^2 - 1} = \dfrac{1}{m + 1}$.&lt;/li&gt;
    &lt;li&gt;$m = -1$: $\det A = 0$ but $D_x = -2 \ne 0$, so there is no solution (the lines $-x + y = 1$ and $x - y = 1$ are parallel).&lt;/li&gt;
    &lt;li&gt;$m = 1$: every determinant is 0. Cramer’s rule says nothing; eliminate instead: the two equations coincide and there are infinitely many solutions.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;p&gt;Example 2 shows a common mistake: when $\det A = 0$ and all $D_i = 0$, the system &lt;em&gt;may&lt;/em&gt; have infinitely many solutions, but it &lt;em&gt;may&lt;/em&gt; also have none (for $n \ge 3$). When $\det A = 0$, always go back to elimination (Lesson 2.4).&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3 (how the solution depends on the data).&lt;/strong&gt; For the general $2 \times 2$ system, $x = \dfrac{ed - bf}{ad - bc}$. The formula shows directly that the solution is a rational function of the coefficients, and that when $ad - bc$ is close to 0, a small change in $e, f$ makes $x$ change a lot. For instance with $a = 1, b = 1, c = 1, d = 1.01$ we have $\det A = 0.01$, so increasing $f$ by $0.01$ changes $x$ by $\dfrac{-b \cdot 0.01}{0.01} = -1$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-comparative-statics-in-economics&quot;&gt;Application: comparative statics in economics&lt;/h2&gt;

&lt;p&gt;In a linear market equilibrium model the endogenous variables (prices, quantities) solve a system $Ax = b$, where $b$ holds the exogenous variables (taxes, income). An economist asks: if income rises by one unit, how much does the equilibrium price change? Cramer’s rule gives the explicit formula $x_i = \det A_i(b) / \det A$, so the derivative with respect to $b_k$ is $C_{ki} / \det A$, and its sign can be read from the signs of determinants. This is how Cramer’s rule is commonly used in micro- and macroeconomics textbooks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When not to use it.&lt;/strong&gt; Solving an $n \times n$ system by Cramer needs $n + 1$ determinants. Even computing each by elimination, the total cost is about $n^4$, compared with $\tfrac23 n^3$ for one elimination. Cramer’s rule is also less numerically stable. Software never solves large systems this way.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: Cramer&apos;s rule as areas&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag b: the area det A₁(b) always equals x₁ times det A.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=cramer&amp;amp;lang=en&quot; title=&quot;Interactive: Cramer&amp;#39;s rule as areas&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=cramer&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Solve by Cramer’s rule: $2x - y = 3$, $x + 3y = 5$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\det A = 7$, $D_x = 9 + 5 = 14$, $D_y = 10 - 3 = 7$. $x = 2$, $y = 1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Solve by Cramer’s rule: $x_1 + x_2 + x_3 = 6$, $x_1 + 2x_2 + 3x_3 = 14$, $x_1 + 4x_2 + 9x_3 = 36$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The coefficient matrix is a Vandermonde matrix in $1, 2, 3$ (by columns): $\det A = 2$. $D_1 = 2$, $D_2 = 4$, $D_3 = 6$, so $x = (1, 2, 3)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Discuss in terms of $m$: $x + y + z = 1$, $x + my + z = 1$, $x + y + mz = 1$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\det A = (m - 1)^2$ (Exercise 4, Lesson 4.2). For $m \ne 1$: $D_x = (m-1)^2$, $D_y = D_z = 0$, solution $(1, 0, 0)$. For $m = 1$: the three equations coincide, infinitely many solutions $x + y + z = 1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; Prove: if $A$ and $b$ have integer entries and $\det A = \pm 1$, then the solution of $Ax = b$ has integer entries.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\det A_i(b)$ is an integer (only integer additions, subtractions and multiplications), and dividing by $\pm 1$ keeps it an integer.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Find a $3 \times 3$ system with $\det A = 0$ and $D_1 = D_2 = D_3 = 0$ that has no solution.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$x + y + z = 1$, $x + y + z = 2$, $x + y + z = 3$. Every $A_i(b)$ has two equal columns (the remaining columns of $A$ are both $(1,1,1)$), so every determinant is 0, yet the system is inconsistent.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;If $\det A \ne 0$: $x_i = \det A_i(b) / \det A$, where $A_i(b)$ is $A$ with column $i$ replaced by $b$.&lt;/li&gt;
    &lt;li&gt;The proof uses $A^{-1} = \operatorname{adj}(A)/\det A$ and Laplace expansion along column $i$.&lt;/li&gt;
    &lt;li&gt;When $\det A = 0$, Cramer’s rule is not conclusive; use elimination.&lt;/li&gt;
    &lt;li&gt;Cramer’s rule suits small systems, parametric systems and explicit formulas; not large systems.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Laplace expansion and the adjugate</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter04/04_03_Khai_Trien_Laplace_Va_Ma_Tran_Phu_Hop/"/>
   <updated>2026-01-04T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter04/04_03_Khai_Trien_Laplace_Va_Ma_Tran_Phu_Hop</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;compute minors and cofactors, using the checkerboard sign pattern;&lt;/li&gt;
    &lt;li&gt;expand a determinant along any row or column, choosing one with many zeros;&lt;/li&gt;
    &lt;li&gt;build the adjugate and use it to invert $2 \times 2$ and $3 \times 3$ matrices;&lt;/li&gt;
    &lt;li&gt;decide when to use Laplace expansion and when to use elimination.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;The $3 \times 3$ formula of Lesson 4.1 reads&lt;/p&gt;

\[\det A = a_{11} \begin{vmatrix} a_{22} &amp;amp; a_{23} \\ a_{32} &amp;amp; a_{33} \end{vmatrix} - a_{12} \begin{vmatrix} a_{21} &amp;amp; a_{23} \\ a_{31} &amp;amp; a_{33} \end{vmatrix} + a_{13} \begin{vmatrix} a_{21} &amp;amp; a_{22} \\ a_{31} &amp;amp; a_{32} \end{vmatrix} .\]

&lt;p&gt;Each entry of row 1 is multiplied by the $2 \times 2$ determinant left after deleting its row and column, with alternating signs $+, -, +$. This lesson shows the same works along any row or column, in every size.&lt;/p&gt;

&lt;h2 id=&quot;minors-and-cofactors&quot;&gt;Minors and cofactors&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1.&lt;/strong&gt; Let $A$ be $n \times n$.&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;The &lt;em&gt;minor&lt;/em&gt; $M_{ij}$ is the $(n-1) \times (n-1)$ determinant of the matrix obtained by deleting row $i$ and column $j$ of $A$.&lt;/li&gt;
    &lt;li&gt;The &lt;em&gt;cofactor&lt;/em&gt; of $a_{ij}$ is $C_{ij} = (-1)^{i+j} M_{ij}$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;p&gt;The signs $(-1)^{i+j}$ form a checkerboard with a plus in the top-left corner:&lt;/p&gt;

\[\begin{bmatrix} + &amp;amp; - &amp;amp; + &amp;amp; - \\ - &amp;amp; + &amp;amp; - &amp;amp; + \\ + &amp;amp; - &amp;amp; + &amp;amp; - \\ - &amp;amp; + &amp;amp; - &amp;amp; + \end{bmatrix} .\]

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Laplace expansion).&lt;/strong&gt; For every row $i$,&lt;/p&gt;

\[\det A = a_{i1} C_{i1} + a_{i2} C_{i2} + \dots + a_{in} C_{in},\]

  &lt;p&gt;and for every column $j$, $\det A = a_{1j} C_{1j} + a_{2j} C_{2j} + \dots + a_{nj} C_{nj}$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof (sketch, for row 1).&lt;/strong&gt; Write row 1 as $\sum_j a_{1j} e_j^T$. By linearity (Lesson 4.2), $\det A = \sum_j a_{1j} \det A^{(j)}$, where $A^{(j)}$ has row 1 equal to $e_j^T$. In $A^{(j)}$, subtract multiples of row 1 from the other rows to clear column $j$ below it (no change in the determinant). Swap column $j$ successively with columns $j-1, \dots, 1$: that is $j - 1$ column swaps, each changing the sign (column swaps change sign too, because $\det A^T = \det A$, Lesson 4.5). We get the block matrix $\begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; A_{1j} \end{bmatrix}$, where $A_{1j}$ is $A$ with row 1 and column $j$ deleted; its determinant is $M_{1j}$ (eliminate by rows as in Theorem 3 of Lesson 4.2). So $\det A^{(j)} = (-1)^{j-1} M_{1j} = (-1)^{1+j} M_{1j} = C_{1j}$. For row $i$, first move row $i$ to the top with $i - 1$ adjacent swaps; for columns, apply the result to $A^T$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (choose a row with a zero).&lt;/strong&gt;&lt;/p&gt;

\[A = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 3 \\ 4 &amp;amp; 0 &amp;amp; 1 \\ 2 &amp;amp; 1 &amp;amp; 5 \end{bmatrix} .\]

  &lt;p&gt;Row 2 has a zero, and its signs are $-, +, -$:&lt;/p&gt;

  &lt;p&gt;\(\det A = -4 \begin{vmatrix} 2 &amp;amp; 3 \\ 1 &amp;amp; 5 \end{vmatrix} + 0 - 1 \begin{vmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 1 \end{vmatrix} = -4 \cdot 7 - 1 \cdot (-3) = -25 .\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (the 3×3 Vandermonde determinant).&lt;/strong&gt;&lt;/p&gt;

\[V = \begin{vmatrix} 1 &amp;amp; a &amp;amp; a^2 \\ 1 &amp;amp; b &amp;amp; b^2 \\ 1 &amp;amp; c &amp;amp; c^2 \end{vmatrix} .\]

  &lt;p&gt;Subtract row 1 from rows 2 and 3: the new rows are $(0, b - a, b^2 - a^2)$ and $(0, c - a, c^2 - a^2)$. Expand along column 1:&lt;/p&gt;

\[V = \begin{vmatrix} b - a &amp;amp; (b-a)(b+a) \\ c - a &amp;amp; (c-a)(c+a) \end{vmatrix} = (b - a)(c - a) \begin{vmatrix} 1 &amp;amp; b + a \\ 1 &amp;amp; c + a \end{vmatrix} = (b - a)(c - a)(c - b) .\]

  &lt;p&gt;So $V \ne 0$ exactly when $a, b, c$ are distinct. This is why exactly one parabola $y = p_0 + p_1 x + p_2 x^2$ passes through three points with distinct $x$-coordinates: the coefficient matrix of the system for $p_0, p_1, p_2$ is the Vandermonde matrix.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;the-adjugate-and-the-inverse-formula&quot;&gt;The adjugate and the inverse formula&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 2 (Adjugate).&lt;/strong&gt; The &lt;em&gt;adjugate&lt;/em&gt; of $A$ is the transpose of its matrix of cofactors:&lt;/p&gt;

  &lt;p&gt;\(\operatorname{adj}(A) = [C_{ij}]^T, \qquad \text{so the } (i, j) \text{ entry of } \operatorname{adj}(A) \text{ is } C_{ji} .\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2.&lt;/strong&gt; $A \operatorname{adj}(A) = \operatorname{adj}(A) A = (\det A) I$. Hence if $\det A \ne 0$,&lt;/p&gt;

  &lt;p&gt;\(A^{-1} = \frac{1}{\det A} \operatorname{adj}(A) .\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; The $(i, k)$ entry of $A \operatorname{adj}(A)$ is $\sum_j a_{ij} C_{kj}$. For $k = i$ this is the Laplace expansion along row $i$, equal to $\det A$. For $k \ne i$ it is the expansion along row $k$ of the matrix $A&apos;$ obtained from $A$ by replacing row $k$ with row $i$ (the cofactors $C_{kj}$ do not involve row $k$, so they are unchanged). $A&apos;$ has two equal rows, so $\det A&apos; = 0$ (Lemma 1, Lesson 4.2). The identity $\operatorname{adj}(A) A = (\det A) I$ follows the same way using column expansions.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;For $2 \times 2$, $\operatorname{adj} \begin{bmatrix} a &amp;amp; b \\ c &amp;amp; d \end{bmatrix} = \begin{bmatrix} d &amp;amp; -b \\ -c &amp;amp; a \end{bmatrix}$, recovering the formula of Lesson 3.3.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3.&lt;/strong&gt; $C = \begin{bmatrix} 2 &amp;amp; 1 &amp;amp; 0 \\ 1 &amp;amp; 3 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; 2 \end{bmatrix}$. Expanding along row 1: $\det C = 2(6 - 1) - 1(2 - 0) = 8$. The cofactors:&lt;/p&gt;

\[C_{11} = 5,\ C_{12} = -2,\ C_{13} = 1,\quad C_{21} = -2,\ C_{22} = 4,\ C_{23} = -2,\quad C_{31} = 1,\ C_{32} = -2,\ C_{33} = 5 .\]

  &lt;p&gt;The matrix is symmetric, so the transpose changes nothing:&lt;/p&gt;

\[C^{-1} = \frac18 \begin{bmatrix} 5 &amp;amp; -2 &amp;amp; 1 \\ -2 &amp;amp; 4 &amp;amp; -2 \\ 1 &amp;amp; -2 &amp;amp; 5 \end{bmatrix} .\]

  &lt;p&gt;Check row 1 times column 1: $\tfrac18(2 \cdot 5 + 1 \cdot (-2) + 0) = 1$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-inverting-integer-matrices-in-the-hill-cipher&quot;&gt;Application: inverting integer matrices in the Hill cipher&lt;/h2&gt;

&lt;p&gt;In Lesson 3.3 we decoded a $2 \times 2$ Hill cipher modulo 26. For a $3 \times 3$ key, $K^{-1} = (\det K)^{-1} \operatorname{adj}(K)$ still holds modulo 26, because $\operatorname{adj}(K)$ uses only integer multiplication and addition, no division. Decoding is possible when $\det K$ is coprime to 26, that is, odd and not divisible by 13. Ordinary elimination divides at every step, so the adjugate formula is more convenient here.&lt;/p&gt;

&lt;p&gt;Outside such cases, Laplace expansion costs about $n!$ operations, so use it only for $n \le 3$, for matrices with many zeros, or for matrices with symbolic entries as in Example 2.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: Laplace expansion term by term&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Pick a row or column; see the sign pattern, the minors and the sum.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter04/laplace.html?lang=en&quot; title=&quot;Interactive: Laplace expansion term by term&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter04/laplace.html?lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Compute $\begin{vmatrix} 2 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0 \\ 1 &amp;amp; 3 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 2 &amp;amp; 0 \\ 4 &amp;amp; 2 &amp;amp; 1 &amp;amp; 5 \end{vmatrix}$ by expanding along column 4.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Only the entry $5$ at $(4, 4)$ remains, with sign $+$: $5 \begin{vmatrix} 2 &amp;amp; 0 &amp;amp; 1 \\ 1 &amp;amp; 3 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 2 \end{vmatrix} = 5(2 \cdot 6 - 0 + 1 \cdot 1) = 65$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Invert $\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 3 \\ 2 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$ (determinant 13, Example 1 of Lesson 4.1) with the adjugate.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\dfrac{1}{13} \begin{bmatrix} 1 &amp;amp; -2 &amp;amp; 6 \\ 6 &amp;amp; 1 &amp;amp; -3 \\ -2 &amp;amp; 4 &amp;amp; 1 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Prove $\det(\operatorname{adj} A) = (\det A)^{n-1}$ when $\det A \ne 0$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Take determinants in $A \operatorname{adj}(A) = (\det A) I$ and use $\det(AB) = \det A \det B$ (Lesson 4.5): $\det A \cdot \det(\operatorname{adj} A) = (\det A)^n$, then divide by $\det A$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; Find the parabola $y = p_0 + p_1 x + p_2 x^2$ through $(0, 1)$, $(1, 2)$, $(2, 5)$, and compute the Vandermonde determinant of the system.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$y = 1 + x^2$. With $a, b, c = 0, 1, 2$: $V = (1)(2)(1) = 2$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (programming).&lt;/strong&gt; Implement the determinant by recursive Laplace expansion, time it for $n = 5, 6, \dots, 10$ and compare with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.det&lt;/code&gt;.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The Laplace time grows by about a factor $n$ each time $n$ increases by 1 (like $n!$); by $n = 10$ it takes on the order of seconds in Python, while `numpy.linalg.det` stays under a millisecond.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$C_{ij} = (-1)^{i+j} M_{ij}$, with checkerboard signs.&lt;/li&gt;
    &lt;li&gt;$\det A = \sum_j a_{ij} C_{ij}$ for every row $i$, and likewise for every column. Pick a row or column with many zeros.&lt;/li&gt;
    &lt;li&gt;$\operatorname{adj}(A) = [C_{ij}]^T$ and $A^{-1} = \operatorname{adj}(A) / \det A$.&lt;/li&gt;
    &lt;li&gt;Laplace expansion costs about $n!$ operations; for large $n$ use elimination.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Properties of determinants</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter04/04_02_Tinh_Chat_Cua_Dinh_Thuc/"/>
   <updated>2026-01-04T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter04/04_02_Tinh_Chat_Cua_Dinh_Thuc</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;state the three basic row properties of the determinant;&lt;/li&gt;
    &lt;li&gt;derive how each elementary row operation changes the determinant;&lt;/li&gt;
    &lt;li&gt;compute determinants of size 4 and larger by Gaussian elimination;&lt;/li&gt;
    &lt;li&gt;use the determinant to test whether a matrix is invertible.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;The $3 \times 3$ formula has 6 terms. The analogous formula for $4 \times 4$ has $4! = 24$ terms, and for $10 \times 10$ more than 3.6 million. Nobody computes that way. Look at the upper triangular matrix&lt;/p&gt;

\[U = \begin{bmatrix} 2 &amp;amp; 5 &amp;amp; -1 \\ 0 &amp;amp; 3 &amp;amp; 4 \\ 0 &amp;amp; 0 &amp;amp; -1 \end{bmatrix} .\]

&lt;p&gt;In the $3 \times 3$ formula only the term $2 \cdot 3 \cdot (-1) = -6$ survives; every other term contains a zero from below the diagonal. This lesson shows that the same holds in every size: the determinant of a triangular matrix is the product of its diagonal entries. So if we know how row operations change the determinant, we only need to run Gaussian elimination down to triangular form.&lt;/p&gt;

&lt;h2 id=&quot;three-basic-properties&quot;&gt;Three basic properties&lt;/h2&gt;

&lt;p&gt;Write $r_1, \dots, r_n$ for the rows of $A$ and $\det A = D(r_1, \dots, r_n)$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Defining properties).&lt;/strong&gt; For every $n$ there is exactly one function $D$ on $n \times n$ matrices such that:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;&lt;strong&gt;Linear in each row.&lt;/strong&gt; With the other rows fixed, $D(\dots, \alpha r + \beta r&apos;, \dots) = \alpha D(\dots, r, \dots) + \beta D(\dots, r&apos;, \dots)$.&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Sign change on swaps.&lt;/strong&gt; Swapping two rows changes the sign of $D$.&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Normalisation.&lt;/strong&gt; $D(I) = 1$.&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;This function is the &lt;em&gt;determinant&lt;/em&gt;. For $n = 2, 3$ it agrees with the formulas of Lesson 4.1.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;We take existence and uniqueness as known (one proof uses the permutation formula; Lesson 4.3 gives another explicit formula). For $n = 2$ you can check the three properties for $ad - bc$ directly. Geometrically, property 1 says that stretching one edge by $\alpha$ multiplies the volume by $\alpha$; property 3 says the unit cube has volume 1.&lt;/p&gt;

&lt;h2 id=&quot;consequences&quot;&gt;Consequences&lt;/h2&gt;

&lt;div class=&quot;textbook-lemma&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Lemma 1.&lt;/strong&gt; If $A$ has two equal rows, then $\det A = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Swapping the two equal rows leaves the matrix unchanged, but by property 2 it changes the sign of the determinant. So $\det A = -\det A$, hence $\det A = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2 (Determinants and row operations).&lt;/strong&gt;&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;Swapping two rows changes the sign.&lt;/li&gt;
    &lt;li&gt;Multiplying a row by $c$ multiplies the determinant by $c$.&lt;/li&gt;
    &lt;li&gt;Adding $k$ times row $j$ to row $i$ ($i \ne j$) leaves the determinant unchanged.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; (1) is property 2 and (2) is property 1 with $\beta = 0$. For (3), by property 1,&lt;/p&gt;

\[D(\dots, r_i + k r_j, \dots, r_j, \dots) = D(\dots, r_i, \dots, r_j, \dots) + k\, D(\dots, r_j, \dots, r_j, \dots),\]

  &lt;p&gt;and the last term is 0 by Lemma 1.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Operation (3) is the one used most in elimination, and it does &lt;em&gt;not&lt;/em&gt; change the determinant. Geometrically it is a shear: one edge slides parallel to another, keeping base and height.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 3 (Triangular matrices).&lt;/strong&gt; If $U$ is triangular (upper or lower), then $\det U = u_{11} u_{22} \cdots u_{nn}$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Take $U$ upper triangular. If every $u_{ii} \ne 0$: use operation (3) with the last row to clear the entries above $u_{nn}$, then with row $n-1$, and so on, until the matrix is diagonal; the determinant does not change. By property 1, pulling $u_{11}, \dots, u_{nn}$ out of the rows gives $u_{11} \cdots u_{nn} \det I$. If some $u_{ii} = 0$, take the largest such $i$; back-substituting with rows $i+1, \dots, n$ turns row $i$ into a zero row, and a determinant with a zero row is 0 (property 1 with $\alpha = 0$). Both sides are 0. The lower triangular case is similar.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 4.&lt;/strong&gt; A square matrix $A$ is invertible if and only if $\det A \ne 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Elimination takes $A$ to an echelon form $U$. Each step multiplies the determinant by a nonzero number (a sign change, a factor $c \ne 0$, or 1), so $\det A \ne 0 \iff \det U \ne 0$. $U$ is upper triangular, so $\det U \ne 0 \iff$ all diagonal entries are nonzero $\iff$ there are $n$ pivots $\iff A$ is invertible (Theorem 3 of Lesson 3.3).&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;computing-determinants-by-elimination&quot;&gt;Computing determinants by elimination&lt;/h2&gt;

&lt;p&gt;The procedure: eliminate, count the number $s$ of row swaps (and any scaling factors), then&lt;/p&gt;

\[\det A = (-1)^s \times (\text{product of the pivots}).\]

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt;&lt;/p&gt;

\[A = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 1 &amp;amp; 0 \\ 2 &amp;amp; 5 &amp;amp; 3 &amp;amp; 1 \\ 1 &amp;amp; 3 &amp;amp; 4 &amp;amp; 2 \\ 0 &amp;amp; 1 &amp;amp; 2 &amp;amp; 5 \end{bmatrix} .\]

  &lt;p&gt;$R_2 - 2R_1$, $R_3 - R_1$:&lt;/p&gt;

\[\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 1 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; 3 &amp;amp; 2 \\ 0 &amp;amp; 1 &amp;amp; 2 &amp;amp; 5 \end{bmatrix}
\xrightarrow{R_3 - R_2,\ R_4 - R_2}
\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 1 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 2 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 4 \end{bmatrix}
\xrightarrow{R_4 - \frac12 R_3}
\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 1 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 2 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 7/2 \end{bmatrix} .\]

  &lt;p&gt;Only operation (3) was used, no swaps: $\det A = 1 \cdot 1 \cdot 2 \cdot \tfrac72 = 7$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (with a row swap).&lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;\(\begin{vmatrix} 0 &amp;amp; 2 &amp;amp; 1 \\ 1 &amp;amp; 3 &amp;amp; 2 \\ 2 &amp;amp; 4 &amp;amp; 1 \end{vmatrix}
= -\begin{vmatrix} 1 &amp;amp; 3 &amp;amp; 2 \\ 0 &amp;amp; 2 &amp;amp; 1 \\ 2 &amp;amp; 4 &amp;amp; 1 \end{vmatrix}
= -\begin{vmatrix} 1 &amp;amp; 3 &amp;amp; 2 \\ 0 &amp;amp; 2 &amp;amp; 1 \\ 0 &amp;amp; -2 &amp;amp; -3 \end{vmatrix}
= -\begin{vmatrix} 1 &amp;amp; 3 &amp;amp; 2 \\ 0 &amp;amp; 2 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; -2 \end{vmatrix}
= -(1 \cdot 2 \cdot (-2)) = 4 .\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3 (pulling out a factor).&lt;/strong&gt; $\begin{vmatrix} 3 &amp;amp; 6 &amp;amp; 9 \\ 1 &amp;amp; 0 &amp;amp; 2 \\ 2 &amp;amp; 1 &amp;amp; 1 \end{vmatrix} = 3 \begin{vmatrix} 1 &amp;amp; 2 &amp;amp; 3 \\ 1 &amp;amp; 0 &amp;amp; 2 \\ 2 &amp;amp; 1 &amp;amp; 1 \end{vmatrix}$. Eliminate: $R_2 - R_1 = (0, -2, -1)$, $R_3 - 2R_1 = (0, -3, -5)$, then $R_3 - \tfrac32 R_2 = (0, 0, -\tfrac72)$. The determinant is $3 \cdot 1 \cdot (-2) \cdot (-\tfrac72) = 21$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-computational-cost&quot;&gt;Application: computational cost&lt;/h2&gt;

&lt;p&gt;Elimination takes about $\tfrac23 n^3$ operations, while the full expansion has $n!$ terms. For $n = 20$: $\tfrac23 \cdot 8000 \approx 5300$ operations versus $20! \approx 2.4 \cdot 10^{18}$ terms. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.det&lt;/code&gt; does exactly this: it factors $PA = LU$ (Lesson 3.4) and multiplies the diagonal of $U$, with the sign of $P$.&lt;/p&gt;

&lt;p&gt;A practical warning: the determinant is a poor measure of being “nearly singular”. The $20 \times 20$ matrix $0.1 I$ has determinant $10^{-20}$ yet is trivial to invert. To measure closeness to singularity we use the condition number (Chapter 11).&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: adding a multiple of a column keeps the determinant&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag k: the parallelogram shears but its area stays the same.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=shear&amp;amp;lang=en&quot; title=&quot;Interactive: adding a multiple of a column keeps the determinant&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=shear&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Compute by elimination: $\begin{vmatrix} 1 &amp;amp; 1 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 2 &amp;amp; 2 &amp;amp; 2 \\ 1 &amp;amp; 2 &amp;amp; 3 &amp;amp; 3 \\ 1 &amp;amp; 2 &amp;amp; 3 &amp;amp; 4 \end{vmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Subtract from each row the row just above it (working from the bottom up) to get an upper triangular matrix with all ones on the diagonal. The determinant is 1.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Given $\det A = 5$ for a $3 \times 3$ matrix $A$, find $\det(2A)$, $\det(-A)$, and the determinant after swapping rows 1 and 3 of $A$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$2^3 \cdot 5 = 40$; $(-1)^3 \cdot 5 = -5$; $-5$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Prove: if one row of $A$ is a linear combination of the other rows, then $\det A = 0$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

If $r_i = \sum_{j \ne i} c_j r_j$, subtract each $c_j r_j$ from row $i$ (operation (3), no change) to get a zero row, so the determinant is 0.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; For which $x$ is $\begin{bmatrix} 1 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; x &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; x \end{bmatrix}$ not invertible?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Subtract row 1 from the other rows: diagonal $1, x - 1, x - 1$. The determinant $(x-1)^2$ is 0 when $x = 1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (programming).&lt;/strong&gt; Write a determinant function using elimination with partial pivoting (Lesson 2.6) and compare it with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.det&lt;/code&gt; on a random $100 \times 100$ matrix.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Flip a `sign` variable at each row swap; the result is `sign * prod(diag(U))`. The two agree to about $10^{-12}$ relative error. For large $n$ the product can overflow; then sum logarithms instead, as `numpy.linalg.slogdet` does.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;The determinant is the unique function that is linear in each row, changes sign when two rows are swapped, and equals 1 at $I$.&lt;/li&gt;
    &lt;li&gt;Row swap: sign change; scaling a row by $c$: multiply by $c$; adding a multiple of another row: no change.&lt;/li&gt;
    &lt;li&gt;Triangular matrix: product of the diagonal. Compute determinants by elimination, about $\tfrac23 n^3$ operations.&lt;/li&gt;
    &lt;li&gt;$A$ is invertible $\iff \det A \ne 0$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>2×2 and 3×3 determinants as area and volume</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter04/04_01_Dinh_Thuc_Qua_Dien_Tich_Va_The_Tich/"/>
   <updated>2026-01-04T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter04/04_01_Dinh_Thuc_Qua_Dien_Tich_Va_The_Tich</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;compute $2 \times 2$ and $3 \times 3$ determinants;&lt;/li&gt;
    &lt;li&gt;explain $\lvert \det A \rvert$ as the area of the parallelogram (volume of the parallelepiped) spanned by the columns of $A$;&lt;/li&gt;
    &lt;li&gt;explain the sign of the determinant through orientation: whether the shape is flipped;&lt;/li&gt;
    &lt;li&gt;use determinants to find the area of a triangle and to test whether three vectors are coplanar.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;The matrix $A = \begin{bmatrix} 3 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}$ sends the unit square (sides $e_1, e_2$) to the parallelogram with sides equal to the columns $(3, 1)$ and $(1, 2)$. What is its area?&lt;/p&gt;

&lt;p&gt;Draw the $4 \times 3$ rectangle around it (vertices $(0,0)$, $(3,1)$, $(4,3)$, $(1,2)$). The leftover pieces are two $3 \times 1$ right triangles, two $1 \times 2$ right triangles and two $1 \times 1$ corner squares: $3 + 2 + 2 = 7$ in total. The parallelogram has area $12 - 7 = 5$. The number $3 \cdot 2 - 1 \cdot 1 = 5$ is exactly the determinant of $A$. Since every small square of the grid goes to a parallelogram of the same shape, $A$ multiplies the area of &lt;em&gt;every&lt;/em&gt; region by 5.&lt;/p&gt;

&lt;h2 id=&quot;the-22-determinant&quot;&gt;The 2×2 determinant&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (2×2 determinant).&lt;/strong&gt; For $A = \begin{bmatrix} a &amp;amp; b \\ c &amp;amp; d \end{bmatrix}$,&lt;/p&gt;

  &lt;p&gt;\(\det A = \begin{vmatrix} a &amp;amp; b \\ c &amp;amp; d \end{vmatrix} = ad - bc .\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Area).&lt;/strong&gt; The parallelogram spanned by the columns $u = (a, c)$ and $v = (b, d)$ of $A$ has area $\lvert \det A \rvert$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Area is base times height: $\lVert u \rVert \cdot \lVert v \rVert \sin\theta$, where $\theta$ is the angle between $u$ and $v$. Square it and use $\sin^2\theta = 1 - \cos^2\theta$ with $u \cdot v = \lVert u \rVert \lVert v \rVert \cos\theta$:&lt;/p&gt;

\[S^2 = \lVert u \rVert^2 \lVert v \rVert^2 - (u \cdot v)^2 = (a^2 + c^2)(b^2 + d^2) - (ab + cd)^2 .\]

  &lt;p&gt;Expanding, the terms $a^2b^2$ and $c^2d^2$ cancel, leaving $a^2 d^2 + b^2 c^2 - 2abcd = (ad - bc)^2$. So $S = \lvert ad - bc \rvert$.&lt;/p&gt;
&lt;/div&gt;

&lt;h3 id=&quot;the-sign-of-the-determinant&quot;&gt;The sign of the determinant&lt;/h3&gt;

&lt;p&gt;The sign records &lt;em&gt;orientation&lt;/em&gt;. If turning from $u$ to $v$ through the angle less than $180^\circ$ is counterclockwise (as from $e_1$ to $e_2$), then $\det A &amp;gt; 0$: the map keeps orientation. If it is clockwise, $\det A &amp;lt; 0$: the picture is flipped like a mirror image. Swapping the two columns changes the sign: $\begin{vmatrix} 1 &amp;amp; 3 \\ 2 &amp;amp; 1 \end{vmatrix} = -5$.&lt;/p&gt;

&lt;p&gt;When $\det A = 0$ the columns are parallel, the parallelogram collapses to a segment, and $A$ squashes the whole plane onto a line. This matches Lesson 3.3: $A$ is invertible exactly when $\det A \ne 0$.&lt;/p&gt;

&lt;h2 id=&quot;the-33-determinant&quot;&gt;The 3×3 determinant&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 2 (3×3 determinant).&lt;/strong&gt; For a $3 \times 3$ matrix $A = [a_{ij}]$,&lt;/p&gt;

  &lt;p&gt;\(\det A = a_{11}(a_{22}a_{33} - a_{23}a_{32}) - a_{12}(a_{21}a_{33} - a_{23}a_{31}) + a_{13}(a_{21}a_{32} - a_{22}a_{31}) .\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Expanded, this has six terms: three products along “down” diagonals with a plus sign and three along “up” diagonals with a minus sign (the rule of Sarrus). Sarrus’ rule only works for $3 \times 3$; Lesson 4.3 gives the general method.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2 (Volume and the triple product).&lt;/strong&gt; Let $u, v, w$ be the columns of $A$. Then&lt;/p&gt;

\[\det A = u \cdot (v \times w),\]

  &lt;p&gt;and $\lvert \det A \rvert$ is the volume of the parallelepiped spanned by $u, v, w$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Write $v \times w$ by Definition 4 of Lesson 1.3 and dot it with $u = (a_{11}, a_{21}, a_{31})$; comparing with the expansion of $\det A$ (regrouped by the first column) shows the two expressions agree. For the volume: the base is the parallelogram spanned by $v, w$, with area $\lVert v \times w \rVert$ (taken as known here; we meet it again in Lesson 4.5). The vector $v \times w$ is perpendicular to the base, so the height is the length of the projection of $u$ onto that direction, namely $\lvert u \cdot (v \times w) \rvert / \lVert v \times w \rVert$. Base times height gives $\lvert u \cdot (v \times w) \rvert$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; $B = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 3 \\ 2 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$:&lt;/p&gt;

\[\det B = 1(1 \cdot 1 - 3 \cdot 0) - 2(0 \cdot 1 - 3 \cdot 2) + 0 = 1 + 12 = 13 .\]

  &lt;p&gt;The map $x \mapsto Bx$ sends the unit cube to a parallelepiped of volume 13 and keeps orientation.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (coplanar vectors).&lt;/strong&gt; The vectors $(1, 2, 3)$, $(4, 5, 6)$, $(7, 8, 9)$ from Lesson 1.5 give&lt;/p&gt;

\[\begin{vmatrix} 1 &amp;amp; 4 &amp;amp; 7 \\ 2 &amp;amp; 5 &amp;amp; 8 \\ 3 &amp;amp; 6 &amp;amp; 9 \end{vmatrix} = 1(45 - 48) - 4(18 - 24) + 7(12 - 15) = -3 + 24 - 21 = 0 .\]

  &lt;p&gt;The box is flat, with volume 0: the three vectors lie in one plane through the origin, so they are linearly dependent.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3 (area of a triangle).&lt;/strong&gt; Take the triangle with vertices $P = (1, 1)$, $Q = (4, 2)$, $R = (2, 5)$. The edges from $P$ are $Q - P = (3, 1)$ and $R - P = (1, 4)$. The triangle is half a parallelogram, so&lt;/p&gt;

\[S = \tfrac12 \left\lvert \begin{vmatrix} 3 &amp;amp; 1 \\ 1 &amp;amp; 4 \end{vmatrix} \right\rvert = \tfrac12 \cdot 11 = 5.5 .\]

  &lt;p&gt;The determinant is positive, so going $P \to Q \to R$ is counterclockwise.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-polygon-areas-and-orientation-tests-in-graphics&quot;&gt;Application: polygon areas and orientation tests in graphics&lt;/h2&gt;

&lt;p&gt;Cutting a polygon into triangles that share a vertex $P$ and adding their signed areas gives the &lt;em&gt;shoelace formula&lt;/em&gt;, which computes a polygon’s area from the coordinates of its vertices. Mapping software uses it to compute land-parcel areas.&lt;/p&gt;

&lt;p&gt;The sign of a $2 \times 2$ determinant is the basic test in computational geometry: is the point $R$ to the left or to the right of the path $P \to Q$? Convex hull algorithms, segment-intersection tests and back-face culling in 3D graphics (dropping faces that point away from the camera) all rely on this sign.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: the determinant scales area&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag the columns of A: the unit square becomes a parallelogram of area ∣det A∣; the letter F flips when det A &amp;lt; 0.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=det&amp;amp;lang=en&quot; title=&quot;Interactive: the determinant scales area&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=det&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-the-determinant-is-the-area-scaling-factor&quot;&gt;Short video: The determinant is the area scaling factor&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/determinant-area.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;The unit square becomes the parallelogram spanned by the two columns, and its signed area is det. Collinear columns give det = 0; swapping the columns flips the shape and the sign. Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Compute $\begin{vmatrix} 2 &amp;amp; -3 \\ 4 &amp;amp; 5 \end{vmatrix}$ and $\begin{vmatrix} 1 &amp;amp; 2 &amp;amp; 3 \\ 4 &amp;amp; 5 &amp;amp; 6 \\ 7 &amp;amp; 8 &amp;amp; 10 \end{vmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$10 + 12 = 22$. The $3 \times 3$ determinant is $1(50 - 48) - 2(40 - 42) + 3(32 - 35) = 2 + 4 - 9 = -3$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Find the area of the triangle with vertices $(0, 0)$, $(5, 1)$, $(2, 4)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\tfrac12 \lvert 5 \cdot 4 - 1 \cdot 2 \rvert = 9$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Find $t$ such that $(1, 1, 0)$, $(1, 0, 1)$, $(0, 1, t)$ are coplanar. Compare with Example 3 of Lesson 1.5.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The determinant is $-1 - t$, which is 0 when $t = -1$, matching Lesson 1.5.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; What are the determinants of the rotation by $\theta$ and of the reflection in the $x$-axis? Explain geometrically.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Rotation: $\cos^2\theta + \sin^2\theta = 1$, keeping area and orientation. Reflection $\begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; -1 \end{bmatrix}$: $-1$, keeping area but flipping the picture.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Prove that $(x_1, y_1)$, $(x_2, y_2)$, $(x_3, y_3)$ are collinear if and only if $\begin{vmatrix} 1 &amp;amp; x_1 &amp;amp; y_1 \\ 1 &amp;amp; x_2 &amp;amp; y_2 \\ 1 &amp;amp; x_3 &amp;amp; y_3 \end{vmatrix} = 0$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Expanding (or subtracting row 1 from the other rows) gives $(x_2 - x_1)(y_3 - y_1) - (x_3 - x_1)(y_2 - y_1)$, twice the signed area of the triangle. The triangle is degenerate exactly when the points are collinear.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$\det \begin{bmatrix} a &amp;amp; b \\ c &amp;amp; d \end{bmatrix} = ad - bc$; the $3 \times 3$ formula has six terms, and $\det[u\ v\ w] = u \cdot (v \times w)$.&lt;/li&gt;
    &lt;li&gt;$\lvert \det A \rvert$ is the area (volume) spanned by the columns, and the area scaling factor of $x \mapsto Ax$.&lt;/li&gt;
    &lt;li&gt;The sign tells whether the map keeps or flips orientation; $\det A = 0$ when the columns are linearly dependent.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Nhân ma trận nhanh: thuật toán Strassen</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter03/03_06_Nhan_Ma_Tran_Nhanh_Strassen/"/>
   <updated>2026-01-03T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter03/03_06_Nhan_Ma_Tran_Nhanh_Strassen</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;đếm số phép nhân của cách nhân ma trận theo định nghĩa;&lt;/li&gt;
    &lt;li&gt;kiểm tra bảy công thức Strassen cho tích hai ma trận $2 \times 2$;&lt;/li&gt;
    &lt;li&gt;giải thích vì sao áp dụng đệ quy theo khối cho độ phức tạp $O(n^{\log_2 7}) \approx O(n^{2.81})$;&lt;/li&gt;
    &lt;li&gt;biết khi nào thuật toán nhanh có lợi trong thực tế.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Nhân hai ma trận $n \times n$ theo định nghĩa cần $n$ phép nhân cho mỗi phần tử, tức $n^3$ phép nhân tất cả. Với $n = 2$ là 8 phép nhân. Năm 1969, Volker Strassen tìm ra cách chỉ dùng 7 phép nhân (đổi lại bằng thêm phép cộng). Bớt một phép nhân trong tám nghe có vẻ nhỏ, nhưng vì các “số” trong công thức có thể là cả một khối ma trận, khoản tiết kiệm nhân lên ở mỗi tầng đệ quy. Với $n = 4096$, cách thường cần khoảng $6.9 \times 10^{10}$ phép nhân, Strassen đệ quy hết cỡ chỉ cần khoảng $1.4 \times 10^{10}$.&lt;/p&gt;

&lt;h2 id=&quot;bảy-phép-nhân&quot;&gt;Bảy phép nhân&lt;/h2&gt;

&lt;p&gt;Cho $A = \begin{bmatrix} a_{11} &amp;amp; a_{12} \\ a_{21} &amp;amp; a_{22} \end{bmatrix}$, $B = \begin{bmatrix} b_{11} &amp;amp; b_{12} \\ b_{21} &amp;amp; b_{22} \end{bmatrix}$. Đặt&lt;/p&gt;

\[\begin{aligned}
M_1 &amp;amp;= (a_{11} + a_{22})(b_{11} + b_{22}), &amp;amp; M_2 &amp;amp;= (a_{21} + a_{22})\, b_{11},\\
M_3 &amp;amp;= a_{11}(b_{12} - b_{22}), &amp;amp; M_4 &amp;amp;= a_{22}(b_{21} - b_{11}),\\
M_5 &amp;amp;= (a_{11} + a_{12})\, b_{22}, &amp;amp; M_6 &amp;amp;= (a_{21} - a_{11})(b_{11} + b_{12}),\\
M_7 &amp;amp;= (a_{12} - a_{22})(b_{21} + b_{22}).
\end{aligned}\]

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Strassen).&lt;/strong&gt; Với các $M_i$ như trên, $C = AB$ có&lt;/p&gt;

\[c_{11} = M_1 + M_4 - M_5 + M_7, \quad c_{12} = M_3 + M_5, \quad c_{21} = M_2 + M_4, \quad c_{22} = M_1 - M_2 + M_3 + M_6 .\]

  &lt;p&gt;Công thức chỉ dùng phép cộng, trừ và phép nhân, không dùng tính giao hoán của phép nhân, nên đúng cả khi các $a_{ij}, b_{ij}$ là các khối ma trận.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Khai triển, giữ thứ tự “phần tử của $A$ đứng trước phần tử của $B$” trong mọi tích. Ví dụ với $c_{12}$: $M_3 + M_5 = a_{11}b_{12} - a_{11}b_{22} + a_{11}b_{22} + a_{12}b_{22} = a_{11}b_{12} + a_{12}b_{22}$, đúng bằng phần tử $(1, 2)$ của $AB$. Với $c_{11}$:&lt;/p&gt;

\[M_1 + M_4 - M_5 + M_7 = (a_{11}b_{11} + a_{11}b_{22} + a_{22}b_{11} + a_{22}b_{22}) + (a_{22}b_{21} - a_{22}b_{11}) - (a_{11}b_{22} + a_{12}b_{22}) + (a_{12}b_{21} + a_{12}b_{22} - a_{22}b_{21} - a_{22}b_{22}),\]

  &lt;p&gt;rút gọn còn $a_{11}b_{11} + a_{12}b_{21}$. Hai phần tử còn lại làm tương tự. Trong mọi bước ta không đổi chỗ hai thừa số của một tích, nên lập luận vẫn đúng khi các phần tử là ma trận.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; $A = \begin{bmatrix} 1 &amp;amp; 2 \\ 3 &amp;amp; 4 \end{bmatrix}$, $B = \begin{bmatrix} 5 &amp;amp; 6 \\ 7 &amp;amp; 8 \end{bmatrix}$:&lt;/p&gt;

\[M_1 = 5 \cdot 13 = 65,\ M_2 = 7 \cdot 5 = 35,\ M_3 = 1 \cdot (-2) = -2,\ M_4 = 4 \cdot 2 = 8,\ M_5 = 3 \cdot 8 = 24,\ M_6 = 2 \cdot 11 = 22,\ M_7 = (-2) \cdot 15 = -30.\]

  &lt;p&gt;Khi đó $c_{11} = 65 + 8 - 24 - 30 = 19$, $c_{12} = -2 + 24 = 22$, $c_{21} = 35 + 8 = 43$, $c_{22} = 65 - 35 - 2 + 22 = 50$. Khớp với $AB$ ở Bài 3.2.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;đệ-quy-theo-khối&quot;&gt;Đệ quy theo khối&lt;/h2&gt;

&lt;p&gt;Với $n = 2^k$, chia $A, B$ thành bốn khối $n/2 \times n/2$ (Bài 3.5) và áp dụng Định lý 1: cần 7 tích khối cỡ $n/2$ và 18 phép cộng/trừ khối. Mỗi tích khối lại được tính bằng chính cách này.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2.&lt;/strong&gt; Thuật toán Strassen đệ quy tới cỡ $1 \times 1$ dùng đúng $7^k = n^{\log_2 7}$ phép nhân số để nhân hai ma trận $n \times n$ với $n = 2^k$. Tổng số phép tính (kể cả phép cộng) là $O(n^{\log_2 7})$, với $\log_2 7 \approx 2.807$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Gọi $T(n)$ là số phép nhân. Ta có $T(1) = 1$ và $T(n) = 7\,T(n/2)$, nên $T(2^k) = 7^k$. Vì $7^k = (2^k)^{\log_2 7} = n^{\log_2 7}$, ta có kết quả về phép nhân. Phép cộng: gọi $S(n)$ là tổng số phép tính, $S(n) = 7 S(n/2) + 18 (n/2)^2$. Mở rộng ra,&lt;/p&gt;

\[S(n) = 7^k S(1) + \tfrac{18}{4} n^2 \left(1 + \tfrac74 + \left(\tfrac74\right)^2 + \cdots + \left(\tfrac74\right)^{k-1}\right).\]

  &lt;p&gt;Tổng cấp số nhân bằng $\tfrac{(7/4)^k - 1}{3/4} &amp;lt; \tfrac43 (7/4)^k$, và $n^2 (7/4)^k = 4^k (7/4)^k = 7^k$. Vậy $S(n) \le 7^k + 6 \cdot 7^k = 7 \cdot 7^k = O(n^{\log_2 7})$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Nếu $n$ không là lũy thừa của 2, ta thêm hàng, cột số 0 cho đủ; cỡ tăng không quá gấp đôi nên độ phức tạp không đổi.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (đếm cụ thể).&lt;/strong&gt; Với $n = 4$: cách thường $4^3 = 64$ phép nhân; Strassen $7^2 = 49$. Với $n = 1024 = 2^{10}$: $2^{30} \approx 1.07 \times 10^9$ so với $7^{10} \approx 2.8 \times 10^8$, ít hơn khoảng 3.8 lần.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;thực-tế-và-ứng-dụng&quot;&gt;Thực tế và ứng dụng&lt;/h2&gt;

&lt;p&gt;Trong thực tế, thư viện chỉ đệ quy Strassen tới một cỡ nào đó (thường vài trăm), rồi dùng cách thường đã tối ưu cho bộ nhớ đệm, vì ở cỡ nhỏ chi phí 18 phép cộng khối và việc cấp phát bộ nhớ lớn hơn khoản tiết kiệm phép nhân. Strassen cũng kém ổn định số hơn một chút do các phép trừ.&lt;/p&gt;

&lt;p&gt;Câu hỏi “cần bao nhiêu phép nhân” vẫn là bài toán mở. Số mũ tốt nhất hiện biết là khoảng $2.37$, nhưng các thuật toán đó chỉ có lợi với ma trận lớn tới mức không dùng được. Năm 2022, hệ thống AlphaTensor của DeepMind tìm bằng học tăng cường một cách nhân hai ma trận $4 \times 4$ với 47 phép nhân trong số học modulo 2, ít hơn 49 của Strassen hai tầng. Nhân ma trận nhanh quan trọng vì nó là lõi của học sâu: huấn luyện một mô hình ngôn ngữ lớn phần lớn là nhân các ma trận khổng lồ. Thuật toán Cannon (nhân ma trận trên lưới bộ xử lý song song) giải quyết câu hỏi cùng loại cho máy tính song song.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: thuật toán Strassen&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Bảy phép nhân khối thay cho tám, và so sánh số phép tính theo n.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/strassen.html&quot; title=&quot;Minh hoạ: thuật toán Strassen&quot; loading=&quot;lazy&quot; style=&quot;height: 760px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/strassen.html&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: thuật toán Cannon nhân ma trận song song&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Các khối của A dịch trái, khối của B dịch lên trên lưới bộ xử lý.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/cannon.html&quot; title=&quot;Minh hoạ: thuật toán Cannon nhân ma trận song song&quot; loading=&quot;lazy&quot; style=&quot;height: 760px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/cannon.html&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Dùng công thức Strassen tính $\begin{bmatrix} 1 &amp;amp; 0 \\ 2 &amp;amp; 1 \end{bmatrix}\begin{bmatrix} 3 &amp;amp; 1 \\ 0 &amp;amp; 2 \end{bmatrix}$ và so với cách thường.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$M_1 = 2 \cdot 5 = 10$, $M_2 = 3 \cdot 3 = 9$, $M_3 = 1 \cdot (-1) = -1$, $M_4 = 1 \cdot (-3) = -3$, $M_5 = 1 \cdot 2 = 2$, $M_6 = 1 \cdot 4 = 4$, $M_7 = (-1) \cdot 2 = -2$. Khi đó $C = \begin{bmatrix} 3 &amp;amp; 1 \\ 6 &amp;amp; 4 \end{bmatrix}$, khớp với cách thường.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Kiểm tra công thức $c_{21} = M_2 + M_4$ bằng khai triển.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$M_2 + M_4 = a_{21}b_{11} + a_{22}b_{11} + a_{22}b_{21} - a_{22}b_{11} = a_{21}b_{11} + a_{22}b_{21}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Với $n = 2^k$, tìm $k$ nhỏ nhất để Strassen đệ quy hết cỡ dùng ít hơn một nửa số phép nhân của cách thường.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Cần $(7/8)^k &amp;lt; 1/2$, tức $k &amp;gt; \ln 2 / \ln(8/7) \approx 5.19$. Vậy $k = 6$, $n = 64$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Một biến thể (Winograd) dùng 7 phép nhân và 15 phép cộng khối thay vì 18. Viết lại hệ thức truy hồi và cho biết số mũ có đổi không.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$S(n) = 7S(n/2) + 15(n/2)^2$. Số mũ vẫn là $\log_2 7$; chỉ hằng số đứng trước thay đổi.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao / lập trình).&lt;/strong&gt; Cài đặt Strassen đệ quy trong NumPy, dừng đệ quy ở cỡ $m$ và dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@&lt;/code&gt; cho khối nhỏ. Đo thời gian với $n = 1024$ cho $m = 32, 64, 128, 256$ và so với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A @ B&lt;/code&gt;.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Kết quả phụ thuộc máy, nhưng thường cài đặt Python chậm hơn `A @ B` thuần với mọi $m$, vì BLAS đã rất tối ưu và việc tạo các khối tạm tốn thời gian. Sai số làm tròn của Strassen thường lớn hơn một chút so với `A @ B`, do có thêm các phép trừ.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Nhân theo định nghĩa: $n^3$ phép nhân.&lt;/li&gt;
    &lt;li&gt;Strassen: 7 phép nhân cho tích $2 \times 2$, công thức không dùng tính giao hoán nên áp dụng được cho khối.&lt;/li&gt;
    &lt;li&gt;Đệ quy theo khối cho $n^{\log_2 7} \approx n^{2.81}$ phép nhân và cùng bậc cho tổng số phép tính.&lt;/li&gt;
    &lt;li&gt;Thực tế chỉ có lợi với ma trận lớn; thư viện kết hợp Strassen với cách thường.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Chuyển vị, ma trận đối xứng và ma trận khối</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter03/03_05_Chuyen_Vi_Doi_Xung_Va_Ma_Tran_Khoi/"/>
   <updated>2026-01-03T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter03/03_05_Chuyen_Vi_Doi_Xung_Va_Ma_Tran_Khoi</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;dùng các tính chất của chuyển vị, đặc biệt $(AB)^T = B^T A^T$;&lt;/li&gt;
    &lt;li&gt;nhận biết ma trận đối xứng và chứng minh $A^T A$, $AA^T$ luôn đối xứng;&lt;/li&gt;
    &lt;li&gt;chia ma trận thành khối và nhân theo khối như nhân ma trận số;&lt;/li&gt;
    &lt;li&gt;dùng $A^T A$ để tính tất cả các tích vô hướng giữa các cột dữ liệu.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Bốn sinh viên được đo hai đặc trưng (đã chuẩn hoá): số giờ tự học và số bài tập đã nộp. Ghi thành ma trận dữ liệu $X$ cỡ $4 \times 2$, mỗi cột là một đặc trưng:&lt;/p&gt;

\[X = \begin{bmatrix} 1 &amp;amp; 2 \\ 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \\ 2 &amp;amp; 1 \end{bmatrix}.\]

&lt;p&gt;Muốn biết hai đặc trưng “đi cùng nhau” đến mức nào, ta tính tích vô hướng của hai cột: $1\cdot2 + 0\cdot1 + 1\cdot0 + 2\cdot1 = 4$. Cùng với độ dài bình phương của mỗi cột ($6$ và $6$), cả ba số nằm gọn trong một tích:&lt;/p&gt;

\[X^T X = \begin{bmatrix} 6 &amp;amp; 4 \\ 4 &amp;amp; 6 \end{bmatrix}.\]

&lt;p&gt;Ma trận này đối xứng qua đường chéo. Bài này giải thích vì sao, và vì sao $X^T X$ xuất hiện khắp nơi trong thống kê và học máy.&lt;/p&gt;

&lt;h2 id=&quot;các-tính-chất-của-chuyển-vị&quot;&gt;Các tính chất của chuyển vị&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Với các ma trận có cỡ phù hợp và số $c$:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$(A^T)^T = A$;&lt;/li&gt;
    &lt;li&gt;$(A + B)^T = A^T + B^T$ và $(cA)^T = c A^T$;&lt;/li&gt;
    &lt;li&gt;$(AB)^T = B^T A^T$.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; (1) và (2) suy ra trực tiếp từ định nghĩa $(A^T)_{ij} = a_{ji}$. Với (3), cho $A$ cỡ $m \times n$, $B$ cỡ $n \times p$. Phần tử $(i, j)$ của $(AB)^T$ là phần tử $(j, i)$ của $AB$, tức $\sum_k a_{jk} b_{ki}$. Phần tử $(i, j)$ của $B^T A^T$ là $\sum_k (B^T)_{ik} (A^T)_{kj} = \sum_k b_{ki} a_{jk}$. Hai tổng bằng nhau.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Chú ý thứ tự đảo ngược, giống như $(AB)^{-1} = B^{-1}A^{-1}$. Với ba ma trận, $(ABC)^T = C^T B^T A^T$.&lt;/p&gt;

&lt;p&gt;Tích vô hướng và chuyển vị liên hệ qua một đẳng thức hay dùng: với $x \in \mathbb{R}^n$, $y \in \mathbb{R}^m$ và $A$ cỡ $m \times n$,&lt;/p&gt;

\[(Ax) \cdot y = (Ax)^T y = x^T A^T y = x \cdot (A^T y).\]

&lt;p&gt;Đẳng thức này là cách định nghĩa chuyển vị “không cần toạ độ”, và sẽ dùng nhiều ở Chương 07 và 10.&lt;/p&gt;

&lt;h2 id=&quot;ma-trận-đối-xứng&quot;&gt;Ma trận đối xứng&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Ma trận đối xứng, phản đối xứng).&lt;/strong&gt; Ma trận vuông $A$ gọi là &lt;em&gt;đối xứng&lt;/em&gt; nếu $A^T = A$, tức $a_{ij} = a_{ji}$ với mọi $i, j$. $A$ gọi là &lt;em&gt;phản đối xứng&lt;/em&gt; nếu $A^T = -A$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Ma trận đối xứng giống như ảnh soi gương qua đường chéo chính. Ví dụ ma trận khoảng cách giữa các thành phố (khoảng cách từ $i$ tới $j$ bằng từ $j$ tới $i$), ma trận kề của đồ thị vô hướng, ma trận hiệp phương sai.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2.&lt;/strong&gt; Với mọi ma trận $A$ cỡ $m \times n$, các ma trận $A^T A$ (cấp $n$) và $A A^T$ (cấp $m$) đều đối xứng. Hơn nữa phần tử $(i, j)$ của $A^T A$ là tích vô hướng của cột $i$ với cột $j$ của $A$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; $(A^T A)^T = A^T (A^T)^T = A^T A$ theo Định lý 1. Tương tự cho $AA^T$. Phần tử $(i, j)$ của $A^T A$ là hàng $i$ của $A^T$ (tức cột $i$ của $A$) nhân vô hướng với cột $j$ của $A$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Mệnh đề 1.&lt;/strong&gt; Mọi ma trận vuông $A$ viết được duy nhất thành tổng một ma trận đối xứng và một ma trận phản đối xứng:&lt;/p&gt;

  &lt;p&gt;\(A = \underbrace{\tfrac12 (A + A^T)}_{\text{đối xứng}} + \underbrace{\tfrac12 (A - A^T)}_{\text{phản đối xứng}} .\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Kiểm tra trực tiếp bằng Định lý 1 rằng hai số hạng có tính chất như ghi. Nếu $A = S + K = S&apos; + K&apos;$ với $S, S&apos;$ đối xứng và $K, K&apos;$ phản đối xứng, thì $S - S&apos; = K&apos; - K$ vừa đối xứng vừa phản đối xứng, nên bằng chính đối của nó, tức bằng $0$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; $A = \begin{bmatrix} 1 &amp;amp; 4 \\ 2 &amp;amp; 3 \end{bmatrix}$ có phần đối xứng $\begin{bmatrix} 1 &amp;amp; 3 \\ 3 &amp;amp; 3 \end{bmatrix}$ và phần phản đối xứng $\begin{bmatrix} 0 &amp;amp; 1 \\ -1 &amp;amp; 0 \end{bmatrix}$. Phần phản đối xứng là phép quay $90^\circ$ theo chiều kim đồng hồ; nó không đóng góp gì vào $x^T A x$, vì $x^T K x$ là một số bằng chuyển vị của chính nó $x^T K^T x = -x^T K x$, nên bằng 0. Điều này quan trọng cho dạng toàn phương ở Chương 10.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ma-trận-khối&quot;&gt;Ma trận khối&lt;/h2&gt;

&lt;p&gt;Một ma trận lớn có thể chia thành các &lt;em&gt;khối&lt;/em&gt; bằng các đường kẻ ngang và dọc. Nếu cách chia cột của $A$ khớp với cách chia hàng của $B$, thì nhân $AB$ theo khối giống hệt nhân ma trận số, chỉ cần giữ thứ tự trong mỗi tích khối:&lt;/p&gt;

\[\begin{bmatrix} A_{11} &amp;amp; A_{12} \\ A_{21} &amp;amp; A_{22} \end{bmatrix}
\begin{bmatrix} B_{11} &amp;amp; B_{12} \\ B_{21} &amp;amp; B_{22} \end{bmatrix}
= \begin{bmatrix} A_{11}B_{11} + A_{12}B_{21} &amp;amp; A_{11}B_{12} + A_{12}B_{22} \\ A_{21}B_{11} + A_{22}B_{21} &amp;amp; A_{21}B_{12} + A_{22}B_{22} \end{bmatrix}.\]

&lt;p&gt;Lý do: phần tử $(i, j)$ của $AB$ là $\sum_k a_{ik} b_{kj}$; tách tổng theo $k$ thành các đoạn ứng với khối cột của $A$, mỗi đoạn là một phần tử của một tích khối.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; Cho $A = \begin{bmatrix} A_{11} &amp;amp; I \\ 0 &amp;amp; 2I \end{bmatrix}$ và $B = \begin{bmatrix} I &amp;amp; 0 \\ C &amp;amp; I \end{bmatrix}$ với các khối $2 \times 2$, $A_{11} = \begin{bmatrix} 1 &amp;amp; 2 \\ 3 &amp;amp; 4 \end{bmatrix}$, $C = \begin{bmatrix} 1 &amp;amp; 1 \\ 2 &amp;amp; 0 \end{bmatrix}$. Nhân theo khối:&lt;/p&gt;

\[AB = \begin{bmatrix} A_{11} + C &amp;amp; I \\ 2C &amp;amp; 2I \end{bmatrix} = \begin{bmatrix} 2 &amp;amp; 3 &amp;amp; 1 &amp;amp; 0 \\ 5 &amp;amp; 4 &amp;amp; 0 &amp;amp; 1 \\ 2 &amp;amp; 2 &amp;amp; 2 &amp;amp; 0 \\ 4 &amp;amp; 0 &amp;amp; 0 &amp;amp; 2 \end{bmatrix}.\]

  &lt;p&gt;Ta chỉ cần cộng hai ma trận $2 \times 2$ và nhân $C$ với 2, thay vì 64 phép nhân số.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3 (nghịch đảo khối chéo).&lt;/strong&gt; Nếu $M = \begin{bmatrix} A &amp;amp; 0 \\ 0 &amp;amp; D \end{bmatrix}$ với $A, D$ vuông khả nghịch thì $M^{-1} = \begin{bmatrix} A^{-1} &amp;amp; 0 \\ 0 &amp;amp; D^{-1} \end{bmatrix}$: nhân theo khối được $I$. Ví dụ $\begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}^{-1} = \begin{bmatrix} 1 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{bmatrix}$ và $\begin{bmatrix} 3 &amp;amp; 0 \\ 1 &amp;amp; 1 \end{bmatrix}^{-1} = \begin{bmatrix} 1/3 &amp;amp; 0 \\ -1/3 &amp;amp; 1 \end{bmatrix}$ cho ngay nghịch đảo của ma trận $4 \times 4$ ghép chéo từ hai khối này.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-ma-trận-gram-và-hiệp-phương-sai&quot;&gt;Ứng dụng: ma trận Gram và hiệp phương sai&lt;/h2&gt;

&lt;p&gt;Trong học máy, ma trận dữ liệu $X$ có $m$ hàng (mẫu) và $n$ cột (đặc trưng). Ma trận $X^T X$ cỡ $n \times n$ gọi là &lt;em&gt;ma trận Gram&lt;/em&gt; của các cột. Nếu mỗi cột đã trừ đi trung bình của nó, thì $\tfrac{1}{m-1} X^T X$ là &lt;em&gt;ma trận hiệp phương sai&lt;/em&gt;: phần tử chéo là phương sai của mỗi đặc trưng, phần tử ngoài chéo là hiệp phương sai giữa hai đặc trưng. Nó đối xứng theo Định lý 2. Hồi quy tuyến tính (Chương 08) giải hệ $X^T X\, \beta = X^T y$, và PCA (Chương 11) tìm các hướng riêng của ma trận hiệp phương sai.&lt;/p&gt;

&lt;p&gt;Ma trận khối cũng là cách các thư viện nhân ma trận lớn: chia thành khối vừa bộ nhớ đệm của CPU, hoặc chia cho nhiều máy tính, mỗi máy nhân một số tích khối.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: chuyển vị và ma trận đối xứng&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Bấm một ô của A để xem nó đi đâu trong Aᵀ; thẻ A + Aᵀ cho một ma trận đối xứng.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/phep_toan_ma_tran.html?mode=T&quot; title=&quot;Minh hoạ: chuyển vị và ma trận đối xứng&quot; loading=&quot;lazy&quot; style=&quot;height: 560px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/phep_toan_ma_tran.html?mode=T&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Với $A = \begin{bmatrix} 1 &amp;amp; 2 \\ 0 &amp;amp; 1 \end{bmatrix}$, $B = \begin{bmatrix} 3 &amp;amp; 0 \\ 1 &amp;amp; 1 \end{bmatrix}$, kiểm tra $(AB)^T = B^T A^T$ và $(AB)^T \ne A^T B^T$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$AB = \begin{bmatrix} 5 &amp;amp; 2 \\ 1 &amp;amp; 1 \end{bmatrix}$, $(AB)^T = \begin{bmatrix} 5 &amp;amp; 1 \\ 2 &amp;amp; 1 \end{bmatrix} = B^T A^T$. Còn $A^T B^T = \begin{bmatrix} 3 &amp;amp; 1 \\ 6 &amp;amp; 3 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Tìm $a, b, c$ để $\begin{bmatrix} 1 &amp;amp; a &amp;amp; 3 \\ 2 &amp;amp; 4 &amp;amp; b \\ c &amp;amp; 5 &amp;amp; 6 \end{bmatrix}$ đối xứng.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$a = 2$, $b = 5$, $c = 3$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Chứng minh: nếu $A, B$ đối xứng cùng cấp thì $AB$ đối xứng khi và chỉ khi $AB = BA$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$(AB)^T = B^T A^T = BA$. Vậy $(AB)^T = AB$ khi và chỉ khi $BA = AB$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Tính $XX^T$ với $X$ ở ví dụ mở đầu. Phần tử $(i, j)$ của nó có nghĩa gì?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$XX^T = \begin{bmatrix} 5 &amp;amp; 2 &amp;amp; 1 &amp;amp; 4 \\ 2 &amp;amp; 1 &amp;amp; 0 &amp;amp; 1 \\ 1 &amp;amp; 0 &amp;amp; 1 &amp;amp; 2 \\ 4 &amp;amp; 1 &amp;amp; 2 &amp;amp; 5 \end{bmatrix}$. Phần tử $(i, j)$ là tích vô hướng của sinh viên $i$ và sinh viên $j$ (hai hàng), đo mức giống nhau giữa hai sinh viên.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Cho $M = \begin{bmatrix} A &amp;amp; B \\ 0 &amp;amp; D \end{bmatrix}$ với $A, D$ vuông khả nghịch. Tìm $M^{-1}$ dạng khối.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$M^{-1} = \begin{bmatrix} A^{-1} &amp;amp; -A^{-1} B D^{-1} \\ 0 &amp;amp; D^{-1} \end{bmatrix}$. Kiểm tra bằng nhân khối: khối $(1, 2)$ của $MM^{-1}$ là $-AA^{-1}BD^{-1} + BD^{-1} = 0$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$(AB)^T = B^T A^T$; $(Ax)\cdot y = x \cdot (A^T y)$.&lt;/li&gt;
    &lt;li&gt;Ma trận đối xứng: $A^T = A$. $A^TA$ và $AA^T$ luôn đối xứng; $A^TA$ chứa mọi tích vô hướng giữa các cột của $A$.&lt;/li&gt;
    &lt;li&gt;Mọi ma trận vuông = phần đối xứng + phần phản đối xứng.&lt;/li&gt;
    &lt;li&gt;Nhân theo khối như nhân số, giữ thứ tự trong mỗi tích khối.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Ma trận sơ cấp và phân rã LU</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter03/03_04_Ma_Tran_So_Cap_Va_Phan_Ra_LU/"/>
   <updated>2026-01-03T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter03/03_04_Ma_Tran_So_Cap_Va_Phan_Ra_LU</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;viết ma trận sơ cấp ứng với một phép biến đổi sơ cấp trên hàng, và nghịch đảo của nó;&lt;/li&gt;
    &lt;li&gt;phân rã $A = LU$ bằng cách ghi lại các hệ số nhân của khử Gauss;&lt;/li&gt;
    &lt;li&gt;giải $Ax = b$ bằng hai lần thế: $Ly = b$ rồi $Ux = y$;&lt;/li&gt;
    &lt;li&gt;dùng $PA = LU$ khi khử cần đổi hàng.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Một kỹ sư kết cấu phải tính độ võng của cùng một khung thép dưới 50 trường hợp tải trọng khác nhau. Mỗi trường hợp là một hệ $Ax = b_k$ với cùng ma trận $A$ (độ cứng của khung) và vế phải $b_k$ khác nhau. Khử Gauss 50 lần là lãng phí: phần tốn kém ($\approx n^3/3$ phép nhân) chỉ phụ thuộc $A$. Ta muốn khử $A$ một lần, &lt;em&gt;ghi lại&lt;/em&gt; các bước, rồi áp dụng các bước đó cho từng $b_k$ với chi phí chỉ khoảng $n^2$. Bản ghi đó chính là phân rã $A = LU$.&lt;/p&gt;

&lt;h2 id=&quot;ma-trận-sơ-cấp&quot;&gt;Ma trận sơ cấp&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Ma trận sơ cấp).&lt;/strong&gt; &lt;em&gt;Ma trận sơ cấp&lt;/em&gt; là ma trận nhận được từ $I_n$ bằng đúng một phép biến đổi sơ cấp trên hàng.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Ví dụ với $n = 3$:&lt;/p&gt;

\[E_{21}(-2) = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 \\ -2 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix} \ (R_2 \to R_2 - 2R_1), \qquad
P_{23} = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; 0 \end{bmatrix} \ (R_2 \leftrightarrow R_3).\]

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Nếu $E$ nhận được từ $I$ bằng một phép biến đổi sơ cấp, thì với mọi ma trận $A$ có $n$ hàng, $EA$ là ma trận nhận được từ $A$ bằng đúng phép biến đổi đó. Mọi ma trận sơ cấp đều khả nghịch, và nghịch đảo của nó là ma trận sơ cấp của phép ngược.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Theo cách nhìn hàng (Bài 3.2), hàng $i$ của $EA$ là tổ hợp các hàng của $A$ với hệ số lấy từ hàng $i$ của $E$. Với $E = E_{ij}(c)$, hàng $i$ của $E$ là $e_i^T + c\, e_j^T$, nên hàng $i$ của $EA$ là (hàng $i$) $+ c$ (hàng $j$) của $A$; các hàng khác của $E$ là hàng của $I$ nên giữ nguyên các hàng khác của $A$. Hai loại còn lại kiểm tra giống vậy. Gọi $E&apos;$ là ma trận của phép ngược (Bổ đề 1, Bài 2.2); áp dụng phép rồi phép ngược cho $I$ được $I$, tức $E&apos;E = I$, và tương tự $EE&apos; = I$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Ví dụ, $E_{21}(-2)^{-1} = E_{21}(2)$: trừ hai lần hàng 1 thì muốn hoàn tác phải cộng lại hai lần hàng 1.&lt;/p&gt;

&lt;h2 id=&quot;phân-rã-lu&quot;&gt;Phân rã LU&lt;/h2&gt;

&lt;p&gt;Khi khử Gauss &lt;em&gt;không cần đổi hàng&lt;/em&gt;, ta chỉ dùng các phép $R_i \to R_i - \ell_{ij} R_j$ với $i &amp;gt; j$. Mỗi phép là nhân trái với $E_{ij}(-\ell_{ij})$, một ma trận tam giác dưới. Kết quả là&lt;/p&gt;

\[E_k \cdots E_2 E_1 A = U ,\]

&lt;p&gt;với $U$ là ma trận &lt;em&gt;tam giác trên&lt;/em&gt; (dạng bậc thang). Do đó $A = (E_1^{-1} E_2^{-1} \cdots E_k^{-1})\, U = LU$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2 (Phân rã LU).&lt;/strong&gt; Nếu khử Gauss trên $A$ vuông cấp $n$ không cần đổi hàng, thì $A = LU$, trong đó $U$ là ma trận tam giác trên nhận được sau khử, và $L$ là ma trận tam giác dưới có đường chéo bằng 1 và phần tử $(i, j)$ với $i &amp;gt; j$ bằng đúng hệ số nhân $\ell_{ij}$ đã dùng.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh (ý chính).&lt;/strong&gt; Ta vừa thấy $L = E_1^{-1} \cdots E_k^{-1}$, mỗi $E^{-1} = E_{ij}(+\ell_{ij})$. Các phép khử làm theo thứ tự cột $1, 2, \dots$; nhân các ma trận $E_{ij}(\ell_{ij})$ theo đúng thứ tự này thì mỗi hệ số $\ell_{ij}$ được đặt vào vị trí $(i, j)$ mà không bị trộn với nhau: khi nhân $E_{ij}(\ell)$ ở bên phải, nó chỉ cộng $\ell$ lần cột $i$ vào cột $j$, và cột $i$ của tích đang có lúc đó vẫn là $e_i$ (các cột $i &amp;gt; j$ chưa bị đụng tới). Kiểm tra trên ví dụ dưới đây.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; $A = \begin{bmatrix} 2 &amp;amp; 1 &amp;amp; 1 \\ 4 &amp;amp; -6 &amp;amp; 0 \\ -2 &amp;amp; 7 &amp;amp; 2 \end{bmatrix}$.&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$\ell_{21} = 4/2 = 2$: $R_2 \to R_2 - 2R_1$ cho $(0, -8, -2)$.&lt;/li&gt;
    &lt;li&gt;$\ell_{31} = -2/2 = -1$: $R_3 \to R_3 + R_1$ cho $(0, 8, 3)$.&lt;/li&gt;
    &lt;li&gt;$\ell_{32} = 8/(-8) = -1$: $R_3 \to R_3 + R_2$ cho $(0, 0, 1)$.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Vậy&lt;/p&gt;

\[L = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 \\ 2 &amp;amp; 1 &amp;amp; 0 \\ -1 &amp;amp; -1 &amp;amp; 1 \end{bmatrix}, \qquad U = \begin{bmatrix} 2 &amp;amp; 1 &amp;amp; 1 \\ 0 &amp;amp; -8 &amp;amp; -2 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}.\]

  &lt;p&gt;Nhân lại $LU$ được đúng $A$: ví dụ hàng 3 của $LU$ là $-1 \cdot (2, 1, 1) - 1 \cdot (0, -8, -2) + (0, 0, 1) = (-2, 7, 2)$.&lt;/p&gt;
&lt;/div&gt;

&lt;h3 id=&quot;giải-hệ-bằng-lu&quot;&gt;Giải hệ bằng LU&lt;/h3&gt;

&lt;p&gt;$Ax = b$ thành $L(Ux) = b$. Đặt $y = Ux$:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Giải $Ly = b$ bằng &lt;em&gt;thế xuôi&lt;/em&gt; (từ trên xuống), vì $L$ tam giác dưới.&lt;/li&gt;
  &lt;li&gt;Giải $Ux = y$ bằng &lt;em&gt;thế ngược&lt;/em&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Mỗi bước tốn khoảng $n^2/2$ phép nhân.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; Với $A$ ở Ví dụ 1 và $b = (5, -2, 9)$. Thế xuôi: $y_1 = 5$; $2y_1 + y_2 = -2$ nên $y_2 = -12$; $-y_1 - y_2 + y_3 = 9$ nên $y_3 = 2$. Thế ngược với $U$: $x_3 = 2$; $-8x_2 - 2x_3 = -12$ nên $x_2 = 1$; $2x_1 + x_2 + x_3 = 5$ nên $x_1 = 1$. Nghiệm $x = (1, 1, 2)$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;khi-cần-đổi-hàng-pa--lu&quot;&gt;Khi cần đổi hàng: $PA = LU$&lt;/h2&gt;

&lt;p&gt;Nếu có lúc phần tử ở vị trí chốt bằng 0 (hoặc ta chọn chốt từng phần như Bài 2.6), ta phải đổi hàng. Gom tất cả các phép đổi hàng vào một &lt;em&gt;ma trận hoán vị&lt;/em&gt; $P$ (một hoán vị các hàng của $I$) và làm chúng trước.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 3.&lt;/strong&gt; Với mọi ma trận vuông khả nghịch $A$, có ma trận hoán vị $P$ sao cho $PA = LU$, với $L$ tam giác dưới có đường chéo 1 và $U$ tam giác trên có đường chéo khác 0.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Ta công nhận định lý này; phần chứng minh là kiểm tra rằng có thể dời mọi phép đổi hàng lên đầu nếu đổi chỗ tương ứng các hệ số nhân đã ghi trong $L$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3.&lt;/strong&gt; $A = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 1 \\ 2 &amp;amp; 4 &amp;amp; 3 \\ 1 &amp;amp; 3 &amp;amp; 2 \end{bmatrix}$. Khử cột 1: hàng 2 thành $(0, 0, 1)$, hàng 3 thành $(0, 1, 1)$. Vị trí chốt $(2, 2)$ bằng 0, phải đổi hàng 2 và 3. Làm việc đổi đó trước với $P = P_{23}$:&lt;/p&gt;

  &lt;p&gt;\(PA = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 1 \\ 1 &amp;amp; 3 &amp;amp; 2 \\ 2 &amp;amp; 4 &amp;amp; 3 \end{bmatrix} = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 \\ 1 &amp;amp; 1 &amp;amp; 0 \\ 2 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-nhiều-vế-phải&quot;&gt;Ứng dụng: nhiều vế phải&lt;/h2&gt;

&lt;p&gt;Quay lại ví dụ mở đầu với $n = 1000$ và 50 trường hợp tải. Khử Gauss riêng cho từng trường hợp: $50 \times 3.3 \times 10^8 \approx 1.7 \times 10^{10}$ phép nhân. Phân rã LU một lần ($3.3 \times 10^8$) rồi 50 lần thế xuôi, thế ngược ($50 \times 10^6$): tổng khoảng $3.8 \times 10^8$, nhanh hơn khoảng 40 lần. Trong SciPy: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lu, piv = scipy.linalg.lu_factor(A)&lt;/code&gt; một lần, rồi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scipy.linalg.lu_solve((lu, piv), b)&lt;/code&gt; cho mỗi $b$. Cũng vì lý do này mà thư viện số không tính $A^{-1}$ để giải hệ: LU rẻ hơn và chính xác hơn.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: phân rã LU từng bước&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Mỗi bước khử ghi hệ số vào L; cuối cùng kiểm tra L·U = A.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/phan_ra_lu.html&quot; title=&quot;Minh hoạ: phân rã LU từng bước&quot; loading=&quot;lazy&quot; style=&quot;height: 560px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/phan_ra_lu.html&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Viết ma trận sơ cấp $3 \times 3$ cho phép $R_3 \to R_3 + 5R_1$ và nghịch đảo của nó.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$E = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 0 \\ 5 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$, $E^{-1} = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 0 \\ -5 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Tìm phân rã LU của $\begin{bmatrix} 1 &amp;amp; 2 \\ 3 &amp;amp; 8 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\ell_{21} = 3$: $L = \begin{bmatrix} 1 &amp;amp; 0 \\ 3 &amp;amp; 1 \end{bmatrix}$, $U = \begin{bmatrix} 1 &amp;amp; 2 \\ 0 &amp;amp; 2 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Tìm phân rã LU của $\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 \\ 2 &amp;amp; 5 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; 3 \end{bmatrix}$, rồi dùng nó giải $Ax = (3, 8, 4)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$L = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 \\ 2 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 1 \end{bmatrix}$, $U = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 2 \end{bmatrix}$. Thế xuôi: $y = (3, 2, 2)$. Thế ngược: $x_3 = 1$, $x_2 = 1$, $x_1 = 1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Dùng lại $L, U$ ở Ví dụ 1 để giải $Ax = (2, -4, 7)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$y = (2, -8, 1)$; rồi $x_3 = 1$, $-8x_2 - 2 = -8$ nên $x_2 = 3/4$, $2x_1 + 3/4 + 1 = 2$ nên $x_1 = 1/8$. Vậy $x = (1/8, 3/4, 1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Chứng minh ma trận $\begin{bmatrix} 0 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$ không có phân rã $A = LU$ với $L$ tam giác dưới, $U$ tam giác trên, nhưng có $PA = LU$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Nếu $A = LU$ thì $a_{11} = l_{11} u_{11} = 0$, nên $l_{11} = 0$ hoặc $u_{11} = 0$. Khi đó hàng 1 của $L$ hoặc cột 1 của $U$ bằng 0, kéo theo hàng 1 hoặc cột 1 của $A$ bằng 0, mâu thuẫn. Với $P = P_{12}$: $PA = \begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \end{bmatrix} = I \cdot U$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Phép biến đổi sơ cấp trên hàng = nhân trái với ma trận sơ cấp; mọi ma trận sơ cấp khả nghịch.&lt;/li&gt;
    &lt;li&gt;Khử Gauss không đổi hàng cho $A = LU$: $L$ ghi các hệ số nhân, $U$ là kết quả khử.&lt;/li&gt;
    &lt;li&gt;Giải $Ax = b$: thế xuôi $Ly = b$, thế ngược $Ux = y$, mỗi bước khoảng $n^2/2$ phép nhân.&lt;/li&gt;
    &lt;li&gt;Khi cần đổi hàng: $PA = LU$. Phân rã một lần, dùng cho nhiều vế phải.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Ma trận nghịch đảo</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter03/03_03_Ma_Tran_Nghich_Dao/"/>
   <updated>2026-01-03T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter03/03_03_Ma_Tran_Nghich_Dao</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;kiểm tra một ma trận vuông có khả nghịch hay không;&lt;/li&gt;
    &lt;li&gt;tính nghịch đảo của ma trận $2 \times 2$ bằng công thức và của ma trận $n \times n$ bằng Gauss–Jordan trên $[A \mid I]$;&lt;/li&gt;
    &lt;li&gt;dùng các tính chất $(AB)^{-1} = B^{-1}A^{-1}$ và $(A^T)^{-1} = (A^{-1})^T$;&lt;/li&gt;
    &lt;li&gt;nêu các điều kiện tương đương với “$A$ khả nghịch”.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Phương trình số $3x = 6$ giải bằng cách nhân hai vế với $3^{-1}$. Với hệ $Ax = b$, ta muốn làm tương tự: tìm một ma trận $A^{-1}$ sao cho $A^{-1}A = I$, rồi $x = A^{-1} b$.&lt;/p&gt;

&lt;p&gt;Về hình học: $A$ biến đổi mặt phẳng, $A^{-1}$ là phép “chạy phim ngược” đưa mọi điểm về chỗ cũ. Nếu $A$ ép cả mặt phẳng xuống một đường thẳng, thì nhiều điểm bị dồn vào cùng một chỗ và không có cách nào chạy ngược. Khi đó $A$ không khả nghịch.&lt;/p&gt;

&lt;h2 id=&quot;định-nghĩa-và-tính-duy-nhất&quot;&gt;Định nghĩa và tính duy nhất&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Ma trận khả nghịch).&lt;/strong&gt; Ma trận vuông $A$ cấp $n$ gọi là &lt;em&gt;khả nghịch&lt;/em&gt; nếu có ma trận $B$ cấp $n$ sao cho&lt;/p&gt;

\[AB = BA = I_n .\]

  &lt;p&gt;Khi đó $B$ gọi là &lt;em&gt;ma trận nghịch đảo&lt;/em&gt; của $A$, ký hiệu $A^{-1}$. Ma trận không khả nghịch gọi là &lt;em&gt;suy biến&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-lemma&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Bổ đề 1.&lt;/strong&gt; Nghịch đảo, nếu có, là duy nhất.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Nếu $AB = BA = I$ và $AC = CA = I$ thì $B = BI = B(AC) = (BA)C = IC = C$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Nghịch đảo $2 \times 2$).&lt;/strong&gt; Ma trận $A = \begin{bmatrix} a &amp;amp; b \\ c &amp;amp; d \end{bmatrix}$ khả nghịch khi và chỉ khi $ad - bc \ne 0$, và khi đó&lt;/p&gt;

  &lt;p&gt;\(A^{-1} = \frac{1}{ad - bc} \begin{bmatrix} d &amp;amp; -b \\ -c &amp;amp; a \end{bmatrix}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Nhân trực tiếp: $\begin{bmatrix} a &amp;amp; b \\ c &amp;amp; d \end{bmatrix}\begin{bmatrix} d &amp;amp; -b \\ -c &amp;amp; a \end{bmatrix} = (ad - bc) I$, và tương tự khi nhân theo thứ tự ngược lại. Nếu $ad - bc \ne 0$, chia cho nó được nghịch đảo. Nếu $ad - bc = 0$ thì hai cột $(a, c)$ và $(b, d)$ cùng phương (hoặc có một cột bằng 0), nên mọi $Ax$ nằm trên một đường thẳng qua gốc. Không có $B$ nào làm $AB = I$, vì cột $e_1, e_2$ của $I$ không cùng nằm trên một đường thẳng.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Số $ad - bc$ là &lt;em&gt;định thức&lt;/em&gt; của $A$. Chương 04 mở rộng nó cho ma trận cấp $n$ và giải thích nó là tỉ lệ diện tích.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 5 &amp;amp; 3 \end{bmatrix}$ có $ad - bc = 6 - 5 = 1$, nên $A^{-1} = \begin{bmatrix} 3 &amp;amp; -1 \\ -5 &amp;amp; 2 \end{bmatrix}$. Giải $Ax = (1, 2)$: $x = A^{-1}(1, 2) = (3 - 2, -5 + 4) = (1, -1)$. Kiểm tra: $2 - 1 = 1$, $5 - 3 = 2$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;tính-chất&quot;&gt;Tính chất&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2.&lt;/strong&gt; Cho $A, B$ khả nghịch cùng cấp. Khi đó&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$A^{-1}$ khả nghịch và $(A^{-1})^{-1} = A$;&lt;/li&gt;
    &lt;li&gt;$AB$ khả nghịch và $(AB)^{-1} = B^{-1} A^{-1}$;&lt;/li&gt;
    &lt;li&gt;$A^T$ khả nghịch và $(A^T)^{-1} = (A^{-1})^T$.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; (1) Đẳng thức $AA^{-1} = A^{-1}A = I$ cũng nói rằng $A$ là nghịch đảo của $A^{-1}$. (2) $(AB)(B^{-1}A^{-1}) = A(BB^{-1})A^{-1} = AA^{-1} = I$, và tương tự $(B^{-1}A^{-1})(AB) = I$. (3) Dùng $(XY)^T = Y^T X^T$ (Bài 3.5): $A^T (A^{-1})^T = (A^{-1}A)^T = I^T = I$, và tương tự theo thứ tự kia.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Thứ tự đảo ngược ở (2) có lý do hình học: mang tất rồi mang giày, thì muốn tháo phải tháo giày trước rồi mới tháo tất.&lt;/p&gt;

&lt;h2 id=&quot;tính-nghịch-đảo-bằng-gaussjordan&quot;&gt;Tính nghịch đảo bằng Gauss–Jordan&lt;/h2&gt;

&lt;p&gt;Tìm $A^{-1}$ là giải $n$ hệ $A x_j = e_j$ cùng lúc (cột $j$ của $A^{-1}$ là $x_j$). Ta đặt cả $n$ vế phải cạnh nhau và khử một lần:&lt;/p&gt;

\[[A \mid I] \ \xrightarrow{\text{Gauss–Jordan}}\ [I \mid A^{-1}].\]

&lt;p&gt;Nếu trong quá trình khử, phần bên trái xuất hiện một hàng toàn số 0 (tức $\operatorname{rank} A &amp;lt; n$), thì $A$ không khả nghịch.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; Tìm nghịch đảo của $A = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 3 \\ 0 &amp;amp; 1 &amp;amp; 4 \\ 5 &amp;amp; 6 &amp;amp; 0 \end{bmatrix}$.&lt;/p&gt;

\[\left[\begin{array}{rrr|rrr} 1 &amp;amp; 2 &amp;amp; 3 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 4 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0 \\ 5 &amp;amp; 6 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1 \end{array}\right]
\xrightarrow{R_3 \to R_3 - 5R_1}
\left[\begin{array}{rrr|rrr} 1 &amp;amp; 2 &amp;amp; 3 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 4 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; -4 &amp;amp; -15 &amp;amp; -5 &amp;amp; 0 &amp;amp; 1 \end{array}\right]
\xrightarrow{R_3 \to R_3 + 4R_2}
\left[\begin{array}{rrr|rrr} 1 &amp;amp; 2 &amp;amp; 3 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 4 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 &amp;amp; -5 &amp;amp; 4 &amp;amp; 1 \end{array}\right].\]

  &lt;p&gt;Khử phía trên: $R_2 \to R_2 - 4R_3$ cho $(0, 1, 0 \mid 20, -15, -4)$; $R_1 \to R_1 - 3R_3$ cho $(1, 2, 0 \mid 16, -12, -3)$; rồi $R_1 \to R_1 - 2R_2$ cho $(1, 0, 0 \mid -24, 18, 5)$. Vậy&lt;/p&gt;

\[A^{-1} = \begin{bmatrix} -24 &amp;amp; 18 &amp;amp; 5 \\ 20 &amp;amp; -15 &amp;amp; -4 \\ -5 &amp;amp; 4 &amp;amp; 1 \end{bmatrix}.\]

  &lt;p&gt;Kiểm tra một phần tử: hàng 1 của $A$ nhân cột 1 của $A^{-1}$ là $-24 + 40 - 15 = 1$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3 (suy biến).&lt;/strong&gt; $A = \begin{bmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 4 \end{bmatrix}$ có $ad - bc = 0$. Khử $[A \mid I]$: $R_2 \to R_2 - 2R_1$ cho hàng $(0, 0 \mid -2, 1)$. Phần bên trái có hàng 0, nên không khả nghịch. Hình học: $A$ ép cả mặt phẳng lên đường thẳng $y = 2x$; hai điểm $(2, 0)$ và $(0, 1)$ cùng bị đưa tới $(2, 4)$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;định-lý-về-ma-trận-khả-nghịch&quot;&gt;Định lý về ma trận khả nghịch&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 3.&lt;/strong&gt; Với $A$ vuông cấp $n$, các mệnh đề sau tương đương:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$A$ khả nghịch;&lt;/li&gt;
    &lt;li&gt;$Ax = b$ có nghiệm duy nhất với mọi $b$;&lt;/li&gt;
    &lt;li&gt;$Ax = 0$ chỉ có nghiệm tầm thường;&lt;/li&gt;
    &lt;li&gt;$\operatorname{rank} A = n$;&lt;/li&gt;
    &lt;li&gt;dạng bậc thang rút gọn của $A$ là $I_n$;&lt;/li&gt;
    &lt;li&gt;các cột của $A$ độc lập tuyến tính;&lt;/li&gt;
    &lt;li&gt;các cột của $A$ sinh ra $\mathbb{R}^n$;&lt;/li&gt;
    &lt;li&gt;có ma trận $B$ với $BA = I$ (chỉ cần một phía).&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; (1) ⇒ (2): $x = A^{-1}b$ là nghiệm, và nếu $Ax = b$ thì nhân trái với $A^{-1}$ được $x = A^{-1}b$. (2) ⇒ (3): lấy $b = 0$. (3) ⇒ (4): theo Bài 2.4, không có biến tự do nên có $n$ chốt. (4) ⇔ (5): ma trận vuông có $n$ chốt thì dạng rút gọn là $I$. (5) ⇒ (1): Gauss–Jordan trên $[A \mid I]$ chạy tới $[I \mid X]$, nên $AX = I$; các phép biến đổi sơ cấp đảo ngược được (Bài 3.4 viết chúng thành ma trận $E_k$ với $E_k \cdots E_1 A = I$), suy ra $XA = I$ với $X = E_k \cdots E_1$. (3) ⇔ (6): $Ax = 0$ là $\sum x_j a_j = 0$, đúng định nghĩa độc lập tuyến tính. (4) ⇔ (7): $n$ chốt nghĩa là cột cuối của $[A \mid b]$ không bao giờ có chốt, tức mọi $b$ thuộc span các cột. (1) ⇒ (8) hiển nhiên; (8) ⇒ (3): nếu $Ax = 0$ thì $x = BAx = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Điều (8) nói rằng với ma trận vuông, nghịch đảo một phía tự động là nghịch đảo hai phía. Với ma trận không vuông thì không đúng.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-mật-mã-hill&quot;&gt;Ứng dụng: mật mã Hill&lt;/h2&gt;

&lt;p&gt;Mật mã Hill (1929) mã hoá từng cặp chữ cái bằng một ma trận. Đánh số $A = 0, B = 1, \dots, Z = 25$ và làm mọi phép tính theo modulo 26. Chọn khoá $K = \begin{bmatrix} 3 &amp;amp; 3 \\ 2 &amp;amp; 5 \end{bmatrix}$.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Mã hoá “HI” $= (7, 8)$: $K(7, 8) = (45, 54) \equiv (19, 2)$, tức “TC”.&lt;/li&gt;
  &lt;li&gt;Giải mã cần $K^{-1}$ modulo 26. Ở đây $ad - bc = 9$, và $9 \cdot 3 = 27 \equiv 1$, nên $9^{-1} \equiv 3$. Công thức của Định lý 1 cho $K^{-1} \equiv 3\begin{bmatrix} 5 &amp;amp; -3 \\ -2 &amp;amp; 3 \end{bmatrix} \equiv \begin{bmatrix} 15 &amp;amp; 17 \\ 20 &amp;amp; 9 \end{bmatrix}$.&lt;/li&gt;
  &lt;li&gt;Kiểm tra: $K^{-1}(19, 2) = (319, 398) \equiv (7, 8)$, đúng “HI”.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Khoá chỉ dùng được khi $ad - bc$ khả nghịch modulo 26, tức nguyên tố cùng nhau với 26. Mật mã Hill ngày nay không còn an toàn (biết vài cặp bản rõ–bản mã là giải được $K$ bằng một hệ tuyến tính), nhưng các thuật toán mã khối hiện đại như AES vẫn có một bước trộn bằng nhân ma trận khả nghịch.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: ma trận nghịch đảo đưa lưới về chỗ cũ&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo t để thấy A⁻¹ đưa lưới của A về lưới ô vuông; thử ma trận suy biến.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=inverse&quot; title=&quot;Minh hoạ: ma trận nghịch đảo đưa lưới về chỗ cũ&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=inverse&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-nghịch-đảo-là-chạy-phim-ngược&quot;&gt;Video ngắn: Nghịch đảo là chạy phim ngược&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/inverse-rewind.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;A kéo mọi điểm đi, A⁻¹ tua ngược từng điểm về chỗ cũ. Khi det A = 0, mặt phẳng bị ép thành một đường, nhiều điểm chồng lên nhau nên không thể chạy ngược. Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Tìm nghịch đảo của $\begin{bmatrix} 4 &amp;amp; 7 \\ 2 &amp;amp; 6 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$ad - bc = 10$, nghịch đảo $\dfrac{1}{10}\begin{bmatrix} 6 &amp;amp; -7 \\ -2 &amp;amp; 4 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Tìm nghịch đảo của $\begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 1 \end{bmatrix}$ bằng Gauss–Jordan.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\dfrac12 \begin{bmatrix} 1 &amp;amp; 1 &amp;amp; -1 \\ -1 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; -1 &amp;amp; 1 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Chứng minh $(AB)^{-1} = B^{-1}A^{-1}$ và cho ví dụ $2 \times 2$ với $(AB)^{-1} \ne A^{-1}B^{-1}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Chứng minh như Định lý 2. Ví dụ $A = R$ (quay $90^\circ$), $B = S$ (trượt) ở Bài 3.2: $B^{-1}A^{-1} = S^{-1}R^{-1}$ và $A^{-1}B^{-1} = R^{-1}S^{-1}$ là nghịch đảo của $SR \ne RS$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Với giá trị nào của $k$ thì $\begin{bmatrix} 1 &amp;amp; k \\ k &amp;amp; 4 \end{bmatrix}$ suy biến? Giải thích hình học khi đó.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$4 - k^2 = 0$, tức $k = \pm 2$. Khi đó hai cột cùng phương và ma trận ép mặt phẳng lên một đường thẳng.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Giả sử $A^2 - 3A + 2I = 0$. Chứng minh $A$ khả nghịch và viết $A^{-1}$ theo $A$ và $I$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A(3I - A) = 2I$, nên $A \cdot \tfrac12(3I - A) = I$. Theo Định lý 3 (điều 8, áp dụng cho một phía), $A^{-1} = \tfrac12 (3I - A)$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$A^{-1}$ thoả $AA^{-1} = A^{-1}A = I$; nó duy nhất nếu có.&lt;/li&gt;
    &lt;li&gt;Với $2 \times 2$: khả nghịch khi và chỉ khi $ad - bc \ne 0$, và có công thức tường minh.&lt;/li&gt;
    &lt;li&gt;Tính $A^{-1}$ bằng Gauss–Jordan trên $[A \mid I]$.&lt;/li&gt;
    &lt;li&gt;$(AB)^{-1} = B^{-1}A^{-1}$, $(A^T)^{-1} = (A^{-1})^T$.&lt;/li&gt;
    &lt;li&gt;Khả nghịch ⇔ hạng $n$ ⇔ $Ax = 0$ chỉ có nghiệm $0$ ⇔ cột độc lập ⇔ cột sinh $\mathbb{R}^n$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Nhân ma trận: bốn cách nhìn</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter03/03_02_Nhan_Ma_Tran_Bon_Cach_Nhin/"/>
   <updated>2026-01-03T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter03/03_02_Nhan_Ma_Tran_Bon_Cach_Nhin</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;tính $AB$ theo bốn cách: phần tử, cột, hàng, tổng các tích cột–hàng;&lt;/li&gt;
    &lt;li&gt;chọn cách nhìn phù hợp cho từng câu hỏi;&lt;/li&gt;
    &lt;li&gt;giải thích tích ma trận là hợp của hai phép biến đổi, và vì sao $AB \ne BA$ bằng hình học.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Trên mặt phẳng, phép quay $90^\circ$ ngược chiều kim đồng hồ đưa $e_1 = (1, 0)$ tới $(0, 1)$ và $e_2 = (0, 1)$ tới $(-1, 0)$. Phép trượt ngang giữ $e_1$ và đẩy $e_2$ tới $(1, 1)$. Ghi ảnh của $e_1, e_2$ thành cột, ta có hai ma trận&lt;/p&gt;

\[R = \begin{bmatrix} 0 &amp;amp; -1 \\ 1 &amp;amp; 0 \end{bmatrix}, \qquad S = \begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \end{bmatrix}.\]

&lt;p&gt;Trượt trước rồi quay, hay quay trước rồi trượt: hình vuông đơn vị có rơi vào cùng một chỗ không? Tính bằng ma trận, $RS = \begin{bmatrix} 0 &amp;amp; -1 \\ 1 &amp;amp; 1 \end{bmatrix}$ còn $SR = \begin{bmatrix} 1 &amp;amp; -1 \\ 1 &amp;amp; 0 \end{bmatrix}$. Hai kết quả khác nhau. Bài này giải thích vì sao tích ma trận lại là “làm phép này rồi làm phép kia”.&lt;/p&gt;

&lt;h2 id=&quot;cách-1-theo-phần-tử&quot;&gt;Cách 1: theo phần tử&lt;/h2&gt;

&lt;p&gt;Đây là định nghĩa ở Bài 3.1: $(AB)_{ij}$ là tích vô hướng của hàng $i$ của $A$ với cột $j$ của $B$. Dùng khi chỉ cần một vài phần tử, hoặc khi tính tay ma trận nhỏ.&lt;/p&gt;

&lt;h2 id=&quot;cách-2-theo-cột&quot;&gt;Cách 2: theo cột&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Mệnh đề 1 (Cột của tích).&lt;/strong&gt; Nếu $B = [b_1 \ \cdots \ b_p]$ thì $AB = [A b_1 \ \cdots \ A b_p]$. Mỗi cột của $AB$ là một tổ hợp tuyến tính các cột của $A$, với hệ số lấy từ cột tương ứng của $B$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Phần tử thứ $i$ của cột $j$ của $AB$ là $\sum_k a_{ik} b_{kj}$, cũng là phần tử thứ $i$ của $A b_j$. Theo Định nghĩa 2 của Bài 2.1, $A b_j = \sum_k b_{kj} a_k$ là tổ hợp các cột $a_k$ của $A$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Hệ quả: mọi cột của $AB$ nằm trong span các cột của $A$. Dùng cách này khi hỏi về &lt;em&gt;không gian cột&lt;/em&gt;, hoặc khi giải nhiều hệ $Ax = b_j$ cùng lúc.&lt;/p&gt;

&lt;h2 id=&quot;cách-3-theo-hàng&quot;&gt;Cách 3: theo hàng&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Mệnh đề 2 (Hàng của tích).&lt;/strong&gt; Hàng $i$ của $AB$ bằng (hàng $i$ của $A$) nhân $B$. Mỗi hàng của $AB$ là tổ hợp tuyến tính các hàng của $B$, với hệ số lấy từ hàng tương ứng của $A$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Phần tử thứ $j$ của hàng $i$ của $AB$ là $\sum_k a_{ik} b_{kj}$. Đây là thành phần thứ $j$ của vectơ hàng $\sum_k a_{ik}\,(\text{hàng } k \text{ của } B)$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Phép biến đổi sơ cấp trên hàng là phép nhân bên trái bằng một ma trận (Bài 3.4) chính vì cách nhìn này.&lt;/p&gt;

&lt;h2 id=&quot;cách-4-tổng-các-tích-cộthàng&quot;&gt;Cách 4: tổng các tích cột–hàng&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Mệnh đề 3 (Tích ngoài).&lt;/strong&gt; Gọi $a_k$ là cột $k$ của $A$ và $r_k$ là hàng $k$ của $B$. Khi đó&lt;/p&gt;

\[AB = a_1 r_1 + a_2 r_2 + \cdots + a_n r_n ,\]

  &lt;p&gt;trong đó mỗi $a_k r_k$ (cột nhân hàng) là một ma trận cỡ $m \times p$ có hạng tối đa 1.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Phần tử $(i, j)$ của $a_k r_k$ là $a_{ik} b_{kj}$. Cộng theo $k$ được $\sum_k a_{ik} b_{kj} = (AB)_{ij}$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Cách nhìn này là nền của SVD ở Chương 11: một ma trận được viết thành tổng các ma trận hạng 1, và giữ lại vài số hạng lớn nhất là nén dữ liệu.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (bốn cách cho cùng một tích).&lt;/strong&gt; $A = \begin{bmatrix} 1 &amp;amp; 2 \\ 3 &amp;amp; 4 \end{bmatrix}$, $B = \begin{bmatrix} 5 &amp;amp; 6 \\ 7 &amp;amp; 8 \end{bmatrix}$.&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;Phần tử: $(AB)_{11} = 1\cdot5 + 2\cdot7 = 19$, $(AB)_{12} = 22$, $(AB)_{21} = 43$, $(AB)_{22} = 50$.&lt;/li&gt;
    &lt;li&gt;Cột: cột 1 của $AB$ là $5(1, 3) + 7(2, 4) = (19, 43)$.&lt;/li&gt;
    &lt;li&gt;Hàng: hàng 2 của $AB$ là $3(5, 6) + 4(7, 8) = (43, 50)$.&lt;/li&gt;
    &lt;li&gt;Cột–hàng:&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;\(\begin{bmatrix} 1 \\ 3 \end{bmatrix}\begin{bmatrix} 5 &amp;amp; 6 \end{bmatrix} + \begin{bmatrix} 2 \\ 4 \end{bmatrix}\begin{bmatrix} 7 &amp;amp; 8 \end{bmatrix} = \begin{bmatrix} 5 &amp;amp; 6 \\ 15 &amp;amp; 18 \end{bmatrix} + \begin{bmatrix} 14 &amp;amp; 16 \\ 28 &amp;amp; 32 \end{bmatrix} = \begin{bmatrix} 19 &amp;amp; 22 \\ 43 &amp;amp; 50 \end{bmatrix}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;nhân-ma-trận-là-hợp-các-phép-biến-đổi&quot;&gt;Nhân ma trận là hợp các phép biến đổi&lt;/h2&gt;

&lt;p&gt;Mỗi ma trận $A$ cỡ $m \times n$ cho một phép biến đổi $x \mapsto Ax$ từ $\mathbb{R}^n$ vào $\mathbb{R}^m$. Cột $j$ của $A$ là ảnh của $e_j$ (vectơ có số 1 ở vị trí $j$): $A e_j = a_j$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Tích là hợp).&lt;/strong&gt; Với mọi $x$, $(AB)x = A(Bx)$. Tức là áp dụng $AB$ cho $x$ giống hệt việc áp dụng $B$ trước, rồi $A$ sau.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Xem $x$ là ma trận một cột và dùng tính kết hợp (Định lý 1, Bài 3.1).&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Chú ý thứ tự: trong $AB$, phép $B$ đứng bên phải nên được làm &lt;strong&gt;trước&lt;/strong&gt;. Đọc từ phải sang trái, như khi viết hợp hàm $f(g(x))$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (giải thích ví dụ mở đầu bằng hình).&lt;/strong&gt; $RS$ là trượt trước, quay sau. Hình vuông đơn vị bị trượt thành hình bình hành có đỉnh $(1, 0), (2, 1), (1, 1)$, rồi quay $90^\circ$: cột của $RS$ là $R(1, 0) = (0, 1)$ và $R(1, 1) = (-1, 1)$.&lt;/p&gt;

  &lt;p&gt;$SR$ là quay trước, trượt sau. Hình vuông quay thành hình vuông có cạnh $(0, 1)$ và $(-1, 0)$, rồi bị trượt ngang: $S(0, 1) = (1, 1)$ và $S(-1, 0) = (-1, 0)$. Hình bình hành cuối cùng nghiêng theo hướng khác. Hai phép không đổi chỗ được cho nhau, nên $RS \ne SR$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3 (quay hai lần).&lt;/strong&gt; Phép quay góc $\alpha$ có ma trận $R_\alpha = \begin{bmatrix} \cos\alpha &amp;amp; -\sin\alpha \\ \sin\alpha &amp;amp; \cos\alpha \end{bmatrix}$. Quay $\beta$ rồi quay $\alpha$ là quay $\alpha + \beta$, nên $R_\alpha R_\beta = R_{\alpha+\beta}$. Nhân hai ma trận ra, so sánh phần tử $(1, 1)$:&lt;/p&gt;

\[\cos\alpha\cos\beta - \sin\alpha\sin\beta = \cos(\alpha + \beta).\]

  &lt;p&gt;Công thức cộng lượng giác hoá ra là một phép nhân ma trận. Ở đây $R_\alpha R_\beta = R_\beta R_\alpha$: hai phép quay quanh cùng một gốc giao hoán với nhau.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-mạng-nơ-ron-và-quy-tắc-dây-chuyền&quot;&gt;Ứng dụng: mạng nơ-ron và quy tắc dây chuyền&lt;/h2&gt;

&lt;p&gt;Một mạng nơ-ron tuyến tính hai lớp tính $y = W_2 (W_1 x)$. Theo Định lý 1, nó tương đương với một lớp duy nhất có ma trận $W = W_2 W_1$. Vì vậy mạng sâu cần hàm kích hoạt phi tuyến giữa các lớp; nếu không, thêm lớp không làm mô hình mạnh hơn. Khi huấn luyện, đạo hàm của hợp các phép biến đổi là tích các ma trận Jacobi (quy tắc dây chuyền trong khoá Giải tích), và thư viện học sâu tính các tích đó theo đúng thứ tự từ phải sang trái hoặc ngược lại tuỳ chi phí.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: bốn cách nhìn phép nhân ma trận&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Chọn cách nhìn: hàng · cột, theo cột, theo hàng, hay tổng các tích cột × hàng.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/phep_toan_ma_tran.html?mode=mul&quot; title=&quot;Minh hoạ: bốn cách nhìn phép nhân ma trận&quot; loading=&quot;lazy&quot; style=&quot;height: 560px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/phep_toan_ma_tran.html?mode=mul&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: nhân ma trận là hợp hai phép biến đổi&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Thực hiện B rồi A trên mặt phẳng; so sánh AB và BA.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=compose&quot; title=&quot;Minh hoạ: nhân ma trận là hợp hai phép biến đổi&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=compose&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-nhân-ma-trận-là-hợp-hai-phép-biến-đổi&quot;&gt;Video ngắn: Nhân ma trận là hợp hai phép biến đổi&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/composition-grid.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Trượt bằng A rồi quay bằng B cho đúng kết quả của một ma trận BA; đổi thứ tự thì lá cờ nằm chỗ khác, nên AB ≠ BA. Cột của BA là B nhân cột của A. Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Tính cột 2 của $AB$ với $A = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 2 \\ 0 &amp;amp; 1 &amp;amp; -1 \end{bmatrix}$, $B = \begin{bmatrix} 1 &amp;amp; 3 \\ 2 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix}$ chỉ bằng cách nhìn theo cột.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$3(1, 0) + 0(0, 1) + 1(2, -1) = (5, -1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Viết $\begin{bmatrix} 2 &amp;amp; 4 \\ 3 &amp;amp; 6 \end{bmatrix}$ thành tích một cột với một hàng.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\begin{bmatrix} 2 \\ 3 \end{bmatrix}\begin{bmatrix} 1 &amp;amp; 2 \end{bmatrix}$. Ma trận có hạng 1.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Phép phản xạ qua trục $x$ là $F = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; -1 \end{bmatrix}$. Tính $FR$ và $RF$ với $R$ là phép quay $90^\circ$. Mỗi tích là phép biến đổi hình học nào?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$FR = \begin{bmatrix} 0 &amp;amp; -1 \\ -1 &amp;amp; 0 \end{bmatrix}$: phản xạ qua đường $y = -x$. $RF = \begin{bmatrix} 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix}$: phản xạ qua đường $y = x$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Chứng minh: nếu $B$ có một cột bằng 0 thì $AB$ có cột đó bằng 0; nếu $A$ có một hàng bằng 0 thì $AB$ có hàng đó bằng 0.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Theo cột: cột $j$ của $AB$ là $A b_j = A\,0 = 0$. Theo hàng: hàng $i$ của $AB$ là (hàng $i$ của $A$)$B = 0 B = 0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao / lập trình).&lt;/strong&gt; Với hai ma trận ngẫu nhiên cỡ $500 \times 500$ trong NumPy, so sánh thời gian của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A @ B&lt;/code&gt; với một vòng lặp Python ba tầng theo định nghĩa. Vì sao chênh lệch lớn như vậy dù số phép nhân bằng nhau?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

`A @ B` chạy trong vài mili giây, vòng lặp Python mất hàng chục giây. Thư viện BLAS sắp xếp phép tính theo khối để dùng bộ nhớ đệm, dùng lệnh vectơ của CPU và nhiều lõi; chi phí của vòng lặp Python nằm ở trình thông dịch, không ở phép nhân.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Phần tử: hàng nhân cột. Cột: $AB = [Ab_1 \cdots Ab_p]$. Hàng: hàng của $AB$ là tổ hợp các hàng của $B$. Cột–hàng: $AB = \sum_k a_k r_k$, tổng các ma trận hạng 1.&lt;/li&gt;
    &lt;li&gt;Cột $j$ của $A$ là ảnh của $e_j$.&lt;/li&gt;
    &lt;li&gt;$(AB)x = A(Bx)$: tích là hợp, làm $B$ trước rồi $A$; thứ tự quan trọng nên $AB \ne BA$ nói chung.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Các phép toán trên ma trận</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter03/03_01_Cac_Phep_Toan_Tren_Ma_Tran/"/>
   <updated>2026-01-03T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter03/03_01_Cac_Phep_Toan_Tren_Ma_Tran</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;cộng hai ma trận, nhân ma trận với một số, nhân hai ma trận và lấy chuyển vị;&lt;/li&gt;
    &lt;li&gt;kiểm tra cỡ của hai ma trận để biết phép nhân có xác định không và kết quả có cỡ nào;&lt;/li&gt;
    &lt;li&gt;dùng các tính chất kết hợp, phân phối của phép nhân ma trận, và biết rằng phép nhân không giao hoán.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Một lớp có ba sinh viên. Điểm chuyên cần, giữa kỳ, cuối kỳ của họ ghi thành bảng&lt;/p&gt;

\[G = \begin{bmatrix} 8 &amp;amp; 7 &amp;amp; 9 \\ 6 &amp;amp; 9 &amp;amp; 7 \\ 10 &amp;amp; 8 &amp;amp; 6 \end{bmatrix}\]

&lt;p&gt;(mỗi hàng là một sinh viên). Trọng số của ba cột điểm là $20\%$, $30\%$, $50\%$, ghi thành vectơ $w = (0.2, 0.3, 0.5)$. Điểm tổng kết của sinh viên thứ nhất là $8 \cdot 0.2 + 7 \cdot 0.3 + 9 \cdot 0.5 = 8.2$, tức tích vô hướng của hàng 1 với $w$. Làm vậy cho cả ba hàng chính là tính $Gw = (8.2,\ 7.4,\ 7.4)$.&lt;/p&gt;

&lt;p&gt;Nếu khoa muốn thử thêm một cách tính điểm thứ hai, ta ghép hai vectơ trọng số thành hai cột của một ma trận $W$ và tính $GW$ một lần. Đó là phép nhân hai ma trận.&lt;/p&gt;

&lt;h2 id=&quot;ma-trận-và-các-phép-toán-đơn-giản&quot;&gt;Ma trận và các phép toán đơn giản&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Ma trận).&lt;/strong&gt; Một &lt;em&gt;ma trận cỡ $m \times n$&lt;/em&gt; là bảng số có $m$ hàng và $n$ cột. Phần tử ở hàng $i$, cột $j$ của $A$ ký hiệu $a_{ij}$ hoặc $(A)_{ij}$. Hai ma trận bằng nhau khi cùng cỡ và mọi phần tử tương ứng bằng nhau. Ma trận cỡ $n \times n$ gọi là &lt;em&gt;ma trận vuông cấp $n$&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 2 (Cộng và nhân với số).&lt;/strong&gt; Với $A, B$ cùng cỡ $m \times n$ và số $c$:&lt;/p&gt;

\[(A + B)_{ij} = a_{ij} + b_{ij}, \qquad (cA)_{ij} = c\, a_{ij}.\]

  &lt;p&gt;Ma trận không $0$ có mọi phần tử bằng 0. &lt;em&gt;Ma trận đơn vị&lt;/em&gt; $I_n$ là ma trận vuông cấp $n$ có các phần tử trên đường chéo chính bằng 1, các phần tử khác bằng 0.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Hai phép này làm theo từng phần tử, giống phép toán trên vectơ. Vì vậy chúng thoả đúng tám tính chất của Định lý 1, Bài 1.1. Ma trận cỡ $m \times n$ có thể xem như một vectơ có $mn$ thành phần.&lt;/p&gt;

&lt;h2 id=&quot;nhân-hai-ma-trận&quot;&gt;Nhân hai ma trận&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 3 (Tích hai ma trận).&lt;/strong&gt; Cho $A$ cỡ $m \times n$ và $B$ cỡ $n \times p$. Tích $AB$ là ma trận cỡ $m \times p$ với&lt;/p&gt;

\[(AB)_{ij} = a_{i1} b_{1j} + a_{i2} b_{2j} + \cdots + a_{in} b_{nj} = \sum_{k=1}^{n} a_{ik} b_{kj} .\]

  &lt;p&gt;Nói cách khác, phần tử $(i, j)$ của $AB$ là tích vô hướng của hàng $i$ của $A$ với cột $j$ của $B$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Phép nhân chỉ xác định khi &lt;strong&gt;số cột của $A$ bằng số hàng của $B$&lt;/strong&gt;. Quy tắc nhớ: $(m \times n)(n \times p) = (m \times p)$; hai số ở giữa phải bằng nhau và “triệt tiêu”.&lt;/p&gt;

&lt;p&gt;Với $p = 1$, $B$ là một vectơ cột và $AB$ là tích ma trận với vectơ của Bài 2.1. Hơn nữa, cột $j$ của $AB$ bằng $A$ nhân với cột $j$ của $B$: $AB = [A b_1 \ \cdots \ A b_p]$. Bài 3.2 khai thác điều này.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Cho $C = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 2 \\ -1 &amp;amp; 3 &amp;amp; 1 \end{bmatrix}$ (cỡ $2 \times 3$) và $D = \begin{bmatrix} 3 &amp;amp; 1 \\ 2 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix}$ (cỡ $3 \times 2$). Khi đó $CD$ có cỡ $2 \times 2$:&lt;/p&gt;

\[CD = \begin{bmatrix} 1\cdot3 + 0\cdot2 + 2\cdot1 &amp;amp; 1\cdot1 + 0 + 0 \\ -3 + 6 + 1 &amp;amp; -1 + 3 + 0 \end{bmatrix} = \begin{bmatrix} 5 &amp;amp; 1 \\ 4 &amp;amp; 2 \end{bmatrix},\]

  &lt;p&gt;còn $DC$ có cỡ $3 \times 3$:&lt;/p&gt;

\[DC = \begin{bmatrix} 2 &amp;amp; 3 &amp;amp; 7 \\ 1 &amp;amp; 3 &amp;amp; 5 \\ 1 &amp;amp; 0 &amp;amp; 2 \end{bmatrix}.\]

  &lt;p&gt;$CD$ và $DC$ thậm chí không cùng cỡ.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (không giao hoán).&lt;/strong&gt; Với $A = \begin{bmatrix} 1 &amp;amp; 2 \\ 3 &amp;amp; 4 \end{bmatrix}$ và $B = \begin{bmatrix} 5 &amp;amp; 6 \\ 7 &amp;amp; 8 \end{bmatrix}$:&lt;/p&gt;

\[AB = \begin{bmatrix} 19 &amp;amp; 22 \\ 43 &amp;amp; 50 \end{bmatrix}, \qquad BA = \begin{bmatrix} 23 &amp;amp; 34 \\ 31 &amp;amp; 46 \end{bmatrix}.\]

  &lt;p&gt;Hai ma trận vuông cùng cấp nhưng $AB \ne BA$. Bài 3.2 giải thích bằng hình học: nhân ma trận là làm hai phép biến đổi nối tiếp nhau, và thứ tự làm quan trọng.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Tính chất của phép nhân).&lt;/strong&gt; Với các ma trận có cỡ phù hợp và số $c$:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$(AB)C = A(BC)$ (kết hợp);&lt;/li&gt;
    &lt;li&gt;$A(B + C) = AB + AC$ và $(A + B)C = AC + BC$ (phân phối);&lt;/li&gt;
    &lt;li&gt;$c(AB) = (cA)B = A(cB)$;&lt;/li&gt;
    &lt;li&gt;$I_m A = A = A I_n$ với $A$ cỡ $m \times n$.&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;Nói chung $AB \ne BA$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Ta chứng minh tính kết hợp; các tính chất còn lại kiểm tra trực tiếp từ định nghĩa. Phần tử $(i, l)$ của $(AB)C$ là&lt;/p&gt;

\[\sum_{j} (AB)_{ij} c_{jl} = \sum_j \sum_k a_{ik} b_{kj} c_{jl},\]

  &lt;p&gt;còn phần tử $(i, l)$ của $A(BC)$ là $\sum_k a_{ik} (BC)_{kl} = \sum_k \sum_j a_{ik} b_{kj} c_{jl}$. Hai tổng kép gồm cùng các số hạng, chỉ khác thứ tự cộng, nên bằng nhau.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;content-box warning-box textbook-block&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Lưu ý.&lt;/strong&gt; Hai điều quen thuộc với số thực bị sai với ma trận:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$AB = 0$ không kéo theo $A = 0$ hoặc $B = 0$. Ví dụ $\begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}\begin{bmatrix} 1 &amp;amp; -1 \\ -1 &amp;amp; 1 \end{bmatrix} = 0$.&lt;/li&gt;
    &lt;li&gt;$(A + B)^2 = A^2 + AB + BA + B^2$, khác $A^2 + 2AB + B^2$ khi $AB \ne BA$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;h2 id=&quot;chuyển-vị&quot;&gt;Chuyển vị&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 4 (Chuyển vị).&lt;/strong&gt; &lt;em&gt;Chuyển vị&lt;/em&gt; của $A$ cỡ $m \times n$ là ma trận $A^T$ cỡ $n \times m$ với $(A^T)_{ij} = a_{ji}$: hàng của $A$ thành cột của $A^T$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Ví dụ, với $C$ ở Ví dụ 1, $C^T = \begin{bmatrix} 1 &amp;amp; -1 \\ 0 &amp;amp; 3 \\ 2 &amp;amp; 1 \end{bmatrix}$. Tích vô hướng viết được bằng chuyển vị: $x \cdot y = x^T y$ khi $x, y$ là vectơ cột. Các tính chất của chuyển vị, trong đó có $(AB)^T = B^T A^T$, ở Bài 3.5.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-bảng-điểm-và-hệ-thống-gợi-ý&quot;&gt;Ứng dụng: bảng điểm và hệ thống gợi ý&lt;/h2&gt;

&lt;p&gt;Quay lại ví dụ mở đầu. Giả sử khoa thử hai cách tính điểm: cách cũ $w_1 = (0.2, 0.3, 0.5)$ và cách mới $w_2 = (0.1, 0.4, 0.5)$. Ghép thành $W = [w_1 \ w_2]$ cỡ $3 \times 2$. Tích $GW$ cỡ $3 \times 2$ cho điểm của 3 sinh viên theo cả 2 cách trong một phép tính.&lt;/p&gt;

&lt;p&gt;Các hệ thống gợi ý phim dùng cùng ý tưởng ở quy mô lớn: ma trận “người dùng × đặc điểm” (thích hành động bao nhiêu, thích hài bao nhiêu, …) nhân với ma trận “đặc điểm × phim” cho ma trận “người dùng × phim” dự đoán mức yêu thích. Một lớp kết nối đầy đủ trong mạng nơ-ron cũng là một phép nhân ma trận (xem khoá Học sâu, Chương 02).&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: các phép toán trên ma trận&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Sửa A, B; chọn A + B, k·A, Aᵀ hoặc A·B và di chuột vào ô kết quả.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/phep_toan_ma_tran.html?mode=add&quot; title=&quot;Minh hoạ: các phép toán trên ma trận&quot; loading=&quot;lazy&quot; style=&quot;height: 560px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/phep_toan_ma_tran.html?mode=add&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Với $C, D$ ở Ví dụ 1, tính $2C - D^T$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$D^T = \begin{bmatrix} 3 &amp;amp; 2 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 0 \end{bmatrix}$, nên $2C - D^T = \begin{bmatrix} -1 &amp;amp; -2 &amp;amp; 3 \\ -3 &amp;amp; 5 &amp;amp; 2 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; $A$ cỡ $2 \times 3$, $B$ cỡ $3 \times 4$, $C$ cỡ $4 \times 2$. Tích nào xác định và có cỡ bao nhiêu: $AB$, $BA$, $ABC$, $CA$, $BC$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$AB$: $2 \times 4$. $BA$: không xác định. $ABC$: $2 \times 2$. $CA$: $4 \times 3$. $BC$: $3 \times 2$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Tìm mọi ma trận $X = \begin{bmatrix} a &amp;amp; b \\ c &amp;amp; d \end{bmatrix}$ giao hoán với $J = \begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \end{bmatrix}$, tức $XJ = JX$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$XJ = \begin{bmatrix} a &amp;amp; a + b \\ c &amp;amp; c + d \end{bmatrix}$, $JX = \begin{bmatrix} a + c &amp;amp; b + d \\ c &amp;amp; d \end{bmatrix}$. So sánh: $c = 0$, $a = d$. Vậy $X = \begin{bmatrix} a &amp;amp; b \\ 0 &amp;amp; a \end{bmatrix} = aI + bN$ với $N = \begin{bmatrix} 0 &amp;amp; 1 \\ 0 &amp;amp; 0 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Tính $GW$ ở mục Ứng dụng. Sinh viên nào có lợi khi đổi sang cách tính mới?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Cột 1: $(8.2, 7.4, 7.4)$. Cột 2: $(0.8 + 2.8 + 4.5, \ 0.6 + 3.6 + 3.5, \ 1.0 + 3.2 + 3.0) = (8.1, 7.7, 7.2)$. Sinh viên thứ hai có lợi (điểm giữa kỳ cao).

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Cho $N = \begin{bmatrix} 0 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 0 \end{bmatrix}$. Tính $N^2$, $N^3$. Suy ra $(I + N)^{k}$ với mọi $k \ge 2$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$N^2$ chỉ có phần tử $(1, 3)$ bằng 1; $N^3 = 0$. Vì $I$ giao hoán với $N$, khai triển nhị thức dùng được: $(I + N)^k = I + kN + \binom{k}{2} N^2$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Cộng và nhân với số làm theo từng phần tử.&lt;/li&gt;
    &lt;li&gt;$(AB)_{ij}$ = hàng $i$ của $A$ nhân vô hướng với cột $j$ của $B$; cần $(m \times n)(n \times p)$.&lt;/li&gt;
    &lt;li&gt;Phép nhân kết hợp, phân phối, có phần tử đơn vị $I$, nhưng không giao hoán, và $AB = 0$ không kéo theo $A = 0$ hay $B = 0$.&lt;/li&gt;
    &lt;li&gt;Chuyển vị đổi hàng thành cột; $x \cdot y = x^T y$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Fast matrix multiplication: Strassen's algorithm</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter03/03_06_Nhan_Ma_Tran_Nhanh_Strassen/"/>
   <updated>2026-01-03T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter03/03_06_Nhan_Ma_Tran_Nhanh_Strassen</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;count the multiplications of the definition-based matrix product;&lt;/li&gt;
    &lt;li&gt;verify Strassen’s seven formulas for the product of two $2 \times 2$ matrices;&lt;/li&gt;
    &lt;li&gt;explain why applying them recursively to blocks gives complexity $O(n^{\log_2 7}) \approx O(n^{2.81})$;&lt;/li&gt;
    &lt;li&gt;know when fast algorithms pay off in practice.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Multiplying two $n \times n$ matrices by the definition needs $n$ multiplications per entry, $n^3$ in total. For $n = 2$ that is 8. In 1969 Volker Strassen found a way with only 7 multiplications (at the price of more additions). Saving one multiplication out of eight sounds small, but since the “numbers” in the formulas may be whole matrix blocks, the saving compounds at every level of recursion. For $n = 4096$ the usual method needs about $6.9 \times 10^{10}$ multiplications; fully recursive Strassen needs about $1.4 \times 10^{10}$.&lt;/p&gt;

&lt;h2 id=&quot;seven-multiplications&quot;&gt;Seven multiplications&lt;/h2&gt;

&lt;p&gt;Let $A = \begin{bmatrix} a_{11} &amp;amp; a_{12} \\ a_{21} &amp;amp; a_{22} \end{bmatrix}$, $B = \begin{bmatrix} b_{11} &amp;amp; b_{12} \\ b_{21} &amp;amp; b_{22} \end{bmatrix}$. Define&lt;/p&gt;

\[\begin{aligned}
M_1 &amp;amp;= (a_{11} + a_{22})(b_{11} + b_{22}), &amp;amp; M_2 &amp;amp;= (a_{21} + a_{22})\, b_{11},\\
M_3 &amp;amp;= a_{11}(b_{12} - b_{22}), &amp;amp; M_4 &amp;amp;= a_{22}(b_{21} - b_{11}),\\
M_5 &amp;amp;= (a_{11} + a_{12})\, b_{22}, &amp;amp; M_6 &amp;amp;= (a_{21} - a_{11})(b_{11} + b_{12}),\\
M_7 &amp;amp;= (a_{12} - a_{22})(b_{21} + b_{22}).
\end{aligned}\]

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Strassen).&lt;/strong&gt; With the $M_i$ above, $C = AB$ satisfies&lt;/p&gt;

\[c_{11} = M_1 + M_4 - M_5 + M_7, \quad c_{12} = M_3 + M_5, \quad c_{21} = M_2 + M_4, \quad c_{22} = M_1 - M_2 + M_3 + M_6 .\]

  &lt;p&gt;The formulas use only addition, subtraction and multiplication, never commutativity of multiplication, so they hold when the $a_{ij}, b_{ij}$ are matrix blocks.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Expand, keeping “entry of $A$ before entry of $B$” in every product. For $c_{12}$: $M_3 + M_5 = a_{11}b_{12} - a_{11}b_{22} + a_{11}b_{22} + a_{12}b_{22} = a_{11}b_{12} + a_{12}b_{22}$, exactly entry $(1, 2)$ of $AB$. For $c_{11}$:&lt;/p&gt;

\[M_1 + M_4 - M_5 + M_7 = (a_{11}b_{11} + a_{11}b_{22} + a_{22}b_{11} + a_{22}b_{22}) + (a_{22}b_{21} - a_{22}b_{11}) - (a_{11}b_{22} + a_{12}b_{22}) + (a_{12}b_{21} + a_{12}b_{22} - a_{22}b_{21} - a_{22}b_{22}),\]

  &lt;p&gt;which simplifies to $a_{11}b_{11} + a_{12}b_{21}$. The remaining two entries are similar. At no step do we swap the two factors of a product, so the argument still works when the entries are matrices.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; $A = \begin{bmatrix} 1 &amp;amp; 2 \\ 3 &amp;amp; 4 \end{bmatrix}$, $B = \begin{bmatrix} 5 &amp;amp; 6 \\ 7 &amp;amp; 8 \end{bmatrix}$:&lt;/p&gt;

\[M_1 = 5 \cdot 13 = 65,\ M_2 = 7 \cdot 5 = 35,\ M_3 = 1 \cdot (-2) = -2,\ M_4 = 4 \cdot 2 = 8,\ M_5 = 3 \cdot 8 = 24,\ M_6 = 2 \cdot 11 = 22,\ M_7 = (-2) \cdot 15 = -30.\]

  &lt;p&gt;Then $c_{11} = 65 + 8 - 24 - 30 = 19$, $c_{12} = -2 + 24 = 22$, $c_{21} = 35 + 8 = 43$, $c_{22} = 65 - 35 - 2 + 22 = 50$, matching $AB$ from Lesson 3.2.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;recursion-on-blocks&quot;&gt;Recursion on blocks&lt;/h2&gt;

&lt;p&gt;For $n = 2^k$, split $A, B$ into four $n/2 \times n/2$ blocks (Lesson 3.5) and apply Theorem 1: this needs 7 block products of size $n/2$ and 18 block additions/subtractions. Each block product is computed the same way.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2.&lt;/strong&gt; Strassen’s algorithm, recursing down to $1 \times 1$, uses exactly $7^k = n^{\log_2 7}$ scalar multiplications to multiply two $n \times n$ matrices with $n = 2^k$. The total number of operations (including additions) is $O(n^{\log_2 7})$, where $\log_2 7 \approx 2.807$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Let $T(n)$ be the number of multiplications. Then $T(1) = 1$ and $T(n) = 7\,T(n/2)$, so $T(2^k) = 7^k$. Since $7^k = (2^k)^{\log_2 7} = n^{\log_2 7}$, the claim about multiplications follows. For all operations, let $S(n)$ be the total; $S(n) = 7 S(n/2) + 18 (n/2)^2$. Unrolling,&lt;/p&gt;

\[S(n) = 7^k S(1) + \tfrac{18}{4} n^2 \left(1 + \tfrac74 + \left(\tfrac74\right)^2 + \cdots + \left(\tfrac74\right)^{k-1}\right).\]

  &lt;p&gt;The geometric sum equals $\tfrac{(7/4)^k - 1}{3/4} &amp;lt; \tfrac43 (7/4)^k$, and $n^2 (7/4)^k = 4^k (7/4)^k = 7^k$. Hence $S(n) \le 7^k + 6 \cdot 7^k = 7 \cdot 7^k = O(n^{\log_2 7})$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;If $n$ is not a power of 2, pad with zero rows and columns; the size at most doubles, so the complexity is unchanged.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (concrete counts).&lt;/strong&gt; For $n = 4$: the usual method uses $4^3 = 64$ multiplications; Strassen uses $7^2 = 49$. For $n = 1024 = 2^{10}$: $2^{30} \approx 1.07 \times 10^9$ against $7^{10} \approx 2.8 \times 10^8$, about 3.8 times fewer.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;practice-and-applications&quot;&gt;Practice and applications&lt;/h2&gt;

&lt;p&gt;In practice, libraries recurse with Strassen only down to some size (often a few hundred) and then switch to the usual cache-optimised method, because at small sizes the 18 block additions and memory allocation cost more than the multiplications saved. Strassen is also slightly less numerically stable because of the subtractions.&lt;/p&gt;

&lt;p&gt;The question “how many multiplications are needed” is still open. The best known exponent is about $2.37$, but those algorithms only pay off for matrices too large to be practical. In 2022 DeepMind’s AlphaTensor used reinforcement learning to find a way to multiply two $4 \times 4$ matrices with 47 multiplications in arithmetic modulo 2, fewer than the 49 of two-level Strassen. Fast matrix multiplication matters because it is the core of deep learning: training a large language model is mostly multiplying huge matrices. Cannon’s algorithm (matrix multiplication on a grid of parallel processors) addresses the same kind of question for parallel computers.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: Strassen&apos;s algorithm&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Seven block products instead of eight, and operation counts as n grows.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/strassen.html?lang=en&quot; title=&quot;Interactive: Strassen&amp;#39;s algorithm&quot; loading=&quot;lazy&quot; style=&quot;height: 760px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/strassen.html?lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: Cannon&apos;s parallel matrix multiplication&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Blocks of A shift left and blocks of B shift up on a processor grid.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/cannon.html?lang=en&quot; title=&quot;Interactive: Cannon&amp;#39;s parallel matrix multiplication&quot; loading=&quot;lazy&quot; style=&quot;height: 760px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/cannon.html?lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Use Strassen’s formulas to compute $\begin{bmatrix} 1 &amp;amp; 0 \\ 2 &amp;amp; 1 \end{bmatrix}\begin{bmatrix} 3 &amp;amp; 1 \\ 0 &amp;amp; 2 \end{bmatrix}$ and compare with the usual method.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$M_1 = 2 \cdot 5 = 10$, $M_2 = 3 \cdot 3 = 9$, $M_3 = 1 \cdot (-1) = -1$, $M_4 = 1 \cdot (-3) = -3$, $M_5 = 1 \cdot 2 = 2$, $M_6 = 1 \cdot 4 = 4$, $M_7 = (-1) \cdot 2 = -2$. Then $C = \begin{bmatrix} 3 &amp;amp; 1 \\ 6 &amp;amp; 4 \end{bmatrix}$, matching the usual method.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Verify $c_{21} = M_2 + M_4$ by expanding.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$M_2 + M_4 = a_{21}b_{11} + a_{22}b_{11} + a_{22}b_{21} - a_{22}b_{11} = a_{21}b_{11} + a_{22}b_{21}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; For $n = 2^k$, find the smallest $k$ for which fully recursive Strassen uses fewer than half the multiplications of the usual method.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

We need $(7/8)^k &amp;lt; 1/2$, i.e. $k &amp;gt; \ln 2 / \ln(8/7) \approx 5.19$. So $k = 6$, $n = 64$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; A variant (Winograd) uses 7 multiplications and 15 block additions instead of 18. Write the recurrence and say whether the exponent changes.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$S(n) = 7S(n/2) + 15(n/2)^2$. The exponent is still $\log_2 7$; only the leading constant changes.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced / programming).&lt;/strong&gt; Implement recursive Strassen in NumPy, stopping at size $m$ and using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@&lt;/code&gt; for small blocks. Time it for $n = 1024$ with $m = 32, 64, 128, 256$ and compare with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A @ B&lt;/code&gt;.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Results depend on the machine, but a Python implementation is usually slower than plain `A @ B` for every $m$, because BLAS is highly optimised and creating temporary blocks costs time. Strassen&apos;s rounding error is usually a little larger than that of `A @ B`, because of the extra subtractions.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Multiplication by the definition: $n^3$ multiplications.&lt;/li&gt;
    &lt;li&gt;Strassen: 7 multiplications for a $2 \times 2$ product, with formulas that do not use commutativity and so apply to blocks.&lt;/li&gt;
    &lt;li&gt;Block recursion gives $n^{\log_2 7} \approx n^{2.81}$ multiplications and the same order for all operations.&lt;/li&gt;
    &lt;li&gt;In practice it pays off only for large matrices; libraries combine Strassen with the usual method.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Transpose, symmetric matrices and block matrices</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter03/03_05_Chuyen_Vi_Doi_Xung_Va_Ma_Tran_Khoi/"/>
   <updated>2026-01-03T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter03/03_05_Chuyen_Vi_Doi_Xung_Va_Ma_Tran_Khoi</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;use the properties of the transpose, in particular $(AB)^T = B^T A^T$;&lt;/li&gt;
    &lt;li&gt;recognise symmetric matrices and prove that $A^T A$ and $AA^T$ are always symmetric;&lt;/li&gt;
    &lt;li&gt;split matrices into blocks and multiply block by block like matrices of numbers;&lt;/li&gt;
    &lt;li&gt;use $A^T A$ to compute all dot products between data columns.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Four students are measured on two (standardised) features: hours of self-study and number of homework sets handed in. Record them as a $4 \times 2$ data matrix $X$, one column per feature:&lt;/p&gt;

\[X = \begin{bmatrix} 1 &amp;amp; 2 \\ 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \\ 2 &amp;amp; 1 \end{bmatrix}.\]

&lt;p&gt;To see how much the two features “go together”, compute the dot product of the two columns: $1\cdot2 + 0\cdot1 + 1\cdot0 + 2\cdot1 = 4$. Together with the squared lengths of the columns ($6$ and $6$), all three numbers fit in one product:&lt;/p&gt;

\[X^T X = \begin{bmatrix} 6 &amp;amp; 4 \\ 4 &amp;amp; 6 \end{bmatrix}.\]

&lt;p&gt;This matrix is symmetric about its diagonal. This lesson explains why, and why $X^T X$ appears everywhere in statistics and machine learning.&lt;/p&gt;

&lt;h2 id=&quot;properties-of-the-transpose&quot;&gt;Properties of the transpose&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; For matrices of compatible sizes and a number $c$:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$(A^T)^T = A$;&lt;/li&gt;
    &lt;li&gt;$(A + B)^T = A^T + B^T$ and $(cA)^T = c A^T$;&lt;/li&gt;
    &lt;li&gt;$(AB)^T = B^T A^T$.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; (1) and (2) follow directly from $(A^T)_{ij} = a_{ji}$. For (3), let $A$ be $m \times n$ and $B$ be $n \times p$. Entry $(i, j)$ of $(AB)^T$ is entry $(j, i)$ of $AB$, namely $\sum_k a_{jk} b_{ki}$. Entry $(i, j)$ of $B^T A^T$ is $\sum_k (B^T)_{ik} (A^T)_{kj} = \sum_k b_{ki} a_{jk}$. The sums agree.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Note the reversed order, as in $(AB)^{-1} = B^{-1}A^{-1}$. For three matrices, $(ABC)^T = C^T B^T A^T$.&lt;/p&gt;

&lt;p&gt;Dot products and transposes are linked by a frequently used identity: for $x \in \mathbb{R}^n$, $y \in \mathbb{R}^m$ and $A$ of size $m \times n$,&lt;/p&gt;

\[(Ax) \cdot y = (Ax)^T y = x^T A^T y = x \cdot (A^T y).\]

&lt;p&gt;This identity is a coordinate-free way to define the transpose, and it will be used often in Chapters 07 and 10.&lt;/p&gt;

&lt;h2 id=&quot;symmetric-matrices&quot;&gt;Symmetric matrices&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Symmetric, skew-symmetric).&lt;/strong&gt; A square matrix $A$ is &lt;em&gt;symmetric&lt;/em&gt; if $A^T = A$, i.e. $a_{ij} = a_{ji}$ for all $i, j$. It is &lt;em&gt;skew-symmetric&lt;/em&gt; if $A^T = -A$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;A symmetric matrix is its own mirror image across the main diagonal. Examples: a table of distances between cities (from $i$ to $j$ equals from $j$ to $i$), the adjacency matrix of an undirected graph, a covariance matrix.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2.&lt;/strong&gt; For every $m \times n$ matrix $A$, the matrices $A^T A$ (order $n$) and $A A^T$ (order $m$) are symmetric. Moreover entry $(i, j)$ of $A^T A$ is the dot product of columns $i$ and $j$ of $A$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; $(A^T A)^T = A^T (A^T)^T = A^T A$ by Theorem 1, and likewise for $AA^T$. Entry $(i, j)$ of $A^T A$ is row $i$ of $A^T$ (that is, column $i$ of $A$) dotted with column $j$ of $A$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proposition 1.&lt;/strong&gt; Every square matrix $A$ is uniquely the sum of a symmetric and a skew-symmetric matrix:&lt;/p&gt;

  &lt;p&gt;\(A = \underbrace{\tfrac12 (A + A^T)}_{\text{symmetric}} + \underbrace{\tfrac12 (A - A^T)}_{\text{skew-symmetric}} .\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Theorem 1 shows directly that the two terms have the stated properties. If $A = S + K = S&apos; + K&apos;$ with $S, S&apos;$ symmetric and $K, K&apos;$ skew-symmetric, then $S - S&apos; = K&apos; - K$ is both symmetric and skew-symmetric, so it equals its own negative and is therefore $0$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; $A = \begin{bmatrix} 1 &amp;amp; 4 \\ 2 &amp;amp; 3 \end{bmatrix}$ has symmetric part $\begin{bmatrix} 1 &amp;amp; 3 \\ 3 &amp;amp; 3 \end{bmatrix}$ and skew-symmetric part $\begin{bmatrix} 0 &amp;amp; 1 \\ -1 &amp;amp; 0 \end{bmatrix}$. The skew part is the clockwise rotation by $90^\circ$; it contributes nothing to $x^T A x$, because $x^T K x$ is a number equal to its own transpose $x^T K^T x = -x^T K x$, hence 0. This matters for quadratic forms in Chapter 10.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;block-matrices&quot;&gt;Block matrices&lt;/h2&gt;

&lt;p&gt;A large matrix can be cut into &lt;em&gt;blocks&lt;/em&gt; by horizontal and vertical lines. If the column partition of $A$ matches the row partition of $B$, then $AB$ can be computed block by block exactly as for matrices of numbers, keeping the order in each block product:&lt;/p&gt;

\[\begin{bmatrix} A_{11} &amp;amp; A_{12} \\ A_{21} &amp;amp; A_{22} \end{bmatrix}
\begin{bmatrix} B_{11} &amp;amp; B_{12} \\ B_{21} &amp;amp; B_{22} \end{bmatrix}
= \begin{bmatrix} A_{11}B_{11} + A_{12}B_{21} &amp;amp; A_{11}B_{12} + A_{12}B_{22} \\ A_{21}B_{11} + A_{22}B_{21} &amp;amp; A_{21}B_{12} + A_{22}B_{22} \end{bmatrix}.\]

&lt;p&gt;Reason: entry $(i, j)$ of $AB$ is $\sum_k a_{ik} b_{kj}$; split the sum over $k$ into the pieces belonging to the column blocks of $A$; each piece is an entry of one block product.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; Let $A = \begin{bmatrix} A_{11} &amp;amp; I \\ 0 &amp;amp; 2I \end{bmatrix}$ and $B = \begin{bmatrix} I &amp;amp; 0 \\ C &amp;amp; I \end{bmatrix}$ with $2 \times 2$ blocks, $A_{11} = \begin{bmatrix} 1 &amp;amp; 2 \\ 3 &amp;amp; 4 \end{bmatrix}$, $C = \begin{bmatrix} 1 &amp;amp; 1 \\ 2 &amp;amp; 0 \end{bmatrix}$. Block multiplication gives&lt;/p&gt;

\[AB = \begin{bmatrix} A_{11} + C &amp;amp; I \\ 2C &amp;amp; 2I \end{bmatrix} = \begin{bmatrix} 2 &amp;amp; 3 &amp;amp; 1 &amp;amp; 0 \\ 5 &amp;amp; 4 &amp;amp; 0 &amp;amp; 1 \\ 2 &amp;amp; 2 &amp;amp; 2 &amp;amp; 0 \\ 4 &amp;amp; 0 &amp;amp; 0 &amp;amp; 2 \end{bmatrix}.\]

  &lt;p&gt;We only add two $2 \times 2$ matrices and double $C$, instead of performing 64 multiplications of numbers.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3 (block diagonal inverse).&lt;/strong&gt; If $M = \begin{bmatrix} A &amp;amp; 0 \\ 0 &amp;amp; D \end{bmatrix}$ with $A, D$ square and invertible, then $M^{-1} = \begin{bmatrix} A^{-1} &amp;amp; 0 \\ 0 &amp;amp; D^{-1} \end{bmatrix}$: block multiplication gives $I$. For example $\begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}^{-1} = \begin{bmatrix} 1 &amp;amp; -1 \\ -1 &amp;amp; 2 \end{bmatrix}$ and $\begin{bmatrix} 3 &amp;amp; 0 \\ 1 &amp;amp; 1 \end{bmatrix}^{-1} = \begin{bmatrix} 1/3 &amp;amp; 0 \\ -1/3 &amp;amp; 1 \end{bmatrix}$ give at once the inverse of the $4 \times 4$ block diagonal matrix built from them.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-gram-and-covariance-matrices&quot;&gt;Application: Gram and covariance matrices&lt;/h2&gt;

&lt;p&gt;In machine learning, a data matrix $X$ has $m$ rows (samples) and $n$ columns (features). The $n \times n$ matrix $X^T X$ is the &lt;em&gt;Gram matrix&lt;/em&gt; of the columns. If each column has had its mean subtracted, then $\tfrac{1}{m-1} X^T X$ is the &lt;em&gt;covariance matrix&lt;/em&gt;: the diagonal holds the variance of each feature, the off-diagonal entries the covariance between two features. It is symmetric by Theorem 2. Linear regression (Chapter 08) solves $X^T X\, \beta = X^T y$, and PCA (Chapter 11) finds the eigenvectors of the covariance matrix.&lt;/p&gt;

&lt;p&gt;Block matrices are also how libraries multiply large matrices: they split them into blocks that fit the CPU cache, or distribute them over several machines, each computing some block products.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: transpose and symmetric matrices&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Click an entry of A to see where it goes in Aᵀ; the A + Aᵀ tab builds a symmetric matrix.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/phep_toan_ma_tran.html?mode=T&amp;amp;lang=en&quot; title=&quot;Interactive: transpose and symmetric matrices&quot; loading=&quot;lazy&quot; style=&quot;height: 560px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/phep_toan_ma_tran.html?mode=T&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; For $A = \begin{bmatrix} 1 &amp;amp; 2 \\ 0 &amp;amp; 1 \end{bmatrix}$, $B = \begin{bmatrix} 3 &amp;amp; 0 \\ 1 &amp;amp; 1 \end{bmatrix}$, check that $(AB)^T = B^T A^T$ and $(AB)^T \ne A^T B^T$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$AB = \begin{bmatrix} 5 &amp;amp; 2 \\ 1 &amp;amp; 1 \end{bmatrix}$, $(AB)^T = \begin{bmatrix} 5 &amp;amp; 1 \\ 2 &amp;amp; 1 \end{bmatrix} = B^T A^T$, while $A^T B^T = \begin{bmatrix} 3 &amp;amp; 1 \\ 6 &amp;amp; 3 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Find $a, b, c$ so that $\begin{bmatrix} 1 &amp;amp; a &amp;amp; 3 \\ 2 &amp;amp; 4 &amp;amp; b \\ c &amp;amp; 5 &amp;amp; 6 \end{bmatrix}$ is symmetric.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$a = 2$, $b = 5$, $c = 3$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Prove: if $A, B$ are symmetric of the same order, then $AB$ is symmetric if and only if $AB = BA$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$(AB)^T = B^T A^T = BA$. So $(AB)^T = AB$ if and only if $BA = AB$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; Compute $XX^T$ for $X$ from the opening example. What does entry $(i, j)$ mean?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$XX^T = \begin{bmatrix} 5 &amp;amp; 2 &amp;amp; 1 &amp;amp; 4 \\ 2 &amp;amp; 1 &amp;amp; 0 &amp;amp; 1 \\ 1 &amp;amp; 0 &amp;amp; 1 &amp;amp; 2 \\ 4 &amp;amp; 1 &amp;amp; 2 &amp;amp; 5 \end{bmatrix}$. Entry $(i, j)$ is the dot product of students $i$ and $j$ (two rows), a measure of how similar they are.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Let $M = \begin{bmatrix} A &amp;amp; B \\ 0 &amp;amp; D \end{bmatrix}$ with $A, D$ square and invertible. Find $M^{-1}$ in block form.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$M^{-1} = \begin{bmatrix} A^{-1} &amp;amp; -A^{-1} B D^{-1} \\ 0 &amp;amp; D^{-1} \end{bmatrix}$. Check by block multiplication: block $(1, 2)$ of $MM^{-1}$ is $-AA^{-1}BD^{-1} + BD^{-1} = 0$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$(AB)^T = B^T A^T$; $(Ax)\cdot y = x \cdot (A^T y)$.&lt;/li&gt;
    &lt;li&gt;Symmetric: $A^T = A$. $A^TA$ and $AA^T$ are always symmetric; $A^TA$ holds all dot products between the columns of $A$.&lt;/li&gt;
    &lt;li&gt;Every square matrix = symmetric part + skew-symmetric part.&lt;/li&gt;
    &lt;li&gt;Multiply block by block like numbers, keeping the order in each block product.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Elementary matrices and the LU factorization</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter03/03_04_Ma_Tran_So_Cap_Va_Phan_Ra_LU/"/>
   <updated>2026-01-03T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter03/03_04_Ma_Tran_So_Cap_Va_Phan_Ra_LU</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;write the elementary matrix of an elementary row operation, and its inverse;&lt;/li&gt;
    &lt;li&gt;factor $A = LU$ by recording the multipliers of Gaussian elimination;&lt;/li&gt;
    &lt;li&gt;solve $Ax = b$ by two substitutions: $Ly = b$, then $Ux = y$;&lt;/li&gt;
    &lt;li&gt;use $PA = LU$ when elimination needs row swaps.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;A structural engineer must compute the deflection of the same steel frame under 50 different load cases. Each case is a system $Ax = b_k$ with the same matrix $A$ (the stiffness of the frame) and different right-hand sides $b_k$. Running Gaussian elimination 50 times is wasteful: the expensive part ($\approx n^3/3$ multiplications) depends only on $A$. We want to eliminate $A$ once, &lt;em&gt;record&lt;/em&gt; the steps, and then apply them to each $b_k$ at a cost of only about $n^2$. That record is the factorization $A = LU$.&lt;/p&gt;

&lt;h2 id=&quot;elementary-matrices&quot;&gt;Elementary matrices&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Elementary matrix).&lt;/strong&gt; An &lt;em&gt;elementary matrix&lt;/em&gt; is a matrix obtained from $I_n$ by exactly one elementary row operation.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;For example with $n = 3$:&lt;/p&gt;

\[E_{21}(-2) = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 \\ -2 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix} \ (R_2 \to R_2 - 2R_1), \qquad
P_{23} = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; 0 \end{bmatrix} \ (R_2 \leftrightarrow R_3).\]

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; If $E$ is obtained from $I$ by an elementary row operation, then for every matrix $A$ with $n$ rows, $EA$ is obtained from $A$ by that same operation. Every elementary matrix is invertible, and its inverse is the elementary matrix of the inverse operation.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; By the row view (Lesson 3.2), row $i$ of $EA$ is a combination of the rows of $A$ with coefficients from row $i$ of $E$. For $E = E_{ij}(c)$, row $i$ of $E$ is $e_i^T + c\, e_j^T$, so row $i$ of $EA$ is (row $i$) $+ c$ (row $j$) of $A$; the other rows of $E$ are rows of $I$ and keep the other rows of $A$. The other two types are checked the same way. Let $E&apos;$ be the matrix of the inverse operation (Lemma 1, Lesson 2.2); applying the operation and then its inverse to $I$ gives $I$, i.e. $E&apos;E = I$, and similarly $EE&apos; = I$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;For example, $E_{21}(-2)^{-1} = E_{21}(2)$: after subtracting twice row 1, undo by adding twice row 1 back.&lt;/p&gt;

&lt;h2 id=&quot;the-lu-factorization&quot;&gt;The LU factorization&lt;/h2&gt;

&lt;p&gt;When Gaussian elimination &lt;em&gt;needs no row swaps&lt;/em&gt;, it uses only operations $R_i \to R_i - \ell_{ij} R_j$ with $i &amp;gt; j$. Each is left multiplication by $E_{ij}(-\ell_{ij})$, a lower triangular matrix. The result is&lt;/p&gt;

\[E_k \cdots E_2 E_1 A = U ,\]

&lt;p&gt;where $U$ is &lt;em&gt;upper triangular&lt;/em&gt; (the echelon form). Hence $A = (E_1^{-1} E_2^{-1} \cdots E_k^{-1})\, U = LU$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2 (LU factorization).&lt;/strong&gt; If Gaussian elimination on a square matrix $A$ of order $n$ needs no row swaps, then $A = LU$, where $U$ is the upper triangular matrix produced by elimination and $L$ is lower triangular with ones on the diagonal and entry $(i, j)$, $i &amp;gt; j$, equal to the multiplier $\ell_{ij}$ used.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof (main idea).&lt;/strong&gt; We saw $L = E_1^{-1} \cdots E_k^{-1}$ with each $E^{-1} = E_{ij}(+\ell_{ij})$. The eliminations are done column by column, $1, 2, \dots$; multiplying the matrices $E_{ij}(\ell_{ij})$ in this order puts each $\ell_{ij}$ at position $(i, j)$ without mixing: multiplying on the right by $E_{ij}(\ell)$ only adds $\ell$ times column $i$ to column $j$, and column $i$ of the running product is still $e_i$ at that moment (columns beyond $j$ have not been touched). Check it on the example below.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; $A = \begin{bmatrix} 2 &amp;amp; 1 &amp;amp; 1 \\ 4 &amp;amp; -6 &amp;amp; 0 \\ -2 &amp;amp; 7 &amp;amp; 2 \end{bmatrix}$.&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$\ell_{21} = 4/2 = 2$: $R_2 \to R_2 - 2R_1$ gives $(0, -8, -2)$.&lt;/li&gt;
    &lt;li&gt;$\ell_{31} = -2/2 = -1$: $R_3 \to R_3 + R_1$ gives $(0, 8, 3)$.&lt;/li&gt;
    &lt;li&gt;$\ell_{32} = 8/(-8) = -1$: $R_3 \to R_3 + R_2$ gives $(0, 0, 1)$.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Hence&lt;/p&gt;

\[L = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 \\ 2 &amp;amp; 1 &amp;amp; 0 \\ -1 &amp;amp; -1 &amp;amp; 1 \end{bmatrix}, \qquad U = \begin{bmatrix} 2 &amp;amp; 1 &amp;amp; 1 \\ 0 &amp;amp; -8 &amp;amp; -2 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}.\]

  &lt;p&gt;Multiplying back gives $A$: for instance row 3 of $LU$ is $-1 \cdot (2, 1, 1) - 1 \cdot (0, -8, -2) + (0, 0, 1) = (-2, 7, 2)$.&lt;/p&gt;
&lt;/div&gt;

&lt;h3 id=&quot;solving-with-lu&quot;&gt;Solving with LU&lt;/h3&gt;

&lt;p&gt;$Ax = b$ becomes $L(Ux) = b$. Put $y = Ux$:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Solve $Ly = b$ by &lt;em&gt;forward substitution&lt;/em&gt; (top to bottom), since $L$ is lower triangular.&lt;/li&gt;
  &lt;li&gt;Solve $Ux = y$ by &lt;em&gt;back substitution&lt;/em&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Each step costs about $n^2/2$ multiplications.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; With $A$ from Example 1 and $b = (5, -2, 9)$. Forward: $y_1 = 5$; $2y_1 + y_2 = -2$ so $y_2 = -12$; $-y_1 - y_2 + y_3 = 9$ so $y_3 = 2$. Back with $U$: $x_3 = 2$; $-8x_2 - 2x_3 = -12$ so $x_2 = 1$; $2x_1 + x_2 + x_3 = 5$ so $x_1 = 1$. Solution $x = (1, 1, 2)$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;when-rows-must-be-swapped-pa--lu&quot;&gt;When rows must be swapped: $PA = LU$&lt;/h2&gt;

&lt;p&gt;If at some point the pivot position holds 0 (or we pivot as in Lesson 2.6), rows must be swapped. Collect all swaps in a &lt;em&gt;permutation matrix&lt;/em&gt; $P$ (a reordering of the rows of $I$) and do them first.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 3.&lt;/strong&gt; For every invertible square matrix $A$ there is a permutation matrix $P$ with $PA = LU$, where $L$ is lower triangular with unit diagonal and $U$ is upper triangular with nonzero diagonal.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;We accept this theorem; its proof checks that all row swaps can be moved to the front if the recorded multipliers in $L$ are permuted accordingly.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3.&lt;/strong&gt; $A = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 1 \\ 2 &amp;amp; 4 &amp;amp; 3 \\ 1 &amp;amp; 3 &amp;amp; 2 \end{bmatrix}$. Eliminating column 1 turns row 2 into $(0, 0, 1)$ and row 3 into $(0, 1, 1)$. The pivot position $(2, 2)$ is 0, so rows 2 and 3 must be swapped. Do that swap first with $P = P_{23}$:&lt;/p&gt;

  &lt;p&gt;\(PA = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 1 \\ 1 &amp;amp; 3 &amp;amp; 2 \\ 2 &amp;amp; 4 &amp;amp; 3 \end{bmatrix} = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 \\ 1 &amp;amp; 1 &amp;amp; 0 \\ 2 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-many-right-hand-sides&quot;&gt;Application: many right-hand sides&lt;/h2&gt;

&lt;p&gt;Back to the opening example with $n = 1000$ and 50 load cases. Separate elimination for each case: $50 \times 3.3 \times 10^8 \approx 1.7 \times 10^{10}$ multiplications. One LU factorization ($3.3 \times 10^8$) plus 50 forward and back substitutions ($50 \times 10^6$): about $3.8 \times 10^8$ in total, roughly 40 times faster. In SciPy: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lu, piv = scipy.linalg.lu_factor(A)&lt;/code&gt; once, then &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scipy.linalg.lu_solve((lu, piv), b)&lt;/code&gt; for each $b$. This is also why numerical libraries do not compute $A^{-1}$ to solve systems: LU is cheaper and more accurate.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: LU factorization step by step&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Each elimination step writes its multiplier into L; at the end L·U = A is checked.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/phan_ra_lu.html?lang=en&quot; title=&quot;Interactive: LU factorization step by step&quot; loading=&quot;lazy&quot; style=&quot;height: 560px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/phan_ra_lu.html?lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Write the $3 \times 3$ elementary matrix of $R_3 \to R_3 + 5R_1$ and its inverse.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$E = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 0 \\ 5 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$, $E^{-1} = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 0 \\ -5 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Find the LU factorization of $\begin{bmatrix} 1 &amp;amp; 2 \\ 3 &amp;amp; 8 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\ell_{21} = 3$: $L = \begin{bmatrix} 1 &amp;amp; 0 \\ 3 &amp;amp; 1 \end{bmatrix}$, $U = \begin{bmatrix} 1 &amp;amp; 2 \\ 0 &amp;amp; 2 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Find the LU factorization of $\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 \\ 2 &amp;amp; 5 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; 3 \end{bmatrix}$ and use it to solve $Ax = (3, 8, 4)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$L = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 \\ 2 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 1 \end{bmatrix}$, $U = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 2 \end{bmatrix}$. Forward: $y = (3, 2, 2)$. Back: $x_3 = 1$, $x_2 = 1$, $x_1 = 1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; Reuse $L, U$ from Example 1 to solve $Ax = (2, -4, 7)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$y = (2, -8, 1)$; then $x_3 = 1$, $-8x_2 - 2 = -8$ so $x_2 = 3/4$, $2x_1 + 3/4 + 1 = 2$ so $x_1 = 1/8$. Hence $x = (1/8, 3/4, 1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Show that $\begin{bmatrix} 0 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}$ has no factorization $A = LU$ with $L$ lower and $U$ upper triangular, but does have $PA = LU$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

If $A = LU$ then $a_{11} = l_{11} u_{11} = 0$, so $l_{11} = 0$ or $u_{11} = 0$. Then row 1 of $L$ or column 1 of $U$ is zero, forcing row 1 or column 1 of $A$ to be zero, a contradiction. With $P = P_{12}$: $PA = \begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \end{bmatrix} = I \cdot U$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;An elementary row operation = left multiplication by an elementary matrix; every elementary matrix is invertible.&lt;/li&gt;
    &lt;li&gt;Elimination without swaps gives $A = LU$: $L$ records the multipliers, $U$ is the result of elimination.&lt;/li&gt;
    &lt;li&gt;Solve $Ax = b$: forward $Ly = b$, back $Ux = y$, each about $n^2/2$ multiplications.&lt;/li&gt;
    &lt;li&gt;With swaps: $PA = LU$. Factor once, reuse for many right-hand sides.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>The inverse matrix</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter03/03_03_Ma_Tran_Nghich_Dao/"/>
   <updated>2026-01-03T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter03/03_03_Ma_Tran_Nghich_Dao</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;decide whether a square matrix is invertible;&lt;/li&gt;
    &lt;li&gt;compute the inverse of a $2 \times 2$ matrix by formula and of an $n \times n$ matrix by Gauss–Jordan on $[A \mid I]$;&lt;/li&gt;
    &lt;li&gt;use $(AB)^{-1} = B^{-1}A^{-1}$ and $(A^T)^{-1} = (A^{-1})^T$;&lt;/li&gt;
    &lt;li&gt;state the conditions equivalent to “$A$ is invertible”.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;The number equation $3x = 6$ is solved by multiplying both sides by $3^{-1}$. For a system $Ax = b$ we want to do the same: find a matrix $A^{-1}$ with $A^{-1}A = I$, and then $x = A^{-1} b$.&lt;/p&gt;

&lt;p&gt;Geometrically: $A$ transforms the plane, and $A^{-1}$ “plays the film backwards”, sending every point back where it came from. If $A$ squashes the whole plane onto a line, many points land on the same spot and there is no way to run backwards. Then $A$ is not invertible.&lt;/p&gt;

&lt;h2 id=&quot;definition-and-uniqueness&quot;&gt;Definition and uniqueness&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Invertible matrix).&lt;/strong&gt; A square matrix $A$ of order $n$ is &lt;em&gt;invertible&lt;/em&gt; if there is a matrix $B$ of order $n$ with&lt;/p&gt;

\[AB = BA = I_n .\]

  &lt;p&gt;Then $B$ is the &lt;em&gt;inverse&lt;/em&gt; of $A$, written $A^{-1}$. A matrix that is not invertible is &lt;em&gt;singular&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-lemma&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Lemma 1.&lt;/strong&gt; The inverse, if it exists, is unique.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; If $AB = BA = I$ and $AC = CA = I$ then $B = BI = B(AC) = (BA)C = IC = C$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 ($2 \times 2$ inverse).&lt;/strong&gt; The matrix $A = \begin{bmatrix} a &amp;amp; b \\ c &amp;amp; d \end{bmatrix}$ is invertible if and only if $ad - bc \ne 0$, and then&lt;/p&gt;

  &lt;p&gt;\(A^{-1} = \frac{1}{ad - bc} \begin{bmatrix} d &amp;amp; -b \\ -c &amp;amp; a \end{bmatrix}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Multiply directly: $\begin{bmatrix} a &amp;amp; b \\ c &amp;amp; d \end{bmatrix}\begin{bmatrix} d &amp;amp; -b \\ -c &amp;amp; a \end{bmatrix} = (ad - bc) I$, and likewise in the other order. If $ad - bc \ne 0$, dividing by it gives the inverse. If $ad - bc = 0$, the columns $(a, c)$ and $(b, d)$ are parallel (or one is zero), so every $Ax$ lies on one line through the origin. No $B$ can give $AB = I$, because the columns $e_1, e_2$ of $I$ do not lie on one line.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The number $ad - bc$ is the &lt;em&gt;determinant&lt;/em&gt; of $A$. Chapter 04 extends it to order $n$ and explains it as an area ratio.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; $A = \begin{bmatrix} 2 &amp;amp; 1 \\ 5 &amp;amp; 3 \end{bmatrix}$ has $ad - bc = 6 - 5 = 1$, so $A^{-1} = \begin{bmatrix} 3 &amp;amp; -1 \\ -5 &amp;amp; 2 \end{bmatrix}$. Solve $Ax = (1, 2)$: $x = A^{-1}(1, 2) = (3 - 2, -5 + 4) = (1, -1)$. Check: $2 - 1 = 1$, $5 - 3 = 2$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;properties&quot;&gt;Properties&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2.&lt;/strong&gt; Let $A, B$ be invertible of the same order. Then&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$A^{-1}$ is invertible and $(A^{-1})^{-1} = A$;&lt;/li&gt;
    &lt;li&gt;$AB$ is invertible and $(AB)^{-1} = B^{-1} A^{-1}$;&lt;/li&gt;
    &lt;li&gt;$A^T$ is invertible and $(A^T)^{-1} = (A^{-1})^T$.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; (1) The identity $AA^{-1} = A^{-1}A = I$ also says that $A$ is the inverse of $A^{-1}$. (2) $(AB)(B^{-1}A^{-1}) = A(BB^{-1})A^{-1} = AA^{-1} = I$, and similarly $(B^{-1}A^{-1})(AB) = I$. (3) Using $(XY)^T = Y^T X^T$ (Lesson 3.5): $A^T (A^{-1})^T = (A^{-1}A)^T = I^T = I$, and similarly in the other order.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The reversed order in (2) has a geometric reason: you put on socks and then shoes, so to undo you take off the shoes first and then the socks.&lt;/p&gt;

&lt;h2 id=&quot;computing-the-inverse-by-gaussjordan&quot;&gt;Computing the inverse by Gauss–Jordan&lt;/h2&gt;

&lt;p&gt;Finding $A^{-1}$ means solving the $n$ systems $A x_j = e_j$ at once (column $j$ of $A^{-1}$ is $x_j$). Put all $n$ right-hand sides side by side and eliminate once:&lt;/p&gt;

\[[A \mid I] \ \xrightarrow{\text{Gauss–Jordan}}\ [I \mid A^{-1}].\]

&lt;p&gt;If during elimination a zero row appears on the left (i.e. $\operatorname{rank} A &amp;lt; n$), then $A$ is not invertible.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; Find the inverse of $A = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 3 \\ 0 &amp;amp; 1 &amp;amp; 4 \\ 5 &amp;amp; 6 &amp;amp; 0 \end{bmatrix}$.&lt;/p&gt;

\[\left[\begin{array}{rrr|rrr} 1 &amp;amp; 2 &amp;amp; 3 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 4 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0 \\ 5 &amp;amp; 6 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1 \end{array}\right]
\xrightarrow{R_3 \to R_3 - 5R_1}
\left[\begin{array}{rrr|rrr} 1 &amp;amp; 2 &amp;amp; 3 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 4 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; -4 &amp;amp; -15 &amp;amp; -5 &amp;amp; 0 &amp;amp; 1 \end{array}\right]
\xrightarrow{R_3 \to R_3 + 4R_2}
\left[\begin{array}{rrr|rrr} 1 &amp;amp; 2 &amp;amp; 3 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 4 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 &amp;amp; -5 &amp;amp; 4 &amp;amp; 1 \end{array}\right].\]

  &lt;p&gt;Clear above: $R_2 \to R_2 - 4R_3$ gives $(0, 1, 0 \mid 20, -15, -4)$; $R_1 \to R_1 - 3R_3$ gives $(1, 2, 0 \mid 16, -12, -3)$; then $R_1 \to R_1 - 2R_2$ gives $(1, 0, 0 \mid -24, 18, 5)$. Hence&lt;/p&gt;

\[A^{-1} = \begin{bmatrix} -24 &amp;amp; 18 &amp;amp; 5 \\ 20 &amp;amp; -15 &amp;amp; -4 \\ -5 &amp;amp; 4 &amp;amp; 1 \end{bmatrix}.\]

  &lt;p&gt;Check one entry: row 1 of $A$ times column 1 of $A^{-1}$ is $-24 + 40 - 15 = 1$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3 (singular).&lt;/strong&gt; $A = \begin{bmatrix} 1 &amp;amp; 2 \\ 2 &amp;amp; 4 \end{bmatrix}$ has $ad - bc = 0$. Eliminating $[A \mid I]$: $R_2 \to R_2 - 2R_1$ gives the row $(0, 0 \mid -2, 1)$. The left part has a zero row, so $A$ is not invertible. Geometrically: $A$ squashes the plane onto the line $y = 2x$; the points $(2, 0)$ and $(0, 1)$ both go to $(2, 4)$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;the-invertible-matrix-theorem&quot;&gt;The invertible matrix theorem&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 3.&lt;/strong&gt; For a square matrix $A$ of order $n$ the following are equivalent:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$A$ is invertible;&lt;/li&gt;
    &lt;li&gt;$Ax = b$ has a unique solution for every $b$;&lt;/li&gt;
    &lt;li&gt;$Ax = 0$ has only the trivial solution;&lt;/li&gt;
    &lt;li&gt;$\operatorname{rank} A = n$;&lt;/li&gt;
    &lt;li&gt;the reduced echelon form of $A$ is $I_n$;&lt;/li&gt;
    &lt;li&gt;the columns of $A$ are linearly independent;&lt;/li&gt;
    &lt;li&gt;the columns of $A$ span $\mathbb{R}^n$;&lt;/li&gt;
    &lt;li&gt;there is a matrix $B$ with $BA = I$ (one side suffices).&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; (1) ⇒ (2): $x = A^{-1}b$ is a solution, and if $Ax = b$ then multiplying on the left by $A^{-1}$ gives $x = A^{-1}b$. (2) ⇒ (3): take $b = 0$. (3) ⇒ (4): by Lesson 2.4 there are no free variables, hence $n$ pivots. (4) ⇔ (5): a square matrix with $n$ pivots has reduced form $I$. (5) ⇒ (1): Gauss–Jordan on $[A \mid I]$ reaches $[I \mid X]$, so $AX = I$; the elementary operations are invertible (Lesson 3.4 writes them as matrices $E_k$ with $E_k \cdots E_1 A = I$), hence $XA = I$ with $X = E_k \cdots E_1$. (3) ⇔ (6): $Ax = 0$ is $\sum x_j a_j = 0$, exactly the definition of independence. (4) ⇔ (7): $n$ pivots means the last column of $[A \mid b]$ never has a pivot, i.e. every $b$ is in the span of the columns. (1) ⇒ (8) is clear; (8) ⇒ (3): if $Ax = 0$ then $x = BAx = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Condition (8) says that for square matrices a one-sided inverse is automatically two-sided. For non-square matrices this fails.&lt;/p&gt;

&lt;h2 id=&quot;application-the-hill-cipher&quot;&gt;Application: the Hill cipher&lt;/h2&gt;

&lt;p&gt;The Hill cipher (1929) encrypts pairs of letters with a matrix. Number the letters $A = 0, B = 1, \dots, Z = 25$ and compute modulo 26. Choose the key $K = \begin{bmatrix} 3 &amp;amp; 3 \\ 2 &amp;amp; 5 \end{bmatrix}$.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Encrypt “HI” $= (7, 8)$: $K(7, 8) = (45, 54) \equiv (19, 2)$, i.e. “TC”.&lt;/li&gt;
  &lt;li&gt;Decryption needs $K^{-1}$ modulo 26. Here $ad - bc = 9$, and $9 \cdot 3 = 27 \equiv 1$, so $9^{-1} \equiv 3$. The formula of Theorem 1 gives $K^{-1} \equiv 3\begin{bmatrix} 5 &amp;amp; -3 \\ -2 &amp;amp; 3 \end{bmatrix} \equiv \begin{bmatrix} 15 &amp;amp; 17 \\ 20 &amp;amp; 9 \end{bmatrix}$.&lt;/li&gt;
  &lt;li&gt;Check: $K^{-1}(19, 2) = (319, 398) \equiv (7, 8)$, which is “HI”.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A key works only if $ad - bc$ is invertible modulo 26, i.e. coprime to 26. The Hill cipher is no longer secure (a few plaintext–ciphertext pairs reveal $K$ by solving a linear system), but modern block ciphers such as AES still contain a mixing step that multiplies by an invertible matrix.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: the inverse matrix undoes the warp&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag t to watch A⁻¹ bring the warped grid back; try a singular matrix.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=inverse&amp;amp;lang=en&quot; title=&quot;Interactive: the inverse matrix undoes the warp&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=inverse&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-the-inverse-plays-the-film-backwards&quot;&gt;Short video: The inverse plays the film backwards&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/inverse-rewind.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;A drags every point away and A⁻¹ rewinds each one back to where it started. When det A = 0 the plane is squashed onto a line, many points land on top of each other, and there is no way back. Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Find the inverse of $\begin{bmatrix} 4 &amp;amp; 7 \\ 2 &amp;amp; 6 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$ad - bc = 10$, inverse $\dfrac{1}{10}\begin{bmatrix} 6 &amp;amp; -7 \\ -2 &amp;amp; 4 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Find the inverse of $\begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 1 \end{bmatrix}$ by Gauss–Jordan.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\dfrac12 \begin{bmatrix} 1 &amp;amp; 1 &amp;amp; -1 \\ -1 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; -1 &amp;amp; 1 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Prove $(AB)^{-1} = B^{-1}A^{-1}$ and give a $2 \times 2$ example with $(AB)^{-1} \ne A^{-1}B^{-1}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The proof is as in Theorem 2. Example: $A = R$ ($90^\circ$ rotation), $B = S$ (shear) from Lesson 3.2. $B^{-1}A^{-1} = S^{-1}R^{-1}$, whereas $A^{-1}B^{-1} = R^{-1}S^{-1}$ is the inverse of $SR \ne RS$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; For which $k$ is $\begin{bmatrix} 1 &amp;amp; k \\ k &amp;amp; 4 \end{bmatrix}$ singular? Explain geometrically.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$4 - k^2 = 0$, i.e. $k = \pm 2$. Then the two columns are parallel and the matrix squashes the plane onto a line.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Suppose $A^2 - 3A + 2I = 0$. Prove that $A$ is invertible and express $A^{-1}$ in terms of $A$ and $I$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A(3I - A) = 2I$, so $A \cdot \tfrac12(3I - A) = I$. By Theorem 3 (condition 8, applied to one side), $A^{-1} = \tfrac12 (3I - A)$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$A^{-1}$ satisfies $AA^{-1} = A^{-1}A = I$; it is unique if it exists.&lt;/li&gt;
    &lt;li&gt;For $2 \times 2$: invertible if and only if $ad - bc \ne 0$, with an explicit formula.&lt;/li&gt;
    &lt;li&gt;Compute $A^{-1}$ by Gauss–Jordan on $[A \mid I]$.&lt;/li&gt;
    &lt;li&gt;$(AB)^{-1} = B^{-1}A^{-1}$, $(A^T)^{-1} = (A^{-1})^T$.&lt;/li&gt;
    &lt;li&gt;Invertible ⇔ rank $n$ ⇔ $Ax = 0$ has only $0$ ⇔ independent columns ⇔ columns span $\mathbb{R}^n$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Matrix multiplication: four views</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter03/03_02_Nhan_Ma_Tran_Bon_Cach_Nhin/"/>
   <updated>2026-01-03T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter03/03_02_Nhan_Ma_Tran_Bon_Cach_Nhin</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;compute $AB$ in four ways: entries, columns, rows, sum of column–row products;&lt;/li&gt;
    &lt;li&gt;choose the view that fits a given question;&lt;/li&gt;
    &lt;li&gt;explain a matrix product as the composition of two transformations, and why $AB \ne BA$ geometrically.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;In the plane, the $90^\circ$ counterclockwise rotation sends $e_1 = (1, 0)$ to $(0, 1)$ and $e_2 = (0, 1)$ to $(-1, 0)$. The horizontal shear keeps $e_1$ and pushes $e_2$ to $(1, 1)$. Recording the images of $e_1, e_2$ as columns gives two matrices&lt;/p&gt;

\[R = \begin{bmatrix} 0 &amp;amp; -1 \\ 1 &amp;amp; 0 \end{bmatrix}, \qquad S = \begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \end{bmatrix}.\]

&lt;p&gt;Shear then rotate, or rotate then shear: does the unit square land in the same place? With matrices, $RS = \begin{bmatrix} 0 &amp;amp; -1 \\ 1 &amp;amp; 1 \end{bmatrix}$ while $SR = \begin{bmatrix} 1 &amp;amp; -1 \\ 1 &amp;amp; 0 \end{bmatrix}$. The results differ. This lesson explains why a matrix product means “do this, then do that”.&lt;/p&gt;

&lt;h2 id=&quot;view-1-by-entries&quot;&gt;View 1: by entries&lt;/h2&gt;

&lt;p&gt;This is the definition from Lesson 3.1: $(AB)_{ij}$ is the dot product of row $i$ of $A$ with column $j$ of $B$. Use it when you need only a few entries, or for small matrices by hand.&lt;/p&gt;

&lt;h2 id=&quot;view-2-by-columns&quot;&gt;View 2: by columns&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proposition 1 (Columns of a product).&lt;/strong&gt; If $B = [b_1 \ \cdots \ b_p]$ then $AB = [A b_1 \ \cdots \ A b_p]$. Each column of $AB$ is a linear combination of the columns of $A$, with coefficients from the corresponding column of $B$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Entry $i$ of column $j$ of $AB$ is $\sum_k a_{ik} b_{kj}$, which is also entry $i$ of $A b_j$. By Definition 2 of Lesson 2.1, $A b_j = \sum_k b_{kj} a_k$ is a combination of the columns $a_k$ of $A$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Consequence: every column of $AB$ lies in the span of the columns of $A$. Use this view for questions about the &lt;em&gt;column space&lt;/em&gt;, or when solving several systems $Ax = b_j$ at once.&lt;/p&gt;

&lt;h2 id=&quot;view-3-by-rows&quot;&gt;View 3: by rows&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proposition 2 (Rows of a product).&lt;/strong&gt; Row $i$ of $AB$ equals (row $i$ of $A$) times $B$. Each row of $AB$ is a linear combination of the rows of $B$, with coefficients from the corresponding row of $A$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Entry $j$ of row $i$ of $AB$ is $\sum_k a_{ik} b_{kj}$, the $j$-th component of the row vector $\sum_k a_{ik}\,(\text{row } k \text{ of } B)$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Elementary row operations are left multiplications by a matrix (Lesson 3.4) precisely because of this view.&lt;/p&gt;

&lt;h2 id=&quot;view-4-sum-of-columnrow-products&quot;&gt;View 4: sum of column–row products&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proposition 3 (Outer products).&lt;/strong&gt; Let $a_k$ be column $k$ of $A$ and $r_k$ row $k$ of $B$. Then&lt;/p&gt;

\[AB = a_1 r_1 + a_2 r_2 + \cdots + a_n r_n ,\]

  &lt;p&gt;where each $a_k r_k$ (column times row) is an $m \times p$ matrix of rank at most 1.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Entry $(i, j)$ of $a_k r_k$ is $a_{ik} b_{kj}$. Summing over $k$ gives $\sum_k a_{ik} b_{kj} = (AB)_{ij}$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;This view underlies the SVD in Chapter 11: a matrix is written as a sum of rank-1 matrices, and keeping the few largest terms compresses data.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (four ways to the same product).&lt;/strong&gt; $A = \begin{bmatrix} 1 &amp;amp; 2 \\ 3 &amp;amp; 4 \end{bmatrix}$, $B = \begin{bmatrix} 5 &amp;amp; 6 \\ 7 &amp;amp; 8 \end{bmatrix}$.&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;Entries: $(AB)_{11} = 1\cdot5 + 2\cdot7 = 19$, $(AB)_{12} = 22$, $(AB)_{21} = 43$, $(AB)_{22} = 50$.&lt;/li&gt;
    &lt;li&gt;Columns: column 1 of $AB$ is $5(1, 3) + 7(2, 4) = (19, 43)$.&lt;/li&gt;
    &lt;li&gt;Rows: row 2 of $AB$ is $3(5, 6) + 4(7, 8) = (43, 50)$.&lt;/li&gt;
    &lt;li&gt;Column–row:&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;\(\begin{bmatrix} 1 \\ 3 \end{bmatrix}\begin{bmatrix} 5 &amp;amp; 6 \end{bmatrix} + \begin{bmatrix} 2 \\ 4 \end{bmatrix}\begin{bmatrix} 7 &amp;amp; 8 \end{bmatrix} = \begin{bmatrix} 5 &amp;amp; 6 \\ 15 &amp;amp; 18 \end{bmatrix} + \begin{bmatrix} 14 &amp;amp; 16 \\ 28 &amp;amp; 32 \end{bmatrix} = \begin{bmatrix} 19 &amp;amp; 22 \\ 43 &amp;amp; 50 \end{bmatrix}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;matrix-multiplication-is-composition&quot;&gt;Matrix multiplication is composition&lt;/h2&gt;

&lt;p&gt;Each $m \times n$ matrix $A$ gives a transformation $x \mapsto Ax$ from $\mathbb{R}^n$ to $\mathbb{R}^m$. Column $j$ of $A$ is the image of $e_j$ (the vector with 1 in position $j$): $A e_j = a_j$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Product is composition).&lt;/strong&gt; For every $x$, $(AB)x = A(Bx)$. Applying $AB$ to $x$ is the same as applying $B$ first, then $A$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; View $x$ as a one-column matrix and use associativity (Theorem 1, Lesson 3.1).&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Mind the order: in $AB$, the transformation $B$ stands on the right and acts &lt;strong&gt;first&lt;/strong&gt;. Read from right to left, as in a composition $f(g(x))$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (the opening example as pictures).&lt;/strong&gt; $RS$ is shear first, rotation second. The unit square is sheared into the parallelogram with vertices $(1, 0), (2, 1), (1, 1)$, then rotated by $90^\circ$: the columns of $RS$ are $R(1, 0) = (0, 1)$ and $R(1, 1) = (-1, 1)$.&lt;/p&gt;

  &lt;p&gt;$SR$ is rotation first, shear second. The square is rotated to the square with sides $(0, 1)$ and $(-1, 0)$, then sheared horizontally: $S(0, 1) = (1, 1)$ and $S(-1, 0) = (-1, 0)$. The final parallelogram leans the other way. The two operations cannot be swapped, so $RS \ne SR$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3 (two rotations).&lt;/strong&gt; The rotation by angle $\alpha$ has matrix $R_\alpha = \begin{bmatrix} \cos\alpha &amp;amp; -\sin\alpha \\ \sin\alpha &amp;amp; \cos\alpha \end{bmatrix}$. Rotating by $\beta$ and then by $\alpha$ is rotating by $\alpha + \beta$, so $R_\alpha R_\beta = R_{\alpha+\beta}$. Multiplying out and comparing entry $(1, 1)$:&lt;/p&gt;

\[\cos\alpha\cos\beta - \sin\alpha\sin\beta = \cos(\alpha + \beta).\]

  &lt;p&gt;The trigonometric addition formula is a matrix product. Here $R_\alpha R_\beta = R_\beta R_\alpha$: rotations about the same origin commute.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-neural-networks-and-the-chain-rule&quot;&gt;Application: neural networks and the chain rule&lt;/h2&gt;

&lt;p&gt;A two-layer linear neural network computes $y = W_2 (W_1 x)$. By Theorem 1 this equals a single layer with matrix $W = W_2 W_1$. That is why deep networks need nonlinear activations between layers; otherwise extra layers add no power. During training, the derivative of a composition of transformations is a product of Jacobian matrices (the chain rule in the Calculus course), and deep-learning libraries evaluate these products right-to-left or left-to-right depending on cost.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: four views of matrix multiplication&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Pick a view: row · column, by columns, by rows, or a sum of column × row products.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/phep_toan_ma_tran.html?mode=mul&amp;amp;lang=en&quot; title=&quot;Interactive: four views of matrix multiplication&quot; loading=&quot;lazy&quot; style=&quot;height: 560px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/phep_toan_ma_tran.html?mode=mul&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: multiplying matrices composes two maps&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Apply B, then A to the plane; compare AB and BA.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=compose&amp;amp;lang=en&quot; title=&quot;Interactive: multiplying matrices composes two maps&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/bien_doi_luoi.html?mode=compose&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-matrix-multiplication-is-composition&quot;&gt;Short video: Matrix multiplication is composition&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/composition-grid.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;A shear A followed by a rotation B is exactly the single matrix BA; swap the order and the flag lands elsewhere, so AB ≠ BA. Each column of BA is B times a column of A. Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Compute column 2 of $AB$ for $A = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 2 \\ 0 &amp;amp; 1 &amp;amp; -1 \end{bmatrix}$, $B = \begin{bmatrix} 1 &amp;amp; 3 \\ 2 &amp;amp; 0 \\ 0 &amp;amp; 1 \end{bmatrix}$ using only the column view.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$3(1, 0) + 0(0, 1) + 1(2, -1) = (5, -1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Write $\begin{bmatrix} 2 &amp;amp; 4 \\ 3 &amp;amp; 6 \end{bmatrix}$ as a column times a row.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\begin{bmatrix} 2 \\ 3 \end{bmatrix}\begin{bmatrix} 1 &amp;amp; 2 \end{bmatrix}$. The matrix has rank 1.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; The reflection across the $x$-axis is $F = \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; -1 \end{bmatrix}$. Compute $FR$ and $RF$ with $R$ the $90^\circ$ rotation. Which geometric transformation is each product?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$FR = \begin{bmatrix} 0 &amp;amp; -1 \\ -1 &amp;amp; 0 \end{bmatrix}$: reflection across the line $y = -x$. $RF = \begin{bmatrix} 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix}$: reflection across the line $y = x$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; Prove: if $B$ has a zero column then $AB$ has that column zero; if $A$ has a zero row then $AB$ has that row zero.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Columns: column $j$ of $AB$ is $A b_j = A\,0 = 0$. Rows: row $i$ of $AB$ is (row $i$ of $A$)$B = 0 B = 0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced / programming).&lt;/strong&gt; For two random $500 \times 500$ matrices in NumPy, compare the time of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A @ B&lt;/code&gt; with a triple Python loop following the definition. Why is the gap so large although the number of multiplications is the same?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

`A @ B` takes milliseconds; the Python loop takes tens of seconds. BLAS libraries organise the work in blocks that fit the cache, use the CPU&apos;s vector instructions and several cores; the cost of the Python loop is in the interpreter, not in the multiplications.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Entries: row times column. Columns: $AB = [Ab_1 \cdots Ab_p]$. Rows: rows of $AB$ are combinations of rows of $B$. Column–row: $AB = \sum_k a_k r_k$, a sum of rank-1 matrices.&lt;/li&gt;
    &lt;li&gt;Column $j$ of $A$ is the image of $e_j$.&lt;/li&gt;
    &lt;li&gt;$(AB)x = A(Bx)$: a product is a composition, $B$ first then $A$; order matters, so $AB \ne BA$ in general.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Matrix operations</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter03/03_01_Cac_Phep_Toan_Tren_Ma_Tran/"/>
   <updated>2026-01-03T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter03/03_01_Cac_Phep_Toan_Tren_Ma_Tran</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;add two matrices, multiply a matrix by a number, multiply two matrices and take a transpose;&lt;/li&gt;
    &lt;li&gt;check the sizes of two matrices to see whether their product is defined and what size it has;&lt;/li&gt;
    &lt;li&gt;use associativity and distributivity of matrix multiplication, and know that it is not commutative.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;A class has three students. Their attendance, midterm and final scores form the table&lt;/p&gt;

\[G = \begin{bmatrix} 8 &amp;amp; 7 &amp;amp; 9 \\ 6 &amp;amp; 9 &amp;amp; 7 \\ 10 &amp;amp; 8 &amp;amp; 6 \end{bmatrix}\]

&lt;p&gt;(each row is a student). The weights of the three score columns are $20\%$, $30\%$, $50\%$, recorded as the vector $w = (0.2, 0.3, 0.5)$. The first student’s final grade is $8 \cdot 0.2 + 7 \cdot 0.3 + 9 \cdot 0.5 = 8.2$, the dot product of row 1 with $w$. Doing this for all three rows is computing $Gw = (8.2,\ 7.4,\ 7.4)$.&lt;/p&gt;

&lt;p&gt;If the department wants to try a second grading scheme, we put the two weight vectors as the two columns of a matrix $W$ and compute $GW$ at once. That is the product of two matrices.&lt;/p&gt;

&lt;h2 id=&quot;matrices-and-simple-operations&quot;&gt;Matrices and simple operations&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Matrix).&lt;/strong&gt; An &lt;em&gt;$m \times n$ matrix&lt;/em&gt; is a table of numbers with $m$ rows and $n$ columns. The entry in row $i$, column $j$ of $A$ is written $a_{ij}$ or $(A)_{ij}$. Two matrices are equal when they have the same size and all corresponding entries are equal. An $n \times n$ matrix is a &lt;em&gt;square matrix of order $n$&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 2 (Addition and scalar multiplication).&lt;/strong&gt; For $A, B$ of the same size $m \times n$ and a number $c$:&lt;/p&gt;

\[(A + B)_{ij} = a_{ij} + b_{ij}, \qquad (cA)_{ij} = c\, a_{ij}.\]

  &lt;p&gt;The zero matrix $0$ has all entries 0. The &lt;em&gt;identity matrix&lt;/em&gt; $I_n$ is the square matrix of order $n$ with 1 on the main diagonal and 0 elsewhere.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Both operations act entry by entry, as for vectors. So they satisfy exactly the eight properties of Theorem 1, Lesson 1.1. An $m \times n$ matrix can be viewed as a vector with $mn$ components.&lt;/p&gt;

&lt;h2 id=&quot;multiplying-two-matrices&quot;&gt;Multiplying two matrices&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 3 (Matrix product).&lt;/strong&gt; Let $A$ be $m \times n$ and $B$ be $n \times p$. The product $AB$ is the $m \times p$ matrix with&lt;/p&gt;

\[(AB)_{ij} = a_{i1} b_{1j} + a_{i2} b_{2j} + \cdots + a_{in} b_{nj} = \sum_{k=1}^{n} a_{ik} b_{kj} .\]

  &lt;p&gt;In words, entry $(i, j)$ of $AB$ is the dot product of row $i$ of $A$ with column $j$ of $B$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The product is defined only when &lt;strong&gt;the number of columns of $A$ equals the number of rows of $B$&lt;/strong&gt;. Mnemonic: $(m \times n)(n \times p) = (m \times p)$; the two inner numbers must agree and “cancel”.&lt;/p&gt;

&lt;p&gt;For $p = 1$, $B$ is a column vector and $AB$ is the matrix–vector product of Lesson 2.1. Moreover, column $j$ of $AB$ is $A$ times column $j$ of $B$: $AB = [A b_1 \ \cdots \ A b_p]$. Lesson 3.2 builds on this.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; Let $C = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 2 \\ -1 &amp;amp; 3 &amp;amp; 1 \end{bmatrix}$ ($2 \times 3$) and $D = \begin{bmatrix} 3 &amp;amp; 1 \\ 2 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix}$ ($3 \times 2$). Then $CD$ is $2 \times 2$:&lt;/p&gt;

\[CD = \begin{bmatrix} 1\cdot3 + 0\cdot2 + 2\cdot1 &amp;amp; 1\cdot1 + 0 + 0 \\ -3 + 6 + 1 &amp;amp; -1 + 3 + 0 \end{bmatrix} = \begin{bmatrix} 5 &amp;amp; 1 \\ 4 &amp;amp; 2 \end{bmatrix},\]

  &lt;p&gt;while $DC$ is $3 \times 3$:&lt;/p&gt;

\[DC = \begin{bmatrix} 2 &amp;amp; 3 &amp;amp; 7 \\ 1 &amp;amp; 3 &amp;amp; 5 \\ 1 &amp;amp; 0 &amp;amp; 2 \end{bmatrix}.\]

  &lt;p&gt;$CD$ and $DC$ do not even have the same size.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (not commutative).&lt;/strong&gt; With $A = \begin{bmatrix} 1 &amp;amp; 2 \\ 3 &amp;amp; 4 \end{bmatrix}$ and $B = \begin{bmatrix} 5 &amp;amp; 6 \\ 7 &amp;amp; 8 \end{bmatrix}$:&lt;/p&gt;

\[AB = \begin{bmatrix} 19 &amp;amp; 22 \\ 43 &amp;amp; 50 \end{bmatrix}, \qquad BA = \begin{bmatrix} 23 &amp;amp; 34 \\ 31 &amp;amp; 46 \end{bmatrix}.\]

  &lt;p&gt;Both are square of the same order, yet $AB \ne BA$. Lesson 3.2 explains this geometrically: multiplying matrices means performing two transformations one after the other, and the order matters.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Properties of the product).&lt;/strong&gt; For matrices of compatible sizes and a number $c$:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$(AB)C = A(BC)$ (associativity);&lt;/li&gt;
    &lt;li&gt;$A(B + C) = AB + AC$ and $(A + B)C = AC + BC$ (distributivity);&lt;/li&gt;
    &lt;li&gt;$c(AB) = (cA)B = A(cB)$;&lt;/li&gt;
    &lt;li&gt;$I_m A = A = A I_n$ for $A$ of size $m \times n$.&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;In general $AB \ne BA$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; We prove associativity; the other properties are checked directly from the definition. Entry $(i, l)$ of $(AB)C$ is&lt;/p&gt;

\[\sum_{j} (AB)_{ij} c_{jl} = \sum_j \sum_k a_{ik} b_{kj} c_{jl},\]

  &lt;p&gt;and entry $(i, l)$ of $A(BC)$ is $\sum_k a_{ik} (BC)_{kl} = \sum_k \sum_j a_{ik} b_{kj} c_{jl}$. Both double sums contain the same terms in a different order, so they are equal.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;content-box warning-box textbook-block&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Warning.&lt;/strong&gt; Two familiar facts about real numbers fail for matrices:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$AB = 0$ does not imply $A = 0$ or $B = 0$. For example $\begin{bmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bmatrix}\begin{bmatrix} 1 &amp;amp; -1 \\ -1 &amp;amp; 1 \end{bmatrix} = 0$.&lt;/li&gt;
    &lt;li&gt;$(A + B)^2 = A^2 + AB + BA + B^2$, which differs from $A^2 + 2AB + B^2$ when $AB \ne BA$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;h2 id=&quot;transpose&quot;&gt;Transpose&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 4 (Transpose).&lt;/strong&gt; The &lt;em&gt;transpose&lt;/em&gt; of an $m \times n$ matrix $A$ is the $n \times m$ matrix $A^T$ with $(A^T)_{ij} = a_{ji}$: the rows of $A$ become the columns of $A^T$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;For $C$ in Example 1, $C^T = \begin{bmatrix} 1 &amp;amp; -1 \\ 0 &amp;amp; 3 \\ 2 &amp;amp; 1 \end{bmatrix}$. The dot product can be written with a transpose: $x \cdot y = x^T y$ for column vectors $x, y$. The properties of the transpose, including $(AB)^T = B^T A^T$, are in Lesson 3.5.&lt;/p&gt;

&lt;h2 id=&quot;application-grade-sheets-and-recommender-systems&quot;&gt;Application: grade sheets and recommender systems&lt;/h2&gt;

&lt;p&gt;Back to the opening example. Suppose the department tries two grading schemes: the old $w_1 = (0.2, 0.3, 0.5)$ and the new $w_2 = (0.1, 0.4, 0.5)$. Put them together as $W = [w_1 \ w_2]$ of size $3 \times 2$. The $3 \times 2$ product $GW$ gives the grades of 3 students under both schemes in one computation.&lt;/p&gt;

&lt;p&gt;Movie recommender systems use the same idea at scale: a “user × feature” matrix (how much someone likes action, comedy, …) times a “feature × movie” matrix gives a “user × movie” matrix of predicted preferences. A fully connected layer in a neural network is also a matrix product (see the Deep Learning course, Chapter 02).&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: matrix operations&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Edit A and B; pick A + B, k·A, Aᵀ or A·B and hover over a result entry.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter03/phep_toan_ma_tran.html?mode=add&amp;amp;lang=en&quot; title=&quot;Interactive: matrix operations&quot; loading=&quot;lazy&quot; style=&quot;height: 560px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter03/phep_toan_ma_tran.html?mode=add&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; With $C, D$ from Example 1, compute $2C - D^T$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$D^T = \begin{bmatrix} 3 &amp;amp; 2 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 0 \end{bmatrix}$, so $2C - D^T = \begin{bmatrix} -1 &amp;amp; -2 &amp;amp; 3 \\ -3 &amp;amp; 5 &amp;amp; 2 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; $A$ is $2 \times 3$, $B$ is $3 \times 4$, $C$ is $4 \times 2$. Which products are defined and what are their sizes: $AB$, $BA$, $ABC$, $CA$, $BC$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$AB$: $2 \times 4$. $BA$: undefined. $ABC$: $2 \times 2$. $CA$: $4 \times 3$. $BC$: $3 \times 2$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Find all matrices $X = \begin{bmatrix} a &amp;amp; b \\ c &amp;amp; d \end{bmatrix}$ that commute with $J = \begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \end{bmatrix}$, i.e. $XJ = JX$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$XJ = \begin{bmatrix} a &amp;amp; a + b \\ c &amp;amp; c + d \end{bmatrix}$, $JX = \begin{bmatrix} a + c &amp;amp; b + d \\ c &amp;amp; d \end{bmatrix}$. Comparing: $c = 0$, $a = d$. So $X = \begin{bmatrix} a &amp;amp; b \\ 0 &amp;amp; a \end{bmatrix} = aI + bN$ with $N = \begin{bmatrix} 0 &amp;amp; 1 \\ 0 &amp;amp; 0 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; Compute $GW$ from the application. Which student benefits from the new scheme?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Column 1: $(8.2, 7.4, 7.4)$. Column 2: $(0.8 + 2.8 + 4.5, \ 0.6 + 3.6 + 3.5, \ 1.0 + 3.2 + 3.0) = (8.1, 7.7, 7.2)$. The second student benefits (high midterm score).

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Let $N = \begin{bmatrix} 0 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 0 \end{bmatrix}$. Compute $N^2$, $N^3$. Deduce $(I + N)^{k}$ for every $k \ge 2$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$N^2$ has a single 1 at position $(1, 3)$; $N^3 = 0$. Since $I$ commutes with $N$, the binomial expansion applies: $(I + N)^k = I + kN + \binom{k}{2} N^2$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Addition and scalar multiplication act entry by entry.&lt;/li&gt;
    &lt;li&gt;$(AB)_{ij}$ = row $i$ of $A$ dotted with column $j$ of $B$; sizes must be $(m \times n)(n \times p)$.&lt;/li&gt;
    &lt;li&gt;The product is associative, distributive, has identity $I$, but is not commutative, and $AB = 0$ does not force $A = 0$ or $B = 0$.&lt;/li&gt;
    &lt;li&gt;The transpose turns rows into columns; $x \cdot y = x^T y$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Sai số làm tròn và chọn phần tử chốt</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter02/02_06_Sai_So_Lam_Tron_Va_Chon_Phan_Tu_Chot/"/>
   <updated>2026-01-02T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter02/02_06_Sai_So_Lam_Tron_Va_Chon_Phan_Tu_Chot</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;giải thích vì sao phần tử chốt rất nhỏ làm khử Gauss trên máy cho kết quả sai;&lt;/li&gt;
    &lt;li&gt;thực hiện khử Gauss với &lt;em&gt;chọn chốt từng phần&lt;/em&gt; (partial pivoting);&lt;/li&gt;
    &lt;li&gt;phân biệt lỗi do thuật toán (chọn chốt kém) với lỗi do bản thân bài toán (ma trận có số điều kiện lớn).&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Máy tính không lưu được mọi số thực. Kiểu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float64&lt;/code&gt; giữ khoảng 16 chữ số có nghĩa; mọi phép tính đều được làm tròn về số gần nhất lưu được. Thường thì sai số này rất nhỏ. Nhưng thử hệ&lt;/p&gt;

\[10^{-20} x + y = 1, \qquad x + y = 2 .\]

&lt;p&gt;Nghiệm đúng là $x = \dfrac{1}{1 - 10^{-20}} \approx 1$, $y \approx 1$. Khử Gauss theo đúng thứ tự (chốt $10^{-20}$) trên NumPy cho $x = 0$, $y = 1$. Đổi chỗ hai phương trình trước rồi mới khử thì được $x = 1$, $y = 1$. Cùng một thuật toán, chỉ khác thứ tự hàng, mà một đáp số sai hoàn toàn.&lt;/p&gt;

&lt;h2 id=&quot;số-thực-dấu-phẩy-động&quot;&gt;Số thực dấu phẩy động&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Làm tròn với $t$ chữ số).&lt;/strong&gt; Trong số học dấu phẩy động với $t$ chữ số có nghĩa, mỗi số thực $a$ được thay bằng số gần nhất $\operatorname{fl}(a)$ có dạng $\pm d_1.d_2\ldots d_t \times 10^e$. Sai số tương đối thoả $\lvert \operatorname{fl}(a) - a \rvert \le u\,\lvert a \rvert$ với $u = \tfrac12 10^{1-t}$, gọi là &lt;em&gt;đơn vị làm tròn&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float64&lt;/code&gt; (cơ số 2), $u \approx 1.1 \times 10^{-16}$. Hệ quả quan trọng: cộng một số nhỏ vào một số rất lớn có thể không làm đổi gì. Trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float64&lt;/code&gt;, $10^{20} - 1$ được làm tròn thành đúng $10^{20}$.&lt;/p&gt;

&lt;h2 id=&quot;phân-tích-ví-dụ&quot;&gt;Phân tích ví dụ&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (tính tay với 3 chữ số).&lt;/strong&gt; Hệ $0.0001\,x + y = 1$, $x + y = 2$; nghiệm đúng $x \approx 1.0001$, $y \approx 0.9999$. Làm tròn mọi kết quả trung gian về 3 chữ số có nghĩa.&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;Không đổi hàng.&lt;/em&gt; Hệ số nhân $\ell = 1 / 0.0001 = 10^4$. Hàng hai trở thành&lt;/p&gt;

\[(1 - 10^4)\, y = 2 - 10^4 \quad\Longrightarrow\quad -1.00\times 10^4\, y = -1.00 \times 10^4 ,\]

  &lt;p&gt;vì cả $-9999$ và $-9998$ đều làm tròn thành $-1.00 \times 10^4$. Vậy $y = 1$, rồi $x = (1 - y)/0.0001 = 0$. Thông tin “2” ở vế phải của phương trình hai đã bị nuốt mất trong phép trừ với $10^4$.&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;Đổi hàng trước.&lt;/em&gt; Chốt là $1$, hệ số nhân $\ell = 0.0001$. Hàng hai: $(1 - 0.0001)\, y = 1 - 0.0002$, làm tròn thành $1.00\, y = 1.00$. Vậy $y = 1$, $x = 2 - y = 1$. Sai số chỉ ở chữ số thứ tư, đúng mức độ chính xác của số học 3 chữ số.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Hình học: hai đường thẳng $0.0001x + y = 1$ và $x + y = 2$ cắt nhau rõ ràng, góc giữa chúng gần $45^\circ$. Bài toán không khó. Cái khó là do thuật toán chọn một phần tử chốt quá nhỏ, nên hệ số nhân quá lớn và làm khuếch đại sai số làm tròn.&lt;/p&gt;

&lt;h2 id=&quot;chọn-chốt-từng-phần&quot;&gt;Chọn chốt từng phần&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 2 (Chọn chốt từng phần).&lt;/strong&gt; Ở mỗi bước khử cột $k$, chọn trong các hàng từ $k$ trở xuống hàng có $\lvert a_{ik} \rvert$ lớn nhất, đổi hàng đó lên vị trí $k$, rồi mới khử.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Mệnh đề 1.&lt;/strong&gt; Với chọn chốt từng phần, mọi hệ số nhân $\ell_{ik} = a_{ik}/a_{kk}$ thoả $\lvert \ell_{ik} \rvert \le 1$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Sau khi đổi hàng, $\lvert a_{kk} \rvert \ge \lvert a_{ik} \rvert$ với mọi $i &amp;gt; k$, nên $\lvert a_{ik} / a_{kk} \rvert \le 1$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Hệ số nhân bị chặn bởi 1 nghĩa là mỗi bước khử không phóng đại các số trong ma trận quá nhiều. Trong thực tế, khử Gauss có chọn chốt từng phần ổn định với gần như mọi ma trận gặp phải; nó là thuật toán chạy bên trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.solve&lt;/code&gt; (qua thư viện LAPACK).&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; Khử có chọn chốt cho ma trận mở rộng&lt;/p&gt;

\[\left[\begin{array}{rr|r} 1 &amp;amp; 2 &amp;amp; 3 \\ 3 &amp;amp; 1 &amp;amp; 4 \end{array}\right].\]

  &lt;p&gt;Ở cột 1, $\lvert 3 \rvert &amp;gt; \lvert 1 \rvert$, nên đổi hàng: $(3, 1 \mid 4)$ lên trên. Hệ số nhân $\ell = 1/3$: hàng hai thành $(0, \tfrac53 \mid \tfrac53)$. Thế ngược: $y = 1$, $x = 1$. Tính tay không cần chọn chốt, nhưng thói quen này giúp đọc hiểu mã nguồn thư viện.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;khi-lỗi-nằm-ở-bài-toán-số-điều-kiện&quot;&gt;Khi lỗi nằm ở bài toán: số điều kiện&lt;/h2&gt;

&lt;p&gt;Chọn chốt chữa được lỗi do thuật toán. Nó không chữa được bài toán vốn nhạy cảm. Nếu hai đường thẳng gần như song song, một thay đổi nhỏ của vế phải làm giao điểm chạy rất xa. Mức độ nhạy này đo bằng &lt;em&gt;số điều kiện&lt;/em&gt; $\kappa(A)$, sẽ định nghĩa chính xác ở Chương 11 qua các giá trị kỳ dị. Quy tắc kinh nghiệm: giải $Ax = b$ trên &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float64&lt;/code&gt; mất khoảng $\log_{10}\kappa(A)$ chữ số chính xác trong 16 chữ số.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3 (ma trận Hilbert).&lt;/strong&gt; Ma trận Hilbert $H_{ij} = \dfrac{1}{i + j - 1}$ cỡ $10 \times 10$ có $\kappa(H) \approx 1.6 \times 10^{13}$. Lấy $x = (1, \dots, 1)$, tính $b = Hx$, rồi giải lại $Hx = b$ bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.solve&lt;/code&gt; (có chọn chốt): sai số lớn nhất khoảng $2 \times 10^{-4}$. Mất khoảng 13 chữ số, đúng như dự đoán.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-mô-phỏng-kỹ-thuật&quot;&gt;Ứng dụng: mô phỏng kỹ thuật&lt;/h2&gt;

&lt;p&gt;Phần mềm phần tử hữu hạn (tính độ bền cầu, khung nhà, cánh máy bay) giải các hệ với hàng triệu ẩn. Kỹ sư cần biết hai điều từ bài này: thư viện đã chọn chốt để tránh lỗi thuật toán, và nếu kết quả vẫn dao động mạnh khi đổi dữ liệu rất ít, thì vấn đề nằm ở mô hình (số điều kiện lớn, ví dụ một thanh dầm gần như không được giữ), không phải ở máy tính.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: sai số làm tròn và chọn phần tử chốt&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Làm tròn 3 chữ số với chốt 0,0001 cho nghiệm sai; bật “chọn phần tử chốt lớn nhất” để sửa.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter02/khu_gauss.html?preset=round&quot; title=&quot;Minh hoạ: sai số làm tròn và chọn phần tử chốt&quot; loading=&quot;lazy&quot; style=&quot;height: 680px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter02/khu_gauss.html?preset=round&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-phần-tử-chốt-nhỏ-làm-hỏng-phép-khử&quot;&gt;Video ngắn: Phần tử chốt nhỏ làm hỏng phép khử&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/pivot-rounding.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Với 3 chữ số có nghĩa, khử bằng chốt 0,0001 làm hệ số nhân thành 10 000 và nghiệm x sai hẳn 1 đơn vị. Đổi hàng để chọn chốt lớn nhất thì nghiệm đúng trở lại. Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Trong số học 3 chữ số, tính $\operatorname{fl}(1000 + 0.4)$ và $\operatorname{fl}(\operatorname{fl}(1000 + 0.4) - 1000)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$1000.4$ làm tròn thành $1.00 \times 10^3$; hiệu bằng $0$. Phần $0.4$ đã mất.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Với chọn chốt từng phần, hàng nào được chọn làm chốt ở cột 1 của ma trận có cột đầu $(2, -7, 5)$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Hàng 2, vì $\lvert -7 \rvert$ lớn nhất.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Giải $0.001\,x + y = 1$, $x - y = 0$ trong số học 3 chữ số, lần lượt không đổi hàng và có đổi hàng. So với nghiệm đúng $x = y = 1/1.001 \approx 0.999$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Không đổi hàng: $\ell = 1000$, hàng hai $-1.00\times10^3\, y = -1.00 \times 10^3$, $y = 1$, $x = (1 - 1)/0.001 = 0$, sai hoàn toàn. Có đổi hàng: $\ell = 0.001$, hàng hai $1.00\, y = 1.00$, $y = 1$, $x = 1$, sai ở chữ số thứ ba.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Giải thích vì sao trong Ví dụ 1 việc làm tròn ở hàng hai &lt;em&gt;không&lt;/em&gt; gây hại khi đã đổi hàng, dù vẫn có làm tròn.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Hệ số nhân $0.0001$ nhỏ, nên hàng hai chỉ bị sửa một lượng rất nhỏ. Sai số làm tròn ở mức $10^{-3}$ của các số cỡ $1$, đúng bằng độ chính xác sẵn có; nó không bị khuếch đại.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao / lập trình).&lt;/strong&gt; Cài đặt khử Gauss có và không có chọn chốt trong khoảng 20 dòng NumPy. So sánh với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.solve&lt;/code&gt; trên hệ ở ví dụ mở đầu và trên ma trận Hilbert $8 \times 8$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Không chọn chốt: hệ mở đầu cho $x = 0$. Có chọn chốt: $x = 1$, trùng `solve`. Với Hilbert $8 \times 8$ ($\kappa \approx 1.5 \times 10^{10}$) cả ba cách đều mất khoảng 10 chữ số: đó là giới hạn của bài toán, không phải của thuật toán.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Máy tính làm tròn mọi phép tính; cộng số nhỏ vào số rất lớn có thể làm mất số nhỏ.&lt;/li&gt;
    &lt;li&gt;Chốt nhỏ cho hệ số nhân lớn, khuếch đại sai số làm tròn.&lt;/li&gt;
    &lt;li&gt;Chọn chốt từng phần (đổi lên hàng có $\lvert a_{ik} \rvert$ lớn nhất) giữ $\lvert \ell_{ik} \rvert \le 1$ và là chuẩn trong mọi thư viện.&lt;/li&gt;
    &lt;li&gt;Ma trận có số điều kiện lớn vẫn cho nghiệm kém chính xác; đó là tính chất của bài toán.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Hệ thuần nhất và nghiệm tổng quát</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter02/02_05_He_Thuan_Nhat_Va_Nghiem_Tong_Quat/"/>
   <updated>2026-01-02T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter02/02_05_He_Thuan_Nhat_Va_Nghiem_Tong_Quat</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;giải hệ thuần nhất $Ax = 0$ và viết tập nghiệm dưới dạng span của các vectơ cụ thể;&lt;/li&gt;
    &lt;li&gt;viết nghiệm tổng quát của $Ax = b$ dưới dạng nghiệm riêng cộng nghiệm của hệ thuần nhất;&lt;/li&gt;
    &lt;li&gt;chứng minh hệ thuần nhất có nhiều ẩn hơn phương trình luôn có nghiệm khác không;&lt;/li&gt;
    &lt;li&gt;giải thích cấu trúc tập nghiệm bằng hình học: một tập con qua gốc được tịnh tiến đi.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Ở Bài 2.4, hệ $x + 3y + z = 9$, $x + y - z = 1$, $3x + 11y + 5z = 35$ có nghiệm&lt;/p&gt;

\[(x, y, z) = (-3, 4, 0) + t\,(2, -1, 1).\]

&lt;p&gt;Thử thay vectơ $(2, -1, 1)$ vào vế trái: $2 - 3 + 1 = 0$, $2 - 1 - 1 = 0$, $6 - 11 + 5 = 0$. Nó là nghiệm của hệ có cùng vế trái nhưng &lt;em&gt;vế phải bằng 0&lt;/em&gt;. Còn $(-3, 4, 0)$ là một nghiệm của hệ ban đầu. Nghiệm tổng quát là “một nghiệm cộng mọi nghiệm của hệ thuần nhất”. Bài này chứng minh điều đó luôn đúng.&lt;/p&gt;

&lt;h2 id=&quot;hệ-thuần-nhất&quot;&gt;Hệ thuần nhất&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Hệ thuần nhất).&lt;/strong&gt; Hệ $Ax = 0$ gọi là &lt;em&gt;hệ thuần nhất&lt;/em&gt;. Nó luôn có &lt;em&gt;nghiệm tầm thường&lt;/em&gt; $x = 0$. Tập nghiệm của nó gọi là &lt;em&gt;không gian nghiệm&lt;/em&gt; hay &lt;em&gt;hạt nhân&lt;/em&gt; của $A$, ký hiệu $\operatorname{Nul} A$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Nếu $u, v \in \operatorname{Nul} A$ và $c$ là số thực thì $u + v \in \operatorname{Nul} A$ và $c\,u \in \operatorname{Nul} A$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; $A(u + v) = Au + Av = 0 + 0 = 0$ và $A(cu) = c\,Au = 0$, dùng tính chất $A(cx + dy) = c\,Ax + d\,Ay$ của Bài 2.1.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Như vậy $\operatorname{Nul} A$ chứa $0$ và đóng với hai phép toán: đó là một không gian con. Cách khử Gauss cho thấy nó luôn là span của một số vectơ cụ thể.&lt;/p&gt;

&lt;h3 id=&quot;cách-viết-operatornamenul-a-thành-span&quot;&gt;Cách viết $\operatorname{Nul} A$ thành span&lt;/h3&gt;

&lt;p&gt;Đưa $A$ về dạng bậc thang rút gọn. Mỗi biến chốt được biểu diễn qua các biến tự do. Viết nghiệm thành tổng, mỗi biến tự do nhân với một vectơ. Các vectơ đó sinh ra $\operatorname{Nul} A$, và số vectơ bằng số biến tự do, tức $n - \operatorname{rank} A$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Cho&lt;/p&gt;

\[A = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 1 &amp;amp; 1 \\ 2 &amp;amp; 4 &amp;amp; 3 &amp;amp; 4 \\ 1 &amp;amp; 2 &amp;amp; 2 &amp;amp; 3 \end{bmatrix}
\quad\longrightarrow\quad
\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 &amp;amp; -1 \\ 0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 2 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \end{bmatrix}.\]

  &lt;p&gt;Cột chốt là cột 1 và 3; biến tự do là $x_2 = s$, $x_4 = t$. Từ hai hàng: $x_1 = -2s + t$, $x_3 = -2t$. Vậy&lt;/p&gt;

\[x = s \begin{bmatrix} -2 \\ 1 \\ 0 \\ 0 \end{bmatrix} + t \begin{bmatrix} 1 \\ 0 \\ -2 \\ 1 \end{bmatrix},
\qquad \operatorname{Nul} A = \operatorname{span}\{(-2, 1, 0, 0),\ (1, 0, -2, 1)\}.\]

  &lt;p&gt;Hai vectơ này độc lập tuyến tính: nhìn thành phần thứ 2 và thứ 4, chỉ vectơ đầu có số 1 ở vị trí 2, chỉ vectơ sau có số 1 ở vị trí 4. Không gian nghiệm là một “mặt phẳng” qua gốc trong $\mathbb{R}^4$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2 (Nhiều ẩn hơn phương trình).&lt;/strong&gt; Hệ thuần nhất $m$ phương trình, $n$ ẩn với $m &amp;lt; n$ luôn có nghiệm khác không.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Hệ thuần nhất luôn có nghiệm. Theo Hệ quả 1 của Bài 2.4, vì $m &amp;lt; n$ nên có ít nhất một biến tự do. Cho biến tự do đó bằng 1, các biến tự do khác bằng 0, ta được một nghiệm khác không.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Định lý 2 hoàn thành chứng minh Định lý 3 của Bài 1.5: $k &amp;gt; n$ vectơ trong $\mathbb{R}^n$ luôn phụ thuộc tuyến tính, vì đẳng thức $c_1 v_1 + \cdots + c_k v_k = 0$ là một hệ thuần nhất $n$ phương trình, $k$ ẩn.&lt;/p&gt;

&lt;h2 id=&quot;nghiệm-tổng-quát-của-hệ-không-thuần-nhất&quot;&gt;Nghiệm tổng quát của hệ không thuần nhất&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 3 (Cấu trúc tập nghiệm).&lt;/strong&gt; Giả sử $x_p$ là một nghiệm của $Ax = b$ (gọi là &lt;em&gt;nghiệm riêng&lt;/em&gt;). Khi đó tập nghiệm của $Ax = b$ là&lt;/p&gt;

  &lt;p&gt;\(\{\, x_p + x_h : x_h \in \operatorname{Nul} A \,\}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Nếu $x_h \in \operatorname{Nul} A$ thì $A(x_p + x_h) = b + 0 = b$, nên $x_p + x_h$ là nghiệm. Ngược lại, nếu $Ax = b$ thì $A(x - x_p) = b - b = 0$, nên $x_h = x - x_p$ thuộc $\operatorname{Nul} A$ và $x = x_p + x_h$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Hình học: tập nghiệm của $Ax = b$ là $\operatorname{Nul} A$ &lt;em&gt;tịnh tiến&lt;/em&gt; đi một vectơ $x_p$. Trong $\mathbb{R}^3$, nếu $\operatorname{Nul} A$ là một đường thẳng qua gốc thì tập nghiệm của $Ax = b$ là một đường thẳng song song với nó; nếu $\operatorname{Nul} A = \{0\}$ thì nghiệm duy nhất. Đổi vế phải $b$ chỉ làm dời chỗ tập nghiệm, không làm đổi hình dạng của nó.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; Với $A$ ở Ví dụ 1 và $b = (3, 8, 5)$, dạng bậc thang rút gọn của $[A \mid b]$ có hai hàng khác 0: $x_1 + 2x_2 - x_4 = 1$ và $x_3 + 2x_4 = 2$. Cho các biến tự do bằng 0 được nghiệm riêng $x_p = (1, 0, 2, 0)$. Kiểm tra: $1 + 2 = 3$, $2 + 6 = 8$, $1 + 4 = 5$. Nghiệm tổng quát:&lt;/p&gt;

  &lt;p&gt;\(x = (1, 0, 2, 0) + s\,(-2, 1, 0, 0) + t\,(1, 0, -2, 1).\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3.&lt;/strong&gt; Hệ $x + y + z = 0$, $x - y + 2z = 0$ (hai mặt phẳng qua gốc). Biến tự do $z = t$: cộng hai phương trình được $2x + 3z = 0$, nên $x = -\tfrac32 t$, $y = \tfrac12 t$. Không gian nghiệm là đường thẳng $\operatorname{span}\{(-3, 1, 2)\}$, giao tuyến của hai mặt phẳng. Đổi vế phải thành $(1, 0)$ thì giao tuyến dời đi nhưng vẫn song song với $(-3, 1, 2)$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-cùng-cấu-trúc-trong-phương-trình-vi-phân&quot;&gt;Ứng dụng: cùng cấu trúc trong phương trình vi phân&lt;/h2&gt;

&lt;p&gt;Phương trình vi phân $y&apos;&apos; + y = 1$ có nghiệm riêng $y_p = 1$. Phương trình thuần nhất $y&apos;&apos; + y = 0$ có nghiệm $c_1 \cos t + c_2 \sin t$. Nghiệm tổng quát là&lt;/p&gt;

\[y = 1 + c_1 \cos t + c_2 \sin t .\]

&lt;p&gt;Lý do giống hệt Định lý 3: phép $y \mapsto y&apos;&apos; + y$ “tuyến tính” giống như $x \mapsto Ax$, tức là giữ phép cộng và phép nhân với số. Khoá Phương trình vi phân dùng chính cấu trúc “nghiệm riêng + nghiệm thuần nhất” này. Trong kỹ thuật, nghiệm thuần nhất mô tả dao động tự do của hệ, còn nghiệm riêng mô tả phản ứng với lực tác động bên ngoài.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: hệ thuần nhất và nghiệm tổng quát&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Hệ thuần nhất luôn có nghiệm 0; nghiệm tổng quát = nghiệm riêng + tổ hợp các vectơ của Nul A.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter02/khu_gauss.html?preset=hom&quot; title=&quot;Minh hoạ: hệ thuần nhất và nghiệm tổng quát&quot; loading=&quot;lazy&quot; style=&quot;height: 680px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter02/khu_gauss.html?preset=hom&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Viết $\operatorname{Nul} A$ thành span với $A = \begin{bmatrix} 1 &amp;amp; -1 &amp;amp; 2 \\ 2 &amp;amp; -2 &amp;amp; 4 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Hạng 1, hai biến tự do $x_2 = s$, $x_3 = t$: $x_1 = s - 2t$. $\operatorname{Nul} A = \operatorname{span}\{(1, 1, 0), (-2, 0, 1)\}$, một mặt phẳng qua gốc.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Biết $x_p = (1, 1)$ là một nghiệm của $Ax = b$ và $\operatorname{Nul} A = \operatorname{span}\{(2, -1)\}$. Viết nghiệm tổng quát và chỉ ra một nghiệm khác.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$x = (1, 1) + t(2, -1)$. Với $t = 1$: $(3, 0)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Giải hệ $x_1 + 2x_2 - x_3 = 4$, $2x_1 + 4x_2 + x_3 = 5$ và viết nghiệm dưới dạng $x_p + x_h$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$R_2 \to R_2 - 2R_1$: $3x_3 = -3$, $x_3 = -1$. Khi đó $x_1 + 2x_2 = 3$. Với $x_2 = t$: $x = (3, 0, -1) + t(-2, 1, 0)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Chứng minh: nếu $x_1$ và $x_2$ là hai nghiệm của $Ax = b$ thì $x_1 - x_2 \in \operatorname{Nul} A$, nhưng $x_1 + x_2$ là nghiệm của $Ax = 2b$ chứ không phải của $Ax = b$ (khi $b \ne 0$).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A(x_1 - x_2) = b - b = 0$ và $A(x_1 + x_2) = 2b \ne b$. Vì vậy tập nghiệm của hệ không thuần nhất không phải không gian con.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao / lập trình).&lt;/strong&gt; Dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sympy.Matrix(A).nullspace()&lt;/code&gt; với $A$ ở Ví dụ 1. So kết quả với cơ sở tính tay. Sau đó dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scipy.linalg.null_space(A)&lt;/code&gt; (số thực) và kiểm tra các cột kết quả cũng sinh ra cùng không gian.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

SymPy trả về đúng $(-2, 1, 0, 0)$ và $(1, 0, -2, 1)$. SciPy trả về hai vectơ trực chuẩn khác (tính từ SVD, Chương 11). Mỗi vectơ của SciPy là tổ hợp tuyến tính của hai vectơ của SymPy và ngược lại; có thể kiểm tra bằng cách xem hạng của ma trận ghép bốn cột vẫn bằng 2.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$\operatorname{Nul} A$ = tập nghiệm của $Ax = 0$; nó chứa $0$, đóng với phép cộng và phép nhân với số, và là span của $n - \operatorname{rank} A$ vectơ đọc ra từ dạng bậc thang rút gọn.&lt;/li&gt;
    &lt;li&gt;Hệ thuần nhất có nhiều ẩn hơn phương trình luôn có nghiệm khác không.&lt;/li&gt;
    &lt;li&gt;Nghiệm tổng quát của $Ax = b$ là $x_p + x_h$ với $x_h \in \operatorname{Nul} A$: tập nghiệm là $\operatorname{Nul} A$ tịnh tiến đi.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Số nghiệm, biến tự do và hạng</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter02/02_04_So_Nghiem_Bien_Tu_Do_Va_Hang/"/>
   <updated>2026-01-02T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter02/02_04_So_Nghiem_Bien_Tu_Do_Va_Hang</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;xác định hạng của một ma trận, các biến chốt và các biến tự do từ dạng bậc thang;&lt;/li&gt;
    &lt;li&gt;dùng định lý Kronecker–Capelli để kết luận hệ vô nghiệm, có nghiệm duy nhất hay vô số nghiệm;&lt;/li&gt;
    &lt;li&gt;viết nghiệm tổng quát bằng tham số khi hệ có vô số nghiệm;&lt;/li&gt;
    &lt;li&gt;biện luận số nghiệm của hệ có tham số.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Khử Gauss hệ $x + 3y + z = 9$, $x + y - z = 1$, $3x + 11y + 5z = 35$ cho dạng bậc thang rút gọn&lt;/p&gt;

\[\left[\begin{array}{rrr|r} 1 &amp;amp; 0 &amp;amp; -2 &amp;amp; -3 \\ 0 &amp;amp; 1 &amp;amp; 1 &amp;amp; 4 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \end{array}\right].\]

&lt;p&gt;Hàng cuối là $0 = 0$: luôn đúng, không cho thêm thông tin. Chỉ còn hai phương trình $x - 2z = -3$ và $y + z = 4$ cho ba ẩn. Ẩn $z$ không bị ràng buộc: chọn $z = t$ tuỳ ý thì $x = -3 + 2t$, $y = 4 - t$. Hệ có vô số nghiệm, nằm trên một đường thẳng trong $\mathbb{R}^3$. Bài này biến quan sát đó thành quy tắc tổng quát.&lt;/p&gt;

&lt;h2 id=&quot;hạng-biến-chốt-và-biến-tự-do&quot;&gt;Hạng, biến chốt và biến tự do&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Hạng).&lt;/strong&gt; &lt;em&gt;Hạng&lt;/em&gt; của ma trận $A$, ký hiệu $\operatorname{rank} A$, là số phần tử chốt trong một dạng bậc thang của $A$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Theo Định lý 2 của Bài 2.3, vị trí các cột chốt không phụ thuộc cách khử, nên hạng được xác định rõ. Hạng không vượt quá số hàng và không vượt quá số cột, vì mỗi hàng và mỗi cột có nhiều nhất một phần tử chốt.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 2 (Biến chốt, biến tự do).&lt;/strong&gt; Xét hệ $Ax = b$ và một dạng bậc thang của $[A \mid b]$. Ẩn $x_j$ ứng với một cột chốt của $A$ gọi là &lt;em&gt;biến chốt&lt;/em&gt; (biến cơ sở). Các ẩn còn lại gọi là &lt;em&gt;biến tự do&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Ở ví dụ mở đầu, cột 1 và 2 là cột chốt nên $x, y$ là biến chốt; $z$ là biến tự do. Hạng của $A$ là 2.&lt;/p&gt;

&lt;h2 id=&quot;định-lý-về-số-nghiệm&quot;&gt;Định lý về số nghiệm&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Kronecker–Capelli).&lt;/strong&gt; Cho hệ $Ax = b$ với $A$ cỡ $m \times n$.&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;Hệ có nghiệm khi và chỉ khi $\operatorname{rank} A = \operatorname{rank}\,[A \mid b]$, tức là cột cuối của dạng bậc thang không chứa phần tử chốt.&lt;/li&gt;
    &lt;li&gt;Khi hệ có nghiệm: nếu $\operatorname{rank} A = n$ thì nghiệm duy nhất; nếu $\operatorname{rank} A &amp;lt; n$ thì có vô số nghiệm, và nghiệm tổng quát có đúng $n - \operatorname{rank} A$ tham số.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Theo Bài 2.2, ta có thể thay hệ bằng hệ ứng với dạng bậc thang rút gọn của $[A \mid b]$.&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;Phần 1.&lt;/em&gt; Nếu cột cuối có phần tử chốt, hàng chứa nó có dạng $(0, \dots, 0 \mid 1)$, tức phương trình $0 = 1$, nên hệ vô nghiệm. Khi đó $\operatorname{rank}[A \mid b] = \operatorname{rank} A + 1$. Nếu cột cuối không có chốt, hai hạng bằng nhau. Gán cho mỗi biến tự do một giá trị tuỳ ý; mỗi hàng khác 0 có dạng “biến chốt $+$ (tổ hợp các biến tự do) $=$ số”, nên tính được biến chốt. Đó là một nghiệm.&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;Phần 2.&lt;/em&gt; Cũng từ dạng rút gọn: mọi nghiệm có được đúng theo cách vừa nêu, và các giá trị khác nhau của biến tự do cho các nghiệm khác nhau. Số biến tự do là $n - \operatorname{rank} A$. Nếu số này bằng 0 thì có đúng một nghiệm; nếu dương thì có vô số nghiệm.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Hệ quả 1.&lt;/strong&gt; Hệ có ít phương trình hơn ẩn ($m &amp;lt; n$) thì hoặc vô nghiệm, hoặc có vô số nghiệm.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; $\operatorname{rank} A \le m &amp;lt; n$, nên nếu có nghiệm thì có ít nhất một biến tự do.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ&quot;&gt;Ví dụ&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (hạng của ma trận $4 \times 5$).&lt;/strong&gt; Ma trận&lt;/p&gt;

\[B = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; -1 &amp;amp; 3 &amp;amp; 1 \\ 2 &amp;amp; 4 &amp;amp; 0 &amp;amp; 2 &amp;amp; 6 \\ 1 &amp;amp; 2 &amp;amp; 1 &amp;amp; -1 &amp;amp; 5 \\ 3 &amp;amp; 6 &amp;amp; -1 &amp;amp; 5 &amp;amp; 7 \end{bmatrix}\]

  &lt;p&gt;có dạng bậc thang rút gọn&lt;/p&gt;

\[\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 &amp;amp; 1 &amp;amp; 3 \\ 0 &amp;amp; 0 &amp;amp; 1 &amp;amp; -2 &amp;amp; 2 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \end{bmatrix}.\]

  &lt;p&gt;Có hai chốt (cột 1 và cột 3), nên $\operatorname{rank} B = 2$. Bốn hàng của $B$ chỉ “chứa” hai phương trình độc lập: chẳng hạn hàng 4 bằng hàng 1 cộng hàng 2.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (biện luận theo tham số).&lt;/strong&gt; Biện luận số nghiệm của hệ&lt;/p&gt;

\[x + y + z = 1, \qquad x + 2y + m z = 2, \qquad 2x + 3y + 4z = m + 1 .\]

  &lt;p&gt;Làm $R_2 \to R_2 - R_1$, $R_3 \to R_3 - 2R_1$, rồi $R_3 \to R_3 - R_2$:&lt;/p&gt;

\[\left[\begin{array}{ccc|c} 1 &amp;amp; 1 &amp;amp; 1 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; m - 1 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 3 - m &amp;amp; m - 2 \end{array}\right].\]

  &lt;ul&gt;
    &lt;li&gt;Nếu $m \ne 3$: ba chốt, $\operatorname{rank} A = 3 = n$, nghiệm duy nhất với $z = \dfrac{m - 2}{3 - m}$. Ví dụ $m = 2$ cho $(x, y, z) = (0, 1, 0)$.&lt;/li&gt;
    &lt;li&gt;Nếu $m = 3$: hàng cuối là $(0, 0, 0 \mid 1)$, tức $0 = 1$. Hệ vô nghiệm: $\operatorname{rank} A = 2 &amp;lt; 3 = \operatorname{rank}[A \mid b]$.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Hình học: khi $m = 3$, ba mặt phẳng đôi một cắt nhau theo ba đường thẳng song song, như ba mặt của một lăng trụ tam giác, và không có điểm chung.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3.&lt;/strong&gt; Hệ mở đầu: $\operatorname{rank} A = \operatorname{rank}[A \mid b] = 2 &amp;lt; 3$, nên vô số nghiệm với $3 - 2 = 1$ tham số:&lt;/p&gt;

\[(x, y, z) = (-3, 4, 0) + t\,(2, -1, 1).\]

  &lt;p&gt;Đây là phương trình tham số của một đường thẳng (Bài 1.3): giao tuyến chung của ba mặt phẳng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-điều-khiển-giao-thông&quot;&gt;Ứng dụng: điều khiển giao thông&lt;/h2&gt;

&lt;p&gt;Một vòng xoay có ba nút $A, B, C$. Xe vào nút $A$ 300 xe/giờ, ra khỏi nút $B$ 100 xe/giờ, ra khỏi nút $C$ 200 xe/giờ. Gọi $x_1$ là lưu lượng $A \to B$, $x_2$ là $B \to C$, $x_3$ là $A \to C$. Bảo toàn lưu lượng ở mỗi nút (vào bằng ra):&lt;/p&gt;

\[A:\ x_1 + x_3 = 300, \qquad B:\ x_1 = x_2 + 100, \qquad C:\ x_2 + x_3 = 200 .\]

&lt;p&gt;Hạng của ma trận hệ số là 2 (phương trình $C$ là hệ quả của hai phương trình kia), nên có một biến tự do: $x_3 = t$, $x_1 = 300 - t$, $x_2 = 200 - t$. Kỹ sư giao thông có thể chọn $t$, ví dụ đóng đoạn $A \to C$ để sửa đường ($t = 0$), và biết ngay hai đoạn còn lại phải chịu 300 và 200 xe/giờ. Điều kiện $x_i \ge 0$ cho thêm $0 \le t \le 200$.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: số nghiệm, biến tự do và hạng&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Chọn ví dụ vô nghiệm, nghiệm duy nhất, vô số nghiệm; xem hạng và nghiệm tổng quát.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter02/khu_gauss.html?preset=inf&quot; title=&quot;Minh hoạ: số nghiệm, biến tự do và hạng&quot; loading=&quot;lazy&quot; style=&quot;height: 680px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter02/khu_gauss.html?preset=inf&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Tìm hạng của $\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 3 \\ 2 &amp;amp; 4 &amp;amp; 6 \\ 1 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Hàng 2 bằng hai lần hàng 1; hàng 1 và hàng 3 không tỉ lệ. Hạng bằng 2.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Một hệ 5 phương trình, 7 ẩn có nghiệm và ma trận hệ số có hạng 4. Nghiệm tổng quát có mấy tham số?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$7 - 4 = 3$ tham số.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Biện luận theo $k$: $x + y + z = 1$, $x + 2y + 3z = 2$, $2x + 3y + 4z = k$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Hàng 3 trừ hàng 1 và hàng 2 cho $0 = k - 3$. Nếu $k \ne 3$: vô nghiệm. Nếu $k = 3$: vô số nghiệm $(x, y, z) = (t, 1 - 2t, t)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Chứng minh: hệ $n$ phương trình, $n$ ẩn có nghiệm duy nhất với &lt;em&gt;một&lt;/em&gt; vế phải $b$ thì có nghiệm duy nhất với &lt;em&gt;mọi&lt;/em&gt; vế phải.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Nghiệm duy nhất kéo theo $\operatorname{rank} A = n$, tức mỗi hàng có một chốt. Khi đó cột cuối của $[A \mid b&apos;]$ không thể có chốt với bất kỳ $b&apos;$ nào, và vẫn không có biến tự do.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao / lập trình).&lt;/strong&gt; Dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sympy.Matrix(...).rref()&lt;/code&gt; để biện luận Ví dụ 2 với $m$ là ký hiệu. Vì sao SymPy có thể trả lời sai cho giá trị đặc biệt $m = 3$ nếu ta không cẩn thận?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Khi khử, SymPy có thể chia cho $3 - m$ mà không xét riêng trường hợp $3 - m = 0$, nên kết quả chỉ đúng với $m$ &quot;tổng quát&quot;. Phải tự tách trường hợp: thay $m = 3$ vào rồi khử lại.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Hạng là số phần tử chốt; biến chốt ứng với cột chốt, các ẩn còn lại là biến tự do.&lt;/li&gt;
    &lt;li&gt;Có nghiệm khi và chỉ khi $\operatorname{rank} A = \operatorname{rank}[A \mid b]$.&lt;/li&gt;
    &lt;li&gt;Khi có nghiệm: duy nhất nếu $\operatorname{rank} A = n$; vô số nếu $\operatorname{rank} A &amp;lt; n$, với $n - \operatorname{rank} A$ tham số.&lt;/li&gt;
    &lt;li&gt;Ít phương trình hơn ẩn thì không bao giờ có nghiệm duy nhất.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Khử Gauss và Gauss–Jordan</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter02/02_03_Khu_Gauss_Va_Gauss_Jordan/"/>
   <updated>2026-01-02T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter02/02_03_Khu_Gauss_Va_Gauss_Jordan</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;nhận biết ma trận dạng bậc thang và dạng bậc thang rút gọn, chỉ ra các phần tử chốt;&lt;/li&gt;
    &lt;li&gt;đưa một ma trận về dạng bậc thang bằng khử Gauss, rồi giải hệ bằng thế ngược;&lt;/li&gt;
    &lt;li&gt;đưa ma trận về dạng bậc thang rút gọn bằng Gauss–Jordan và đọc nghiệm trực tiếp;&lt;/li&gt;
    &lt;li&gt;ước lượng số phép tính của khử Gauss.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Giải hệ&lt;/p&gt;

\[x + y + z = 6, \qquad 2x + 3y + z = 11, \qquad x - y + 2z = 5 .\]

&lt;p&gt;Ý tưởng: dùng phương trình đầu để loại $x$ khỏi hai phương trình sau, rồi dùng phương trình hai mới để loại $y$ khỏi phương trình ba. Phương trình cuối chỉ còn $z$. Giải $z$, rồi lần ngược lên để có $y$ và $x$. Đây là &lt;em&gt;khử Gauss&lt;/em&gt;. Bài này viết nó thành một thuật toán chạy được cho mọi hệ.&lt;/p&gt;

&lt;h2 id=&quot;dạng-bậc-thang&quot;&gt;Dạng bậc thang&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Dạng bậc thang).&lt;/strong&gt; Một ma trận có &lt;em&gt;dạng bậc thang&lt;/em&gt; (theo hàng) nếu:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;các hàng toàn số 0 (nếu có) nằm dưới cùng;&lt;/li&gt;
    &lt;li&gt;trong mỗi hàng khác 0, phần tử khác 0 đầu tiên tính từ trái (gọi là &lt;em&gt;phần tử chốt&lt;/em&gt;, hay &lt;em&gt;pivot&lt;/em&gt;) nằm ở cột lệch sang phải so với phần tử chốt của hàng trên.&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;Cột chứa phần tử chốt gọi là &lt;em&gt;cột chốt&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Nhìn bằng mắt: các phần tử chốt tạo thành bậc thang đi xuống từ trái sang phải, và mọi số nằm dưới mỗi bậc đều bằng 0.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 2 (Dạng bậc thang rút gọn).&lt;/strong&gt; Ma trận dạng bậc thang có &lt;em&gt;dạng bậc thang rút gọn&lt;/em&gt; nếu thêm hai điều kiện:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;mọi phần tử chốt bằng 1;&lt;/li&gt;
    &lt;li&gt;trong mỗi cột chốt, mọi phần tử khác (cả trên lẫn dưới phần tử chốt) bằng 0.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;p&gt;Ví dụ, trong các ma trận sau, ma trận đầu có dạng bậc thang, ma trận thứ hai có dạng bậc thang rút gọn:&lt;/p&gt;

\[\begin{bmatrix} 2 &amp;amp; 1 &amp;amp; -1 &amp;amp; 8 \\ 0 &amp;amp; 3 &amp;amp; 5 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 4 \end{bmatrix}, \qquad
\begin{bmatrix} 1 &amp;amp; 0 &amp;amp; -2 &amp;amp; -3 \\ 0 &amp;amp; 1 &amp;amp; 1 &amp;amp; 4 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \end{bmatrix}.\]

&lt;h2 id=&quot;thuật-toán-khử-gauss&quot;&gt;Thuật toán khử Gauss&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Mọi ma trận đều tương đương hàng với một ma trận dạng bậc thang.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh (chính là thuật toán).&lt;/strong&gt; Quy nạp theo số hàng. Nếu ma trận toàn số 0 thì nó đã có dạng bậc thang. Ngược lại:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;Tìm cột khác 0 đầu tiên từ trái sang. Chọn một hàng có phần tử khác 0 ở cột này và đổi hàng đó lên đầu. Phần tử này là phần tử chốt $p$.&lt;/li&gt;
    &lt;li&gt;Với mỗi hàng $i$ bên dưới có phần tử $a$ ở cột chốt, làm $R_i \to R_i - \tfrac{a}{p} R_1$. Sau bước này mọi phần tử dưới $p$ bằng 0.&lt;/li&gt;
    &lt;li&gt;Bỏ hàng đầu ra, áp dụng giả thiết quy nạp cho ma trận con gồm các hàng còn lại. Các phép biến đổi trên ma trận con không đụng tới hàng đầu và không làm hỏng các số 0 đã tạo ở cột chốt, vì các hàng con đều có số 0 ở đó.&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;Ghép hàng đầu với ma trận con dạng bậc thang, ta được ma trận dạng bậc thang: phần tử chốt của các hàng con nằm ở cột lệch phải so với $p$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Sau khi có dạng bậc thang, ta giải từ phương trình cuối lên, gọi là &lt;em&gt;thế ngược&lt;/em&gt;.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Hệ mở đầu:&lt;/p&gt;

\[\left[\begin{array}{rrr|r} 1 &amp;amp; 1 &amp;amp; 1 &amp;amp; 6 \\ 2 &amp;amp; 3 &amp;amp; 1 &amp;amp; 11 \\ 1 &amp;amp; -1 &amp;amp; 2 &amp;amp; 5 \end{array}\right]
\xrightarrow[R_3 \to R_3 - R_1]{R_2 \to R_2 - 2R_1}
\left[\begin{array}{rrr|r} 1 &amp;amp; 1 &amp;amp; 1 &amp;amp; 6 \\ 0 &amp;amp; 1 &amp;amp; -1 &amp;amp; -1 \\ 0 &amp;amp; -2 &amp;amp; 1 &amp;amp; -1 \end{array}\right]
\xrightarrow{R_3 \to R_3 + 2R_2}
\left[\begin{array}{rrr|r} 1 &amp;amp; 1 &amp;amp; 1 &amp;amp; 6 \\ 0 &amp;amp; 1 &amp;amp; -1 &amp;amp; -1 \\ 0 &amp;amp; 0 &amp;amp; -1 &amp;amp; -3 \end{array}\right].\]

  &lt;p&gt;Thế ngược: $-z = -3$ nên $z = 3$; $y - z = -1$ nên $y = 2$; $x + y + z = 6$ nên $x = 1$. Nghiệm $(1, 2, 3)$.&lt;/p&gt;

  &lt;p&gt;Hình học: ở mỗi bước, ba mặt phẳng được thay bằng ba mặt phẳng khác vẫn đi qua điểm $(1, 2, 3)$. Mặt phẳng cuối $z = 3$ nằm ngang, mặt phẳng thứ hai $y - z = -1$ song song với trục $x$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;gaussjordan&quot;&gt;Gauss–Jordan&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Gauss–Jordan&lt;/em&gt; đi tiếp từ dạng bậc thang: chia mỗi hàng cho phần tử chốt của nó để chốt bằng 1, rồi khử các phần tử &lt;em&gt;phía trên&lt;/em&gt; mỗi phần tử chốt, làm từ phải sang trái. Kết quả là dạng bậc thang rút gọn, từ đó đọc ngay nghiệm mà không cần thế ngược.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; Tiếp tục Ví dụ 1. Làm $R_3 \to -R_3$ được hàng ba $(0, 0, 1 \mid 3)$. Rồi&lt;/p&gt;

\[\xrightarrow[R_1 \to R_1 - R_3]{R_2 \to R_2 + R_3}
\left[\begin{array}{rrr|r} 1 &amp;amp; 1 &amp;amp; 0 &amp;amp; 3 \\ 0 &amp;amp; 1 &amp;amp; 0 &amp;amp; 2 \\ 0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 3 \end{array}\right]
\xrightarrow{R_1 \to R_1 - R_2}
\left[\begin{array}{rrr|r} 1 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; 0 &amp;amp; 2 \\ 0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 3 \end{array}\right].\]

  &lt;p&gt;Cột cuối là nghiệm.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3 (phần tử chốt không bằng 1).&lt;/strong&gt; Hệ $2x + y - z = 8$, $-3x - y + 2z = -11$, $-2x + y + 2z = -3$. Khử với chốt $2$:&lt;/p&gt;

\[\xrightarrow[R_3 \to R_3 + R_1]{R_2 \to R_2 + \frac32 R_1}
\left[\begin{array}{rrr|r} 2 &amp;amp; 1 &amp;amp; -1 &amp;amp; 8 \\ 0 &amp;amp; \tfrac12 &amp;amp; \tfrac12 &amp;amp; 1 \\ 0 &amp;amp; 2 &amp;amp; 1 &amp;amp; 5 \end{array}\right]
\xrightarrow{R_3 \to R_3 - 4R_2}
\left[\begin{array}{rrr|r} 2 &amp;amp; 1 &amp;amp; -1 &amp;amp; 8 \\ 0 &amp;amp; \tfrac12 &amp;amp; \tfrac12 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; -1 &amp;amp; 1 \end{array}\right].\]

  &lt;p&gt;Thế ngược: $z = -1$; $\tfrac12 y - \tfrac12 = 1$ nên $y = 3$; $2x + 3 + 1 = 8$ nên $x = 2$. Nghiệm $(2, 3, -1)$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2 (Tính duy nhất của dạng bậc thang rút gọn).&lt;/strong&gt; Mỗi ma trận tương đương hàng với đúng một ma trận dạng bậc thang rút gọn.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Ta công nhận định lý này. (Ý chứng minh: hai ma trận rút gọn tương đương hàng thì có cùng tập nghiệm của hệ thuần nhất; từ tập nghiệm đó đọc ngược ra được vị trí chốt và các phần tử ngoài chốt.) Hệ quả quan trọng: vị trí các cột chốt chỉ phụ thuộc ma trận ban đầu, không phụ thuộc cách khử. Số cột chốt sẽ là &lt;em&gt;hạng&lt;/em&gt; ở Bài 2.4. Riêng dạng bậc thang (chưa rút gọn) thì không duy nhất: nhân một hàng với 2 vẫn được dạng bậc thang.&lt;/p&gt;

&lt;h2 id=&quot;số-phép-tính&quot;&gt;Số phép tính&lt;/h2&gt;

&lt;p&gt;Với hệ $n \times n$, bước khử ở cột đầu cần sửa $n - 1$ hàng, mỗi hàng khoảng $n$ phần tử: khoảng $n^2$ phép nhân. Cột thứ hai khoảng $(n-1)^2$, … Tổng cộng khoảng&lt;/p&gt;

\[n^2 + (n-1)^2 + \cdots + 1^2 \approx \frac{n^3}{3}\]

&lt;p&gt;phép nhân (và chừng ấy phép cộng), còn thế ngược chỉ cần khoảng $n^2/2$. Với $n = 1000$, khử Gauss cần khoảng $3 \times 10^8$ phép nhân, máy tính cá nhân làm trong chưa tới một giây. Gấp đôi $n$ thì thời gian gấp khoảng 8 lần.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-cân-bằng-phương-trình-phản-ứng&quot;&gt;Ứng dụng: cân bằng phương trình phản ứng&lt;/h2&gt;

&lt;p&gt;Cân bằng $a\,\mathrm{C_3H_8} + b\,\mathrm{O_2} \to c\,\mathrm{CO_2} + d\,\mathrm{H_2O}$. Đếm từng nguyên tố ở hai vế:&lt;/p&gt;

\[\text{C: } 3a = c, \qquad \text{H: } 8a = 2d, \qquad \text{O: } 2b = 2c + d .\]

&lt;p&gt;Đây là hệ thuần nhất 3 phương trình, 4 ẩn. Khử Gauss cho dạng rút gọn với $d$ là ẩn tự do: $a = d/4$, $b = 5d/4$, $c = 3d/4$. Chọn $d = 4$ để được số nguyên nhỏ nhất: $\mathrm{C_3H_8} + 5\,\mathrm{O_2} \to 3\,\mathrm{CO_2} + 4\,\mathrm{H_2O}$. Phần mềm hoá học cân bằng phương trình đúng theo cách này.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: khử Gauss và Gauss–Jordan&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Khử xuôi tới dạng bậc thang, rồi tiếp tục tới dạng bậc thang rút gọn.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter02/khu_gauss.html?preset=u&quot; title=&quot;Minh hoạ: khử Gauss và Gauss–Jordan&quot; loading=&quot;lazy&quot; style=&quot;height: 680px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter02/khu_gauss.html?preset=u&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Giải bằng Gauss–Jordan: $x - 2y + z = 0$, $2y - 8z = 8$, $5x - 5z = 10$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$(x, y, z) = (1, 0, -1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Ma trận nào có dạng bậc thang, dạng bậc thang rút gọn? $\begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 2 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$, $\begin{bmatrix} 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix}$, $\begin{bmatrix} 1 &amp;amp; 3 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Ma trận đầu có dạng bậc thang nhưng chưa rút gọn (số 2 nằm trên chốt ở cột 3). Ma trận thứ hai không có dạng bậc thang. Ma trận thứ ba có dạng bậc thang rút gọn.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Cân bằng phương trình $a\,\mathrm{Al} + b\,\mathrm{O_2} \to c\,\mathrm{Al_2O_3}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Al: $a = 2c$; O: $2b = 3c$. Với $c = 2$: $a = 4$, $b = 3$, tức $4\,\mathrm{Al} + 3\,\mathrm{O_2} \to 2\,\mathrm{Al_2O_3}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Đếm chính xác số phép nhân và chia trong bước khử (chưa kể thế ngược) cho ma trận mở rộng $3 \times 4$ tổng quát, nếu không bỏ qua phép nào.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Cột 1: 2 hàng, mỗi hàng 1 phép chia để tìm hệ số và 3 phép nhân: 8. Cột 2: 1 hàng, 1 phép chia và 2 phép nhân: 3. Tổng 11.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao / lập trình).&lt;/strong&gt; Viết hàm Python &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rref(M)&lt;/code&gt; dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fractions.Fraction&lt;/code&gt; để đưa một ma trận về dạng bậc thang rút gọn. Kiểm tra với Ví dụ 1 và so với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sympy.Matrix(...).rref()&lt;/code&gt;.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Hàm duyệt từng cột, tìm hàng chốt từ dòng hiện tại trở xuống, đổi chỗ, chia hàng cho chốt, rồi khử cột đó ở *mọi* hàng khác. Với Ví dụ 1 phải được ma trận có cột cuối $(1, 2, 3)$ và các cột chốt $(0, 1, 2)$, khớp với SymPy.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Dạng bậc thang: chốt đi xuống từ trái sang phải, dưới chốt toàn 0. Dạng rút gọn: thêm chốt bằng 1 và cột chốt chỉ có một số khác 0.&lt;/li&gt;
    &lt;li&gt;Khử Gauss đưa mọi ma trận về dạng bậc thang; thế ngược cho nghiệm.&lt;/li&gt;
    &lt;li&gt;Gauss–Jordan cho dạng bậc thang rút gọn, duy nhất với mỗi ma trận; vị trí cột chốt không phụ thuộc cách khử.&lt;/li&gt;
    &lt;li&gt;Khử Gauss cho hệ $n \times n$ tốn khoảng $n^3/3$ phép nhân.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Phép biến đổi sơ cấp trên hàng</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter02/02_02_Phep_Bien_Doi_So_Cap_Tren_Hang/"/>
   <updated>2026-01-02T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter02/02_02_Phep_Bien_Doi_So_Cap_Tren_Hang</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;thực hiện ba phép biến đổi sơ cấp trên hàng của ma trận mở rộng và ghi đúng ký hiệu;&lt;/li&gt;
    &lt;li&gt;chứng minh các phép biến đổi này không làm thay đổi tập nghiệm;&lt;/li&gt;
    &lt;li&gt;biết mỗi phép biến đổi có phép ngược cùng loại.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Khi giải hệ $x + y = 5$, $2x - y = 1$ ở phổ thông, ta thường làm ba việc: đổi chỗ hai phương trình, nhân một phương trình với một số khác 0, cộng một bội của phương trình này vào phương trình khác. Ví dụ: lấy phương trình hai trừ hai lần phương trình một được $-3y = -9$, nên $y = 3$, rồi $x = 2$.&lt;/p&gt;

&lt;p&gt;Câu hỏi: vì sao làm như vậy không làm mất nghiệm, cũng không sinh thêm nghiệm lạ? Bài này trả lời câu hỏi đó, và từ đây ta chỉ làm việc với ma trận mở rộng thay vì chép lại cả hệ.&lt;/p&gt;

&lt;h2 id=&quot;ba-phép-biến-đổi-sơ-cấp&quot;&gt;Ba phép biến đổi sơ cấp&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Phép biến đổi sơ cấp trên hàng).&lt;/strong&gt; Trên một ma trận, ba phép sau gọi là &lt;em&gt;phép biến đổi sơ cấp trên hàng&lt;/em&gt;:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;&lt;strong&gt;Đổi chỗ&lt;/strong&gt; hai hàng $i$ và $j$, ký hiệu $R_i \leftrightarrow R_j$.&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Nhân&lt;/strong&gt; hàng $i$ với một số $c \ne 0$, ký hiệu $R_i \to c R_i$.&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Cộng&lt;/strong&gt; vào hàng $i$ một bội $c$ của hàng $j$ ($j \ne i$), ký hiệu $R_i \to R_i + c R_j$.&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;Hai ma trận gọi là &lt;em&gt;tương đương hàng&lt;/em&gt; nếu biến được ma trận này thành ma trận kia bằng một dãy hữu hạn phép biến đổi sơ cấp trên hàng.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Điều kiện $c \ne 0$ ở phép 2 là bắt buộc. Nhân một phương trình với 0 là xoá phương trình đó, và tập nghiệm có thể lớn lên.&lt;/p&gt;

&lt;div class=&quot;textbook-lemma&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Bổ đề 1 (Mỗi phép có phép ngược).&lt;/strong&gt; Mỗi phép biến đổi sơ cấp trên hàng có thể đảo ngược bằng một phép biến đổi sơ cấp cùng loại:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$R_i \leftrightarrow R_j$ ngược với chính nó;&lt;/li&gt;
    &lt;li&gt;$R_i \to c R_i$ ngược với $R_i \to \tfrac1c R_i$;&lt;/li&gt;
    &lt;li&gt;$R_i \to R_i + c R_j$ ngược với $R_i \to R_i - c R_j$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Hai trường hợp đầu là hiển nhiên. Với trường hợp ba: phép $R_i \to R_i + cR_j$ không đổi hàng $j$, nên sau đó trừ đi $c$ lần hàng $j$ (vẫn như cũ) thì hàng $i$ trở về như ban đầu.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;tập-nghiệm-không-đổi&quot;&gt;Tập nghiệm không đổi&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Nếu hai ma trận mở rộng $[A \mid b]$ và $[A&apos; \mid b&apos;]$ tương đương hàng thì hai hệ $Ax = b$ và $A&apos;x = b&apos;$ có cùng tập nghiệm.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Chỉ cần xét một phép biến đổi. Gọi $S$ là tập nghiệm của hệ cũ, $S&apos;$ của hệ mới.&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;$S \subseteq S&apos;$.&lt;/em&gt; Lấy $x \in S$. Mỗi phương trình của hệ mới là một phương trình cũ (phép 1), hoặc $c$ lần một phương trình cũ (phép 2), hoặc tổng của phương trình $i$ với $c$ lần phương trình $j$ (phép 3). Vì $x$ thoả các phương trình cũ, nó thoả các phương trình mới: ví dụ với phép 3, nếu $r_i \cdot x = b_i$ và $r_j \cdot x = b_j$ thì $(r_i + c r_j)\cdot x = b_i + c b_j$.&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;$S&apos; \subseteq S$.&lt;/em&gt; Theo Bổ đề 1, hệ cũ nhận được từ hệ mới bằng một phép biến đổi sơ cấp. Áp dụng lập luận vừa rồi theo chiều ngược lại.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;content-box warning-box textbook-block&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Lưu ý.&lt;/strong&gt; Định lý 1 nói về phép biến đổi trên &lt;strong&gt;hàng&lt;/strong&gt; của ma trận mở rộng. Phép biến đổi trên cột (ví dụ đổi chỗ hai cột) làm đổi vai trò các ẩn, nên không giữ tập nghiệm nếu không ghi lại việc đổi tên ẩn.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ&quot;&gt;Ví dụ&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Hệ mở đầu viết bằng ma trận mở rộng:&lt;/p&gt;

\[\left[\begin{array}{rr|r} 1 &amp;amp; 1 &amp;amp; 5 \\ 2 &amp;amp; -1 &amp;amp; 1 \end{array}\right]
\xrightarrow{R_2 \to R_2 - 2R_1}
\left[\begin{array}{rr|r} 1 &amp;amp; 1 &amp;amp; 5 \\ 0 &amp;amp; -3 &amp;amp; -9 \end{array}\right]
\xrightarrow{R_2 \to -\frac13 R_2}
\left[\begin{array}{rr|r} 1 &amp;amp; 1 &amp;amp; 5 \\ 0 &amp;amp; 1 &amp;amp; 3 \end{array}\right]
\xrightarrow{R_1 \to R_1 - R_2}
\left[\begin{array}{rr|r} 1 &amp;amp; 0 &amp;amp; 2 \\ 0 &amp;amp; 1 &amp;amp; 3 \end{array}\right].\]

  &lt;p&gt;Ma trận cuối đọc ngay ra nghiệm $x = 2$, $y = 3$. Theo cách nhìn hàng, mỗi bước thay hai đường thẳng bằng hai đường thẳng khác &lt;em&gt;cùng đi qua điểm $(2, 3)$&lt;/em&gt;; bước cuối cùng là hai đường $x = 2$ và $y = 3$, song song với hai trục.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (cần đổi chỗ hàng).&lt;/strong&gt; Hệ $2y = 4$, $x + y = 3$ có hệ số của $x$ ở hàng đầu bằng 0. Đổi chỗ trước:&lt;/p&gt;

\[\left[\begin{array}{rr|r} 0 &amp;amp; 2 &amp;amp; 4 \\ 1 &amp;amp; 1 &amp;amp; 3 \end{array}\right]
\xrightarrow{R_1 \leftrightarrow R_2}
\left[\begin{array}{rr|r} 1 &amp;amp; 1 &amp;amp; 3 \\ 0 &amp;amp; 2 &amp;amp; 4 \end{array}\right],\]

  &lt;p&gt;rồi $y = 2$, $x = 1$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3 (phép sai).&lt;/strong&gt; Từ hệ $x + y = 2$, $x - y = 0$ (nghiệm duy nhất $(1, 1)$), nếu “nhân hàng 2 với 0” ta được hệ chỉ còn $x + y = 2$, có vô số nghiệm như $(2, 0)$. Đó là lý do phép 2 đòi hỏi $c \ne 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-mạch-điện-và-phần-mềm-giải-hệ&quot;&gt;Ứng dụng: mạch điện và phần mềm giải hệ&lt;/h2&gt;

&lt;p&gt;Trong một mạch điện, định luật Kirchhoff cho một phương trình tuyến tính tại mỗi nút và mỗi vòng. Một mạch thật có hàng nghìn ẩn. Phần mềm mô phỏng mạch (như SPICE) không “giải khéo” mà chỉ lặp lại ba phép biến đổi sơ cấp theo một thứ tự cố định, tức là khử Gauss ở Bài 2.3. Định lý 1 đảm bảo rằng dù làm hàng triệu phép biến đổi, đáp số cuối vẫn là nghiệm của mạch ban đầu (bỏ qua sai số làm tròn, xem Bài 2.6).&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: khử Gauss từng bước&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Bấm ▶ để thực hiện từng phép biến đổi sơ cấp trên hàng, với phân số chính xác.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter02/khu_gauss.html?preset=swap&quot; title=&quot;Minh hoạ: khử Gauss từng bước&quot; loading=&quot;lazy&quot; style=&quot;height: 680px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter02/khu_gauss.html?preset=swap&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Áp dụng lần lượt $R_2 \to R_2 - 3R_1$ rồi $R_1 \leftrightarrow R_2$ cho $\begin{bmatrix} 1 &amp;amp; 2 \\ 3 &amp;amp; 4 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Sau bước một: $\begin{bmatrix} 1 &amp;amp; 2 \\ 0 &amp;amp; -2 \end{bmatrix}$. Sau bước hai: $\begin{bmatrix} 0 &amp;amp; -2 \\ 1 &amp;amp; 2 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Tìm phép biến đổi ngược của dãy ở Bài tập 1 (theo đúng thứ tự).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Làm ngược từ cuối: $R_1 \leftrightarrow R_2$, rồi $R_2 \to R_2 + 3R_1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Giải hệ $x + 2y = 4$, $3x + 5y = 7$ chỉ bằng phép biến đổi trên ma trận mở rộng, ghi rõ mỗi bước.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$R_2 \to R_2 - 3R_1$: hàng hai thành $(0, -1 \mid -5)$; $R_2 \to -R_2$: $(0, 1 \mid 5)$; $R_1 \to R_1 - 2R_2$: $(1, 0 \mid -6)$. Nghiệm $x = -6$, $y = 5$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Phép “$R_1 \to R_1 + R_2$ và đồng thời $R_2 \to R_2 + R_1$” (cả hai dùng hàng cũ) có giữ tập nghiệm không? Thử với $x + y = 1$, $-x - y = -1$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Không nhất thiết. Ở ví dụ, cả hai hàng mới đều là $0 = 0$, tập nghiệm từ một đường thẳng thành cả mặt phẳng. Đây không phải một dãy phép biến đổi sơ cấp, vì bước thứ hai phải dùng hàng 1 *đã đổi*.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Chứng minh phép đổi chỗ $R_1 \leftrightarrow R_2$ có thể thực hiện bằng các phép loại 2 và loại 3. (Gợi ý: $R_1 \to R_1 + R_2$, $R_2 \to R_2 - R_1$, …)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Với hai hàng $u, v$: $R_1 \to R_1 + R_2$ cho $(u + v, v)$; $R_2 \to R_2 - R_1$ cho $(u + v, -u)$; $R_1 \to R_1 + R_2$ cho $(v, -u)$; $R_2 \to -R_2$ cho $(v, u)$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Ba phép biến đổi sơ cấp: đổi chỗ hai hàng, nhân một hàng với số khác 0, cộng bội của một hàng vào hàng khác.&lt;/li&gt;
    &lt;li&gt;Mỗi phép có phép ngược cùng loại.&lt;/li&gt;
    &lt;li&gt;Ma trận mở rộng tương đương hàng cho hệ có cùng tập nghiệm (Định lý 1).&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Hệ phương trình tuyến tính: cách nhìn theo hàng và theo cột</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter02/02_01_He_Phuong_Trinh_Tuyen_Tinh/"/>
   <updated>2026-01-02T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter02/02_01_He_Phuong_Trinh_Tuyen_Tinh</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;viết một hệ phương trình tuyến tính dưới dạng ma trận $Ax = b$ và dạng ma trận mở rộng $[A \mid b]$;&lt;/li&gt;
    &lt;li&gt;giải thích nghiệm theo cách nhìn hàng: giao của các đường thẳng hoặc mặt phẳng;&lt;/li&gt;
    &lt;li&gt;giải thích nghiệm theo cách nhìn cột: hệ số để tổ hợp các cột của $A$ thành $b$;&lt;/li&gt;
    &lt;li&gt;nhận ra ba khả năng: vô nghiệm, đúng một nghiệm, vô số nghiệm.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Xét hệ&lt;/p&gt;

\[\begin{aligned}
2x - y &amp;amp;= 1,\\
x + y &amp;amp;= 5.
\end{aligned}\]

&lt;p&gt;Cộng hai phương trình được $3x = 6$, nên $x = 2$ và $y = 3$. Bài này không bàn về cách giải (đó là Bài 2.3) mà về cách &lt;em&gt;nhìn&lt;/em&gt; hệ. Có hai cách nhìn, và cả hai đều dùng suốt khoá học.&lt;/p&gt;

&lt;h2 id=&quot;hệ-phương-trình-tuyến-tính-và-dạng-ma-trận&quot;&gt;Hệ phương trình tuyến tính và dạng ma trận&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Hệ phương trình tuyến tính).&lt;/strong&gt; Một &lt;em&gt;hệ $m$ phương trình tuyến tính $n$ ẩn&lt;/em&gt; có dạng&lt;/p&gt;

\[\begin{aligned}
a_{11} x_1 + a_{12} x_2 + \cdots + a_{1n} x_n &amp;amp;= b_1,\\
&amp;amp;\ \,\vdots\\
a_{m1} x_1 + a_{m2} x_2 + \cdots + a_{mn} x_n &amp;amp;= b_m,
\end{aligned}\]

  &lt;p&gt;với các hệ số $a_{ij}$ và vế phải $b_i$ là số thực. Một &lt;em&gt;nghiệm&lt;/em&gt; là một vectơ $x = (x_1, \dots, x_n)$ thoả mọi phương trình. &lt;em&gt;Tập nghiệm&lt;/em&gt; là tập mọi nghiệm. Hệ gọi là &lt;em&gt;tương thích&lt;/em&gt; nếu có ít nhất một nghiệm.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Bảng hệ số $A = [a_{ij}]$ có $m$ hàng và $n$ cột gọi là &lt;em&gt;ma trận hệ số&lt;/em&gt;. Ghép thêm cột $b$ được &lt;em&gt;ma trận mở rộng&lt;/em&gt; $[A \mid b]$. Hệ được viết gọn là $Ax = b$, trong đó tích $Ax$ được định nghĩa ở mục 4.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Hệ mở đầu có&lt;/p&gt;

  &lt;p&gt;\(A = \begin{bmatrix} 2 &amp;amp; -1 \\ 1 &amp;amp; 1 \end{bmatrix}, \quad b = \begin{bmatrix} 1 \\ 5 \end{bmatrix}, \quad [A \mid b] = \left[\begin{array}{rr|r} 2 &amp;amp; -1 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 5 \end{array}\right].\)&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;cách-nhìn-theo-hàng&quot;&gt;Cách nhìn theo hàng&lt;/h2&gt;

&lt;p&gt;Mỗi phương trình là một điều kiện. Với hai ẩn, mỗi phương trình là một &lt;em&gt;đường thẳng&lt;/em&gt; trong mặt phẳng; với ba ẩn, là một &lt;em&gt;mặt phẳng&lt;/em&gt; trong không gian (Bài 1.3). Nghiệm của hệ là các điểm nằm trên &lt;em&gt;tất cả&lt;/em&gt; các đường (mặt) đó cùng lúc.&lt;/p&gt;

&lt;p&gt;Ở ví dụ mở đầu, đường $2x - y = 1$ đi qua $(0, -1)$ và $(1, 1)$, dốc lên; đường $x + y = 5$ đi qua $(5, 0)$ và $(0, 5)$, dốc xuống. Hai đường cắt nhau tại đúng một điểm $(2, 3)$.&lt;/p&gt;

&lt;p&gt;Hai đường thẳng trong mặt phẳng chỉ có ba vị trí: cắt nhau (một nghiệm), song song (vô nghiệm), trùng nhau (vô số nghiệm). Định lý 2 cho thấy điều này đúng cho mọi hệ.&lt;/p&gt;

&lt;h2 id=&quot;cách-nhìn-theo-cột&quot;&gt;Cách nhìn theo cột&lt;/h2&gt;

&lt;p&gt;Viết lại hệ mở đầu theo cột:&lt;/p&gt;

\[x \begin{bmatrix} 2 \\ 1 \end{bmatrix} + y \begin{bmatrix} -1 \\ 1 \end{bmatrix} = \begin{bmatrix} 1 \\ 5 \end{bmatrix}.\]

&lt;p&gt;Câu hỏi bây giờ là: cần bao nhiêu lần cột thứ nhất và bao nhiêu lần cột thứ hai để tổ hợp thành $b$? Đây chính là câu hỏi $b \in \operatorname{span}$ của Bài 1.4. Đáp số $x = 2$, $y = 3$: đi hai lần mũi tên $(2, 1)$ được $(4, 2)$, rồi ba lần mũi tên $(-1, 1)$ được $(1, 5)$.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 2 (Tích ma trận với vectơ).&lt;/strong&gt; Cho ma trận $A$ cỡ $m \times n$ với các cột $a_1, \dots, a_n \in \mathbb{R}^m$ và $x \in \mathbb{R}^n$. Ta định nghĩa&lt;/p&gt;

  &lt;p&gt;\(Ax = x_1 a_1 + x_2 a_2 + \cdots + x_n a_n .\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Thành phần thứ $i$ của $Ax$ là $a_{i1}x_1 + \cdots + a_{in}x_n$, tức tích vô hướng của hàng $i$ của $A$ với $x$. Như vậy cùng một tích $Ax$ có hai cách tính: theo cột (tổ hợp các cột) và theo hàng (các tích vô hướng). Hai cách nhìn hệ phương trình đến từ đây.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Hai cách nhìn là một).&lt;/strong&gt; Hệ $Ax = b$ có nghiệm khi và chỉ khi $b$ thuộc span các cột của $A$. Hơn nữa $x$ là nghiệm khi và chỉ khi $x_1, \dots, x_n$ là các hệ số của một cách viết $b = x_1 a_1 + \cdots + x_n a_n$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Theo Định nghĩa 2, đẳng thức $Ax = b$ chính là đẳng thức $x_1 a_1 + \cdots + x_n a_n = b$. So sánh thành phần thứ $i$ của hai vế, ta được đúng phương trình thứ $i$ của hệ. Vậy hai điều kiện trùng nhau.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2 (Không có đúng hai nghiệm).&lt;/strong&gt; Nếu hệ $Ax = b$ có hai nghiệm khác nhau thì nó có vô số nghiệm.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Giả sử $Au = b$ và $Av = b$ với $u \ne v$. Với mọi số $t$, đặt $w = u + t(v - u)$. Vì $A(cx + dy) = cAx + dAy$ (kiểm tra trực tiếp từ Định nghĩa 2),&lt;/p&gt;

\[Aw = Au + t(Av - Au) = b + t(b - b) = b .\]

  &lt;p&gt;Các vectơ $w$ khác nhau với các $t$ khác nhau, vì $v - u \ne 0$. Về hình học: cả đường thẳng qua $u$ và $v$ đều là nghiệm.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ&quot;&gt;Ví dụ&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (vô nghiệm).&lt;/strong&gt; Hệ $x + 2y = 3$, $2x + 4y = 5$. Theo hàng: hai đường thẳng có cùng vectơ pháp tuyến hướng $(1, 2)$ nên song song; nhân phương trình đầu với 2 được $2x + 4y = 6 \ne 5$, nên chúng không trùng nhau. Theo cột: hai cột $(1, 2)$ và $(2, 4)$ cùng phương, span là đường $y = 2x$, còn $b = (3, 5)$ không nằm trên đường đó.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3 (ba ẩn).&lt;/strong&gt; Hệ&lt;/p&gt;

\[x + y + z = 6, \qquad 2x + 3y + z = 11, \qquad x - y + 2z = 5\]

  &lt;p&gt;có nghiệm $(1, 2, 3)$ (thay vào để kiểm tra). Theo hàng: ba mặt phẳng trong không gian gặp nhau tại một điểm, giống góc phòng nơi hai bức tường và sàn nhà gặp nhau. Theo cột:&lt;/p&gt;

  &lt;p&gt;\(1\begin{bmatrix}1\\2\\1\end{bmatrix} + 2\begin{bmatrix}1\\3\\-1\end{bmatrix} + 3\begin{bmatrix}1\\1\\2\end{bmatrix} = \begin{bmatrix}6\\11\\5\end{bmatrix}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-đường-cong-qua-các-điểm-dữ-liệu&quot;&gt;Ứng dụng: đường cong qua các điểm dữ liệu&lt;/h2&gt;

&lt;p&gt;Tìm parabol $y = ax^2 + bx + c$ đi qua ba điểm $(1, 2)$, $(2, 3)$, $(3, 6)$. Mỗi điểm cho một phương trình tuyến tính với ẩn $a, b, c$:&lt;/p&gt;

\[a + b + c = 2, \qquad 4a + 2b + c = 3, \qquad 9a + 3b + c = 6.\]

&lt;p&gt;Trừ phương trình đầu khỏi hai phương trình sau: $3a + b = 1$ và $8a + 2b = 4$, tức $4a + b = 2$. Suy ra $a = 1$, $b = -2$, $c = 3$, và parabol là $y = x^2 - 2x + 3$. Phương trình là tuyến tính theo các &lt;em&gt;hệ số&lt;/em&gt; $a, b, c$ dù đường cong không phải đường thẳng. Đây là ý tưởng của nội suy và của hồi quy (Chương 08): phần mềm vẽ đồ thị, mô hình học máy tuyến tính đều đưa về hệ $Ax = b$.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: cách nhìn theo hàng và theo cột&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Sửa hệ 2 × 2, kéo b: giao điểm hai đường thẳng (trái) và cách pha hai cột thành b (phải).&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter02/hang_cot.html&quot; title=&quot;Minh hoạ: cách nhìn theo hàng và theo cột&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter02/hang_cot.html&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-một-hệ-phương-trình-hai-cách-nhìn&quot;&gt;Video ngắn: Một hệ phương trình, hai cách nhìn&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/row-column-picture.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Cách nhìn hàng: hai đường thẳng cắt nhau tại nghiệm. Cách nhìn cột: ghép hai cột để được vế phải. Khi hai cột cùng phương, cả hai cách nhìn cùng suy biến. Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Viết ma trận hệ số và ma trận mở rộng của hệ $3x - z = 2$, $x + y + z = 0$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$A = \begin{bmatrix} 3 &amp;amp; 0 &amp;amp; -1 \\ 1 &amp;amp; 1 &amp;amp; 1 \end{bmatrix}$, $[A \mid b] = \left[\begin{array}{rrr|r} 3 &amp;amp; 0 &amp;amp; -1 &amp;amp; 2 \\ 1 &amp;amp; 1 &amp;amp; 1 &amp;amp; 0 \end{array}\right]$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Tính $Ax$ theo cột và theo hàng với $A = \begin{bmatrix} 1 &amp;amp; 2 \\ 3 &amp;amp; 4 \\ 0 &amp;amp; -1 \end{bmatrix}$, $x = (2, -1)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Theo cột: $2(1, 3, 0) - (2, 4, -1) = (0, 2, 1)$. Theo hàng: $1\cdot 2 + 2 \cdot(-1) = 0$, $3 \cdot 2 + 4 \cdot (-1) = 2$, $0 - (-1) = 1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Với giá trị nào của $k$ thì hệ $x + 2y = 3$, $2x + 4y = k$ có nghiệm? Khi đó có bao nhiêu nghiệm? Giải thích theo cả hai cách nhìn.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$k = 6$, và khi đó có vô số nghiệm $x = 3 - 2t$, $y = t$. Theo hàng: hai đường thẳng trùng nhau. Theo cột: $b = (3, 6)$ nằm trên đường thẳng sinh bởi hai cột cùng phương.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Tìm parabol $y = ax^2 + bx + c$ qua $(0, 1)$, $(1, 0)$, $(2, 3)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$c = 1$; $a + b = -1$; $4a + 2b = 2$. Suy ra $a = 2$, $b = -3$: $y = 2x^2 - 3x + 1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Chứng minh $A(cx + dy) = c\,Ax + d\,Ay$ với mọi $x, y \in \mathbb{R}^n$ và số $c, d$ (đã dùng trong Định lý 2).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Theo Định nghĩa 2, $A(cx + dy) = \sum_j (c x_j + d y_j) a_j = c \sum_j x_j a_j + d \sum_j y_j a_j$, dùng Định lý 1 của Bài 1.1.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Hệ $m$ phương trình $n$ ẩn viết gọn là $Ax = b$; ma trận mở rộng là $[A \mid b]$.&lt;/li&gt;
    &lt;li&gt;Theo hàng: nghiệm là giao của các đường thẳng hoặc mặt phẳng.&lt;/li&gt;
    &lt;li&gt;Theo cột: $Ax = x_1 a_1 + \cdots + x_n a_n$, và hệ có nghiệm khi và chỉ khi $b$ thuộc span các cột.&lt;/li&gt;
    &lt;li&gt;Một hệ tuyến tính chỉ có thể vô nghiệm, có đúng một nghiệm, hoặc có vô số nghiệm.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Rounding errors and pivoting</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter02/02_06_Sai_So_Lam_Tron_Va_Chon_Phan_Tu_Chot/"/>
   <updated>2026-01-02T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter02/02_06_Sai_So_Lam_Tron_Va_Chon_Phan_Tu_Chot</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;explain why a very small pivot makes Gaussian elimination on a computer give wrong answers;&lt;/li&gt;
    &lt;li&gt;perform Gaussian elimination with &lt;em&gt;partial pivoting&lt;/em&gt;;&lt;/li&gt;
    &lt;li&gt;distinguish errors caused by the algorithm (poor pivoting) from errors caused by the problem itself (a matrix with a large condition number).&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;A computer cannot store every real number. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float64&lt;/code&gt; type keeps about 16 significant digits, and every operation is rounded to the nearest representable number. Usually this error is tiny. But try the system&lt;/p&gt;

\[10^{-20} x + y = 1, \qquad x + y = 2 .\]

&lt;p&gt;The exact solution is $x = \dfrac{1}{1 - 10^{-20}} \approx 1$, $y \approx 1$. Gaussian elimination in the given order (pivot $10^{-20}$) in NumPy gives $x = 0$, $y = 1$. Swapping the equations first and then eliminating gives $x = 1$, $y = 1$. Same algorithm, only the row order differs, and one answer is completely wrong.&lt;/p&gt;

&lt;h2 id=&quot;floating-point-numbers&quot;&gt;Floating-point numbers&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Rounding to $t$ digits).&lt;/strong&gt; In floating-point arithmetic with $t$ significant digits, each real number $a$ is replaced by the nearest number $\operatorname{fl}(a)$ of the form $\pm d_1.d_2\ldots d_t \times 10^e$. The relative error satisfies $\lvert \operatorname{fl}(a) - a \rvert \le u\,\lvert a \rvert$ with $u = \tfrac12 10^{1-t}$, the &lt;em&gt;unit roundoff&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;For &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float64&lt;/code&gt; (base 2), $u \approx 1.1 \times 10^{-16}$. An important consequence: adding a small number to a very large one may change nothing. In &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float64&lt;/code&gt;, $10^{20} - 1$ is rounded to exactly $10^{20}$.&lt;/p&gt;

&lt;h2 id=&quot;analysing-the-example&quot;&gt;Analysing the example&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (by hand with 3 digits).&lt;/strong&gt; The system $0.0001\,x + y = 1$, $x + y = 2$ has exact solution $x \approx 1.0001$, $y \approx 0.9999$. Round every intermediate result to 3 significant digits.&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;Without swapping.&lt;/em&gt; The multiplier is $\ell = 1 / 0.0001 = 10^4$. Row two becomes&lt;/p&gt;

\[(1 - 10^4)\, y = 2 - 10^4 \quad\Longrightarrow\quad -1.00\times 10^4\, y = -1.00 \times 10^4 ,\]

  &lt;p&gt;since both $-9999$ and $-9998$ round to $-1.00 \times 10^4$. So $y = 1$, and then $x = (1 - y)/0.0001 = 0$. The information “2” on the right of equation two was swallowed by the subtraction of $10^4$.&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;Swapping first.&lt;/em&gt; The pivot is $1$ and the multiplier $\ell = 0.0001$. Row two: $(1 - 0.0001)\, y = 1 - 0.0002$, rounded to $1.00\, y = 1.00$. So $y = 1$, $x = 2 - y = 1$. The error is only in the fourth digit, exactly the accuracy of 3-digit arithmetic.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Geometry: the lines $0.0001x + y = 1$ and $x + y = 2$ cross clearly, at an angle close to $45^\circ$. The problem is not hard. The trouble is that the algorithm picked a tiny pivot, so the multiplier was huge and amplified the rounding error.&lt;/p&gt;

&lt;h2 id=&quot;partial-pivoting&quot;&gt;Partial pivoting&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 2 (Partial pivoting).&lt;/strong&gt; At each step, when eliminating column $k$, choose among rows $k$ and below the row with the largest $\lvert a_{ik} \rvert$, swap it into position $k$, and then eliminate.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proposition 1.&lt;/strong&gt; With partial pivoting every multiplier $\ell_{ik} = a_{ik}/a_{kk}$ satisfies $\lvert \ell_{ik} \rvert \le 1$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; After the swap, $\lvert a_{kk} \rvert \ge \lvert a_{ik} \rvert$ for every $i &amp;gt; k$, so $\lvert a_{ik} / a_{kk} \rvert \le 1$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Multipliers bounded by 1 mean that no elimination step blows up the entries of the matrix by much. In practice, Gaussian elimination with partial pivoting is stable on almost every matrix one meets; it is the algorithm inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.solve&lt;/code&gt; (through the LAPACK library).&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; Eliminate with pivoting on the augmented matrix&lt;/p&gt;

\[\left[\begin{array}{rr|r} 1 &amp;amp; 2 &amp;amp; 3 \\ 3 &amp;amp; 1 &amp;amp; 4 \end{array}\right].\]

  &lt;p&gt;In column 1, $\lvert 3 \rvert &amp;gt; \lvert 1 \rvert$, so swap: $(3, 1 \mid 4)$ goes on top. The multiplier is $\ell = 1/3$: row two becomes $(0, \tfrac53 \mid \tfrac53)$. Back substitution: $y = 1$, $x = 1$. By hand pivoting is unnecessary, but the habit helps when reading library code.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;when-the-problem-is-to-blame-the-condition-number&quot;&gt;When the problem is to blame: the condition number&lt;/h2&gt;

&lt;p&gt;Pivoting cures errors caused by the algorithm. It cannot cure a problem that is sensitive by nature. If two lines are nearly parallel, a small change in the right-hand side moves their intersection far away. This sensitivity is measured by the &lt;em&gt;condition number&lt;/em&gt; $\kappa(A)$, defined precisely in Chapter 11 through singular values. Rule of thumb: solving $Ax = b$ in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float64&lt;/code&gt; loses about $\log_{10}\kappa(A)$ of the 16 digits.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3 (the Hilbert matrix).&lt;/strong&gt; The $10 \times 10$ Hilbert matrix $H_{ij} = \dfrac{1}{i + j - 1}$ has $\kappa(H) \approx 1.6 \times 10^{13}$. Take $x = (1, \dots, 1)$, compute $b = Hx$, then solve $Hx = b$ again with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.solve&lt;/code&gt; (with pivoting): the largest error is about $2 \times 10^{-4}$. About 13 digits are lost, as predicted.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-engineering-simulation&quot;&gt;Application: engineering simulation&lt;/h2&gt;

&lt;p&gt;Finite-element software (for the strength of bridges, building frames, aircraft wings) solves systems with millions of unknowns. An engineer needs two facts from this lesson: the library already pivots to avoid algorithmic errors, and if the result still swings wildly when the data change very little, the problem lies in the model (a large condition number, say a beam that is barely supported), not in the computer.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: rounding error and pivoting&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Rounding to 3 digits with the pivot 0.0001 gives a wrong answer; turn on partial pivoting to fix it.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter02/khu_gauss.html?preset=round&amp;amp;lang=en&quot; title=&quot;Interactive: rounding error and pivoting&quot; loading=&quot;lazy&quot; style=&quot;height: 680px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter02/khu_gauss.html?preset=round&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-a-small-pivot-ruins-elimination&quot;&gt;Short video: A small pivot ruins elimination&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/pivot-rounding.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;With 3 significant digits, eliminating with the pivot 0.0001 makes the multiplier 10,000 and x comes out wrong by a whole unit. Swapping rows to pick the largest pivot fixes it. Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; In 3-digit arithmetic compute $\operatorname{fl}(1000 + 0.4)$ and $\operatorname{fl}(\operatorname{fl}(1000 + 0.4) - 1000)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$1000.4$ rounds to $1.00 \times 10^3$; the difference is $0$. The $0.4$ is lost.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; With partial pivoting, which row becomes the pivot row in column 1 of a matrix whose first column is $(2, -7, 5)$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Row 2, because $\lvert -7 \rvert$ is largest.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Solve $0.001\,x + y = 1$, $x - y = 0$ in 3-digit arithmetic, first without and then with a row swap. Compare with the exact solution $x = y = 1/1.001 \approx 0.999$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Without swap: $\ell = 1000$, row two $-1.00\times10^3\, y = -1.00 \times 10^3$, $y = 1$, $x = (1 - 1)/0.001 = 0$, completely wrong. With swap: $\ell = 0.001$, row two $1.00\, y = 1.00$, $y = 1$, $x = 1$, wrong only in the third digit.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; Explain why in Example 1 rounding in row two does &lt;em&gt;no&lt;/em&gt; harm once the rows are swapped, even though rounding still happens.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The multiplier $0.0001$ is small, so row two changes only by a tiny amount. The rounding error is at the $10^{-3}$ level for numbers of size $1$, exactly the available accuracy; it is not amplified.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced / programming).&lt;/strong&gt; Implement Gaussian elimination with and without partial pivoting in about 20 lines of NumPy. Compare with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.linalg.solve&lt;/code&gt; on the opening system and on the $8 \times 8$ Hilbert matrix.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Without pivoting the opening system gives $x = 0$. With pivoting it gives $x = 1$, like `solve`. For the $8 \times 8$ Hilbert matrix ($\kappa \approx 1.5 \times 10^{10}$) all three lose about 10 digits: that is the limit of the problem, not of the algorithm.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Computers round every operation; adding a small number to a very large one can lose the small number.&lt;/li&gt;
    &lt;li&gt;A small pivot means a large multiplier, which amplifies rounding errors.&lt;/li&gt;
    &lt;li&gt;Partial pivoting (swap up the row with the largest $\lvert a_{ik} \rvert$) keeps $\lvert \ell_{ik} \rvert \le 1$ and is standard in every library.&lt;/li&gt;
    &lt;li&gt;A matrix with a large condition number still gives inaccurate solutions; that is a property of the problem.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Homogeneous systems and the general solution</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter02/02_05_He_Thuan_Nhat_Va_Nghiem_Tong_Quat/"/>
   <updated>2026-01-02T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter02/02_05_He_Thuan_Nhat_Va_Nghiem_Tong_Quat</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;solve a homogeneous system $Ax = 0$ and write its solution set as the span of explicit vectors;&lt;/li&gt;
    &lt;li&gt;write the general solution of $Ax = b$ as a particular solution plus solutions of the homogeneous system;&lt;/li&gt;
    &lt;li&gt;prove that a homogeneous system with more unknowns than equations has a nonzero solution;&lt;/li&gt;
    &lt;li&gt;explain the structure of the solution set geometrically: a set through the origin, shifted.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;In Lesson 2.4, the system $x + 3y + z = 9$, $x + y - z = 1$, $3x + 11y + 5z = 35$ has solutions&lt;/p&gt;

\[(x, y, z) = (-3, 4, 0) + t\,(2, -1, 1).\]

&lt;p&gt;Substitute the vector $(2, -1, 1)$ into the left-hand sides: $2 - 3 + 1 = 0$, $2 - 1 - 1 = 0$, $6 - 11 + 5 = 0$. It solves the system with the same left-hand side but &lt;em&gt;right-hand side 0&lt;/em&gt;. And $(-3, 4, 0)$ is one solution of the original system. The general solution is “one solution plus every solution of the homogeneous system”. This lesson proves that this is always so.&lt;/p&gt;

&lt;h2 id=&quot;homogeneous-systems&quot;&gt;Homogeneous systems&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Homogeneous system).&lt;/strong&gt; The system $Ax = 0$ is &lt;em&gt;homogeneous&lt;/em&gt;. It always has the &lt;em&gt;trivial solution&lt;/em&gt; $x = 0$. Its solution set is the &lt;em&gt;null space&lt;/em&gt; (or &lt;em&gt;kernel&lt;/em&gt;) of $A$, written $\operatorname{Nul} A$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; If $u, v \in \operatorname{Nul} A$ and $c$ is a real number, then $u + v \in \operatorname{Nul} A$ and $c\,u \in \operatorname{Nul} A$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; $A(u + v) = Au + Av = 0 + 0 = 0$ and $A(cu) = c\,Au = 0$, using the property $A(cx + dy) = c\,Ax + d\,Ay$ from Lesson 2.1.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;So $\operatorname{Nul} A$ contains $0$ and is closed under both operations: it is a subspace. Elimination shows it is always the span of explicit vectors.&lt;/p&gt;

&lt;h3 id=&quot;writing-operatornamenul-a-as-a-span&quot;&gt;Writing $\operatorname{Nul} A$ as a span&lt;/h3&gt;

&lt;p&gt;Bring $A$ to reduced echelon form. Express each pivot variable through the free variables. Write the solution as a sum, each free variable times a vector. Those vectors span $\operatorname{Nul} A$, and their number equals the number of free variables, $n - \operatorname{rank} A$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; Let&lt;/p&gt;

\[A = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 1 &amp;amp; 1 \\ 2 &amp;amp; 4 &amp;amp; 3 &amp;amp; 4 \\ 1 &amp;amp; 2 &amp;amp; 2 &amp;amp; 3 \end{bmatrix}
\quad\longrightarrow\quad
\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 &amp;amp; -1 \\ 0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 2 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \end{bmatrix}.\]

  &lt;p&gt;Pivot columns are 1 and 3; the free variables are $x_2 = s$, $x_4 = t$. From the two rows: $x_1 = -2s + t$, $x_3 = -2t$. Hence&lt;/p&gt;

\[x = s \begin{bmatrix} -2 \\ 1 \\ 0 \\ 0 \end{bmatrix} + t \begin{bmatrix} 1 \\ 0 \\ -2 \\ 1 \end{bmatrix},
\qquad \operatorname{Nul} A = \operatorname{span}\{(-2, 1, 0, 0),\ (1, 0, -2, 1)\}.\]

  &lt;p&gt;These two vectors are independent: look at components 2 and 4; only the first vector has a 1 in position 2, only the second has a 1 in position 4. The null space is a “plane” through the origin in $\mathbb{R}^4$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2 (More unknowns than equations).&lt;/strong&gt; A homogeneous system of $m$ equations in $n$ unknowns with $m &amp;lt; n$ always has a nonzero solution.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; A homogeneous system is always consistent. By Corollary 1 of Lesson 2.4, since $m &amp;lt; n$ there is at least one free variable. Set it to 1 and the other free variables to 0 to get a nonzero solution.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Theorem 2 completes the proof of Theorem 3 in Lesson 1.5: $k &amp;gt; n$ vectors in $\mathbb{R}^n$ are always dependent, because $c_1 v_1 + \cdots + c_k v_k = 0$ is a homogeneous system of $n$ equations in $k$ unknowns.&lt;/p&gt;

&lt;h2 id=&quot;the-general-solution-of-a-non-homogeneous-system&quot;&gt;The general solution of a non-homogeneous system&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 3 (Structure of the solution set).&lt;/strong&gt; Let $x_p$ be one solution of $Ax = b$ (a &lt;em&gt;particular solution&lt;/em&gt;). Then the solution set of $Ax = b$ is&lt;/p&gt;

  &lt;p&gt;\(\{\, x_p + x_h : x_h \in \operatorname{Nul} A \,\}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; If $x_h \in \operatorname{Nul} A$ then $A(x_p + x_h) = b + 0 = b$, so $x_p + x_h$ is a solution. Conversely, if $Ax = b$ then $A(x - x_p) = b - b = 0$, so $x_h = x - x_p$ lies in $\operatorname{Nul} A$ and $x = x_p + x_h$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Geometry: the solution set of $Ax = b$ is $\operatorname{Nul} A$ &lt;em&gt;translated&lt;/em&gt; by a vector $x_p$. In $\mathbb{R}^3$, if $\operatorname{Nul} A$ is a line through the origin, the solution set of $Ax = b$ is a parallel line; if $\operatorname{Nul} A = \{0\}$ the solution is unique. Changing the right-hand side $b$ only moves the solution set; it does not change its shape.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; With $A$ from Example 1 and $b = (3, 8, 5)$, the reduced echelon form of $[A \mid b]$ has two nonzero rows: $x_1 + 2x_2 - x_4 = 1$ and $x_3 + 2x_4 = 2$. Setting the free variables to 0 gives the particular solution $x_p = (1, 0, 2, 0)$. Check: $1 + 2 = 3$, $2 + 6 = 8$, $1 + 4 = 5$. General solution:&lt;/p&gt;

  &lt;p&gt;\(x = (1, 0, 2, 0) + s\,(-2, 1, 0, 0) + t\,(1, 0, -2, 1).\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3.&lt;/strong&gt; The system $x + y + z = 0$, $x - y + 2z = 0$ (two planes through the origin). Free variable $z = t$: adding the equations gives $2x + 3z = 0$, so $x = -\tfrac32 t$, $y = \tfrac12 t$. The null space is the line $\operatorname{span}\{(-3, 1, 2)\}$, the intersection line of the two planes. Changing the right-hand side to $(1, 0)$ moves the intersection line but keeps it parallel to $(-3, 1, 2)$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-the-same-structure-in-differential-equations&quot;&gt;Application: the same structure in differential equations&lt;/h2&gt;

&lt;p&gt;The differential equation $y&apos;&apos; + y = 1$ has the particular solution $y_p = 1$. The homogeneous equation $y&apos;&apos; + y = 0$ has the solutions $c_1 \cos t + c_2 \sin t$. The general solution is&lt;/p&gt;

\[y = 1 + c_1 \cos t + c_2 \sin t .\]

&lt;p&gt;The reason is exactly Theorem 3: the map $y \mapsto y&apos;&apos; + y$ is “linear” like $x \mapsto Ax$, i.e. it respects addition and scalar multiplication. The Differential Equations course uses this “particular + homogeneous” structure throughout. In engineering, the homogeneous solution describes the free vibration of a system and the particular solution its response to an external force.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: homogeneous systems and the general solution&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;A homogeneous system always has the zero solution; general solution = particular solution + combination of Nul A vectors.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter02/khu_gauss.html?preset=hom&amp;amp;lang=en&quot; title=&quot;Interactive: homogeneous systems and the general solution&quot; loading=&quot;lazy&quot; style=&quot;height: 680px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter02/khu_gauss.html?preset=hom&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Write $\operatorname{Nul} A$ as a span for $A = \begin{bmatrix} 1 &amp;amp; -1 &amp;amp; 2 \\ 2 &amp;amp; -2 &amp;amp; 4 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Rank 1, two free variables $x_2 = s$, $x_3 = t$: $x_1 = s - 2t$. $\operatorname{Nul} A = \operatorname{span}\{(1, 1, 0), (-2, 0, 1)\}$, a plane through the origin.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Suppose $x_p = (1, 1)$ solves $Ax = b$ and $\operatorname{Nul} A = \operatorname{span}\{(2, -1)\}$. Write the general solution and give another solution.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$x = (1, 1) + t(2, -1)$. With $t = 1$: $(3, 0)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Solve $x_1 + 2x_2 - x_3 = 4$, $2x_1 + 4x_2 + x_3 = 5$ and write the solution as $x_p + x_h$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$R_2 \to R_2 - 2R_1$: $3x_3 = -3$, $x_3 = -1$. Then $x_1 + 2x_2 = 3$. With $x_2 = t$: $x = (3, 0, -1) + t(-2, 1, 0)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; Prove: if $x_1$ and $x_2$ solve $Ax = b$, then $x_1 - x_2 \in \operatorname{Nul} A$, but $x_1 + x_2$ solves $Ax = 2b$, not $Ax = b$ (when $b \ne 0$).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A(x_1 - x_2) = b - b = 0$ and $A(x_1 + x_2) = 2b \ne b$. That is why the solution set of a non-homogeneous system is not a subspace.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced / programming).&lt;/strong&gt; Use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sympy.Matrix(A).nullspace()&lt;/code&gt; with $A$ from Example 1 and compare with the hand-computed vectors. Then use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scipy.linalg.null_space(A)&lt;/code&gt; (floating point) and check that its columns span the same space.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

SymPy returns exactly $(-2, 1, 0, 0)$ and $(1, 0, -2, 1)$. SciPy returns two different orthonormal vectors (computed from the SVD, Chapter 11). Each SciPy vector is a combination of the two SymPy vectors and vice versa; check that the matrix of all four columns still has rank 2.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$\operatorname{Nul} A$ is the solution set of $Ax = 0$; it contains $0$, is closed under addition and scaling, and is the span of $n - \operatorname{rank} A$ vectors read off from the reduced echelon form.&lt;/li&gt;
    &lt;li&gt;A homogeneous system with more unknowns than equations always has a nonzero solution.&lt;/li&gt;
    &lt;li&gt;The general solution of $Ax = b$ is $x_p + x_h$ with $x_h \in \operatorname{Nul} A$: the solution set is $\operatorname{Nul} A$ shifted.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Number of solutions, free variables and rank</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter02/02_04_So_Nghiem_Bien_Tu_Do_Va_Hang/"/>
   <updated>2026-01-02T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter02/02_04_So_Nghiem_Bien_Tu_Do_Va_Hang</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;find the rank of a matrix, the pivot variables and the free variables from echelon form;&lt;/li&gt;
    &lt;li&gt;use the Rouché–Capelli (Kronecker–Capelli) theorem to decide whether a system has no solution, exactly one, or infinitely many;&lt;/li&gt;
    &lt;li&gt;write the general solution with parameters when there are infinitely many solutions;&lt;/li&gt;
    &lt;li&gt;analyse systems that depend on a parameter.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Elimination on the system $x + 3y + z = 9$, $x + y - z = 1$, $3x + 11y + 5z = 35$ gives the reduced echelon form&lt;/p&gt;

\[\left[\begin{array}{rrr|r} 1 &amp;amp; 0 &amp;amp; -2 &amp;amp; -3 \\ 0 &amp;amp; 1 &amp;amp; 1 &amp;amp; 4 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \end{array}\right].\]

&lt;p&gt;The last row says $0 = 0$: always true, no information. Only two equations $x - 2z = -3$ and $y + z = 4$ remain for three unknowns. The unknown $z$ is unconstrained: choose $z = t$ freely, then $x = -3 + 2t$, $y = 4 - t$. The system has infinitely many solutions lying on a line in $\mathbb{R}^3$. This lesson turns that observation into a general rule.&lt;/p&gt;

&lt;h2 id=&quot;rank-pivot-variables-and-free-variables&quot;&gt;Rank, pivot variables and free variables&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Rank).&lt;/strong&gt; The &lt;em&gt;rank&lt;/em&gt; of a matrix $A$, written $\operatorname{rank} A$, is the number of pivots in an echelon form of $A$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;By Theorem 2 of Lesson 2.3 the pivot positions do not depend on how we eliminate, so the rank is well defined. The rank is at most the number of rows and at most the number of columns, since each row and each column contains at most one pivot.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 2 (Pivot and free variables).&lt;/strong&gt; Consider the system $Ax = b$ and an echelon form of $[A \mid b]$. An unknown $x_j$ corresponding to a pivot column of $A$ is a &lt;em&gt;pivot variable&lt;/em&gt; (basic variable). The other unknowns are &lt;em&gt;free variables&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;In the opening example columns 1 and 2 are pivot columns, so $x, y$ are pivot variables and $z$ is free. The rank of $A$ is 2.&lt;/p&gt;

&lt;h2 id=&quot;the-theorem-on-the-number-of-solutions&quot;&gt;The theorem on the number of solutions&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Rouché–Capelli).&lt;/strong&gt; Let $A$ be $m \times n$ and consider $Ax = b$.&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;The system is consistent if and only if $\operatorname{rank} A = \operatorname{rank}\,[A \mid b]$, i.e. the last column of the echelon form contains no pivot.&lt;/li&gt;
    &lt;li&gt;If the system is consistent: when $\operatorname{rank} A = n$ the solution is unique; when $\operatorname{rank} A &amp;lt; n$ there are infinitely many solutions, and the general solution has exactly $n - \operatorname{rank} A$ parameters.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; By Lesson 2.2 we may replace the system by the one given by the reduced echelon form of $[A \mid b]$.&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;Part 1.&lt;/em&gt; If the last column has a pivot, its row reads $(0, \dots, 0 \mid 1)$, the equation $0 = 1$, so there is no solution. In that case $\operatorname{rank}[A \mid b] = \operatorname{rank} A + 1$. If the last column has no pivot, the two ranks agree. Give each free variable an arbitrary value; every nonzero row has the form “pivot variable $+$ (combination of free variables) $=$ number”, so the pivot variables can be computed. That is a solution.&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;Part 2.&lt;/em&gt; Also from the reduced form: every solution arises exactly in this way, and different values of the free variables give different solutions. The number of free variables is $n - \operatorname{rank} A$. If it is 0 there is exactly one solution; if it is positive there are infinitely many.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Corollary 1.&lt;/strong&gt; A system with fewer equations than unknowns ($m &amp;lt; n$) has either no solution or infinitely many.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; $\operatorname{rank} A \le m &amp;lt; n$, so if a solution exists there is at least one free variable.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;examples&quot;&gt;Examples&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (rank of a $4 \times 5$ matrix).&lt;/strong&gt; The matrix&lt;/p&gt;

\[B = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; -1 &amp;amp; 3 &amp;amp; 1 \\ 2 &amp;amp; 4 &amp;amp; 0 &amp;amp; 2 &amp;amp; 6 \\ 1 &amp;amp; 2 &amp;amp; 1 &amp;amp; -1 &amp;amp; 5 \\ 3 &amp;amp; 6 &amp;amp; -1 &amp;amp; 5 &amp;amp; 7 \end{bmatrix}\]

  &lt;p&gt;has reduced echelon form&lt;/p&gt;

\[\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 &amp;amp; 1 &amp;amp; 3 \\ 0 &amp;amp; 0 &amp;amp; 1 &amp;amp; -2 &amp;amp; 2 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \end{bmatrix}.\]

  &lt;p&gt;There are two pivots (columns 1 and 3), so $\operatorname{rank} B = 2$. The four rows of $B$ “contain” only two independent equations: for instance row 4 equals row 1 plus row 2.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (a parameter).&lt;/strong&gt; Discuss the number of solutions of&lt;/p&gt;

\[x + y + z = 1, \qquad x + 2y + m z = 2, \qquad 2x + 3y + 4z = m + 1 .\]

  &lt;p&gt;Do $R_2 \to R_2 - R_1$, $R_3 \to R_3 - 2R_1$, then $R_3 \to R_3 - R_2$:&lt;/p&gt;

\[\left[\begin{array}{ccc|c} 1 &amp;amp; 1 &amp;amp; 1 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; m - 1 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 3 - m &amp;amp; m - 2 \end{array}\right].\]

  &lt;ul&gt;
    &lt;li&gt;If $m \ne 3$: three pivots, $\operatorname{rank} A = 3 = n$, a unique solution with $z = \dfrac{m - 2}{3 - m}$. For example $m = 2$ gives $(x, y, z) = (0, 1, 0)$.&lt;/li&gt;
    &lt;li&gt;If $m = 3$: the last row is $(0, 0, 0 \mid 1)$, i.e. $0 = 1$. No solution: $\operatorname{rank} A = 2 &amp;lt; 3 = \operatorname{rank}[A \mid b]$.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Geometry: for $m = 3$ the three planes meet pairwise in three parallel lines, like the three faces of a triangular prism, and have no common point.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3.&lt;/strong&gt; The opening system: $\operatorname{rank} A = \operatorname{rank}[A \mid b] = 2 &amp;lt; 3$, so infinitely many solutions with $3 - 2 = 1$ parameter:&lt;/p&gt;

\[(x, y, z) = (-3, 4, 0) + t\,(2, -1, 1).\]

  &lt;p&gt;This is a parametric equation of a line (Lesson 1.3): the common intersection line of the three planes.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-traffic-flow&quot;&gt;Application: traffic flow&lt;/h2&gt;

&lt;p&gt;A roundabout has three junctions $A, B, C$. Cars enter at $A$ at 300 cars/hour, leave at $B$ at 100 cars/hour and leave at $C$ at 200 cars/hour. Let $x_1$ be the flow $A \to B$, $x_2$ the flow $B \to C$, $x_3$ the flow $A \to C$. Conservation of flow at each junction (in equals out):&lt;/p&gt;

\[A:\ x_1 + x_3 = 300, \qquad B:\ x_1 = x_2 + 100, \qquad C:\ x_2 + x_3 = 200 .\]

&lt;p&gt;The coefficient matrix has rank 2 (equation $C$ follows from the other two), so there is one free variable: $x_3 = t$, $x_1 = 300 - t$, $x_2 = 200 - t$. A traffic engineer can choose $t$, for instance close the road $A \to C$ for repairs ($t = 0$), and immediately knows the other two roads must carry 300 and 200 cars/hour. The conditions $x_i \ge 0$ add $0 \le t \le 200$.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: number of solutions, free variables and rank&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Pick the no-solution, unique or infinitely-many examples; see the rank and the general solution.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter02/khu_gauss.html?preset=inf&amp;amp;lang=en&quot; title=&quot;Interactive: number of solutions, free variables and rank&quot; loading=&quot;lazy&quot; style=&quot;height: 680px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter02/khu_gauss.html?preset=inf&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Find the rank of $\begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 3 \\ 2 &amp;amp; 4 &amp;amp; 6 \\ 1 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Row 2 is twice row 1; rows 1 and 3 are not proportional. The rank is 2.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; A consistent system of 5 equations in 7 unknowns has a coefficient matrix of rank 4. How many parameters does the general solution have?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$7 - 4 = 3$ parameters.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Discuss in terms of $k$: $x + y + z = 1$, $x + 2y + 3z = 2$, $2x + 3y + 4z = k$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Row 3 minus rows 1 and 2 gives $0 = k - 3$. If $k \ne 3$: no solution. If $k = 3$: infinitely many solutions $(x, y, z) = (t, 1 - 2t, t)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; Prove: if a system of $n$ equations in $n$ unknowns has a unique solution for &lt;em&gt;one&lt;/em&gt; right-hand side $b$, then it has a unique solution for &lt;em&gt;every&lt;/em&gt; right-hand side.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

A unique solution forces $\operatorname{rank} A = n$, so every row has a pivot. Then the last column of $[A \mid b&apos;]$ cannot contain a pivot for any $b&apos;$, and there are still no free variables.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced / programming).&lt;/strong&gt; Use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sympy.Matrix(...).rref()&lt;/code&gt; on Example 2 with $m$ as a symbol. Why can SymPy give a wrong answer for the special value $m = 3$ if we are not careful?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

During elimination SymPy may divide by $3 - m$ without treating $3 - m = 0$ separately, so the result is only valid for &quot;generic&quot; $m$. Split the cases yourself: substitute $m = 3$ and eliminate again.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;The rank is the number of pivots; pivot variables correspond to pivot columns, the other unknowns are free.&lt;/li&gt;
    &lt;li&gt;Consistent if and only if $\operatorname{rank} A = \operatorname{rank}[A \mid b]$.&lt;/li&gt;
    &lt;li&gt;When consistent: unique if $\operatorname{rank} A = n$; infinitely many if $\operatorname{rank} A &amp;lt; n$, with $n - \operatorname{rank} A$ parameters.&lt;/li&gt;
    &lt;li&gt;Fewer equations than unknowns never gives a unique solution.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Gaussian and Gauss–Jordan elimination</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter02/02_03_Khu_Gauss_Va_Gauss_Jordan/"/>
   <updated>2026-01-02T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter02/02_03_Khu_Gauss_Va_Gauss_Jordan</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;recognise matrices in echelon form and reduced echelon form, and point out the pivots;&lt;/li&gt;
    &lt;li&gt;bring a matrix to echelon form by Gaussian elimination and solve a system by back substitution;&lt;/li&gt;
    &lt;li&gt;bring a matrix to reduced echelon form by Gauss–Jordan and read off the solution;&lt;/li&gt;
    &lt;li&gt;estimate the number of operations in Gaussian elimination.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Solve&lt;/p&gt;

\[x + y + z = 6, \qquad 2x + 3y + z = 11, \qquad x - y + 2z = 5 .\]

&lt;p&gt;Idea: use the first equation to remove $x$ from the other two, then use the new second equation to remove $y$ from the third. The last equation contains only $z$. Solve for $z$, then work back up to get $y$ and $x$. This is &lt;em&gt;Gaussian elimination&lt;/em&gt;. This lesson turns it into an algorithm that works for every system.&lt;/p&gt;

&lt;h2 id=&quot;echelon-form&quot;&gt;Echelon form&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Echelon form).&lt;/strong&gt; A matrix is in (row) &lt;em&gt;echelon form&lt;/em&gt; if:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;all zero rows (if any) are at the bottom;&lt;/li&gt;
    &lt;li&gt;in each nonzero row, the first nonzero entry from the left (the &lt;em&gt;pivot&lt;/em&gt;) lies in a column to the right of the pivot of the row above.&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;A column containing a pivot is a &lt;em&gt;pivot column&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Visually: the pivots form a staircase going down from left to right, and every entry below each step is 0.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 2 (Reduced echelon form).&lt;/strong&gt; A matrix in echelon form is in &lt;em&gt;reduced echelon form&lt;/em&gt; if in addition:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;every pivot equals 1;&lt;/li&gt;
    &lt;li&gt;in each pivot column, all other entries (above and below the pivot) are 0.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;p&gt;For example, the first matrix below is in echelon form and the second is in reduced echelon form:&lt;/p&gt;

\[\begin{bmatrix} 2 &amp;amp; 1 &amp;amp; -1 &amp;amp; 8 \\ 0 &amp;amp; 3 &amp;amp; 5 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 4 \end{bmatrix}, \qquad
\begin{bmatrix} 1 &amp;amp; 0 &amp;amp; -2 &amp;amp; -3 \\ 0 &amp;amp; 1 &amp;amp; 1 &amp;amp; 4 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \end{bmatrix}.\]

&lt;h2 id=&quot;the-gaussian-elimination-algorithm&quot;&gt;The Gaussian elimination algorithm&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; Every matrix is row equivalent to a matrix in echelon form.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof (this is the algorithm).&lt;/strong&gt; Induction on the number of rows. If the matrix is zero it is already in echelon form. Otherwise:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;Find the first nonzero column from the left. Choose a row with a nonzero entry in that column and swap it to the top. That entry is the pivot $p$.&lt;/li&gt;
    &lt;li&gt;For each row $i$ below with entry $a$ in the pivot column, do $R_i \to R_i - \tfrac{a}{p} R_1$. Afterwards every entry below $p$ is 0.&lt;/li&gt;
    &lt;li&gt;Set the top row aside and apply the induction hypothesis to the submatrix of the remaining rows. Operations on the submatrix do not touch the top row and do not spoil the zeros created in the pivot column, since all rows of the submatrix have 0 there.&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;The top row together with the submatrix in echelon form is in echelon form: the pivots of the lower rows lie to the right of $p$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Once in echelon form, we solve from the last equation upwards: &lt;em&gt;back substitution&lt;/em&gt;.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; The opening system:&lt;/p&gt;

\[\left[\begin{array}{rrr|r} 1 &amp;amp; 1 &amp;amp; 1 &amp;amp; 6 \\ 2 &amp;amp; 3 &amp;amp; 1 &amp;amp; 11 \\ 1 &amp;amp; -1 &amp;amp; 2 &amp;amp; 5 \end{array}\right]
\xrightarrow[R_3 \to R_3 - R_1]{R_2 \to R_2 - 2R_1}
\left[\begin{array}{rrr|r} 1 &amp;amp; 1 &amp;amp; 1 &amp;amp; 6 \\ 0 &amp;amp; 1 &amp;amp; -1 &amp;amp; -1 \\ 0 &amp;amp; -2 &amp;amp; 1 &amp;amp; -1 \end{array}\right]
\xrightarrow{R_3 \to R_3 + 2R_2}
\left[\begin{array}{rrr|r} 1 &amp;amp; 1 &amp;amp; 1 &amp;amp; 6 \\ 0 &amp;amp; 1 &amp;amp; -1 &amp;amp; -1 \\ 0 &amp;amp; 0 &amp;amp; -1 &amp;amp; -3 \end{array}\right].\]

  &lt;p&gt;Back substitution: $-z = -3$ so $z = 3$; $y - z = -1$ so $y = 2$; $x + y + z = 6$ so $x = 1$. Solution $(1, 2, 3)$.&lt;/p&gt;

  &lt;p&gt;Geometry: at each step the three planes are replaced by three other planes still passing through $(1, 2, 3)$. The final plane $z = 3$ is horizontal, and the second plane $y - z = -1$ is parallel to the $x$-axis.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;gaussjordan&quot;&gt;Gauss–Jordan&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Gauss–Jordan&lt;/em&gt; continues from echelon form: divide each row by its pivot to make the pivots 1, then clear the entries &lt;em&gt;above&lt;/em&gt; each pivot, working from right to left. The result is the reduced echelon form, from which the solution is read off without back substitution.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; Continue Example 1. Do $R_3 \to -R_3$ to get row three $(0, 0, 1 \mid 3)$. Then&lt;/p&gt;

\[\xrightarrow[R_1 \to R_1 - R_3]{R_2 \to R_2 + R_3}
\left[\begin{array}{rrr|r} 1 &amp;amp; 1 &amp;amp; 0 &amp;amp; 3 \\ 0 &amp;amp; 1 &amp;amp; 0 &amp;amp; 2 \\ 0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 3 \end{array}\right]
\xrightarrow{R_1 \to R_1 - R_2}
\left[\begin{array}{rrr|r} 1 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; 0 &amp;amp; 2 \\ 0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 3 \end{array}\right].\]

  &lt;p&gt;The last column is the solution.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3 (pivot different from 1).&lt;/strong&gt; The system $2x + y - z = 8$, $-3x - y + 2z = -11$, $-2x + y + 2z = -3$. Eliminate with pivot $2$:&lt;/p&gt;

\[\xrightarrow[R_3 \to R_3 + R_1]{R_2 \to R_2 + \frac32 R_1}
\left[\begin{array}{rrr|r} 2 &amp;amp; 1 &amp;amp; -1 &amp;amp; 8 \\ 0 &amp;amp; \tfrac12 &amp;amp; \tfrac12 &amp;amp; 1 \\ 0 &amp;amp; 2 &amp;amp; 1 &amp;amp; 5 \end{array}\right]
\xrightarrow{R_3 \to R_3 - 4R_2}
\left[\begin{array}{rrr|r} 2 &amp;amp; 1 &amp;amp; -1 &amp;amp; 8 \\ 0 &amp;amp; \tfrac12 &amp;amp; \tfrac12 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; -1 &amp;amp; 1 \end{array}\right].\]

  &lt;p&gt;Back substitution: $z = -1$; $\tfrac12 y - \tfrac12 = 1$ so $y = 3$; $2x + 3 + 1 = 8$ so $x = 2$. Solution $(2, 3, -1)$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2 (Uniqueness of the reduced echelon form).&lt;/strong&gt; Every matrix is row equivalent to exactly one matrix in reduced echelon form.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;We accept this theorem without full proof. (Idea: two row-equivalent reduced matrices have the same solution set for the homogeneous system, and from that set one can read back the pivot positions and the non-pivot entries.) An important consequence: the positions of the pivot columns depend only on the original matrix, not on how we eliminate. Their number will be the &lt;em&gt;rank&lt;/em&gt; in Lesson 2.4. An echelon form that is not reduced is not unique: doubling a row still gives an echelon form.&lt;/p&gt;

&lt;h2 id=&quot;operation-count&quot;&gt;Operation count&lt;/h2&gt;

&lt;p&gt;For an $n \times n$ system, eliminating the first column updates $n - 1$ rows of about $n$ entries each: about $n^2$ multiplications. The second column takes about $(n-1)^2$, and so on. In total about&lt;/p&gt;

\[n^2 + (n-1)^2 + \cdots + 1^2 \approx \frac{n^3}{3}\]

&lt;p&gt;multiplications (and as many additions), while back substitution needs only about $n^2/2$. For $n = 1000$, Gaussian elimination needs about $3 \times 10^8$ multiplications, which a laptop does in under a second. Doubling $n$ multiplies the time by about 8.&lt;/p&gt;

&lt;h2 id=&quot;application-balancing-chemical-equations&quot;&gt;Application: balancing chemical equations&lt;/h2&gt;

&lt;p&gt;Balance $a\,\mathrm{C_3H_8} + b\,\mathrm{O_2} \to c\,\mathrm{CO_2} + d\,\mathrm{H_2O}$. Count each element on both sides:&lt;/p&gt;

\[\text{C: } 3a = c, \qquad \text{H: } 8a = 2d, \qquad \text{O: } 2b = 2c + d .\]

&lt;p&gt;This is a homogeneous system of 3 equations in 4 unknowns. Elimination gives the reduced form with $d$ free: $a = d/4$, $b = 5d/4$, $c = 3d/4$. Choose $d = 4$ for the smallest integers: $\mathrm{C_3H_8} + 5\,\mathrm{O_2} \to 3\,\mathrm{CO_2} + 4\,\mathrm{H_2O}$. Chemistry software balances equations exactly this way.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: Gauss and Gauss–Jordan elimination&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Forward elimination to echelon form, then on to reduced echelon form.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter02/khu_gauss.html?preset=u&amp;amp;lang=en&quot; title=&quot;Interactive: Gauss and Gauss–Jordan elimination&quot; loading=&quot;lazy&quot; style=&quot;height: 680px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter02/khu_gauss.html?preset=u&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Solve by Gauss–Jordan: $x - 2y + z = 0$, $2y - 8z = 8$, $5x - 5z = 10$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$(x, y, z) = (1, 0, -1)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Which matrices are in echelon form, in reduced echelon form? $\begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 2 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$, $\begin{bmatrix} 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix}$, $\begin{bmatrix} 1 &amp;amp; 3 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The first is in echelon form but not reduced (the 2 sits above the pivot in column 3). The second is not in echelon form. The third is in reduced echelon form.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Balance $a\,\mathrm{Al} + b\,\mathrm{O_2} \to c\,\mathrm{Al_2O_3}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Al: $a = 2c$; O: $2b = 3c$. With $c = 2$: $a = 4$, $b = 3$, i.e. $4\,\mathrm{Al} + 3\,\mathrm{O_2} \to 2\,\mathrm{Al_2O_3}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; Count exactly the multiplications and divisions in the elimination phase (without back substitution) for a general $3 \times 4$ augmented matrix, skipping nothing.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Column 1: 2 rows, each with 1 division for the multiplier and 3 multiplications: 8. Column 2: 1 row, 1 division and 2 multiplications: 3. Total 11.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced / programming).&lt;/strong&gt; Write a Python function &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rref(M)&lt;/code&gt; using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fractions.Fraction&lt;/code&gt; that brings a matrix to reduced echelon form. Test it on Example 1 and compare with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sympy.Matrix(...).rref()&lt;/code&gt;.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The function scans the columns, finds a pivot row from the current row down, swaps, divides the row by the pivot, then clears that column in *every* other row. On Example 1 it must return a matrix with last column $(1, 2, 3)$ and pivot columns $(0, 1, 2)$, matching SymPy.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Echelon form: pivots step down from left to right, zeros below the pivots. Reduced form: in addition pivots are 1 and each pivot column has a single nonzero entry.&lt;/li&gt;
    &lt;li&gt;Gaussian elimination brings every matrix to echelon form; back substitution gives the solution.&lt;/li&gt;
    &lt;li&gt;Gauss–Jordan gives the reduced echelon form, which is unique; the pivot positions do not depend on how we eliminate.&lt;/li&gt;
    &lt;li&gt;Gaussian elimination for an $n \times n$ system costs about $n^3/3$ multiplications.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Elementary row operations</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter02/02_02_Phep_Bien_Doi_So_Cap_Tren_Hang/"/>
   <updated>2026-01-02T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter02/02_02_Phep_Bien_Doi_So_Cap_Tren_Hang</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;perform the three elementary row operations on an augmented matrix and record them with standard notation;&lt;/li&gt;
    &lt;li&gt;prove that these operations do not change the solution set;&lt;/li&gt;
    &lt;li&gt;know that each operation has an inverse of the same type.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;When solving $x + y = 5$, $2x - y = 1$ at school we usually do three things: swap two equations, multiply an equation by a nonzero number, add a multiple of one equation to another. For instance, subtracting twice the first equation from the second gives $-3y = -9$, so $y = 3$ and then $x = 2$.&lt;/p&gt;

&lt;p&gt;Question: why does this neither lose solutions nor create new ones? This lesson answers that question, and from now on we work with the augmented matrix instead of copying the whole system.&lt;/p&gt;

&lt;h2 id=&quot;the-three-elementary-operations&quot;&gt;The three elementary operations&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Elementary row operations).&lt;/strong&gt; On a matrix, the following three operations are the &lt;em&gt;elementary row operations&lt;/em&gt;:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;&lt;strong&gt;Swap&lt;/strong&gt; rows $i$ and $j$, written $R_i \leftrightarrow R_j$.&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Scale&lt;/strong&gt; row $i$ by a number $c \ne 0$, written $R_i \to c R_i$.&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Add&lt;/strong&gt; to row $i$ a multiple $c$ of row $j$ ($j \ne i$), written $R_i \to R_i + c R_j$.&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;Two matrices are &lt;em&gt;row equivalent&lt;/em&gt; if one can be turned into the other by a finite sequence of elementary row operations.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The condition $c \ne 0$ in operation 2 is essential. Multiplying an equation by 0 deletes it, and the solution set may grow.&lt;/p&gt;

&lt;div class=&quot;textbook-lemma&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Lemma 1 (Each operation has an inverse).&lt;/strong&gt; Each elementary row operation can be undone by an elementary row operation of the same type:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$R_i \leftrightarrow R_j$ is its own inverse;&lt;/li&gt;
    &lt;li&gt;$R_i \to c R_i$ is undone by $R_i \to \tfrac1c R_i$;&lt;/li&gt;
    &lt;li&gt;$R_i \to R_i + c R_j$ is undone by $R_i \to R_i - c R_j$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; The first two cases are clear. In the third case, $R_i \to R_i + cR_j$ leaves row $j$ unchanged, so subtracting $c$ times row $j$ (still the same) afterwards returns row $i$ to its original value.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;the-solution-set-does-not-change&quot;&gt;The solution set does not change&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; If the augmented matrices $[A \mid b]$ and $[A&apos; \mid b&apos;]$ are row equivalent, then the systems $Ax = b$ and $A&apos;x = b&apos;$ have the same solution set.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; It suffices to consider one operation. Let $S$ be the solution set of the old system and $S&apos;$ that of the new one.&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;$S \subseteq S&apos;$.&lt;/em&gt; Take $x \in S$. Each equation of the new system is an old equation (operation 1), or $c$ times an old equation (operation 2), or the sum of equation $i$ and $c$ times equation $j$ (operation 3). Since $x$ satisfies the old equations, it satisfies the new ones: for operation 3, if $r_i \cdot x = b_i$ and $r_j \cdot x = b_j$ then $(r_i + c r_j)\cdot x = b_i + c b_j$.&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;$S&apos; \subseteq S$.&lt;/em&gt; By Lemma 1 the old system is obtained from the new one by an elementary operation. Apply the same argument in reverse.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;content-box warning-box textbook-block&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Warning.&lt;/strong&gt; Theorem 1 is about operations on the &lt;strong&gt;rows&lt;/strong&gt; of the augmented matrix. Column operations (for example swapping two columns) change the roles of the unknowns, so they do not preserve the solution set unless you record the renaming of unknowns.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;examples&quot;&gt;Examples&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; The opening system as an augmented matrix:&lt;/p&gt;

\[\left[\begin{array}{rr|r} 1 &amp;amp; 1 &amp;amp; 5 \\ 2 &amp;amp; -1 &amp;amp; 1 \end{array}\right]
\xrightarrow{R_2 \to R_2 - 2R_1}
\left[\begin{array}{rr|r} 1 &amp;amp; 1 &amp;amp; 5 \\ 0 &amp;amp; -3 &amp;amp; -9 \end{array}\right]
\xrightarrow{R_2 \to -\frac13 R_2}
\left[\begin{array}{rr|r} 1 &amp;amp; 1 &amp;amp; 5 \\ 0 &amp;amp; 1 &amp;amp; 3 \end{array}\right]
\xrightarrow{R_1 \to R_1 - R_2}
\left[\begin{array}{rr|r} 1 &amp;amp; 0 &amp;amp; 2 \\ 0 &amp;amp; 1 &amp;amp; 3 \end{array}\right].\]

  &lt;p&gt;The last matrix shows the solution $x = 2$, $y = 3$ directly. In the row picture, each step replaces two lines by two other lines &lt;em&gt;through the same point $(2, 3)$&lt;/em&gt;; the final step gives the lines $x = 2$ and $y = 3$, parallel to the axes.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (a swap is needed).&lt;/strong&gt; The system $2y = 4$, $x + y = 3$ has coefficient 0 for $x$ in the first row. Swap first:&lt;/p&gt;

\[\left[\begin{array}{rr|r} 0 &amp;amp; 2 &amp;amp; 4 \\ 1 &amp;amp; 1 &amp;amp; 3 \end{array}\right]
\xrightarrow{R_1 \leftrightarrow R_2}
\left[\begin{array}{rr|r} 1 &amp;amp; 1 &amp;amp; 3 \\ 0 &amp;amp; 2 &amp;amp; 4 \end{array}\right],\]

  &lt;p&gt;then $y = 2$, $x = 1$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3 (an illegal step).&lt;/strong&gt; From $x + y = 2$, $x - y = 0$ (unique solution $(1, 1)$), “multiplying row 2 by 0” leaves only $x + y = 2$, which has infinitely many solutions such as $(2, 0)$. That is why operation 2 requires $c \ne 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-circuits-and-equation-solvers&quot;&gt;Application: circuits and equation solvers&lt;/h2&gt;

&lt;p&gt;In an electric circuit, Kirchhoff’s laws give one linear equation at each node and each loop. A real circuit has thousands of unknowns. Circuit simulators (such as SPICE) do not “solve cleverly”; they repeat the three elementary operations in a fixed order, which is Gaussian elimination from Lesson 2.3. Theorem 1 guarantees that after millions of operations the final answer is still a solution of the original circuit (ignoring rounding errors, see Lesson 2.6).&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: Gaussian elimination step by step&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Press ▶ to apply one elementary row operation at a time, with exact fractions.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter02/khu_gauss.html?preset=swap&amp;amp;lang=en&quot; title=&quot;Interactive: Gaussian elimination step by step&quot; loading=&quot;lazy&quot; style=&quot;height: 680px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter02/khu_gauss.html?preset=swap&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Apply $R_2 \to R_2 - 3R_1$ and then $R_1 \leftrightarrow R_2$ to $\begin{bmatrix} 1 &amp;amp; 2 \\ 3 &amp;amp; 4 \end{bmatrix}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

After step one: $\begin{bmatrix} 1 &amp;amp; 2 \\ 0 &amp;amp; -2 \end{bmatrix}$. After step two: $\begin{bmatrix} 0 &amp;amp; -2 \\ 1 &amp;amp; 2 \end{bmatrix}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Give the inverse of the sequence in Exercise 1 (in the right order).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Undo from the end: $R_1 \leftrightarrow R_2$, then $R_2 \to R_2 + 3R_1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Solve $x + 2y = 4$, $3x + 5y = 7$ using only operations on the augmented matrix, recording each step.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$R_2 \to R_2 - 3R_1$: row two becomes $(0, -1 \mid -5)$; $R_2 \to -R_2$: $(0, 1 \mid 5)$; $R_1 \to R_1 - 2R_2$: $(1, 0 \mid -6)$. Solution $x = -6$, $y = 5$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; Does the step “$R_1 \to R_1 + R_2$ and simultaneously $R_2 \to R_2 + R_1$” (both using the old rows) preserve the solution set? Try it on $x + y = 1$, $-x - y = -1$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Not necessarily. In the example both new rows are $0 = 0$, and the solution set grows from a line to the whole plane. This is not a sequence of elementary operations, because the second step would have to use the *updated* row 1.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Show that the swap $R_1 \leftrightarrow R_2$ can be done with operations of types 2 and 3. (Hint: $R_1 \to R_1 + R_2$, $R_2 \to R_2 - R_1$, …)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

With rows $u, v$: $R_1 \to R_1 + R_2$ gives $(u + v, v)$; $R_2 \to R_2 - R_1$ gives $(u + v, -u)$; $R_1 \to R_1 + R_2$ gives $(v, -u)$; $R_2 \to -R_2$ gives $(v, u)$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Three elementary operations: swap two rows, scale a row by a nonzero number, add a multiple of one row to another.&lt;/li&gt;
    &lt;li&gt;Each operation has an inverse of the same type.&lt;/li&gt;
    &lt;li&gt;Row-equivalent augmented matrices give systems with the same solution set (Theorem 1).&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Linear systems: the row picture and the column picture</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter02/02_01_He_Phuong_Trinh_Tuyen_Tinh/"/>
   <updated>2026-01-02T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter02/02_01_He_Phuong_Trinh_Tuyen_Tinh</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;write a linear system in matrix form $Ax = b$ and as an augmented matrix $[A \mid b]$;&lt;/li&gt;
    &lt;li&gt;explain a solution through the row picture: an intersection of lines or planes;&lt;/li&gt;
    &lt;li&gt;explain a solution through the column picture: the coefficients that combine the columns of $A$ into $b$;&lt;/li&gt;
    &lt;li&gt;recognise the three possibilities: no solution, exactly one, infinitely many.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Consider the system&lt;/p&gt;

\[\begin{aligned}
2x - y &amp;amp;= 1,\\
x + y &amp;amp;= 5.
\end{aligned}\]

&lt;p&gt;Adding the equations gives $3x = 6$, so $x = 2$ and $y = 3$. This lesson is not about how to solve (that is Lesson 2.3) but about how to &lt;em&gt;look at&lt;/em&gt; a system. There are two pictures, and both are used throughout the course.&lt;/p&gt;

&lt;h2 id=&quot;linear-systems-and-matrix-form&quot;&gt;Linear systems and matrix form&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Linear system).&lt;/strong&gt; A &lt;em&gt;system of $m$ linear equations in $n$ unknowns&lt;/em&gt; has the form&lt;/p&gt;

\[\begin{aligned}
a_{11} x_1 + a_{12} x_2 + \cdots + a_{1n} x_n &amp;amp;= b_1,\\
&amp;amp;\ \,\vdots\\
a_{m1} x_1 + a_{m2} x_2 + \cdots + a_{mn} x_n &amp;amp;= b_m,
\end{aligned}\]

  &lt;p&gt;with real coefficients $a_{ij}$ and right-hand sides $b_i$. A &lt;em&gt;solution&lt;/em&gt; is a vector $x = (x_1, \dots, x_n)$ satisfying every equation. The &lt;em&gt;solution set&lt;/em&gt; is the set of all solutions. The system is &lt;em&gt;consistent&lt;/em&gt; if it has at least one solution.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The table of coefficients $A = [a_{ij}]$ with $m$ rows and $n$ columns is the &lt;em&gt;coefficient matrix&lt;/em&gt;. Appending the column $b$ gives the &lt;em&gt;augmented matrix&lt;/em&gt; $[A \mid b]$. The system is written compactly as $Ax = b$, where the product $Ax$ is defined in Section 4.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; The opening system has&lt;/p&gt;

  &lt;p&gt;\(A = \begin{bmatrix} 2 &amp;amp; -1 \\ 1 &amp;amp; 1 \end{bmatrix}, \quad b = \begin{bmatrix} 1 \\ 5 \end{bmatrix}, \quad [A \mid b] = \left[\begin{array}{rr|r} 2 &amp;amp; -1 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 5 \end{array}\right].\)&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;the-row-picture&quot;&gt;The row picture&lt;/h2&gt;

&lt;p&gt;Each equation is a condition. With two unknowns each equation is a &lt;em&gt;line&lt;/em&gt; in the plane; with three unknowns it is a &lt;em&gt;plane&lt;/em&gt; in space (Lesson 1.3). The solutions of the system are the points lying on &lt;em&gt;all&lt;/em&gt; of these lines (planes) at once.&lt;/p&gt;

&lt;p&gt;In the opening example, the line $2x - y = 1$ passes through $(0, -1)$ and $(1, 1)$ and rises; the line $x + y = 5$ passes through $(5, 0)$ and $(0, 5)$ and falls. They meet in exactly one point, $(2, 3)$.&lt;/p&gt;

&lt;p&gt;Two lines in the plane have only three possible positions: crossing (one solution), parallel (none), coincident (infinitely many). Theorem 2 shows this holds for every system.&lt;/p&gt;

&lt;h2 id=&quot;the-column-picture&quot;&gt;The column picture&lt;/h2&gt;

&lt;p&gt;Rewrite the opening system by columns:&lt;/p&gt;

\[x \begin{bmatrix} 2 \\ 1 \end{bmatrix} + y \begin{bmatrix} -1 \\ 1 \end{bmatrix} = \begin{bmatrix} 1 \\ 5 \end{bmatrix}.\]

&lt;p&gt;Now the question is: how many copies of the first column and of the second column combine to $b$? This is exactly the question $b \in \operatorname{span}$ from Lesson 1.4. The answer $x = 2$, $y = 3$: two copies of the arrow $(2, 1)$ give $(4, 2)$, then three copies of $(-1, 1)$ reach $(1, 5)$.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 2 (Matrix–vector product).&lt;/strong&gt; Let $A$ be an $m \times n$ matrix with columns $a_1, \dots, a_n \in \mathbb{R}^m$ and let $x \in \mathbb{R}^n$. Define&lt;/p&gt;

  &lt;p&gt;\(Ax = x_1 a_1 + x_2 a_2 + \cdots + x_n a_n .\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The $i$-th component of $Ax$ is $a_{i1}x_1 + \cdots + a_{in}x_n$, the dot product of row $i$ of $A$ with $x$. So the same product $Ax$ can be computed in two ways: by columns (a combination of columns) and by rows (dot products). The two pictures of a system come from here.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (The two pictures agree).&lt;/strong&gt; The system $Ax = b$ is consistent if and only if $b$ lies in the span of the columns of $A$. Moreover $x$ is a solution if and only if $x_1, \dots, x_n$ are the coefficients of a representation $b = x_1 a_1 + \cdots + x_n a_n$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; By Definition 2, the equation $Ax = b$ is the equation $x_1 a_1 + \cdots + x_n a_n = b$. Comparing $i$-th components of both sides gives exactly the $i$-th equation of the system. So the two conditions coincide.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2 (Never exactly two solutions).&lt;/strong&gt; If $Ax = b$ has two different solutions, it has infinitely many.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Suppose $Au = b$ and $Av = b$ with $u \ne v$. For every number $t$ let $w = u + t(v - u)$. Since $A(cx + dy) = cAx + dAy$ (check directly from Definition 2),&lt;/p&gt;

\[Aw = Au + t(Av - Au) = b + t(b - b) = b .\]

  &lt;p&gt;Different $t$ give different $w$, because $v - u \ne 0$. Geometrically: the whole line through $u$ and $v$ consists of solutions.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;examples&quot;&gt;Examples&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (no solution).&lt;/strong&gt; The system $x + 2y = 3$, $2x + 4y = 5$. Rows: both lines have normal direction $(1, 2)$, so they are parallel; doubling the first equation gives $2x + 4y = 6 \ne 5$, so they do not coincide. Columns: the columns $(1, 2)$ and $(2, 4)$ are parallel, their span is the line $y = 2x$, and $b = (3, 5)$ is not on it.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3 (three unknowns).&lt;/strong&gt; The system&lt;/p&gt;

\[x + y + z = 6, \qquad 2x + 3y + z = 11, \qquad x - y + 2z = 5\]

  &lt;p&gt;has the solution $(1, 2, 3)$ (substitute to check). Rows: three planes in space meet at one point, like the corner of a room where two walls and the floor meet. Columns:&lt;/p&gt;

  &lt;p&gt;\(1\begin{bmatrix}1\\2\\1\end{bmatrix} + 2\begin{bmatrix}1\\3\\-1\end{bmatrix} + 3\begin{bmatrix}1\\1\\2\end{bmatrix} = \begin{bmatrix}6\\11\\5\end{bmatrix}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-a-curve-through-data-points&quot;&gt;Application: a curve through data points&lt;/h2&gt;

&lt;p&gt;Find the parabola $y = ax^2 + bx + c$ through the three points $(1, 2)$, $(2, 3)$, $(3, 6)$. Each point gives a linear equation in the unknowns $a, b, c$:&lt;/p&gt;

\[a + b + c = 2, \qquad 4a + 2b + c = 3, \qquad 9a + 3b + c = 6.\]

&lt;p&gt;Subtracting the first equation from the other two: $3a + b = 1$ and $8a + 2b = 4$, i.e. $4a + b = 2$. Hence $a = 1$, $b = -2$, $c = 3$, and the parabola is $y = x^2 - 2x + 3$. The equations are linear in the &lt;em&gt;coefficients&lt;/em&gt; $a, b, c$ even though the curve is not a line. This is the idea behind interpolation and regression (Chapter 08): plotting software and linear machine-learning models all reduce to a system $Ax = b$.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: the row picture and the column picture&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Edit a 2 × 2 system and drag b: the intersection of two lines (left) and mixing the two columns into b (right).&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter02/hang_cot.html?lang=en&quot; title=&quot;Interactive: the row picture and the column picture&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter02/hang_cot.html?lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-one-system-two-pictures&quot;&gt;Short video: One system, two pictures&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/row-column-picture.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Row picture: two lines meet at the solution. Column picture: combine the two columns to reach the right-hand side. When the columns are parallel, both pictures break down together. Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Write the coefficient matrix and the augmented matrix of the system $3x - z = 2$, $x + y + z = 0$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$A = \begin{bmatrix} 3 &amp;amp; 0 &amp;amp; -1 \\ 1 &amp;amp; 1 &amp;amp; 1 \end{bmatrix}$, $[A \mid b] = \left[\begin{array}{rrr|r} 3 &amp;amp; 0 &amp;amp; -1 &amp;amp; 2 \\ 1 &amp;amp; 1 &amp;amp; 1 &amp;amp; 0 \end{array}\right]$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Compute $Ax$ by columns and by rows for $A = \begin{bmatrix} 1 &amp;amp; 2 \\ 3 &amp;amp; 4 \\ 0 &amp;amp; -1 \end{bmatrix}$, $x = (2, -1)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

By columns: $2(1, 3, 0) - (2, 4, -1) = (0, 2, 1)$. By rows: $1\cdot 2 + 2 \cdot(-1) = 0$, $3 \cdot 2 + 4 \cdot (-1) = 2$, $0 - (-1) = 1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; For which $k$ is the system $x + 2y = 3$, $2x + 4y = k$ consistent? How many solutions are there then? Explain with both pictures.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$k = 6$, and then there are infinitely many solutions $x = 3 - 2t$, $y = t$. Rows: the two lines coincide. Columns: $b = (3, 6)$ lies on the line spanned by the two parallel columns.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; Find the parabola $y = ax^2 + bx + c$ through $(0, 1)$, $(1, 0)$, $(2, 3)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$c = 1$; $a + b = -1$; $4a + 2b = 2$. Hence $a = 2$, $b = -3$: $y = 2x^2 - 3x + 1$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Prove $A(cx + dy) = c\,Ax + d\,Ay$ for all $x, y \in \mathbb{R}^n$ and numbers $c, d$ (used in Theorem 2).&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

By Definition 2, $A(cx + dy) = \sum_j (c x_j + d y_j) a_j = c \sum_j x_j a_j + d \sum_j y_j a_j$, using Theorem 1 of Lesson 1.1.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;A system of $m$ equations in $n$ unknowns is written $Ax = b$; the augmented matrix is $[A \mid b]$.&lt;/li&gt;
    &lt;li&gt;Row picture: solutions are intersections of lines or planes.&lt;/li&gt;
    &lt;li&gt;Column picture: $Ax = x_1 a_1 + \cdots + x_n a_n$, and the system is consistent if and only if $b$ is in the span of the columns.&lt;/li&gt;
    &lt;li&gt;A linear system has no solution, exactly one, or infinitely many.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Độc lập tuyến tính</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter01/01_05_Doc_Lap_Tuyen_Tinh/"/>
   <updated>2026-01-01T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter01/01_05_Doc_Lap_Tuyen_Tinh</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;kiểm tra một họ vectơ độc lập hay phụ thuộc tuyến tính bằng cách giải hệ thuần nhất;&lt;/li&gt;
    &lt;li&gt;khi họ phụ thuộc, tìm một hệ thức phụ thuộc cụ thể và viết một vectơ qua các vectơ còn lại;&lt;/li&gt;
    &lt;li&gt;giải thích độc lập tuyến tính bằng hình học trong $\mathbb{R}^2$, $\mathbb{R}^3$;&lt;/li&gt;
    &lt;li&gt;dùng tính duy nhất của hệ số trong tổ hợp tuyến tính.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Ba vectơ $v_1 = (1, 2, 3)$, $v_2 = (4, 5, 6)$, $v_3 = (7, 8, 9)$ trông có vẻ “khác nhau”. Nhưng&lt;/p&gt;

\[v_1 - 2v_2 + v_3 = (1 - 8 + 7,\ 2 - 10 + 8,\ 3 - 12 + 9) = (0, 0, 0).\]

&lt;p&gt;Vậy $v_3 = 2v_2 - v_1$: vectơ thứ ba không mang thêm hướng mới nào. Ba vectơ này nằm trên cùng một mặt phẳng qua gốc, và span của chúng chỉ là mặt phẳng đó chứ không phải cả $\mathbb{R}^3$. Ta nói họ này &lt;em&gt;phụ thuộc tuyến tính&lt;/em&gt;. Bài này cho cách phát hiện điều đó một cách có hệ thống.&lt;/p&gt;

&lt;h2 id=&quot;định-nghĩa&quot;&gt;Định nghĩa&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Độc lập và phụ thuộc tuyến tính).&lt;/strong&gt; Họ vectơ $v_1, \dots, v_k \in \mathbb{R}^n$ gọi là &lt;em&gt;độc lập tuyến tính&lt;/em&gt; nếu đẳng thức&lt;/p&gt;

\[c_1 v_1 + c_2 v_2 + \cdots + c_k v_k = 0\]

  &lt;p&gt;chỉ xảy ra khi $c_1 = c_2 = \cdots = c_k = 0$. Ngược lại, nếu có các hệ số không đồng thời bằng 0 làm tổ hợp bằng $0$, họ gọi là &lt;em&gt;phụ thuộc tuyến tính&lt;/em&gt;, và đẳng thức đó gọi là một &lt;em&gt;hệ thức phụ thuộc&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Tổ hợp với mọi hệ số bằng 0 luôn cho $0$; ta gọi nó là tổ hợp &lt;em&gt;tầm thường&lt;/em&gt;. Độc lập tuyến tính nghĩa là: tổ hợp tầm thường là cách duy nhất để về gốc.&lt;/p&gt;

&lt;h3 id=&quot;một-số-trường-hợp-đơn-giản&quot;&gt;Một số trường hợp đơn giản&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Một vectơ $v$ độc lập khi và chỉ khi $v \ne 0$.&lt;/li&gt;
  &lt;li&gt;Họ nào chứa vectơ $0$ cũng phụ thuộc: $1 \cdot 0 = 0$ là hệ thức phụ thuộc.&lt;/li&gt;
  &lt;li&gt;Hai vectơ phụ thuộc khi và chỉ khi một vectơ là bội của vectơ kia, tức chúng cùng phương.&lt;/li&gt;
  &lt;li&gt;Ba vectơ trong $\mathbb{R}^3$ phụ thuộc khi và chỉ khi chúng cùng nằm trên một mặt phẳng qua gốc.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;các-định-lý&quot;&gt;Các định lý&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Phụ thuộc nghĩa là có vectơ thừa).&lt;/strong&gt; Với $k \ge 2$, họ $v_1, \dots, v_k$ phụ thuộc tuyến tính khi và chỉ khi có ít nhất một vectơ $v_j$ là tổ hợp tuyến tính của các vectơ còn lại.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Giả sử có hệ thức $c_1 v_1 + \cdots + c_k v_k = 0$ với một hệ số $c_j \ne 0$. Chuyển vế rồi chia cho $c_j$:&lt;/p&gt;

\[v_j = -\frac{1}{c_j} \sum_{i \ne j} c_i v_i .\]

  &lt;p&gt;Ngược lại, nếu $v_j = \sum_{i \ne j} a_i v_i$ thì $\sum_{i \ne j} a_i v_i - v_j = 0$ là một hệ thức phụ thuộc, vì hệ số của $v_j$ là $-1 \ne 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Kết hợp với Định lý 2 của Bài 1.4: trong một họ phụ thuộc, bỏ đi vectơ thừa $v_j$ thì span không đổi. Họ độc lập là họ không có vectơ nào thừa.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2 (Hệ số duy nhất).&lt;/strong&gt; Họ $v_1, \dots, v_k$ độc lập tuyến tính khi và chỉ khi mọi vectơ $b \in \operatorname{span}\{v_1, \dots, v_k\}$ được viết &lt;em&gt;duy nhất&lt;/em&gt; dưới dạng $b = c_1 v_1 + \cdots + c_k v_k$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Giả sử họ độc lập và $b = \sum c_i v_i = \sum d_i v_i$. Trừ hai đẳng thức: $\sum (c_i - d_i) v_i = 0$. Do độc lập, $c_i - d_i = 0$ với mọi $i$.&lt;/p&gt;

  &lt;p&gt;Ngược lại, giả sử mọi $b$ trong span có cách viết duy nhất. Lấy $b = 0$: tổ hợp tầm thường là một cách viết, nên đó là cách duy nhất. Đây chính là định nghĩa độc lập tuyến tính.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Định lý 2 là lý do ta cần họ độc lập: khi đó các hệ số $c_i$ là “toạ độ” của $b$, giống như toạ độ $(x, y)$ trên mặt phẳng. Chương 05 gọi một họ độc lập sinh ra cả không gian là &lt;em&gt;cơ sở&lt;/em&gt;.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 3 (Quá nhiều vectơ thì phụ thuộc).&lt;/strong&gt; Mọi họ gồm nhiều hơn $n$ vectơ trong $\mathbb{R}^n$ đều phụ thuộc tuyến tính.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh (cho $n = 2$).&lt;/strong&gt; Cho $u, v, w \in \mathbb{R}^2$. Nếu $u, v$ cùng phương thì họ đã phụ thuộc. Nếu không, theo cách làm ở Ví dụ 2 của Bài 1.4, $u, v$ sinh ra $\mathbb{R}^2$, nên $w$ là tổ hợp của $u, v$, và theo Định lý 1 họ phụ thuộc. Với $n$ tổng quát, đẳng thức $\sum c_i v_i = 0$ là một hệ thuần nhất $n$ phương trình, $k &amp;gt; n$ ẩn; Bài 2.5 chứng minh hệ như vậy luôn có nghiệm khác không.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;cách-kiểm-tra&quot;&gt;Cách kiểm tra&lt;/h2&gt;

&lt;p&gt;Để kiểm tra họ $v_1, \dots, v_k$: viết hệ $c_1 v_1 + \cdots + c_k v_k = 0$ theo từng thành phần, rồi giải. Nếu nghiệm duy nhất là $c = 0$ thì họ độc lập; nếu có nghiệm khác không thì nghiệm đó là một hệ thức phụ thuộc.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Kiểm tra $v_1 = (1, 0, 2)$, $v_2 = (0, 1, 1)$, $v_3 = (1, 1, 4)$.&lt;/p&gt;

  &lt;p&gt;Hệ $c_1 v_1 + c_2 v_2 + c_3 v_3 = 0$ là&lt;/p&gt;

\[c_1 + c_3 = 0, \qquad c_2 + c_3 = 0, \qquad 2c_1 + c_2 + 4c_3 = 0.\]

  &lt;p&gt;Từ hai phương trình đầu, $c_1 = c_2 = -c_3$. Thế vào phương trình ba: $-2c_3 - c_3 + 4c_3 = c_3 = 0$. Vậy $c_1 = c_2 = c_3 = 0$, họ độc lập. Ba mũi tên này không cùng nằm trên một mặt phẳng, nên span của chúng là cả $\mathbb{R}^3$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; Đổi $v_3$ thành $(1, 1, 3)$. Lần này phương trình ba cho $-2c_3 - c_3 + 3c_3 = 0$, đúng với mọi $c_3$. Lấy $c_3 = 1$: $c_1 = c_2 = -1$, nên $-v_1 - v_2 + v_3 = 0$, tức $v_3 = v_1 + v_2$. Ba vectơ nằm trên mặt phẳng sinh bởi $v_1, v_2$, mặt phẳng có pháp tuyến $v_1 \times v_2 = (-2, -1, 1)$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3 (có tham số).&lt;/strong&gt; Tìm $t$ để $(1, 1, 0)$, $(1, 0, 1)$, $(0, 1, t)$ phụ thuộc tuyến tính.&lt;/p&gt;

  &lt;p&gt;Hệ: $c_1 + c_2 = 0$, $c_1 + c_3 = 0$, $c_2 + t c_3 = 0$. Hai phương trình đầu cho $c_2 = c_3 = -c_1$. Phương trình ba: $-c_1 - t c_1 = -(1 + t) c_1 = 0$. Có nghiệm $c_1 \ne 0$ khi và chỉ khi $t = -1$. Khi đó $(1, 1, 0) - (1, 0, 1) - (0, 1, -1) = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-đặc-trưng-thừa-trong-dữ-liệu&quot;&gt;Ứng dụng: đặc trưng thừa trong dữ liệu&lt;/h2&gt;

&lt;p&gt;Một bảng dữ liệu nhà đất có các cột: diện tích theo m², diện tích theo feet vuông, số phòng, giá. Cột thứ hai bằng $10.764$ lần cột thứ nhất. Hai cột này là hai vectơ trong $\mathbb{R}^m$ ($m$ là số căn nhà) và phụ thuộc tuyến tính.&lt;/p&gt;

&lt;p&gt;Khi một mô hình hồi quy tuyến tính dùng cả hai cột, theo Định lý 2 hệ số của chúng không còn duy nhất: tăng hệ số cột m² thêm $10.764$ và giảm hệ số cột feet vuông đi $1$ cho đúng cùng một dự đoán. Phần mềm sẽ báo ma trận “suy biến” hoặc cho các hệ số rất lớn, trái dấu và vô nghĩa. Hiện tượng này gọi là &lt;em&gt;đa cộng tuyến&lt;/em&gt;. Cách xử lý đơn giản nhất là bỏ cột thừa, đúng như Định lý 1 gợi ý.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: độc lập và phụ thuộc tuyến tính&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo b về cùng phương với a: lưới sụp thành một đường thẳng và det[a b] = 0.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter01/to_hop_tuyen_tinh.html?mode=span&quot; title=&quot;Minh hoạ: độc lập và phụ thuộc tuyến tính&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter01/to_hop_tuyen_tinh.html?mode=span&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-khi-b-cùng-phương-với-a-phần-cuối-của-reel-tổ-hợp-tuyến-tính&quot;&gt;Video ngắn: Khi b cùng phương với a (phần cuối của reel tổ hợp tuyến tính)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/linear-combination-span.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Xem từ 1:18: kéo b về cùng phương với a, diện tích ô lưới giảm về 0 và span chỉ còn một đường thẳng. Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Họ $(2, -1)$, $(-6, 3)$ độc lập hay phụ thuộc? Họ $(1, 2, 0)$, $(0, 0, 0)$, $(3, 1, 1)$ thì sao?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Họ thứ nhất phụ thuộc: $(-6, 3) = -3(2, -1)$. Họ thứ hai phụ thuộc vì chứa vectơ $0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Kiểm tra $(1, 2, 1)$, $(2, 1, 0)$, $(1, -1, 2)$ độc lập tuyến tính.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Hệ $c_1 + 2c_2 + c_3 = 0$, $2c_1 + c_2 - c_3 = 0$, $c_1 + 2c_3 = 0$ chỉ có nghiệm $0$: từ phương trình ba $c_1 = -2c_3$; phương trình một cho $c_2 = c_3/2$; phương trình hai cho $-4c_3 + c_3/2 - c_3 = -\tfrac92 c_3 = 0$. Họ độc lập.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Tìm $a$ để $(1, a, 1)$, $(a, 1, 1)$, $(1, 1, a)$ phụ thuộc tuyến tính.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$a = 1$ (ba vectơ trùng nhau) hoặc $a = -2$ (khi đó tổng ba vectơ bằng $0$). Chương 04 cho cách làm nhanh bằng định thức: $\det = -(a - 1)^2(a + 2)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Cho $u, v, w$ độc lập tuyến tính. Chứng minh $u + v$, $v + w$, $w + u$ cũng độc lập tuyến tính.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Nếu $a(u+v) + b(v+w) + c(w+u) = 0$ thì $(a + c)u + (a + b)v + (b + c)w = 0$. Do $u, v, w$ độc lập: $a + c = a + b = b + c = 0$, suy ra $a = b = c = 0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao / lập trình).&lt;/strong&gt; Trong NumPy, tạo ma trận có các cột $(1,2,3)$, $(4,5,6)$, $(7,8,9)$ và tính &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.linalg.matrix_rank&lt;/code&gt;. Đổi phần tử $9$ thành $9.000001$ và tính lại. Vì sao kết quả kiểm tra độc lập tuyến tính trên số thực dấu phẩy động cần thận trọng?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Hạng lần đầu là 2 (phụ thuộc), lần sau là 3 (độc lập). Một thay đổi rất nhỏ biến họ phụ thuộc thành độc lập, nên trên máy tính người ta đo &quot;gần phụ thuộc&quot; bằng các giá trị kỳ dị (Chương 11) thay vì trả lời có/không.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Độc lập tuyến tính: $\sum c_i v_i = 0$ kéo theo mọi $c_i = 0$.&lt;/li&gt;
    &lt;li&gt;Phụ thuộc khi và chỉ khi có một vectơ là tổ hợp của các vectơ còn lại; bỏ vectơ đó thì span không đổi.&lt;/li&gt;
    &lt;li&gt;Độc lập khi và chỉ khi hệ số của mỗi vectơ trong span là duy nhất.&lt;/li&gt;
    &lt;li&gt;Trong $\mathbb{R}^n$, họ có hơn $n$ vectơ luôn phụ thuộc.&lt;/li&gt;
    &lt;li&gt;Kiểm tra bằng cách giải hệ thuần nhất $\sum c_i v_i = 0$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Tổ hợp tuyến tính và không gian sinh</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter01/01_04_To_Hop_Tuyen_Tinh_Va_Khong_Gian_Sinh/"/>
   <updated>2026-01-01T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter01/01_04_To_Hop_Tuyen_Tinh_Va_Khong_Gian_Sinh</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;viết một vectơ dưới dạng tổ hợp tuyến tính của các vectơ cho trước, hoặc chỉ ra rằng không viết được;&lt;/li&gt;
    &lt;li&gt;mô tả bằng hình học span của một, hai, ba vectơ trong $\mathbb{R}^2$ và $\mathbb{R}^3$;&lt;/li&gt;
    &lt;li&gt;chứng minh span đóng với phép cộng và phép nhân với số.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Một trại chăn nuôi có hai loại thức ăn. Mỗi kg loại A chứa 20 g đạm và 5 g chất béo; mỗi kg loại B chứa 10 g đạm và 10 g chất béo. Muốn cho đàn vật nuôi đúng 50 g đạm và 25 g chất béo thì trộn bao nhiêu kg mỗi loại?&lt;/p&gt;

&lt;p&gt;Gọi số kg là $a$ và $b$. Ta cần&lt;/p&gt;

\[a\,(20, 5) + b\,(10, 10) = (50, 25).\]

&lt;p&gt;Từ $20a + 10b = 50$ và $5a + 10b = 25$, trừ hai phương trình được $15a = 25$, nên $a = b = 5/3$. Vế trái gọi là một &lt;em&gt;tổ hợp tuyến tính&lt;/em&gt; của hai vectơ thức ăn. Câu hỏi “trộn được những khẩu phần nào” là câu hỏi về &lt;em&gt;không gian sinh&lt;/em&gt; của chúng.&lt;/p&gt;

&lt;h2 id=&quot;tổ-hợp-tuyến-tính&quot;&gt;Tổ hợp tuyến tính&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Tổ hợp tuyến tính).&lt;/strong&gt; Cho các vectơ $v_1, \dots, v_k \in \mathbb{R}^n$. Một &lt;em&gt;tổ hợp tuyến tính&lt;/em&gt; của chúng là vectơ dạng&lt;/p&gt;

\[c_1 v_1 + c_2 v_2 + \cdots + c_k v_k, \qquad c_1, \dots, c_k \in \mathbb{R}.\]

  &lt;p&gt;Các số $c_i$ gọi là &lt;em&gt;hệ số&lt;/em&gt; của tổ hợp.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Hình dung: mỗi $v_i$ là một loại bước đi. Một tổ hợp tuyến tính là một lộ trình: đi $c_1$ bước loại 1, $c_2$ bước loại 2, … Hệ số âm nghĩa là đi lùi, hệ số không nguyên nghĩa là đi một phần bước.&lt;/p&gt;

&lt;h2 id=&quot;không-gian-sinh&quot;&gt;Không gian sinh&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 2 (Span).&lt;/strong&gt; &lt;em&gt;Không gian sinh&lt;/em&gt; (span) của $v_1, \dots, v_k$ là tập mọi tổ hợp tuyến tính của chúng:&lt;/p&gt;

\[\operatorname{span}\{v_1, \dots, v_k\} = \{\, c_1 v_1 + \cdots + c_k v_k : c_i \in \mathbb{R} \,\}.\]

  &lt;p&gt;Quy ước $\operatorname{span}\varnothing = \{0\}$. Nếu $\operatorname{span}\{v_1, \dots, v_k\} = \mathbb{R}^n$, ta nói họ này &lt;em&gt;sinh ra&lt;/em&gt; $\mathbb{R}^n$.&lt;/p&gt;
&lt;/div&gt;

&lt;h3 id=&quot;hình-ảnh-trong-mathbbr2-và-mathbbr3&quot;&gt;Hình ảnh trong $\mathbb{R}^2$ và $\mathbb{R}^3$&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Span của một vectơ $v \ne 0$ là đường thẳng qua gốc chứa $v$. Span của vectơ $0$ chỉ là $\{0\}$.&lt;/li&gt;
  &lt;li&gt;Span của hai vectơ không cùng phương trong $\mathbb{R}^3$ là mặt phẳng qua gốc chứa chúng. Nếu hai vectơ cùng phương, span chỉ là một đường thẳng.&lt;/li&gt;
  &lt;li&gt;Span của ba vectơ trong $\mathbb{R}^3$ là cả $\mathbb{R}^3$ nếu chúng không cùng nằm trên một mặt phẳng qua gốc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Span luôn chứa gốc $0$ (lấy mọi hệ số bằng 0). Vì vậy đường thẳng $x = (1, 0) + t(0, 1)$ không phải là span của vectơ nào: nó không đi qua gốc.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Span đóng với hai phép toán).&lt;/strong&gt; Cho $S = \operatorname{span}\{v_1, \dots, v_k\}$. Nếu $x, y \in S$ và $c \in \mathbb{R}$ thì $x + y \in S$ và $c\,x \in S$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Viết $x = \sum a_i v_i$ và $y = \sum b_i v_i$. Theo Định lý 1 của Bài 1.1, $x + y = \sum (a_i + b_i) v_i$ và $c\,x = \sum (c a_i) v_i$. Cả hai đều là tổ hợp tuyến tính của $v_1, \dots, v_k$, nên thuộc $S$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Một tập con của $\mathbb{R}^n$ chứa $0$ và đóng với hai phép toán gọi là &lt;em&gt;không gian con&lt;/em&gt;. Chương 05 sẽ nghiên cứu khái niệm này kỹ hơn.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2 (Thêm vectơ thừa không làm span lớn hơn).&lt;/strong&gt; Nếu $w \in \operatorname{span}\{v_1, \dots, v_k\}$ thì&lt;/p&gt;

  &lt;p&gt;\(\operatorname{span}\{v_1, \dots, v_k, w\} = \operatorname{span}\{v_1, \dots, v_k\}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Tập bên phải nằm trong tập bên trái: lấy hệ số của $w$ bằng 0. Ngược lại, viết $w = \sum a_i v_i$. Một tổ hợp $\sum c_i v_i + c\,w = \sum (c_i + c\,a_i) v_i$ thuộc tập bên phải.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;kiểm-tra-một-vectơ-có-thuộc-span-hay-không&quot;&gt;Kiểm tra một vectơ có thuộc span hay không&lt;/h2&gt;

&lt;p&gt;Câu hỏi “$b \in \operatorname{span}\{v_1, \dots, v_k\}$?” tương đương với câu hỏi: hệ phương trình $c_1 v_1 + \cdots + c_k v_k = b$ (ẩn là $c_1, \dots, c_k$) có nghiệm không? Chương 02 cho một thuật toán tổng quát; với các ví dụ nhỏ ta giải trực tiếp.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Cho $v_1 = (1, 0, 1)$, $v_2 = (0, 1, 1)$. Vectơ $b = (2, 3, 5)$ có thuộc span không?&lt;/p&gt;

  &lt;p&gt;Hệ $c_1 v_1 + c_2 v_2 = b$ là $c_1 = 2$, $c_2 = 3$, $c_1 + c_2 = 5$. Hai phương trình đầu cho $c_1 = 2$, $c_2 = 3$, và phương trình thứ ba đúng: $2 + 3 = 5$. Vậy $b = 2v_1 + 3v_2$.&lt;/p&gt;

  &lt;p&gt;Với $b&apos; = (2, 3, 4)$: hai phương trình đầu vẫn ép $c_1 = 2$, $c_2 = 3$, nhưng $2 + 3 \ne 4$. Vậy $b&apos; \notin \operatorname{span}\{v_1, v_2\}$.&lt;/p&gt;

  &lt;p&gt;Hình học: span là mặt phẳng qua gốc. Pháp tuyến của nó là $v_1 \times v_2 = (-1, -1, 1)$, tức mặt phẳng $z = x + y$. Điểm $(2, 3, 5)$ nằm trên mặt phẳng này, còn $(2, 3, 4)$ ở dưới nó một đơn vị.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; Chứng minh $u = (1, 2)$ và $w = (3, 1)$ sinh ra $\mathbb{R}^2$.&lt;/p&gt;

  &lt;p&gt;Với $b = (b_1, b_2)$ tuỳ ý, giải $c_1 + 3c_2 = b_1$, $2c_1 + c_2 = b_2$. Nhân phương trình đầu với 2 rồi trừ phương trình sau: $5 c_2 = 2b_1 - b_2$. Vậy&lt;/p&gt;

\[c_2 = \frac{2b_1 - b_2}{5}, \qquad c_1 = b_1 - 3c_2 = \frac{3b_2 - b_1}{5}.\]

  &lt;p&gt;Hệ luôn có nghiệm, nên mọi $b$ đều thuộc span. Với $b = (7, 4)$ ta được lại $c_1 = 1$, $c_2 = 2$ như ở Bài 1.1. Hình học: hai họ đường thẳng song song với $u$ và $w$ tạo thành một lưới xiên phủ kín mặt phẳng.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3.&lt;/strong&gt; Span của $(1, 2)$ và $(2, 4)$ là gì? Vì $(2, 4) = 2(1, 2)$, theo Định lý 2 span chỉ là đường thẳng $\{t(1, 2)\}$, tức đường $y = 2x$. Điểm $(1, 0)$ không tới được.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-khẩu-phần-và-hỗn-hợp&quot;&gt;Ứng dụng: khẩu phần và hỗn hợp&lt;/h2&gt;

&lt;p&gt;Quay lại ví dụ mở đầu. Hai vectơ $(20, 5)$ và $(10, 10)$ không cùng phương, nên span của chúng là cả $\mathbb{R}^2$: mọi cặp (đạm, chất béo) đều đạt được &lt;em&gt;nếu cho phép hệ số âm&lt;/em&gt;. Trong thực tế số kg không thể âm, nên chỉ đạt được các khẩu phần nằm trong góc giữa hai vectơ, tức các tổ hợp với $a, b \ge 0$. Ví dụ khẩu phần $(10, 20)$ đòi hỏi $a = -2/3 &amp;lt; 0$, không trộn được. Tập các tổ hợp với hệ số không âm gọi là &lt;em&gt;nón&lt;/em&gt;; nó là đối tượng chính của quy hoạch tuyến tính trong khoá Tối ưu.&lt;/p&gt;

&lt;p&gt;Cùng ý đó xuất hiện trong pha màu (màn hình trộn đỏ, lục, lam với cường độ không âm), trong hoá học (cân bằng phương trình phản ứng), và trong học máy (lớp tuyến tính của mạng nơ-ron tính tổ hợp tuyến tính của các đặc trưng).&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: tổ hợp tuyến tính và không gian sinh&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo a, b và các hệ số c₁, c₂; bấm “Quét mọi tổ hợp” để thấy span{a, b}.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter01/to_hop_tuyen_tinh.html?mode=span&quot; title=&quot;Minh hoạ: tổ hợp tuyến tính và không gian sinh&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter01/to_hop_tuyen_tinh.html?mode=span&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-tổ-hợp-tuyến-tính-phủ-kín-mặt-phẳng&quot;&gt;Video ngắn: Tổ hợp tuyến tính phủ kín mặt phẳng&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/linear-combination-span.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Co giãn a, nối thêm d · b, lưới do a và b dựng nên phủ kín mặt phẳng; kéo b về cùng phương với a thì lưới sụp thành một đường thẳng. Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Vectơ $(1, 2, 3)$ có thuộc $\operatorname{span}\{(1, 1, 0), (0, 1, 1)\}$ không?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Hệ $c_1 = 1$, $c_1 + c_2 = 2$, $c_2 = 3$ mâu thuẫn ($c_2 = 1$ và $c_2 = 3$). Không thuộc.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Tìm $h$ để $(1, h, 5) \in \operatorname{span}\{(1, 2, 1), (0, 1, 1)\}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Thành phần đầu cho $c_1 = 1$; thành phần cuối cho $1 + c_2 = 5$, $c_2 = 4$; thành phần giữa cho $h = 2 + 4 = 6$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Mô tả bằng một phương trình mặt phẳng tập $\operatorname{span}\{(1, 0, 2), (0, 1, -1)\}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Pháp tuyến $(1, 0, 2) \times (0, 1, -1) = (-2, 1, 1)$. Mặt phẳng qua gốc: $-2x + y + z = 0$, hay $z = 2x - y$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Chứng minh $\operatorname{span}\{u, w\} = \operatorname{span}\{u + w, u - w\}$ với mọi $u, w \in \mathbb{R}^n$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$u + w$ và $u - w$ thuộc span bên trái, nên (Định lý 1) span bên phải nằm trong span bên trái. Ngược lại, $u = \tfrac12[(u+w) + (u-w)]$ và $w = \tfrac12[(u+w) - (u-w)]$ thuộc span bên phải.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao / lập trình).&lt;/strong&gt; Trong NumPy, dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.linalg.lstsq(A, b)&lt;/code&gt; với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A&lt;/code&gt; có các cột $(1,0,1)$, $(0,1,1)$ và lần lượt $b = (2,3,5)$, $b = (2,3,4)$. Quan sát phần dư (residual). Phần dư bằng 0 nói lên điều gì?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Với $b = (2,3,5)$ phần dư bằng 0 và nghiệm là $(2, 3)$: $b$ thuộc span. Với $b = (2,3,4)$ phần dư dương: $b$ không thuộc span, và hàm trả về tổ hợp gần $b$ nhất. Đây là bài toán bình phương tối thiểu của Chương 08.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Tổ hợp tuyến tính: $c_1 v_1 + \cdots + c_k v_k$. Span là tập mọi tổ hợp như vậy.&lt;/li&gt;
    &lt;li&gt;Span luôn chứa $0$ và đóng với phép cộng, phép nhân với số; trong $\mathbb{R}^3$ nó là $\{0\}$, một đường thẳng, một mặt phẳng qua gốc, hoặc cả $\mathbb{R}^3$.&lt;/li&gt;
    &lt;li&gt;$b \in \operatorname{span}\{v_i\}$ khi và chỉ khi hệ $\sum c_i v_i = b$ có nghiệm.&lt;/li&gt;
    &lt;li&gt;Thêm một vectơ đã nằm trong span không làm span lớn hơn.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Đường thẳng và mặt phẳng</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter01/01_03_Duong_Thang_Va_Mat_Phang/"/>
   <updated>2026-01-01T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter01/01_03_Duong_Thang_Va_Mat_Phang</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;viết phương trình tham số của đường thẳng và mặt phẳng từ một điểm và các vectơ chỉ phương;&lt;/li&gt;
    &lt;li&gt;viết phương trình tổng quát của mặt phẳng từ một điểm và một vectơ pháp tuyến;&lt;/li&gt;
    &lt;li&gt;chuyển qua lại giữa hai dạng phương trình;&lt;/li&gt;
    &lt;li&gt;tính giao điểm của đường thẳng với mặt phẳng và khoảng cách từ một điểm đến mặt phẳng.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Trong một trò chơi 3D, camera ở gốc toạ độ nhìn theo hướng $d = (1, 1, 1)$. Phía trước có một bức tường phẳng đi qua ba điểm $(1, 0, 0)$, $(0, 2, 0)$, $(0, 0, 3)$. Tia nhìn chạm tường ở đâu?&lt;/p&gt;

&lt;p&gt;Để trả lời, ta cần hai thứ: mô tả tia nhìn bằng một tham số $t$ (đi $t$ bước theo $d$), và mô tả bức tường bằng một phương trình. Bài này dựng cả hai bằng vectơ, rồi giải bài toán ở Ví dụ 3.&lt;/p&gt;

&lt;h2 id=&quot;đường-thẳng&quot;&gt;Đường thẳng&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Đường thẳng).&lt;/strong&gt; Cho điểm $p \in \mathbb{R}^n$ và vectơ $d \ne 0$. &lt;em&gt;Đường thẳng&lt;/em&gt; qua $p$ với vectơ chỉ phương $d$ là tập&lt;/p&gt;

\[L = \{\, p + t\,d : t \in \mathbb{R} \,\}.\]

  &lt;p&gt;Đẳng thức $x = p + t\,d$ gọi là &lt;em&gt;phương trình tham số&lt;/em&gt; của $L$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Hình dung: đứng ở $p$, đi $t$ bước theo hướng $d$. Với $t &amp;gt; 0$ đi về phía trước, $t &amp;lt; 0$ đi lùi, $t = 0$ đứng yên ở $p$. Một đường thẳng có nhiều phương trình tham số: đổi $p$ thành một điểm khác trên $L$, hoặc đổi $d$ thành một bội khác không của $d$, vẫn được cùng đường thẳng.&lt;/p&gt;

&lt;p&gt;Đường thẳng qua hai điểm $p, q$ có vectơ chỉ phương $q - p$: $x = p + t(q - p)$. Khi $t$ chạy từ 0 đến 1, điểm $x$ đi hết đoạn $pq$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Đường thẳng trong $\mathbb{R}^2$ có phương trình $2x + 3y = 6$. Cho $x = 0$ được điểm $(0, 2)$; cho $y = 0$ được $(3, 0)$. Vectơ chỉ phương là $(3, 0) - (0, 2) = (3, -2)$, nên&lt;/p&gt;

\[(x, y) = (0, 2) + t\,(3, -2).\]

  &lt;p&gt;Chú ý $(2, 3) \cdot (3, -2) = 0$: vectơ hệ số $(2, 3)$ vuông góc với đường thẳng. Đây là ý của vectơ pháp tuyến ở mục sau.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;mặt-phẳng&quot;&gt;Mặt phẳng&lt;/h2&gt;

&lt;h3 id=&quot;phương-trình-tổng-quát&quot;&gt;Phương trình tổng quát&lt;/h3&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 2 (Mặt phẳng qua một điểm, với pháp tuyến cho trước).&lt;/strong&gt; Cho điểm $p \in \mathbb{R}^3$ và vectơ $n = (a, b, c) \ne 0$. Mặt phẳng qua $p$ có &lt;em&gt;vectơ pháp tuyến&lt;/em&gt; $n$ là tập các điểm $x$ sao cho $x - p$ vuông góc với $n$:&lt;/p&gt;

  &lt;p&gt;\(n \cdot (x - p) = 0 \quad\Longleftrightarrow\quad a x_1 + b x_2 + c x_3 = d, \ \text{ với } d = n \cdot p.\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Hình dung: cắm một cây kim $n$ thẳng đứng tại $p$. Mặt phẳng là tất cả các hướng đi từ $p$ mà vuông góc với cây kim.&lt;/p&gt;

&lt;h3 id=&quot;phương-trình-tham-số&quot;&gt;Phương trình tham số&lt;/h3&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 3 (Mặt phẳng tham số).&lt;/strong&gt; Cho điểm $p$ và hai vectơ $u, v$ không cùng phương. Tập&lt;/p&gt;

\[\{\, p + s\,u + t\,v : s, t \in \mathbb{R} \,\}\]

  &lt;p&gt;là mặt phẳng qua $p$ chứa hai hướng $u, v$.&lt;/p&gt;
&lt;/div&gt;

&lt;h3 id=&quot;tích-có-hướng&quot;&gt;Tích có hướng&lt;/h3&gt;

&lt;p&gt;Để chuyển từ dạng tham số sang dạng tổng quát, ta cần một vectơ vuông góc với cả $u$ và $v$.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 4 (Tích có hướng).&lt;/strong&gt; Với $u = (u_1, u_2, u_3)$ và $v = (v_1, v_2, v_3)$,&lt;/p&gt;

  &lt;p&gt;\(u \times v = (u_2 v_3 - u_3 v_2,\ \ u_3 v_1 - u_1 v_3,\ \ u_1 v_2 - u_2 v_1).\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; $u \times v$ vuông góc với cả $u$ và $v$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Tính trực tiếp:&lt;/p&gt;

\[u \cdot (u \times v) = u_1(u_2 v_3 - u_3 v_2) + u_2(u_3 v_1 - u_1 v_3) + u_3(u_1 v_2 - u_2 v_1) = 0,\]

  &lt;p&gt;vì sáu số hạng triệt tiêu từng cặp. Tương tự với $v \cdot (u \times v)$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Ở Chương 04 ta sẽ thấy độ dài của $u \times v$ là diện tích hình bình hành dựng trên $u, v$, và $u \times v = 0$ khi và chỉ khi $u, v$ cùng phương.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (mặt phẳng qua ba điểm).&lt;/strong&gt; Lấy $A = (1, 0, 0)$, $B = (0, 2, 0)$, $C = (0, 0, 3)$. Hai vectơ trong mặt phẳng là $B - A = (-1, 2, 0)$ và $C - A = (-1, 0, 3)$. Pháp tuyến:&lt;/p&gt;

\[n = (B - A) \times (C - A) = (2 \cdot 3 - 0,\ 0 - (-1)\cdot 3,\ 0 - 2 \cdot (-1)) = (6, 3, 2).\]

  &lt;p&gt;Với $d = n \cdot A = 6$, mặt phẳng là $6x + 3y + 2z = 6$. Kiểm tra: $B$ cho $6$, $C$ cho $6$. Mặt phẳng này cắt ba trục tại $x = 1$, $y = 2$, $z = 3$, đúng ba điểm đã cho.&lt;/p&gt;
&lt;/div&gt;

&lt;h3 id=&quot;từ-dạng-tổng-quát-sang-dạng-tham-số&quot;&gt;Từ dạng tổng quát sang dạng tham số&lt;/h3&gt;

&lt;p&gt;Với $2x - y + z = 4$: chọn hai ẩn làm tham số, chẳng hạn $x = s$, $y = t$. Khi đó $z = 4 - 2s + t$, nên&lt;/p&gt;

\[(x, y, z) = (0, 0, 4) + s\,(1, 0, -2) + t\,(0, 1, 1).\]

&lt;p&gt;Kiểm tra: hai vectơ chỉ phương đều vuông góc với pháp tuyến $(2, -1, 1)$. Cách “chọn ẩn tự do làm tham số” này chính là cách ta viết nghiệm tổng quát của hệ phương trình ở Chương 02.&lt;/p&gt;

&lt;h2 id=&quot;giao-điểm-và-khoảng-cách&quot;&gt;Giao điểm và khoảng cách&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3 (tia nhìn chạm tường).&lt;/strong&gt; Quay lại ví dụ mở đầu. Tia nhìn là $x = t\,(1, 1, 1)$ với $t \ge 0$. Thế vào $6x + 3y + 2z = 6$: $11 t = 6$, nên $t = 6/11$ và điểm chạm là $\left(\tfrac{6}{11}, \tfrac{6}{11}, \tfrac{6}{11}\right)$. Vì $t &amp;gt; 0$, bức tường nằm phía trước camera.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2 (Khoảng cách từ điểm đến mặt phẳng).&lt;/strong&gt; Khoảng cách từ điểm $q$ đến mặt phẳng $n \cdot x = d$ là&lt;/p&gt;

  &lt;p&gt;\(\operatorname{dist} = \frac{\lvert n \cdot q - d \rvert}{\lVert n \rVert}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Đường thẳng qua $q$ theo hướng $n$ là $x = q + t\,n$. Nó cắt mặt phẳng khi $n \cdot q + t \lVert n \rVert^2 = d$, tức $t_0 = (d - n\cdot q)/\lVert n \rVert^2$. Điểm cắt $h = q + t_0 n$ là chân đường vuông góc. Với mọi điểm $x$ khác trên mặt phẳng, $x - h$ vuông góc với $n$, nên theo Pythagore $\lVert x - q \rVert^2 = \lVert x - h \rVert^2 + \lVert h - q \rVert^2 \ge \lVert h - q \rVert^2$. Vậy khoảng cách là $\lVert h - q \rVert = \lvert t_0 \rvert\, \lVert n \rVert = \lvert n\cdot q - d \rvert / \lVert n \rVert$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 4.&lt;/strong&gt; Khoảng cách từ $q = (1, 1, 1)$ đến $6x + 3y + 2z = 6$ bằng $\dfrac{\lvert 6 + 3 + 2 - 6 \rvert}{\sqrt{36 + 9 + 4}} = \dfrac57$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-dò-tia-trong-đồ-hoạ-máy-tính&quot;&gt;Ứng dụng: dò tia trong đồ hoạ máy tính&lt;/h2&gt;

&lt;p&gt;Phần mềm dựng ảnh bằng phương pháp &lt;em&gt;dò tia&lt;/em&gt; (ray tracing) bắn một tia $x = c + t\,d$ từ camera qua mỗi điểm ảnh. Với mỗi mặt phẳng $n \cdot x = k$ trong cảnh, nó giải&lt;/p&gt;

\[t = \frac{k - n \cdot c}{n \cdot d}.\]

&lt;p&gt;Nếu $n \cdot d = 0$, tia song song với mặt phẳng và không chạm. Nếu $t &amp;lt; 0$, mặt phẳng ở sau camera. Trong các $t &amp;gt; 0$ còn lại, giá trị nhỏ nhất cho vật gần nhất, tức vật mà ta nhìn thấy. Một ảnh Full HD cần khoảng hai triệu phép tính như vậy cho mỗi mặt phẳng, và mỗi phép chỉ gồm vài tích vô hướng. Chương 12 sẽ quay lại chủ đề đồ hoạ.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: đường thẳng và mặt phẳng trong ℝ³&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Đổi p, d, n, c; kéo chuột để xoay; xem giao điểm.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter01/duong_mat_3d.html&quot; title=&quot;Minh hoạ: đường thẳng và mặt phẳng trong ℝ³&quot; loading=&quot;lazy&quot; style=&quot;height: 700px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter01/duong_mat_3d.html&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Viết phương trình mặt phẳng qua ba điểm $(1, 1, 1)$, $(2, 0, 1)$, $(0, 1, 3)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Hai vectơ $(1, -1, 0)$ và $(-1, 0, 2)$, tích có hướng $(-2, -2, -1)$. Đổi dấu được pháp tuyến $(2, 2, 1)$, và mặt phẳng là $2x + 2y + z = 5$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Viết phương trình tham số của đường thẳng qua $(1, 0, 2)$ và $(3, 1, 0)$. Tìm giao điểm của nó với mặt phẳng $x + y + z = 7$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$x = (1, 0, 2) + t(2, 1, -2)$. Thế vào: $3 + t = 7$, $t = 4$, giao điểm $(9, 4, -6)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Tìm một phương trình tham số cho giao tuyến của hai mặt phẳng $x + y + z = 1$ và $x - y + 2z = 3$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Vectơ chỉ phương vuông góc với cả hai pháp tuyến: $(1, 1, 1) \times (1, -1, 2) = (3, -1, -2)$. Cho $z = 0$: $x + y = 1$, $x - y = 3$, nên $(2, -1, 0)$ thuộc giao tuyến. Vậy $x = (2, -1, 0) + t(3, -1, -2)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Tính khoảng cách giữa hai mặt phẳng song song $x + 2y + 2z = 3$ và $x + 2y + 2z = 12$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Lấy điểm $(3, 0, 0)$ trên mặt thứ nhất. Khoảng cách đến mặt thứ hai là $\lvert 3 - 12 \rvert / 3 = 3$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Chứng minh rằng nếu $p$ và $q$ đều thuộc mặt phẳng $n \cdot x = d$ thì cả đường thẳng qua $p, q$ nằm trong mặt phẳng đó.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Với $x = p + t(q - p)$: $n \cdot x = n\cdot p + t(n \cdot q - n \cdot p) = d + t(d - d) = d$ với mọi $t$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Đường thẳng: $x = p + t\,d$. Mặt phẳng tham số: $x = p + s\,u + t\,v$.&lt;/li&gt;
    &lt;li&gt;Mặt phẳng tổng quát: $n \cdot x = d$, với $n$ là pháp tuyến; $u \times v$ cho pháp tuyến từ hai hướng $u, v$.&lt;/li&gt;
    &lt;li&gt;Từ dạng tổng quát sang tham số: chọn ẩn tự do làm tham số.&lt;/li&gt;
    &lt;li&gt;Khoảng cách từ $q$ đến mặt phẳng: $\lvert n \cdot q - d \rvert / \lVert n \rVert$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Tích vô hướng, độ dài và góc</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter01/01_02_Tich_Vo_Huong_Do_Dai_Va_Goc/"/>
   <updated>2026-01-01T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter01/01_02_Tich_Vo_Huong_Do_Dai_Va_Goc</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;tính tích vô hướng, độ dài của vectơ và góc giữa hai vectơ trong $\mathbb{R}^n$;&lt;/li&gt;
    &lt;li&gt;kiểm tra hai vectơ vuông góc bằng tích vô hướng;&lt;/li&gt;
    &lt;li&gt;phát biểu và chứng minh bất đẳng thức Cauchy–Schwarz và bất đẳng thức tam giác;&lt;/li&gt;
    &lt;li&gt;dùng độ tương tự cosin để so sánh hai mẫu dữ liệu.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Hai vectơ $a = (3, 4)$ và $b = (4, -3)$ trên giấy kẻ ô trông như vuông góc với nhau. Làm sao kiểm tra mà không cần thước đo góc?&lt;/p&gt;

&lt;p&gt;Tính $3 \cdot 4 + 4 \cdot (-3) = 12 - 12 = 0$. Con số $0$ này chính là dấu hiệu vuông góc. Tổng “nhân từng cặp thành phần rồi cộng lại” gọi là tích vô hướng. Từ nó ta có độ dài, góc, và một phép thử vuông góc dùng được cả trong $\mathbb{R}^{100}$, nơi không ai vẽ được hình.&lt;/p&gt;

&lt;h2 id=&quot;tích-vô-hướng-và-độ-dài&quot;&gt;Tích vô hướng và độ dài&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Tích vô hướng).&lt;/strong&gt; Tích vô hướng của $x = (x_1, \dots, x_n)$ và $y = (y_1, \dots, y_n)$ là số thực&lt;/p&gt;

  &lt;p&gt;\(x \cdot y = x_1 y_1 + x_2 y_2 + \cdots + x_n y_n .\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Tính chất của tích vô hướng).&lt;/strong&gt; Với mọi $x, y, z \in \mathbb{R}^n$ và số thực $c$:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$x \cdot y = y \cdot x$ (đối xứng);&lt;/li&gt;
    &lt;li&gt;$(x + y) \cdot z = x \cdot z + y \cdot z$ và $(c\,x) \cdot y = c\,(x \cdot y)$ (tuyến tính);&lt;/li&gt;
    &lt;li&gt;$x \cdot x \ge 0$, và $x \cdot x = 0$ khi và chỉ khi $x = 0$ (xác định dương).&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Tính chất 1 và 2 suy ra trực tiếp từ định nghĩa và tính giao hoán, phân phối của số thực. Với tính chất 3: $x \cdot x = x_1^2 + \cdots + x_n^2$ là tổng các bình phương nên không âm, và tổng này bằng 0 chỉ khi mọi $x_i = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 2 (Độ dài, vectơ đơn vị, khoảng cách).&lt;/strong&gt; &lt;em&gt;Độ dài&lt;/em&gt; (hay &lt;em&gt;chuẩn&lt;/em&gt;) của $x$ là&lt;/p&gt;

\[\lVert x \rVert = \sqrt{x \cdot x} = \sqrt{x_1^2 + \cdots + x_n^2}.\]

  &lt;p&gt;Vectơ có độ dài 1 gọi là &lt;em&gt;vectơ đơn vị&lt;/em&gt;. Với $x \ne 0$, vectơ $x / \lVert x \rVert$ là vectơ đơn vị cùng hướng với $x$. &lt;em&gt;Khoảng cách&lt;/em&gt; giữa hai điểm $x, y$ là $\lVert x - y \rVert$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Với $n = 2$, công thức độ dài chính là định lý Pythagore: mũi tên $(x_1, x_2)$ là cạnh huyền của tam giác vuông có hai cạnh $\lvert x_1 \rvert$ và $\lvert x_2 \rvert$. Với $n = 3$, ta áp dụng Pythagore hai lần.&lt;/p&gt;

&lt;p&gt;Từ định nghĩa, $\lVert c\,x \rVert = \lvert c \rvert\, \lVert x \rVert$: nhân vectơ với $c$ thì độ dài nhân với $\lvert c \rvert$.&lt;/p&gt;

&lt;h2 id=&quot;bất-đẳng-thức-cauchyschwarz&quot;&gt;Bất đẳng thức Cauchy–Schwarz&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2 (Cauchy–Schwarz).&lt;/strong&gt; Với mọi $x, y \in \mathbb{R}^n$,&lt;/p&gt;

\[\lvert x \cdot y \rvert \le \lVert x \rVert\, \lVert y \rVert .\]

  &lt;p&gt;Dấu bằng xảy ra khi và chỉ khi một trong hai vectơ là bội của vectơ kia.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Nếu $y = 0$ thì hai vế đều bằng 0. Giả sử $y \ne 0$. Với mọi số thực $t$, theo Định lý 1,&lt;/p&gt;

\[0 \le \lVert x - t y \rVert^2 = (x - ty)\cdot(x - ty) = \lVert x \rVert^2 - 2t\,(x \cdot y) + t^2 \lVert y \rVert^2 .\]

  &lt;p&gt;Vế phải là một tam thức bậc hai theo $t$ với hệ số $t^2$ dương, và nó không âm với mọi $t$. Do đó biệt thức không dương: $4 (x \cdot y)^2 - 4 \lVert x \rVert^2 \lVert y \rVert^2 \le 0$. Lấy căn hai vế ta được bất đẳng thức.&lt;/p&gt;

  &lt;p&gt;Dấu bằng xảy ra khi biệt thức bằng 0, tức là có một $t$ làm $\lVert x - ty \rVert = 0$, nghĩa là $x = t y$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Hệ quả 1 (Bất đẳng thức tam giác).&lt;/strong&gt; Với mọi $x, y \in \mathbb{R}^n$, $\lVert x + y \rVert \le \lVert x \rVert + \lVert y \rVert$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; $\lVert x + y \rVert^2 = \lVert x \rVert^2 + 2\, x\cdot y + \lVert y \rVert^2 \le \lVert x \rVert^2 + 2 \lVert x \rVert \lVert y \rVert + \lVert y \rVert^2 = (\lVert x \rVert + \lVert y \rVert)^2$, trong đó bước $\le$ dùng Cauchy–Schwarz. Lấy căn hai vế (cả hai đều không âm).&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Về hình học: trong tam giác có hai cạnh là $x$ và $y$, cạnh thứ ba $x + y$ không dài hơn tổng hai cạnh kia. Đi thẳng luôn ngắn nhất.&lt;/p&gt;

&lt;h2 id=&quot;góc-giữa-hai-vectơ-và-vuông-góc&quot;&gt;Góc giữa hai vectơ và vuông góc&lt;/h2&gt;

&lt;p&gt;Theo Cauchy–Schwarz, với $x, y \ne 0$ ta có $-1 \le \dfrac{x \cdot y}{\lVert x \rVert \lVert y \rVert} \le 1$. Vì vậy định nghĩa sau hợp lệ.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 3 (Góc, vuông góc).&lt;/strong&gt; Góc $\theta \in [0, \pi]$ giữa hai vectơ khác không $x, y$ xác định bởi&lt;/p&gt;

\[\cos\theta = \frac{x \cdot y}{\lVert x \rVert\, \lVert y \rVert}.\]

  &lt;p&gt;Hai vectơ $x, y$ gọi là &lt;em&gt;vuông góc&lt;/em&gt; (hay &lt;em&gt;trực giao&lt;/em&gt;), ký hiệu $x \perp y$, nếu $x \cdot y = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Trong $\mathbb{R}^2$ và $\mathbb{R}^3$, góc này trùng với góc đo bằng thước, nhờ định lý cosin: tam giác có hai cạnh $x, y$ thì cạnh thứ ba là $x - y$, và&lt;/p&gt;

\[\lVert x - y \rVert^2 = \lVert x \rVert^2 + \lVert y \rVert^2 - 2\, x\cdot y\]

&lt;p&gt;so với $c^2 = a^2 + b^2 - 2ab\cos\theta$ cho đúng $x \cdot y = \lVert x \rVert \lVert y \rVert \cos\theta$.&lt;/p&gt;

&lt;p&gt;Dấu của tích vô hướng cho biết ngay loại góc: dương thì góc nhọn, bằng 0 thì vuông, âm thì tù. Một cách hình dung: $x \cdot y$ bằng độ dài của $x$ nhân với độ dài có dấu của &lt;em&gt;bóng&lt;/em&gt; của $y$ chiếu lên đường thẳng chứa $x$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 3 (Pythagore).&lt;/strong&gt; $x \perp y$ khi và chỉ khi $\lVert x + y \rVert^2 = \lVert x \rVert^2 + \lVert y \rVert^2$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Khai triển $\lVert x + y \rVert^2 = \lVert x \rVert^2 + 2\,x \cdot y + \lVert y \rVert^2$. Đẳng thức cần chứng minh tương đương với $x \cdot y = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-tính-toán&quot;&gt;Ví dụ tính toán&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Cho $u = (1, 2, 2)$, $v = (2, 0, 1)$. Ta có&lt;/p&gt;

\[u \cdot v = 2 + 0 + 2 = 4, \quad \lVert u \rVert = \sqrt{1 + 4 + 4} = 3, \quad \lVert v \rVert = \sqrt{5}.\]

  &lt;p&gt;Vậy $\cos\theta = \dfrac{4}{3\sqrt5} \approx 0.596$ và $\theta \approx 53.4^\circ$. Tích vô hướng dương nên góc nhọn, khớp với kết quả. Vectơ đơn vị cùng hướng với $u$ là $\tfrac13 (1, 2, 2)$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; Tìm mọi vectơ trong $\mathbb{R}^2$ vuông góc với $a = (1, 2)$.&lt;/p&gt;

  &lt;p&gt;Điều kiện $x_1 + 2x_2 = 0$ cho $x_1 = -2x_2$, tức là $x = t(-2, 1)$ với $t$ tuỳ ý. Tập này là một đường thẳng qua gốc. Mặt phẳng có đúng một hướng vuông góc với $a$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3.&lt;/strong&gt; Khoảng cách giữa $P = (1, 1, 0)$ và $Q = (3, 0, 2)$ là $\lVert Q - P \rVert = \lVert (2, -1, 2) \rVert = \sqrt{4 + 1 + 4} = 3$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-độ-tương-tự-cosin&quot;&gt;Ứng dụng: độ tương tự cosin&lt;/h2&gt;

&lt;p&gt;Một văn bản có thể biểu diễn bằng vectơ đếm từ. Chọn bốn từ khoá “ma trận”, “vectơ”, “mèo”, “định thức”. Ba văn bản cho ba vectơ:&lt;/p&gt;

\[d_1 = (2, 1, 0, 1), \quad d_2 = (1, 1, 1, 0), \quad d_3 = (0, 0, 3, 1).\]

&lt;p&gt;&lt;em&gt;Độ tương tự cosin&lt;/em&gt; là $\cos\theta$ giữa hai vectơ. Nó không phụ thuộc độ dài văn bản, chỉ phụ thuộc tỉ lệ các từ:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;$\cos(d_1, d_2) = \dfrac{3}{\sqrt6 \cdot \sqrt3} \approx 0.71$;&lt;/li&gt;
  &lt;li&gt;$\cos(d_1, d_3) = \dfrac{1}{\sqrt6 \cdot \sqrt{10}} \approx 0.13$;&lt;/li&gt;
  &lt;li&gt;$\cos(d_2, d_3) = \dfrac{3}{\sqrt3 \cdot \sqrt{10}} \approx 0.55$.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Văn bản 1 và 2 gần nhau nhất (cùng nói về đại số), văn bản 1 và 3 gần như “vuông góc”. Các công cụ tìm kiếm và các mô hình ngôn ngữ dùng đúng phép đo này trên vectơ có hàng trăm thành phần; cơ chế attention trong Transformer cũng bắt đầu bằng các tích vô hướng.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: tích vô hướng, góc và hình chiếu&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo u, v để xem u·v, cos θ và hình chiếu của u lên v.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter01/vecto_2d.html?mode=dot&quot; title=&quot;Minh hoạ: tích vô hướng, góc và hình chiếu&quot; loading=&quot;lazy&quot; style=&quot;height: 620px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter01/vecto_2d.html?mode=dot&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-tích-vô-hướng-là-cái-bóng&quot;&gt;Video ngắn: Tích vô hướng là cái bóng&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/dot-product-shadow.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Đèn chiếu vuông góc với a, b in bóng lên a: a · b = |a| × bóng. Quay b qua 90° thì bóng đổi chiều và a · b đổi dấu. Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Tính góc giữa $(1, 1, 0)$ và $(0, 1, 1)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Tích vô hướng bằng 1, mỗi vectơ dài $\sqrt2$, nên $\cos\theta = 1/2$ và $\theta = 60^\circ$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Tìm $m$ để $(m, 2, -1)$ vuông góc với $(3, m, 4)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$3m + 2m - 4 = 0$, nên $m = 4/5$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Chứng minh &lt;em&gt;đẳng thức hình bình hành&lt;/em&gt;: $\lVert x + y \rVert^2 + \lVert x - y \rVert^2 = 2\lVert x \rVert^2 + 2\lVert y \rVert^2$. Giải thích bằng hình.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Khai triển hai bình phương: các số hạng $\pm 2\,x\cdot y$ triệt tiêu. Về hình học: tổng bình phương hai đường chéo của hình bình hành bằng tổng bình phương bốn cạnh.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Cho $\lVert x \rVert = 3$, $\lVert y \rVert = 4$, $x \cdot y = 6$. Tính $\lVert 2x - y \rVert$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\lVert 2x - y \rVert^2 = 4 \cdot 9 - 4 \cdot 6 + 16 = 28$, nên $\lVert 2x - y \rVert = 2\sqrt7$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao / lập trình).&lt;/strong&gt; Cho ma trận dữ liệu NumPy có các cột là $d_1, d_2, d_3$ ở mục Ứng dụng. Chuẩn hoá từng cột về độ dài 1 rồi tính &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;D.T @ D&lt;/code&gt;. Giải thích vì sao các phần tử trên đường chéo bằng 1 và các phần tử còn lại là độ tương tự cosin.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Phần tử $(i, j)$ của `D.T @ D` là tích vô hướng của cột $i$ và cột $j$. Sau khi chuẩn hoá, tích vô hướng của hai vectơ đơn vị bằng cosin góc giữa chúng; một cột với chính nó cho $\cos 0 = 1$. Ma trận nhận được có các phần tử ngoài đường chéo xấp xỉ $0.71$, $0.13$, $0.55$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$x \cdot y = \sum x_i y_i$; độ dài $\lVert x \rVert = \sqrt{x \cdot x}$.&lt;/li&gt;
    &lt;li&gt;Cauchy–Schwarz: $\lvert x \cdot y \rvert \le \lVert x \rVert \lVert y \rVert$, kéo theo bất đẳng thức tam giác.&lt;/li&gt;
    &lt;li&gt;$\cos\theta = \dfrac{x \cdot y}{\lVert x \rVert \lVert y \rVert}$; vuông góc khi và chỉ khi $x \cdot y = 0$.&lt;/li&gt;
    &lt;li&gt;Độ tương tự cosin so sánh hai mẫu dữ liệu mà không phụ thuộc độ lớn.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Vectơ trong ℝⁿ và các phép toán</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter01/01_01_Vecto_Trong_Rn/"/>
   <updated>2026-01-01T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter01/01_01_Vecto_Trong_Rn</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;viết một vectơ trong $\mathbb{R}^n$ dưới dạng bộ số và vẽ nó dưới dạng mũi tên khi $n = 2, 3$;&lt;/li&gt;
    &lt;li&gt;cộng hai vectơ, nhân vectơ với một số, và giải thích hai phép toán đó bằng hình;&lt;/li&gt;
    &lt;li&gt;dùng tám tính chất của phép cộng và phép nhân với số để biến đổi biểu thức vectơ.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Một robot hút bụi đứng ở gốc toạ độ trên sàn nhà. Lệnh thứ nhất bảo nó đi 2 m về phía đông và 1 m về phía bắc. Lệnh thứ hai bảo nó đi 1 m về phía tây và 3 m về phía bắc. Sau hai lệnh, robot ở đâu?&lt;/p&gt;

&lt;p&gt;Ta ghi mỗi lệnh bằng một cặp số: $u = (2, 1)$ và $v = (-1, 3)$. Đi lệnh này rồi đi lệnh kia thì cộng từng thành phần: robot ở $(2 + (-1),\ 1 + 3) = (1, 4)$. Nếu lặp lệnh thứ nhất ba lần, robot ở $(6, 3)$, tức là nhân mỗi thành phần với 3.&lt;/p&gt;

&lt;p&gt;Hai phép toán “cộng từng thành phần” và “nhân từng thành phần với một số” là toàn bộ nội dung của bài này. Chúng có ý nghĩa hình học rõ ràng, và chúng là nền cho cả khoá học.&lt;/p&gt;

&lt;h2 id=&quot;vectơ-trong-mathbbrn&quot;&gt;Vectơ trong $\mathbb{R}^n$&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Vectơ trong $\mathbb{R}^n$).&lt;/strong&gt; Với số nguyên dương $n$, một &lt;em&gt;vectơ&lt;/em&gt; trong $\mathbb{R}^n$ là một bộ $n$ số thực có thứ tự&lt;/p&gt;

\[x = (x_1, x_2, \dots, x_n).\]

  &lt;p&gt;Số $x_i$ gọi là &lt;em&gt;thành phần thứ $i$&lt;/em&gt; của $x$. Tập mọi vectơ như vậy ký hiệu là $\mathbb{R}^n$. Hai vectơ bằng nhau khi mọi thành phần tương ứng bằng nhau.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Trong tính toán ma trận ở các chương sau, ta thường viết vectơ thành &lt;strong&gt;cột&lt;/strong&gt;:&lt;/p&gt;

\[x = \begin{bmatrix} x_1 \\ x_2 \\ \vdots \\ x_n \end{bmatrix}.\]

&lt;p&gt;Cách viết theo hàng $(x_1, \dots, x_n)$ chỉ để tiết kiệm chỗ; hai cách viết chỉ cùng một vectơ.&lt;/p&gt;

&lt;h3 id=&quot;hai-cách-nhìn-một-vectơ&quot;&gt;Hai cách nhìn một vectơ&lt;/h3&gt;

&lt;p&gt;Với $n = 2$ hoặc $n = 3$, vectơ $x$ có hai cách hiểu:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;điểm&lt;/strong&gt;: điểm có toạ độ $(x_1, x_2)$ trên mặt phẳng;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;mũi tên&lt;/strong&gt;: mũi tên đi từ gốc $O$ đến điểm đó. Mũi tên có thể tịnh tiến đi chỗ khác mà vẫn là cùng một vectơ, vì nó chỉ ghi “đi bao nhiêu theo mỗi trục”.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Với $n \ge 4$ ta không vẽ được, nhưng các phép tính vẫn y hệt. Ví dụ, điểm thi bốn môn của một sinh viên $(7.5,\ 8,\ 6.5,\ 9)$ là một vectơ trong $\mathbb{R}^4$.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 2 (Vectơ không).&lt;/strong&gt; Vectơ $0 = (0, 0, \dots, 0) \in \mathbb{R}^n$ gọi là &lt;em&gt;vectơ không&lt;/em&gt;. Về hình học, đó là mũi tên có độ dài 0, nằm ở gốc.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;cộng-vectơ-và-nhân-vectơ-với-một-số&quot;&gt;Cộng vectơ và nhân vectơ với một số&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 3 (Phép cộng và phép nhân với số).&lt;/strong&gt; Cho $x = (x_1, \dots, x_n)$, $y = (y_1, \dots, y_n)$ trong $\mathbb{R}^n$ và số thực $c$. Ta định nghĩa&lt;/p&gt;

\[x + y = (x_1 + y_1, \dots, x_n + y_n), \qquad c\,x = (c x_1, \dots, c x_n).\]

  &lt;p&gt;Vectơ $-x = (-1)x$ là &lt;em&gt;vectơ đối&lt;/em&gt; của $x$, và $x - y = x + (-y)$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Chỉ cộng được hai vectơ có cùng số thành phần. Biểu thức $(1, 2) + (1, 2, 3)$ không có nghĩa.&lt;/p&gt;

&lt;h3 id=&quot;ý-nghĩa-hình-học&quot;&gt;Ý nghĩa hình học&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Quy tắc nối đuôi.&lt;/strong&gt; Đặt gốc của mũi tên $y$ vào ngọn của mũi tên $x$. Mũi tên từ gốc $O$ đến ngọn mới là $x + y$. Nếu đặt $x$ và $y$ cùng gốc, thì $x + y$ là đường chéo của hình bình hành dựng trên $x$ và $y$.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhân với số.&lt;/strong&gt; Với $c &amp;gt; 0$, mũi tên $c\,x$ cùng hướng với $x$ và dài gấp $c$ lần. Với $c &amp;lt; 0$, mũi tên đổi hướng ngược lại. Với $c = 0$ ta được vectơ không.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hiệu.&lt;/strong&gt; $x - y$ là mũi tên đi từ ngọn của $y$ đến ngọn của $x$ (khi hai mũi tên chung gốc).&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Cho $u = (2, 1)$ và $v = (-1, 3)$. Khi đó&lt;/p&gt;

\[u + v = (1, 4), \qquad 3u = (6, 3), \qquad 2u - v = (4 - (-1),\ 2 - 3) = (5, -1).\]

  &lt;p&gt;Vẽ trên giấy kẻ ô: $u$ chỉ sang phải và hơi lên, $v$ chỉ lên trên và hơi sang trái. Hình bình hành dựng trên $u, v$ có đỉnh thứ tư là $(1, 4)$. Vectơ $3u$ nằm trên cùng đường thẳng với $u$, dài gấp ba.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt; Tìm các số $c_1, c_2$ sao cho $c_1 (1, 2) + c_2 (3, 1) = (7, 4)$.&lt;/p&gt;

  &lt;p&gt;So sánh từng thành phần: $c_1 + 3c_2 = 7$ và $2c_1 + c_2 = 4$. Từ phương trình thứ hai, $c_2 = 4 - 2c_1$. Thế vào phương trình đầu: $c_1 + 12 - 6c_1 = 7$, nên $c_1 = 1$ và $c_2 = 2$. Kiểm tra: $(1, 2) + 2(3, 1) = (7, 4)$.&lt;/p&gt;

  &lt;p&gt;Về hình học: đi một bước theo $(1,2)$ rồi hai bước theo $(3,1)$ thì tới đúng điểm $(7,4)$. Câu hỏi “tới được điểm nào bằng các bước như vậy” sẽ là nội dung của Bài 1.4.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3 (trung điểm).&lt;/strong&gt; Trung điểm $M$ của đoạn $AB$ với $A = (1, 0, 4)$, $B = (3, -2, 2)$ là&lt;/p&gt;

\[M = \tfrac12 (A + B) = \tfrac12 (4, -2, 6) = (2, -1, 3).\]

  &lt;p&gt;Lý do: đi từ $A$ thêm nửa vectơ $B - A$ thì được $A + \tfrac12(B - A) = \tfrac12(A + B)$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;các-tính-chất-đại-số&quot;&gt;Các tính chất đại số&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Tám tính chất).&lt;/strong&gt; Với mọi $x, y, z \in \mathbb{R}^n$ và mọi số thực $a, b$:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$x + y = y + x$;&lt;/li&gt;
    &lt;li&gt;$(x + y) + z = x + (y + z)$;&lt;/li&gt;
    &lt;li&gt;$x + 0 = x$;&lt;/li&gt;
    &lt;li&gt;$x + (-x) = 0$;&lt;/li&gt;
    &lt;li&gt;$1\,x = x$;&lt;/li&gt;
    &lt;li&gt;$a(b\,x) = (ab)\,x$;&lt;/li&gt;
    &lt;li&gt;$a(x + y) = a x + a y$;&lt;/li&gt;
    &lt;li&gt;$(a + b)\,x = a x + b x$.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Mỗi đẳng thức là một đẳng thức giữa hai vectơ, nên chỉ cần kiểm tra thành phần thứ $i$ của hai vế với mọi $i$. Thành phần thứ $i$ của mỗi vế là một biểu thức với số thực, và đẳng thức đúng nhờ tính chất của số thực. Ví dụ với tính chất 7: thành phần thứ $i$ của $a(x+y)$ là $a(x_i + y_i)$, của $ax + ay$ là $a x_i + a y_i$; hai số này bằng nhau theo luật phân phối của số thực. Các tính chất còn lại làm tương tự.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Tám tính chất này rất quan trọng. Ở Chương 05, ta lấy chính chúng làm định nghĩa của &lt;em&gt;không gian vectơ&lt;/em&gt;, rồi áp dụng cho đa thức, ma trận, hàm số.&lt;/p&gt;

&lt;div class=&quot;content-box insight-box textbook-block&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Nhận xét.&lt;/strong&gt; Nhờ Định lý 1, ta biến đổi biểu thức vectơ như biến đổi biểu thức số: chuyển vế, nhóm số hạng, đặt nhân tử chung. Ví dụ, từ $2x + (1, 3) = (5, -1)$ suy ra $2x = (4, -4)$, nên $x = (2, -2)$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-ảnh-màu-và-dữ-liệu-là-vectơ&quot;&gt;Ứng dụng: ảnh màu và dữ liệu là vectơ&lt;/h2&gt;

&lt;p&gt;Một điểm ảnh màu được mô tả bằng ba số (đỏ, xanh lá, xanh dương), mỗi số trong khoảng $[0, 1]$. Ví dụ màu cam là $o = (1,\ 0.5,\ 0)$, màu xanh dương là $b = (0,\ 0,\ 1)$.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Trộn hai màu theo tỉ lệ $t$ và $1 - t$ là tính $t\,o + (1 - t)\,b$. Với $t = 0.5$ ta được $(0.5,\ 0.25,\ 0.5)$, một màu tím nhạt. Đây là cách phần mềm đồ hoạ làm hiệu ứng chuyển màu.&lt;/li&gt;
  &lt;li&gt;Làm tối ảnh một nửa là nhân mọi vectơ màu với $0.5$.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Trong học máy, mỗi mẫu dữ liệu cũng là một vectơ: một căn nhà có thể là $(\text{diện tích}, \text{số phòng}, \text{tuổi nhà}) = (75, 3, 10) \in \mathbb{R}^3$. Lấy trung bình của nhiều mẫu là cộng các vectơ rồi nhân với $1/m$.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: cộng, trừ và nhân vectơ với số&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo u, v; chọn các thẻ u + v, u − v, k·u.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter01/vecto_2d.html?mode=add&quot; title=&quot;Minh hoạ: cộng, trừ và nhân vectơ với số&quot; loading=&quot;lazy&quot; style=&quot;height: 620px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter01/vecto_2d.html?mode=add&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (cơ bản).&lt;/strong&gt; Cho $x = (1, -2, 3)$, $y = (0, 4, -1)$. Tính $x + y$, $-2x$, $3x - 2y$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$x + y = (1, 2, 2)$; $-2x = (-2, 4, -6)$; $3x - 2y = (3, -14, 11)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (cơ bản).&lt;/strong&gt; Tìm $x \in \mathbb{R}^2$ biết $3x - (1, 2) = (5, 4)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$3x = (6, 6)$ nên $x = (2, 2)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (vận dụng).&lt;/strong&gt; Cho tam giác $ABC$ với $A = (0, 0)$, $B = (4, 0)$, $C = (2, 6)$. Tính trọng tâm $G = \tfrac13(A + B + C)$ và kiểm tra rằng $G$ nằm trên đoạn nối $C$ với trung điểm $M$ của $AB$, tại vị trí $M + \tfrac13 (C - M)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$G = (2, 2)$. Trung điểm $M = (2, 0)$, và $M + \tfrac13 (C - M) = (2, 0) + \tfrac13 (0, 6) = (2, 2) = G$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4 (vận dụng).&lt;/strong&gt; Chứng minh từ Định lý 1 rằng $0\,x = 0$ với mọi $x$. (Gợi ý: $0\,x = (0 + 0)\,x$.)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Theo tính chất 8, $0\,x = (0+0)\,x = 0\,x + 0\,x$. Cộng $-(0\,x)$ vào hai vế và dùng tính chất 2, 3, 4 ta được $0 = 0\,x$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao / lập trình).&lt;/strong&gt; Viết trong NumPy: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x = np.array([1, -2, 3]); y = np.array([0, 4, -1])&lt;/code&gt;, rồi tính &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;3*x - 2*y&lt;/code&gt;. So với kết quả Bài tập 1. Sau đó tính màu ở giữa cam $(1, 0.5, 0)$ và xanh dương $(0, 0, 1)$ với $t = 0.25$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

`array([ 3, -14, 11])`. Với $t = 0.25$: $0.25(1, 0.5, 0) + 0.75(0, 0, 1) = (0.25,\ 0.125,\ 0.75)$, gần với màu xanh dương hơn.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Vectơ trong $\mathbb{R}^n$ là bộ $n$ số; với $n = 2, 3$ nó là một mũi tên.&lt;/li&gt;
    &lt;li&gt;Cộng vectơ và nhân với số làm theo từng thành phần; về hình học là quy tắc hình bình hành và phép co giãn.&lt;/li&gt;
    &lt;li&gt;Tám tính chất của Định lý 1 cho phép biến đổi biểu thức vectơ như biểu thức số, và sẽ là định nghĩa của không gian vectơ ở Chương 05.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Làm việc với ma trận trên máy tính</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter00/00_03_Lam_Viec_Voi_Ma_Tran_Tren_May_Tinh/"/>
   <updated>2026-01-01T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter00/00_03_Lam_Viec_Voi_Ma_Tran_Tren_May_Tinh</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;tạo vectơ, ma trận và thực hiện các phép toán cơ bản bằng NumPy và SymPy;&lt;/li&gt;
    &lt;li&gt;dùng SymPy để kiểm tra một kết quả tính tay (khử Gauss, nghịch đảo, định thức) bằng phân số chính xác;&lt;/li&gt;
    &lt;li&gt;giải thích vì sao &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.1 + 0.2 == 0.3&lt;/code&gt; trả về &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;False&lt;/code&gt; và cách so sánh số thực dấu phẩy động cho đúng.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Mở Python và gõ:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.3&lt;/span&gt;
&lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.2&lt;/span&gt;
&lt;span class=&quot;mf&quot;&gt;0.30000000000000004&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Máy tính không sai: nó lưu số thực ở hệ nhị phân với 53 bit, và $0.1$ không biểu diễn được chính xác trong hệ nhị phân, giống như $1/3$ không viết được chính xác bằng số thập phân hữu hạn. Khi tính với ma trận, các sai số nhỏ này có thể cộng dồn. Bài này giới thiệu hai công cụ: NumPy (tính nhanh, xấp xỉ) và SymPy (tính chậm hơn, chính xác), và khi nào dùng công cụ nào.&lt;/p&gt;

&lt;h2 id=&quot;cài-đặt&quot;&gt;Cài đặt&lt;/h2&gt;

&lt;p&gt;Cả hai thư viện cài bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pip&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python3 &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; venv la-venv
&lt;span class=&quot;nb&quot;&gt;source &lt;/span&gt;la-venv/bin/activate
pip &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;numpy sympy
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Có thể dùng Jupyter hoặc Google Colab (đã có sẵn cả hai thư viện) nếu không muốn cài đặt.&lt;/p&gt;

&lt;h2 id=&quot;numpy-tính-xấp-xỉ-nhanh&quot;&gt;NumPy: tính xấp xỉ, nhanh&lt;/h2&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;               &lt;span class=&quot;c1&quot;&gt;# tích ma trận với vectơ: array([11, 18])
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;                 &lt;span class=&quot;c1&quot;&gt;# ma trận chuyển vị
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;det&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;# định thức: 5.000000000000001
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;inv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;# nghịch đảo (số thực)
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;solve&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;# nghiệm của Ax = b: array([0.8, 1.4])
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Chú ý: phép nhân ma trận là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@&lt;/code&gt;, còn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;*&lt;/code&gt; nhân &lt;em&gt;từng phần tử&lt;/em&gt;. Định thức ra &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;5.000000000000001&lt;/code&gt; chứ không phải &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;5&lt;/code&gt;: NumPy tính bằng phân tích LU với số thực dấu phẩy động (Chương 03).&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Số dấu phẩy động).&lt;/strong&gt; Một &lt;em&gt;số dấu phẩy động&lt;/em&gt; độ chính xác kép (kiểu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float64&lt;/code&gt;) có dạng $\pm m \cdot 2^e$ với $m$ có 53 bit nhị phân. Sai số tương đối khi làm tròn một số thực về &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float64&lt;/code&gt; không vượt quá $\varepsilon = 2^{-53} \approx 1{,}1 \times 10^{-16}$, gọi là &lt;em&gt;đơn vị làm tròn&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Hệ quả thực hành: &lt;strong&gt;không so sánh hai số thực bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;==&lt;/code&gt;&lt;/strong&gt;. Thay vào đó, kiểm tra hiệu đủ nhỏ:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;isclose&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;          &lt;span class=&quot;c1&quot;&gt;# True
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;allclose&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;inv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;eye&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;# True
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;sympy-tính-chính-xác-bằng-ký-hiệu&quot;&gt;SymPy: tính chính xác, bằng ký hiệu&lt;/h2&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sympy&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Matrix&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Rational&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;symbols&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Matrix&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;det&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;         &lt;span class=&quot;c1&quot;&gt;# 5
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;inv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;         &lt;span class=&quot;c1&quot;&gt;# Matrix([[3/5, -1/5], [-1/5, 2/5]])
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rref&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;        &lt;span class=&quot;c1&quot;&gt;# (Matrix([[1, 0], [0, 1]]), (0, 1))
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;nullspace&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;# [] (hạt nhân chỉ có vectơ 0)
&lt;/span&gt;
&lt;span class=&quot;nc&quot;&gt;Rational&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Rational&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Rational&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;# True
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;SymPy lưu số hữu tỉ dưới dạng phân số, nên khử Gauss cho kết quả đúng tuyệt đối. Nó còn tính với biến:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;symbols&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;M&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Matrix&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;det&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;         &lt;span class=&quot;c1&quot;&gt;# 1 - t**2
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Từ đó ta biết ngay $M$ suy biến đúng khi $t = \pm 1$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1 (kiểm tra bài khử Gauss).&lt;/strong&gt; Giả sử bằng tay ta đưa ma trận&lt;/p&gt;

\[B = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 &amp;amp; 1 \\ 2 &amp;amp; 4 &amp;amp; 1 &amp;amp; 3 \\ 3 &amp;amp; 6 &amp;amp; 1 &amp;amp; 4 \end{bmatrix}\]

  &lt;p&gt;về dạng bậc thang rút gọn và được hai cột trụ là cột 1 và cột 3. Kiểm tra bằng SymPy:&lt;/p&gt;

  &lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;B&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Matrix&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;R&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pivots&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rref&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# R = Matrix([[1, 2, 0, 1], [0, 0, 1, 1], [0, 0, 0, 0]]), pivots = (0, 2)
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;  &lt;/div&gt;

  &lt;p&gt;SymPy đánh số cột từ $0$, nên &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(0, 2)&lt;/code&gt; là cột 1 và cột 3. Hạng bằng 2, khớp với tính tay.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;khi-nào-dùng-công-cụ-nào&quot;&gt;Khi nào dùng công cụ nào&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;SymPy&lt;/strong&gt; cho ma trận nhỏ có hệ số nguyên hoặc phân số, khi cần kết quả chính xác: kiểm tra bài tập, tìm cơ sở của hạt nhân, tính định thức có tham số.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;NumPy&lt;/strong&gt; cho ma trận lớn hoặc dữ liệu đo đạc (vốn đã có sai số): bình phương tối thiểu (Chương 08), trị riêng của ma trận lớn (Chương 09), SVD và PCA (Chương 11).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Một hiện tượng cần biết: với số thực dấu phẩy động, “hạng” không còn rõ ràng. Một ma trận về lý thuyết suy biến có thể cho định thức $10^{-17}$ thay vì $0$. Cách xử lý đúng là dùng các giá trị kỳ dị (Chương 11) và một ngưỡng sai số, như &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.linalg.matrix_rank&lt;/code&gt; làm.&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-kiểm-tra-bài-làm-của-chính-mình&quot;&gt;Ứng dụng: kiểm tra bài làm của chính mình&lt;/h2&gt;

&lt;p&gt;Mỗi bài tập trong khoá đều có thể kiểm tra bằng vài dòng SymPy. Thói quen tốt: giải bằng tay trước, rồi dùng máy để kiểm tra; nếu khác nhau, tìm bước sai thay vì chép kết quả máy. Với NumPy, kiểm tra một nghiệm $x$ của $Ax = b$ bằng cách tính &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.allclose(A @ x, b)&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: chạy NumPy và SymPy ngay trên trình duyệt&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Sửa và chạy mã Python để so sánh kết quả xấp xỉ của NumPy với kết quả chính xác của SymPy.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter00/may_tinh_ma_tran.html&quot; title=&quot;Minh hoạ: chạy NumPy và SymPy ngay trên trình duyệt&quot; loading=&quot;lazy&quot; style=&quot;height: 760px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter00/may_tinh_ma_tran.html&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1 (lập trình).&lt;/strong&gt; So sánh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.1 + 0.2 == 0.3&lt;/code&gt; trong NumPy (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.float64(0.1) + np.float64(0.2) == np.float64(0.3)&lt;/code&gt;) với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Rational(1,10) + Rational(2,10) == Rational(3,10)&lt;/code&gt; trong SymPy. Giải thích kết quả.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

NumPy cho `False` vì $0.1$, $0.2$, $0.3$ đều bị làm tròn khi lưu ở hệ nhị phân, và tổng sau làm tròn khác $0.3$ sau làm tròn ở bit cuối. SymPy cho `True` vì nó lưu các phân số $1/10$, $2/10$, $3/10$ chính xác.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2 (lập trình).&lt;/strong&gt; Dùng SymPy tính nghịch đảo của $\begin{bmatrix} 1 &amp;amp; 2 \\ 3 &amp;amp; 4 \end{bmatrix}$ và kiểm tra bằng tay.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

`Matrix([[1, 2], [3, 4]]).inv()` cho $\begin{bmatrix} -2 &amp;amp; 1 \\ 3/2 &amp;amp; -1/2 \end{bmatrix}$. Theo công thức $\frac{1}{ad - bc}\begin{bmatrix} d &amp;amp; -b \\ -c &amp;amp; a \end{bmatrix}$ với $ad - bc = -2$, kết quả khớp.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3 (lập trình).&lt;/strong&gt; Ma trận Hilbert $H_n$ có phần tử $1/(i + j - 1)$. Với $n = 12$, tính &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.linalg.inv(H) @ H&lt;/code&gt; bằng NumPy và so với ma trận đơn vị. Làm lại bằng SymPy (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sympy.hilbert(12)&lt;/code&gt;). Nhận xét.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Với NumPy, kết quả khác ma trận đơn vị rõ rệt (sai số có thể cỡ $10^{-2}$ trở lên) vì $H_{12}$ có số điều kiện cỡ $10^{16}$ (Chương 11): sai số làm tròn bị khuếch đại khoảng $10^{16}$ lần. SymPy tính bằng phân số và cho đúng ma trận đơn vị.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Dùng SymPy tìm các giá trị $t$ để $\begin{bmatrix} 1 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; t &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; t \end{bmatrix}$ suy biến.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Định thức là $(t - 1)^2$, nên ma trận suy biến đúng khi $t = 1$.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;NumPy tính nhanh với số thực dấu phẩy động (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float64&lt;/code&gt;, sai số tương đối khoảng $10^{-16}$); dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@&lt;/code&gt; để nhân ma trận và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.isclose&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.allclose&lt;/code&gt; để so sánh.&lt;/li&gt;
    &lt;li&gt;SymPy tính chính xác với phân số và biến: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Matrix&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rref&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inv&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;det&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nullspace&lt;/code&gt;.&lt;/li&gt;
    &lt;li&gt;Giải tay trước, kiểm tra bằng máy sau; ma trận nhỏ dùng SymPy, dữ liệu lớn dùng NumPy.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Số phức và trường số</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter00/00_02_So_Phuc_Va_Truong_So/"/>
   <updated>2026-01-01T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter00/00_02_So_Phuc_Va_Truong_So</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;cộng, nhân, chia số phức ở dạng đại số $a + bi$ và tính số phức liên hợp, môđun;&lt;/li&gt;
    &lt;li&gt;chuyển số phức sang dạng lượng giác và dùng công thức de Moivre để tính luỹ thừa và căn;&lt;/li&gt;
    &lt;li&gt;nêu định nghĩa trường và kiểm tra $\mathbb{Q}$, $\mathbb{R}$, $\mathbb{C}$, $\mathbb{F}_2$ là trường.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Ma trận quay góc $90^\circ$ trong mặt phẳng là&lt;/p&gt;

\[A = \begin{bmatrix} 0 &amp;amp; -1 \\ 1 &amp;amp; 0 \end{bmatrix}.\]

&lt;p&gt;Không có vectơ thực khác $0$ nào được $A$ giữ nguyên phương: mọi vectơ đều bị quay đi. Ở Chương 09, điều này có nghĩa là $A$ không có trị riêng thực; phương trình đặc trưng của nó là $\lambda^2 + 1 = 0$. Trong số phức, phương trình này có hai nghiệm $\lambda = \pm i$. Số phức cho phép ta nói về “trị riêng” của phép quay, và nhân với $i$ chính là quay $90^\circ$.&lt;/p&gt;

&lt;h2 id=&quot;số-phức-ở-dạng-đại-số&quot;&gt;Số phức ở dạng đại số&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Số phức).&lt;/strong&gt; Một &lt;em&gt;số phức&lt;/em&gt; là biểu thức $z = a + bi$ với $a, b \in \mathbb{R}$ và $i^2 = -1$. Số $a = \operatorname{Re} z$ là &lt;em&gt;phần thực&lt;/em&gt;, $b = \operatorname{Im} z$ là &lt;em&gt;phần ảo&lt;/em&gt;. Tập các số phức ký hiệu $\mathbb{C}$. Phép cộng và nhân:&lt;/p&gt;

\[(a + bi) + (c + di) = (a + c) + (b + d)i, \qquad (a + bi)(c + di) = (ac - bd) + (ad + bc)i.\]

  &lt;p&gt;&lt;em&gt;Số phức liên hợp&lt;/em&gt; của $z = a + bi$ là $\bar z = a - bi$, &lt;em&gt;môđun&lt;/em&gt; của $z$ là $|z| = \sqrt{a^2 + b^2}$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Công thức nhân không cần nhớ: khai triển như đa thức theo $i$ rồi thay $i^2 = -1$. Ta có $z \bar z = a^2 + b^2 = |z|^2$, nên với $z \ne 0$:&lt;/p&gt;

\[\frac{1}{z} = \frac{\bar z}{|z|^2}.\]

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Với $z = 2 + 3i$, $w = 1 - i$:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$z + w = 3 + 2i$;&lt;/li&gt;
    &lt;li&gt;$zw = 2 - 2i + 3i - 3i^2 = 5 + i$;&lt;/li&gt;
    &lt;li&gt;$\dfrac{z}{w} = \dfrac{(2 + 3i)(1 + i)}{(1 - i)(1 + i)} = \dfrac{2 + 2i + 3i - 3}{2} = -\dfrac{1}{2} + \dfrac{5}{2} i$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;p&gt;Số phức $a + bi$ ứng với điểm $(a, b)$ trong &lt;em&gt;mặt phẳng phức&lt;/em&gt; (mặt phẳng Argand). Phép cộng số phức là phép cộng vectơ trong $\mathbb{R}^2$; $\bar z$ là ảnh đối xứng của $z$ qua trục thực; $|z|$ là độ dài vectơ.&lt;/p&gt;

&lt;h2 id=&quot;dạng-lượng-giác-và-công-thức-de-moivre&quot;&gt;Dạng lượng giác và công thức de Moivre&lt;/h2&gt;

&lt;p&gt;Mọi $z \ne 0$ viết được dưới dạng&lt;/p&gt;

\[z = r(\cos\theta + i \sin\theta) = r e^{i\theta}, \qquad r = |z|,\]

&lt;p&gt;trong đó $\theta$ là góc từ trục thực dương đến vectơ $z$, gọi là &lt;em&gt;argument&lt;/em&gt; của $z$ (xác định sai khác bội của $2\pi$). Ký hiệu $e^{i\theta} = \cos\theta + i\sin\theta$ là &lt;em&gt;công thức Euler&lt;/em&gt;.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1 (Nhân ở dạng lượng giác).&lt;/strong&gt; Nếu $z = r e^{i\alpha}$ và $w = s e^{i\beta}$ thì $zw = rs\, e^{i(\alpha + \beta)}$. Hệ quả (công thức de Moivre): $z^n = r^n e^{in\alpha}$ với mọi số nguyên $n$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Nhân trực tiếp:
$(\cos\alpha + i\sin\alpha)(\cos\beta + i\sin\beta) = (\cos\alpha\cos\beta - \sin\alpha\sin\beta) + i(\sin\alpha\cos\beta + \cos\alpha\sin\beta)$,
và theo công thức cộng góc, vế phải bằng $\cos(\alpha + \beta) + i\sin(\alpha + \beta)$. Công thức de Moivre suy ra bằng quy nạp theo $n$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Ý nghĩa hình học: nhân với $w = s e^{i\beta}$ là &lt;em&gt;quay&lt;/em&gt; mặt phẳng phức góc $\beta$ và &lt;em&gt;co giãn&lt;/em&gt; hệ số $s$. Nhân với $i = e^{i\pi/2}$ là quay $90^\circ$, khớp với ví dụ mở đầu.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2 (luỹ thừa).&lt;/strong&gt; Tính $(1 + i)^{10}$. Ta có $1 + i = \sqrt{2}\, e^{i\pi/4}$, nên&lt;/p&gt;

  &lt;p&gt;\((1 + i)^{10} = (\sqrt{2})^{10} e^{i \cdot 10\pi/4} = 32\, e^{i 5\pi/2} = 32\, e^{i\pi/2} = 32 i.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3 (căn bậc $n$).&lt;/strong&gt; Giải $z^3 = 8i$. Viết $8i = 8 e^{i\pi/2}$ và $z = r e^{i\theta}$. Từ $r^3 e^{3i\theta} = 8 e^{i\pi/2}$ được $r = 2$ và $3\theta = \pi/2 + 2k\pi$, tức $\theta = \pi/6 + 2k\pi/3$ với $k = 0, 1, 2$. Ba nghiệm:&lt;/p&gt;

\[z_0 = 2e^{i\pi/6} = \sqrt{3} + i, \qquad z_1 = 2e^{i5\pi/6} = -\sqrt{3} + i, \qquad z_2 = 2e^{i3\pi/2} = -2i.\]

  &lt;p&gt;Ba nghiệm là ba đỉnh của một tam giác đều nội tiếp đường tròn bán kính 2.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2 (Định lý cơ bản của đại số).&lt;/strong&gt; Mọi đa thức bậc $n \ge 1$ với hệ số phức có đúng $n$ nghiệm phức, tính cả bội.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Ta công nhận định lý này (chứng minh cần giải tích phức). Nó đảm bảo mọi ma trận vuông cỡ $n$ có đúng $n$ trị riêng phức tính cả bội (Chương 09).&lt;/p&gt;

&lt;h2 id=&quot;số-phức-như-ma-trận&quot;&gt;Số phức như ma trận&lt;/h2&gt;

&lt;p&gt;Phép nhân với $z = a + bi$ là ánh xạ $\mathbb{R}^2 \to \mathbb{R}^2$ biến $(x, y)$ thành $(ax - by,\ bx + ay)$. Ánh xạ này tuyến tính, với ma trận&lt;/p&gt;

\[M_z = \begin{bmatrix} a &amp;amp; -b \\ b &amp;amp; a \end{bmatrix} = r \begin{bmatrix} \cos\theta &amp;amp; -\sin\theta \\ \sin\theta &amp;amp; \cos\theta \end{bmatrix}.\]

&lt;p&gt;Ta có $M_{zw} = M_z M_w$ và $M_{z + w} = M_z + M_w$: số phức “là” các ma trận quay–co giãn. Với $z = i$ ta được đúng ma trận $A$ ở ví dụ mở đầu.&lt;/p&gt;

&lt;h2 id=&quot;trường-số&quot;&gt;Trường số&lt;/h2&gt;

&lt;p&gt;Khi giải hệ phương trình bằng khử Gauss (Chương 02), ta chỉ dùng bốn phép toán cộng, trừ, nhân, chia cho số khác $0$. Mọi tập số có bốn phép toán này với các quy tắc quen thuộc đều dùng được.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 2 (Trường).&lt;/strong&gt; Một &lt;em&gt;trường&lt;/em&gt; là một tập $\mathbb{F}$ có hai phép toán $+$ và $\cdot$ thoả mãn, với mọi $a, b, c \in \mathbb{F}$:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$+$ và $\cdot$ giao hoán, kết hợp, và $a(b + c) = ab + ac$;&lt;/li&gt;
    &lt;li&gt;có phần tử $0$ với $a + 0 = a$, và mỗi $a$ có phần tử đối $-a$ với $a + (-a) = 0$;&lt;/li&gt;
    &lt;li&gt;có phần tử $1 \ne 0$ với $a \cdot 1 = a$, và mỗi $a \ne 0$ có nghịch đảo $a^{-1}$ với $a a^{-1} = 1$.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 4.&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$\mathbb{Q}$, $\mathbb{R}$, $\mathbb{C}$ là trường. Với $\mathbb{C}$, nghịch đảo của $z \ne 0$ là $\bar z / |z|^2$.&lt;/li&gt;
    &lt;li&gt;$\mathbb{Z}$ không phải trường: $2$ không có nghịch đảo trong $\mathbb{Z}$.&lt;/li&gt;
    &lt;li&gt;$\mathbb{F}_2 = \{0, 1\}$ với phép cộng và nhân theo modulo 2 ($1 + 1 = 0$) là một trường. Đây là hai lớp chẵn, lẻ ở Bài 00-01.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;p&gt;Bảng phép toán của $\mathbb{F}_2$: $0 + 0 = 0$, $0 + 1 = 1$, $1 + 1 = 0$; $0 \cdot 0 = 0 \cdot 1 = 0$, $1 \cdot 1 = 1$. Trong $\mathbb{F}_2$, $-1 = 1$, nên trừ cũng là cộng.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 5 (cùng một hệ, khác trường).&lt;/strong&gt; Xét hệ&lt;/p&gt;

\[x + y = 1, \qquad y + z = 1, \qquad x + z = 1.\]

  &lt;p&gt;Trên $\mathbb{R}$, cộng ba phương trình được $2(x + y + z) = 3$, và hệ có nghiệm duy nhất $x = y = z = 1/2$. Trên $\mathbb{F}_2$, cộng ba phương trình được $2(x + y + z) = 0$ ở vế trái và $1 + 1 + 1 = 1$ ở vế phải, tức $0 = 1$: hệ vô nghiệm. Kết quả phụ thuộc trường ta làm việc.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Trong khoá này, trừ khi nói khác, các số là số thực. Hầu hết định lý ở Chương 01 đến Chương 06 đúng nguyên văn trên mọi trường; ta sẽ chỉ rõ khi cần đến $\mathbb{C}$ (trị riêng phức, Chương 09) hoặc khi cần đến thứ tự và căn bậc hai của $\mathbb{R}$ (độ dài, góc, Chương 07).&lt;/p&gt;

&lt;h2 id=&quot;ứng-dụng-mã-sửa-lỗi-trên-mathbbf_2&quot;&gt;Ứng dụng: mã sửa lỗi trên $\mathbb{F}_2$&lt;/h2&gt;

&lt;p&gt;Dữ liệu số là dãy bit, tức là vectơ trên $\mathbb{F}_2$. Mã Hamming $(7, 4)$ gửi 4 bit dữ liệu kèm 3 bit kiểm tra, sao cho mỗi từ mã $c$ thoả $Hc = 0$ với một ma trận $H$ cỡ $3 \times 7$ trên $\mathbb{F}_2$. Nếu đường truyền làm sai một bit, người nhận tính $Hc&apos;$, và kết quả cho biết vị trí bit bị sai. Toàn bộ phép tính là đại số tuyến tính trên trường $\mathbb{F}_2$.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: số phức trên mặt phẳng phức&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Kéo z₁, z₂ để thấy phép cộng, nhân (nhân mô-đun, cộng góc), chia, liên hợp và luỹ thừa.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter00/so_phuc.html&quot; title=&quot;Minh hoạ: số phức trên mặt phẳng phức&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter00/so_phuc.html&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;video-ngắn-nhân-số-phức-là-quay-và-co-giãn-mặt-phẳng&quot;&gt;Video ngắn: Nhân số phức là quay và co giãn mặt phẳng&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/complex-rotation.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Nhân với i quay 90°, nhân với 1 + i quay 45° và giãn √2 lần; độ dài nhân nhau, góc cộng nhau. Bản im lặng.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Tính $(3 - 2i)(1 + 4i)$ và $\dfrac{3 - 2i}{1 + 4i}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$(3 - 2i)(1 + 4i) = 3 + 12i - 2i - 8i^2 = 11 + 10i$.
$\dfrac{3 - 2i}{1 + 4i} = \dfrac{(3 - 2i)(1 - 4i)}{17} = \dfrac{3 - 12i - 2i + 8i^2}{17} = \dfrac{-5 - 14i}{17}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Viết $z = -1 + \sqrt{3}\, i$ ở dạng lượng giác rồi tính $z^6$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$|z| = 2$, $\theta = 2\pi/3$, nên $z = 2e^{i2\pi/3}$ và $z^6 = 64\, e^{i4\pi} = 64$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Giải $z^4 = -16$ trong $\mathbb{C}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$-16 = 16 e^{i\pi}$, nên $z = 2 e^{i(\pi/4 + k\pi/2)}$, $k = 0, 1, 2, 3$: $z = \pm\sqrt{2} \pm \sqrt{2}\, i$ (bốn tổ hợp dấu).

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Kiểm tra $M_z M_w = M_{zw}$ với $z = 1 + i$, $w = 2 - i$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$zw = 2 - i + 2i - i^2 = 3 + i$. Ta có $M_z M_w = \begin{bmatrix} 1 &amp;amp; -1 \\ 1 &amp;amp; 1 \end{bmatrix} \begin{bmatrix} 2 &amp;amp; 1 \\ -1 &amp;amp; 2 \end{bmatrix} = \begin{bmatrix} 3 &amp;amp; -1 \\ 1 &amp;amp; 3 \end{bmatrix} = M_{3 + i}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Tập $\mathbb{Z}_4 = \{0, 1, 2, 3\}$ với cộng và nhân modulo 4 có phải trường không? Còn $\mathbb{Z}_5$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\mathbb{Z}_4$ không phải trường: $2 \cdot 2 = 0$, nên $2$ không có nghịch đảo (nếu $2a = 1$ thì $0 = 2 \cdot 2a = 2$, vô lý). $\mathbb{Z}_5$ là trường: $1^{-1} = 1$, $2^{-1} = 3$, $3^{-1} = 2$, $4^{-1} = 4$. Tổng quát, $\mathbb{Z}_p$ là trường đúng khi $p$ là số nguyên tố.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$z = a + bi$, $i^2 = -1$; $\bar z = a - bi$; $|z|^2 = z\bar z$; $1/z = \bar z / |z|^2$.&lt;/li&gt;
    &lt;li&gt;Dạng lượng giác $z = re^{i\theta}$: nhân là nhân môđun và cộng góc, $z^n = r^n e^{in\theta}$; phương trình $z^n = w$ có $n$ nghiệm cách đều trên một đường tròn.&lt;/li&gt;
    &lt;li&gt;Nhân với $a + bi$ là ánh xạ tuyến tính của $\mathbb{R}^2$ với ma trận $\begin{bmatrix} a &amp;amp; -b \\ b &amp;amp; a \end{bmatrix}$ (quay và co giãn).&lt;/li&gt;
    &lt;li&gt;Trường là tập có bốn phép toán với các quy tắc quen thuộc: $\mathbb{Q}$, $\mathbb{R}$, $\mathbb{C}$, $\mathbb{F}_2$. Đại số tuyến tính làm được trên mọi trường.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Tập hợp, ánh xạ và quan hệ</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/vi/chapter00/00_01_Tap_Hop_Anh_Xa_Va_Quan_He/"/>
   <updated>2026-01-01T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/vi/chapter00/00_01_Tap_Hop_Anh_Xa_Va_Quan_He</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Mục tiêu học tập.&lt;/strong&gt; Sau bài này, người học có thể:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;đọc và viết tập hợp bằng ký hiệu liệt kê và ký hiệu mô tả, dùng đúng $\in$, $\subseteq$, $\cup$, $\cap$, $\times$;&lt;/li&gt;
    &lt;li&gt;kiểm tra một ánh xạ có phải đơn ánh, toàn ánh, song ánh hay không;&lt;/li&gt;
    &lt;li&gt;nhận ra một quan hệ tương đương và mô tả các lớp tương đương của nó.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;ví-dụ-mở-đầu&quot;&gt;Ví dụ mở đầu&lt;/h2&gt;

&lt;p&gt;Một hệ thống cấp mã số cho sinh viên. Mỗi sinh viên nhận đúng một mã: đó là một &lt;em&gt;ánh xạ&lt;/em&gt; từ tập sinh viên vào tập mã. Hai câu hỏi tự nhiên:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Có hai sinh viên nào trùng mã không? Nếu không, ánh xạ là &lt;em&gt;đơn ánh&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Mã nào cũng có người dùng không? Nếu có, ánh xạ là &lt;em&gt;toàn ánh&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Khi cả hai đều đúng, từ mã ta tìm lại được đúng một sinh viên: ánh xạ có &lt;em&gt;nghịch đảo&lt;/em&gt;. Trong đại số tuyến tính, câu hỏi “hệ $Ax = b$ có nghiệm không, có duy nhất không” chính là hai câu hỏi này cho ánh xạ $x \mapsto Ax$.&lt;/p&gt;

&lt;h2 id=&quot;tập-hợp&quot;&gt;Tập hợp&lt;/h2&gt;

&lt;p&gt;Một &lt;em&gt;tập hợp&lt;/em&gt; là một bộ sưu tập các đối tượng, gọi là &lt;em&gt;phần tử&lt;/em&gt;. Viết $x \in S$ nếu $x$ là phần tử của $S$, và $x \notin S$ nếu không.&lt;/p&gt;

&lt;p&gt;Có hai cách mô tả tập hợp:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;liệt kê: $S = \{1, 2, 3\}$;&lt;/li&gt;
  &lt;li&gt;mô tả bằng tính chất: $S = \{x \in \mathbb{Z} : 1 \le x \le 3\}$, đọc là “tập các số nguyên $x$ sao cho $1 \le x \le 3$”.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Các tập số dùng trong khoá: $\mathbb{N} = \{0, 1, 2, \dots\}$, $\mathbb{Z}$ (số nguyên), $\mathbb{Q}$ (số hữu tỉ), $\mathbb{R}$ (số thực), $\mathbb{C}$ (số phức, Bài 00-02).&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 1 (Các phép toán tập hợp).&lt;/strong&gt; Cho hai tập $A$, $B$.&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$A \subseteq B$ ($A$ là &lt;em&gt;tập con&lt;/em&gt; của $B$) nếu mọi phần tử của $A$ đều thuộc $B$. Hai tập bằng nhau khi $A \subseteq B$ và $B \subseteq A$.&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;Hợp&lt;/em&gt;: $A \cup B = \{x : x \in A \text{ hoặc } x \in B\}$.&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;Giao&lt;/em&gt;: $A \cap B = \{x : x \in A \text{ và } x \in B\}$.&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;Hiệu&lt;/em&gt;: $A \setminus B = \{x \in A : x \notin B\}$.&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;Tích Descartes&lt;/em&gt;: $A \times B = \{(a, b) : a \in A,\ b \in B\}$, tập các cặp có thứ tự.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Tập không có phần tử nào là &lt;em&gt;tập rỗng&lt;/em&gt;, ký hiệu $\varnothing$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Tích Descartes là nơi $\mathbb{R}^n$ ra đời: $\mathbb{R}^2 = \mathbb{R} \times \mathbb{R}$ là tập các cặp $(x_1, x_2)$, và $\mathbb{R}^n$ là tập các bộ $n$ số thực.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 1.&lt;/strong&gt; Tập nghiệm của bất phương trình $x^2 &amp;lt; 4$ trong $\mathbb{R}$ là&lt;/p&gt;

\[\{x \in \mathbb{R} : x^2 &amp;lt; 4\} = \{x \in \mathbb{R} : -2 &amp;lt; x &amp;lt; 2\} = (-2, 2).\]

  &lt;p&gt;Với $A = \{1, 2, 3\}$ và $B = \{2, 3, 4\}$: $A \cup B = \{1, 2, 3, 4\}$, $A \cap B = \{2, 3\}$, $A \setminus B = \{1\}$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Để chứng minh $A = B$, cách chuẩn là chứng minh hai chiều $A \subseteq B$ và $B \subseteq A$: lấy $x$ tuỳ ý trong một tập rồi chỉ ra $x$ thuộc tập kia. Ta sẽ dùng cách này nhiều lần, ví dụ khi chứng minh hai không gian con bằng nhau ở Chương 05.&lt;/p&gt;

&lt;h2 id=&quot;ánh-xạ&quot;&gt;Ánh xạ&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 2 (Ánh xạ).&lt;/strong&gt; Một &lt;em&gt;ánh xạ&lt;/em&gt; $f : X \to Y$ gán cho mỗi phần tử $x \in X$ đúng một phần tử $f(x) \in Y$. Tập $X$ là &lt;em&gt;tập nguồn&lt;/em&gt;, $Y$ là &lt;em&gt;tập đích&lt;/em&gt;. &lt;em&gt;Ảnh&lt;/em&gt; của $f$ là&lt;/p&gt;

\[f(X) = \{f(x) : x \in X\} \subseteq Y.\]

  &lt;p&gt;Với $y \in Y$, &lt;em&gt;tạo ảnh&lt;/em&gt; (hay &lt;em&gt;nghịch ảnh&lt;/em&gt;) của $y$ là $f^{-1}(y) = \{x \in X : f(x) = y\}$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 3 (Đơn ánh, toàn ánh, song ánh).&lt;/strong&gt; Ánh xạ $f : X \to Y$ là&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;&lt;em&gt;đơn ánh&lt;/em&gt; nếu $f(x_1) = f(x_2)$ kéo theo $x_1 = x_2$ (hai phần tử khác nhau có ảnh khác nhau);&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;toàn ánh&lt;/em&gt; nếu với mọi $y \in Y$ có $x \in X$ sao cho $f(x) = y$ (tức $f(X) = Y$);&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;song ánh&lt;/em&gt; nếu vừa đơn ánh vừa toàn ánh.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;p&gt;Nói theo phương trình: $f$ là đơn ánh khi phương trình $f(x) = y$ có &lt;em&gt;nhiều nhất&lt;/em&gt; một nghiệm với mọi $y$; toàn ánh khi nó có &lt;em&gt;ít nhất&lt;/em&gt; một nghiệm với mọi $y$; song ánh khi nó có &lt;em&gt;đúng&lt;/em&gt; một nghiệm.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 2.&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$f : \mathbb{R} \to \mathbb{R}$, $f(x) = x^2$ không đơn ánh ($f(-1) = f(1)$) và không toàn ánh (không có $x$ nào với $f(x) = -1$).&lt;/li&gt;
    &lt;li&gt;$g : \mathbb{R} \to [0, \infty)$, $g(x) = x^2$ là toàn ánh nhưng không đơn ánh. Cùng công thức, đổi tập đích thì tính chất đổi.&lt;/li&gt;
    &lt;li&gt;$h : \mathbb{R} \to \mathbb{R}$, $h(x) = 2x + 1$ là song ánh: $2x + 1 = y$ có đúng một nghiệm $x = (y - 1)/2$.&lt;/li&gt;
    &lt;li&gt;$p : \mathbb{R}^2 \to \mathbb{R}$, $p(x_1, x_2) = x_1$ là toàn ánh nhưng không đơn ánh: mọi điểm trên một đường thẳng đứng có cùng ảnh.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 4 (Hợp và nghịch đảo).&lt;/strong&gt; Với $f : X \to Y$ và $g : Y \to Z$, &lt;em&gt;ánh xạ hợp&lt;/em&gt; $g \circ f : X \to Z$ là $(g \circ f)(x) = g(f(x))$. &lt;em&gt;Ánh xạ đồng nhất&lt;/em&gt; trên $X$ là $\mathrm{id}_X(x) = x$. Ánh xạ $g : Y \to X$ là &lt;em&gt;nghịch đảo&lt;/em&gt; của $f$ nếu $g \circ f = \mathrm{id}_X$ và $f \circ g = \mathrm{id}_Y$; khi đó viết $g = f^{-1}$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 1.&lt;/strong&gt; Ánh xạ $f : X \to Y$ có nghịch đảo khi và chỉ khi $f$ là song ánh. Nghịch đảo, nếu có, là duy nhất.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh (phác thảo).&lt;/strong&gt; Nếu $f$ song ánh, với mỗi $y$ có đúng một $x$ để $f(x) = y$; đặt $g(y) = x$ thì $g \circ f = \mathrm{id}_X$ và $f \circ g = \mathrm{id}_Y$. Ngược lại, nếu có $g$: từ $f(x_1) = f(x_2)$ suy ra $x_1 = g(f(x_1)) = g(f(x_2)) = x_2$, nên $f$ đơn ánh; với mọi $y$ có $f(g(y)) = y$, nên $f$ toàn ánh. Nếu $g$ và $g&apos;$ đều là nghịch đảo thì $g = g \circ (f \circ g&apos;) = (g \circ f) \circ g&apos; = g&apos;$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Ở Chương 03, ma trận vuông $A$ khả nghịch đúng khi ánh xạ $x \mapsto Ax$ là song ánh từ $\mathbb{R}^n$ vào $\mathbb{R}^n$; ở Chương 06, đơn ánh tương ứng với hạt nhân bằng $\{0\}$ và toàn ánh tương ứng với ảnh bằng cả tập đích.&lt;/p&gt;

&lt;h2 id=&quot;quan-hệ-tương-đương&quot;&gt;Quan hệ tương đương&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định nghĩa 5 (Quan hệ tương đương).&lt;/strong&gt; Một &lt;em&gt;quan hệ&lt;/em&gt; $\sim$ trên tập $X$ là một cách nói hai phần tử “có liên hệ” hay không. Quan hệ $\sim$ là &lt;em&gt;quan hệ tương đương&lt;/em&gt; nếu với mọi $x, y, z \in X$:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;&lt;em&gt;phản xạ&lt;/em&gt;: $x \sim x$;&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;đối xứng&lt;/em&gt;: $x \sim y$ kéo theo $y \sim x$;&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;bắc cầu&lt;/em&gt;: $x \sim y$ và $y \sim z$ kéo theo $x \sim z$.&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;&lt;em&gt;Lớp tương đương&lt;/em&gt; của $x$ là $[x] = \{y \in X : y \sim x\}$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Định lý 2.&lt;/strong&gt; Các lớp tương đương của một quan hệ tương đương trên $X$ phủ kín $X$, và hai lớp bất kỳ hoặc trùng nhau hoặc rời nhau.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Chứng minh.&lt;/strong&gt; Mỗi $x$ thuộc lớp $[x]$ vì $x \sim x$. Giả sử $z \in [x] \cap [y]$. Khi đó $z \sim x$ và $z \sim y$, nên $x \sim y$ (đối xứng rồi bắc cầu). Với $w \in [x]$ thì $w \sim x \sim y$, nên $w \in [y]$; vậy $[x] \subseteq [y]$, và tương tự $[y] \subseteq [x]$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Ví dụ 3.&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;Trên $\mathbb{Z}$, đặt $a \sim b$ nếu $a - b$ chia hết cho 2. Có hai lớp: số chẵn và số lẻ. Đây là nền của trường $\mathbb{F}_2$ ở Bài 00-02.&lt;/li&gt;
    &lt;li&gt;Trên tập các ma trận cỡ $m \times n$, đặt $A \sim B$ nếu biến đổi được $A$ thành $B$ bằng các phép biến đổi sơ cấp trên hàng. Đây là quan hệ tương đương (mỗi phép biến đổi có phép ngược), và mỗi lớp chứa đúng một ma trận bậc thang rút gọn (Chương 02).&lt;/li&gt;
    &lt;li&gt;Ở Chương 06, “đồng dạng” $B = P^{-1} A P$ là một quan hệ tương đương trên ma trận vuông.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ứng-dụng-phân-loại-bằng-lớp-tương-đương&quot;&gt;Ứng dụng: phân loại bằng lớp tương đương&lt;/h2&gt;

&lt;p&gt;Quan hệ tương đương là cách toán học nói “coi như giống nhau”. Khi giải $Ax = b$, ta thay hệ bằng một hệ tương đương đơn giản hơn; mọi hệ trong cùng lớp có cùng tập nghiệm. Khi nghiên cứu ánh xạ tuyến tính, ta chọn trong lớp các ma trận đồng dạng một đại diện đơn giản nhất (ma trận chéo ở Chương 09). Tư duy “chọn đại diện tốt cho mỗi lớp” xuất hiện xuyên suốt khoá học.&lt;/p&gt;

&lt;h2 id=&quot;minh-hoạ&quot;&gt;Minh hoạ&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Minh hoạ: sơ đồ mũi tên của ánh xạ&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Nối các phần tử của A với B, xem ánh xạ có là đơn ánh, toàn ánh, song ánh không.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter00/anh_xa.html&quot; title=&quot;Minh hoạ: sơ đồ mũi tên của ánh xạ&quot; loading=&quot;lazy&quot; style=&quot;height: 620px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter00/anh_xa.html&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mở minh hoạ ở cửa sổ riêng&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 1.&lt;/strong&gt; Viết tập nghiệm thực của $|x - 1| \le 3$ bằng ký hiệu tập hợp và dưới dạng khoảng.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\{x \in \mathbb{R} : |x - 1| \le 3\} = \{x \in \mathbb{R} : -2 \le x \le 4\} = [-2, 4]$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 2.&lt;/strong&gt; Với $A = \{1, 2\}$, $B = \{a, b, c\}$, liệt kê $A \times B$. Tập này có bao nhiêu phần tử?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

$\{(1,a), (1,b), (1,c), (2,a), (2,b), (2,c)\}$, gồm $2 \cdot 3 = 6$ phần tử.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 3.&lt;/strong&gt; Ánh xạ nào sau đây là đơn ánh, toàn ánh, song ánh?
(a) $f : \mathbb{R} \to \mathbb{R}$, $f(x) = x^3$.
(b) $g : \mathbb{R}^2 \to \mathbb{R}^2$, $g(x_1, x_2) = (x_1 + x_2,\ x_1 - x_2)$.
(c) $h : \mathbb{R} \to \mathbb{R}^2$, $h(t) = (t, 2t)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

(a) Song ánh: $x^3 = y$ có đúng một nghiệm thực $x = \sqrt[3]{y}$.
(b) Song ánh: hệ $x_1 + x_2 = y_1$, $x_1 - x_2 = y_2$ có đúng một nghiệm $x_1 = (y_1 + y_2)/2$, $x_2 = (y_1 - y_2)/2$.
(c) Đơn ánh nhưng không toàn ánh: ảnh chỉ là đường thẳng $y_2 = 2 y_1$, không chứa $(1, 0)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 4.&lt;/strong&gt; Chứng minh: nếu $f : X \to Y$ và $g : Y \to Z$ đều là đơn ánh thì $g \circ f$ là đơn ánh.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Nếu $g(f(x_1)) = g(f(x_2))$ thì $f(x_1) = f(x_2)$ vì $g$ đơn ánh, rồi $x_1 = x_2$ vì $f$ đơn ánh.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Bài tập 5 (nâng cao).&lt;/strong&gt; Trên $\mathbb{R}^2$, đặt $u \sim v$ nếu $u - v$ nằm trên đường thẳng $L = \{t(1, 1) : t \in \mathbb{R}\}$. Chứng minh $\sim$ là quan hệ tương đương và mô tả các lớp tương đương bằng hình học.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Đáp án&lt;/summary&gt;

Phản xạ: $u - u = 0 \in L$. Đối xứng: nếu $u - v = t(1,1)$ thì $v - u = (-t)(1,1)$. Bắc cầu: $(u - v) + (v - w) = (t + s)(1,1)$. Lớp của $u$ là $u + L$, đường thẳng qua $u$ song song với $L$. Các lớp là các đường thẳng song song với $L$; đây là ví dụ đầu tiên của &quot;không gian thương&quot;.

&lt;/details&gt;

&lt;h2 id=&quot;tóm-tắt&quot;&gt;Tóm tắt&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Tập hợp viết bằng liệt kê hoặc mô tả $\{x \in S : \dots\}$; chứng minh $A = B$ bằng hai chiều $A \subseteq B$, $B \subseteq A$.&lt;/li&gt;
    &lt;li&gt;$\mathbb{R}^n$ là tích Descartes của $n$ bản $\mathbb{R}$.&lt;/li&gt;
    &lt;li&gt;Đơn ánh: $f(x) = y$ có nhiều nhất một nghiệm; toàn ánh: có ít nhất một nghiệm; song ánh: đúng một nghiệm, tương đương với có nghịch đảo.&lt;/li&gt;
    &lt;li&gt;Quan hệ tương đương (phản xạ, đối xứng, bắc cầu) chia tập thành các lớp rời nhau.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Linear independence</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter01/01_05_Doc_Lap_Tuyen_Tinh/"/>
   <updated>2026-01-01T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter01/01_05_Doc_Lap_Tuyen_Tinh</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;test whether a set of vectors is linearly independent or dependent by solving a homogeneous system;&lt;/li&gt;
    &lt;li&gt;for a dependent set, find an explicit dependence relation and express one vector through the others;&lt;/li&gt;
    &lt;li&gt;explain linear independence geometrically in $\mathbb{R}^2$, $\mathbb{R}^3$;&lt;/li&gt;
    &lt;li&gt;use the uniqueness of coefficients in a linear combination.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;The three vectors $v_1 = (1, 2, 3)$, $v_2 = (4, 5, 6)$, $v_3 = (7, 8, 9)$ look “different”. But&lt;/p&gt;

\[v_1 - 2v_2 + v_3 = (1 - 8 + 7,\ 2 - 10 + 8,\ 3 - 12 + 9) = (0, 0, 0).\]

&lt;p&gt;So $v_3 = 2v_2 - v_1$: the third vector adds no new direction. The three vectors lie in one plane through the origin, and their span is that plane rather than all of $\mathbb{R}^3$. We say the set is &lt;em&gt;linearly dependent&lt;/em&gt;. This lesson gives a systematic way to detect this.&lt;/p&gt;

&lt;h2 id=&quot;definition&quot;&gt;Definition&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Linear independence and dependence).&lt;/strong&gt; Vectors $v_1, \dots, v_k \in \mathbb{R}^n$ are &lt;em&gt;linearly independent&lt;/em&gt; if the equation&lt;/p&gt;

\[c_1 v_1 + c_2 v_2 + \cdots + c_k v_k = 0\]

  &lt;p&gt;holds only when $c_1 = c_2 = \cdots = c_k = 0$. Otherwise, if some coefficients, not all zero, make the combination equal to $0$, the set is &lt;em&gt;linearly dependent&lt;/em&gt; and that equation is a &lt;em&gt;dependence relation&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The combination with all coefficients 0 always gives $0$; we call it the &lt;em&gt;trivial&lt;/em&gt; combination. Linear independence means: the trivial combination is the only way back to the origin.&lt;/p&gt;

&lt;h3 id=&quot;simple-cases&quot;&gt;Simple cases&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;One vector $v$ is independent if and only if $v \ne 0$.&lt;/li&gt;
  &lt;li&gt;Any set containing $0$ is dependent: $1 \cdot 0 = 0$ is a dependence relation.&lt;/li&gt;
  &lt;li&gt;Two vectors are dependent if and only if one is a multiple of the other, i.e. they are parallel.&lt;/li&gt;
  &lt;li&gt;Three vectors in $\mathbb{R}^3$ are dependent if and only if they lie in one plane through the origin.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;theorems&quot;&gt;Theorems&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Dependent means some vector is redundant).&lt;/strong&gt; For $k \ge 2$, the vectors $v_1, \dots, v_k$ are linearly dependent if and only if at least one $v_j$ is a linear combination of the others.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Suppose $c_1 v_1 + \cdots + c_k v_k = 0$ with some $c_j \ne 0$. Move the other terms across and divide by $c_j$:&lt;/p&gt;

\[v_j = -\frac{1}{c_j} \sum_{i \ne j} c_i v_i .\]

  &lt;p&gt;Conversely, if $v_j = \sum_{i \ne j} a_i v_i$ then $\sum_{i \ne j} a_i v_i - v_j = 0$ is a dependence relation, since the coefficient of $v_j$ is $-1 \ne 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Combined with Theorem 2 of Lesson 1.4: in a dependent set, removing the redundant vector $v_j$ does not change the span. An independent set is one with no redundant vector.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2 (Unique coefficients).&lt;/strong&gt; The vectors $v_1, \dots, v_k$ are linearly independent if and only if every $b \in \operatorname{span}\{v_1, \dots, v_k\}$ can be written in exactly &lt;em&gt;one&lt;/em&gt; way as $b = c_1 v_1 + \cdots + c_k v_k$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Suppose the set is independent and $b = \sum c_i v_i = \sum d_i v_i$. Subtracting: $\sum (c_i - d_i) v_i = 0$. By independence, $c_i - d_i = 0$ for every $i$.&lt;/p&gt;

  &lt;p&gt;Conversely, suppose every $b$ in the span has a unique representation. Take $b = 0$: the trivial combination is one representation, so it is the only one. That is exactly linear independence.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Theorem 2 is why we want independent sets: the coefficients $c_i$ then act as “coordinates” of $b$, like $(x, y)$ in the plane. Chapter 05 calls an independent set that spans the whole space a &lt;em&gt;basis&lt;/em&gt;.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 3 (Too many vectors are dependent).&lt;/strong&gt; Any set of more than $n$ vectors in $\mathbb{R}^n$ is linearly dependent.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof (for $n = 2$).&lt;/strong&gt; Let $u, v, w \in \mathbb{R}^2$. If $u, v$ are parallel the set is already dependent. Otherwise, as in Example 2 of Lesson 1.4, $u, v$ span $\mathbb{R}^2$, so $w$ is a combination of $u, v$ and by Theorem 1 the set is dependent. For general $n$, the equation $\sum c_i v_i = 0$ is a homogeneous system of $n$ equations in $k &amp;gt; n$ unknowns; Lesson 2.5 proves such a system always has a nonzero solution.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;how-to-test&quot;&gt;How to test&lt;/h2&gt;

&lt;p&gt;To test $v_1, \dots, v_k$: write the system $c_1 v_1 + \cdots + c_k v_k = 0$ component by component and solve it. If the only solution is $c = 0$ the set is independent; a nonzero solution is a dependence relation.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; Test $v_1 = (1, 0, 2)$, $v_2 = (0, 1, 1)$, $v_3 = (1, 1, 4)$.&lt;/p&gt;

  &lt;p&gt;The system $c_1 v_1 + c_2 v_2 + c_3 v_3 = 0$ is&lt;/p&gt;

\[c_1 + c_3 = 0, \qquad c_2 + c_3 = 0, \qquad 2c_1 + c_2 + 4c_3 = 0.\]

  &lt;p&gt;The first two give $c_1 = c_2 = -c_3$. Substituting in the third: $-2c_3 - c_3 + 4c_3 = c_3 = 0$. So $c_1 = c_2 = c_3 = 0$ and the set is independent. The three arrows do not lie in one plane, so they span $\mathbb{R}^3$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; Change $v_3$ to $(1, 1, 3)$. Now the third equation gives $-2c_3 - c_3 + 3c_3 = 0$, true for every $c_3$. Take $c_3 = 1$: $c_1 = c_2 = -1$, so $-v_1 - v_2 + v_3 = 0$, i.e. $v_3 = v_1 + v_2$. The three vectors lie in the plane spanned by $v_1, v_2$, which has normal $v_1 \times v_2 = (-2, -1, 1)$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3 (with a parameter).&lt;/strong&gt; Find $t$ such that $(1, 1, 0)$, $(1, 0, 1)$, $(0, 1, t)$ are dependent.&lt;/p&gt;

  &lt;p&gt;System: $c_1 + c_2 = 0$, $c_1 + c_3 = 0$, $c_2 + t c_3 = 0$. The first two give $c_2 = c_3 = -c_1$. The third: $-c_1 - t c_1 = -(1 + t) c_1 = 0$. A solution with $c_1 \ne 0$ exists if and only if $t = -1$. Then $(1, 1, 0) - (1, 0, 1) - (0, 1, -1) = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-redundant-features-in-data&quot;&gt;Application: redundant features in data&lt;/h2&gt;

&lt;p&gt;A housing data table has columns: area in m², area in square feet, number of rooms, price. The second column is $10.764$ times the first. These two columns are vectors in $\mathbb{R}^m$ ($m$ houses) and are linearly dependent.&lt;/p&gt;

&lt;p&gt;If a linear regression model uses both columns, by Theorem 2 their coefficients are no longer unique: raising the m² coefficient by $10.764$ and lowering the square-feet coefficient by $1$ gives exactly the same predictions. Software reports a “singular” matrix, or returns huge coefficients of opposite signs that mean nothing. This is called &lt;em&gt;multicollinearity&lt;/em&gt;. The simplest fix is to drop the redundant column, just as Theorem 1 suggests.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: linear independence and dependence&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag b onto the line of a: the grid collapses to a line and det[a b] = 0.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter01/to_hop_tuyen_tinh.html?mode=span&amp;amp;lang=en&quot; title=&quot;Interactive: linear independence and dependence&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter01/to_hop_tuyen_tinh.html?mode=span&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-when-b-lines-up-with-a-last-part-of-the-linear-combination-reel&quot;&gt;Short video: When b lines up with a (last part of the linear-combination reel)&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/linear-combination-span.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;From 1:18: as b is pulled onto the direction of a, the cell area drops to 0 and the span shrinks to a line. Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Are $(2, -1)$, $(-6, 3)$ independent? What about $(1, 2, 0)$, $(0, 0, 0)$, $(3, 1, 1)$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The first set is dependent: $(-6, 3) = -3(2, -1)$. The second is dependent because it contains $0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Check that $(1, 2, 1)$, $(2, 1, 0)$, $(1, -1, 2)$ are linearly independent.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The system $c_1 + 2c_2 + c_3 = 0$, $2c_1 + c_2 - c_3 = 0$, $c_1 + 2c_3 = 0$ has only the zero solution: the third equation gives $c_1 = -2c_3$; the first gives $c_2 = c_3/2$; the second gives $-4c_3 + c_3/2 - c_3 = -\tfrac92 c_3 = 0$. Independent.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Find $a$ such that $(1, a, 1)$, $(a, 1, 1)$, $(1, 1, a)$ are dependent.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$a = 1$ (the three vectors coincide) or $a = -2$ (then the three vectors add up to $0$). Chapter 04 gives a quick method with determinants: $\det = -(a - 1)^2(a + 2)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; Let $u, v, w$ be independent. Prove that $u + v$, $v + w$, $w + u$ are independent.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

If $a(u+v) + b(v+w) + c(w+u) = 0$ then $(a + c)u + (a + b)v + (b + c)w = 0$. By independence of $u, v, w$: $a + c = a + b = b + c = 0$, hence $a = b = c = 0$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced / programming).&lt;/strong&gt; In NumPy build the matrix with columns $(1,2,3)$, $(4,5,6)$, $(7,8,9)$ and compute &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.linalg.matrix_rank&lt;/code&gt;. Change the entry $9$ to $9.000001$ and compute again. Why must independence tests in floating point be treated with care?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The rank is 2 the first time (dependent) and 3 the second time (independent). A tiny change turns a dependent set into an independent one, so in numerical work one measures &quot;near dependence&quot; with singular values (Chapter 11) rather than answering yes/no.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Linear independence: $\sum c_i v_i = 0$ forces every $c_i = 0$.&lt;/li&gt;
    &lt;li&gt;Dependent if and only if some vector is a combination of the others; removing it leaves the span unchanged.&lt;/li&gt;
    &lt;li&gt;Independent if and only if the coefficients of each vector in the span are unique.&lt;/li&gt;
    &lt;li&gt;In $\mathbb{R}^n$, a set of more than $n$ vectors is always dependent.&lt;/li&gt;
    &lt;li&gt;Test by solving the homogeneous system $\sum c_i v_i = 0$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Linear combinations and span</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter01/01_04_To_Hop_Tuyen_Tinh_Va_Khong_Gian_Sinh/"/>
   <updated>2026-01-01T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter01/01_04_To_Hop_Tuyen_Tinh_Va_Khong_Gian_Sinh</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;write a vector as a linear combination of given vectors, or show that this is impossible;&lt;/li&gt;
    &lt;li&gt;describe geometrically the span of one, two or three vectors in $\mathbb{R}^2$ and $\mathbb{R}^3$;&lt;/li&gt;
    &lt;li&gt;prove that a span is closed under addition and scalar multiplication.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;A farm has two kinds of feed. Each kg of feed A contains 20 g of protein and 5 g of fat; each kg of feed B contains 10 g of protein and 10 g of fat. How many kg of each should be mixed to supply exactly 50 g of protein and 25 g of fat?&lt;/p&gt;

&lt;p&gt;Call the amounts $a$ and $b$. We need&lt;/p&gt;

\[a\,(20, 5) + b\,(10, 10) = (50, 25).\]

&lt;p&gt;From $20a + 10b = 50$ and $5a + 10b = 25$, subtracting gives $15a = 25$, so $a = b = 5/3$. The left-hand side is a &lt;em&gt;linear combination&lt;/em&gt; of the two feed vectors. The question “which rations can be mixed” is a question about their &lt;em&gt;span&lt;/em&gt;.&lt;/p&gt;

&lt;h2 id=&quot;linear-combinations&quot;&gt;Linear combinations&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Linear combination).&lt;/strong&gt; Let $v_1, \dots, v_k \in \mathbb{R}^n$. A &lt;em&gt;linear combination&lt;/em&gt; of them is a vector of the form&lt;/p&gt;

\[c_1 v_1 + c_2 v_2 + \cdots + c_k v_k, \qquad c_1, \dots, c_k \in \mathbb{R}.\]

  &lt;p&gt;The numbers $c_i$ are the &lt;em&gt;coefficients&lt;/em&gt; of the combination.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Picture: each $v_i$ is a kind of step. A linear combination is a route: $c_1$ steps of kind 1, $c_2$ steps of kind 2, … A negative coefficient means walking backwards, a non-integer coefficient means part of a step.&lt;/p&gt;

&lt;h2 id=&quot;span&quot;&gt;Span&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 2 (Span).&lt;/strong&gt; The &lt;em&gt;span&lt;/em&gt; of $v_1, \dots, v_k$ is the set of all their linear combinations:&lt;/p&gt;

\[\operatorname{span}\{v_1, \dots, v_k\} = \{\, c_1 v_1 + \cdots + c_k v_k : c_i \in \mathbb{R} \,\}.\]

  &lt;p&gt;By convention $\operatorname{span}\varnothing = \{0\}$. If $\operatorname{span}\{v_1, \dots, v_k\} = \mathbb{R}^n$ we say the set &lt;em&gt;spans&lt;/em&gt; $\mathbb{R}^n$.&lt;/p&gt;
&lt;/div&gt;

&lt;h3 id=&quot;pictures-in-mathbbr2-and-mathbbr3&quot;&gt;Pictures in $\mathbb{R}^2$ and $\mathbb{R}^3$&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;The span of one vector $v \ne 0$ is the line through the origin containing $v$. The span of $0$ is just $\{0\}$.&lt;/li&gt;
  &lt;li&gt;The span of two non-parallel vectors in $\mathbb{R}^3$ is the plane through the origin containing them. If the two vectors are parallel, the span is only a line.&lt;/li&gt;
  &lt;li&gt;The span of three vectors in $\mathbb{R}^3$ is all of $\mathbb{R}^3$ if they do not lie in one plane through the origin.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A span always contains the origin $0$ (take all coefficients 0). So the line $x = (1, 0) + t(0, 1)$ is not the span of anything: it misses the origin.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (A span is closed under both operations).&lt;/strong&gt; Let $S = \operatorname{span}\{v_1, \dots, v_k\}$. If $x, y \in S$ and $c \in \mathbb{R}$, then $x + y \in S$ and $c\,x \in S$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Write $x = \sum a_i v_i$ and $y = \sum b_i v_i$. By Theorem 1 of Lesson 1.1, $x + y = \sum (a_i + b_i) v_i$ and $c\,x = \sum (c a_i) v_i$. Both are linear combinations of $v_1, \dots, v_k$, so both lie in $S$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;A subset of $\mathbb{R}^n$ that contains $0$ and is closed under both operations is a &lt;em&gt;subspace&lt;/em&gt;. Chapter 05 studies this notion in depth.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2 (A redundant vector does not enlarge the span).&lt;/strong&gt; If $w \in \operatorname{span}\{v_1, \dots, v_k\}$ then&lt;/p&gt;

  &lt;p&gt;\(\operatorname{span}\{v_1, \dots, v_k, w\} = \operatorname{span}\{v_1, \dots, v_k\}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; The right-hand set is contained in the left-hand set: take the coefficient of $w$ to be 0. Conversely, write $w = \sum a_i v_i$. A combination $\sum c_i v_i + c\,w = \sum (c_i + c\,a_i) v_i$ lies in the right-hand set.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;testing-membership-in-a-span&quot;&gt;Testing membership in a span&lt;/h2&gt;

&lt;p&gt;The question “$b \in \operatorname{span}\{v_1, \dots, v_k\}$?” is the same as asking: does the system $c_1 v_1 + \cdots + c_k v_k = b$ (unknowns $c_1, \dots, c_k$) have a solution? Chapter 02 gives a general algorithm; for small examples we solve directly.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; Let $v_1 = (1, 0, 1)$, $v_2 = (0, 1, 1)$. Is $b = (2, 3, 5)$ in their span?&lt;/p&gt;

  &lt;p&gt;The system $c_1 v_1 + c_2 v_2 = b$ reads $c_1 = 2$, $c_2 = 3$, $c_1 + c_2 = 5$. The first two equations give $c_1 = 2$, $c_2 = 3$, and the third holds: $2 + 3 = 5$. So $b = 2v_1 + 3v_2$.&lt;/p&gt;

  &lt;p&gt;For $b&apos; = (2, 3, 4)$ the first two equations still force $c_1 = 2$, $c_2 = 3$, but $2 + 3 \ne 4$. So $b&apos; \notin \operatorname{span}\{v_1, v_2\}$.&lt;/p&gt;

  &lt;p&gt;Geometry: the span is a plane through the origin. Its normal is $v_1 \times v_2 = (-1, -1, 1)$, i.e. the plane $z = x + y$. The point $(2, 3, 5)$ lies on it, while $(2, 3, 4)$ is one unit below it.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; Show that $u = (1, 2)$ and $w = (3, 1)$ span $\mathbb{R}^2$.&lt;/p&gt;

  &lt;p&gt;For arbitrary $b = (b_1, b_2)$ solve $c_1 + 3c_2 = b_1$, $2c_1 + c_2 = b_2$. Doubling the first equation and subtracting the second gives $5 c_2 = 2b_1 - b_2$. Thus&lt;/p&gt;

\[c_2 = \frac{2b_1 - b_2}{5}, \qquad c_1 = b_1 - 3c_2 = \frac{3b_2 - b_1}{5}.\]

  &lt;p&gt;The system always has a solution, so every $b$ is in the span. For $b = (7, 4)$ we recover $c_1 = 1$, $c_2 = 2$ from Lesson 1.1. Geometry: the two families of lines parallel to $u$ and $w$ form a slanted grid that covers the whole plane.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3.&lt;/strong&gt; What is the span of $(1, 2)$ and $(2, 4)$? Since $(2, 4) = 2(1, 2)$, by Theorem 2 the span is just the line $\{t(1, 2)\}$, i.e. the line $y = 2x$. The point $(1, 0)$ cannot be reached.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-rations-and-mixtures&quot;&gt;Application: rations and mixtures&lt;/h2&gt;

&lt;p&gt;Back to the opening example. The vectors $(20, 5)$ and $(10, 10)$ are not parallel, so their span is all of $\mathbb{R}^2$: every (protein, fat) pair can be reached &lt;em&gt;if negative coefficients are allowed&lt;/em&gt;. In practice amounts cannot be negative, so only the rations in the wedge between the two vectors are possible, i.e. combinations with $a, b \ge 0$. For example the ration $(10, 20)$ requires $a = -2/3 &amp;lt; 0$ and cannot be mixed. The set of combinations with non-negative coefficients is called a &lt;em&gt;cone&lt;/em&gt;; it is the main object of linear programming in the Optimization course.&lt;/p&gt;

&lt;p&gt;The same idea appears in colour mixing (a screen mixes red, green, blue with non-negative intensities), in chemistry (balancing reaction equations), and in machine learning (a linear layer of a neural network computes linear combinations of features).&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: linear combinations and span&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag a, b and the coefficients c₁, c₂; press the sweep button to see span{a, b}.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter01/to_hop_tuyen_tinh.html?mode=span&amp;amp;lang=en&quot; title=&quot;Interactive: linear combinations and span&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter01/to_hop_tuyen_tinh.html?mode=span&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-linear-combinations-fill-the-plane&quot;&gt;Short video: Linear combinations fill the plane&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/linear-combination-span.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Scale a, add d · b: the lattice built from a and b fills the plane; when b is pulled onto the direction of a the lattice collapses to a line. Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Is $(1, 2, 3)$ in $\operatorname{span}\{(1, 1, 0), (0, 1, 1)\}$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The system $c_1 = 1$, $c_1 + c_2 = 2$, $c_2 = 3$ is inconsistent ($c_2 = 1$ and $c_2 = 3$). No.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Find $h$ such that $(1, h, 5) \in \operatorname{span}\{(1, 2, 1), (0, 1, 1)\}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The first component gives $c_1 = 1$; the last gives $1 + c_2 = 5$, $c_2 = 4$; the middle gives $h = 2 + 4 = 6$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Describe $\operatorname{span}\{(1, 0, 2), (0, 1, -1)\}$ by one plane equation.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Normal $(1, 0, 2) \times (0, 1, -1) = (-2, 1, 1)$. Plane through the origin: $-2x + y + z = 0$, i.e. $z = 2x - y$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; Prove $\operatorname{span}\{u, w\} = \operatorname{span}\{u + w, u - w\}$ for all $u, w \in \mathbb{R}^n$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$u + w$ and $u - w$ lie in the left span, so (Theorem 1) the right span is inside the left span. Conversely, $u = \tfrac12[(u+w) + (u-w)]$ and $w = \tfrac12[(u+w) - (u-w)]$ lie in the right span.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced / programming).&lt;/strong&gt; In NumPy use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.linalg.lstsq(A, b)&lt;/code&gt; where &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A&lt;/code&gt; has columns $(1,0,1)$, $(0,1,1)$ and $b = (2,3,5)$, then $b = (2,3,4)$. Look at the residual. What does a zero residual tell you?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

For $b = (2,3,5)$ the residual is 0 and the solution is $(2, 3)$: $b$ is in the span. For $b = (2,3,4)$ the residual is positive: $b$ is not in the span, and the function returns the combination closest to $b$. This is the least-squares problem of Chapter 08.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Linear combination: $c_1 v_1 + \cdots + c_k v_k$. The span is the set of all such combinations.&lt;/li&gt;
    &lt;li&gt;A span contains $0$ and is closed under addition and scaling; in $\mathbb{R}^3$ it is $\{0\}$, a line, a plane through the origin, or all of $\mathbb{R}^3$.&lt;/li&gt;
    &lt;li&gt;$b \in \operatorname{span}\{v_i\}$ if and only if the system $\sum c_i v_i = b$ has a solution.&lt;/li&gt;
    &lt;li&gt;Adding a vector already in the span does not enlarge it.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Lines and planes</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter01/01_03_Duong_Thang_Va_Mat_Phang/"/>
   <updated>2026-01-01T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter01/01_03_Duong_Thang_Va_Mat_Phang</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;write parametric equations of a line or a plane from a point and direction vectors;&lt;/li&gt;
    &lt;li&gt;write the general equation of a plane from a point and a normal vector;&lt;/li&gt;
    &lt;li&gt;convert between the two forms;&lt;/li&gt;
    &lt;li&gt;find where a line meets a plane and the distance from a point to a plane.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;In a 3D game the camera sits at the origin and looks in direction $d = (1, 1, 1)$. Ahead is a flat wall through the three points $(1, 0, 0)$, $(0, 2, 0)$, $(0, 0, 3)$. Where does the line of sight hit the wall?&lt;/p&gt;

&lt;p&gt;We need two things: a description of the line of sight with one parameter $t$ (walk $t$ steps along $d$), and a description of the wall by an equation. This lesson builds both with vectors and solves the problem in Example 3.&lt;/p&gt;

&lt;h2 id=&quot;lines&quot;&gt;Lines&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Line).&lt;/strong&gt; Let $p \in \mathbb{R}^n$ be a point and $d \ne 0$ a vector. The &lt;em&gt;line&lt;/em&gt; through $p$ with direction vector $d$ is the set&lt;/p&gt;

\[L = \{\, p + t\,d : t \in \mathbb{R} \,\}.\]

  &lt;p&gt;The equation $x = p + t\,d$ is a &lt;em&gt;parametric equation&lt;/em&gt; of $L$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Picture: stand at $p$ and walk $t$ steps in direction $d$. For $t &amp;gt; 0$ you go forward, for $t &amp;lt; 0$ backward, for $t = 0$ you stay at $p$. A line has many parametric equations: replacing $p$ by another point of $L$, or $d$ by a nonzero multiple of $d$, gives the same line.&lt;/p&gt;

&lt;p&gt;The line through two points $p, q$ has direction $q - p$: $x = p + t(q - p)$. As $t$ runs from 0 to 1, $x$ traverses the segment $pq$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; The line $2x + 3y = 6$ in $\mathbb{R}^2$. Setting $x = 0$ gives the point $(0, 2)$; setting $y = 0$ gives $(3, 0)$. A direction vector is $(3, 0) - (0, 2) = (3, -2)$, so&lt;/p&gt;

\[(x, y) = (0, 2) + t\,(3, -2).\]

  &lt;p&gt;Note $(2, 3) \cdot (3, -2) = 0$: the coefficient vector $(2, 3)$ is perpendicular to the line. This is the idea of a normal vector in the next section.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;planes&quot;&gt;Planes&lt;/h2&gt;

&lt;h3 id=&quot;general-equation&quot;&gt;General equation&lt;/h3&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 2 (Plane through a point with a given normal).&lt;/strong&gt; Let $p \in \mathbb{R}^3$ and $n = (a, b, c) \ne 0$. The plane through $p$ with &lt;em&gt;normal vector&lt;/em&gt; $n$ is the set of points $x$ such that $x - p$ is perpendicular to $n$:&lt;/p&gt;

  &lt;p&gt;\(n \cdot (x - p) = 0 \quad\Longleftrightarrow\quad a x_1 + b x_2 + c x_3 = d, \ \text{ where } d = n \cdot p.\)&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Picture: stick a needle $n$ upright at $p$. The plane consists of all directions from $p$ that are perpendicular to the needle.&lt;/p&gt;

&lt;h3 id=&quot;parametric-equation&quot;&gt;Parametric equation&lt;/h3&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 3 (Parametric plane).&lt;/strong&gt; Let $p$ be a point and $u, v$ two non-parallel vectors. The set&lt;/p&gt;

\[\{\, p + s\,u + t\,v : s, t \in \mathbb{R} \,\}\]

  &lt;p&gt;is the plane through $p$ containing the directions $u, v$.&lt;/p&gt;
&lt;/div&gt;

&lt;h3 id=&quot;the-cross-product&quot;&gt;The cross product&lt;/h3&gt;

&lt;p&gt;To pass from the parametric form to the general form we need a vector perpendicular to both $u$ and $v$.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 4 (Cross product).&lt;/strong&gt; For $u = (u_1, u_2, u_3)$ and $v = (v_1, v_2, v_3)$,&lt;/p&gt;

  &lt;p&gt;\(u \times v = (u_2 v_3 - u_3 v_2,\ \ u_3 v_1 - u_1 v_3,\ \ u_1 v_2 - u_2 v_1).\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; $u \times v$ is perpendicular to both $u$ and $v$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Direct computation:&lt;/p&gt;

\[u \cdot (u \times v) = u_1(u_2 v_3 - u_3 v_2) + u_2(u_3 v_1 - u_1 v_3) + u_3(u_1 v_2 - u_2 v_1) = 0,\]

  &lt;p&gt;since the six terms cancel in pairs. The same works for $v \cdot (u \times v)$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;In Chapter 04 we will see that the length of $u \times v$ is the area of the parallelogram built on $u, v$, and that $u \times v = 0$ exactly when $u, v$ are parallel.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (plane through three points).&lt;/strong&gt; Take $A = (1, 0, 0)$, $B = (0, 2, 0)$, $C = (0, 0, 3)$. Two vectors in the plane are $B - A = (-1, 2, 0)$ and $C - A = (-1, 0, 3)$. A normal is&lt;/p&gt;

\[n = (B - A) \times (C - A) = (2 \cdot 3 - 0,\ 0 - (-1)\cdot 3,\ 0 - 2 \cdot (-1)) = (6, 3, 2).\]

  &lt;p&gt;With $d = n \cdot A = 6$ the plane is $6x + 3y + 2z = 6$. Check: $B$ gives $6$ and $C$ gives $6$. This plane meets the three axes at $x = 1$, $y = 2$, $z = 3$, exactly the given points.&lt;/p&gt;
&lt;/div&gt;

&lt;h3 id=&quot;from-the-general-form-to-the-parametric-form&quot;&gt;From the general form to the parametric form&lt;/h3&gt;

&lt;p&gt;For $2x - y + z = 4$: choose two unknowns as parameters, say $x = s$, $y = t$. Then $z = 4 - 2s + t$, so&lt;/p&gt;

\[(x, y, z) = (0, 0, 4) + s\,(1, 0, -2) + t\,(0, 1, 1).\]

&lt;p&gt;Check: both direction vectors are perpendicular to the normal $(2, -1, 1)$. This trick of “taking free unknowns as parameters” is exactly how we write the general solution of a linear system in Chapter 02.&lt;/p&gt;

&lt;h2 id=&quot;intersections-and-distances&quot;&gt;Intersections and distances&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3 (line of sight hits the wall).&lt;/strong&gt; Back to the opening example. The line of sight is $x = t\,(1, 1, 1)$ with $t \ge 0$. Substitute into $6x + 3y + 2z = 6$: $11 t = 6$, so $t = 6/11$ and the hit point is $\left(\tfrac{6}{11}, \tfrac{6}{11}, \tfrac{6}{11}\right)$. Since $t &amp;gt; 0$, the wall is in front of the camera.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2 (Distance from a point to a plane).&lt;/strong&gt; The distance from a point $q$ to the plane $n \cdot x = d$ is&lt;/p&gt;

  &lt;p&gt;\(\operatorname{dist} = \frac{\lvert n \cdot q - d \rvert}{\lVert n \rVert}.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; The line through $q$ in direction $n$ is $x = q + t\,n$. It meets the plane when $n \cdot q + t \lVert n \rVert^2 = d$, i.e. $t_0 = (d - n\cdot q)/\lVert n \rVert^2$. The meeting point $h = q + t_0 n$ is the foot of the perpendicular. For any other point $x$ of the plane, $x - h$ is perpendicular to $n$, so by Pythagoras $\lVert x - q \rVert^2 = \lVert x - h \rVert^2 + \lVert h - q \rVert^2 \ge \lVert h - q \rVert^2$. Hence the distance is $\lVert h - q \rVert = \lvert t_0 \rvert\, \lVert n \rVert = \lvert n\cdot q - d \rvert / \lVert n \rVert$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 4.&lt;/strong&gt; The distance from $q = (1, 1, 1)$ to $6x + 3y + 2z = 6$ is $\dfrac{\lvert 6 + 3 + 2 - 6 \rvert}{\sqrt{36 + 9 + 4}} = \dfrac57$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-ray-tracing-in-computer-graphics&quot;&gt;Application: ray tracing in computer graphics&lt;/h2&gt;

&lt;p&gt;Rendering software based on &lt;em&gt;ray tracing&lt;/em&gt; shoots a ray $x = c + t\,d$ from the camera through each pixel. For each plane $n \cdot x = k$ in the scene it solves&lt;/p&gt;

\[t = \frac{k - n \cdot c}{n \cdot d}.\]

&lt;p&gt;If $n \cdot d = 0$ the ray is parallel to the plane and misses it. If $t &amp;lt; 0$ the plane is behind the camera. Among the remaining $t &amp;gt; 0$, the smallest belongs to the nearest object, the one we see. A Full HD image needs about two million such computations per plane, each only a few dot products. Chapter 12 returns to graphics.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: lines and planes in ℝ³&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Change p, d, n, c; drag to orbit; see the intersection point.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter01/duong_mat_3d.html?lang=en&quot; title=&quot;Interactive: lines and planes in ℝ³&quot; loading=&quot;lazy&quot; style=&quot;height: 700px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter01/duong_mat_3d.html?lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Find the plane through $(1, 1, 1)$, $(2, 0, 1)$, $(0, 1, 3)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Two vectors $(1, -1, 0)$ and $(-1, 0, 2)$, cross product $(-2, -2, -1)$. Changing sign gives the normal $(2, 2, 1)$, and the plane is $2x + 2y + z = 5$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Write a parametric equation of the line through $(1, 0, 2)$ and $(3, 1, 0)$. Find where it meets the plane $x + y + z = 7$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$x = (1, 0, 2) + t(2, 1, -2)$. Substituting: $3 + t = 7$, $t = 4$, point $(9, 4, -6)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Find a parametric equation for the intersection line of the planes $x + y + z = 1$ and $x - y + 2z = 3$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The direction is perpendicular to both normals: $(1, 1, 1) \times (1, -1, 2) = (3, -1, -2)$. Setting $z = 0$: $x + y = 1$, $x - y = 3$, so $(2, -1, 0)$ is on the line. Hence $x = (2, -1, 0) + t(3, -1, -2)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; Find the distance between the parallel planes $x + 2y + 2z = 3$ and $x + 2y + 2z = 12$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Take the point $(3, 0, 0)$ on the first plane. Its distance to the second is $\lvert 3 - 12 \rvert / 3 = 3$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Prove that if $p$ and $q$ lie on the plane $n \cdot x = d$, then the whole line through $p, q$ lies in that plane.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

For $x = p + t(q - p)$: $n \cdot x = n\cdot p + t(n \cdot q - n \cdot p) = d + t(d - d) = d$ for every $t$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Line: $x = p + t\,d$. Parametric plane: $x = p + s\,u + t\,v$.&lt;/li&gt;
    &lt;li&gt;General plane: $n \cdot x = d$ with normal $n$; $u \times v$ gives a normal from two directions $u, v$.&lt;/li&gt;
    &lt;li&gt;From general to parametric form: take the free unknowns as parameters.&lt;/li&gt;
    &lt;li&gt;Distance from $q$ to a plane: $\lvert n \cdot q - d \rvert / \lVert n \rVert$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Dot product, length and angle</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter01/01_02_Tich_Vo_Huong_Do_Dai_Va_Goc/"/>
   <updated>2026-01-01T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter01/01_02_Tich_Vo_Huong_Do_Dai_Va_Goc</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;compute the dot product, the length of a vector and the angle between two vectors in $\mathbb{R}^n$;&lt;/li&gt;
    &lt;li&gt;test whether two vectors are perpendicular using the dot product;&lt;/li&gt;
    &lt;li&gt;state and prove the Cauchy–Schwarz inequality and the triangle inequality;&lt;/li&gt;
    &lt;li&gt;use cosine similarity to compare two data samples.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;On grid paper the vectors $a = (3, 4)$ and $b = (4, -3)$ look perpendicular. How can we check without a protractor?&lt;/p&gt;

&lt;p&gt;Compute $3 \cdot 4 + 4 \cdot (-3) = 12 - 12 = 0$. That $0$ is the sign of perpendicularity. The sum “multiply matching components and add” is called the dot product. From it we get length, angle, and a perpendicularity test that works even in $\mathbb{R}^{100}$, where nobody can draw a picture.&lt;/p&gt;

&lt;h2 id=&quot;dot-product-and-length&quot;&gt;Dot product and length&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Dot product).&lt;/strong&gt; The dot product of $x = (x_1, \dots, x_n)$ and $y = (y_1, \dots, y_n)$ is the real number&lt;/p&gt;

  &lt;p&gt;\(x \cdot y = x_1 y_1 + x_2 y_2 + \cdots + x_n y_n .\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Properties of the dot product).&lt;/strong&gt; For all $x, y, z \in \mathbb{R}^n$ and real $c$:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$x \cdot y = y \cdot x$ (symmetry);&lt;/li&gt;
    &lt;li&gt;$(x + y) \cdot z = x \cdot z + y \cdot z$ and $(c\,x) \cdot y = c\,(x \cdot y)$ (linearity);&lt;/li&gt;
    &lt;li&gt;$x \cdot x \ge 0$, and $x \cdot x = 0$ if and only if $x = 0$ (positive definiteness).&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Properties 1 and 2 follow directly from the definition and the commutative and distributive laws for real numbers. For property 3: $x \cdot x = x_1^2 + \cdots + x_n^2$ is a sum of squares, hence non-negative, and it is 0 only when every $x_i = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 2 (Length, unit vector, distance).&lt;/strong&gt; The &lt;em&gt;length&lt;/em&gt; (or &lt;em&gt;norm&lt;/em&gt;) of $x$ is&lt;/p&gt;

\[\lVert x \rVert = \sqrt{x \cdot x} = \sqrt{x_1^2 + \cdots + x_n^2}.\]

  &lt;p&gt;A vector of length 1 is a &lt;em&gt;unit vector&lt;/em&gt;. For $x \ne 0$, the vector $x / \lVert x \rVert$ is the unit vector in the direction of $x$. The &lt;em&gt;distance&lt;/em&gt; between points $x, y$ is $\lVert x - y \rVert$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;For $n = 2$ the length formula is Pythagoras’ theorem: the arrow $(x_1, x_2)$ is the hypotenuse of a right triangle with legs $\lvert x_1 \rvert$ and $\lvert x_2 \rvert$. For $n = 3$ we apply Pythagoras twice.&lt;/p&gt;

&lt;p&gt;From the definition, $\lVert c\,x \rVert = \lvert c \rvert\, \lVert x \rVert$: scaling a vector by $c$ scales its length by $\lvert c \rvert$.&lt;/p&gt;

&lt;h2 id=&quot;the-cauchyschwarz-inequality&quot;&gt;The Cauchy–Schwarz inequality&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2 (Cauchy–Schwarz).&lt;/strong&gt; For all $x, y \in \mathbb{R}^n$,&lt;/p&gt;

\[\lvert x \cdot y \rvert \le \lVert x \rVert\, \lVert y \rVert .\]

  &lt;p&gt;Equality holds if and only if one vector is a multiple of the other.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; If $y = 0$ both sides are 0. Assume $y \ne 0$. For every real $t$, by Theorem 1,&lt;/p&gt;

\[0 \le \lVert x - t y \rVert^2 = (x - ty)\cdot(x - ty) = \lVert x \rVert^2 - 2t\,(x \cdot y) + t^2 \lVert y \rVert^2 .\]

  &lt;p&gt;The right-hand side is a quadratic in $t$ with positive leading coefficient that is never negative. So its discriminant is not positive: $4 (x \cdot y)^2 - 4 \lVert x \rVert^2 \lVert y \rVert^2 \le 0$. Taking square roots gives the inequality.&lt;/p&gt;

  &lt;p&gt;Equality holds when the discriminant is 0, that is, when some $t$ makes $\lVert x - ty \rVert = 0$, meaning $x = t y$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Corollary 1 (Triangle inequality).&lt;/strong&gt; For all $x, y \in \mathbb{R}^n$, $\lVert x + y \rVert \le \lVert x \rVert + \lVert y \rVert$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; $\lVert x + y \rVert^2 = \lVert x \rVert^2 + 2\, x\cdot y + \lVert y \rVert^2 \le \lVert x \rVert^2 + 2 \lVert x \rVert \lVert y \rVert + \lVert y \rVert^2 = (\lVert x \rVert + \lVert y \rVert)^2$, where the $\le$ step uses Cauchy–Schwarz. Take square roots (both sides are non-negative).&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Geometrically: in the triangle with sides $x$ and $y$, the third side $x + y$ is no longer than the other two together. The straight path is the shortest.&lt;/p&gt;

&lt;h2 id=&quot;angle-and-perpendicularity&quot;&gt;Angle and perpendicularity&lt;/h2&gt;

&lt;p&gt;By Cauchy–Schwarz, for $x, y \ne 0$ we have $-1 \le \dfrac{x \cdot y}{\lVert x \rVert \lVert y \rVert} \le 1$, so the following definition makes sense.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 3 (Angle, perpendicular).&lt;/strong&gt; The angle $\theta \in [0, \pi]$ between nonzero vectors $x, y$ is given by&lt;/p&gt;

\[\cos\theta = \frac{x \cdot y}{\lVert x \rVert\, \lVert y \rVert}.\]

  &lt;p&gt;Vectors $x, y$ are &lt;em&gt;perpendicular&lt;/em&gt; (or &lt;em&gt;orthogonal&lt;/em&gt;), written $x \perp y$, if $x \cdot y = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;In $\mathbb{R}^2$ and $\mathbb{R}^3$ this agrees with the angle measured by a protractor, by the law of cosines: the triangle with sides $x, y$ has third side $x - y$, and&lt;/p&gt;

\[\lVert x - y \rVert^2 = \lVert x \rVert^2 + \lVert y \rVert^2 - 2\, x\cdot y ,\]

&lt;p&gt;which compared with $c^2 = a^2 + b^2 - 2ab\cos\theta$ gives exactly $x \cdot y = \lVert x \rVert \lVert y \rVert \cos\theta$.&lt;/p&gt;

&lt;p&gt;The sign of the dot product tells the kind of angle at once: positive means acute, zero means right, negative means obtuse. One picture to keep in mind: $x \cdot y$ equals the length of $x$ times the signed length of the &lt;em&gt;shadow&lt;/em&gt; of $y$ on the line through $x$.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 3 (Pythagoras).&lt;/strong&gt; $x \perp y$ if and only if $\lVert x + y \rVert^2 = \lVert x \rVert^2 + \lVert y \rVert^2$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Expand $\lVert x + y \rVert^2 = \lVert x \rVert^2 + 2\,x \cdot y + \lVert y \rVert^2$. The claimed identity is equivalent to $x \cdot y = 0$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;worked-examples&quot;&gt;Worked examples&lt;/h2&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; Let $u = (1, 2, 2)$, $v = (2, 0, 1)$. Then&lt;/p&gt;

\[u \cdot v = 2 + 0 + 2 = 4, \quad \lVert u \rVert = \sqrt{1 + 4 + 4} = 3, \quad \lVert v \rVert = \sqrt{5}.\]

  &lt;p&gt;So $\cos\theta = \dfrac{4}{3\sqrt5} \approx 0.596$ and $\theta \approx 53.4^\circ$. The dot product is positive, so the angle is acute, as computed. The unit vector in the direction of $u$ is $\tfrac13 (1, 2, 2)$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; Find all vectors in $\mathbb{R}^2$ perpendicular to $a = (1, 2)$.&lt;/p&gt;

  &lt;p&gt;The condition $x_1 + 2x_2 = 0$ gives $x_1 = -2x_2$, so $x = t(-2, 1)$ for arbitrary $t$. This set is a line through the origin. The plane has exactly one direction perpendicular to $a$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3.&lt;/strong&gt; The distance between $P = (1, 1, 0)$ and $Q = (3, 0, 2)$ is $\lVert Q - P \rVert = \lVert (2, -1, 2) \rVert = \sqrt{4 + 1 + 4} = 3$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-cosine-similarity&quot;&gt;Application: cosine similarity&lt;/h2&gt;

&lt;p&gt;A document can be represented by a word-count vector. Pick four keywords: “matrix”, “vector”, “cat”, “determinant”. Three documents give three vectors:&lt;/p&gt;

\[d_1 = (2, 1, 0, 1), \quad d_2 = (1, 1, 1, 0), \quad d_3 = (0, 0, 3, 1).\]

&lt;p&gt;&lt;em&gt;Cosine similarity&lt;/em&gt; is $\cos\theta$ between two vectors. It does not depend on document length, only on the proportions of words:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;$\cos(d_1, d_2) = \dfrac{3}{\sqrt6 \cdot \sqrt3} \approx 0.71$;&lt;/li&gt;
  &lt;li&gt;$\cos(d_1, d_3) = \dfrac{1}{\sqrt6 \cdot \sqrt{10}} \approx 0.13$;&lt;/li&gt;
  &lt;li&gt;$\cos(d_2, d_3) = \dfrac{3}{\sqrt3 \cdot \sqrt{10}} \approx 0.55$.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Documents 1 and 2 are closest (both about algebra), while documents 1 and 3 are nearly “perpendicular”. Search engines and language models use exactly this measure on vectors with hundreds of components; attention in Transformers also starts with dot products.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: dot product, angle and projection&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag u and v to see u·v, cos θ and the projection of u onto v.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter01/vecto_2d.html?mode=dot&amp;amp;lang=en&quot; title=&quot;Interactive: dot product, angle and projection&quot; loading=&quot;lazy&quot; style=&quot;height: 620px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter01/vecto_2d.html?mode=dot&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-the-dot-product-is-a-shadow&quot;&gt;Short video: The dot product is a shadow&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/dot-product-shadow.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;A light perpendicular to a makes b cast a shadow on a: a · b = |a| × shadow. Past 90° the shadow flips and a · b turns negative. Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Find the angle between $(1, 1, 0)$ and $(0, 1, 1)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The dot product is 1 and each vector has length $\sqrt2$, so $\cos\theta = 1/2$ and $\theta = 60^\circ$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Find $m$ so that $(m, 2, -1)$ is perpendicular to $(3, m, 4)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$3m + 2m - 4 = 0$, so $m = 4/5$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Prove the &lt;em&gt;parallelogram law&lt;/em&gt;: $\lVert x + y \rVert^2 + \lVert x - y \rVert^2 = 2\lVert x \rVert^2 + 2\lVert y \rVert^2$. Explain it with a picture.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Expand both squares: the terms $\pm 2\,x\cdot y$ cancel. Geometrically: the squares of the two diagonals of a parallelogram add up to the squares of its four sides.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; Given $\lVert x \rVert = 3$, $\lVert y \rVert = 4$, $x \cdot y = 6$, compute $\lVert 2x - y \rVert$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\lVert 2x - y \rVert^2 = 4 \cdot 9 - 4 \cdot 6 + 16 = 28$, so $\lVert 2x - y \rVert = 2\sqrt7$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced / programming).&lt;/strong&gt; Build a NumPy matrix &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;D&lt;/code&gt; whose columns are $d_1, d_2, d_3$ from the application. Normalise each column to length 1 and compute &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;D.T @ D&lt;/code&gt;. Explain why the diagonal entries are 1 and the other entries are cosine similarities.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Entry $(i, j)$ of `D.T @ D` is the dot product of columns $i$ and $j$. After normalising, the dot product of two unit vectors is the cosine of the angle between them; a column with itself gives $\cos 0 = 1$. The off-diagonal entries are about $0.71$, $0.13$, $0.55$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$x \cdot y = \sum x_i y_i$; length $\lVert x \rVert = \sqrt{x \cdot x}$.&lt;/li&gt;
    &lt;li&gt;Cauchy–Schwarz: $\lvert x \cdot y \rvert \le \lVert x \rVert \lVert y \rVert$, which implies the triangle inequality.&lt;/li&gt;
    &lt;li&gt;$\cos\theta = \dfrac{x \cdot y}{\lVert x \rVert \lVert y \rVert}$; perpendicular if and only if $x \cdot y = 0$.&lt;/li&gt;
    &lt;li&gt;Cosine similarity compares two data samples independently of their size.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Vectors in ℝⁿ and their operations</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter01/01_01_Vecto_Trong_Rn/"/>
   <updated>2026-01-01T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter01/01_01_Vecto_Trong_Rn</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson you can:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;write a vector in $\mathbb{R}^n$ as a list of numbers and draw it as an arrow when $n = 2, 3$;&lt;/li&gt;
    &lt;li&gt;add two vectors, multiply a vector by a number, and explain both operations with a picture;&lt;/li&gt;
    &lt;li&gt;use the eight properties of addition and scalar multiplication to manipulate vector expressions.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;A robot vacuum starts at the origin of the floor. The first command sends it 2 m east and 1 m north. The second sends it 1 m west and 3 m north. Where is the robot after both commands?&lt;/p&gt;

&lt;p&gt;Record each command as a pair of numbers: $u = (2, 1)$ and $v = (-1, 3)$. Doing one command after the other adds the components: the robot ends at $(2 + (-1),\ 1 + 3) = (1, 4)$. Repeating the first command three times puts it at $(6, 3)$: every component is multiplied by 3.&lt;/p&gt;

&lt;p&gt;“Add componentwise” and “multiply every component by a number” are the whole content of this lesson. Both have a clear geometric meaning, and both underlie the entire course.&lt;/p&gt;

&lt;h2 id=&quot;vectors-in-mathbbrn&quot;&gt;Vectors in $\mathbb{R}^n$&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Vector in $\mathbb{R}^n$).&lt;/strong&gt; For a positive integer $n$, a &lt;em&gt;vector&lt;/em&gt; in $\mathbb{R}^n$ is an ordered list of $n$ real numbers&lt;/p&gt;

\[x = (x_1, x_2, \dots, x_n).\]

  &lt;p&gt;The number $x_i$ is the &lt;em&gt;$i$-th component&lt;/em&gt; of $x$. The set of all such vectors is $\mathbb{R}^n$. Two vectors are equal when all corresponding components are equal.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;In matrix computations later in the course we usually write vectors as &lt;strong&gt;columns&lt;/strong&gt;:&lt;/p&gt;

\[x = \begin{bmatrix} x_1 \\ x_2 \\ \vdots \\ x_n \end{bmatrix}.\]

&lt;p&gt;The row notation $(x_1, \dots, x_n)$ only saves space; both notations denote the same vector.&lt;/p&gt;

&lt;h3 id=&quot;two-ways-to-see-a-vector&quot;&gt;Two ways to see a vector&lt;/h3&gt;

&lt;p&gt;For $n = 2$ or $n = 3$ a vector $x$ can be read in two ways:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;a point&lt;/strong&gt;: the point with coordinates $(x_1, x_2)$ in the plane;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;an arrow&lt;/strong&gt;: the arrow from the origin $O$ to that point. The arrow may be translated anywhere and remains the same vector, because it only records “how far to go along each axis”.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For $n \ge 4$ we cannot draw, but the computations are exactly the same. For example, a student’s marks in four subjects $(7.5,\ 8,\ 6.5,\ 9)$ form a vector in $\mathbb{R}^4$.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 2 (Zero vector).&lt;/strong&gt; The vector $0 = (0, 0, \dots, 0) \in \mathbb{R}^n$ is the &lt;em&gt;zero vector&lt;/em&gt;. Geometrically it is the arrow of length 0 sitting at the origin.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;vector-addition-and-scalar-multiplication&quot;&gt;Vector addition and scalar multiplication&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 3 (Addition and scalar multiplication).&lt;/strong&gt; Let $x = (x_1, \dots, x_n)$, $y = (y_1, \dots, y_n)$ be in $\mathbb{R}^n$ and let $c$ be a real number. Define&lt;/p&gt;

\[x + y = (x_1 + y_1, \dots, x_n + y_n), \qquad c\,x = (c x_1, \dots, c x_n).\]

  &lt;p&gt;The vector $-x = (-1)x$ is the &lt;em&gt;negative&lt;/em&gt; of $x$, and $x - y = x + (-y)$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Only vectors with the same number of components can be added. The expression $(1, 2) + (1, 2, 3)$ is meaningless.&lt;/p&gt;

&lt;h3 id=&quot;geometric-meaning&quot;&gt;Geometric meaning&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Head-to-tail rule.&lt;/strong&gt; Put the tail of arrow $y$ at the head of arrow $x$. The arrow from $O$ to the new head is $x + y$. If $x$ and $y$ start at the same point, $x + y$ is the diagonal of the parallelogram built on $x$ and $y$.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Scaling.&lt;/strong&gt; For $c &amp;gt; 0$ the arrow $c\,x$ points the same way as $x$ and is $c$ times as long. For $c &amp;lt; 0$ it points the opposite way. For $c = 0$ we get the zero vector.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Difference.&lt;/strong&gt; $x - y$ is the arrow from the head of $y$ to the head of $x$ (when both start at the same point).&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; Let $u = (2, 1)$ and $v = (-1, 3)$. Then&lt;/p&gt;

\[u + v = (1, 4), \qquad 3u = (6, 3), \qquad 2u - v = (4 - (-1),\ 2 - 3) = (5, -1).\]

  &lt;p&gt;On grid paper, $u$ points right and slightly up, $v$ points up and slightly left. The parallelogram built on $u, v$ has fourth vertex $(1, 4)$. The vector $3u$ lies on the same line as $u$ and is three times as long.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt; Find numbers $c_1, c_2$ with $c_1 (1, 2) + c_2 (3, 1) = (7, 4)$.&lt;/p&gt;

  &lt;p&gt;Compare components: $c_1 + 3c_2 = 7$ and $2c_1 + c_2 = 4$. The second gives $c_2 = 4 - 2c_1$. Substituting into the first: $c_1 + 12 - 6c_1 = 7$, so $c_1 = 1$ and $c_2 = 2$. Check: $(1, 2) + 2(3, 1) = (7, 4)$.&lt;/p&gt;

  &lt;p&gt;Geometrically: one step along $(1,2)$ and then two steps along $(3,1)$ lands exactly at $(7,4)$. The question “which points can be reached with such steps” is the topic of Lesson 1.4.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3 (midpoint).&lt;/strong&gt; The midpoint $M$ of segment $AB$ with $A = (1, 0, 4)$, $B = (3, -2, 2)$ is&lt;/p&gt;

\[M = \tfrac12 (A + B) = \tfrac12 (4, -2, 6) = (2, -1, 3).\]

  &lt;p&gt;Reason: starting at $A$ and adding half of $B - A$ gives $A + \tfrac12(B - A) = \tfrac12(A + B)$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;algebraic-properties&quot;&gt;Algebraic properties&lt;/h2&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Eight properties).&lt;/strong&gt; For all $x, y, z \in \mathbb{R}^n$ and all real numbers $a, b$:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$x + y = y + x$;&lt;/li&gt;
    &lt;li&gt;$(x + y) + z = x + (y + z)$;&lt;/li&gt;
    &lt;li&gt;$x + 0 = x$;&lt;/li&gt;
    &lt;li&gt;$x + (-x) = 0$;&lt;/li&gt;
    &lt;li&gt;$1\,x = x$;&lt;/li&gt;
    &lt;li&gt;$a(b\,x) = (ab)\,x$;&lt;/li&gt;
    &lt;li&gt;$a(x + y) = a x + a y$;&lt;/li&gt;
    &lt;li&gt;$(a + b)\,x = a x + b x$.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Each identity is an equality of vectors, so it suffices to compare the $i$-th components of both sides for every $i$. Each $i$-th component is an expression in real numbers, and the identity holds by the properties of real numbers. For property 7, say: the $i$-th component of $a(x+y)$ is $a(x_i + y_i)$ and that of $ax + ay$ is $a x_i + a y_i$; these agree by the distributive law for real numbers. The other properties are checked the same way.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;These eight properties matter a lot. In Chapter 05 we take exactly them as the definition of a &lt;em&gt;vector space&lt;/em&gt; and apply it to polynomials, matrices and functions.&lt;/p&gt;

&lt;div class=&quot;content-box insight-box textbook-block&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Remark.&lt;/strong&gt; Thanks to Theorem 1 we manipulate vector expressions like number expressions: move terms across, group terms, factor. For example, $2x + (1, 3) = (5, -1)$ gives $2x = (4, -4)$, so $x = (2, -2)$.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-colours-and-data-are-vectors&quot;&gt;Application: colours and data are vectors&lt;/h2&gt;

&lt;p&gt;A colour pixel is described by three numbers (red, green, blue), each in $[0, 1]$. Orange is $o = (1,\ 0.5,\ 0)$ and blue is $b = (0,\ 0,\ 1)$.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Blending the two colours in proportions $t$ and $1 - t$ means computing $t\,o + (1 - t)\,b$. With $t = 0.5$ we get $(0.5,\ 0.25,\ 0.5)$, a light purple. Graphics software produces colour gradients this way.&lt;/li&gt;
  &lt;li&gt;Darkening an image by half multiplies every colour vector by $0.5$.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In machine learning each data sample is also a vector: a house may be $(\text{area}, \text{rooms}, \text{age}) = (75, 3, 10) \in \mathbb{R}^3$. Averaging many samples means adding the vectors and multiplying by $1/m$.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: adding, subtracting and scaling vectors&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag u and v; use the tabs u + v, u − v, k·u.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter01/vecto_2d.html?mode=add&amp;amp;lang=en&quot; title=&quot;Interactive: adding, subtracting and scaling vectors&quot; loading=&quot;lazy&quot; style=&quot;height: 620px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter01/vecto_2d.html?mode=add&amp;amp;lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (basic).&lt;/strong&gt; Let $x = (1, -2, 3)$, $y = (0, 4, -1)$. Compute $x + y$, $-2x$, $3x - 2y$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$x + y = (1, 2, 2)$; $-2x = (-2, 4, -6)$; $3x - 2y = (3, -14, 11)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (basic).&lt;/strong&gt; Find $x \in \mathbb{R}^2$ with $3x - (1, 2) = (5, 4)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$3x = (6, 6)$, so $x = (2, 2)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (applied).&lt;/strong&gt; Triangle $ABC$ has $A = (0, 0)$, $B = (4, 0)$, $C = (2, 6)$. Compute the centroid $G = \tfrac13(A + B + C)$ and check that $G$ lies on the segment from $C$ to the midpoint $M$ of $AB$, at $M + \tfrac13 (C - M)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$G = (2, 2)$. The midpoint is $M = (2, 0)$, and $M + \tfrac13 (C - M) = (2, 0) + \tfrac13 (0, 6) = (2, 2) = G$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4 (applied).&lt;/strong&gt; Prove from Theorem 1 that $0\,x = 0$ for every $x$. (Hint: $0\,x = (0 + 0)\,x$.)&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

By property 8, $0\,x = (0+0)\,x = 0\,x + 0\,x$. Add $-(0\,x)$ to both sides and use properties 2, 3, 4 to get $0 = 0\,x$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced / programming).&lt;/strong&gt; In NumPy run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x = np.array([1, -2, 3]); y = np.array([0, 4, -1])&lt;/code&gt; and compute &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;3*x - 2*y&lt;/code&gt;. Compare with Exercise 1. Then compute the colour between orange $(1, 0.5, 0)$ and blue $(0, 0, 1)$ for $t = 0.25$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

`array([ 3, -14, 11])`. For $t = 0.25$: $0.25(1, 0.5, 0) + 0.75(0, 0, 1) = (0.25,\ 0.125,\ 0.75)$, closer to blue.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;A vector in $\mathbb{R}^n$ is a list of $n$ numbers; for $n = 2, 3$ it is an arrow.&lt;/li&gt;
    &lt;li&gt;Addition and scalar multiplication act componentwise; geometrically they are the parallelogram rule and scaling.&lt;/li&gt;
    &lt;li&gt;The eight properties of Theorem 1 let us manipulate vector expressions like number expressions, and they become the definition of a vector space in Chapter 05.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Working with Matrices on a Computer</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter00/00_03_Lam_Viec_Voi_Ma_Tran_Tren_May_Tinh/"/>
   <updated>2026-01-01T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter00/00_03_Lam_Viec_Voi_Ma_Tran_Tren_May_Tinh</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;create vectors and matrices and do basic operations with NumPy and SymPy;&lt;/li&gt;
    &lt;li&gt;use SymPy to check a hand computation (Gaussian elimination, inverse, determinant) with exact fractions;&lt;/li&gt;
    &lt;li&gt;explain why &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.1 + 0.2 == 0.3&lt;/code&gt; returns &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;False&lt;/code&gt; and how to compare floating-point numbers correctly.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;Open Python and type:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.3&lt;/span&gt;
&lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.2&lt;/span&gt;
&lt;span class=&quot;mf&quot;&gt;0.30000000000000004&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The computer is not wrong: it stores real numbers in binary with 53 bits, and $0.1$ has no exact binary representation, just as $1/3$ has no finite decimal expansion. In matrix computations these tiny errors can accumulate. This lesson introduces two tools, NumPy (fast, approximate) and SymPy (slower, exact), and when to use which.&lt;/p&gt;

&lt;h2 id=&quot;installation&quot;&gt;Installation&lt;/h2&gt;

&lt;p&gt;Both libraries install with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pip&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python3 &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; venv la-venv
&lt;span class=&quot;nb&quot;&gt;source &lt;/span&gt;la-venv/bin/activate
pip &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;numpy sympy
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Jupyter or Google Colab (which ship with both libraries) work too if you prefer not to install anything.&lt;/p&gt;

&lt;h2 id=&quot;numpy-approximate-and-fast&quot;&gt;NumPy: approximate and fast&lt;/h2&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;               &lt;span class=&quot;c1&quot;&gt;# matrix-vector product: array([11, 18])
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;                 &lt;span class=&quot;c1&quot;&gt;# transpose
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;det&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;# determinant: 5.000000000000001
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;inv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;# inverse (floating point)
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;solve&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;# solution of Ax = b: array([0.8, 1.4])
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Note: matrix multiplication is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@&lt;/code&gt;, while &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;*&lt;/code&gt; multiplies &lt;em&gt;entrywise&lt;/em&gt;. The determinant comes out as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;5.000000000000001&lt;/code&gt;, not &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;5&lt;/code&gt;: NumPy computes it through an LU factorization in floating point (Chapter 03).&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Floating-point number).&lt;/strong&gt; A double-precision &lt;em&gt;floating-point number&lt;/em&gt; (type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float64&lt;/code&gt;) has the form $\pm m \cdot 2^e$ with $m$ having 53 binary digits. Rounding a real number to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float64&lt;/code&gt; has relative error at most $\varepsilon = 2^{-53} \approx 1.1 \times 10^{-16}$, called the &lt;em&gt;unit roundoff&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Practical consequence: &lt;strong&gt;do not compare two floats with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;==&lt;/code&gt;&lt;/strong&gt;. Check that the difference is small instead:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;isclose&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;          &lt;span class=&quot;c1&quot;&gt;# True
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;allclose&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linalg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;inv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;eye&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;# True
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;sympy-exact-and-symbolic&quot;&gt;SymPy: exact and symbolic&lt;/h2&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sympy&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Matrix&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Rational&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;symbols&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Matrix&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;det&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;         &lt;span class=&quot;c1&quot;&gt;# 5
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;inv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;         &lt;span class=&quot;c1&quot;&gt;# Matrix([[3/5, -1/5], [-1/5, 2/5]])
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rref&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;        &lt;span class=&quot;c1&quot;&gt;# (Matrix([[1, 0], [0, 1]]), (0, 1))
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;nullspace&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;# [] (the kernel is only the zero vector)
&lt;/span&gt;
&lt;span class=&quot;nc&quot;&gt;Rational&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Rational&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Rational&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;# True
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;SymPy stores rationals as fractions, so Gaussian elimination is exact. It also computes with variables:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;symbols&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;M&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Matrix&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;det&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;         &lt;span class=&quot;c1&quot;&gt;# 1 - t**2
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So $M$ is singular exactly when $t = \pm 1$.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1 (checking an elimination).&lt;/strong&gt; Suppose that by hand we reduced&lt;/p&gt;

\[B = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 &amp;amp; 1 \\ 2 &amp;amp; 4 &amp;amp; 1 &amp;amp; 3 \\ 3 &amp;amp; 6 &amp;amp; 1 &amp;amp; 4 \end{bmatrix}\]

  &lt;p&gt;to reduced row echelon form and found pivots in columns 1 and 3. Check with SymPy:&lt;/p&gt;

  &lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;B&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Matrix&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;R&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pivots&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rref&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# R = Matrix([[1, 2, 0, 1], [0, 0, 1, 1], [0, 0, 0, 0]]), pivots = (0, 2)
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;  &lt;/div&gt;

  &lt;p&gt;SymPy numbers columns from $0$, so &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(0, 2)&lt;/code&gt; means columns 1 and 3. The rank is 2, matching the hand computation.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;which-tool-when&quot;&gt;Which tool when&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;SymPy&lt;/strong&gt; for small matrices with integer or fraction entries when you need exact answers: checking exercises, finding a basis of a kernel, determinants with parameters.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;NumPy&lt;/strong&gt; for large matrices or measured data (which already carries errors): least squares (Chapter 08), eigenvalues of large matrices (Chapter 09), SVD and PCA (Chapter 11).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One phenomenon to know: in floating point, “rank” is no longer clear-cut. A matrix that is singular in theory may give determinant $10^{-17}$ instead of $0$. The right fix uses singular values (Chapter 11) with a tolerance, as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.linalg.matrix_rank&lt;/code&gt; does.&lt;/p&gt;

&lt;h2 id=&quot;application-checking-your-own-work&quot;&gt;Application: checking your own work&lt;/h2&gt;

&lt;p&gt;Every exercise in the course can be checked with a few lines of SymPy. A good habit: solve by hand first, then check by machine; if they disagree, find the wrong step instead of copying the machine’s answer. With NumPy, check a solution $x$ of $Ax = b$ with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.allclose(A @ x, b)&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: run NumPy and SymPy in the browser&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Edit and run Python code to compare NumPy&apos;s approximate results with SymPy&apos;s exact ones.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter00/may_tinh_ma_tran.html?lang=en&quot; title=&quot;Interactive: run NumPy and SymPy in the browser&quot; loading=&quot;lazy&quot; style=&quot;height: 760px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter00/may_tinh_ma_tran.html?lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1 (programming).&lt;/strong&gt; Compare &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.1 + 0.2 == 0.3&lt;/code&gt; in NumPy (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.float64(0.1) + np.float64(0.2) == np.float64(0.3)&lt;/code&gt;) with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Rational(1,10) + Rational(2,10) == Rational(3,10)&lt;/code&gt; in SymPy. Explain the results.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

NumPy gives `False` because $0.1$, $0.2$, $0.3$ are all rounded when stored in binary, and the rounded sum differs from the rounded $0.3$ in the last bit. SymPy gives `True` because it stores the fractions $1/10$, $2/10$, $3/10$ exactly.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2 (programming).&lt;/strong&gt; Use SymPy to invert $\begin{bmatrix} 1 &amp;amp; 2 \\ 3 &amp;amp; 4 \end{bmatrix}$ and check by hand.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

`Matrix([[1, 2], [3, 4]]).inv()` gives $\begin{bmatrix} -2 &amp;amp; 1 \\ 3/2 &amp;amp; -1/2 \end{bmatrix}$. By the formula $\frac{1}{ad - bc}\begin{bmatrix} d &amp;amp; -b \\ -c &amp;amp; a \end{bmatrix}$ with $ad - bc = -2$, the results agree.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3 (programming).&lt;/strong&gt; The Hilbert matrix $H_n$ has entries $1/(i + j - 1)$. For $n = 12$, compute &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.linalg.inv(H) @ H&lt;/code&gt; with NumPy and compare with the identity. Redo it with SymPy (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sympy.hilbert(12)&lt;/code&gt;). Comment.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

With NumPy the result is visibly far from the identity (errors of order $10^{-2}$ or larger) because $H_{12}$ has condition number about $10^{16}$ (Chapter 11): rounding errors are amplified about $10^{16}$ times. SymPy works with fractions and returns exactly the identity.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Use SymPy to find the values of $t$ for which $\begin{bmatrix} 1 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; t &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; t \end{bmatrix}$ is singular.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

The determinant is $(t - 1)^2$, so the matrix is singular exactly when $t = 1$.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;NumPy computes fast in floating point (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float64&lt;/code&gt;, relative error about $10^{-16}$); use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@&lt;/code&gt; for matrix products and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.isclose&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.allclose&lt;/code&gt; for comparisons.&lt;/li&gt;
    &lt;li&gt;SymPy computes exactly with fractions and symbols: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Matrix&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rref&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inv&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;det&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nullspace&lt;/code&gt;.&lt;/li&gt;
    &lt;li&gt;Solve by hand first, check by machine after; small matrices with SymPy, large data with NumPy.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Complex Numbers and Fields</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter00/00_02_So_Phuc_Va_Truong_So/"/>
   <updated>2026-01-01T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter00/00_02_So_Phuc_Va_Truong_So</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;add, multiply and divide complex numbers in the form $a + bi$, and compute conjugates and moduli;&lt;/li&gt;
    &lt;li&gt;convert a complex number to polar form and use de Moivre’s formula to compute powers and roots;&lt;/li&gt;
    &lt;li&gt;state the definition of a field and check that $\mathbb{Q}$, $\mathbb{R}$, $\mathbb{C}$, $\mathbb{F}_2$ are fields.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;The matrix of the $90^\circ$ rotation of the plane is&lt;/p&gt;

\[A = \begin{bmatrix} 0 &amp;amp; -1 \\ 1 &amp;amp; 0 \end{bmatrix}.\]

&lt;p&gt;No nonzero real vector keeps its direction under $A$: every vector is rotated away. In Chapter 09 this means $A$ has no real eigenvalues; its characteristic equation is $\lambda^2 + 1 = 0$. Over the complex numbers this equation has two roots $\lambda = \pm i$. Complex numbers let us talk about the “eigenvalues” of a rotation, and multiplying by $i$ is exactly a $90^\circ$ rotation.&lt;/p&gt;

&lt;h2 id=&quot;complex-numbers-in-algebraic-form&quot;&gt;Complex numbers in algebraic form&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Complex number).&lt;/strong&gt; A &lt;em&gt;complex number&lt;/em&gt; is an expression $z = a + bi$ with $a, b \in \mathbb{R}$ and $i^2 = -1$. The number $a = \operatorname{Re} z$ is the &lt;em&gt;real part&lt;/em&gt; and $b = \operatorname{Im} z$ the &lt;em&gt;imaginary part&lt;/em&gt;. The set of complex numbers is $\mathbb{C}$. Addition and multiplication:&lt;/p&gt;

\[(a + bi) + (c + di) = (a + c) + (b + d)i, \qquad (a + bi)(c + di) = (ac - bd) + (ad + bc)i.\]

  &lt;p&gt;The &lt;em&gt;conjugate&lt;/em&gt; of $z = a + bi$ is $\bar z = a - bi$, and the &lt;em&gt;modulus&lt;/em&gt; of $z$ is $|z| = \sqrt{a^2 + b^2}$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;No need to memorize the product formula: expand as a polynomial in $i$ and replace $i^2$ by $-1$. Since $z \bar z = a^2 + b^2 = |z|^2$, for $z \ne 0$:&lt;/p&gt;

\[\frac{1}{z} = \frac{\bar z}{|z|^2}.\]

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; With $z = 2 + 3i$, $w = 1 - i$:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$z + w = 3 + 2i$;&lt;/li&gt;
    &lt;li&gt;$zw = 2 - 2i + 3i - 3i^2 = 5 + i$;&lt;/li&gt;
    &lt;li&gt;$\dfrac{z}{w} = \dfrac{(2 + 3i)(1 + i)}{(1 - i)(1 + i)} = \dfrac{2 + 2i + 3i - 3}{2} = -\dfrac{1}{2} + \dfrac{5}{2} i$.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;p&gt;The complex number $a + bi$ corresponds to the point $(a, b)$ in the &lt;em&gt;complex plane&lt;/em&gt; (Argand plane). Complex addition is vector addition in $\mathbb{R}^2$; $\bar z$ is the reflection of $z$ in the real axis; $|z|$ is the length of the vector.&lt;/p&gt;

&lt;h2 id=&quot;polar-form-and-de-moivres-formula&quot;&gt;Polar form and de Moivre’s formula&lt;/h2&gt;

&lt;p&gt;Every $z \ne 0$ can be written as&lt;/p&gt;

\[z = r(\cos\theta + i \sin\theta) = r e^{i\theta}, \qquad r = |z|,\]

&lt;p&gt;where $\theta$ is the angle from the positive real axis to $z$, called the &lt;em&gt;argument&lt;/em&gt; of $z$ (defined up to multiples of $2\pi$). The notation $e^{i\theta} = \cos\theta + i\sin\theta$ is &lt;em&gt;Euler’s formula&lt;/em&gt;.&lt;/p&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1 (Multiplication in polar form).&lt;/strong&gt; If $z = r e^{i\alpha}$ and $w = s e^{i\beta}$, then $zw = rs\, e^{i(\alpha + \beta)}$. Consequence (de Moivre’s formula): $z^n = r^n e^{in\alpha}$ for every integer $n$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Multiply directly:
$(\cos\alpha + i\sin\alpha)(\cos\beta + i\sin\beta) = (\cos\alpha\cos\beta - \sin\alpha\sin\beta) + i(\sin\alpha\cos\beta + \cos\alpha\sin\beta)$,
and by the angle-addition formulas the right side equals $\cos(\alpha + \beta) + i\sin(\alpha + \beta)$. De Moivre’s formula follows by induction on $n$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Geometrically, multiplying by $w = s e^{i\beta}$ &lt;em&gt;rotates&lt;/em&gt; the complex plane by $\beta$ and &lt;em&gt;scales&lt;/em&gt; it by $s$. Multiplying by $i = e^{i\pi/2}$ is a $90^\circ$ rotation, matching the motivating example.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2 (powers).&lt;/strong&gt; Compute $(1 + i)^{10}$. Since $1 + i = \sqrt{2}\, e^{i\pi/4}$,&lt;/p&gt;

  &lt;p&gt;\((1 + i)^{10} = (\sqrt{2})^{10} e^{i \cdot 10\pi/4} = 32\, e^{i 5\pi/2} = 32\, e^{i\pi/2} = 32 i.\)&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3 ($n$th roots).&lt;/strong&gt; Solve $z^3 = 8i$. Write $8i = 8 e^{i\pi/2}$ and $z = r e^{i\theta}$. From $r^3 e^{3i\theta} = 8 e^{i\pi/2}$ we get $r = 2$ and $3\theta = \pi/2 + 2k\pi$, so $\theta = \pi/6 + 2k\pi/3$ for $k = 0, 1, 2$. The three roots are&lt;/p&gt;

\[z_0 = 2e^{i\pi/6} = \sqrt{3} + i, \qquad z_1 = 2e^{i5\pi/6} = -\sqrt{3} + i, \qquad z_2 = 2e^{i3\pi/2} = -2i.\]

  &lt;p&gt;They are the vertices of an equilateral triangle inscribed in the circle of radius 2.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2 (Fundamental theorem of algebra).&lt;/strong&gt; Every polynomial of degree $n \ge 1$ with complex coefficients has exactly $n$ complex roots, counted with multiplicity.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;We accept this theorem without proof (it needs complex analysis). It guarantees that every $n \times n$ matrix has exactly $n$ complex eigenvalues counted with multiplicity (Chapter 09).&lt;/p&gt;

&lt;h2 id=&quot;complex-numbers-as-matrices&quot;&gt;Complex numbers as matrices&lt;/h2&gt;

&lt;p&gt;Multiplication by $z = a + bi$ is the map $\mathbb{R}^2 \to \mathbb{R}^2$ sending $(x, y)$ to $(ax - by,\ bx + ay)$. This map is linear, with matrix&lt;/p&gt;

\[M_z = \begin{bmatrix} a &amp;amp; -b \\ b &amp;amp; a \end{bmatrix} = r \begin{bmatrix} \cos\theta &amp;amp; -\sin\theta \\ \sin\theta &amp;amp; \cos\theta \end{bmatrix}.\]

&lt;p&gt;We have $M_{zw} = M_z M_w$ and $M_{z + w} = M_z + M_w$: complex numbers “are” rotation–scaling matrices. For $z = i$ we get exactly the matrix $A$ from the motivating example.&lt;/p&gt;

&lt;h2 id=&quot;fields&quot;&gt;Fields&lt;/h2&gt;

&lt;p&gt;When solving systems by Gaussian elimination (Chapter 02) we only use addition, subtraction, multiplication and division by nonzero numbers. Any number system with these four operations and the familiar rules will do.&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 2 (Field).&lt;/strong&gt; A &lt;em&gt;field&lt;/em&gt; is a set $\mathbb{F}$ with two operations $+$ and $\cdot$ such that, for all $a, b, c \in \mathbb{F}$:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;$+$ and $\cdot$ are commutative and associative, and $a(b + c) = ab + ac$;&lt;/li&gt;
    &lt;li&gt;there is an element $0$ with $a + 0 = a$, and each $a$ has a negative $-a$ with $a + (-a) = 0$;&lt;/li&gt;
    &lt;li&gt;there is an element $1 \ne 0$ with $a \cdot 1 = a$, and each $a \ne 0$ has an inverse $a^{-1}$ with $a a^{-1} = 1$.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 4.&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$\mathbb{Q}$, $\mathbb{R}$, $\mathbb{C}$ are fields. In $\mathbb{C}$ the inverse of $z \ne 0$ is $\bar z / |z|^2$.&lt;/li&gt;
    &lt;li&gt;$\mathbb{Z}$ is not a field: $2$ has no inverse in $\mathbb{Z}$.&lt;/li&gt;
    &lt;li&gt;$\mathbb{F}_2 = \{0, 1\}$ with addition and multiplication modulo 2 ($1 + 1 = 0$) is a field. These are the even and odd classes of Lesson 00-01.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;p&gt;The tables of $\mathbb{F}_2$: $0 + 0 = 0$, $0 + 1 = 1$, $1 + 1 = 0$; $0 \cdot 0 = 0 \cdot 1 = 0$, $1 \cdot 1 = 1$. In $\mathbb{F}_2$, $-1 = 1$, so subtraction is the same as addition.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 5 (same system, different field).&lt;/strong&gt; Consider&lt;/p&gt;

\[x + y = 1, \qquad y + z = 1, \qquad x + z = 1.\]

  &lt;p&gt;Over $\mathbb{R}$, adding the three equations gives $2(x + y + z) = 3$, and the system has the unique solution $x = y = z = 1/2$. Over $\mathbb{F}_2$, adding the three equations gives $2(x + y + z) = 0$ on the left and $1 + 1 + 1 = 1$ on the right, so $0 = 1$: the system is inconsistent. The answer depends on the field.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;In this course, numbers are real unless stated otherwise. Most theorems in Chapters 01 to 06 hold word for word over any field; we will say so when we need $\mathbb{C}$ (complex eigenvalues, Chapter 09) or the order and square roots of $\mathbb{R}$ (lengths and angles, Chapter 07).&lt;/p&gt;

&lt;h2 id=&quot;application-error-correcting-codes-over-mathbbf_2&quot;&gt;Application: error-correcting codes over $\mathbb{F}_2$&lt;/h2&gt;

&lt;p&gt;Digital data is a string of bits, that is, a vector over $\mathbb{F}_2$. The Hamming $(7, 4)$ code sends 4 data bits with 3 check bits, so that every codeword $c$ satisfies $Hc = 0$ for a $3 \times 7$ matrix $H$ over $\mathbb{F}_2$. If the channel flips one bit, the receiver computes $Hc&apos;$, and the result tells which bit was flipped. The whole computation is linear algebra over the field $\mathbb{F}_2$.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: complex numbers in the plane&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Drag z₁, z₂ to see addition, multiplication (moduli multiply, angles add), division, conjugate and powers.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter00/so_phuc.html?lang=en&quot; title=&quot;Interactive: complex numbers in the plane&quot; loading=&quot;lazy&quot; style=&quot;height: 640px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter00/so_phuc.html?lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;short-video-multiplying-by-a-complex-number-rotates-and-scales-the-plane&quot;&gt;Short video: Multiplying by a complex number rotates and scales the plane&lt;/h3&gt;

&lt;div class=&quot;reel-video&quot;&gt;
  &lt;video controls=&quot;&quot; playsinline=&quot;&quot; preload=&quot;metadata&quot; src=&quot;/public/videos/reels/complex-rotation.mp4&quot;&gt;&lt;/video&gt;
  &lt;p class=&quot;reel-caption&quot;&gt;Multiplying by i turns the plane 90°, by 1 + i turns it 45° and stretches it by √2; lengths multiply, angles add. Silent version; on-screen text in Vietnamese.&lt;/p&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Compute $(3 - 2i)(1 + 4i)$ and $\dfrac{3 - 2i}{1 + 4i}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$(3 - 2i)(1 + 4i) = 3 + 12i - 2i - 8i^2 = 11 + 10i$.
$\dfrac{3 - 2i}{1 + 4i} = \dfrac{(3 - 2i)(1 - 4i)}{17} = \dfrac{3 - 12i - 2i + 8i^2}{17} = \dfrac{-5 - 14i}{17}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; Write $z = -1 + \sqrt{3}\, i$ in polar form, then compute $z^6$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$|z| = 2$, $\theta = 2\pi/3$, so $z = 2e^{i2\pi/3}$ and $z^6 = 64\, e^{i4\pi} = 64$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Solve $z^4 = -16$ in $\mathbb{C}$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$-16 = 16 e^{i\pi}$, so $z = 2 e^{i(\pi/4 + k\pi/2)}$, $k = 0, 1, 2, 3$: $z = \pm\sqrt{2} \pm \sqrt{2}\, i$ (all four sign choices).

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Check that $M_z M_w = M_{zw}$ for $z = 1 + i$, $w = 2 - i$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$zw = 2 - i + 2i - i^2 = 3 + i$. And $M_z M_w = \begin{bmatrix} 1 &amp;amp; -1 \\ 1 &amp;amp; 1 \end{bmatrix} \begin{bmatrix} 2 &amp;amp; 1 \\ -1 &amp;amp; 2 \end{bmatrix} = \begin{bmatrix} 3 &amp;amp; -1 \\ 1 &amp;amp; 3 \end{bmatrix} = M_{3 + i}$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; Is $\mathbb{Z}_4 = \{0, 1, 2, 3\}$ with addition and multiplication modulo 4 a field? What about $\mathbb{Z}_5$?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\mathbb{Z}_4$ is not a field: $2 \cdot 2 = 0$, so $2$ has no inverse (if $2a = 1$ then $0 = 2 \cdot 2a = 2$, a contradiction). $\mathbb{Z}_5$ is a field: $1^{-1} = 1$, $2^{-1} = 3$, $3^{-1} = 2$, $4^{-1} = 4$. In general, $\mathbb{Z}_p$ is a field exactly when $p$ is prime.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;$z = a + bi$, $i^2 = -1$; $\bar z = a - bi$; $|z|^2 = z\bar z$; $1/z = \bar z / |z|^2$.&lt;/li&gt;
    &lt;li&gt;Polar form $z = re^{i\theta}$: multiplying multiplies moduli and adds angles, $z^n = r^n e^{in\theta}$; the equation $z^n = w$ has $n$ roots equally spaced on a circle.&lt;/li&gt;
    &lt;li&gt;Multiplication by $a + bi$ is a linear map of $\mathbb{R}^2$ with matrix $\begin{bmatrix} a &amp;amp; -b \\ b &amp;amp; a \end{bmatrix}$ (rotation and scaling).&lt;/li&gt;
    &lt;li&gt;A field is a set with four operations obeying the familiar rules: $\mathbb{Q}$, $\mathbb{R}$, $\mathbb{C}$, $\mathbb{F}_2$. Linear algebra works over any field.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Sets, Maps and Relations</title>
   <link href="https://linear-algebra-self-learning.pages.dev/contents/en/chapter00/00_01_Tap_Hop_Anh_Xa_Va_Quan_He/"/>
   <updated>2026-01-01T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/contents/en/chapter00/00_01_Tap_Hop_Anh_Xa_Va_Quan_He</id>
   <content type="html">&lt;div class=&quot;textbook-objectives&quot;&gt;

  &lt;p&gt;&lt;strong&gt;Learning objectives.&lt;/strong&gt; After this lesson, you should be able to:&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;read and write sets in roster and set-builder notation, using $\in$, $\subseteq$, $\cup$, $\cap$, $\times$ correctly;&lt;/li&gt;
    &lt;li&gt;check whether a map is injective, surjective or bijective;&lt;/li&gt;
    &lt;li&gt;recognize an equivalence relation and describe its equivalence classes.&lt;/li&gt;
  &lt;/ul&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-motivating-example&quot;&gt;A motivating example&lt;/h2&gt;

&lt;p&gt;A system assigns ID numbers to students. Each student gets exactly one ID: this is a &lt;em&gt;map&lt;/em&gt; from the set of students to the set of IDs. Two natural questions:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Do two students share an ID? If not, the map is &lt;em&gt;injective&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Is every ID used by someone? If so, the map is &lt;em&gt;surjective&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When both hold, each ID leads back to exactly one student: the map has an &lt;em&gt;inverse&lt;/em&gt;. In linear algebra, the questions “does $Ax = b$ have a solution, and is it unique?” are exactly these two questions for the map $x \mapsto Ax$.&lt;/p&gt;

&lt;h2 id=&quot;sets&quot;&gt;Sets&lt;/h2&gt;

&lt;p&gt;A &lt;em&gt;set&lt;/em&gt; is a collection of objects, called its &lt;em&gt;elements&lt;/em&gt;. Write $x \in S$ if $x$ is an element of $S$, and $x \notin S$ otherwise.&lt;/p&gt;

&lt;p&gt;There are two ways to describe a set:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;by listing: $S = \{1, 2, 3\}$;&lt;/li&gt;
  &lt;li&gt;by a property: $S = \{x \in \mathbb{Z} : 1 \le x \le 3\}$, read “the set of integers $x$ such that $1 \le x \le 3$”.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Number sets used in the course: $\mathbb{N} = \{0, 1, 2, \dots\}$, $\mathbb{Z}$ (integers), $\mathbb{Q}$ (rationals), $\mathbb{R}$ (reals), $\mathbb{C}$ (complex numbers, Lesson 00-02).&lt;/p&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 1 (Set operations).&lt;/strong&gt; Let $A$, $B$ be sets.&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$A \subseteq B$ ($A$ is a &lt;em&gt;subset&lt;/em&gt; of $B$) if every element of $A$ belongs to $B$. Two sets are equal when $A \subseteq B$ and $B \subseteq A$.&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;Union&lt;/em&gt;: $A \cup B = \{x : x \in A \text{ or } x \in B\}$.&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;Intersection&lt;/em&gt;: $A \cap B = \{x : x \in A \text{ and } x \in B\}$.&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;Difference&lt;/em&gt;: $A \setminus B = \{x \in A : x \notin B\}$.&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;Cartesian product&lt;/em&gt;: $A \times B = \{(a, b) : a \in A,\ b \in B\}$, the set of ordered pairs.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;The set with no elements is the &lt;em&gt;empty set&lt;/em&gt;, written $\varnothing$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The Cartesian product is where $\mathbb{R}^n$ comes from: $\mathbb{R}^2 = \mathbb{R} \times \mathbb{R}$ is the set of pairs $(x_1, x_2)$, and $\mathbb{R}^n$ is the set of $n$-tuples of real numbers.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 1.&lt;/strong&gt; The solution set of $x^2 &amp;lt; 4$ in $\mathbb{R}$ is&lt;/p&gt;

\[\{x \in \mathbb{R} : x^2 &amp;lt; 4\} = \{x \in \mathbb{R} : -2 &amp;lt; x &amp;lt; 2\} = (-2, 2).\]

  &lt;p&gt;With $A = \{1, 2, 3\}$ and $B = \{2, 3, 4\}$: $A \cup B = \{1, 2, 3, 4\}$, $A \cap B = \{2, 3\}$, $A \setminus B = \{1\}$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;To prove $A = B$, the standard method is to prove both inclusions $A \subseteq B$ and $B \subseteq A$: take an arbitrary $x$ in one set and show it lies in the other. We will do this many times, for example when proving two subspaces are equal in Chapter 05.&lt;/p&gt;

&lt;h2 id=&quot;maps&quot;&gt;Maps&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 2 (Map).&lt;/strong&gt; A &lt;em&gt;map&lt;/em&gt; (or &lt;em&gt;function&lt;/em&gt;) $f : X \to Y$ assigns to each element $x \in X$ exactly one element $f(x) \in Y$. The set $X$ is the &lt;em&gt;domain&lt;/em&gt; and $Y$ is the &lt;em&gt;codomain&lt;/em&gt;. The &lt;em&gt;image&lt;/em&gt; of $f$ is&lt;/p&gt;

\[f(X) = \{f(x) : x \in X\} \subseteq Y.\]

  &lt;p&gt;For $y \in Y$, the &lt;em&gt;preimage&lt;/em&gt; of $y$ is $f^{-1}(y) = \{x \in X : f(x) = y\}$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 3 (Injective, surjective, bijective).&lt;/strong&gt; A map $f : X \to Y$ is&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;&lt;em&gt;injective&lt;/em&gt; if $f(x_1) = f(x_2)$ implies $x_1 = x_2$ (different elements have different images);&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;surjective&lt;/em&gt; if for every $y \in Y$ there is $x \in X$ with $f(x) = y$ (that is, $f(X) = Y$);&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;bijective&lt;/em&gt; if it is both injective and surjective.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;p&gt;In terms of equations: $f$ is injective when $f(x) = y$ has &lt;em&gt;at most&lt;/em&gt; one solution for every $y$; surjective when it has &lt;em&gt;at least&lt;/em&gt; one solution for every $y$; bijective when it has &lt;em&gt;exactly&lt;/em&gt; one.&lt;/p&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 2.&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;$f : \mathbb{R} \to \mathbb{R}$, $f(x) = x^2$ is neither injective ($f(-1) = f(1)$) nor surjective (no $x$ has $f(x) = -1$).&lt;/li&gt;
    &lt;li&gt;$g : \mathbb{R} \to [0, \infty)$, $g(x) = x^2$ is surjective but not injective. Same formula, different codomain, different properties.&lt;/li&gt;
    &lt;li&gt;$h : \mathbb{R} \to \mathbb{R}$, $h(x) = 2x + 1$ is bijective: $2x + 1 = y$ has exactly one solution $x = (y - 1)/2$.&lt;/li&gt;
    &lt;li&gt;$p : \mathbb{R}^2 \to \mathbb{R}$, $p(x_1, x_2) = x_1$ is surjective but not injective: all points on a vertical line have the same image.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 4 (Composition and inverse).&lt;/strong&gt; For $f : X \to Y$ and $g : Y \to Z$, the &lt;em&gt;composition&lt;/em&gt; $g \circ f : X \to Z$ is $(g \circ f)(x) = g(f(x))$. The &lt;em&gt;identity map&lt;/em&gt; on $X$ is $\mathrm{id}_X(x) = x$. A map $g : Y \to X$ is an &lt;em&gt;inverse&lt;/em&gt; of $f$ if $g \circ f = \mathrm{id}_X$ and $f \circ g = \mathrm{id}_Y$; then we write $g = f^{-1}$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 1.&lt;/strong&gt; A map $f : X \to Y$ has an inverse if and only if $f$ is bijective. The inverse, if it exists, is unique.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof (sketch).&lt;/strong&gt; If $f$ is bijective, each $y$ has exactly one $x$ with $f(x) = y$; set $g(y) = x$, so $g \circ f = \mathrm{id}_X$ and $f \circ g = \mathrm{id}_Y$. Conversely, if $g$ exists: $f(x_1) = f(x_2)$ gives $x_1 = g(f(x_1)) = g(f(x_2)) = x_2$, so $f$ is injective; every $y$ satisfies $f(g(y)) = y$, so $f$ is surjective. If $g$ and $g&apos;$ are both inverses, then $g = g \circ (f \circ g&apos;) = (g \circ f) \circ g&apos; = g&apos;$.&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;In Chapter 03, a square matrix $A$ is invertible exactly when $x \mapsto Ax$ is a bijection from $\mathbb{R}^n$ to $\mathbb{R}^n$; in Chapter 06, injectivity corresponds to a kernel equal to $\{0\}$ and surjectivity to an image equal to the whole codomain.&lt;/p&gt;

&lt;h2 id=&quot;equivalence-relations&quot;&gt;Equivalence relations&lt;/h2&gt;

&lt;div class=&quot;textbook-definition&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Definition 5 (Equivalence relation).&lt;/strong&gt; A &lt;em&gt;relation&lt;/em&gt; $\sim$ on a set $X$ says, for each pair of elements, whether they are “related”. The relation $\sim$ is an &lt;em&gt;equivalence relation&lt;/em&gt; if for all $x, y, z \in X$:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;&lt;em&gt;reflexive&lt;/em&gt;: $x \sim x$;&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;symmetric&lt;/em&gt;: $x \sim y$ implies $y \sim x$;&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;transitive&lt;/em&gt;: $x \sim y$ and $y \sim z$ imply $x \sim z$.&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;The &lt;em&gt;equivalence class&lt;/em&gt; of $x$ is $[x] = \{y \in X : y \sim x\}$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-theorem&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Theorem 2.&lt;/strong&gt; The equivalence classes of an equivalence relation on $X$ cover $X$, and any two classes are either equal or disjoint.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-proof&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Proof.&lt;/strong&gt; Each $x$ lies in $[x]$ since $x \sim x$. Suppose $z \in [x] \cap [y]$. Then $z \sim x$ and $z \sim y$, so $x \sim y$ (symmetry, then transitivity). For $w \in [x]$ we get $w \sim x \sim y$, so $w \in [y]$; hence $[x] \subseteq [y]$, and likewise $[y] \subseteq [x]$.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;textbook-example&quot;&gt;
  &lt;p&gt;&lt;strong&gt;Example 3.&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;On $\mathbb{Z}$, let $a \sim b$ if $a - b$ is divisible by 2. There are two classes: even and odd numbers. This is the basis of the field $\mathbb{F}_2$ in Lesson 00-02.&lt;/li&gt;
    &lt;li&gt;On $m \times n$ matrices, let $A \sim B$ if $A$ can be turned into $B$ by elementary row operations. This is an equivalence relation (each operation can be undone), and each class contains exactly one reduced row echelon matrix (Chapter 02).&lt;/li&gt;
    &lt;li&gt;In Chapter 06, “similarity” $B = P^{-1} A P$ is an equivalence relation on square matrices.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;h2 id=&quot;application-classifying-by-equivalence-classes&quot;&gt;Application: classifying by equivalence classes&lt;/h2&gt;

&lt;p&gt;An equivalence relation is the mathematical way of saying “treat these as the same”. When solving $Ax = b$, we replace the system by a simpler equivalent one; all systems in one class have the same solution set. When studying linear maps, we pick the simplest representative in a class of similar matrices (a diagonal matrix in Chapter 09). The idea “choose a good representative for each class” runs through the whole course.&lt;/p&gt;

&lt;h2 id=&quot;interactive-minh-hoạ&quot;&gt;Interactive (Minh hoạ)&lt;/h2&gt;

&lt;div class=&quot;interactive-frame&quot;&gt;
  &lt;div class=&quot;interactive-frame-head&quot;&gt;
    &lt;div class=&quot;interactive-frame-title&quot;&gt;Interactive: arrow diagram of a map&lt;/div&gt;
    &lt;div class=&quot;interactive-frame-desc&quot;&gt;Connect elements of A to B and see whether the map is injective, surjective or bijective.&lt;/div&gt;
  &lt;/div&gt;
  &lt;iframe src=&quot;/interactives/chapter00/anh_xa.html?lang=en&quot; title=&quot;Interactive: arrow diagram of a map&quot; loading=&quot;lazy&quot; style=&quot;height: 620px;&quot;&gt;&lt;/iframe&gt;
  &lt;div class=&quot;interactive-frame-foot&quot;&gt;
    &lt;a href=&quot;/interactives/chapter00/anh_xa.html?lang=en&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Open the interactive in a new window&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exercise 1.&lt;/strong&gt; Write the real solution set of $|x - 1| \le 3$ in set-builder notation and as an interval.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\{x \in \mathbb{R} : |x - 1| \le 3\} = \{x \in \mathbb{R} : -2 \le x \le 4\} = [-2, 4]$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 2.&lt;/strong&gt; With $A = \{1, 2\}$, $B = \{a, b, c\}$, list $A \times B$. How many elements does it have?&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

$\{(1,a), (1,b), (1,c), (2,a), (2,b), (2,c)\}$, with $2 \cdot 3 = 6$ elements.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 3.&lt;/strong&gt; Which of these maps are injective, surjective, bijective?
(a) $f : \mathbb{R} \to \mathbb{R}$, $f(x) = x^3$.
(b) $g : \mathbb{R}^2 \to \mathbb{R}^2$, $g(x_1, x_2) = (x_1 + x_2,\ x_1 - x_2)$.
(c) $h : \mathbb{R} \to \mathbb{R}^2$, $h(t) = (t, 2t)$.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

(a) Bijective: $x^3 = y$ has exactly one real solution $x = \sqrt[3]{y}$.
(b) Bijective: the system $x_1 + x_2 = y_1$, $x_1 - x_2 = y_2$ has exactly one solution $x_1 = (y_1 + y_2)/2$, $x_2 = (y_1 - y_2)/2$.
(c) Injective but not surjective: the image is only the line $y_2 = 2 y_1$, which does not contain $(1, 0)$.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 4.&lt;/strong&gt; Prove: if $f : X \to Y$ and $g : Y \to Z$ are injective, then $g \circ f$ is injective.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

If $g(f(x_1)) = g(f(x_2))$ then $f(x_1) = f(x_2)$ because $g$ is injective, and then $x_1 = x_2$ because $f$ is injective.

&lt;/details&gt;

&lt;p&gt;&lt;strong&gt;Exercise 5 (advanced).&lt;/strong&gt; On $\mathbb{R}^2$, let $u \sim v$ if $u - v$ lies on the line $L = \{t(1, 1) : t \in \mathbb{R}\}$. Prove that $\sim$ is an equivalence relation and describe its classes geometrically.&lt;/p&gt;

&lt;details&gt;
&lt;summary&gt;Answer&lt;/summary&gt;

Reflexive: $u - u = 0 \in L$. Symmetric: if $u - v = t(1,1)$ then $v - u = (-t)(1,1)$. Transitive: $(u - v) + (v - w) = (t + s)(1,1)$. The class of $u$ is $u + L$, the line through $u$ parallel to $L$. The classes are the lines parallel to $L$; this is a first example of a &quot;quotient space&quot;.

&lt;/details&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;div class=&quot;content-box summary-box textbook-block&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Sets are written by listing or as $\{x \in S : \dots\}$; prove $A = B$ by the two inclusions $A \subseteq B$, $B \subseteq A$.&lt;/li&gt;
    &lt;li&gt;$\mathbb{R}^n$ is the Cartesian product of $n$ copies of $\mathbb{R}$.&lt;/li&gt;
    &lt;li&gt;Injective: $f(x) = y$ has at most one solution; surjective: at least one; bijective: exactly one, which is equivalent to having an inverse.&lt;/li&gt;
    &lt;li&gt;An equivalence relation (reflexive, symmetric, transitive) splits a set into disjoint classes.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>reference</title>
   <link href="https://linear-algebra-self-learning.pages.dev/reference/26_reference/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/reference/26_reference</id>
   <content type="html">&lt;h1 id=&quot;tài-liệu-tham-khảo&quot;&gt;Tài liệu tham khảo&lt;/h1&gt;

&lt;h2 id=&quot;giáo-trình&quot;&gt;Giáo trình&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Gilbert Strang, &lt;em&gt;Introduction to Linear Algebra&lt;/em&gt;, 5th ed., Wellesley–Cambridge Press.&lt;/li&gt;
  &lt;li&gt;David C. Lay, Steven R. Lay, Judi J. McDonald, &lt;em&gt;Linear Algebra and Its Applications&lt;/em&gt;, Pearson.&lt;/li&gt;
  &lt;li&gt;Sheldon Axler, &lt;em&gt;Linear Algebra Done Right&lt;/em&gt;, Springer.&lt;/li&gt;
  &lt;li&gt;Stephen Boyd, Lieven Vandenberghe, &lt;em&gt;Introduction to Applied Linear Algebra&lt;/em&gt;, Cambridge University Press.&lt;/li&gt;
  &lt;li&gt;Lloyd N. Trefethen, David Bau III, &lt;em&gt;Numerical Linear Algebra&lt;/em&gt;, SIAM.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;video&quot;&gt;Video&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Grant Sanderson (3Blue1Brown), &lt;em&gt;Essence of linear algebra&lt;/em&gt; (tiếng Anh).&lt;/li&gt;
  &lt;li&gt;Gilbert Strang, &lt;em&gt;18.06 Linear Algebra&lt;/em&gt;, MIT OpenCourseWare (tiếng Anh).&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>introduction</title>
   <link href="https://linear-algebra-self-learning.pages.dev/home/introduction/"/>
   <updated>2021-01-20T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/home/introduction</id>
   <content type="html">&lt;h1 id=&quot;tự-học-đại-số-tuyến-tính&quot;&gt;Tự học Đại số tuyến tính&lt;/h1&gt;

&lt;p&gt;Khoá học dành cho sinh viên đại học năm thứ nhất và thứ hai các ngành kỹ thuật, công nghệ thông tin và khoa học dữ liệu. Nội dung đi từ vectơ và hệ phương trình tuyến tính đến trị riêng, phân rã giá trị kỳ dị (SVD) và ứng dụng trong đồ hoạ máy tính, chuỗi Markov và học máy.&lt;/p&gt;

&lt;h2 id=&quot;cách-học&quot;&gt;Cách học&lt;/h2&gt;

&lt;p&gt;Mỗi bài có định nghĩa, định lý, chứng minh và ví dụ tính tay. Những chỗ khó hình dung đều có một &lt;strong&gt;Minh hoạ&lt;/strong&gt; tương tác để thay đổi số liệu và quan sát kết quả, và nhiều bài có video ngắn dạng reel giải thích bằng hình động. Cuối mỗi chương có bài tập theo ba mức: cơ bản, vận dụng, nâng cao.&lt;/p&gt;

&lt;h2 id=&quot;cần-biết-trước&quot;&gt;Cần biết trước&lt;/h2&gt;

&lt;p&gt;Đại số trung học phổ thông (hệ phương trình bậc nhất, lượng giác cơ bản) và ký hiệu tập hợp, hàm số. Một số bài ở Chương 09 đến 11 dùng đạo hàm và tích phân cơ bản.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Nội dung khoá học</title>
   <link href="https://linear-algebra-self-learning.pages.dev/home/contents/"/>
   <updated>2021-01-20T00:00:00+00:00</updated>
   <id>https://linear-algebra-self-learning.pages.dev/home/contents</id>
   <content type="html">&lt;h1 id=&quot;nội-dung-khoá-học&quot;&gt;Nội dung khoá học&lt;/h1&gt;

&lt;p&gt;Khoá học gồm 15 chương (Chương 00 đến 14) và khoảng 83 bài, trong đó 8 bài tùy chọn. Mỗi bài có phiên bản tiếng Việt và tiếng Anh. Kế hoạch chi tiết nằm trong tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PLAN.md&lt;/code&gt; của kho mã nguồn.&lt;/p&gt;

&lt;h3 id=&quot;chương-0-chuẩn-bị-ngôn-ngữ-và-công-cụ&quot;&gt;Chương 0: Chuẩn bị: ngôn ngữ và công cụ&lt;/h3&gt;

&lt;p&gt;Ký hiệu tập hợp, ánh xạ, số phức và công cụ tính toán dùng xuyên suốt khoá học.&lt;/p&gt;

&lt;h3 id=&quot;chương-1-vectơ&quot;&gt;Chương 1: Vectơ&lt;/h3&gt;

&lt;p&gt;Vectơ trong $\mathbb{R}^n$, tích vô hướng, đường thẳng, mặt phẳng, tổ hợp tuyến tính và độc lập tuyến tính.&lt;/p&gt;

&lt;h3 id=&quot;chương-2-hệ-phương-trình-tuyến-tính-và-khử-gauss&quot;&gt;Chương 2: Hệ phương trình tuyến tính và khử Gauss&lt;/h3&gt;

&lt;p&gt;Biểu diễn hệ dưới dạng $Ax = b$, khử Gauss, hạng, biến tự do và cấu trúc của tập nghiệm.&lt;/p&gt;

&lt;h3 id=&quot;chương-3-ma-trận&quot;&gt;Chương 3: Ma trận&lt;/h3&gt;

&lt;p&gt;Phép toán ma trận, bốn cách nhìn phép nhân, nghịch đảo, phân rã LU và ma trận khối.&lt;/p&gt;

&lt;h3 id=&quot;chương-4-định-thức&quot;&gt;Chương 4: Định thức&lt;/h3&gt;

&lt;p&gt;Định thức qua diện tích và thể tích có dấu, tính chất, khai triển Laplace và quy tắc Cramer.&lt;/p&gt;

&lt;h3 id=&quot;chương-5-không-gian-vectơ&quot;&gt;Chương 5: Không gian vectơ&lt;/h3&gt;

&lt;p&gt;Không gian vectơ trừu tượng, không gian con, cơ sở, số chiều, bốn không gian con cơ bản và đổi cơ sở.&lt;/p&gt;

&lt;h3 id=&quot;chương-6-ánh-xạ-tuyến-tính&quot;&gt;Chương 6: Ánh xạ tuyến tính&lt;/h3&gt;

&lt;p&gt;Ánh xạ tuyến tính, ma trận của ánh xạ, hạt nhân và ảnh, đẳng cấu, đồng dạng và các phép biến đổi hình học.&lt;/p&gt;

&lt;h3 id=&quot;chương-7-không-gian-tích-vô-hướng-và-trực-giao&quot;&gt;Chương 7: Không gian tích vô hướng và trực giao&lt;/h3&gt;

&lt;p&gt;Tích vô hướng tổng quát, chuẩn, trực giao, hình chiếu vuông góc, Gram–Schmidt, QR và ma trận trực giao.&lt;/p&gt;

&lt;h3 id=&quot;chương-8-bình-phương-tối-thiểu&quot;&gt;Chương 8: Bình phương tối thiểu&lt;/h3&gt;

&lt;p&gt;Xấp xỉ nghiệm của hệ vô nghiệm, phương trình chuẩn, hồi quy tuyến tính, QR và ridge.&lt;/p&gt;

&lt;h3 id=&quot;chương-9-trị-riêng-và-chéo-hoá&quot;&gt;Chương 9: Trị riêng và chéo hoá&lt;/h3&gt;

&lt;p&gt;Trị riêng, vectơ riêng, đa thức đặc trưng, chéo hoá, trị riêng phức, lũy thừa ma trận và hệ vi phân tuyến tính.&lt;/p&gt;

&lt;h3 id=&quot;chương-10-ma-trận-đối-xứng-và-dạng-toàn-phương&quot;&gt;Chương 10: Ma trận đối xứng và dạng toàn phương&lt;/h3&gt;

&lt;p&gt;Định lý phổ, chéo hoá trực giao, dạng toàn phương, ma trận xác định dương, Sylvester, Cholesky và thương Rayleigh.&lt;/p&gt;

&lt;h3 id=&quot;chương-11-svd-và-pca&quot;&gt;Chương 11: SVD và PCA&lt;/h3&gt;

&lt;p&gt;Phân rã giá trị kỳ dị, xấp xỉ hạng thấp, giả nghịch đảo và phân tích thành phần chính.&lt;/p&gt;

&lt;h3 id=&quot;chương-12-ứng-dụng-đồ-họa-máy-tính&quot;&gt;Chương 12: Ứng dụng: đồ họa máy tính&lt;/h3&gt;

&lt;p&gt;Toạ độ thuần nhất, phép quay 3D, phép chiếu phối cảnh và chuỗi phép biến đổi.&lt;/p&gt;

&lt;h3 id=&quot;chương-13-ứng-dụng-chuỗi-markov-và-pagerank&quot;&gt;Chương 13: Ứng dụng: chuỗi Markov và PageRank&lt;/h3&gt;

&lt;p&gt;Ma trận chuyển, phân phối dừng, tốc độ hội tụ và thuật toán PageRank.&lt;/p&gt;

&lt;h3 id=&quot;chương-14-ứng-dụng-học-máy&quot;&gt;Chương 14: Ứng dụng: học máy&lt;/h3&gt;

&lt;p&gt;Ma trận dữ liệu, độ tương tự cosin, hồi quy dạng ma trận, lớp mạng nơ-ron, phân rã ma trận cho hệ gợi ý và tensor.&lt;/p&gt;

&lt;h2 id=&quot;giáo-trình-chính&quot;&gt;Giáo trình chính&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Gilbert Strang, &lt;em&gt;Introduction to Linear Algebra&lt;/em&gt;, 5th ed., Wellesley–Cambridge Press.&lt;/li&gt;
  &lt;li&gt;David C. Lay, Steven R. Lay, Judi J. McDonald, &lt;em&gt;Linear Algebra and Its Applications&lt;/em&gt;, Pearson.&lt;/li&gt;
  &lt;li&gt;Sheldon Axler, &lt;em&gt;Linear Algebra Done Right&lt;/em&gt;, Springer.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;tài-liệu-bổ-sung&quot;&gt;Tài liệu bổ sung&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Stephen Boyd, Lieven Vandenberghe, &lt;em&gt;Introduction to Applied Linear Algebra: Vectors, Matrices, and Least Squares&lt;/em&gt;, Cambridge University Press.&lt;/li&gt;
  &lt;li&gt;Lloyd N. Trefethen, David Bau III, &lt;em&gt;Numerical Linear Algebra&lt;/em&gt;, SIAM.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 

</feed>
