-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.xml
546 lines (263 loc) · 216 KB
/
search.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title>【玩转Docker】Docker替代Anaconda进行Python开发</title>
<link href="/posts/782176d8/"/>
<url>/posts/782176d8/</url>
<content type="html"><![CDATA[<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/hint.css/2.4.1/hint.min.css"><p>Python开发者常用Anaconda或者venv等虚拟环境进行包管理和环境隔离,而我发现了有一个更优秀的虚拟隔离手段,那就是著名的Docker。它提供了优秀的环境隔离性,尽最大可能避免了在本机可以运行,但是他人机器就无法运行的问题。另外选择Docker替代Anaconda的原因是,Docker拥有如下的优点:</p><ul><li>在Docker中的同一操作系统上使用一致、易于重现的工具链进行开发。</li><li>在不同的独立开发环境之间快速切换并安全地进行更新,而不必担心影响个人的本地计算机环境。</li><li>使新的团队成员/贡献者可以轻松地在一致的开发环境中启动和运行。在不影响本地设置的情况下尝试新技术或克隆代码库副本。</li></ul><p>并且,Vs Code提供了优秀的容器插件 - <code>Remote-Containers</code> ,同 <code>Remote - SSH</code> 插件效果类似。使用 VS Code 就可以虽然在容器中开发,但是似乎一切都在个人机器上本地运行一样无感。</p><h2 id="一、安装">一、安装</h2><h3 id="1-Docker安装">1. Docker安装</h3><p>参加我之前的博客:</p><div class="tag link"><a class="link-card" title="【玩转 Docker】Docker 和 docker-compose 多平台安装" href="https://cyicz123.top/posts/4d01e9bf/"><div class="left"><img src="https://image.cyicz123.top/i/2022/06/02/louztr-0.png"/></div><div class="right"><p class="text">【玩转 Docker】Docker 和 docker-compose 多平台安装</p><p class="url">https://cyicz123.top/posts/4d01e9bf/</p></div></a></div><h3 id="2-VS-Code插件安装">2. VS Code插件安装</h3><p>插件商店搜索<code>Remote-Containers</code> ,下载安装。</p><h2 id="二、Python开发">二、Python开发</h2><h3 id="1-创建Docker开发容器">1. 创建Docker开发容器</h3><p>可以在 <a href="https://hub.docker.com">docker hub</a> 搜索Python,然后挑选符合需求的基础镜像,例如我需要基于Debian的Python3.9,我可以在Python的官方仓库里搜索3.9,就可以看到Debian和3.9的版本的Docker镜像标签 - <code>3.9.14-slim-buster</code><br><img src="https://image.cyicz123.top/i/2022/10/12/123xmf9.png" alt="搜索Python"><br><img src="https://image.cyicz123.top/i/2022/10/12/12700pm.png" alt="3.9.14-slim-buster"><br>然后打开vscode,并且快捷键 <code>ctrl + ~</code> 打开终端,输入如下命令</p><figure class="highlight docker"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker <span class="keyword">run</span><span class="language-bash"> -it --name 容器名 -v 项目路径:/root/项目名 python:3.9.14-slim-buster /bin/bash</span></span><br></pre></td></tr></table></figure><details class="folding-tag" cyan><summary> 命令参数解析 </summary> <div class='content'> <ul><li><code>-it</code>: 这是两个参数,一个是 <code>-i</code>:交互式操作,一个是 <code>-t</code> 终端。如果需要交互式终端,就需要带<code>-it</code>参数。<sup id="fnref:1"><a href="#fn:1" rel="footnote"><span class="hint--top hint--error hint--medium hint--rounded hint--bounce" aria-label="[Docker - 从入门到实践](https://yeasy.gitbook.io/docker_practice/image/pull)">[1]</span></a></sup></li><li><code>--name 容器名</code>: 将容器名更换为自定义的名称,用来标识创建的容器。</li><li><code>-v 项目路径:/root/项目名</code>: 挂载命令,冒号前面添加 本地机器的项目的绝对路径,冒号后面为挂载到容器内部路径 一般可设置为/root/项目名</li><li><code>/bin/bash</code>: 放在镜像名后的是命令,如果需要交互式 Shell,这里就需要用<code>/bin/bash</code></li></ul><p>如下为示例:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -it --name virtual-env -v /home/abc/Python-<span class="built_in">test</span>:/root/Python-<span class="built_in">test</span> python:3.9.14-slim-buster /bin/bash</span><br></pre></td></tr></table></figure> </div> </details><h3 id="2-VS-Code连接上容器">2. VS Code连接上容器</h3><p>正如<code>Remote - SSH</code>插件一样的操作,<code>Remote - Containers</code> 连接容器只需要点击侧边栏小显示器图标,下拉框选择containers后,在选择刚刚创建的对应的容器。<br><img src="https://image.cyicz123.top/i/2022/10/14/11bto7v.png" alt="连接容器"></p><h3 id="3-VS-Code开发">3. VS Code开发</h3><p>打开容器内,第一步中挂载的文件夹<br><img src="https://image.cyicz123.top/i/2022/10/14/121gr6i.png" alt="打开项目"><br>也可以正常安装相关插件,和用<code>apt update && apt install 相关软件包</code>,或者<code>pip installl 相关软件包</code></p><p>关闭VS Code后,只要不手动删除相关容器,下次再打开此容器,仍然存在相关环境。另外,无论是否删除相关容器,容器内开发的项目都保存在本地,因为容器内的项目文件夹是从本地机器挂载进去的。</p><div id="footnotes"><hr><div id="footnotelist"><ol style="list-style: none; padding-left: 0; margin-left: 40px"><li id="fn:1"><span style="display: inline-block; vertical-align: top; padding-right: 10px; margin-left: -40px">1.</span><span style="display: inline-block; vertical-align: top; margin-left: 10px;"><a href="https://yeasy.gitbook.io/docker_practice/image/pull">Docker - 从入门到实践</a><a href="#fnref:1" rev="footnote"> ↩</a></span></li></ol></div></div>]]></content>
<categories>
<category> 玩转Docker </category>
</categories>
<tags>
<tag> Docker </tag>
<tag> 玩转Docker </tag>
<tag> Python </tag>
<tag> Anaconda </tag>
</tags>
</entry>
<entry>
<title>千字深入浅出C语言指针</title>
<link href="/posts/66e43908/"/>
<url>/posts/66e43908/</url>
<content type="html"><![CDATA[<p>网络中的指针教学或者详解,多是直接从语法或者用法角度讲解,再辅以比喻。这种讲解我觉得不够深入,让新人学了仍然不知道其原理。还有些教程深入计算机底层去讲解指针,又让我觉得不够通俗易懂。因此,我决定自己也写一篇关于指针的讲解,希望做到深入浅出让新人一看就懂。<br><img src="https://image.cyicz123.top/i/2022/08/06/nixn2j.png" alt=""></p><h2 id="一、什么是指针">一、什么是指针</h2><p>指针的语法非常简单,就是如下所示:</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">char</span>* point; <span class="comment">//声明一个变量名为point的指针变量</span></span><br><span class="line">point = (<span class="type">char</span>*)<span class="built_in">malloc</span>(<span class="number">8</span>*<span class="keyword">sizeof</span>(<span class="type">char</span>)); <span class="comment">//申请一个长度为16个字节的空间给point</span></span><br><span class="line"><span class="built_in">free</span>(point); <span class="comment">//释放刚刚申请的空间</span></span><br></pre></td></tr></table></figure><p>可能大家很疑惑,这样一通操作有啥用呢?我先讲此番代码,计算机是怎么处理的。再讲解有什么用。</p><h3 id="1-1-变量在计算机中的存储">1.1 变量在计算机中的存储</h3><p>首先我们可以将计算机抽象为一个CPU和一个长长的字节数组(就是内存或者硬盘)。如果学过C语言数组的朋友应该知道数组要取某个位置的元素,就要用该元素的下标来取出此元素值。</p><p>计算机也是如此取出变量中所存储的元素值的,步骤为:</p><ol><li><p>在计算机眼中,每一个变量名都对应一个计算机中独一无二的地址,此地址实际就是字节数组的下标。</p></li><li><p>CPU根据下标找到字节数组相应位置的字节。</p></li><li><p>根据变量的类型,从(2)中找到的字节开始,连续读取若干个字节,这些连续字节组成的值就是变量存储的元素值。<br><img src="https://image.cyicz123.top/i/2022/08/06/p268yx.png" alt="图一 计算机变量存储结构"><br>举个例子,例如我们声明了一个变量a,那么编译的时候,计算机就知道了变量名a所对应的地址为0,它的类型为int类型。当计算机需要取用变量a时,CPU就会去找到字节数组0号位置,因为int类型的长度为4个字节,所以CPU会从0开始连续取四个字节。这四个字节组合在一起就是一个int类型的数。</p></li></ol><p>如上,我解释了变量的结构,以及计算机是如何去读取变量中的元素值的过程。接下来,我来讲解指针。</p><h3 id="1-2-图解指针">1.2 图解指针</h3><p>指针顾名思义就是一根针指向一个目标。这里的目标就是一块元素的首地址。例如,</p><p>我用如下代码,声明了一个指针变量point。</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">char</span>* point;</span><br></pre></td></tr></table></figure><p>在代码编译后,如下图二,此变量被分到起始地址为5,长度为4的地方。至于为什么所有指针长度都为4个字节,我待会再讲。<br><img src="https://image.cyicz123.top/i/2022/08/06/pgd7gb.png" alt="图二"><br>此时变量point里面什么元素值都没有存放。然后我申请了一块空间,将它的首地址赋值给point,即将首地址存入指针变量point中。</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">point = (<span class="type">char</span>*)<span class="built_in">malloc</span>(<span class="number">8</span>);</span><br></pre></td></tr></table></figure><p>如下图三<br><img src="https://image.cyicz123.top/i/2022/08/06/pk2hnz.png" alt="图三"><br>此时,申请的地址空间长度为8个字节,首地址为9,所以point中存放的元素值为9。</p><p>这样我们就能用point[数组下标]来赋值或者读取相应位置的元素值。例如</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">point[<span class="number">0</span>] = <span class="string">'L'</span>;</span><br><span class="line">point[<span class="number">1</span>] = <span class="string">'o'</span>;</span><br><span class="line">point[<span class="number">2</span>] = <span class="string">'v'</span>;</span><br><span class="line">......</span><br><span class="line">point[<span class="number">7</span>] = <span class="string">'\0'</span>;</span><br></pre></td></tr></table></figure><p><img src="https://image.cyicz123.top/i/2022/08/06/po9g1p.png" alt="图四"><br>计算机读取point[1]的流程如下:</p><ol><li>已经知道point对应的位置是字节数组5号位置,计算机读取5~8四个字节,得到元素值为9。</li><li>到字节数组9号位置,又知道偏移为1,类型为char,char类型长度为1个字节。所以计算机从9号位置往右移1个字节。</li><li>取到字节数组10号位置中的元素值o。</li></ol><h3 id="1-3-通过原理理解语法">1.3 通过原理理解语法</h3><p>在上文中提到指针的语法大概就下面三行代码。</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">char</span>* point; <span class="comment">//声明一个变量名为point的指针变量</span></span><br><span class="line">point = (<span class="type">char</span>*)<span class="built_in">malloc</span>(<span class="number">8</span>*<span class="keyword">sizeof</span>(<span class="type">char</span>)); <span class="comment">//申请一个长度为16个字节的空间给point</span></span><br><span class="line"><span class="built_in">free</span>(point); <span class="comment">//释放刚刚申请的空间</span></span><br></pre></td></tr></table></figure><p>根据1.2我们知道,指针也是一种变量。而变量的C语言代码流程为**<em>声明+使用</em>**。而指针变量自然一样。</p><h3 id="1-3-1-指针变量声明">1.3.1 指针变量声明</h3><p>变量声明方式为_<strong>类型名+变量名</strong><em>。指针变量也一样,指针变量的<strong>类型名</strong>就是它要指向的</em><strong>数据类型+</strong>*_,例如字符型指针变量声明方式为:</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">char</span>* point; <span class="comment">//字符类型char + * + 变量名point</span></span><br></pre></td></tr></table></figure><h3 id="1-3-2-指针变量使用">1.3.2 指针变量使用</h3><p>变量使用方式一般为**<em>变量名 = 元素值</em>**。例如</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">char</span> a;</span><br><span class="line">a = <span class="string">'a'</span>;</span><br></pre></td></tr></table></figure><p>指针变量也一样,只不过指针变量的值一般都是通过malloc函数返回,通过&取地址或者赋值数组地址,例如</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">char</span>* a;</span><br><span class="line"><span class="comment">// malloc函数返回赋值</span></span><br><span class="line">a = (<span class="type">char</span>*)<span class="built_in">malloc</span>(<span class="number">8</span>); <span class="comment">//申请一个8个字节的空间,返回值通过强制类型转换为字符型指针变量类型(char*),然后赋值给a</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// &取地址</span></span><br><span class="line"><span class="type">char</span> b = <span class="string">'b'</span>;</span><br><span class="line">a = &b; <span class="comment">//这样a中存储着b的地址</span></span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"%c"</span>, *a); <span class="comment">//通过指针变量名前面+ *号,来取值。例如*a</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 数组地址</span></span><br><span class="line"><span class="type">char</span> b[<span class="number">8</span>] = <span class="string">"LoveAMR"</span>;</span><br><span class="line">a = b; <span class="comment">//将数组b的首地址赋值给指针变量a </span></span><br></pre></td></tr></table></figure><h3 id="1-4-一些细节">1.4 一些细节</h3><h3 id="细节一-为什么所有指针的长度都是4个字节">细节一 为什么所有指针的长度都是4个字节</h3><p>上文已经讲了指针就是一个变量,它里面存放的值是它指向元素的<strong>首地址。<strong>所以概括就是</strong>指针变量</strong>中存放的值为<strong>字节数组的序号。<strong>而一个</strong>32位</strong>的计算机虚拟内存(即本文抽象出来的名称-<strong>字节数组</strong>)长度为<strong>4GB</strong>,即2的32次方。</p><p>这代表着用最多32位二进制比特就能表示字节数组中的所有序号。而一字节等于八比特,所以任何指针变量的长度都为4字节。</p><h3 id="细节二-为什么有些变量计算机直接知道它的地址,而有些又需要指针指向其首地址?">细节二 为什么有些变量计算机直接知道它的地址,而有些又需要指针指向其首地址?</h3><p>一个可执行程序exe在运行的时候,变量主要分两块区域存储。一块叫做<strong>栈</strong>,这一块部分存储那些在代码中就声明和使用了的变量,例如:</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">char</span> a[<span class="number">10</span>];</span><br><span class="line"><span class="type">int</span> b;</span><br></pre></td></tr></table></figure><p>这些变量或者数组大小在编译时就可以确定。如上的字符数组a,字符型变量长度1个字节,数组长度为10。所以计算机编译代码时,就直接在栈中划分了一个10个字节的区域给数组a。int型变量b,int类型长度为4个字节,所以编译时直接在栈中划分出4个字节的区域给它。</p><p>而像malloc这个函数开辟的空间都是代码编译成可执行程序exe,然后在运行过程中执行到了malloc语句所在位置时才会开辟相应的空间。而这种程序运行时才会动态分配空间的地方叫做<strong>堆。</strong></p><h3 id="细节三-使用指针最常见的问题内存泄漏到底是什么?">细节三 使用指针最常见的问题内存泄漏到底是什么?</h3><p>上面讲了,程序运行时使用malloc从堆中动态开辟空间。这些空间是向操作系统借的,存放在指针中。如果你这个指针中的地址值非但没用free语句归还,反而有用malloc语句又借了一块新空间,新空间的首地址存放在此指针变量中,覆盖了原先的值。那么原先空间的首地址就丢失了,这样想还给操作系统都没办法了。</p><p>具体表现就是,随着程序不断地运行,占用的内存越来越高,直到达到计算机内存的上限,造成操作系统的崩溃。</p><p>用一个比喻就是,你租仓库,仓库管理员给了你一个仓库地址,归还仓库的时候也要用这个地址。于是,你用一张纸记录此地址。紧接着,你又租了一个仓库,既没有归还旧仓库,又很愚蠢的擦掉纸上旧仓库的地址,写上新仓库的。因此你彻底丧失了归还旧仓库的地址。</p><p>而你还在不停的借新仓库,不归还旧仓库。最终达到仓库总量。造成了仓库管理员的崩溃。</p><h2 id="二、指针的实战用法">二、指针的实战用法</h2><p>埋坑……</p>]]></content>
<categories>
<category> C语言 </category>
</categories>
<tags>
<tag> C语言 </tag>
</tags>
</entry>
<entry>
<title>【玩转docker】反向代理神器:Nginx Proxy Manager</title>
<link href="/posts/1ff9cff3/"/>
<url>/posts/1ff9cff3/</url>
<content type="html"><![CDATA[<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/hint.css/2.4.1/hint.min.css"><h2 id="一、什么是反向代理?">一、什么是反向代理?</h2><p>众所周知,浏览器访问网页需要<code>域名:端口号</code> 或者<code>ip:端口号</code> 这种形式,而当你访问页面时不输入端口号时,浏览器会根据<code>http</code>协议或者<code>https</code>协议,自动在后面加上默认端口号<code>80</code>或者<code>443</code> 。</p><p>但是我这种小白使用服务器搭建服务时,一个服务器上往往有多种web服务。端口又不能复用,所以其他服务都是需要<code>域名:端口号</code> 或者<code>ip:端口号</code> 这种形式来访问。于是,我就有一个疑问了,能不能用不同的域名来对应不同的服务呢。</p><p>那这就是反向代理的作用了。</p><p>反向代理类似于一个菜鸟驿站。邮局(互联网)对于地址(域名)是每个咱们小区(服务器)的包裹(数据报文)都直接发给咱们小区的菜鸟驿站(反向代理服务器),然后菜鸟驿站根据每个包裹地址(域名)然后交付给咱们小区的具体家庭(服务器中的每一个服务)。</p><p><img src="https://image.cyicz123.top/i/2022/06/20/sbchy7-0.gif" alt="反向代理作用"></p><p>而Nginx则作为非常有名的反向代理web服务器,被广大站长采用。Nginx功能十分强大,但是配置对于小白来说,还是有一些门槛。那么有没有一款基于Nginx的web管理界面,来设置Nginx的反向代理呢?</p><p>这就是此篇博客要写的神器:Nginx Proxy Manager。</p><h2 id="二、Nginx-Proxy-Manager有什么功能?">二、Nginx Proxy Manager有什么功能?</h2><p>以下是Nginx Proxy Manager的官网介绍<sup id="fnref:1"><a href="#fn:1" rel="footnote"><span class="hint--top hint--error hint--medium hint--rounded hint--bounce" aria-label="[Nginx Proxy Manager官网](https://nginxproxymanager.com/)">[1]</span></a></sup></p><blockquote><p>This project comes as a pre-built docker image that enables you to easily forward to your websites running at home or otherwise, including free SSL, without having to know too much about Nginx or Letsencrypt.</p><p>该项目作为一个预构建的 docker 镜像提供,使您能够轻松地转发到在家里或其他地方运行的网站,包括免费的 SSL,而无需对 Nginx 或 Letsencrypt 有太多了解。</p></blockquote><p>它的功能总结起来就是以下几点:</p><ul><li>轻松的反向代理设置</li><li>轻松配置HTTPS</li><li>提供简单的访问权限设置</li></ul><p>好了,talk is cheap。接下来进入Nginx Proxy Manager一系列实战操作,让我们玩转Nginx Proxy Manager!</p><h2 id="三、Nginx-Proxy-Manager的安装">三、Nginx Proxy Manager的安装</h2><h3 id="1-前提">1. 前提</h3><div class='checkbox checked'><input type="checkbox" checked="checked"/> <p><a href="https://blog.cyicz123.top/docker%E5%AE%89%E8%A3%85/">安装docker和docker-compose</a></p> </div><h3 id="2-安装">2. 安装</h3><p>ssh连接上服务器后,新建一个名为ngingx_proxy_manager的文件夹用来存放文件和数据(最好建一个统一存放各种docker容器应用的目录,例如本人命名为docker文件夹)</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> ~/docker/</span><br><span class="line"><span class="built_in">mkdir</span> ngingx_proxy_manager && <span class="built_in">cd</span> ngingx_proxy_manager</span><br></pre></td></tr></table></figure><p>新建docker-compose.yml文件并复制以下内容</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 编辑文件</span></span><br><span class="line">vim docker-compose.yml</span><br><span class="line"></span><br><span class="line"><span class="comment"># 复制以下内容</span></span><br><span class="line">version: <span class="string">"3"</span></span><br><span class="line">services:</span><br><span class="line"> app:</span><br><span class="line"> image: <span class="string">'jc21/nginx-proxy-manager:latest'</span></span><br><span class="line"> restart: unless-stopped</span><br><span class="line"> ports:</span><br><span class="line"> <span class="comment"># These ports are in format <host-port>:<container-port></span></span><br><span class="line"> - <span class="string">'80:80'</span> <span class="comment"># Public HTTP Port</span></span><br><span class="line"> - <span class="string">'443:443'</span> <span class="comment"># Public HTTPS Port</span></span><br><span class="line"> - <span class="string">'81:81'</span> <span class="comment"># Admin Web Port</span></span><br><span class="line"> <span class="comment"># Add any other Stream port you want to expose</span></span><br><span class="line"> <span class="comment"># - '21:21' # FTP</span></span><br><span class="line"> environment:</span><br><span class="line"> DB_MYSQL_HOST: <span class="string">"db"</span></span><br><span class="line"> DB_MYSQL_PORT: 3306</span><br><span class="line"> DB_MYSQL_USER: <span class="string">"npm"</span></span><br><span class="line"> DB_MYSQL_PASSWORD: <span class="string">"npm"</span></span><br><span class="line"> DB_MYSQL_NAME: <span class="string">"npm"</span></span><br><span class="line"> <span class="comment"># Uncomment this if IPv6 is not enabled on your host</span></span><br><span class="line"> <span class="comment"># DISABLE_IPV6: 'true'</span></span><br><span class="line"> volumes:</span><br><span class="line"> - ./data:/data</span><br><span class="line"> - ./letsencrypt:/etc/letsencrypt</span><br><span class="line"> depends_on:</span><br><span class="line"> - db</span><br><span class="line"></span><br><span class="line"> db:</span><br><span class="line"> image: <span class="string">'jc21/mariadb-aria:latest'</span></span><br><span class="line"> restart: unless-stopped</span><br><span class="line"> environment:</span><br><span class="line"> MYSQL_ROOT_PASSWORD: <span class="string">'npm'</span></span><br><span class="line"> MYSQL_DATABASE: <span class="string">'npm'</span></span><br><span class="line"> MYSQL_USER: <span class="string">'npm'</span></span><br><span class="line"> MYSQL_PASSWORD: <span class="string">'npm'</span></span><br><span class="line"> volumes:</span><br><span class="line"> - ./data/mysql:/var/lib/mysql</span><br></pre></td></tr></table></figure><p>启动服务</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker-compose up -d</span><br></pre></td></tr></table></figure><p>在确保云服务器防火墙已经放行80、81和443端口后即可访问服务器<code>ip:81</code> 进入ngingx_proxy_manager的web管理界面。默认密码为:</p><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">Email:</span> <span class="string">admin@example.com</span></span><br><span class="line"><span class="attr">Password:</span> <span class="string">changeme</span></span><br></pre></td></tr></table></figure><p>输入密码,进入后台后会强制要求更改用户名和密码。</p><h2 id="实战一、设置后台管理界面的反向代理">实战一、设置后台管理界面的反向代理</h2><p>在前文中,已介绍了反向代理的作用,即常见的需求是输入<code>ip:port</code> 形式访问界面太不优雅,并且无法设置https,因此需要用一个域名与此绑定。用户浏览器输入域名,服务器会根据此域名自动转发请求报文到对应绑定的<code>ip:port</code> 服务,然后将响应报文回复给用户。</p><p>这里,我们就用a.test.com来绑定我们的端口号为81的后台管理界面,实现浏览器输入a.test.com即可访问后台管理界面,并且设置HTTPS。</p><h3 id="1-前提-2">1. 前提</h3><div class='checkbox checked'><input type="checkbox" checked="checked"/> <p>安装好Nginx Proxy Manager</p> </div> <div class='checkbox checked'><input type="checkbox" checked="checked"/> <p>拥有一个域名</p> </div><div class='checkbox checked'><input type="checkbox" checked="checked"/> <p>将a.test.com解析到安装Nginx Proxy Manager的服务器ip地址上</p> </div><h3 id="2-反向代理操作">2. 反向代理操作</h3><p>先用<code>ip:81</code> 访问后台管理界面,然后输入账号密码进入后台。</p><p>点击绿色图标的选项</p><p><img src="https://image.cyicz123.top/i/2022/06/20/xhsdwe-0.png" alt="设置反向代理"></p><p>点击右边<code>Add Proxy Host</code> ,在弹出的界面<code>Details</code>选项中填写相应的字段。</p><div class="note info simple"><ul><li>Domain Names: 填写要反向代理的域名,<a href="http://xn--a-ll2b480a6o7bkbc.test.com">这里就是a.test.com</a></li><li>Forward Hostname / IP: 填写的ip值见下文解释👇</li><li>Forward Port: 反向代理的端口,这里就是81</li><li>Block Common Exploits: 开启后阻止一些常见漏洞</li><li>其余两个暂不知作用</li></ul></div><details class="folding-tag" cyan><summary> Forward Hostname / IP填写说明 </summary> <div class='content'> <p>如果搭建的服务和nginx proxy manager服务所在不是一个服务器,则填写能访问对应服务的IP。</p><p>如果都在同一台服务器上,则填写在服务器中输入<code>ip addr show docker0</code> 命令获取得到的ip。</p><p><img src="https://image.cyicz123.top/i/2022/06/20/yr1f0z-0.png" alt="查看宿主机ip"></p><p>这里不填<code>127.0.0.1</code>的原因是使用的是docker容器搭建web应用,docker容器和宿主机即服务器不在同一个网络下,所以<code>127.0.0.1</code> 并不能访问到宿主机,而<code>ip addr show docker0</code> 获得的ip地址就是宿主机地址。</p> </div> </details><p><img src="https://image.cyicz123.top/i/2022/06/20/z4mp9f-0.png" alt="反代设置细节"></p><p>接下来即可用<code>a.test.com</code> 访问后台管理界面,此时还只是http协议,没有https。不过此时就可以把之前的81端口关闭了,输入<code>a.test.com</code> 访问的是服务器<code>80</code>端口,然后在转发给内部的81端口。</p><h3 id="3-申请泛域名ssl证书">3. 申请泛域名ssl证书</h3><p>就是申请一个<code>*.test.com</code> 证书,这样二级域名无论是什么都可以用这个证书,不需要一个二级域名申请一个。</p><p>在Nginx Proxy Manager管理后台,选择<code>Access Lists</code>-><code>Add SSL Certificate</code>-><code>Let's Encrypt</code>选项。</p><p><img src="https://image.cyicz123.top/i/2022/06/20/zb8voj-0.png" alt="SSL管理"></p><p>Domain Names中填写<code>*.test.com</code> <code>test.com</code> ,打开<code>Use a DNS Challenge</code> 选项,并选择个人域名的DNS解析服务商(本人就是腾讯的DNSPod),最后填入服务商提供的api key或者token。</p><details class="folding-tag" cyan><summary> DNSPod的id,key获取教程 </summary> <div class='content'> <ol><li>进入<a href="https://console.dnspod.cn/">DNSPod控制台</a></li><li>步骤直接看图</li></ol><p><img src="https://image.cyicz123.top/i/2022/06/20/zjssm8-0.png" alt="DNSPod密钥管理"></p><ol><li>随便取一个名字后,复制ID和Token到对应位置。</li></ol><p><img src="https://image.cyicz123.top/i/2022/06/20/10fnoog.png" alt="获取密钥"></p> </div> </details><p><img src="https://image.cyicz123.top/i/2022/06/20/zeepll-0.png" alt="SSL全部设置"></p><h3 id="4-设置HTTPS">4. 设置HTTPS</h3><p>进入反向代理设置界面,编辑上文创建的反代服务,选择SSL选项,下拉菜单中选择我们申请的证书,然后可以勾选<code>Force SSL</code>即强制HTTPS。</p><p><img src="https://image.cyicz123.top/i/2022/06/20/zo83wu-0.png" alt="选择相应的证书"></p><p>同理以后新创建的反向代理可以直接在SSL选项中选择我们刚刚申请的泛域名证书。</p><h2 id="实战二、搭建服务器监控并用NPM设置密码访问">实战二、搭建服务器监控并用NPM设置密码访问</h2><p>下面再通过用docker搭建的小而美的服务器监控,来介绍Nginx Proxy Manager添加权限访问的操作。<br><img src="https://image.cyicz123.top/i/2022/06/24/12ngj3t-0.png" alt="ward服务器状态监控界面"></p><h3 id="1-小而美的服务器状态监控:ward">1. 小而美的服务器状态监控:ward</h3><blockquote><p>Ward is a simple and and minimalistic server monitoring tool. Ward supports adaptive design system. Also it supports dark theme. It shows only principal information and can be used, if you want to see nice looking dashboard instead looking on bunch of numbers and graphs. Ward works nice on all popular operating systems, because it uses OSHI.<sup id="fnref:2"><a href="#fn:2" rel="footnote"><span class="hint--top hint--error hint--medium hint--rounded hint--bounce" aria-label="[Ward github](https://github.com/Rudolf-Barbu/Ward)">[2]</span></a></sup></p><p>Ward是一个简单且最低限度的服务器监控工具。Ward支持自适应设计系统。它还支持黑暗主题。如果您想看到漂亮的仪表板,而不是查看一堆数字和图形,那么它只显示主要信息,并且可以使用。Ward在所有流行的操作系统上都运行良好,因为它使用<a href="https://github.com/oshi/oshi">OSHI</a>。</p></blockquote><h3 id="2-前提">2. 前提</h3><div class='checkbox checked'><input type="checkbox" checked="checked"/> <p>安装好Nginx Proxy Manager</p> </div> <div class='checkbox checked'><input type="checkbox" checked="checked"/> <p>拥有一个域名</p> </div><div class='checkbox checked'><input type="checkbox" checked="checked"/> <p>将b.test.com解析到安装Nginx Proxy Manager的服务器ip地址上</p> </div><h3 id="3-安装">3. 安装</h3><p>ssh连接上服务器后,新建一个名为ward的文件夹用来存放文件和数据(最好建一个统一存放各种docker容器应用的目录,例如本人命名为docker文件夹)</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> ~/docker/</span><br><span class="line"><span class="built_in">mkdir</span> ward && <span class="built_in">cd</span> ward</span><br></pre></td></tr></table></figure><p>新建docker-compose.yml文件并复制以下内容</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 编辑文件</span></span><br><span class="line">vim docker-compose.yml</span><br><span class="line"></span><br><span class="line"><span class="comment"># 复制以下内容</span></span><br><span class="line">version: <span class="string">'3.3'</span></span><br><span class="line">services:</span><br><span class="line"> run:</span><br><span class="line"> restart: unless-stopped</span><br><span class="line"> container_name: ward</span><br><span class="line"> ports:</span><br><span class="line"> - <span class="string">'4000:4000'</span> <span class="comment"># 第一个4000表示外部可访问的端口,可修改</span></span><br><span class="line"> environment:</span><br><span class="line"> - WARD_PORT=4000 <span class="comment"># 和上面后一个端口号相同</span></span><br><span class="line"> - WARD_THEME=dark <span class="comment"># 可选light或者dark</span></span><br><span class="line"> - WARD_NAME=leons-server <span class="comment"># 网站名称,可修改</span></span><br><span class="line"> privileged: <span class="literal">true</span></span><br><span class="line"> image: antonyleons/ward</span><br></pre></td></tr></table></figure><p>启动服务</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker-compose up -d</span><br></pre></td></tr></table></figure><h3 id="4-设置反向代理和ssl">4. 设置反向代理和ssl</h3><p>打开Nginx Proxy Manager的管理页面。<br>新建反向代理,<code>Detail</code>如下填写</p><div class="note info simple"><ul><li>Domain Names: 填写要反向代理的域名,<a href="http://xn--b-ll2b480a6o7bkbc.test.com">这里就是b.test.com</a></li><li>Forward Hostname / IP: 填写的ip值见下文解释👇</li><li>Forward Port: 反向代理的端口,这里就是4000</li></ul></div><details class="folding-tag" cyan><summary> Forward Hostname / IP填写说明 </summary> <div class='content'> <p>如果搭建的服务和nginx proxy manager服务所在不是一个服务器,则填写能访问对应服务的IP。</p><p>如果都在同一台服务器上,则填写在服务器中输入<code>ip addr show docker0</code> 命令获取得到的ip。</p><p><img src="https://image.cyicz123.top/i/2022/06/20/yr1f0z-0.png" alt="查看宿主机ip"></p><p>这里不填<code>127.0.0.1</code>的原因是使用的是docker容器搭建web应用,docker容器和宿主机即服务器不在同一个网络下,所以<code>127.0.0.1</code> 并不能访问到宿主机,而<code>ip addr show docker0</code> 获得的ip地址就是宿主机地址。</p> </div> </details><p><img src="https://image.cyicz123.top/i/2022/06/22/zodwi7-0.png" alt="detail设置"><br><code>SSL</code>选项选择自己申请的泛域名证书。<br><img src="https://image.cyicz123.top/i/2022/06/22/zp18qd-0.png" alt="ssl设置"></p><h3 id="5-权限设置">5. 权限设置</h3><p>在Nginx Proxy Manager管理首页,选<code>Access Lists</code>页面->点击<code>Add Access List</code>。</p><p><code>Detail</code>页面</p><div class="note info simple"><ul><li>Name: 这个权限设置的名称</li><li>Satisfy Any: <code>Access</code>选项条件满足任意即可访问</li><li>Pass Auth to Host: 暂不知作用</li></ul></div><p><img src="https://image.cyicz123.top/i/2022/06/22/10lpi3e-0.png" alt="detail设置"></p><p><code>Authorization</code><br>可设置多个账户密码</p><p><code>Access</code><br>可设置ip白、黑名单。</p><p>最后保存即可,然后在设置反向代理界面<code>Details</code>-><code>Access List</code>选择刚刚设置的权限选项。<br><img src="https://image.cyicz123.top/i/2022/06/22/10zk0a1-0.png" alt="权限设置"></p><p>以后想设置权限的都可以选择该权限选项。</p><p>最后效果如下<br><img src="https://image.cyicz123.top/i/2022/06/24/12mf0gm-0.png" alt="权限登陆"></p><div id="footnotes"><hr><div id="footnotelist"><ol style="list-style: none; padding-left: 0; margin-left: 40px"><li id="fn:1"><span style="display: inline-block; vertical-align: top; padding-right: 10px; margin-left: -40px">1.</span><span style="display: inline-block; vertical-align: top; margin-left: 10px;"><a href="https://nginxproxymanager.com/">Nginx Proxy Manager官网</a><a href="#fnref:1" rev="footnote"> ↩</a></span></li><li id="fn:2"><span style="display: inline-block; vertical-align: top; padding-right: 10px; margin-left: -40px">2.</span><span style="display: inline-block; vertical-align: top; margin-left: 10px;"><a href="https://github.com/Rudolf-Barbu/Ward">Ward github</a><a href="#fnref:2" rev="footnote"> ↩</a></span></li></ol></div></div>]]></content>
<categories>
<category> 玩转docker </category>
</categories>
<tags>
<tag> docker </tag>
<tag> 玩转docker </tag>
<tag> 反向代理 </tag>
<tag> nginx </tag>
</tags>
</entry>
<entry>
<title>【玩转docker】docker和docker-compose多平台安装</title>
<link href="/posts/4d01e9bf/"/>
<url>/posts/4d01e9bf/</url>
<content type="html"><![CDATA[<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/hint.css/2.4.1/hint.min.css"><h2 id="Docker介绍">Docker介绍</h2><p>网上有许多对于Docker是什么的介绍,这里我就不多赘述了。我开【玩转docker】系列的原因在于,docker是一个划时代的神器。它能打通开发到部署之间的障碍,真正实现一次开发,处处部署。而中文互联网上似乎很少有成体系的文章博客。因此,我将在【玩转docker】系列中介绍本人用docker搭建服务器部署各种应用,用docker结合wsl替代Linux系统并用vscode开发,在wsl中用docker训练神经网络等等的方法。<br>废话不多说,开始安装docker和docker-compose。</p><h2 id="Ubuntu安装-docker和docker-compose">Ubuntu安装 docker和docker-compose</h2><h3 id="docker安装">docker安装</h3><ul><li>Ubuntu20.04LTS</li><li>阿里云轻量级学生服务器1核2g</li></ul><p>docker安装非常简单,如下命令即可。</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">curl -fsSL get.docker.com -o get-docker.sh</span><br><span class="line">sudo sh get-docker.sh --mirror Aliyun</span><br></pre></td></tr></table></figure><p>执行这个命令后,脚本就会自动的将一切准备工作做好,并且把 Docker 的稳定(stable)版本安装在系统中。</p><p>然后可按照如下折叠块内容配置docker。</p><details class="folding-tag" cyan><summary> docker配置方法 </summary> <div class='content'> <p>启动docker</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">sudo systemctl <span class="built_in">enable</span> docker</span><br><span class="line"></span><br><span class="line">sudo systemctl start docker</span><br></pre></td></tr></table></figure><p>添加docker执行权限</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sudo groupadd docker</span><br><span class="line">sudo usermod -aG docker <span class="variable">$USER</span></span><br></pre></td></tr></table></figure><p>退出终端重新进入即可。</p><p>测试安装是否成功</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">docker run --<span class="built_in">rm</span> hello-world</span><br><span class="line"><span class="comment"># 输出如下字段</span></span><br><span class="line">Unable to find image <span class="string">'hello-world:latest'</span> locally</span><br><span class="line">latest: Pulling from library/hello-world</span><br><span class="line">b8dfde127a29: Pull complete</span><br><span class="line">Digest: sha256:308866a43596e83578c7dfa15e27a73011bdd402185a84c5cd7f32a88b501a24</span><br><span class="line">Status: Downloaded newer image <span class="keyword">for</span> hello-world:latest</span><br><span class="line"></span><br><span class="line">Hello from Docker!</span><br><span class="line">This message shows that your installation appears to be working correctly.</span><br><span class="line"></span><br><span class="line">To generate this message, Docker took the following steps:</span><br><span class="line"> 1. The Docker client contacted the Docker daemon.</span><br><span class="line"> 2. The Docker daemon pulled the <span class="string">"hello-world"</span> image from the Docker Hub.</span><br><span class="line"> (amd64)</span><br><span class="line"> 3. The Docker daemon created a new container from that image <span class="built_in">which</span> runs the</span><br><span class="line"> executable that produces the output you are currently reading.</span><br><span class="line"> 4. The Docker daemon streamed that output to the Docker client, <span class="built_in">which</span> sent it</span><br><span class="line"> to your terminal.</span><br><span class="line"></span><br><span class="line">To try something more ambitious, you can run an Ubuntu container with:</span><br><span class="line"> $ docker run -it ubuntu bash</span><br><span class="line"></span><br><span class="line">Share images, automate workflows, and more with a free Docker ID:</span><br><span class="line"> https://hub.docker.com/</span><br><span class="line"></span><br><span class="line">For more examples and ideas, visit:</span><br><span class="line"> https://docs.docker.com/get-started/</span><br></pre></td></tr></table></figure> </div> </details><h3 id="docker-compose安装">docker-compose安装</h3><p>在 Linux 上的也安装十分简单,从 官方 GitHub Release 处直接下载编译好的二进制文件即可。例如,在 Linux 64 位系统上直接下载对应的二进制包。</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">sudo curl -L https://github.com/docker/compose/releases/download/1.27.4/docker-compose-`<span class="built_in">uname</span> -s`-`<span class="built_in">uname</span> -m` > /usr/local/bin/docker-compose</span><br><span class="line"><span class="comment">## 或者国内用户可以使用以下命令替换上一条命令加快下载</span></span><br><span class="line">sudo curl -L https://download.fastgit.org/docker/compose/releases/download/1.27.4/docker-compose-`<span class="built_in">uname</span> -s`-`<span class="built_in">uname</span> -m` > /usr/local/bin/docker-compose</span><br><span class="line"></span><br><span class="line"><span class="comment">## 然后添加执行权限</span></span><br><span class="line">sudo <span class="built_in">chmod</span> +x /usr/local/bin/docker-compose</span><br></pre></td></tr></table></figure><h4 id="验证">验证</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker-compose --version</span><br><span class="line"><span class="comment">## 输出版本信息即为安装成功</span></span><br></pre></td></tr></table></figure><h2 id="WSL-2安装-docker和docker-compose">WSL 2安装 docker和docker-compose</h2><h3 id="前提">前提</h3><p>在安装之前,必须确认如下步骤是否完成:</p><ul><li>Windows 10 版本 1903 以上或 Windows 11。</li><li>在 Windows 上启用 WSL 2 功能。</li><li>WSL 2 至少有一个 Linux 发行版,如 Ubuntu20.04 LTS。</li><li>下载并安装<a href="https://docs.microsoft.com/zh-cn/windows/wsl/install-manual#step-4---download-the-linux-kernel-update-package">WSL Linux内核更新包</a></li></ul><h3 id="下载-docker-desktop-for-windows">下载 docker desktop for windows</h3><p>下载<a href="https://desktop.docker.com/win/main/amd64/Docker%20Desktop%20Installer.exe?utm_source=docker&utm_medium=webreferral&utm_campaign=dd-smartbutton&utm_location=header">适用于 Windows 的 Docker 桌面</a>。</p><h3 id="安装">安装</h3><p>安装前请务必确认满足上文的安装条件。</p><ol><li>通常点击安装程序一直点击下一步即可。Docker Desktop 会在安装过程中提示启用 WSL 2。阅读屏幕上显示的信息并启用 WSL 2 以继续。</li><li>启动 Docker Desktop。</li><li>点击<code>设置</code>-> <code>General</code>。</li><li>勾选 <code>Use the WSL 2 based engine (Windows Home can only run the WSL 2 backend)</code>(一般情况下,默认是勾选的)。</li><li>点击<code>Apply & Restart</code>。<br><img src="https://image.cyicz123.top/i/2022/06/10/qs1ci5-0.png" alt="Docker Desktop启用 WSL 集成步骤"></li><li>点击<code>Resources</code> -> <code>WSL INTEGRATION</code></li><li>勾选 <code>Enable integration with my default WSL distro</code>,如果安装了多个WSL Linux发行版,也可以打开相应的发行版开关。<br><img src="https://image.cyicz123.top/i/2022/06/10/qxw81m-0.png" alt="启用 WSL 中的 docker 和 docker-compose"></li></ol><p>现在<code>docker</code>和<code>docker-compose</code>都可以在 WSL 2 中使用了。</p><h2 id="树莓派安装docker和docker-compose">树莓派安装docker和docker-compose</h2><h3 id="1-前提">1. 前提</h3><div class='checkbox checked'><input type="checkbox" checked="checked"/> <p><a href="https://www.raspberrypi.com/software/operating-systems/">Raspberry Pi OS 32-bit</a></p> </div> <div class='checkbox checked'><input type="checkbox" checked="checked"/> <p>已经执行了<code>sudo apt update</code></p> </div><h3 id="2-安装docker">2.安装docker</h3><p>执行如下命令即可</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">curl -fsSL get.docker.com -o get-docker.sh</span><br><span class="line"></span><br><span class="line">sudo sh get-docker.sh --mirror Aliyun</span><br></pre></td></tr></table></figure><p>然后可按照如下折叠块内容配置docker。</p><details class="folding-tag" cyan><summary> docker配置方法 </summary> <div class='content'> <p>启动docker</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">sudo systemctl <span class="built_in">enable</span> docker</span><br><span class="line"></span><br><span class="line">sudo systemctl start docker</span><br></pre></td></tr></table></figure><p>添加docker执行权限</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sudo groupadd docker</span><br><span class="line">sudo usermod -aG docker <span class="variable">$USER</span></span><br></pre></td></tr></table></figure><p>退出终端重新进入即可。</p><p>测试安装是否成功</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">docker run --<span class="built_in">rm</span> hello-world</span><br><span class="line"><span class="comment"># 输出如下字段</span></span><br><span class="line">Unable to find image <span class="string">'hello-world:latest'</span> locally</span><br><span class="line">latest: Pulling from library/hello-world</span><br><span class="line">b8dfde127a29: Pull complete</span><br><span class="line">Digest: sha256:308866a43596e83578c7dfa15e27a73011bdd402185a84c5cd7f32a88b501a24</span><br><span class="line">Status: Downloaded newer image <span class="keyword">for</span> hello-world:latest</span><br><span class="line"></span><br><span class="line">Hello from Docker!</span><br><span class="line">This message shows that your installation appears to be working correctly.</span><br><span class="line"></span><br><span class="line">To generate this message, Docker took the following steps:</span><br><span class="line"> 1. The Docker client contacted the Docker daemon.</span><br><span class="line"> 2. The Docker daemon pulled the <span class="string">"hello-world"</span> image from the Docker Hub.</span><br><span class="line"> (amd64)</span><br><span class="line"> 3. The Docker daemon created a new container from that image <span class="built_in">which</span> runs the</span><br><span class="line"> executable that produces the output you are currently reading.</span><br><span class="line"> 4. The Docker daemon streamed that output to the Docker client, <span class="built_in">which</span> sent it</span><br><span class="line"> to your terminal.</span><br><span class="line"></span><br><span class="line">To try something more ambitious, you can run an Ubuntu container with:</span><br><span class="line"> $ docker run -it ubuntu bash</span><br><span class="line"></span><br><span class="line">Share images, automate workflows, and more with a free Docker ID:</span><br><span class="line"> https://hub.docker.com/</span><br><span class="line"></span><br><span class="line">For more examples and ideas, visit:</span><br><span class="line"> https://docs.docker.com/get-started/</span><br></pre></td></tr></table></figure> </div> </details><h3 id="3-安装docker-compose">3. 安装docker-compose</h3><div class='checkbox checked'><input type="checkbox" checked="checked"/> <p>安装好python3</p> </div> <p>使用pip3安装docker-compose</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo pip3 install docker-compose</span><br></pre></td></tr></table></figure><div id="footnotes"><hr><div id="footnotelist"><ol style="list-style: none; padding-left: 0; margin-left: 40px"><li id="fn:1"><span style="display: inline-block; vertical-align: top; padding-right: 10px; margin-left: -40px">1.</span><span style="display: inline-block; vertical-align: top; margin-left: 10px;"><a href="https://yeasy.gitbook.io/docker_practice/install">docker 从入门到实践</a><a href="#fnref:1" rev="footnote"> ↩</a></span></li><li id="fn:2"><span style="display: inline-block; vertical-align: top; padding-right: 10px; margin-left: -40px">2.</span><span style="display: inline-block; vertical-align: top; margin-left: 10px;"><a href="https://docs.docker.com/desktop/windows/wsl/">docker WSL 官网安装教程</a><a href="#fnref:2" rev="footnote"> ↩</a></span></li></ol></div></div>]]></content>
<categories>
<category> 玩转docker </category>
<category> 环境搭建 </category>
</categories>
<tags>
<tag> docker </tag>
<tag> 玩转docker </tag>
<tag> 环境搭建 </tag>
<tag> Win10 </tag>
<tag> Ubuntu </tag>
<tag> Rasbian </tag>
</tags>
</entry>
<entry>
<title>优雅使用谷歌colab的一些小技巧</title>
<link href="/posts/d7ca2ef9/"/>
<url>/posts/d7ca2ef9/</url>
<content type="html"><![CDATA[<p>在学习深度学习过程中,我们往往会苦恼没有好的显卡机器去训练自己的模型。而谷歌提供的高性价比的云gpu服务器Colab很好的解决了这个问题。谷歌服务器拥有如下优缺点:</p><p><strong>优点</strong><br><s>1. 免费(最大的优点)</s></p><ol><li>网络高速,下载环境快</li><li>显卡有k80、t4、p100和v100,付费会员至少是P100</li><li>可以连接google drive</li></ol><p><s><strong>缺点(免费就别嫌弃啦)</strong></s></p><p><s>1. 免费用户只能最多占有服务器12小时</s><br><s>2. 白嫖过度,会只分配k80,不能随心所欲使用</s></p><p>为了更高效率利用<s>免费</s>谷歌高性价比的gpu服务器,所以我写下这篇文章,记录一些方便的技巧去优雅使用Colab。</p><h2 id="一、前提条件">一、前提条件</h2><ol><li>一个google账号</li><li>可以访问google的网络环境</li><li>最好购买pro会员,非常划算(个人毕业论文就是靠Colab训练的)</li></ol><h2 id="二、从零开始申请一个gpu服务器">二、从零开始申请一个gpu服务器</h2><p>打开网址<a href="https://link.zhihu.com/?target=http%3A//drive.google.com/">谷歌云盘</a>后,在+号中点击关联更多应用,添加google colaboratory<br><img src="https://image.cyicz123.top/i/2022/09/28/1222vu1.png" alt=""><br>然后在选项栏中选择Colaboratory进入jupyter的编辑页面<br><img src="https://image.cyicz123.top/i/2022/09/28/128osnt.png" alt="如果右上角红色框的部分显示的是连接,说明还没有分配机器,点击连接即可"></p><h2 id="三、一些使用小技巧">三、一些使用小技巧</h2><p><strong>所有命令需要前面加!</strong></p><h3 id="(一)初始设置"><strong>(一)初始设置</strong></h3><ol><li>占用显存</li></ol><p>一般来说,此时就会分配给你一个gpu服务器。建议先输入以下命令占用1个g的gpu显存,以让谷歌认为你没有滥用分配给你的gpu。</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> torch</span><br><span class="line">a = torch.Tensor([<span class="number">1000</span>, <span class="number">1000</span>, <span class="number">1000</span>]).cuda() <span class="comment"># 大约占用 1.1G 显存</span></span><br></pre></td></tr></table></figure><ol start="2"><li>查看分配给自己的显卡</li></ol><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">!nvidia-smi</span><br><span class="line"><span class="comment"># 输出</span></span><br><span class="line">Tue Jul 13 02:58:23 2021 </span><br><span class="line">+-----------------------------------------------------------------------------+</span><br><span class="line">| NVIDIA-SMI 470.42.01 Driver Version: 460.32.03 CUDA Version: 11.2 |</span><br><span class="line">|-------------------------------+----------------------+----------------------+</span><br><span class="line">| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |</span><br><span class="line">| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |</span><br><span class="line">| | | MIG M. |</span><br><span class="line">|===============================+======================+======================|</span><br><span class="line">| 0 Tesla T4 Off | 00000000:00:04.0 Off | 0 |</span><br><span class="line">| N/A 53C P0 28W / 70W | 1068MiB / 15109MiB | 0% Default |</span><br><span class="line">| | | N/A |</span><br><span class="line">+-------------------------------+----------------------+----------------------+</span><br><span class="line"> </span><br><span class="line">+-----------------------------------------------------------------------------+</span><br><span class="line">| Processes: |</span><br><span class="line">| GPU GI CI PID Type Process name GPU Memory |</span><br><span class="line">| ID ID Usage |</span><br><span class="line">|=============================================================================|</span><br><span class="line">| No running processes found |</span><br><span class="line">+-----------------------------------------------------------------------------+</span><br></pre></td></tr></table></figure><p>可以看到分配给我的显卡是tesla t4,显存大概是15g左右。以下是我在网络中找到的显卡算力图<br><img src="https://image.cyicz123.top/i/2022/09/28/129uix9.png" alt="白嫖用户分配的是t4,白嫖过度后就只给k80或者分配失败。colab pro可以分到v100或者p100"></p><h3 id="(二)训练部分">(二)训练部分</h3><h3 id="1-挂载google-drive">1. 挂载google drive</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> google.colab <span class="keyword">import</span> drive</span><br><span class="line">drive.mount(<span class="string">'/content/drive/'</span>)</span><br></pre></td></tr></table></figure><p>点击出现的链接认证谷歌账号,复制认证后的字符串到输入框内。</p><h3 id="2-更改工作目录">2. 更改工作目录</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> os</span><br><span class="line">os.chdir(<span class="string">"更改后的路径"</span>) </span><br></pre></td></tr></table></figure><p>网上很多教程都是用这个将工作路径更改到自己的google drive云盘下,这样的好处是google grive是每个人自己的云盘,所以在服务器实例关闭后,云盘上的文件都会保存,而服务器上的都会销毁。</p><p>但是有个缺点,colab服务器与google drive的文件通信是通过网络传输的,因此造成I/O速度会慢很多。</p><h3 id="3-google-drive扩容">3. google drive扩容</h3><p>可以通过淘宝或者百度搜索谷歌云盘扩容的方法给自己云盘扩容,用来装训练数据。<br><img src="https://image.cyicz123.top/i/2022/09/28/12bjtz2.png" alt="其中的shareddrives就是无限量的空间,存放训练数据"><br>这种共享空间无限量大小,但是数据不一定安全,可能会被泄露或者丢失。但是训练数据没在乎这些问题,因此正好适合存放训练数据和训练的模型。</p><h3 id="4-移动训练数据">4. 移动训练数据</h3><p>原因我在上文说过,训练数据最好复制一份到服务器里。</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">!<span class="built_in">cp</span> /content/drive/Shareddrives/deeplearning_data/centernet-pytorch.zip /content </span><br><span class="line">!unzip -d /content/centernet</span><br></pre></td></tr></table></figure><p>这里是将我的centernet代码的压缩包复制到服务器里,然后解压缩。</p><h3 id="5-训练记得加断点且将输出路径设置为google-drive"><s>5. 训练记得加断点且将输出路径设置为google drive</s></h3><p><s>假如训练时间久,服务器连接可能就断了。假如没有断点的话,那么训练就白费了。所以需要将输出路径改为google drive的位置(就是把输出路径更改为/content/drive/Shareddrives/deeplearning_data/。这里/content/drive/后面的路径每个人都不相同,自己看着修改吧)</s></p><h3 id="5-将模型训练结果文件夹软链接到google-drive里">5. 将模型训练结果文件夹软链接到google drive里</h3><p>之前保存训练中间文件的方式为手动将代码里的输出路径修改为google drive的路径,不过我发现可以使用软链接实现同样的效果,优点是无需修改源代码</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># !ln -s 'google drive路径' '输出结果路径'</span></span><br><span class="line"><span class="comment"># 如下所示,将yolo v5的训练结果软链接到google drive路径下</span></span><br><span class="line">!<span class="built_in">ln</span> -s /content/drive/MyDrive/yolov5/runs /content/yolov5/runs</span><br></pre></td></tr></table></figure><h3 id="6-开始训练">6. 开始训练</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">!python train.py</span><br></pre></td></tr></table></figure><h3 id="7-防止断连">7. 防止断连</h3><p>方法一</p><p>每60分钟自动运行代码刷新,解除90分钟断开限制. 使用方法:colab页面按下 F12或者 Ctrl+Shift+I (mac按 Option+Command+I) 在console(控制台) 输入以下代码并回车. 复制以下代码粘贴在浏览器console!!不要关闭浏览器以免失效</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">ConnectButton</span>(<span class="params"></span>){</span><br><span class="line"> <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">"Connect pushed"</span>); </span><br><span class="line"> <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">"#connect"</span>).<span class="title function_">click</span>() </span><br><span class="line">}</span><br><span class="line"><span class="built_in">setInterval</span>(<span class="title class_">ConnectButton</span>,<span class="number">60000</span>);</span><br></pre></td></tr></table></figure><p>方法二</p><p>安装浏览器插件Colab Alive<br><img src="https://image.cyicz123.top/i/2022/09/28/12c88qr.png" alt=""></p><h3 id="参考文章">参考文章</h3><ol><li><a href="https://blog.csdn.net/iefenghao/article/details/97956440?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.edu_weight&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.edu_weight">最新英伟达GPU算力评估表格_iefenghao的博客-CSDN博客_gpu算力</a></li><li><a href="https://www.cnblogs.com/smiler/p/7000200.html">gunzip 和 unzip 解压文件到指定的目录</a></li><li><a href="https://link.zhihu.com/?target=https%3A//juejin.cn/post/6972787831907287077">白嫖google gpu服务器 Colab实用教程</a></li><li><a href="https://juejin.cn/post/6972787831907287077">佘城璐:Google Colab 的正确使用姿势634 赞同 · 75 评论文章</a></li><li><a href="https://colab.research.google.com/github/iErics/gd-utils/blob/master/Colab_gd_utils.ipynb">Colab-gd-utils.ipynb</a></li></ol>]]></content>
<categories>
<category> 深度学习 </category>
</categories>
<tags>
<tag> 深度学习 </tag>
<tag> Colab </tag>
<tag> 使用技巧 </tag>
</tags>
</entry>
<entry>
<title>兔子繁衍问题</title>
<link href="/posts/1cfd214e/"/>
<url>/posts/1cfd214e/</url>
<content type="html"><![CDATA[<h2 id="摘要">摘要</h2><p>本文针对兔子繁衍问题分析和研究。主要对<strong>问题一</strong>基础兔子繁衍问题,<strong>问题二</strong>寿命六个月繁衍问题,<strong>问题三</strong>死亡率<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mfrac><mn>1</mn><mn>3</mn></mfrac></mrow><annotation encoding="application/x-tex">\frac{1}{3}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1.1901em;vertical-align:-0.345em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8451em;"><span style="top:-2.655em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">3</span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.394em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.345em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span>繁衍问题展开了一系列递推关系式与模型的建立与计算,得出最终兔子族群数量,并探讨了兔子数量稳定时d的值。</p><p>针对基础兔子繁衍问题,也就是兔子长生不老情况下,本文观察了兔子数目与月份之间关系,利用斐波那契数列公式对其进行了计算与建模,得出结果。</p><p>针对兔子存活期为六个月的繁衍问题,本文基于模型一的基础上计算出了兔子数目与月份之间的递推关系式,并对其进行了计算与建模,得出最终结果。</p><p>针对兔子每个月固定死亡率的情况下的繁衍问题,本文也基于模型一的基础上计算出了每月死亡三分之一的情况下,兔子数目与月份之间的递推关系式,并对其进行了计算与建模,得出最终结果。</p><p>关键词:<strong>递归、斐波拉契数列、矩阵</strong></p><h2 id="一、问题重述">一、问题重述</h2><h3 id="1-1-问题一">1.1 问题一</h3><p>一地区开始时有1000对刚出生的小兔。设兔于出生以后两个月就能生小兔,如果每月每一对兔子恰好生一对小兔,呈出生的兔子都成活,试问一年以后共有多少对兔子,两年后有多少对兔子?</p><h3 id="1-2-问题二">1.2 问题二</h3><p>兔子的寿命只有六个月,那么一年以后共有多少对兔子?两年后呢?</p><h3 id="1-3-问题三">1.3 问题三</h3><p>兔子在每个月均死亡<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mfrac><mn>1</mn><mn>3</mn></mfrac></mrow><annotation encoding="application/x-tex">\frac {1}{3}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1.1901em;vertical-align:-0.345em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8451em;"><span style="top:-2.655em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">3</span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.394em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.345em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span>,求一年后共有多少对兔子</p><h2 id="二、基本假设">二、基本假设</h2><ul><li>假设每一对兔子都每月恰好生一对兔子</li><li>对于问题一,假设没有兔子死亡</li><li>对于问题二,假设兔子都恰好活六个月</li><li>对于问题三,假设兔子每个月恰好都死亡<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mfrac><mn>1</mn><mn>3</mn></mfrac></mrow><annotation encoding="application/x-tex">\frac {1}{3}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1.1901em;vertical-align:-0.345em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8451em;"><span style="top:-2.655em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">3</span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.394em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.345em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></li></ul><h2 id="三、符号说明">三、符号说明</h2><table><thead><tr><th>符号</th><th style="text-align:center">说明</th></tr></thead><tbody><tr><td><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>N</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">N_i</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3117em;"><span style="top:-2.55em;margin-left:-0.109em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span></td><td style="text-align:center">第<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>i</mi></mrow><annotation encoding="application/x-tex">i</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6595em;"></span><span class="mord mathnormal">i</span></span></span></span>个月兔子的数量</td></tr><tr><td><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>y</mi><mo stretchy="false">(</mo><mi>j</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">y(j)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.05724em;">j</span><span class="mclose">)</span></span></span></span></td><td style="text-align:center">第<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>j</mi></mrow><annotation encoding="application/x-tex">j</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.854em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.05724em;">j</span></span></span></span>月出生的小兔对数</td></tr><tr><td><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi><mo stretchy="false">(</mo><mi>j</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">r(j)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.05724em;">j</span><span class="mclose">)</span></span></span></span></td><td style="text-align:center">第<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>j</mi></mrow><annotation encoding="application/x-tex">j</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.854em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.05724em;">j</span></span></span></span>月的小兔对数</td></tr><tr><td><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>x</mi><mi>k</mi></msub><mo stretchy="false">(</mo><mi>t</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">x_k(t)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight" style="margin-right:0.03148em;">k</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord mathnormal">t</span><span class="mclose">)</span></span></span></span></td><td style="text-align:center">第<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>t</mi></mrow><annotation encoding="application/x-tex">t</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6151em;"></span><span class="mord mathnormal">t</span></span></span></span>月寿命为<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>k</mi></mrow><annotation encoding="application/x-tex">k</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal" style="margin-right:0.03148em;">k</span></span></span></span>月的兔子数量</td></tr></tbody></table><h2 id="四、问题分析">四、问题分析</h2><h3 id="4-1-问题一">4.1 问题一</h3><p>先直接推算,在第1月只有1对兔子;第2月也只有一对兔子;在第3月这对兔子生了1对小兔子,共有2对兔子;在第4月,老兔子又生了1对小兔子,共有3对小兔子;在第5个月,老兔子生1对小兔子,且在第3月出生的小兔也生育1对小兔子,故共有5对小兔子,在第6个月,老兔子、在第3、第4月出生的小兔子各生1对小兔子,故共有8对小兔子.类推就可以得到以后各月的数量。</p><p>列表得:</p><table><thead><tr><th>月份</th><th>1</th><th>2</th><th>3</th><th>4</th><th>5</th><th>6</th><th>7</th><th>8</th><th>9</th><th>10</th><th>11</th><th>12</th></tr></thead><tbody><tr><td>total</td><td>1</td><td>1</td><td>2</td><td>3</td><td>5</td><td>8</td><td>13</td><td>21</td><td>34</td><td>55</td><td>89</td><td>144</td></tr></tbody></table><p>可发现兔子对数符合斐波拉契数列:</p><p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi>N</mi><mrow><mi>i</mi><mo>+</mo><mn>1</mn></mrow></msub><mo>=</mo><msub><mi>N</mi><mi>i</mi></msub><mo>+</mo><msub><mi>N</mi><mrow><mi>i</mi><mo>−</mo><mn>1</mn></mrow></msub></mrow><annotation encoding="application/x-tex">N_{i+1}=N_i+N_{i-1} </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8917em;vertical-align:-0.2083em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3117em;"><span style="top:-2.55em;margin-left:-0.109em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">i</span><span class="mbin mtight">+</span><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.2083em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3117em;"><span style="top:-2.55em;margin-left:-0.109em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:0.8917em;vertical-align:-0.2083em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3117em;"><span style="top:-2.55em;margin-left:-0.109em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">i</span><span class="mbin mtight">−</span><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.2083em;"><span></span></span></span></span></span></span></span></span></span></span></p><h3 id="4-2-问题二">4.2 问题二</h3><table><thead><tr><th>月份</th><th>1</th><th>2</th><th>3</th><th>4</th><th>5</th><th>6</th><th>7</th><th>8</th><th>9</th><th>10</th><th>11</th><th>12</th></tr></thead><tbody><tr><td>total</td><td>1</td><td>1</td><td>2</td><td>3</td><td>5</td><td>8</td><td>11</td><td>18</td><td>27</td><td>42</td><td>64</td><td>98</td></tr></tbody></table><p>仔细观察一下每月小兔数的变化情况,我们发现从第7月开始,每月小兔对数就是当月及前5个月所生育的小兔对数之和。而当月出生的小兔对数就是前2月到前6月内出生的小兔对数之和。于是,引入变量<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>y</mi><mo stretchy="false">(</mo><mi>j</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">y(j)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.05724em;">j</span><span class="mclose">)</span></span></span></span>,它表示在第<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>j</mi></mrow><annotation encoding="application/x-tex">j</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.854em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.05724em;">j</span></span></span></span>月出生的小兔对数,记<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi><mo stretchy="false">(</mo><mi>j</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">r(j)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.05724em;">j</span><span class="mclose">)</span></span></span></span>为第<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>j</mi></mrow><annotation encoding="application/x-tex">j</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.854em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.05724em;">j</span></span></span></span>月的小兔对数,则我们发现的规律为:</p><table><thead><tr><th><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>i</mi></mrow><annotation encoding="application/x-tex">i</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6595em;"></span><span class="mord mathnormal">i</span></span></span></span></th><th>1</th><th>2</th><th>3</th><th>4</th><th>5</th><th>6</th></tr></thead><tbody><tr><td><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi><mo stretchy="false">(</mo><mi>i</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">r(i)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mopen">(</span><span class="mord mathnormal">i</span><span class="mclose">)</span></span></span></span></td><td>1</td><td>1</td><td>2</td><td>3</td><td>5</td><td>8</td></tr><tr><td><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>y</mi><mo stretchy="false">(</mo><mi>i</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">y(i)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mopen">(</span><span class="mord mathnormal">i</span><span class="mclose">)</span></span></span></span></td><td>1</td><td>0</td><td>1</td><td>1</td><td>2</td><td>3</td></tr></tbody></table><p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>y</mi><mo stretchy="false">(</mo><mi>j</mi><mo stretchy="false">)</mo><mo>=</mo><mi>y</mi><mo stretchy="false">(</mo><mi>j</mi><mo>−</mo><mn>2</mn><mo stretchy="false">)</mo><mo>+</mo><mi>y</mi><mo stretchy="false">(</mo><mi>j</mi><mo>−</mo><mn>3</mn><mo stretchy="false">)</mo><mo>+</mo><mi>y</mi><mo stretchy="false">(</mo><mi>j</mi><mo>−</mo><mn>4</mn><mo stretchy="false">)</mo><mo>+</mo><mi>y</mi><mo stretchy="false">(</mo><mi>j</mi><mo>−</mo><mn>5</mn><mo stretchy="false">)</mo><mo separator="true">,</mo><mtext> </mtext><mi>j</mi><mo>=</mo><mn>7</mn><mo separator="true">,</mo><mn>8</mn><mo separator="true">,</mo><mn>9</mn><mo separator="true">,</mo><mo>⋯</mo></mrow><annotation encoding="application/x-tex">y(j)=y(j-2)+y(j-3)+y(j-4)+y(j-5),\space j=7,8,9,\cdots </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.05724em;">j</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.05724em;">j</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">2</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.05724em;">j</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">3</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.05724em;">j</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">4</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.05724em;">j</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">5</span><span class="mclose">)</span><span class="mpunct">,</span><span class="mspace"> </span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathnormal" style="margin-right:0.05724em;">j</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.8389em;vertical-align:-0.1944em;"></span><span class="mord">7</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord">8</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord">9</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="minner">⋯</span></span></span></span></span></p><p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>r</mi><mo stretchy="false">(</mo><mi>j</mi><mo stretchy="false">)</mo><mo>=</mo><mi>y</mi><mo stretchy="false">(</mo><mi>j</mi><mo stretchy="false">)</mo><mo>+</mo><mi>y</mi><mo stretchy="false">(</mo><mi>j</mi><mo>−</mo><mn>1</mn><mo stretchy="false">)</mo><mo>+</mo><mi>y</mi><mo stretchy="false">(</mo><mi>j</mi><mo>−</mo><mn>2</mn><mo stretchy="false">)</mo><mo>+</mo><mi>y</mi><mo stretchy="false">(</mo><mi>j</mi><mo>−</mo><mn>3</mn><mo stretchy="false">)</mo><mo>+</mo><mi>y</mi><mo stretchy="false">(</mo><mi>j</mi><mo>−</mo><mn>4</mn><mo stretchy="false">)</mo><mo>+</mo><mi>y</mi><mo stretchy="false">(</mo><mi>j</mi><mo>−</mo><mn>5</mn><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">r(j)=y(j)+y(j-1)+y(j-2)+y(j-3)+y(j-4)+y(j-5) </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.05724em;">j</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.05724em;">j</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.05724em;">j</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">1</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.05724em;">j</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">2</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.05724em;">j</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">3</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.05724em;">j</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">4</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.05724em;">j</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">5</span><span class="mclose">)</span></span></span></span></span></p><p>利用递推关系就很容易用计算机算出以后各月兔子的对数。</p><p>假设<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>x</mi><mi>k</mi></msub><mo stretchy="false">(</mo><mi>t</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">x_k(t)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight" style="margin-right:0.03148em;">k</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord mathnormal">t</span><span class="mclose">)</span></span></span></span>为第<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>t</mi></mrow><annotation encoding="application/x-tex">t</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6151em;"></span><span class="mord mathnormal">t</span></span></span></span>月寿命为<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>k</mi></mrow><annotation encoding="application/x-tex">k</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal" style="margin-right:0.03148em;">k</span></span></span></span>月的兔子数量,则</p><p><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>x</mi><mn>1</mn></msub><mo stretchy="false">(</mo><mn>1</mn><mo stretchy="false">)</mo><mo>=</mo><mn>1</mn></mrow><annotation encoding="application/x-tex">x_1(1)=1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord">1</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.6444em;"></span><span class="mord">1</span></span></span></span>,<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>x</mi><mn>2</mn></msub><mo stretchy="false">(</mo><mn>1</mn><mo stretchy="false">)</mo><mo>=</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">x_2(1)=0</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord">1</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.6444em;"></span><span class="mord">0</span></span></span></span>,<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>x</mi><mn>3</mn></msub><mo stretchy="false">(</mo><mn>1</mn><mo stretchy="false">)</mo><mo>=</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">x_3(1)=0</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">3</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord">1</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.6444em;"></span><span class="mord">0</span></span></span></span>,<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>x</mi><mn>4</mn></msub><mo stretchy="false">(</mo><mn>1</mn><mo stretchy="false">)</mo><mo>=</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">x_4(1)=0</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">4</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord">1</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.6444em;"></span><span class="mord">0</span></span></span></span>,<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>x</mi><mn>5</mn></msub><mo stretchy="false">(</mo><mn>1</mn><mo stretchy="false">)</mo><mo>=</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">x_5(1)=0</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">5</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord">1</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.6444em;"></span><span class="mord">0</span></span></span></span>,<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>x</mi><mn>6</mn></msub><mo stretchy="false">(</mo><mn>1</mn><mo stretchy="false">)</mo><mo>=</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">x_6(1)=0</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">6</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord">1</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.6444em;"></span><span class="mord">0</span></span></span></span></p><p>递推关系如下:</p><p><img src="http://image.cyicz123.top/img/20201027143241.png" alt="兔子繁衍论文公式"></p><h3 id="4-3-问题三">4.3 问题三</h3><h2 id="五、模型求解">五、模型求解</h2><h3 id="5-1-问题一">5.1 问题一</h3><p>递归法</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="keyword">import</span> matplotlib.pyplot <span class="keyword">as</span> plt</span><br><span class="line"><span class="keyword">def</span> <span class="title function_">calculateNumrecursively</span>(<span class="params">n</span>):</span><br><span class="line"> <span class="keyword">if</span> n <= <span class="number">1</span>:</span><br><span class="line"> <span class="keyword">return</span> n</span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="keyword">return</span>(calculateNumrecursively(n-<span class="number">1</span>) + calculateNumrecursively(n-<span class="number">2</span>))</span><br><span class="line"></span><br><span class="line">arr=np.zeros(<span class="number">36</span>, dtype = <span class="string">'uint64'</span>, order = <span class="string">'C'</span>)</span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">36</span>):</span><br><span class="line"> arr[i]=calculateNumrecursively(i)</span><br><span class="line">x_ticks=<span class="built_in">range</span>(<span class="number">1</span>,<span class="number">36</span>,<span class="number">3</span>)</span><br><span class="line">plt.xticks(x_ticks)</span><br><span class="line">plt.plot(<span class="built_in">range</span>(<span class="number">36</span>),arr)</span><br><span class="line"><span class="built_in">print</span>(<span class="string">"第35个月兔子对数为:"</span>,arr[<span class="number">35</span>]*<span class="number">1000</span>)</span><br></pre></td></tr></table></figure><p>输出</p><p><img src="http://image.cyicz123.top/img/20201026080128.png" alt="第一题递推"></p><p>数组法</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">def</span> <span class="title function_">calNumArr</span>(<span class="params">n</span>):</span><br><span class="line"> arr=np.zeros(n+<span class="number">1</span>,dtype = <span class="string">'uint64'</span>, order = <span class="string">'C'</span>)</span><br><span class="line"> <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(n+<span class="number">1</span>):</span><br><span class="line"> <span class="keyword">if</span> i<=<span class="number">1</span>:</span><br><span class="line"> arr[i]=i</span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> arr[i]=arr[i-<span class="number">1</span>]+arr[i-<span class="number">2</span>]</span><br><span class="line"> <span class="keyword">return</span> arr</span><br><span class="line">arr2=calNumArr(<span class="number">36</span>)</span><br><span class="line">x_ticks=<span class="built_in">range</span>(<span class="number">1</span>,<span class="number">36</span>,<span class="number">3</span>)</span><br><span class="line">plt.xticks(x_ticks)</span><br><span class="line">plt.plot(<span class="built_in">range</span>(<span class="number">37</span>),arr2)</span><br><span class="line"><span class="built_in">print</span>(<span class="string">"第36个月兔子对数为:"</span>,arr2[<span class="number">36</span>]*<span class="number">1000</span>)</span><br></pre></td></tr></table></figure><p><img src="http://image.cyicz123.top/img/20201026080338.png" alt="第一题数组法"></p><h3 id="5-2-问题二">5.2 问题二</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">def</span> <span class="title function_">calNum2</span>(<span class="params">n</span>):</span><br><span class="line"> arr1=np.array([[<span class="number">0</span>,<span class="number">1</span>,<span class="number">1</span>,<span class="number">1</span>,<span class="number">1</span>,<span class="number">0</span>],</span><br><span class="line"> [<span class="number">1</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>],</span><br><span class="line"> [<span class="number">0</span>,<span class="number">1</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>],</span><br><span class="line"> [<span class="number">0</span>,<span class="number">0</span>,<span class="number">1</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>],</span><br><span class="line"> [<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">1</span>,<span class="number">0</span>,<span class="number">0</span>],</span><br><span class="line"> [<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">1</span>,<span class="number">0</span>]])</span><br><span class="line"> arr2=np.array([[<span class="number">1</span>],</span><br><span class="line"> [<span class="number">0</span>],</span><br><span class="line"> [<span class="number">0</span>],</span><br><span class="line"> [<span class="number">0</span>],</span><br><span class="line"> [<span class="number">0</span>],</span><br><span class="line"> [<span class="number">0</span>]])</span><br><span class="line"> result=np.zeros(n+<span class="number">1</span>, dtype = <span class="string">'uint64'</span>, order = <span class="string">'C'</span>)</span><br><span class="line"> <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,n+<span class="number">1</span>):</span><br><span class="line"> result[i]=np.<span class="built_in">sum</span>(arr2)</span><br><span class="line"> arr2=arr1.dot(arr2)</span><br><span class="line"> <span class="keyword">return</span> result</span><br><span class="line">arr3=calNum2(<span class="number">36</span>)</span><br><span class="line">x_ticks=<span class="built_in">range</span>(<span class="number">1</span>,<span class="number">36</span>,<span class="number">3</span>)</span><br><span class="line">plt.xticks(x_ticks)</span><br><span class="line">plt.plot(<span class="built_in">range</span>(<span class="number">37</span>),arr3)</span><br><span class="line"><span class="built_in">print</span>(<span class="string">"第36个月兔子对数为:"</span>,arr3[<span class="number">36</span>]*<span class="number">1000</span>)</span><br></pre></td></tr></table></figure><p>输出</p><p><img src="http://image.cyicz123.top/img/20201026091033.png" alt="第二题"></p><h3 id="5-3-问题三">5.3 问题三</h3><h2 id="六、模型评价与推广">六、模型评价与推广</h2><h3 id="6-1-好的方面">6.1 好的方面</h3><p>用递推法取得了不错的效果</p><h3 id="6-2-模型推广">6.2 模型推广</h3><p>•兔子在不同的时期生育能力不同,考虑生育情况的变化</p><p>•可以用线性代数的方法解决一大类生物种群数量增长规律的建模问题。</p><h2 id="七、参考文献">七、参考文献</h2><p>【1】老师上课的ppt</p>]]></content>
<categories>
<category> 学习 </category>
</categories>
<tags>
<tag> 数学建模 </tag>
<tag> 递归 </tag>
<tag> 斐波拉契数列 </tag>
</tags>
</entry>
<entry>
<title>数学建模实验论文一</title>
<link href="/posts/2475dabc/"/>
<url>/posts/2475dabc/</url>
<content type="html"><![CDATA[<h2 id="摘要">摘要</h2><p>本篇论文主要是学习使用Matlab中的线性回归函数,通过对于作业中的两题数据通过导入、线性回归后得到回归方程。</p><p>针对问题一,根据题目要求使用polyfit 函数对轿车的使用年数和价格进行线性回归,然后绘图分析,最后优化。</p><p>针对问题二,根据题目要求利用regress对四个自变量(湖区工业产值、总人口数、捕鱼量、降雨量)对因变量污染物实测值进行回归,由于有四个自变量无法绘图分析,所以直接对数据分析,从而优化</p><p>关键词:<strong>线性回归</strong>、<strong>优化</strong>、<strong>可视化</strong></p><span id="more"></span><h2 id="一、问题重述">一、问题重述</h2><h3 id="1-1-美国旧轿车价格和使用年数的关系">1.1 美国旧轿车价格和使用年数的关系</h3><p>表1所示为美国旧轿车价格的调查资料,以x表示轿车的使用年数,y表示相应的平均价格,根据表中的数据建立一个数学模型,分析旧轿车平均价格与其使用年数之间的关系,即求y关于x的回归方程(一元线性回归,polyfit函数,y与x不是线性关系时可转换为线性关系)。</p><p><strong>表1美国旧轿车价格的调查资料</strong></p><table><thead><tr><th>使用年数x</th><th>1</th><th>2</th><th>3</th><th>4</th><th>5</th><th>6</th><th>7</th><th>8</th><th>9</th><th>10</th></tr></thead><tbody><tr><td>平均价格y</td><td>2650</td><td>1942</td><td>1493</td><td>1086</td><td>766</td><td>539</td><td>485</td><td>291</td><td>224</td><td>202</td></tr></tbody></table><h3 id="1-2-洞庭湖水质污染因素分析">1.2 洞庭湖水质污染因素分析</h3><p>已知8年来洞庭湖湖水中污染物实测值Y与影响因素湖区工业产值<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>x</mi><mn>1</mn></msub></mrow><annotation encoding="application/x-tex">x_1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5806em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>,总人口数<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>x</mi><mn>2</mn></msub></mrow><annotation encoding="application/x-tex">x_2</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5806em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>,捕鱼量<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>x</mi><mn>3</mn></msub></mrow><annotation encoding="application/x-tex">x_3</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5806em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">3</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>,降雨量<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>x</mi><mn>4</mn></msub></mrow><annotation encoding="application/x-tex">x_4</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5806em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">4</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>资料如表2所示,建立污染物<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>Y</mi></mrow><annotation encoding="application/x-tex">Y</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord mathnormal" style="margin-right:0.22222em;">Y</span></span></span></span>的水质分析模型(多元线性回归,regress函数)。</p><p><strong>表2</strong></p><table><thead><tr><th><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>x</mi><mn>1</mn></msub></mrow><annotation encoding="application/x-tex">x_1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5806em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span></th><th>1.376</th><th>1.375</th><th>1.387</th><th>1.401</th><th>1.412</th><th>1.428</th><th>1.445</th><th>1.477</th></tr></thead><tbody><tr><td><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>x</mi><mn>2</mn></msub></mrow><annotation encoding="application/x-tex">x_2</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5806em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span></td><td>0.450</td><td>0.475</td><td>0.485</td><td>0.5</td><td>0.535</td><td>0.545</td><td>0.55</td><td>0.575</td></tr><tr><td><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>x</mi><mn>3</mn></msub></mrow><annotation encoding="application/x-tex">x_3</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5806em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">3</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span></td><td>2.17</td><td>2.554</td><td>2.676</td><td>2.713</td><td>2.823</td><td>3.088</td><td>3.122</td><td>3.262</td></tr><tr><td><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>x</mi><mn>4</mn></msub></mrow><annotation encoding="application/x-tex">x_4</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5806em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">4</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span></td><td>0.8922</td><td>1.161</td><td>0.5346</td><td>0.9589</td><td>1.0239</td><td>1.0499</td><td>1.1065</td><td>1.1387</td></tr><tr><td><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>Y</mi></mrow><annotation encoding="application/x-tex">Y</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord mathnormal" style="margin-right:0.22222em;">Y</span></span></span></span></td><td>5.19</td><td>5.3</td><td>5.6</td><td>5.82</td><td>6</td><td>6.06</td><td>6.45</td><td>6.95</td></tr></tbody></table><h2 id="二、基本假设">二、基本假设</h2><ul><li>假设美国旧轿车价格只和使用年份有关而与其他因素无关。</li><li>假设洞庭湖水质污染实测值只与湖区工业产值、总人口数、捕鱼量、降雨量有关而与其他因素无关。</li></ul><h2 id="三、符号说明">三、符号说明</h2><table><thead><tr><th style="text-align:center"><strong>符号</strong></th><th><strong>说明</strong></th></tr></thead><tbody><tr><td style="text-align:center"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>x</mi></mrow><annotation encoding="application/x-tex">x</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.4306em;"></span><span class="mord mathnormal">x</span></span></span></span></td><td>美国旧轿车使用年数</td></tr><tr><td style="text-align:center"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>y</mi></mrow><annotation encoding="application/x-tex">y</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span></span></span></span></td><td>美国旧轿车平均价格</td></tr><tr><td style="text-align:center"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>x</mi><mn>1</mn></msub></mrow><annotation encoding="application/x-tex">x_1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5806em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span></td><td>洞庭湖湖区工业产值</td></tr><tr><td style="text-align:center"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>x</mi><mn>2</mn></msub></mrow><annotation encoding="application/x-tex">x_2</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5806em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span></td><td>洞庭湖湖区总人口数</td></tr><tr><td style="text-align:center"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>x</mi><mn>3</mn></msub></mrow><annotation encoding="application/x-tex">x_3</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5806em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">3</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span></td><td>洞庭湖湖区捕鱼量</td></tr><tr><td style="text-align:center"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>x</mi><mn>4</mn></msub></mrow><annotation encoding="application/x-tex">x_4</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5806em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">4</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span></td><td>洞庭湖湖区降雨量</td></tr><tr><td style="text-align:center"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>Y</mi></mrow><annotation encoding="application/x-tex">Y</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord mathnormal" style="margin-right:0.22222em;">Y</span></span></span></span></td><td>洞庭湖湖区污染物实测值</td></tr></tbody></table><h2 id="四、模型建立与求解">四、模型建立与求解</h2><h3 id="4-1-求解y与x进行一元线性回归">4.1 求解<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>y</mi></mrow><annotation encoding="application/x-tex">y</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span></span></span></span>与<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>x</mi></mrow><annotation encoding="application/x-tex">x</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.4306em;"></span><span class="mord mathnormal">x</span></span></span></span>进行一元线性回归</h3><p>拟合</p><figure class="highlight matlab"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">carX=<span class="number">1</span>:<span class="number">10</span>;</span><br><span class="line">priceY=[<span class="number">2650</span> <span class="number">1942</span> <span class="number">1493</span> <span class="number">1086</span> <span class="number">766</span> <span class="number">539</span> <span class="number">485</span> <span class="number">291</span> <span class="number">224</span> <span class="number">202</span>]</span><br><span class="line">a=polyfit(carX,priceY,<span class="number">1</span>);</span><br><span class="line">predict=polyval(a,carX);</span><br><span class="line"><span class="built_in">plot</span>(carX,priceY,<span class="string">'k+'</span>,carX,predict,<span class="string">'r'</span>);</span><br></pre></td></tr></table></figure><p>绘图</p><p><img src="http://image.cyicz123.top/img/20201025155101.png" alt="一阶线性回归"></p><p>拟合的方程为</p><p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>y</mi><mo>=</mo><mo>−</mo><mn>255.13</mn><mi>x</mi><mo>+</mo><mn>2371.1</mn></mrow><annotation encoding="application/x-tex">y=-255.13x+2371.1 </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.7278em;vertical-align:-0.0833em;"></span><span class="mord">−</span><span class="mord">255.13</span><span class="mord mathnormal">x</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:0.6444em;"></span><span class="mord">2371.1</span></span></span></span></span></p><p>观察可视化图像发现模型函数拟合的并不好,因此决定用三阶线性函数来拟合。</p><p><img src="http://image.cyicz123.top/img/20201025155132.png" alt="三阶线性回归"></p><p>可以发现新的模型拟合的更好。</p><p>拟合的方程为:</p><p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>y</mi><mo>=</mo><mn>3.0</mn><msup><mi>x</mi><mn>3</mn></msup><mo>+</mo><mn>86.0</mn><msup><mi>x</mi><mn>2</mn></msup><mo>−</mo><mn>887.2</mn><mi>x</mi><mo>+</mo><mn>3437.3</mn></mrow><annotation encoding="application/x-tex">y=3.0x^3+86.0x^2-887.2x+3437.3 </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.9474em;vertical-align:-0.0833em;"></span><span class="mord">3.0</span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8641em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">3</span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:0.9474em;vertical-align:-0.0833em;"></span><span class="mord">86.0</span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8641em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:0.7278em;vertical-align:-0.0833em;"></span><span class="mord">887.2</span><span class="mord mathnormal">x</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:0.6444em;"></span><span class="mord">3437.3</span></span></span></span></span></p><h3 id="4-2-洞庭湖污染物多元线性回归">4.2 洞庭湖污染物多元线性回归</h3><p>用regress回归</p><figure class="highlight matlab"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">x1=[<span class="number">1.376</span><span class="number">1.375</span><span class="number">1.387</span><span class="number">1.401</span><span class="number">1.412</span><span class="number">1.428</span><span class="number">1.445</span><span class="number">1.477</span>];</span><br><span class="line">x2=[<span class="number">0.450</span><span class="number">0.475</span><span class="number">0.485</span><span class="number">0.5</span><span class="number">0.535</span><span class="number">0.545</span><span class="number">0.55</span><span class="number">0.575</span>];</span><br><span class="line">x3=[<span class="number">2.17</span><span class="number">2.554</span><span class="number">2.676</span><span class="number">2.713</span><span class="number">2.823</span><span class="number">3.088</span><span class="number">3.122</span><span class="number">3.262</span>];</span><br><span class="line">x4=[<span class="number">0.8922</span><span class="number">1.161</span><span class="number">0.5346</span><span class="number">0.9589</span><span class="number">1.0239</span><span class="number">1.0499</span><span class="number">1.1065</span><span class="number">1.1387</span>];</span><br><span class="line">y=[<span class="number">5.19</span><span class="number">5.3</span><span class="number">5.6</span><span class="number">5.82</span> <span class="number">6</span> <span class="number">6.06</span><span class="number">6.45</span> <span class="number">6.95</span>];</span><br><span class="line">X=[<span class="built_in">ones</span>(<span class="built_in">length</span>(x1),<span class="number">1</span>),x1',x2',x3',x4'];</span><br><span class="line">[b1,b2,b3,b4,b5]=regress(y',X);</span><br></pre></td></tr></table></figure><p>由于输入参数为一个<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>y</mi></mrow><annotation encoding="application/x-tex">y</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span></span></span></span>与<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>x</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">x_i</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5806em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3117em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>构成的五维向量,所以无法画图,但是可以通过分析显著性效果来获得拟合效果,通过代码我们获得的显著性效果分析如下:</p><p><img src="http://image.cyicz123.top/img/20201025155212.png" alt="分析"></p><p>拟合的函数为:</p><p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>Y</mi><mo>=</mo><mn>13.1920</mn><msub><mi>x</mi><mn>1</mn></msub><mo>+</mo><mn>2.4228</mn><msub><mi>x</mi><mn>2</mn></msub><mo>+</mo><mn>0.0754</mn><msub><mi>x</mi><mn>3</mn></msub><mo>−</mo><mn>0.1897</mn><msub><mi>x</mi><mn>4</mn></msub><mo>−</mo><mn>13.9849</mn></mrow><annotation encoding="application/x-tex">Y=13.1920x_1+2.4228x_2+0.0754x_3-0.1897x_4-13.9849 </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord mathnormal" style="margin-right:0.22222em;">Y</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.7944em;vertical-align:-0.15em;"></span><span class="mord">13.1920</span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:0.7944em;vertical-align:-0.15em;"></span><span class="mord">2.4228</span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:0.7944em;vertical-align:-0.15em;"></span><span class="mord">0.0754</span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">3</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:0.7944em;vertical-align:-0.15em;"></span><span class="mord">0.1897</span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">4</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:0.6444em;"></span><span class="mord">13.9849</span></span></span></span></span></p><p>数据中的b2为P的95%置信区间, b5的第三个参数为F检测的p值,p值很小(P<0.001),说明拟合模型有效,但此处的效果为0.0047,可见效果没有那么好但是也还行。</p><p>可以看到,洞庭湖污染物的实测值,与湖区的工业产值<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>x</mi><mn>1</mn></msub></mrow><annotation encoding="application/x-tex">x_1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5806em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>,总人口数<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>x</mi><mn>2</mn></msub></mrow><annotation encoding="application/x-tex">x_2</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5806em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>以及捕鱼量 <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>x</mi><mn>3</mn></msub></mrow><annotation encoding="application/x-tex">x_3</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5806em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">3</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>呈正相关,而与降雨量<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>x</mi><mn>4</mn></msub></mrow><annotation encoding="application/x-tex">x_4</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5806em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">4</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>呈负相关,根据拟合函数知道对于污染物实测值影响最大的是湖区的工业产值 ,如想降低湖区的污染物总量,应该控制工业废料排放,这也与实际情况相符合。</p><h2 id="五、模型的评价与推广">五、模型的评价与推广</h2><p>好的方面:</p><ol><li><p>美国旧轿车一元线性回归获得了不错的效果。</p></li><li><p>洞庭湖污染物获得了<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>y</mi></mrow><annotation encoding="application/x-tex">y</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span></span></span></span>对<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>x</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">x_i</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5806em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3117em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>的拟合效果。</p></li></ol><p>待改进的方面:</p><p>美国旧轿车的拟合效果比较接近,但并未考虑到其他因素的影响,并且没有运用数量化的评估方法挑选合适的阶数。洞庭湖由于无法展示图片,因此只采用了一次多元线性回归。</p><h2 id="六、参考文献">六、参考文献</h2><p>【1】 多项式曲线拟合 - MATLAB polyfit - MathWorks 中国</p><p><a href="https://ww2.mathworks.cn/help/matlab/ref/polyfit.html">https://ww2.mathworks.cn/help/matlab/ref/polyfit.html</a></p><p>【2】 Multiple linear regression - MATLAB regress</p><p><a href="https://www.mathworks.com/help/stats/regress.html">https://www.mathworks.com/help/stats/regress.html</a></p>]]></content>
<categories>
<category> 学习 </category>
</categories>
<tags>
<tag> 数学建模 </tag>
<tag> 线性回归 </tag>
<tag> 优化 </tag>
<tag> 可视化 </tag>
</tags>
</entry>
<entry>
<title>github团队协作</title>
<link href="/posts/bd0f73d1/"/>
<url>/posts/bd0f73d1/</url>
<content type="html"><![CDATA[<p>视觉组开发代码需要用一个版本控制工具,因此需要懂一些Git和Github作为团队协作的操作。这篇博客主要基于我们战队今年开源项目为实例演示团队合作流程。</p><p>首先大家需要掌握基础的Git操作。</p><span id="more"></span><p>由于暂时代码开发不需要用到多分支,所以我们的主仓库只用了两个分支,一个main分支用来存储稳定版本代码,另一个是开发分支dev,用于开发代码。</p><p>团队协作流程大概是这样的:</p><ol><li>战队账号创建一个主仓库</li><li>新建分支dev</li><li>拉小伙伴进入项目</li></ol><p>个人流程是这样的:</p><ol><li>个人账号同意战队账号邀请</li><li>个人账号fork战队的项目</li><li>clone到本地开发</li><li>要提交时先合并一下战队仓库最新的代码</li><li>然后从本地提交给个人远程仓库</li><li>网页上点击PR按钮,待管理员审核后,个人仓库代码合并入主仓库</li></ol><h2 id="管理员操作流程">管理员操作流程</h2><h3 id="创建组织、队伍和仓库">创建组织、队伍和仓库</h3><p>点击Github右上角+,创建组织</p><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201025132226.png" alt="创建组织"></p><p>白嫖免费的组织</p><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201025132410.png" alt="选择个人账户"></p><p>创建组织完成后,回到主页点击右上角个人头像,选择Your organizations</p><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201025132749.png" alt="Your organizations"></p><p>找到自己刚刚创建的组织,然后点击进入组织页面。并选择teams选项来创建队伍</p><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201025132949.png" alt="创建队伍"></p><p>点击New team</p><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201025133053.png" alt="team"></p><p>进入刚刚创建好的team页面,点击Member,点击Add a member添加队员。</p><p>最后回到组织主页,新建项目仓库。</p><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201025133323.png" alt="新建项目仓库"></p><p>进入仓库主页,点击Setting,点击Manage access设置队员权限,点击Invite teams or peaple邀请刚刚创立的队伍。然后设置队伍队员权限为只读。</p><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201025133912.png" alt=""></p><h2 id="队员流程">队员流程</h2><h3 id="1-fork主仓库到自己仓库">1. fork主仓库到自己仓库</h3><h3 id="2-将个人仓库clone到本地">2. 将个人仓库clone到本地</h3><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201025134239.png" alt="获取clone地址"></p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git clone url</span><br></pre></td></tr></table></figure><h3 id="3-设置远程地址简称">3. 设置远程地址简称</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git remote add origin url # 这里的url是个人仓库的地址</span><br><span class="line">git remote add upstream url # 这里的url是战队仓库的地址</span><br></pre></td></tr></table></figure><h3 id="4-fetch、merge和push">4. fetch、merge和push</h3><p>这三个命令是团队协作的关键。</p><p>首先解释一下,第三步里为什么要设置两个远程地址的简称。个人fork主仓库里的内容是将主仓库当时的内容拷贝一份到自己的个人仓库里。但是有个问题是,**当自己的个人代码开发完毕上传到个人远程仓库再PR给主仓库时,主仓库可能在个人拷贝后更新了版本。**这样个人上传的代码是基于旧版本开发的,那么就会有问题。</p><p>所以在个人将自己本地代码提交给远程仓库时,要先**手动更新一下个人远程仓库保持和战队主仓库同步。**然后PR给主仓库。</p><p>具体步骤如下:</p><h4 id="1-开发代码前更新一下个人仓库">1. 开发代码前更新一下个人仓库</h4><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201025135600.png" alt="fetch"></p><p><code>upstream</code>代表战队仓库地址,<code>dev</code>代表要拉取的相应分支(这里拉取的是<code>deb</code>分支)</p><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201025135957.png" alt="merge"></p><p>将刚刚拉取的远程内容合并到本地当前分支,<code>FETCH_HEAD</code>是git里代表刚刚用fetch拉取的内容。</p><h4 id="2-开发代码">2. 开发代码</h4><p>开发完后,使用<code>git add .</code> <code>git commit -m "提交备注"</code>来提交版本。</p><h4 id="3-重复第一步">3. 重复第一步</h4><p>再次拉取战队仓库最新代码,因为个人开发过程中战队仓库可能有修改。</p><h4 id="4-提交本地代码至个人远程仓库">4. 提交本地代码至个人远程仓库</h4><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201025140622.png" alt="push"></p><p><code>origin</code>代表个人远程仓库地址,第一个<code>main</code>代表本地分支名字,第二个<code>main</code>代表要上传到的远程分支名。</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git push <远程主机名> <本地分支名>:<远程分支名></span><br></pre></td></tr></table></figure><h4 id="5-在GitHub网页上点击PR">5. 在GitHub网页上点击PR</h4><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201025141150.png" alt="Pull request"></p><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201025141212.png" alt="注意事项"></p>]]></content>
<categories>
<category> 教程 </category>
<category> RM </category>
</categories>
<tags>
<tag> RM </tag>
<tag> Github </tag>
</tags>
</entry>
<entry>
<title>Principles of Search Engines</title>
<link href="/posts/b65b5a2/"/>
<url>/posts/b65b5a2/</url>
<content type="html"><![CDATA[<h2 id="What’s-the-traditional-principles-of-search-engines">What’s the traditional principles of search engines?</h2><p>Search engine is a computer program that helps users search for content they need. The traditional search engine consists of three modules as shown in the following.</p><span id="more"></span><p>搜索引擎是一个帮助用户搜索他们需要内容的计算机程序。传统搜索引擎由如下图所示的三个模块组成</p><p><img src="http://image.cyicz123.top/img/20201012000200.png" alt="three modules"></p><h3 id="Web-spider">Web spider</h3><p>Information on the Internet is spread all over the world. If a search engine wants to answer users’ searches, it must first rely on web spiders to store web pages on its own local server. Web spiders continuously send requests to various websites and store the obtained web pages.</p><p>So how does it know where to send the request? Search engines usually use links between web pages to solve this question. Web spiders start from a web page, extract links to other pages, and treat them as the next request. Then Repeat this process over and over again. There are many details to be considered here. For example, how to avoid circularly linked web pages, how to parse web documents (usually in html format, but there are also many other formats), how to extract links inside, and how to handle errors when the link cannot be opened.</p><p>互联网上的信息遍布世界各地,搜索引擎要想回答用户的搜索,首先要依靠网路爬虫把网页存在自己本地的服务器上。 网络爬虫不停的向各种网站发送请求,将所得到的网页存储起来。那么它怎么知道往哪发送请求呢?搜索引擎通常的做法是利用网页之间的链接.网络爬虫从一个网页出发,提取出指向其他页面的链接,把它们当成将下次要请求的对象.然后不停重复这个过程。这里有很多细节要被考虑。例如如何避免循环链接的网页,如何解析网页文档(通常是html格式,但也有很多其他格式)如何提取里边的链接;当链接无法打开时如何对错误进行处理等。</p><h3 id="Index-algorithm">Index algorithm</h3><p>How to find information in complex data?</p><p>Every word that appears in a document owned by a search engine has an inverted list. It records how many documents the word appears in, which documents are, how many times each document section appears, and where it appears respectively.</p><p>For example, the word Apple appears in documents 1, 7, 19, 34, 102. Among them, document 1 appears 3 times, respectively at positions 20, 105, and 700. In this way, when searching for Apple, Google does not need to traverse all the documents, only need to find the inverted list corresponding to each word to know where the word appears. Every web document has more than just text information. It may also include URLs, file names, references, etc. In order to improve search quality, search engines need to process different parts of the document separately to construct a reverse list. Each part of the word must be added to the inverted list of words belonging to this part.</p><p>如何在繁杂的数据中找到信息?</p><p>搜索引擎所拥有的文档中出现的每一个单词都拥有一个反转列表。它记录了这个单词在多少文档中出现,分别是哪些文档,每个文档分部出现多少次,分别出现在什么位置等信息。比如Apple这个词出现在文档1,7,19,34,102。其中文档1中出现了3次,分别在位置20,105,700。这样当搜索Apple时,Goolge就不用遍历所有的文档,只需要查找每个单词对应的反转列表就可以知道这个词在哪里出现了。每一个网络文档不仅只有文本信息。它还可能包括URL,文件名,引用等部分。为了提高搜索质量,搜索引擎需要对文档的不同部分分别处理,构造反转列表。每一部分的单词都要被加入到这个词属于此部分的反转列表里。</p><h3 id="Search-algorithm">Search algorithm</h3><p>If the search engine has an index, it can quickly find what users need. As mentioned earlier, search engines find matching content based on users’ information needs. Information needs come from user input. How to understand it has many questions. Simply put, each search sentence will be parsed into a tree structure: leaf nodes are keywords. Then search based on keywords.</p><p>如果搜索引擎有了索引,它就可以快速找到用户所需内容了。前文说过搜索引擎根据用户的信息需求查找匹配的内容。信息需求来自于用户输入。如何理解它有很大学问。简单的说,每个搜索语句会被解析成一个树形结构:叶子节点就是一个个关键词.然后依据关键词检索.</p><h2 id="PageRank">PageRank</h2><h3 id="Introduction">Introduction</h3><p>The PageRank algorithm calculates the PageRank value of each web page, and then ranks the importance of the web pages according to the value of this value.</p><p>The core idea of the PageRank algorithm is that if a webpage is linked to by many other webpages, it means that this webpage is more important, that is, the PageRank value will be relatively high. And if a webpage with a high PageRank value links to another webpage, it will be linked The PageRank value of the web page you arrive will increase accordingly</p><p>PageRank算法计算每一个网页的PageRank值,然后根据这个值的大小对网页的重要性进行排序。PageRank算法的核心思想是如果一个网页被很多其他网页链接到的话说明这个网页比较重要,也就是PageRank值会相对较高.而且如果一个PageRank值很高的网页链接到一个其他的网页,那么被链接到的网页的PageRank值会相应地因此而提高</p><h3 id="Principle">Principle</h3><p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>P</mi><mi>R</mi><mo stretchy="false">(</mo><mi>A</mi><mo stretchy="false">)</mo><mo>=</mo><mn>1</mn><mo>−</mo><mi>d</mi><mo>+</mo><mi>d</mi><mo stretchy="false">(</mo><mi>P</mi><mi>R</mi><mo stretchy="false">(</mo><msub><mi>T</mi><mn>1</mn></msub><mo stretchy="false">)</mo><mi mathvariant="normal">/</mi><mi>C</mi><mo stretchy="false">(</mo><msub><mi>T</mi><mn>1</mn></msub><mo stretchy="false">)</mo><mo>+</mo><mo>⋯</mo><mo>+</mo><mi>P</mi><mi>R</mi><mo stretchy="false">(</mo><msub><mi>T</mi><mi>n</mi></msub><mo stretchy="false">)</mo><mi mathvariant="normal">/</mi><mi>C</mi><mo stretchy="false">(</mo><msub><mi>T</mi><mi>n</mi></msub><mo stretchy="false">)</mo><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">PR(A)=1-d+d(PR(T_1)/C(T_1)+\cdots+PR(T_n)/C(T_n))</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.00773em;">PR</span><span class="mopen">(</span><span class="mord mathnormal">A</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.7278em;vertical-align:-0.0833em;"></span><span class="mord">1</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:0.7778em;vertical-align:-0.0833em;"></span><span class="mord mathnormal">d</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">d</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.00773em;">PR</span><span class="mopen">(</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.1389em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mclose">)</span><span class="mord">/</span><span class="mord mathnormal" style="margin-right:0.07153em;">C</span><span class="mopen">(</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.1389em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:0.6667em;vertical-align:-0.0833em;"></span><span class="minner">⋯</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.00773em;">PR</span><span class="mopen">(</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.1389em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">n</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mclose">)</span><span class="mord">/</span><span class="mord mathnormal" style="margin-right:0.07153em;">C</span><span class="mopen">(</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.1389em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">n</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mclose">))</span></span></span></span></span></p><blockquote><p>PR(A) is the PR value of page A</p><p>PR(Ti) is the PR value of page Ti, where page Ti refers to a certain page among all pages of A</p><p>C(Ti) is the out degree of page Ti, that is, the number of edges where Ti points to other pages</p><p>d is the damping coefficient, and its meaning is the probability that the user will continue to browse backwards after reaching a certain page at any time,</p><p>PR(A)是页面A的PR值</p><p>PR(Ti)是页面Ti的PR值,在这里,页面Ti是指向A的所有页面中的某个页面</p><p>C(Ti)是页面Ti的出度,也就是Ti指向其他页面的边的个数</p><p>d 为阻尼系数,其意义是,在任意时刻,用户到达某页面后并继续向后浏览的概率,</p></blockquote><h3 id="Advantage">Advantage</h3><p>PageRank is a static algorithm that has nothing to do with queries. The PageRank value of all web pages is obtained through offline calculation; it effectively reduces the amount of calculation during online queries and greatly reduces the query response time.</p><p>PageRank是一个与查询无关的静态算法,所有网页的PageRank值通过离线计算获得;有效减少在线查询时的计算量,极大降低了查询响应时间。</p><h2 id="Personal-thoughts-on-using-Baidu">Personal thoughts on using Baidu</h2><p>For individuals, Baidu’s ranking algorithm is also PageRank.</p><p>个人觉得百度的排序算法也是PageRank</p><h2 id="Example-1">Example 1</h2><p>I recommend my personal blog site(<a href="cyicz123.top">cyicz123.top</a>) here. Since I only built the website a month ago, and no other websites reference my website. So I can’t find my website by searching keywords on Baidu.</p><p>我在这里推荐一下我的个人博客网站.由于一个月前我才建好网站,并且没有其他网站引用我的网站.所以我在百度上搜索关键词根本无法找到自己的网站.</p><p><img src="http://image.cyicz123.top/img/20201012010858.png" alt="百度搜索逍遥小站"></p><p><img src="http://image.cyicz123.top/img/20201012010930.png" alt="精准搜索网站"></p><h3 id="Example-2">Example 2</h3><p>But Baidu is not all the PageRank algorithm adopted. After Baidu’s Fengchao system was launched in 2009, Baidu’s page ranking and advertising ranking were officially separated. The front end of the Baidu search homepage is a promotion advertisement recommended based on search keywords. This is also one point that many people do not like Baidu.</p><p>但是百度也不全是采用的PageRank算法.从2009年百度的凤巢系统上线之后,百度网页排名和广告排名正式分开。百度搜索首页最前端是根据搜索关键词推荐的推广广告.这也是很多人不喜欢百度的一点.</p><p><img src="http://image.cyicz123.top/img/20201012011701.png" alt="百度付费推广"></p>]]></content>
<categories>
<category> 英语 </category>
</categories>
<tags>
<tag> 英语 </tag>
<tag> 搜索引擎 </tag>
</tags>
</entry>
<entry>
<title>大一培训策划</title>
<link href="/posts/fcef969/"/>
<url>/posts/fcef969/</url>
<content type="html"><![CDATA[<p>新的赛季又开始了,每年自己都会进步一点,今年仍然是我负责培训。今年希望能让培训变得更好,让萌新的留存率更高。只有不断的人才才是战队第一生产力。毕竟一年能比一年强,总有一年华机可以站在总决赛的赛场上的。</p><span id="more"></span><h2 id="培训内容">培训内容</h2><h3 id="1-C-入门到面向对象程序设计">1. C++入门到面向对象程序设计</h3><p>b站<a href="https://www.bilibili.com/video/BV17s411N78s/">《带你学C带你飞 小甲鱼》</a>学到p31</p><p>中国大学MOOC<a href="https://www.icourse163.org/learn/PKU-1002029030?tid=1450432459#/learn/announce">程序设计与算法(三)C++面向对象程序设计 北大郭炜</a></p><p>学完前六周课程</p><p>参考资料</p><p><a href="https://www.runoob.com/cplusplus/cpp-tutorial.html">C++菜鸟教程</a></p><p>书籍</p><p>C++ Primer Plus (书籍是工具书,查阅而不是全看)链接:<a href="https://pan.baidu.com/s/1_x_Ke1DJ8FJ4eOHZOgZjiw">https://pan.baidu.com/s/1_x_Ke1DJ8FJ4eOHZOgZjiw</a> 提取码:j3ga</p><h3 id="2-Linux操作系统的使用">2. Linux操作系统的使用</h3><p>b站<a href="https://www.bilibili.com/video/BV1dW411M7xL/">尚硅谷Linux教程</a>学到p38</p><p>参考资料</p><p><a href="https://www.runoob.com/linux/linux-tutorial.html">linux 菜鸟教程</a></p><p>书籍</p><p>鸟叔的linux私房菜(书籍是工具书,查阅而不是全看)链接:<a href="https://pan.baidu.com/s/1axTMam4jBCencH6zNnrvng">https://pan.baidu.com/s/1axTMam4jBCencH6zNnrvng</a><br>提取码:P89k</p><h2 id="第一周">第一周</h2><h3 id="1-自我介绍">1. 自我介绍</h3><p>助教们介绍自己,并且分享自己想对学弟学妹们说的经验和故事。</p><h3 id="2-介绍培训计划,分配助教">2. 介绍培训计划,分配助教</h3><p>以新生自学为主,战队人员作为助教,每周告诉新生学习内容和视频,然后给萌新答疑。</p><h3 id="3-搭建C-编程环境">3. 搭建C++编程环境</h3><p>我来带领萌新搭建C++编程环境,介绍VS2019使用方法。带领大家写出自己的第一个程序。</p><h3 id="4-初步介绍git版本控制,介绍如何用markdown编写文档">4. 初步介绍git版本控制,介绍如何用markdown编写文档</h3><h2 id="第二周">第二周</h2><p>暂定,根据第一周教学结果来制订。</p>]]></content>
<categories>
<category> 教程 </category>
<category> RM </category>
</categories>
<tags>
<tag> RM </tag>
<tag> 教程 </tag>
<tag> 培训计划 </tag>
</tags>
</entry>
<entry>
<title>OpenCV4.1.0安装</title>
<link href="/posts/7a87767d/"/>
<url>/posts/7a87767d/</url>
<content type="html"><![CDATA[<p>约定使用OpenCV4.1.0版本开发。这篇博客记录win10安装OpenCV和配置VS 2019 OpenCV编程环境。</p><span id="more"></span><h2 id="官网下载OpenCV4-1-0">官网下载OpenCV4.1.0</h2><p>去<a href="https://opencv.org/releases/">官网下载</a><a href="https://sourceforge.net/projects/opencvlibrary/files/4.1.0/opencv-4.1.0-vc14_vc15.exe/download">OpenCV4.1.0</a></p><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201002143714.png" alt="官网"></p><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201002143731.png" alt="OpenCV4.1.0"></p><h2 id="解压并添加环境变量">解压并添加环境变量</h2><p>下载好后,双击运行exe程序解压,选择一个解压后的目录。( 其会自动生成一个opencv目录,不需要单独再创一个opencv目录。另,<strong>不建议将其解压到C盘根目录下的Program Files或Program File (x86)目录下,可能会因系统权限导致各种问题</strong> )</p><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201002143921.png" alt="解压"></p><h2 id="新建VS-2019配置属性表">新建VS 2019配置属性表</h2><p>在VS 2019中新建一个空项目(具体操作看<a href="https://cyicz123.top/2020/10/01/RM%E7%BC%96%E7%A8%8B%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE/">RM编程环境配置</a>),然后打开属性管理器</p><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201002152922.png" alt="属性管理器"></p><p>选择Debug X64->右键->添加新项目属性表</p><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201002153344.png" alt="新项目属性表"></p><p>这里我重命名为debug为了等下和release属性表区分</p><p><img src="http://image.cyicz123.top/img/20201002154008.png" alt="debug"></p><h2 id="添加头文件和库文件">添加头文件和库文件</h2><p>在刚刚安装opencv的目录中找到如下文件</p><figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="section"># 头文件</span></span><br><span class="line">C:\Users\60292\AppData\Local\opencv\build\include</span><br><span class="line">C:\Users\60292\AppData\Local\opencv\build\include\opencv2</span><br><span class="line"><span class="section"># 库文件</span></span><br><span class="line">C:\Users\60292\AppData\Local\opencv\build\x64\vc15\lib</span><br></pre></td></tr></table></figure><p>右键点击刚刚添加的debug属性表</p><p>将刚刚的头文件目录路径添加到包含目录里,库文件目录路径添加到库目录里</p><p><img src="http://image.cyicz123.top/img/20201002154154.png" alt="包含目录"></p><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201002154624.png" alt="包含目录路径"></p><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201002154655.png" alt="库目录路径"></p><p>添加依赖库</p><p>进入刚才库文件的目录,复制库文件的名字。</p><figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="section">#根据自己安装版本选择</span></span><br><span class="line">opencv<span class="emphasis">_world410d.lib # 带后缀d的为目前debug属性表依赖</span></span><br><span class="line"><span class="emphasis">opencv_</span>world411.lib # 不带后缀d的为等下release属性表依赖</span><br></pre></td></tr></table></figure><p><img src="http://image.cyicz123.top/img/20201002154214.png" alt=""></p><p>最后点击确定完成debug属性表的设置。</p><h2 id="设置release属性表">设置release属性表</h2><p>选择Release X64->右键->添加新项目属性表</p><p>重命名为release与前文的debug区分</p><p>包含目录和库目录设置和前文一样,只有最后添加依赖库时要把带d后缀去掉</p><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201002155019.png" alt="依赖库"></p><p><strong>设置完毕后需要重启电脑</strong></p><h2 id="代码测试">代码测试</h2><p>新建源文件</p><p>输入以下代码</p><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string"><opencv2/opencv.hpp></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string"><iostream></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> cv;</span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line">Mat src = <span class="built_in">imread</span>(<span class="string">"C:/Girlfriend.jpg"</span>); <span class="comment">//图片路径记得修改</span></span><br><span class="line"> <span class="keyword">if</span> (src.<span class="built_in">empty</span>()) {</span><br><span class="line"> cout << <span class="string">"image load fail"</span> << endl;</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">namedWindow</span>(<span class="string">"test"</span>);</span><br><span class="line"> <span class="built_in">imshow</span>(<span class="string">"test"</span>, src);</span><br><span class="line"> <span class="built_in">waitKey</span>(<span class="number">0</span>);<span class="comment">//没有的话,窗口一闪而过。</span></span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>记得将上面的类型改为Debug和X64</p><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201002155643.png" alt="修改为Debug"></p><p>F5运行</p><p>弹出西野七濑照片</p><p><img src="http://image.cyicz123.top/img/20201002155727.png" alt="西野七濑"></p><h2 id="最后">最后</h2><p>其他项目代码可以直接在属性管理器里添加现有属性表(即上文建立的的不过debug和release属性表),debug模式用debug属性表,release模式用release属性表。</p>]]></content>
<categories>
<category> 教程 </category>
<category> RM </category>
</categories>
<tags>
<tag> RM </tag>
<tag> 教程 </tag>
</tags>
</entry>
<entry>
<title>RM编程环境配置</title>
<link href="/posts/6bd85733/"/>
<url>/posts/6bd85733/</url>
<content type="html"><![CDATA[<p>新的RM赛季又开始了,今年我希望能有更多萌新加入我们战队。之前战队培训大家做的不是很好,导致萌新入门难度还是有一些的,所以今年我希望能写完一系列教程,让零基础有热情的萌新能更快入门。</p><span id="more"></span><h2 id="下载VS-2019">下载VS 2019</h2><h3 id="1-百度搜索VS-2019">1. 百度搜索<code>VS 2019</code></h3><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201002100601.png" alt="vscode搜索"></p><h3 id="2-下载社区版">2. 下载社区版</h3><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201002100800.png" alt="下载社区版"></p><h2 id="安装VS-2019">安装VS 2019</h2><p>前面所有步骤略过。</p><p>安装位置最好默认安装,然后因为我们只需要用VS 2019在windows环境下的C++,所以只勾选使用C++的桌面开发。然后点击安装,喝杯咖啡等待下载安装。<br><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201002101918.png" alt="勾选"></p><p>一杯咖啡后安装完毕,点击重启计算机。</p><h2 id="编写自己的第一个程序Hello-world">编写自己的第一个程序Hello world</h2><p>启动下载好的VS 2019并且按照提示登陆自己的微软账号。</p><p>选择创建新项目</p><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201002104421.png" alt="创建新项目"></p><p>选择创建空项目或者控制台应用都可以。这里我选择的是空项目。</p><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201002104453.png" alt="选择空项目"></p><p>在右侧源文件选项中右键点击新建文件,或者Ctrl+Shift+A直接快捷键新建文件。</p><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201002105230.png" alt=""></p><p>选择C++文件,名称最好改为英文名称,这里我改为main.cpp</p><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201002105256.png" alt=""></p><p>输入代码</p><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string"><iostream></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> cout<<<span class="string">"Hello world!"</span><<endl;</span><br><span class="line"> <span class="comment">//可以在双引号里写自己想输出的文字。</span></span><br><span class="line"> <span class="comment">//所有符号一定要是英文输入法里的符号。;和;是不同的。</span></span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>F5执行程序</p><p><img src="https://raw.githubusercontent.com/cyicz123/Picture/main/img/20201002105749.png" alt="程序结果"></p>]]></content>
<categories>
<category> 教程 </category>
<category> RM </category>
</categories>
<tags>
<tag> RM </tag>
<tag> 教程 </tag>
</tags>
</entry>
<entry>
<title>人生苦短,快学python</title>
<link href="/posts/71baf9d2/"/>
<url>/posts/71baf9d2/</url>
<content type="html"><![CDATA[<p>今天帮老师处理数据集。大概流程就是对每一张图片运行程序,将结果截图到文档里。每张图片重复三次。一开始我想的是写一个python脚本,自动化处理。</p><p>思路如下:</p><ol><li>用os库处理切换目录及执行命令。</li><li>用re库提取出需要的输出的结果。</li><li>最后用os.write写入txt文件里。</li></ol><blockquote><p>估算一张图片需要三十毫秒,一共需要三百次,也就九秒左右。</p></blockquote><p>然后花了一下午,最后python的os.popen(‘命令’)总是输出不是内部或者外部命令。折腾到晚上八点,我感觉有些来不及了,就人工处理数据。</p><blockquote><p>最后我花了两小时也只处理完了四分之三,深刻体验到先进技术就是第一生产力。人生苦短,python真的能节省一大笔时间!要是我对于python能很熟悉,这种简单的需求估计半小时解决。</p></blockquote><p><strong>人生苦短,快学python!</strong></p>]]></content>
<categories>
<category> 随笔 </category>
</categories>
<tags>
<tag> 随笔 </tag>
</tags>
</entry>
<entry>
<title>大三上第二周周结</title>
<link href="/posts/86c15d6a/"/>
<url>/posts/86c15d6a/</url>
<content type="html"><![CDATA[<h2 id="这周做了什么?">这周做了什么?</h2><ul><li>迁移了网站</li><li>考了四级</li><li>周三练了胸,周六跑了七公里</li></ul><h2 id="有什么没完成的?">有什么没完成的?</h2><ul><li>上课没有完全认真听讲</li><li>没有规律睡眠</li><li>没有坚持背单词和练习听力</li><li>没有按照计划跑步和健身</li></ul><h2 id="下周要做什么?">下周要做什么?</h2><ul><li>上课全身心投入</li><li>每天背单词、练习听力和做一篇六级阅读</li><li>学习完第一章线代,并做题</li><li>复习完第一章离散数学,并做完课后练习题</li><li>周三、周六、周日跑步和健身</li><li>战队服务器建立</li><li>电脑换固态,并配置完工作环境</li></ul><h2 id="想说的话">想说的话</h2><p>坚持是最难的,加油!每天记得对着镜子鼓励自己哦!</p>]]></content>
<categories>
<category> 随笔 </category>
</categories>
<tags>
<tag> 随笔 </tag>
</tags>
</entry>
<entry>
<title>Comparison of Java and C++</title>
<link href="/posts/9d958f82/"/>
<url>/posts/9d958f82/</url>
<content type="html"><![CDATA[<h2 id="the-similarities">the similarities</h2><p>Java and C++ are object-oriented language which both go in with object-oriented mentality(encapsulation,inherit,polymorphism).Because object-oriented has many very good features,such as inherit,polymorphism,etc,Java and C++ have excellent reusability.</p><p>Java and C++ not only have the most similarity in object-oriented design mentality,but also are similar in the syntax. They have same keywords,such as <code>if for while const new</code>.Although they have too many similar in syntax and object-oriented mentality,there are lots of different between Java and C++ in kernel.</p><h2 id="the-differences">the differences</h2><p>Although Java and C++ all implement the object-oriented programming paradigm,there are lots of different between Java and C++ in kernel.</p><p>For example,C++ supports multi-inheritance,but Java doesn’t.</p><p>So why does C++ support multi-inheritance,but Java doesn’t?</p><p>Firstly,we should understand the diamond problem. Following this graph ,we assume that there are two derived class $ B_1,B_2 $ which derive from the base class A. Then class C derive from class B_1,B_2.</p><p>It has a member function display() in class A. So class C derive from the B_1 and B_2 ,has two same member function display().It’s a question what the method display() should be called?</p><p><img src="https://pic4.zhimg.com/80/v2-b20fbc2d313495e9696d3fa29c260926_720w.jpg" alt="img"></p><p>C++ use the domain qualifier or virtual base class to solve this problem.</p><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> <span class="title class_">B1</span>:<span class="keyword">public</span> B0</span><br><span class="line"><span class="keyword">class</span> <span class="title class_">B2</span>:<span class="keyword">public</span> B0</span><br><span class="line"><span class="keyword">class</span> <span class="title class_">D</span>:<span class="keyword">public</span> B1,<span class="keyword">public</span> B2<span class="comment">// D d;d.display() ERROR</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">B1</span>:<span class="keyword">virtual</span> <span class="keyword">public</span> B0</span><br><span class="line"><span class="keyword">class</span> <span class="title class_">B2</span>:<span class="keyword">virtual</span> <span class="keyword">public</span> B0</span><br><span class="line"><span class="keyword">class</span> <span class="title class_">D</span>:<span class="keyword">public</span> B1,<span class="keyword">public</span> B2<span class="comment">// D d;d.display() no problem</span></span><br></pre></td></tr></table></figure><p>But Java designer chose to delete this characteristic. There is a joke in the following.</p><p>The programmers in C++ designers’ mind:</p><p><img src="https://pic3.zhimg.com/80/636ca241fb4ef4e14034768efd017a1c_1440w.jpg?source=1940ef5c" alt="img"></p><p>The programmers in Java designers’ mind:</p><p><img src="https://pic4.zhimg.com/80/cbd491e1286e83e3e933ad6658a35606_1440w.jpg?source=1940ef5c" alt="img"></p><h2 id="the-difference-of-compiling">the difference of compiling</h2><p>C++ is the standard representative that write once and then compile anywhere(WOCA).</p><p>Conversely Java write once,run anywhere due to JVM.</p><p>JVM is the abbreviation of Java Virtual Machine, which is achieved by simulating various computer functions on an actual computer. It’s constructed by a bitecode Instruction set,a register,a stack,a garbage collection heap,and a storage method field. JVM shields information related to the operating system platform, so that Java programs only need to generate object code (bytecode) that runs on the JVM, and can run on multiple platforms without modification. It’s the reason that write once,run anywhere.</p><p>But precisely because of this,In addition to running a compiled Java program, computers running Java applications generally must also run the JVM, while compiled C++ programs can be run without external applications. Early versions of Java were significantly outperformed by statically compiled languages such as C++. This is because the program statements of these two closely related languages may compile to a few machine instructions with C++, while compiling into several byte codes involving several machine instructions each when interpreted by a JVM.</p><h2 id="Paradigm">Paradigm</h2><p>There are some paradigms.</p><ul><li><p>Imperative paradigm</p></li><li><p>Procedural paradigm</p></li><li><p>Declarative paradigm</p></li><li><p>Functional paradigm</p></li><li><p>Logic paradigm</p></li><li><p>Object-oriented paradigm</p></li></ul><p>Java is a multi-paradigm language. It mainly supports programming functions based on object-oriented, procedural and functional <a href="http://paradigms.At">paradigms.At</a> this point, I feel that there is no difference between C++ and Java.</p>]]></content>
<categories>
<category> 学习 </category>
<category> 英语 </category>
</categories>
<tags>
<tag> 英语 </tag>
<tag> 学习 </tag>
</tags>
</entry>
<entry>
<title>大三考研规划</title>
<link href="/posts/e215d891/"/>
<url>/posts/e215d891/</url>
<content type="html"><![CDATA[<p>转眼间一年就过去了,我转专业到计科也有一年了。回顾自己一年的学习,总体上自己是很不满意的。在这一年的学习中没有重视专业课的学习,绩点从3.8骤降到了2.6。这是断崖式的下跌。</p><p>究其原因,我分析为:初入计科,被繁杂的技术迷花了眼。我就像寓言故事里进入玉米地的猴子,不断的摘玉米,却把握不住手中的玉米,往往摘了一颗丢一颗。</p><p>幸运的是,在大二,犯错的后果我错的起。一年的试错让我明白了“应该多学了点知识而不是技术”的道理。曾经的我觉得我想去工作而不是科研,为什么不把更多的精力放在学习那些技术框架呢?可是一年的学习下来,我发现我锻炼的只是调api的能力,做出的只是玩具。因此我认为在大学应该将更多的精力放在学习“无用”的理论知识,每一个大学生都应该有点“学习是为了改变世界而不是方便就业”的浪漫情怀。</p><p>现在到了大三,一个很重要的一年——考研阶段。我对这一年有了些规划:</p><p>我大体将一年分为三个阶段,第一个阶段是大三上学期、第二个阶段从寒假到大三暑假结束、最后一个阶段是到研究生初试结束。</p><h2 id="第一个阶段——预备阶段">第一个阶段——预备阶段</h2><p>这一学期将学到大量的专业知识,为研究生或者工作打基础,因此我需要将每一门课学好。我的目标是这学期绩点达到4.0+。</p><p>我需要在这一学期做好考研的准备。最重要的就是习惯准备。我要在这一学期养成持续学习的习惯,让我在考研阶段能每天深度学习8~10小时,一周学习六天。因此我的安排是工作日课后去图书馆完成当日作业和学习英语。周日复习一周的课程,周六休息。</p><p>预备阶段养成良好的生活习惯也十分重要。良好的生活习惯包括坚持运动,保持外观的干净整洁,维护宿舍的清洁。</p><p>于我而言,充足的运动使我更有自制力和上进心。有这么一个说法,我的成绩和我的帅气程度成线性正相关。因为坚持运动维护身材,保持自己的白鞋白净,这些小事的坚持完成让我更有自信和动力去挑战更难的任务。</p><h2 id="第二个阶段——基础巩固阶段">第二个阶段——基础巩固阶段</h2><p>在这个阶段,我将正式开始考研的复习。其中最重要的是数学和英语。</p><p>数学在考研成绩中占比很大,而且也是一门非常拉分的科目。我自认为在数学上有些天赋,所以我需要花更多的努力将天赋化为高分。我计划每天上午学习数学,用大概两个月的时间将所有的数学内容过一遍,然后再花两到三个月的时间完全掌握1800里的所有题。</p><p>英语我一直很不擅长,所以更要付出。我的计划是从预备阶段开始每天背50个单词,并花半小时练习听力。在第二个阶段里,我每天晚上七点到十点都用来看网课、做阅读练习。</p><p>最后是数据结构的复习,每日下午复习数据结构,计划跟浙大陈越老师的数据结构。并且用代码复现。</p><h2 id="第三个阶段——强化突击阶段">第三个阶段——强化突击阶段</h2><p>这一阶段前,我应该对于英语和数学都有了较为熟练的掌握。其中六月的六级考试我的目标是500+通过。</p><p>在数学上,我觉得我应该更多的回归课本定义,每天拿出上午的一小时去阅读课本定义概念和习题,然后去做往年的真题(大概三天一套的速度,做卷子时按照考试时间)。</p><p>英语也是刷真题试卷。</p><p>数据结构的话,也是刷题。</p><p>政治就是刷以前的肖四肖八。</p><h2 id="结语">结语</h2><p>三个阶段里最重要的是预备阶段习惯的养成,有了好习惯,学习自然事倍功半。第二和第三阶段的计划由于自己的信息不足可能会失真,需要及时的调整。所以每个周。每个月都要及时回顾过去的学习和适当调整未来的计划。但是第一阶段的任务一定要严格完成!</p><p>最后,我想说的是结果很重要,但是在这一年的坚持努力的过程更重要。我希望这一年过去,我能成为一个更优秀自律的人。我理想的我是一个身材很好,肌肉鲜明,眼睛里有光的人。有了这样的过程,我想结果是这样的也就不重要了吧,毕竟水到渠成!</p>]]></content>
<categories>
<category> 人生规划 </category>
<category> 考研 </category>
</categories>
<tags>
<tag> 随笔 </tag>
<tag> 人生规划 </tag>
<tag> 考研 </tag>
</tags>
</entry>
<entry>
<title>the fist week of junior year</title>
<link href="/posts/82aa914d/"/>
<url>/posts/82aa914d/</url>
<content type="html"><![CDATA[<h2 id="What-do-something-this-week">What do something this week?</h2><ul><li>Listen carefully every lesson</li><li>Complete the class assignments carefully</li><li>Exercise at Wednesday and Saturday</li><li>Have run 4km at Friday and just have run 7km</li><li>Use the Estée Lauder DW firstly</li><li>Make a hairstyle</li><li>Start the Qt by English wiki. Try to learn CS in English</li><li>Start the JavaScript</li><li>Make a delicious hot pot with roommates today</li><li>Have called my mom to talk with my college life</li><li>Have talked with girlfriend</li></ul><h2 id="What-want-to-do-something-more-next-week">What want to do something more next week?</h2><ul><li>Keep exercising at Wednesday Saturday and Sunday</li><li>Running at least 15km a week total</li><li>Learning more in Qt and JavaScript</li><li>Keep reciting words and practicing listening</li><li>Keep get up and go bed early</li></ul><h2 id="What-want-to-say">What want to say?</h2><p>Nothing. It’s to late for writing this. I want to go bed.</p>]]></content>
<categories>
<category> 随笔 </category>
<category> 英语 </category>
</categories>
<tags>
<tag> 英语 </tag>
<tag> 随笔 </tag>
</tags>
</entry>
<entry>
<title>LCFI</title>
<link href="/posts/2b791ab7/"/>
<url>/posts/2b791ab7/</url>
<content type="html"><![CDATA[<p>LCFI is running a series of projects on the nature and impact of AI. There is five modules in the following.</p><span id="more"></span><ul><li><h4 id="AI-FUTURES-AND-RESPONSIBILITY">AI: FUTURES AND RESPONSIBILITY</h4></li><li><h4 id="AI-TRUST-AND-SOCIETY">AI: TRUST AND SOCIETY</h4></li><li><h4 id="KINDS-OF-INTELLIGENCE">KINDS OF INTELLIGENCE</h4></li><li><h4 id="AI-NARRATIVES-AND-JUSTICE">AI: NARRATIVES AND JUSTICE</h4></li><li><h4 id="PHILOSOPHY-AND-THE-ETHICS-OF-AI">PHILOSOPHY AND THE ETHICS OF AI</h4></li></ul><h2 id="Part-Ⅰ">Part Ⅰ</h2><p>Since artificial intelligence was founded as an academic discipline in 1955,more and more humans are afraid of this possibility that AI is an instrument which is benefit for humans transform to a knife stabbed at human beings.</p><p>So in this article, I prefer to introduce the first module — <strong>AI: FUTURES AND RESPONSIBILITY</strong>. This program is aimed at understanding how the long-term development of AI can be demonstrably safe and maximally beneficial to humanity.</p><p>Four issues belong to this module,there are <strong>policy and responsible innovation</strong>,<strong>autonomous weapons prospects for regulation</strong>,<strong>horizon-scanning and road-mapping</strong> and <strong>the value alignment problem</strong>.</p><h2 id="Part-II">Part II</h2><h3 id="What’s-the-value-alignment-problem">What’s the value alignment problem?</h3><p>The Value Alignment Project seeks to design methods for preventing AI systems from inadvertently acting in ways inimical to human values.</p><h3 id="Why-I-decide-to-choose-this-topic">Why I decide to choose this topic?</h3><p>AI systems will operate with increasing autonomy and capability in complex domains in the real world. How can we ensure that they have the right behavioural dispositions – the goals or ‘values’ needed to ensure that things turn out well, from a human point of view?That’s why I interest to this topic.</p><p>For example,Google driverless car are already on California roads. As driverless cars improve,they will make fewer mistakes than human drivers do. Sometimes,however they face a choice between lives.Should the cars be programmed to avoid hitting a child running across the road,even if that will put their passengers at risk?What about making a sudden turn to avoid a dog?What if the only risk is damage to the car itself,not to the passengers?</p><p>Perhaps there will be lessons to learn from driverless car,also from all <a href="http://AI.So">AI.So</a> it’s a good topic to study for AI.</p><h2 id="Part-III">Part III</h2><h3 id="What-I-want-to-do-as-the-leader-of-“AI-FUTURES-AND-RESPONSIBILITY”">What I want to do as the leader of “AI: FUTURES AND RESPONSIBILITY”?</h3><p>I feel curious about AI apply to political domain. Contrary to many people’s worry,I keep optimistic that AI dominate human being in the future. There must be an optimal solution to achieve communism by AI in my assumption. In the future,nobody will worry how live at this world,everybody can do what he loves and is good at.</p><p>So I prefer to start this program to research the possibility that AI apply to political domain as a leader.</p>]]></content>
<categories>
<category> 学习 </category>
<category> 英语 </category>
</categories>
<tags>
<tag> 英语 </tag>
<tag> 学习 </tag>
</tags>
</entry>
<entry>
<title>Hello World</title>
<link href="/posts/4a17b156/"/>
<url>/posts/4a17b156/</url>
<content type="html"><![CDATA[<p>Welcome to <a href="https://hexo.io/">Hexo</a>! This is your very first post. Check <a href="https://hexo.io/docs/">documentation</a> for more info. If you get any problems when using Hexo, you can find the answer in <a href="https://hexo.io/docs/troubleshooting.html">troubleshooting</a> or you can ask me on <a href="https://github.com/hexojs/hexo/issues">GitHub</a>.</p><h2 id="Quick-Start">Quick Start</h2><h3 id="Create-a-new-post">Create a new post</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo new <span class="string">"My New Post"</span></span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/writing.html">Writing</a></p><h3 id="Run-server">Run server</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo server</span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/server.html">Server</a></p><h3 id="Generate-static-files">Generate static files</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo generate</span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/generating.html">Generating</a></p><h3 id="Deploy-to-remote-sites">Deploy to remote sites</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo deploy</span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/one-command-deployment.html">Deployment</a></p>]]></content>
</entry>
</search>