Skip to content

Commit 2a203ab

Browse files
authored
Add files via upload
1 parent 3cc1c5b commit 2a203ab

File tree

3 files changed

+415
-0
lines changed

3 files changed

+415
-0
lines changed

LA_01_04_01.ipynb

+205
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "f04dd603-a2d1-48ce-8c17-9f1dba8de1ee",
6+
"metadata": {},
7+
"source": [
8+
"Chapter 01\n",
9+
"\n",
10+
"# 标量乘法\n",
11+
"《线性代数》 | 鸢尾花书:数学不难"
12+
]
13+
},
14+
{
15+
"cell_type": "markdown",
16+
"id": "ccafb456-2453-4c82-8a65-b1963a370cb2",
17+
"metadata": {},
18+
"source": [
19+
"这段代码的主要目的是演示**标量乘法**(scalar multiplication)在向量上的作用。具体来说,它定义了一个二维向量,并将其与标量相乘,以观察向量的变化情况。\n",
20+
"\n",
21+
"---\n",
22+
"\n",
23+
"### **数学描述**\n",
24+
"\n",
25+
"1. **初始化向量** \n",
26+
" 代码定义了一个二维向量 $a$:\n",
27+
" $$\n",
28+
" \\mathbf{a} = \\begin{bmatrix} 2 \\\\ 1 \\end{bmatrix}\n",
29+
" $$\n",
30+
" 这个向量在二维平面上指向 $(2,1)$ 这个点。\n",
31+
"\n",
32+
"2. **标量乘法** \n",
33+
" 代码定义了一个标量 $k = -2$,然后计算向量 $\\mathbf{a}$ 与标量 $k$ 的乘积:\n",
34+
" $$\n",
35+
" k \\mathbf{a} = (-2) \\cdot \\begin{bmatrix} 2 \\\\ 1 \\end{bmatrix}\n",
36+
" = \\begin{bmatrix} -4 \\\\ -2 \\end{bmatrix}\n",
37+
" $$\n",
38+
" 这个运算的几何意义是**将原向量沿其方向缩放,并翻转方向**:\n",
39+
" - 由于 $|k| = 2$,新向量的长度是原向量的 $2$ 倍,即:\n",
40+
" $$\n",
41+
" \\| k\\mathbf{a} \\| = |k| \\cdot \\|\\mathbf{a}\\| = 2 \\|\\mathbf{a}\\|\n",
42+
" $$\n",
43+
" - 由于 $k$ 是负数,新向量的方向与 $\\mathbf{a}$ **相反**。\n",
44+
"\n",
45+
"3. **结论** \n",
46+
" 计算结果是向量:\n",
47+
" $$\n",
48+
" \\mathbf{a'} = \\begin{bmatrix} -4 \\\\ -2 \\end{bmatrix}\n",
49+
" $$\n",
50+
" 这个向量与原向量 $\\mathbf{a}$ **共线**(collinear),但方向相反,且长度是原向量的两倍。\n",
51+
"\n",
52+
"---\n",
53+
"\n",
54+
"### **总结**\n",
55+
"- 标量乘法会**改变向量的长度**(当 $|k| \\neq 1$ 时)。\n",
56+
"- 若 $k > 0$,向量方向不变;若 $k < 0$,向量方向翻转。\n",
57+
"- 计算后的向量始终与原向量**共线**。"
58+
]
59+
},
60+
{
61+
"cell_type": "markdown",
62+
"id": "27f1d742-511b-4ddb-beca-ff9ced2a9a0e",
63+
"metadata": {},
64+
"source": [
65+
"## 初始化"
66+
]
67+
},
68+
{
69+
"cell_type": "code",
70+
"execution_count": 3,
71+
"id": "6abc03f3-e5ad-44cc-a780-3e91b400e6c6",
72+
"metadata": {},
73+
"outputs": [],
74+
"source": [
75+
"import numpy as np"
76+
]
77+
},
78+
{
79+
"cell_type": "markdown",
80+
"id": "ad5dd6c9-99ef-4c96-afdd-91d97e5a6243",
81+
"metadata": {},
82+
"source": [
83+
"## 定义向量"
84+
]
85+
},
86+
{
87+
"cell_type": "code",
88+
"execution_count": 9,
89+
"id": "ebb78725-794d-408e-b63d-ca88e55ffb45",
90+
"metadata": {},
91+
"outputs": [],
92+
"source": [
93+
"a_vec = np.array([3, 4])"
94+
]
95+
},
96+
{
97+
"cell_type": "code",
98+
"execution_count": 10,
99+
"id": "adbe91b7-d5ec-492e-89de-2bbf2b5ccfda",
100+
"metadata": {},
101+
"outputs": [
102+
{
103+
"data": {
104+
"text/plain": [
105+
"5.0"
106+
]
107+
},
108+
"execution_count": 10,
109+
"metadata": {},
110+
"output_type": "execute_result"
111+
}
112+
],
113+
"source": [
114+
"np.linalg.norm(a_vec)"
115+
]
116+
},
117+
{
118+
"cell_type": "markdown",
119+
"id": "1431be92-8111-499f-9c85-2caf2dc1a351",
120+
"metadata": {},
121+
"source": [
122+
"## 标量乘法"
123+
]
124+
},
125+
{
126+
"cell_type": "code",
127+
"execution_count": 11,
128+
"id": "ff697021-6f3b-42f2-be08-6d5ac68b8ac5",
129+
"metadata": {},
130+
"outputs": [
131+
{
132+
"data": {
133+
"text/plain": [
134+
"array([-6, -8])"
135+
]
136+
},
137+
"execution_count": 11,
138+
"metadata": {},
139+
"output_type": "execute_result"
140+
}
141+
],
142+
"source": [
143+
"k = -2\n",
144+
"k_a_vec = k * a_vec\n",
145+
"k_a_vec"
146+
]
147+
},
148+
{
149+
"cell_type": "code",
150+
"execution_count": 12,
151+
"id": "954b7525-dcef-47cb-af13-40c741ca3891",
152+
"metadata": {},
153+
"outputs": [
154+
{
155+
"data": {
156+
"text/plain": [
157+
"10.0"
158+
]
159+
},
160+
"execution_count": 12,
161+
"metadata": {},
162+
"output_type": "execute_result"
163+
}
164+
],
165+
"source": [
166+
"np.linalg.norm(k_a_vec)"
167+
]
168+
},
169+
{
170+
"cell_type": "markdown",
171+
"id": "58ded0f4-b0b4-41ad-8a8a-521956853916",
172+
"metadata": {},
173+
"source": [
174+
"作者\t**生姜DrGinger** \n",
175+
"脚本\t**生姜DrGinger** \n",
176+
"视频\t**崔崔CuiCui** \n",
177+
"开源资源\t[**GitHub**](https://github.com/Visualize-ML) \n",
178+
"平台\t[**油管**](https://www.youtube.com/@DrGinger_Jiang)\t\t\n",
179+
"\t\t[**iris小课堂**](https://space.bilibili.com/3546865719052873)\t\t\n",
180+
"\t\t[**生姜DrGinger**](https://space.bilibili.com/513194466) "
181+
]
182+
}
183+
],
184+
"metadata": {
185+
"kernelspec": {
186+
"display_name": "Python [conda env:base] *",
187+
"language": "python",
188+
"name": "conda-base-py"
189+
},
190+
"language_info": {
191+
"codemirror_mode": {
192+
"name": "ipython",
193+
"version": 3
194+
},
195+
"file_extension": ".py",
196+
"mimetype": "text/x-python",
197+
"name": "python",
198+
"nbconvert_exporter": "python",
199+
"pygments_lexer": "ipython3",
200+
"version": "3.12.7"
201+
}
202+
},
203+
"nbformat": 4,
204+
"nbformat_minor": 5
205+
}

0 commit comments

Comments
 (0)