提交所有LaTeX文件。
This commit is contained in:
parent
10e6004666
commit
b2fb901612
25
操作系统/作业/mypreamble.tex
Normal file
25
操作系统/作业/mypreamble.tex
Normal file
@ -0,0 +1,25 @@
|
||||
\usepackage{amssymb, amsfonts, amstext, amsmath, amsopn, amsthm}
|
||||
\usepackage{booktabs}
|
||||
\usepackage{multicol}
|
||||
\usepackage{multirow}
|
||||
\usepackage{bm}
|
||||
\usepackage{hyperref}
|
||||
|
||||
\usepackage{fancyhdr}
|
||||
\usepackage{enumitem}
|
||||
\usepackage{totpages}
|
||||
\usepackage{mylatex}
|
||||
\usepackage{subfiles}
|
||||
|
||||
\title{《操作系统》作业}
|
||||
\author{岳锦鹏}
|
||||
\newcommand{\mysignature}{10213903403 岳锦鹏}
|
||||
\date{2024年3月29日——2024年6月18日}
|
||||
\setlist[1]{listparindent=\parindent}
|
||||
\setlist[2]{label=(\arabic{enumii}),listparindent=\parindent}
|
||||
\definecolor{shadecolor}{RGB}{204,232,207}
|
||||
\setminted{fontsize=\zihao{6}, baselinestretch=1}
|
||||
|
||||
\let\kaishu\relax % 清除旧定义
|
||||
\newCJKfontfamily\kaishu{KaiTi}[AutoFakeBold] % 重定义 \kaishu
|
||||
\newcommand{\boldkai}[1]{{\bfseries\kaishu #1}}
|
10
操作系统/作业/mysubpreamble.tex
Normal file
10
操作系统/作业/mysubpreamble.tex
Normal file
@ -0,0 +1,10 @@
|
||||
\pagestyle{fancyplain}
|
||||
\fancyhead{}
|
||||
\fancyhead[C]{\mysignature}
|
||||
\fancyfoot[C]{第 \thepage 页\quad 共 \ref{TotPages} 页}
|
||||
% \definecolor{shadecolor}{named}{white}
|
||||
\makeatletter
|
||||
\ctexset{
|
||||
chapter/break = \addpenalty{\@secpenalty}
|
||||
}
|
||||
\makeatother
|
10
操作系统/作业/全部作业.tex
Normal file
10
操作系统/作业/全部作业.tex
Normal file
@ -0,0 +1,10 @@
|
||||
\documentclass[a4paper]{ctexbook}
|
||||
\input{mypreamble}
|
||||
\begin{document}
|
||||
\maketitle
|
||||
\tableofcontents
|
||||
\subfile{第二章作业}
|
||||
\subfile{第三章作业}
|
||||
\subfile{第四章作业}
|
||||
\subfile{第五六章作业}
|
||||
\end{document}
|
204
操作系统/作业/第三章作业.tex
Normal file
204
操作系统/作业/第三章作业.tex
Normal file
@ -0,0 +1,204 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
\input{mysubpreamble}
|
||||
\begin{document}
|
||||
\setcounter{chapter}{2}
|
||||
\chapter{存储管理}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[]{
|
||||
一个 32 位的系统支持的逻辑空间最大为$2^{32}$字节,假如一个分页系统的页面大小为 4KB(即 $2^{12}$),一个页表项 4 个字节。请问:一个进程页表最多可有多少个表项?此时该进程的页表需要占多大的内存?
|
||||
}{
|
||||
按照题意来看,页表需要放到内存中,因此$2^{32}$字节的逻辑空间不能全部用来放分页页面。那么一个页面对应一个页表项,它们需要$2^{12}+4$字节,所以一个进程页表最多可有$$\dfrac{2^{32}}{2^{12}+4} = \dfrac{1073741824}{1025} \approx 1047552.99902439 \xrightarrow{\text{向下取整}} 1047552$$个表项。此时该进程的页表需要占$1047552\times 4 = 4190208$个字节的内存。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
在分页式系统中,其页表存放在内存中
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[]{
|
||||
如果对内存的一次存取需要 $100 \mathrm{\mu s}$,试问实现一次页面访问至少需要存取时间是多少?
|
||||
}{
|
||||
先访问一次页表,得到页面的地址以及是否缺页,此时如果没有缺页异常,直接从内存中就能访问到页面,所以实现一次页面访问至少需要存取时间为$100+100=200 \mathrm{\mu s}$。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
如果系统有快表,快表的命中率为 80\%,当页表项在快表中时,其查询快表的时间可忽略不计,试问此时平均存取时间为多少?
|
||||
}{
|
||||
当页表项在快表中时(并且没有缺页),此时可以认为一次页面访问只需要一次内存访问的时间,即$100 \mathrm{\mu s}$;所以此时平均存取时间(不考虑缺页)为
|
||||
$$
|
||||
\begin{aligned}
|
||||
EX &= 100 \mu \mathrm{s}\times P(快表命中) + 200 \mu \mathrm{s} \times P(快表未命中) \\
|
||||
&=100 \mu \mathrm{s} \times 0.8 + 200 \mu \mathrm{s} \times 0.2 = 120 \mu\mathrm{s} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
}
|
||||
\questionandanswer[]{
|
||||
采用快表后的平均存取时间比没有采用快表时下降了百分之几?
|
||||
}{
|
||||
$$
|
||||
1 - \frac{120}{200} = \frac{2}{5} = 0.4 = 40 \%
|
||||
$$
|
||||
下降了$40 \%$。
|
||||
}
|
||||
\end{enumerate}
|
||||
\questionandanswer[]{
|
||||
某虚拟存储器的用户编程空间共 32 个页面,每页1KB,主存为16KB。假定某时刻用户表中已调入主存的页面的虚拟页号和物理块号对照表为表一,则与逻辑地址相对应的物理地址为表二。\\
|
||||
\begin{minipage}{0.5\linewidth}
|
||||
\begin{center}
|
||||
\begin{tabular}{cc}
|
||||
\toprule
|
||||
虚拟页号 & 物理块号 \\
|
||||
\midrule
|
||||
0 & 5 \\
|
||||
1 & 10 \\
|
||||
2 & 4 \\
|
||||
8 & 7 \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
|
||||
表一
|
||||
\end{center}
|
||||
\end{minipage}
|
||||
\begin{minipage}{0.5\linewidth}
|
||||
\begin{center}
|
||||
\begin{tabular}{cc}
|
||||
\toprule
|
||||
逻辑地址 & 物理地址 \\
|
||||
\midrule
|
||||
0A5CH & A(\quad) \\
|
||||
1A5CH & B(\quad) \\
|
||||
925DH & C(\quad) \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
|
||||
表二
|
||||
\end{center}
|
||||
\end{minipage}
|
||||
|
||||
可供选择的答案:
|
||||
A,B,C:(1)缺页 (2)1E5DH (3)2A5CH (4)115CH (5)125CH(6)165CH (7)越界 (8)以上答案都不对
|
||||
}{
|
||||
|
||||
页面大小1KB,也就是$2^{10}$字节(其实准确说1KiB才是$2^{10}$字节,1KB是$10^{3}$字节),也就是逻辑地址的后10位代表页内偏移。
|
||||
|
||||
由于一共$32=2^{5}$个页面,所以(序号从右数0开始)第10到14位是页号,题目中的逻辑地址是4位十六进制数(最后的H表示这是十六进制数),也就是16位二进制数,因此第15位(最高位)必定为0,否则就是虚拟页号越界。以0A5CH为例:
|
||||
$$
|
||||
0|\underbrace{000\ 10}_{\text{虚拟页号}}|\underbrace{10\ 0101\ 1100}_{页内偏移}
|
||||
$$
|
||||
从逻辑地址转换到物理地址,只需要把虚拟页号换成对应的物理块号即可,这里虚拟页号为二进制的 00010 也就是十进制的2,对应的物理块号为4,也就是二进制的00100,转换后为
|
||||
$$
|
||||
0|\underbrace{001\ 00}_{\text{物理块号}}|\underbrace{10\ 0101\ 1100}_{页内偏移}
|
||||
$$
|
||||
转换成十六进制也就是125CH,所以A(5)。
|
||||
|
||||
同理,对于1A5CH,
|
||||
$$
|
||||
0|\underbrace{001\ 10}_{\text{虚拟页号}}|\underbrace{10\ 0101\ 1100}_{页内偏移}
|
||||
$$
|
||||
虚拟页号00110,即十进制的6,在表一中没有,所以是缺页,从而B(1)。
|
||||
|
||||
对于925DH
|
||||
$$
|
||||
1|\underbrace{001\ 00}_{\text{虚拟页号}}|\underbrace{10\ 0101\ 1101}_{页内偏移}
|
||||
$$
|
||||
最高位为1,根据前面的分析,虚拟页号越界,所以C(7)。
|
||||
|
||||
综上所述,A(5), B(1), C(7)。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
分页存储管理系统中,逻辑地址长度为 16,页面大小为4K。一个进程有 6 个页面,且页号为 1、2、3 的页面依次存放在物理块5、10、11 中,试问:
|
||||
}{
|
||||
|
||||
4K看作是$2^{12}$,也就是12位逻辑地址,也就是右起3位十六进制。逻辑地址长度为16,$16-12=4$位表示页号,所以左起1位十六进制表示页号。有6个页面,所以页号从0到5有效,否则越界。
|
||||
}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[]{
|
||||
逻辑地址 4010、8500 和 25000 所对应的物理地址分别为多少?
|
||||
}{
|
||||
这里的数字没有字母后缀,应该是十进制,需要先转化成十六进制。\\
|
||||
\begin{center}
|
||||
\begin{tabular}{ccc}
|
||||
\toprule
|
||||
十进制逻辑地址 & 十六进制逻辑地址 & 物理地址 \\
|
||||
\midrule
|
||||
4010 & 0|FAA & 缺页 \\
|
||||
8500 & 2|134 & A134 \\
|
||||
25000 & 6|1A8 & 越界 \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{center}
|
||||
}
|
||||
\questionandanswer[]{
|
||||
逻辑地址 2F6AH、0578H 和 6ACDH 所对应的物理地址分别为多少?
|
||||
}{
|
||||
\begin{center}
|
||||
\begin{tabular}{cc}
|
||||
\toprule
|
||||
逻辑地址 & 物理地址 \\
|
||||
\midrule
|
||||
2|F6A\ H & AF6A\ H \\
|
||||
0|578\ H & 缺页 \\
|
||||
6|ACD\ H & 越界 \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{center}
|
||||
}
|
||||
\end{enumerate}
|
||||
\questionandanswer[]{
|
||||
假定某采用页式存储管理的系统中,主存容量为1M,被分成256 块,块号为 0、1、2、…、255。现有一个共 4 页(页号为0、1、2、3)的作业被依次装入到主存的块 2、4、1、5 中。请回答:
|
||||
}{}
|
||||
|
||||
% 啊?为什么这里如果不加空行,后面就没有parindent了?加了一个空行就重新出现parindent了?
|
||||
\begin{enumerate}
|
||||
\questionandanswer[]{
|
||||
主存地址应该用多少位来表示?
|
||||
}{
|
||||
1M省略了单位,应该是指1MB,看作是$2^{20}$字节,由于寻址的单位为字节,所以主存地址应该用20位来表示。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
作业每一页的长度为多少字节?逻辑地址中的页内地址部分应占用多少位?
|
||||
}{
|
||||
1MB $=2^{20}$字节,分成$256=2^{8}$块,所以每块的大小为$\frac{2^{20}}{2^{8}}=2^{12}$字节,块大小和页大小一样,因此作业每一页的长度为$2^{12}$字节,逻辑地址中的页内地址部分应占用12位。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
把作业中每一页占用的主存块起始地址填入下表。
|
||||
}{
|
||||
\begin{center}
|
||||
\begin{tabular}{cc}
|
||||
\toprule
|
||||
页号 & 起始地址 \\
|
||||
\midrule
|
||||
0 & 02\ 000\ H \\
|
||||
1 & 04\ 000\ H \\
|
||||
2 & 01\ 000\ H \\
|
||||
3 & 05\ 000\ H \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{center}
|
||||
}
|
||||
\questionandanswer[]{
|
||||
若作业执行中要从第 0 页的第 75 单元和第 3 页的第 548 单元读信息,那么,实际应从主存的哪两个单元读信息?请把应访问的主存绝对地址用二进制编码的十六进制数表示。
|
||||
}{
|
||||
|
||||
这里“二进制编码的十六进制数”表述不清,直接描述成“十六进制”或许更好。
|
||||
第 0 页的第 75 单元为 0x02\,048,第 3 页的第 548 单元为 0x05\,224。
|
||||
}
|
||||
\end{enumerate}
|
||||
\questionandanswer[]{
|
||||
在请求式分页系统中,运行一个共有 8 页的作业,且作业在主存中分配到 4 块主存块,作业执行时访问页面顺序为 7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0,1,7,0,1,假如最初四个页面通过缺页中断装入,请问用最佳置换算法、先入先出(FIFO)算法和最近最久未使用(LRU)算法时,它们的页面缺页和置换次数分别为多少?(要求画出页面置换图)
|
||||
}{
|
||||
\begin{center}
|
||||
\includexopp{3.6.1}
|
||||
(图中标了$\times $的是发生置换的)
|
||||
\vspace{1em}
|
||||
|
||||
\begin{tabular}{ccc}
|
||||
\toprule
|
||||
页面置换算法 & 页面缺页次数 & 置换次数 \\
|
||||
\midrule
|
||||
最佳置换(Opt) & 8 & 4 \\
|
||||
先入先出(FIFO) & 10 & 6 \\
|
||||
最近最久未使用(LRU) & 8 & 4 \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{center}
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
283
操作系统/作业/第二章作业.tex
Normal file
283
操作系统/作业/第二章作业.tex
Normal file
@ -0,0 +1,283 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
\input{mysubpreamble}
|
||||
\begin{document}
|
||||
\setcounter{chapter}{1}
|
||||
\chapter{进程与线程}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[]{
|
||||
设有一台计算机,有两条 I/O 通道,分别挂一台输入机和一台打印机。若要把输入机上的数据逐一地输入到缓冲区 B1 中,然后处理,并把结果搬到缓冲区B2中,最后在打印机上输出。请问:
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[]{
|
||||
系统可设置哪些进程完成这一任务?这些进程间有什么具体制约关系?
|
||||
}{
|
||||
\noindent
|
||||
进程一:把输入机上的数据逐一地输入到缓冲区 B1 中;\\
|
||||
进程二:从缓冲区 B1 中取数据,处理后把结果放到缓冲区B2中;\\
|
||||
进程三:从缓冲区 B2 中取数据,在打印机上输出。
|
||||
|
||||
这里的“逐一地”“缓冲区”等关键词表明是单个缓冲区而不是缓冲队列。那么进程一和进程二之间关于缓冲区B1存在同步的制约关系,进程二和进程三之间关于缓冲区B2存在同步的制约关系。(这里不需要互斥)
|
||||
}
|
||||
\questionandanswer[]{
|
||||
用 P-V 操作写出这些进程的同步算法。
|
||||
}{}
|
||||
{\kaishu\noindent
|
||||
\begin{minipage}{0.4\linewidth}
|
||||
\begin{minted}{C}
|
||||
struct semaphore B1_empty = 1, B1_full = 0, B2_empty = 1, B2_full = 0;
|
||||
number temp1, temp2, temp3;
|
||||
buffer B1, B2;
|
||||
cobegin
|
||||
void process1() {
|
||||
while(1) {
|
||||
temp1 = input();
|
||||
P(B1_empty);
|
||||
B1 = temp1;
|
||||
V(B1_full);
|
||||
}
|
||||
}
|
||||
void process2() {
|
||||
while(1) {
|
||||
P(B1_full);
|
||||
temp2 = B1_full;
|
||||
V(B1_empty);
|
||||
temp2 = processing(temp2);
|
||||
P(B2_empty);
|
||||
B2_full = temp2;
|
||||
V(B2_full);
|
||||
}
|
||||
}
|
||||
void process3() {
|
||||
while(1) {
|
||||
P(B2_full);
|
||||
temp3 = B2_full;
|
||||
V(B2_empty);
|
||||
output(temp3);
|
||||
}
|
||||
}
|
||||
coend
|
||||
\end{minted}
|
||||
\end{minipage}
|
||||
% \columnbreak
|
||||
\begin{minipage}{0.6\linewidth}
|
||||
\includexopp{2.1.2.1}
|
||||
\end{minipage}
|
||||
}
|
||||
\questionandanswer[]{
|
||||
用Send和Receive原语写出这些进程的同步算法。
|
||||
}{}
|
||||
{\kaishu\noindent
|
||||
\begin{minipage}{0.4\linewidth}
|
||||
\begin{minted}{C}
|
||||
cobegin
|
||||
void process1() {
|
||||
number item;
|
||||
message m;
|
||||
while (1) {
|
||||
item = input();
|
||||
m = build_message(item);
|
||||
Send(process2, &m);
|
||||
}
|
||||
}
|
||||
void process2() {
|
||||
number item;
|
||||
message m;
|
||||
while (1) {
|
||||
Receive(process1, &m);
|
||||
item = extract_item(&m);
|
||||
item = processing(item);
|
||||
m = build_message(item);
|
||||
Send(process3, &m);
|
||||
}
|
||||
}
|
||||
void process3() {
|
||||
number item;
|
||||
message m;
|
||||
while (1) {
|
||||
Receive(process2, &m);
|
||||
item = extract_item(&m);
|
||||
output(item);
|
||||
}
|
||||
}
|
||||
coend
|
||||
\end{minted}
|
||||
\end{minipage}
|
||||
% \columnbreak
|
||||
\begin{minipage}{0.6\linewidth}
|
||||
\includexopp{2.1.3.1}
|
||||
\end{minipage}
|
||||
}
|
||||
\end{enumerate}
|
||||
|
||||
\questionandanswer[]{
|
||||
“哲学家就餐问题”除课堂上介绍的方案外,有没有其他解决方案?有的话,请
|
||||
写出相应的解决方案。
|
||||
}{}
|
||||
{\kaishu
|
||||
有,比较容易想到的一种最简单的方案是,每次只允许一个哲学家就餐,也就是将所有的叉子视为一个整体的临界资源,但是缺点也很明显,会导致性能低下,因为五个叉子可以满足两个哲学家同时就餐。因此下面使用另一种方案。
|
||||
|
||||
大致方案是偶数序号的哲学家先拿左边的叉子,奇数序号哲学家先拿右边的叉子(释放的时候就不需要讲究先放左边还是先放后边了)。
|
||||
% \begin{multicols}{2}
|
||||
\begin{minted}{C}
|
||||
struct semaphore forks[5] = {1, 1, 1, 1, 1};
|
||||
void philosopher(i) {
|
||||
while (1) {
|
||||
think;
|
||||
if (i % 2) {
|
||||
P(forks[(i + 1) % 5]);
|
||||
P(forks[i])
|
||||
} else {
|
||||
P(forks[i]);
|
||||
P(forks[(i + 1) % 5]);
|
||||
}
|
||||
eat;
|
||||
V(forks[i]);
|
||||
V(forks[(i + 1) % 5]);
|
||||
}
|
||||
}
|
||||
\end{minted}
|
||||
% \end{multicols}
|
||||
}
|
||||
\questionandanswer[]{
|
||||
a,b两点之间是一段东西向的单行车道,现要设计一个自动管理系统,管理的
|
||||
规则如下:当a,b之间有车辆在行驶时同方向的车可以同时驶入a,b段,但另一个
|
||||
方向的车必须在a,b段以外等待;当a,b之间无车辆在行驶时,到达a点(或b点)
|
||||
的车辆可以进入a,b段,但不能同时驶入;当某方向在a,b段行驶的车辆驶出了a,
|
||||
b 段且暂无车辆进入a,b段时,应让另一方向等待的车辆进入a,b段行驶。请用PV
|
||||
操作作为工具,对a,b段实现正确管理以确保行驶安全。
|
||||
}{}
|
||||
{\kaishu
|
||||
可能会存在一个问题,就是一个方向一直有车辆,导致另一个方向无法进入车道,从而产生很长的排队。
|
||||
|
||||
还有个问题,是否要考虑车辆排队的过程,即先入先出,或先排队先进入。
|
||||
|
||||
这里先不考虑这两个问题。
|
||||
|
||||
这种问题大多数做法都是使用两个互斥量和两个计数值,这里尝试使用一个互斥量和一个计数值,计数值为正表示从a到b有车辆,计数值为负表示从b到a有车辆。但是缺点是发生任何一个事件(a或b方向进入或离开车辆)都需要访问临界资源(使用同一个 \mintinline{C}{mutex} 信号量),可能会导致性能较低。
|
||||
|
||||
\begin{multicols}{2}
|
||||
\begin{minted}{C}
|
||||
struct semaphore mutex = 1, s = 1;
|
||||
// 车道内的车辆数
|
||||
int count = 0; // 正数为从a到b,负数为从b到a
|
||||
cobegin
|
||||
void a_to_b() {
|
||||
P(mutex);
|
||||
if (count <= 0) {
|
||||
P(s);
|
||||
}
|
||||
count++;
|
||||
V(mutex);
|
||||
通过 a -> b;
|
||||
P(mutex);
|
||||
count--;
|
||||
assert(count >= 0);
|
||||
if (count == 0) {
|
||||
V(s);
|
||||
}
|
||||
V(mutex);
|
||||
}
|
||||
|
||||
|
||||
void b_to_a() {
|
||||
P(mutex);
|
||||
if (count >= 0) {
|
||||
P(s);
|
||||
}
|
||||
count--;
|
||||
V(mutex);
|
||||
通过 b -> a;
|
||||
P(mutex);
|
||||
count++;
|
||||
assert(count <= 0);
|
||||
if (count == 0) {
|
||||
V(s);
|
||||
}
|
||||
V(mutex);
|
||||
}
|
||||
coend
|
||||
\end{minted}
|
||||
\end{multicols}
|
||||
}
|
||||
\questionandanswer[]{
|
||||
假定有三个进程R、W1、W2共享一个缓冲区B,B中每次只能存放一个整数。
|
||||
进程R每次启动输入设备读一个整数且把它存放在缓冲区B中,若存放到缓冲区B中
|
||||
的是奇数,则由进程W1将其取出打印,否则由进程W2将其取出打印。要求用PV操
|
||||
作管理这3个并发进程,使它们能够正确同步工作。
|
||||
}{}
|
||||
{\kaishu
|
||||
这里使用了三个信号量实现R与W1的同步、R与W2的同步,一个信号量实现了打印的互斥。
|
||||
|
||||
\begin{minipage}{0.4\linewidth}
|
||||
\begin{minted}{C}
|
||||
struct semaphore odd = 0, even = 0, empty = 1;
|
||||
struct semaphore output_mutex;
|
||||
buffer B;
|
||||
cobegin
|
||||
void R() {
|
||||
int temp;
|
||||
while (1) {
|
||||
temp = input();
|
||||
P(empty);
|
||||
B = temp;
|
||||
if (temp % 2) {
|
||||
V(odd);
|
||||
} else {
|
||||
V(even);
|
||||
}
|
||||
}
|
||||
}
|
||||
void W1() {
|
||||
int temp;
|
||||
while (1) {
|
||||
P(odd);
|
||||
temp = B;
|
||||
V(empty);
|
||||
P(output_mutex);
|
||||
output(temp);
|
||||
V(output_mutex);
|
||||
}
|
||||
}
|
||||
void W2() {
|
||||
int temp;
|
||||
while (1) {
|
||||
P(even);
|
||||
temp = B;
|
||||
V(empty);
|
||||
P(output_mutex);
|
||||
output(temp);
|
||||
V(output_mutex);
|
||||
}
|
||||
}
|
||||
coend
|
||||
\end{minted}
|
||||
\end{minipage}
|
||||
\begin{minipage}{0.6\linewidth}
|
||||
\includexopp{2.4.1}
|
||||
\end{minipage}
|
||||
}
|
||||
\questionandanswer[]{
|
||||
假定在一个CPU上执行以下5个作业:(优先数小者优先级高)
|
||||
|
||||
\begin{center}
|
||||
\begin{tabular}{|c|c|c|c|c|c|}
|
||||
\hline
|
||||
作业号 & 1 & 2 & 3 & 4 & 5 \\
|
||||
\hline
|
||||
到达时间 & 0 & 2 & 4 & 6 & 8 \\
|
||||
\hline
|
||||
优先数 & 4 & 3 & 5 & 2 & 1 \\
|
||||
\hline
|
||||
运行时间 & 3 & 6 & 4 & 5 & 2 \\
|
||||
\hline
|
||||
\end{tabular}
|
||||
\end{center}
|
||||
|
||||
当分别采用FCFS、RR(时间片为1)、非抢占式SJF、抢占式SJF、优先级调度5
|
||||
种调度算法时,试(1)画出调度图(2)计算每个作业的周转时间(3)计算平均周转
|
||||
时间。
|
||||
}{
|
||||
\includexopp{2.5.1}
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
106
操作系统/作业/第五六章作业.tex
Normal file
106
操作系统/作业/第五六章作业.tex
Normal file
@ -0,0 +1,106 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
\input{mysubpreamble}
|
||||
\begin{document}
|
||||
\setcounter{chapter}{4}
|
||||
\chapter{I/O设备管理}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[]{
|
||||
假定某磁盘共有 200 个柱面(编号为 0$\sim $199),如果在为访问80 号柱面的请求者服务后,当前正在为访问 108 号柱面的请求者服务,同时有若干个请求者在等待服务,它们依次要访问的柱面号为:
|
||||
|
||||
187,64,169,48,171,118,120,84
|
||||
\begin{enumerate}
|
||||
\item 分别用先来先服务(FCFS)、最短寻道时间优先(SSTF)、扫描(SCAN)和循环扫描(CSCAN)算法进行磁盘调度时,试确定实际的服务次序。
|
||||
\item 按实际服务次序计算(1)中四种算法下磁臂移动的距离。
|
||||
\end{enumerate}
|
||||
}{
|
||||
\includexopp{5.1.1}
|
||||
|
||||
每次磁臂移动的距离已经用蓝色字标在两次访问的柱面号之间,要注意循环扫描的返回是瞬间完成,不应算到磁臂移动的距离中。
|
||||
}
|
||||
\end{enumerate}
|
||||
\chapter{死锁}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[]{
|
||||
在某系统中,有 N 个进程共享 R 台同类设备资源,每个进程最多需要M台设备资源,试问:N 最多为几时才能保证系统不会发生死锁?请简略说明原因。
|
||||
}{
|
||||
% N最多为 $\bm{\left\lfloor R / M \right\rfloor}$ 时才能保证系统不会发生死锁。因为当N达到这个值时,如果此时所有进程都按照最大资源数量申请,那么总申请的资源数量为$\left\lfloor R / M \right\rfloor \times M \leqslant R$,所以不会发生死锁,但如果N多一个,那么总申请的资源数量为$\left( \left\lfloor R / M \right\rfloor+1 \right) \times M$这就可能大于R,那么就可能发生死锁。
|
||||
|
||||
(这里的N、R、M应该均为正整数)
|
||||
|
||||
当N固定时,根据抽屉原理,每个进程都恰好分到最大资源数量少一个资源,并且都申请一个资源,这时如果没有资源可以分配,那么就死锁了;如果有至少一个资源可以分配,那么就不会死锁。所以R最少应取$N\times (M-1) + 1$才能保证不会发生死锁,那么
|
||||
$$
|
||||
R\geqslant N\times (M-1)+1 \implies N \leqslant \frac{R-1}{M-1}
|
||||
$$
|
||||
因为N为整数,所以N最多为$\displaystyle \left\lfloor \frac{R-1}{M-1} \right\rfloor$。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
考虑有 3 个进程共享 9 个资源,当前资源分配情况如下:
|
||||
\begin{center}
|
||||
\begin{tabular}{ccc}
|
||||
\toprule
|
||||
进程 & 已占资源数 & 最大需求量 \\
|
||||
\midrule
|
||||
P1 & 2 & 6 \\
|
||||
P2 & 3 & 6 \\
|
||||
P3 & 1 & 5 \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{center}
|
||||
请回答以下问题:
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[]{
|
||||
目前系统是否处于安全状态?为什么?
|
||||
}{
|
||||
目前已占资源总数为6,那么还有3个资源,这时如果分配给P2,P2就达到了最大需求量,那么P2运行结束后就有6个空闲资源,这时可以分配给P1 4个资源,P1就达到了最大需求量,P1运行结束后分配给P3 4个资源,P3就达到了最大需求量,P3运行完后就结束了。\boldkai{所以可以找到资源分配安全序列 P2、P1、P3,所以目前系统处于安全状态。}示意图如下:
|
||||
\bigskip
|
||||
\includexopp[1.2]{6.2.1.1}
|
||||
}
|
||||
\questionandanswer[]{
|
||||
如果接着 3 个进程均再申请 2 个资源,可以先分配资源给哪个进程?
|
||||
}{
|
||||
在未实际分配资源时,安全序列不变,仍然为P2、P1、P3,所以可以先分配资源给\boldkai{P2}。
|
||||
}
|
||||
\end{enumerate}
|
||||
\questionandanswer[]{
|
||||
假如系统中有 5 个进程{P0,P1,P2,P3,P4}和4 种类型资源{A,B,C,D},T0 时刻系统的资源分配情况如下所示:
|
||||
\begin{center}
|
||||
\begin{tabular}{c|cccc|cccc|cccc}
|
||||
\toprule
|
||||
进程 & \multicolumn{4}{c}{Al} \vline& \multicolumn{4}{c}{Need} \vline & \multicolumn{4}{c}{Av} \\
|
||||
\midrule
|
||||
P0 & 0 & 2 & 3 & 2 & 0 & 0 & 1 & 2 & 1 & 6 & 2 & 2 \\
|
||||
P1 & 1 & 0 & 0 & 0 & 1 & 7 & 5 & 0 & & & & \\
|
||||
P2 & 1 & 3 & 5 & 4 & 2 & 3 & 5 & 6 & & & & \\
|
||||
P3 & 0 & 3 & 3 & 2 & 0 & 6 & 5 & 2 & & & & \\
|
||||
P4 & 1 & 0 & 1 & 4 & 0 & 6 & 5 & 6 & & & & \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{center}
|
||||
试问:
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[]{
|
||||
T0 时刻该系统是否安全?
|
||||
}{
|
||||
尝试寻找安全序列如下图所示:
|
||||
\includexopp[1.3]{6.4.1.1}
|
||||
成功找到安全序列P0、P1、P3、P2、P4,所以T0 时刻系统\boldkai{安全}。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
T1 时刻进程 P2 提出资源请求 Re2(1,2, 0,0),能否将资源分配给它?
|
||||
}{
|
||||
Re2 < Av,进行试探性分配,尝试寻找安全序列如下图所示:
|
||||
\includexopp[1.3]{6.4.2.1}
|
||||
与T0 时刻相比有不同的地方已用红色标出,所以成功找到安全序列P0、P3、P4、P1、P2,所以\boldkai{能}将资源分配给它。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
T2 时刻进程 P3 提出资源请求 Re3(0, 0,2,2),能否将资源分配给它?
|
||||
}{
|
||||
Re3 < Av,进行试探性分配,尝试寻找安全序列如下图所示:
|
||||
\includexopp[1.2]{6.4.3.1}
|
||||
发现找不到安全序列,所以\boldkai{不能}将资源分配给它。
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{enumerate}
|
||||
\end{document}
|
83
操作系统/作业/第四章作业.tex
Normal file
83
操作系统/作业/第四章作业.tex
Normal file
@ -0,0 +1,83 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
\input{mysubpreamble}
|
||||
\begin{document}
|
||||
\setcounter{chapter}{3}
|
||||
\chapter{文件系统}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[]{
|
||||
一个文件系统的盘块大小为1KB,每块地址用4B表示,当分别采用连
|
||||
续、链接、二级索引和UNIX S V 分配方案时,试确定各方案能管理的最大文件,
|
||||
管理一个10MB的大文件和一个10KB的小文件时所需的管理专用块数,以及要
|
||||
访问大文件的第9M+3.5KB单元时需要的磁盘I/O操作次数。
|
||||
|
||||
A$\sim $D:(1)不受限制 (2)1KB (3)256KB (4)64MB
|
||||
(5)16GB (6)1KB+256KB+64MB+16GB
|
||||
(7)10KB+256KB+64MB+16GB
|
||||
}{
|
||||
二级索引管理的最大文件:
|
||||
$$
|
||||
256\times 256\times 1 \mathrm{KB} = 2^{8}\times 2^{8}\times 1 \mathrm{KB} = 2^{16}\mathrm{KB} = 2^{6} \mathrm{MB} = 64 \mathrm{MB}
|
||||
$$
|
||||
二级索引专用块数:
|
||||
$$
|
||||
10\text{KB}/1\text{KB} =10 \text{个存储块}
|
||||
$$
|
||||
$$
|
||||
\left\lceil 10/256 \right\rceil = 1 \text{个二级索引块}, \quad \left\lceil 1/256 \right\rceil =1 \text{个一级索引块}
|
||||
$$
|
||||
$$
|
||||
10\text{MB}/1\text{KB}=10\times 2^{10}\text{个存储块}
|
||||
$$
|
||||
$$
|
||||
10\times 2^{10}/256 = 10\times 2^{2} = 40 \text{个二级索引块}, \quad \left\lceil 1/256 \right\rceil =1 \text{个一级索引块}
|
||||
$$
|
||||
UNIX专用块数:
|
||||
$$
|
||||
10\text{MB}-10\text{KB}-256\text{KB} = (10\times 2^{20} - 10\times 2^{10} - 256\times 2^{10}) = 10213376\text{B} = 9974\text{KB}
|
||||
$$
|
||||
$$
|
||||
\left\lceil 9974/256 \right\rceil = 39 \text{个二级索引块}, \quad \left\lceil 39/256 \right\rceil =1 \text{个一级索引块}
|
||||
$$
|
||||
$$
|
||||
1+39+1=41 \text{个管理专用块}
|
||||
$$
|
||||
大文件的某处信息需要的IO次数:
|
||||
$$
|
||||
\left\lceil 9\times 2^{10} +3.5 \right\rceil + 1 = 9221
|
||||
$$
|
||||
\begin{center}
|
||||
\begin{tabular}{cccccc}
|
||||
\toprule
|
||||
& & 连续分配 & 链接分配 & 二级索引 & UNIX \\
|
||||
\midrule
|
||||
\multicolumn{2}{c}{管理的最大文件} & A(1) & B(1) & C(4) & D(7) \\
|
||||
\hline
|
||||
\multirow{2}{*}{管理用的专用块数} & 10KB 文件 & 0 & 0 & 2 & 0 \\
|
||||
& 10MB 文件 & 0 & 0 & 41 & 41 \\
|
||||
\hline
|
||||
大文件的某处信息 & 9M+3.5KB & 1 & 9221 & 3 & 3 \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{center}
|
||||
}
|
||||
\questionandanswer[]{
|
||||
在 Unix 文件系统中,文件的物理组织为 Unix 直接间接混合寻址方式,假设一个进程要在第 4200 字节、第 210000 字节和第800000 字节三个偏移处读文件,请问分别要访问多少次磁盘?并以必要的图示说明访问之过程。假设该文件的 FCB(即文件说明或文件控制块)已读入内存,每个磁盘块大小为1K,块号用 32 位的指针表示。
|
||||
}{
|
||||
32位即4B,所以一个索引块能存储 $1\text{KB}/4\text{B}=256\text{个块指针}$。
|
||||
|
||||
\includexopp[1.1]{4.2.1}
|
||||
|
||||
图中用不同颜色写出了不同偏移处的计算步骤以及访问过程。访问磁盘次数即不同颜色的箭头数量,在第 4200 字节、第 210000 字节和第800000 字节三个偏移处读文件,分别要访问1、2、3次磁盘。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
假设文件系统的盘块大小为 4KB, 某文件的物理结构采用连续文件方式,假设该文件的首个盘块的盘块号为 85,那么该文件的第8292 字节单元在第几个盘块上?其盘块号为多少?该字节单元是盘块内的第几字节?
|
||||
}{
|
||||
$$
|
||||
8292\text{B}/4\text{KB} = 8292 \div (4\times 2^{10}) = 2 \cdots\cdots 100
|
||||
$$
|
||||
\includexopp[1]{4.3.1}
|
||||
|
||||
所以该文件的第8292字节单元在第3个盘块上,其盘块号为87,该字节单元是盘块内的第101字节。
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
65
操作系统/实验报告/Lab1.tex
Normal file
65
操作系统/实验报告/Lab1.tex
Normal file
@ -0,0 +1,65 @@
|
||||
\documentclass[a4paper]{ctexart}
|
||||
\input{mypreamble}
|
||||
\renewcommand{\mylabname}{系统软件启动过程}
|
||||
\renewcommand{\mydate}{2024年3月26日}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{完成相关实验内容后,回答以下问题:}{
|
||||
\questionandanswer[]{
|
||||
为何要开启A20? uCore OS是如何开启A20的?
|
||||
}{
|
||||
如果不开启A20会导致地址线第21位永远为0,无法完整进行内存寻址。uCore OS通过向8042键盘控制器的命令端口和数据端口发送命令和数据来开启A20。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
试分析段描述符表(GDT )的结构,说明段描述符中每个字段的含义以及作用。uCore OS是如何初始化GDT表的?
|
||||
}{
|
||||
% 段选择子的每个元素为16位,前13位是INDEX,表示这个段选择子在GDT数组或LDT数组的索引号;第14位是Table Indicator,这个值为0表示查找GDT,1则查找LDT;最后两位是Request Privilege Level,表示以什么样的权限去访问段。
|
||||
\begin{center}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-03-26-21-17-25.png}
|
||||
\end{center}
|
||||
uCore OS初始化了一个空的表项、一个内核代码段、一个内核数据段。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
实模式和保护模式有何不同?uCore OS是如何使能和进入保护模式的?
|
||||
}{
|
||||
实模式的寻址范围不超过1M,并且没有分段机制等,而保护模式的寻址范围则没有1M的限制,并且可以实现分段机制等。uCore OS通过把控制寄存器的0位设置成1来使能和进入保护模式。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
Bootloader是如何利用ELF文件头的相关属性加载和运行uCore OS Kernel的?
|
||||
}{
|
||||
首先判断文件头的e\_magic是否等于ELF\_MAGIC,之后根据e\_phoff找到程序头表的位置,在程序头表中找到分段数和各个分段的偏移位置、大小,接着把各个分段加载到内存中,最后跳转到e\_entry入口开始执行。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
分析中断描述符表(IDT)的结构,说明中断描述符中每个字段的含义以及作用。 uCore OS是如何实现中断机制的?
|
||||
}{
|
||||
中断描述符表中的每个表项称为中断描述符,它可以确定相应的中断处理程序的位置,中断描述符的结构和每个字段的含义以及作用如下:
|
||||
\begin{center}
|
||||
\includegraphics[width=1\linewidth]{imgs/IDT1.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/IDT2.png}
|
||||
\end{center}
|
||||
它确定了段选择子、段内偏移、该段是否已调入内存、该中断的特权级、中断类型(中断门或者陷阱门)等。
|
||||
|
||||
uCore OS将每个中断门都初始化为带中断号参数的调用(最后调用trap.c中的内容),之后把系统调用的中断门的特权级设置为用户态,最后加载中断描述符表寄存器。
|
||||
}
|
||||
}
|
||||
\myitem{程序设计与实现的基本思路}{
|
||||
\item 大部分实现的功能在trap.c文件中,首先从实验视频中可以得知,在触发中断后会进入trap.c的执行流程,之后根据不同的中断号执行不同的流程,由于题目要求通过键盘中断实现计时器,因此主要关注键盘中断和时钟中断;
|
||||
\item 根据题意,在键盘按下S时开始,P暂停,E停止,C继续,A正计时,B倒计时。那么首先考虑键盘中断,这里很明显很适合用switch语句,根据键盘中断后得到的字符不同,执行不同的流程;
|
||||
\item 这里还需要注意整个功能是存在不同的状态的(其实是因为单线程才会有这么多状态,如果多线程都不需要考虑状态,事件驱动就行),首先很明显可以知道有正在计时状态和停止状态。然后我们考虑这两个状态会在什么时候互相转化,从停止状态转到开始状态可以是按下S或者C,从开始状态转到停止状态可以是按下P或E,或者是倒计时到0了。而且题目需要实现正计时和倒计时,这是两种不同的模式,因此还需要一个状态变量记录当前的模式,通过按A和B切换;
|
||||
\item 还要注意,当按了B后进入倒计时,此时要输入时间,但是这时候还没有gets等函数的实现,需要自己通过键盘中断进行输入,那么在键盘中断的时候就不仅需要捕获字母,也需要捕获数字,但我们不希望在输入数字的时候不小心输入了字母就打断了数字输入,这时候就需要增加状态了,需要一个状态表示正在输入数字,在按下B后切换到这个状态,当按下Enter后切换到计时状态或停止状态;
|
||||
\item 当倒计时到0的时候,应该切换到停止状态,并且还需要输出一条信息表示当前计时到0了,但是这里就要注意,从计时状态切换到停止状态时不应该输出这条信息,因此这里需要多加一个中间状态,用来表示倒计时结束的准备输出,这个状态在下一次时钟中断(可以类比数字逻辑电路中,同步时序电路,在时钟有效边沿到来时)转换到停止状态,并且输出这条信息;
|
||||
\item 关于检测频率,原先的计时器在每次时钟中断时执行ticks++,而时钟中断频率在clock.c文件中设置的是时钟频率除以100,也就是每0.01秒触发一次,尝试过改成除以1000,但会导致走时变慢,应该是因为触发中断太频繁了时间开销太大,也尝试过改成除以10,又会导致走时过快,看来还是原始的除以100最准时;
|
||||
\item 既然每0.01秒触发一次中断,那么如果是每TICK\_NUM次中断打印一次时间,直观感受就是精度为 TICK\_NUM * 0.01 秒,按照题目要求那么TICK\_NUM应该取10,当然为了提升精度也可以取更小,比如1;
|
||||
\item 当键入退格时字符为$\backslash$b,用于在输入数字时进行退格;当键入回车时字符为$\backslash$n,用于确定倒计时的时间;循环打印时间时需要使用$\backslash$r,表示将光标回到当前行的开头,这样再打印时间就会把之前的时间覆盖掉;
|
||||
\item 当然还存在一些bug,比如从10.000倒计时到9.990时就会无法覆盖最后一个0,导致看起来是9.9900;还有时间精度还是不准的问题;欢迎给出修复建议(可以通过Issue的方式,下面会给出网址)。
|
||||
}
|
||||
\myitem{代码}{
|
||||
\item \url{https://gitea.shuishan.net.cn/10213903403/os_kernel_lab}
|
||||
\item 也可以看上传的附件。
|
||||
}
|
||||
注:\mycircle{1} 要求实验报告以及代码以附件形式提交。
|
||||
\mycircle{2} 实验报告提交的截止期为4月1日。
|
||||
\end{enumerate}
|
||||
\end{document}
|
156
操作系统/实验报告/Lab2.tex
Normal file
156
操作系统/实验报告/Lab2.tex
Normal file
@ -0,0 +1,156 @@
|
||||
\documentclass[a4paper]{ctexart}
|
||||
\input{mypreamble}
|
||||
\renewcommand{\mychapternum}{2}
|
||||
\renewcommand{\mylabname}{物理内存管理}
|
||||
\renewcommand{\mydate}{2024年4月16日}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\item{\textbf{研读理解相关代码后,回答以下问题:}}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[]{
|
||||
uCore如何探测物理内存布局,其返回结果e820映射结构是什么样的?分别表示什么?
|
||||
}{}
|
||||
{\kaishu
|
||||
首先探测物理内存布局可以通过BIOS中断或直接探测,其中BIOS中断调用方法通常只能在实模式下完成,直接探测的方法必须在保护模式下完成,这里$\mu$Core 是在实模式下通过BIOS中断调用完成的。具体可以分为以下三步骤:
|
||||
\begin{enumerate}
|
||||
\item 设置一个存放内存映射地址描述符的物理地址(在此为0x8000);
|
||||
\item 将e820作为参数传递给INT 15h中断;
|
||||
\item 通过检测eflags的CF位来判断探测是否结束。如果CF位为0,则表示探测没有结束,那么就需要设置存放下一个内存映射地址描述符的物理地址,返回步骤2继续进行;否则物理内存检测就此结束。
|
||||
\end{enumerate}
|
||||
|
||||
其返回结果e820的结构为:
|
||||
\begin{minted}[fontsize=\zihao{-5}]{C}
|
||||
struct e820map {
|
||||
int nr_map;
|
||||
struct {
|
||||
uint64_t addr;
|
||||
uint64_t size;
|
||||
uint32_t type;
|
||||
} __attribute__((packed)) map[E820MAX];
|
||||
};
|
||||
\end{minted}
|
||||
其中\mintinline{C}{nr_map}表示内存映射地址描述符的数量,\mintinline{C}{addr}表示系统内存块基地址,\mintinline{C}{size}表示系统内存块大小,\mintinline{C}{type}表示内存类型。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
uCore中的物理内存空间管理采用什么样的方案?跟我们理论课中的哪个方案相似?有何不同之处?
|
||||
}{
|
||||
$\mu$Core 中的物理内存管理采用段页式系统,但是简化了分段机制,将逻辑地址直接恒等映射到线性地址,之后使用分页机制将线性地址通过分页映射到物理地址。由于使用了分页机制,因此需要对空闲物理块管理,对空闲物理块的管理使用了链表来管理,链表按照地址排序。
|
||||
|
||||
跟我们理论课中的“段页式存储管理”和“使用链表管理存储空间”的方案相似,不同之处在于分段机制简化了,并且只使用链表管理了空闲物理块(已分配的物理块在页表中有记录,所以不需要管理)。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
Page数据结构中每个字段含义与作用是什么?如何表示某物理块分配与否?字段property的作用是什么?如何表示 property是否有效?
|
||||
}{}
|
||||
{\kaishu
|
||||
\begin{minted}[fontsize=\zihao{-5}]{C}
|
||||
struct Page {
|
||||
int ref; // page frame's reference counter
|
||||
uint32_t flags; // array of flags that describe the status of the page frame
|
||||
unsigned int property; // the num of free block, used in first fit pm manager
|
||||
list_entry_t page_link; // free list link
|
||||
};
|
||||
\end{minted}
|
||||
|
||||
\mintinline{C}{ref}字段表示此物理块被引用的个数,如果大于1代表这个物理块对应的可能是共享内存;\mintinline{C}{flags}的0位表示此物理块是否已被分配,0位为1代表已被分配;1位代表此描述符的\mintinline{C}{property}字段是否有效,1位为1代表有效。\mintinline{C}{property}只有在此物理块是空闲块时才有效,表示从此物理块开始连续的空闲物理块的数量。
|
||||
|
||||
用\mintinline{C}{flags}的0位表示此物理块是否已被分配,0位为1代表已被分配。
|
||||
|
||||
\mintinline{C}{property}的作用是表示从此物理块开始连续的空闲物理块的数量。
|
||||
|
||||
用\mintinline{C}{flags}的1位表示\mintinline{C}{property}是否有效,1位为1代表有效。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
uCore现有代码已实现的物理块分配首次适应算法以及物理块回收算法有没有问题或者错误?如有的话,请简述相关的问题或者错误,并修改相应的代码。
|
||||
}{
|
||||
\mintinline{C}{default_init_memmap}函数中的\mintinline{C}{p->flags = 0;},这里应该是把\mintinline{C}{flags}的0位设置成0,而不是把整个\mintinline{C}{flags}都设置成0。所以应该修改成\mintinline{C}{p->flags &= ~1;}。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
你认为在uCore的四个物理块基本分配方案基础上有没有进一步优化的可能?如有的话,请简要说明你的相关优化方案。
|
||||
}{
|
||||
四个物理块基本分配方案难道是FF(first fit,首次适应)、BF(best fit,最佳首次适应)、WF(worst fit,最坏首次适应)、NF(next fit,循环首次适应)?有进一步优化的可能,比如合并空闲的内存块:在系统空闲时可以检测所有已分配的物理块,将已分配但最近未使用的物理块合并到相邻的位置(最近使用的物理块不能乱动,不然会影响性能还可能出现问题)。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
\mintinline{C}{get_pte}、\mintinline{C}{get_page}函数的作用是什么?它们的输入与返回分别是什么?
|
||||
}{
|
||||
\mint{C}|pte_t *get_pte(pde_t *pgdir, uintptr_t la, bool create)|
|
||||
\mintinline{C}{get_pte}的作用是根据逻辑地址返回页表指针,它的输入为页目录的起始地址、逻辑地址、页表是否已被调入内存,返回为页表指针。
|
||||
\mint{C}|struct Page *get_page(pde_t *pgdir, uintptr_t la, pte_t **ptep_store)|
|
||||
\mintinline{C}{get_page}的作用是根据逻辑地址返回对应的物理块描述符,它的输入为页目录的起始地址、逻辑地址、以及可能需要存储的页表指针的地址,返回为物理块描述符。
|
||||
}
|
||||
\end{enumerate}
|
||||
\item \textbf{程序设计与实现的基本思路}
|
||||
\begin{enumerate}
|
||||
{\kaishu
|
||||
\item 关于物理内存管理的部分是在kern/mm/中(这里的mm应该是memory map 内存映射的意思?),循环首次适应算法是分配物理块的算法,所以观察到分配物理块的部分在\mintinline{C}{default_pmm.c}中实现,那么只需要关注这个文件的内容。
|
||||
\item 原先的代码中实现的是首次适应算法(first fit),这里要改成循环首次适应算法(next fit),只需要记录下每次分配的指针,每次从该指针的位置开始继续查找下一个空闲块。这里使用了\mintinline{C}{list_entry_t *alloc_le = &free_list;}作为全局变量来记录每次分配的指针。(为什么不用静态局部变量?是因为它的测试函数的问题,后面会提到)这里的\mintinline{C}{alloc_le}和\mintinline{C}{default_alloc_pages}中的\mintinline{C}{le}是同样的作用,只是全局变量名字不能和已有的一样所以改了个名。
|
||||
\item 这里新建的物理块分配函数使用\mintinline{C}{next_fit_alloc_pages}命名和原来的区分,在这个函数中首先需要初始化\mintinline{C}{alloc_le}指向链表头结点,但这个初始化又必须执行且只执行一次,所以这里使用了分支语句,
|
||||
\begin{minted}{C}
|
||||
if (alloc_le == &free_list)
|
||||
alloc_le = list_next(&free_list);
|
||||
\end{minted}
|
||||
|
||||
\item 接下来就开始从\mintinline{C}{default_alloc_pages}中的循环着手,原先的循环条件是\\ \mintinline{C}{while((le=list_next(le)) != &free_list)},表示每次查看下一个链表表项,直到到达末尾(由于是循环链表,所以末尾就是头结点即\mintinline{C}{&free_list})。那么这里就需要修改成循环到下一次遇到\mintinline{C}{alloc_le}。假设链表共有$n$项,那么最多需要执行$n+1$次循环,并且最后一次循环不满足条件退出。那能不能直接固定循环$n$次呢?这里是不行的,还是它的测试函数的问题,也在后面提到。因此首次循环和最后一次循环,循环变量指向的都是同一个位置,但是首次循环需要满足条件,最后一次循环需要不满足条件,这应该怎么实现呢?这就是下面要介绍的中途改变循环结束指针的方式。
|
||||
|
||||
\begin{minted}[fontsize=\zihao{-5}]{C}
|
||||
static struct Page *
|
||||
next_fit_alloc_pages(size_t n) {
|
||||
list_entry_t *start = alloc_le;
|
||||
list_entry_t *end = &free_list;
|
||||
while(1) {
|
||||
if (alloc_le == end) { // 最多两次触发此条件
|
||||
if (end != start) { // 第二次触发le == end的时候这里就不满足了
|
||||
end = start; // 如果循环到链表末尾了就把结束的指针改成循环开始的位置
|
||||
alloc_le = list_next(alloc_le); // 并且这个&free_list不应该被分配
|
||||
continue;
|
||||
}
|
||||
break; // 这时候就是真正的循环完了也没有剩余空间
|
||||
}
|
||||
...
|
||||
alloc_le = list_next(alloc_le);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
\end{minted}
|
||||
|
||||
首先,用\mintinline{C}{start}记录循环指针开始的位置,用\mintinline{C}{end}记录头结点的位置,之后进入循环,在首次循环到末尾的时候(即\mintinline{C}{if (alloc_le == end)},把\mintinline{C}{end}修改到\mintinline{C}{start}的位置,之后第二次触发\mintinline{C}{if (alloc_le == end)}的时候,就可以退出循环了。也就是把循环遍历分成了两段,假设循环指针当前位置为$k$,共有$n$个链表节点,这就是分成了$k \cdots n$的前一段和$1 \cdots k$的后一段。
|
||||
|
||||
\item 上文多次提到原先的测试代码的问题,这里它的测试代码在\mintinline{C}{default_check}和\\ \mintinline{C}{basic_check}这两个函数中,这两个函数的目的是检测内存的分配与回收的方案是否正确,具体方法是多次分配回收,例如先分配3个物理块,之后把空闲物理块链表清空,这时候空闲物理块是多少?已经清空了所以是0个对不对?那么这时候要再分配一个物理块呢?应该是无法分配的是吧,但这里就出现问题了,循环首次适应的指针这时候在哪呢?还在之前分配了的位置,所以实际上这时候还是能分配到空闲物理块的,这就出现问题了,它的\mintinline{C}{assert(alloc_page() == NULL);}就不通过了。
|
||||
|
||||
分配了3个物理块后的情况如下图所示,红色矩形代表已经被分配的物理块,蓝色矩形代表未被分配的物理块,左侧的圆形代表链表头结点,prev和next表示头结点的前驱和后继节点。此时已经分配了3个物理块,所以\mintinline{C}{alloc_le}记录的位置在第三个物理块后。
|
||||
|
||||
\includexopp[1.2]{2.2.1}
|
||||
|
||||
但是之后出现了\mintinline{C}{list_init(&free_list);}这一行,这个函数的定义如下
|
||||
\begin{minted}[fontsize=\zihao{-5}]{C}
|
||||
/* *
|
||||
* list_init - initialize a new entry
|
||||
* @elm: new entry to be initialized
|
||||
* */
|
||||
static inline void
|
||||
list_init(list_entry_t *elm) {
|
||||
elm->prev = elm->next = elm;
|
||||
}
|
||||
\end{minted}
|
||||
|
||||
可见此函数只是把链表的前驱节点和后继节点都指向了自己,也就变成了下图:
|
||||
|
||||
\includexopp[1.2]{2.2.2}
|
||||
|
||||
这时候似乎没什么问题,但注意它的清空不彻底,再分配物理空间的时候,\mintinline{C}{alloc_le}还在原先的位置,所以仍然能分配成功,这就导致\mintinline{C}{assert(alloc_page() == NULL);}不通过了。所以解决方案也很简单,只需要把\mintinline{C}{alloc_le}也指向头结点就行了,如下图所示:
|
||||
|
||||
\includexopp[1.2]{2.2.3}
|
||||
|
||||
还要注意它在清空链表之后还有个恢复的操作,所以这个\mintinline{C}{alloc_le}也需要恢复,而且在\mintinline{C}{default_check}和\mintinline{C}{basic_check}中都有这样的操作,因此两个函数,每个函数一次保存一次恢复,所以需要添加四行\mintinline{C}{alloc_le = &free_list;}。
|
||||
|
||||
% 为什么楷体的仓会变成仑啊??????
|
||||
\item 时间仓促,如有错误敬请指出(在下方的链接中)。
|
||||
}
|
||||
\end{enumerate}
|
||||
\myitem{代码}{
|
||||
\item \url{https://gitea.shuishan.net.cn/10213903403/os_kernel_lab}
|
||||
\item 也可以看上传的附件。
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
113
操作系统/实验报告/Lab3.tex
Normal file
113
操作系统/实验报告/Lab3.tex
Normal file
@ -0,0 +1,113 @@
|
||||
\documentclass[a4paper]{ctexart}
|
||||
\input{mypreamble}
|
||||
\renewcommand{\mychapternum}{3}
|
||||
\renewcommand{\mylabname}{虚拟内存管理}
|
||||
\renewcommand{\mydate}{2024年5月7日}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\item{\textbf{研读理解相关代码后,回答以下问题:}}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[]{
|
||||
uCore 中的段页式存储管理方案与理论课中讲述的方案有何不同?
|
||||
}{
|
||||
$\mu$Core 中简化了分段机制,将逻辑地址直接恒等映射到线性地址,之后使用分页机制将线性地址通过分页映射到物理地址。由于使用了分页机制,因此需要对空闲物理块管理,对空闲物理块的管理使用了链表来管理,链表按照地址排序。
|
||||
|
||||
跟我们理论课中的“段页式存储管理”和“使用链表管理存储空间”的方案相似,不同之处在于分段机制简化了,并且只使用链表管理了空闲物理块(已分配的物理块在页表中有记录,所以不需要管理)。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
试简述uCore中缺页异常的处理过程,它与理论课中讲述的过程有何不同?
|
||||
}{
|
||||
在vmm.c的注释中有这样一行:
|
||||
\mint{C}| * CALL GRAPH: trap--> trap_dispatch-->pgfault_handler-->do_pgfault|
|
||||
显然,在$\mu$Core中,缺页异常从\mintinline{C}{trap}触发,之后通过\mintinline{C}{trap_dispatch}根据中断号(\mintinline{C}{tf->tf_trapno}分发给不同的处理程序,这里是缺页中断(\mintinline{C}{T_PGFLT}),所以分发给\mintinline{C}{pgfault_handler},再调用\mintinline{C}{do_pgfault},之后在\mintinline{C}{do_pgfault}中找到一个pte,并且分配内存或者从交换分区换入一个页面,或者由于访问权限不正确而直接返回失败。
|
||||
|
||||
与理论课中讲述的过程的不同是进行了简化,取消了快表,也就是只有一级索引而没有二级索引。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
为了支持页面置换,在数据结构Page中添加了哪些字段,其作用是什么?
|
||||
}{}
|
||||
{\kaishu
|
||||
\begin{minted}[fontsize=\zihao{-5}]{C}
|
||||
struct Page {
|
||||
int ref; // page frame's reference counter
|
||||
uint32_t flags; // array of flags that describe the status of the page frame
|
||||
unsigned int property; // the num of free block, used in first fit pm manager
|
||||
list_entry_t page_link; // free list link
|
||||
list_entry_t pra_page_link; // used for pra (page replace algorithm)
|
||||
uintptr_t pra_vaddr; // used for pra (page replace algorithm)
|
||||
};
|
||||
\end{minted}
|
||||
|
||||
添加了\mintinline{C}{pra_page_link}和\mintinline{C}{pra_vaddr}这两个字段,\mintinline{C}{pra_page_link}是用来将物理块组织成FIFO队列(使用链表实现)用来进行页面置换的,\mintinline{C}{pra_vaddr}是物理块对应的虚拟地址,用来记录访问哪个虚拟地址的时候产生的缺页,以便进行页面置换。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
请描述页目录项页(PDE)和页表目录项(PTE)的组成部分对uCore实现页面置换算法的潜在用处。请问如何区分未映射的页表表项与被换出页的页表表项?请描述被换出页的页表表项的组成结构。
|
||||
}{
|
||||
用处在于记录某个页面在内存中还是在外存对换区中,以及对应物理地址(在内存中)或者offset(在外存对换区中),在下次页面换入或换出时确保页面被放到正确的位置上。
|
||||
|
||||
由于未映射的页表表项全是0,所以被换出的页的offset从1开始以区分。这样如果页表表项全是0就说明是未映射,如果在offset(高24位)中存在1,那么就是被换出的。
|
||||
|
||||
被换出页的页表表项复用了pte的结构,在\mintinline{C}{memlayout.h}中有这样一行:
|
||||
\mint{C}|typedef pte_t swap_entry_t; //the pte can also be a swap entry|
|
||||
|
||||
再根据示意图:
|
||||
\begin{center}
|
||||
\includegraphics[width=0.5\linewidth]{imgs/2024-05-10-08-49-47.png}
|
||||
\end{center}
|
||||
|
||||
可以看到其高24位为offset,代表在外存对换区里的位置;存在位(最低位)为0,表示此页面不存在对应的物理块;中间的7位都保留暂不使用。
|
||||
}
|
||||
\end{enumerate}
|
||||
\item \textbf{程序设计与实现的基本思路}
|
||||
\begin{enumerate}
|
||||
{\kaishu
|
||||
\item 在$\mu$Core中原先实现的是FIFO页面置换算法,这里要改成第二次机会页面置换算法,可以发现页面的组织方式不需要更改,仍然使用链表,每次插入页面时仍然是添加到链表头部不需要更改,只需要更改换出页面的算法即可。
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=0.9\linewidth]{imgs/2024-05-10-09-00-25.png}
|
||||
\end{center}
|
||||
|
||||
\item 课上讲的这张示意图,右侧是链表的头部,左侧是链表的尾部,每次插入的页面在最右侧即链表的头部。当需要换出页面时,从左侧(链表尾部)取出一个页面,如果这个页面的访问位是1,那么将其访问位改为0,并放到右侧(链表头部)。接着再从左侧(链表尾部)检测下一个页面,直到找到一个访问位为0页面的作为换出的页面。所以可以写出代码如下:
|
||||
|
||||
\begin{minted}{C}
|
||||
// 从后往前,最后面的是最早访问的
|
||||
list_entry_t *current = head->prev;
|
||||
list_entry_t *le = NULL;
|
||||
for (; current != head; current = current->prev) {
|
||||
pte_t *ptep = get_pte(mm->pgdir, le2vma(current, vm_start), 0);
|
||||
if (*ptep & PTE_A) { // 访问位为1
|
||||
*ptep &= !PTE_A; // 清除访问位
|
||||
list_del(current); // 从链表中移除
|
||||
list_add(head, current); // 添加到链表头部
|
||||
} else {
|
||||
le = current;
|
||||
break;
|
||||
}
|
||||
}
|
||||
\end{minted}
|
||||
|
||||
\mintinline{C}{le}即为最终的找到的用来换出的页面。
|
||||
|
||||
\item 当然,还需要完善一些问题。当页面只有一个并且访问位为1时,从链表中移除此页面再放入后链表结构并未改变,所以下一次的\mintinline{C}{current}指向链表头结点,循环退出了,但此时\mintinline{C}{le}还是空的!但期望的返回结果应该是这一个页面,所以需要对这种情况进行处理:
|
||||
|
||||
\begin{minted}{C}
|
||||
if (le == NULL) {
|
||||
le = head->prev; // 循环一遍找不到就最后一个
|
||||
}
|
||||
\end{minted}
|
||||
|
||||
当循环一遍仍然找不到可以换出的页面的时候就选择最后一个页面(和FIFO一样)作为换出的页面。当然,其实使用第二次机会页面置换算法的话,页面大于一个的时候必定能找到一个换出的页面的(请自行验证),而且也不会出现页面为0个情况(总不能页表数量为0吧),所以其实这样就只是解决了页面只有一个时的异常。
|
||||
|
||||
\item 测试代码\mintinline{C}{_fifo_check_swap}仍然需要修改,因为使用第二次机会页面置换算法,缺页次数肯定与FIFO算法不尽相同。测试代码中的\mintinline{C}{pgfault_num}即为缺页次数。
|
||||
|
||||
\item 由于时间紧迫,一些细节可能没有考虑周到,如有发现错误欢迎在下方的链接中提Issue。
|
||||
}
|
||||
\end{enumerate}
|
||||
\myitem{代码}{
|
||||
\item \url{https://gitea.shuishan.net.cn/10213903403/os_kernel_lab}
|
||||
\item 也可以看上传的附件。
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
295
操作系统/实验报告/Lab4.tex
Normal file
295
操作系统/实验报告/Lab4.tex
Normal file
@ -0,0 +1,295 @@
|
||||
\documentclass[a4paper]{ctexart}
|
||||
\input{mypreamble}
|
||||
\renewcommand{\mychapternum}{4}
|
||||
\renewcommand{\mylabname}{内核线程管理}
|
||||
\renewcommand{\mydate}{2024年5月17日}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\item{\textbf{研读理解相关代码后,回答以下问题:}}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[]{
|
||||
请简单说明\mintinline{C}{proc_struct}中各个成员变量含义以及作用。它与理论课中讲述的PCB结构有何不同之处?
|
||||
}{}
|
||||
{\kaishu
|
||||
\setlength{\parskip}{2em}
|
||||
\begin{minted}[]{C}
|
||||
struct proc_struct {
|
||||
enum proc_state state; // Process state
|
||||
int pid; // Process ID
|
||||
int runs; // the running times of Proces
|
||||
uintptr_t kstack; // Process kernel stack
|
||||
volatile bool need_resched; // bool value: need to be rescheduled to release CPU?
|
||||
struct proc_struct *parent; // the parent process
|
||||
struct mm_struct *mm; // Process's memory management field
|
||||
struct context context; // Switch here to run process
|
||||
struct trapframe *tf; // Trap frame for current interrupt
|
||||
uintptr_t cr3; // CR3 register: the base addr of Page Directroy Table(PDT)
|
||||
uint32_t flags; // Process flag
|
||||
char name[PROC_NAME_LEN + 1]; // Process name
|
||||
list_entry_t list_link; // Process link list
|
||||
list_entry_t hash_link; // Process hash list
|
||||
};
|
||||
\end{minted}
|
||||
|
||||
\mintinline{C}{state}是进程的状态,\mintinline{C}{pid}是进程的ID,\mintinline{C}{runs}是进程的被调度到的次数,\mintinline{C}{kstack}是进程的堆栈,\mintinline{C}{need_resched}用于非抢占式调度,表示进程是否运行结束可以把CPU重新调度给其他进程,\mintinline{C}{parent}是进程的父进程,\mintinline{C}{mm}是进程的内存管理的部分的指针,\mintinline{C}{context}是进程的上下文,即
|
||||
\begin{minted}{C}
|
||||
struct context {
|
||||
uint32_t eip;
|
||||
uint32_t esp;
|
||||
uint32_t ebx;
|
||||
uint32_t ecx;
|
||||
uint32_t edx;
|
||||
uint32_t esi;
|
||||
uint32_t edi;
|
||||
uint32_t ebp;
|
||||
};
|
||||
\end{minted}
|
||||
\mintinline{C}{tf}是进程的中断帧,记录了中断的相关信息,\mintinline{C}{cr3}是进程的页目录表的指针,\mintinline{C}{flags}是进程的各种标志位,\mintinline{C}{name}是进程的名称,\mintinline{C}{list_link}是所有进程的链表表项,\mintinline{C}{hash_link}是具有同一个哈希值的进程的链表表项。
|
||||
|
||||
它与理论课中讲述的PCB结构的不同之处在于没有优先级、进程组、进程运行时间、进程使用的CPU时间、进程的子进程的CPU时间、文件管理(因为还没实现文件系统?)。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
试简单分析 uCore中 内核线程的创建过程。(要求说明处理流程,相关的主要函数、它们的功能以及调用关系。)
|
||||
}{}
|
||||
{\kaishu
|
||||
\setlength{\parskip}{2em}
|
||||
\begin{center}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-17-19-18-00.png}
|
||||
\end{center}
|
||||
\begin{minted}{C}
|
||||
// proc_init - set up the first kernel thread idleproc "idle" by itself and
|
||||
// - create the second kernel thread init_main
|
||||
void
|
||||
proc_init(void) {
|
||||
int i;
|
||||
|
||||
list_init(&proc_list);
|
||||
for (i = 0; i < HASH_LIST_SIZE; i ++) {
|
||||
list_init(hash_list + i);
|
||||
}
|
||||
|
||||
if ((idleproc = alloc_proc()) == NULL) {
|
||||
panic("cannot alloc idleproc.\n");
|
||||
}
|
||||
|
||||
idleproc->pid = 0;
|
||||
idleproc->state = PROC_RUNNABLE;
|
||||
idleproc->kstack = (uintptr_t)bootstack;
|
||||
idleproc->need_resched = 1;
|
||||
set_proc_name(idleproc, "idle");
|
||||
nr_process ++;
|
||||
|
||||
current = idleproc;
|
||||
|
||||
int pid = kernel_thread(init_main, "Hello world!!", 0);
|
||||
if (pid <= 0) {
|
||||
panic("create init_main failed.\n");
|
||||
}
|
||||
|
||||
initproc = find_proc(pid);
|
||||
set_proc_name(initproc, "init");
|
||||
|
||||
assert(idleproc != NULL && idleproc->pid == 0);
|
||||
assert(initproc != NULL && initproc->pid == 1);
|
||||
}
|
||||
\end{minted}
|
||||
|
||||
主要的内核线程创建过程在\mintinline{C}{proc_init}中,首先调用\mintinline{C}{list_init}初始化全部进程的链表和相同哈希的进程列表,然后调用 \mintinline{C}{alloc_proc}给当前进程分配一个进程控制块,并且设置相关属性,其中调用\mintinline{C}{set_proc_name}设置当前进程的名称为\mintinline{C}{"idle"},之后调用\mintinline{C}{kernel_thread}创建一个\mintinline{C}{init_main}进程,并调用\mintinline{C}{find_proc},再调用\mintinline{C}{set_proc_name}将其名称设置为\mintinline{C}{init}。
|
||||
|
||||
\begin{minted}{C}
|
||||
// kernel_thread - create a kernel thread using "fn" function
|
||||
// NOTE: the contents of temp trapframe tf will be copied to
|
||||
// proc->tf in do_fork-->copy_thread function
|
||||
int
|
||||
kernel_thread(int (*fn)(void *), void *arg, uint32_t clone_flags) {
|
||||
struct trapframe tf;
|
||||
memset(&tf, 0, sizeof(struct trapframe));
|
||||
tf.tf_cs = KERNEL_CS;
|
||||
tf.tf_ds = tf.tf_es = tf.tf_ss = KERNEL_DS;
|
||||
tf.tf_regs.reg_ebx = (uint32_t)fn;
|
||||
tf.tf_regs.reg_edx = (uint32_t)arg;
|
||||
tf.tf_eip = (uint32_t)kernel_thread_entry;
|
||||
return do_fork(clone_flags | CLONE_VM, 0, &tf);
|
||||
}
|
||||
\end{minted}
|
||||
|
||||
\mintinline{C}{kernel_thread}的功能是通过调用一个函数创建一个新的线程,由于新的线程是由当前线程创建的,这里就调用了\mintinline{C}{do_fork}函数。
|
||||
|
||||
\begin{minted}{C}
|
||||
/* do_fork - parent process for a new child process
|
||||
* @clone_flags: used to guide how to clone the child process
|
||||
* @stack: the parent's user stack pointer. if stack==0, It means to fork a kernel thread.
|
||||
* @tf: the trapframe info, which will be copied to child process's proc->tf
|
||||
*/
|
||||
int
|
||||
do_fork(uint32_t clone_flags, uintptr_t stack, struct trapframe *tf) {
|
||||
int ret = -E_NO_FREE_PROC;
|
||||
struct proc_struct *proc;
|
||||
if (nr_process >= MAX_PROCESS) {
|
||||
goto fork_out;
|
||||
}
|
||||
ret = -E_NO_MEM;
|
||||
//LAB4:EXERCISE2 YOUR CODE
|
||||
/*
|
||||
* Some Useful MACROs, Functions and DEFINEs, you can use them in below implementation.
|
||||
* MACROs or Functions:
|
||||
* alloc_proc: create a proc struct and init fields (lab4:exercise1)
|
||||
* setup_kstack: alloc pages with size KSTACKPAGE as process kernel stack
|
||||
* copy_mm: process "proc" duplicate OR share process "current"'s mm according clone_flags
|
||||
* if clone_flags & CLONE_VM, then "share" ; else "duplicate"
|
||||
* copy_thread: setup the trapframe on the process's kernel stack top and
|
||||
* setup the kernel entry point and stack of process
|
||||
* hash_proc: add proc into proc hash_list
|
||||
* get_pid: alloc a unique pid for process
|
||||
* wakeup_proc: set proc->state = PROC_RUNNABLE
|
||||
* VARIABLES:
|
||||
* proc_list: the process set's list
|
||||
* nr_process: the number of process set
|
||||
*/
|
||||
|
||||
// 1. call alloc_proc to allocate a proc_struct
|
||||
// 2. call setup_kstack to allocate a kernel stack for child process
|
||||
// 3. call copy_mm to dup OR share mm according clone_flag
|
||||
// 4. call copy_thread to setup tf & context in proc_struct
|
||||
// 5. insert proc_struct into hash_list && proc_list
|
||||
// 6. call wakeup_proc to make the new child process RUNNABLE
|
||||
// 7. set ret vaule using child proc's pid
|
||||
if ((proc = alloc_proc()) == NULL) {
|
||||
goto fork_out;
|
||||
}
|
||||
|
||||
proc->parent = current;
|
||||
|
||||
if (setup_kstack(proc) != 0) {
|
||||
goto bad_fork_cleanup_proc;
|
||||
}
|
||||
if (copy_mm(clone_flags, proc) != 0) {
|
||||
goto bad_fork_cleanup_kstack;
|
||||
}
|
||||
copy_thread(proc, stack, tf);
|
||||
|
||||
bool intr_flag;
|
||||
local_intr_save(intr_flag);
|
||||
{
|
||||
proc->pid = get_pid();
|
||||
hash_proc(proc);
|
||||
list_add(&proc_list, &(proc->list_link));
|
||||
nr_process ++;
|
||||
}
|
||||
local_intr_restore(intr_flag);
|
||||
|
||||
wakeup_proc(proc);
|
||||
|
||||
ret = proc->pid;
|
||||
fork_out:
|
||||
return ret;
|
||||
|
||||
bad_fork_cleanup_kstack:
|
||||
put_kstack(proc);
|
||||
bad_fork_cleanup_proc:
|
||||
kfree(proc);
|
||||
goto fork_out;
|
||||
}
|
||||
\end{minted}
|
||||
|
||||
\mintinline{C}{do_fork}函数中,先调用\mintinline{C}{alloc_proc}分配一个进程控制块,再调用\mintinline{C}{setup_kstack}分配一个内核堆栈,再调用\mintinline{C}{copy_mm}将父进程的内存空间复制或者共享给子进程,再调用\mintinline{C}{copy_thread}设置子进程的中断处理,并设置上下文的变量。之后关中断,将新的进程控制块插入到全部进程链表与相同哈希链表中,再开中断。然后把子进程设置成状态为\mintinline{C}{RUNNABLE},返回子进程的\mintinline{C}{pid}。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
试简单分析 uCore中 内核线程的切换过程。(要求说明处理流程,相关的主要函数、它们的功能以及调用关系。)
|
||||
}{}
|
||||
{\kaishu
|
||||
\setlength{\parskip}{2em}
|
||||
切换线程主要使用的是\mintinline{C}{schedule}函数。
|
||||
|
||||
\begin{minted}{C}
|
||||
void
|
||||
schedule(void) {
|
||||
bool intr_flag;
|
||||
list_entry_t *le, *last;
|
||||
struct proc_struct *next = NULL;
|
||||
local_intr_save(intr_flag);
|
||||
{
|
||||
current->need_resched = 0;
|
||||
last = (current == idleproc) ? &proc_list : &(current->list_link);
|
||||
le = last;
|
||||
do {
|
||||
if ((le = list_next(le)) != &proc_list) {
|
||||
next = le2proc(le, list_link);
|
||||
if (next->state == PROC_RUNNABLE) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (le != last);
|
||||
if (next == NULL || next->state != PROC_RUNNABLE) {
|
||||
next = idleproc;
|
||||
}
|
||||
next->runs ++;
|
||||
if (next != current) {
|
||||
proc_run(next);
|
||||
}
|
||||
}
|
||||
local_intr_restore(intr_flag);
|
||||
}
|
||||
\end{minted}
|
||||
|
||||
在\mintinline{C}{schedule}中,我们要找到下一次调度的线程,即找到状态为\mintinline{C}{RUNNABLE}的线程,如果当前的线程为\mintinline{C}{idleproc}即CPU空闲的线程则从线进程链表头开始找(因为\mintinline{C}{idleproc}线程不在线程链表中),否则从当前线程的下一个线程开始找。找到需要调度的\mintinline{C}{RUNNABLE}线程后,如果新的线程和老的线程不是同一个线程,则需要调用\mintinline{C}{proc_run}进行切换。
|
||||
|
||||
\begin{minted}{C}
|
||||
// proc_run - make process "proc" running on cpu
|
||||
// NOTE: before call switch_to, should load base addr of "proc"'s new PDT
|
||||
void
|
||||
proc_run(struct proc_struct *proc) {
|
||||
if (proc != current) {
|
||||
bool intr_flag;
|
||||
struct proc_struct *prev = current, *next = proc;
|
||||
local_intr_save(intr_flag);
|
||||
{
|
||||
current = proc;
|
||||
load_esp0(next->kstack + KSTACKSIZE);
|
||||
lcr3(next->cr3);
|
||||
switch_to(&(prev->context), &(next->context));
|
||||
}
|
||||
local_intr_restore(intr_flag);
|
||||
}
|
||||
}
|
||||
\end{minted}
|
||||
|
||||
在\mintinline{C}{proc_run}中,调用\mintinline{C}{load_esp0}设置任务状态段,调用\mintinline{C}{lcr3}加载新的进程的页表,之后调用\mintinline{C}{switch_to}保存老的进程的上下文,恢复新的进程的上下文。
|
||||
|
||||
\begin{minted}{asm}
|
||||
switch_to: # switch_to(from, to)
|
||||
|
||||
# save from's registers
|
||||
movl 4(%esp), %eax # eax points to from
|
||||
popl 0(%eax) # save eip !popl
|
||||
movl %esp, 4(%eax)
|
||||
movl %ebx, 8(%eax)
|
||||
movl %ecx, 12(%eax)
|
||||
movl %edx, 16(%eax)
|
||||
movl %esi, 20(%eax)
|
||||
movl %edi, 24(%eax)
|
||||
movl %ebp, 28(%eax)
|
||||
|
||||
# restore to's registers
|
||||
movl 4(%esp), %eax # not 8(%esp): popped return address already
|
||||
# eax now points to to
|
||||
movl 28(%eax), %ebp
|
||||
movl 24(%eax), %edi
|
||||
movl 20(%eax), %esi
|
||||
movl 16(%eax), %edx
|
||||
movl 12(%eax), %ecx
|
||||
movl 8(%eax), %ebx
|
||||
movl 4(%eax), %esp
|
||||
|
||||
pushl 0(%eax) # push eip
|
||||
|
||||
ret
|
||||
\end{minted}
|
||||
|
||||
在\mintinline{C}{switch_to}中,从\mintinline{C}{esp+4}的位置加载\mintinline{C}{eax}指针(即\mintinline{C}{&(prev->context)}),并把老的线程中当前的寄存器中的值都放到这个指针所在的\mintinline{C}{context}结构体中,再从\mintinline{C}{esp+8}的位置加载\mintinline{C}{eax}指针(即\mintinline{C}{&(next->context)}),并从这个指针的位置加载新的线程中的上下文寄存器的值,其中\mintinline{C}{eip}需要用\mintinline{C}{popl}和\mintinline{C}{pushl}来设置,不能使用\mintinline{C}{movl}来设置。
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{enumerate}
|
||||
\end{document}
|
130
操作系统/实验报告/Lab5.tex
Normal file
130
操作系统/实验报告/Lab5.tex
Normal file
@ -0,0 +1,130 @@
|
||||
\documentclass[a4paper]{ctexart}
|
||||
\input{mypreamble}
|
||||
\renewcommand{\mychapternum}{5}
|
||||
\renewcommand{\mylabname}{用户进程管理}
|
||||
\renewcommand{\mydate}{2024年5月26日}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\item{\textbf{研读理解相关代码后,回答以下问题:}}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[]{
|
||||
用户进程与内核线程有何不同?为何要引入用户进程?
|
||||
}{
|
||||
用户进程所在的段的特权级是3,而内核进程所在的段的特权级是0。
|
||||
|
||||
引入用户进程是为了确保安全。一些代码和数据只能在内核态访问而不能在用户态访问,例如操作系统进行页面管理和进程管理的代码。如果用户的代码出错,错误地修改了操作系统的代码段或数据段,会造成严重的错误。而引入用户进程后,用户进程在特权级3下运行,无法修改内核进程所在段,只要操作系统不崩溃,用户进程出现错误仍不影响操作系统正常运行。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
uCore是如何实现系统调用的?这样的设计有何优点?
|
||||
}{
|
||||
\begin{center}
|
||||
\includegraphics[width=0.5\linewidth]{imgs/Interrupt_Procedure_Call.jpg}
|
||||
\end{center}
|
||||
|
||||
在用户态(特权级3)通过 \mintinline{asm}{int 0x80} 指令,根据中断描述符表找到中断处理程序的段选择子以及偏移量,根据段选择子在段描述符表中找到对应的段描述符,再把段描述符的地址加上偏移量即可找到最终需要执行的代码,并且以特权级0执行。其中参数(即中断号)和返回值的传递通过 \mintinline{asm}{eax} 寄存器实现。
|
||||
|
||||
这样设计的优点是在用户进程处于用户态的情况下能以内核态执行系统调用,也就是说操作系统可以在切换到内核态之前先进行检查用户是否有权限执行此系统调用,如果没有权限可以提前拦截,避免用户进程错误地或恶意地切换到内核态。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
分析 uCore中 用户进程的创建、调度以及执行的过程。( 要求说明处理流程,相关的主要函数、它们的功能以及调用关系。)
|
||||
}{}
|
||||
{\kaishu\setlength{\parskip}{2em}
|
||||
在 \mintinline{C}{init_main} 中加入了一行 \mintinline{C}{int pid = kernel_thread(user_main, NULL, 0);} , \mintinline{C}{user_main} 的定义如下:
|
||||
\begin{minted}{C}
|
||||
// user_main - kernel thread used to exec a user program
|
||||
static int
|
||||
user_main(void *arg) {
|
||||
#ifdef TEST
|
||||
KERNEL_EXECVE2(TEST, TESTSTART, TESTSIZE);
|
||||
#else
|
||||
KERNEL_EXECVE(exit);
|
||||
#endif
|
||||
panic("user_main execve failed.\n");
|
||||
}
|
||||
\end{minted}
|
||||
可以看到这个进程是用来创建用户进程的,其中调用了 \mintinline{C}{kernel_execve} :
|
||||
\begin{minted}{C}
|
||||
// kernel_execve - do SYS_exec syscall to exec a user program called by user_main kernel_thread
|
||||
static int
|
||||
kernel_execve(const char *name, unsigned char *binary, size_t size) {
|
||||
int ret, len = strlen(name);
|
||||
asm volatile (
|
||||
"int %1;"
|
||||
: "=a" (ret)
|
||||
: "i" (T_SYSCALL), "0" (SYS_exec), "d" (name), "c" (len), "b" (binary), "D" (size)
|
||||
: "memory");
|
||||
return ret;
|
||||
}
|
||||
\end{minted}
|
||||
其中又调用了系统调用子功能 \mintinline{C}{SYS_exec} ,它对应的函数为
|
||||
\begin{minted}{C}
|
||||
static int
|
||||
sys_exec(uint32_t arg[]) {
|
||||
const char *name = (const char *)arg[0];
|
||||
size_t len = (size_t)arg[1];
|
||||
unsigned char *binary = (unsigned char *)arg[2];
|
||||
size_t size = (size_t)arg[3];
|
||||
return do_execve(name, len, binary, size);
|
||||
}
|
||||
\end{minted}
|
||||
其中又调用了 \mintinline{C}{do_execve}
|
||||
\begin{minted}{C}
|
||||
// do_execve - call exit_mmap(mm)&put_pgdir(mm) to reclaim memory space of current process
|
||||
// - call load_icode to setup new memory space accroding binary prog.
|
||||
int
|
||||
do_execve(const char *name, size_t len, unsigned char *binary, size_t size) {
|
||||
struct mm_struct *mm = current->mm;
|
||||
if (!user_mem_check(mm, (uintptr_t)name, len, 0)) {
|
||||
return -E_INVAL;
|
||||
}
|
||||
if (len > PROC_NAME_LEN) {
|
||||
len = PROC_NAME_LEN;
|
||||
}
|
||||
|
||||
char local_name[PROC_NAME_LEN + 1];
|
||||
memset(local_name, 0, sizeof(local_name));
|
||||
memcpy(local_name, name, len);
|
||||
|
||||
if (mm != NULL) {
|
||||
lcr3(boot_cr3);
|
||||
if (mm_count_dec(mm) == 0) {
|
||||
exit_mmap(mm);
|
||||
put_pgdir(mm);
|
||||
mm_destroy(mm);
|
||||
}
|
||||
current->mm = NULL;
|
||||
}
|
||||
int ret;
|
||||
if ((ret = load_icode(binary, size)) != 0) {
|
||||
goto execve_exit;
|
||||
}
|
||||
set_proc_name(current, local_name);
|
||||
return 0;
|
||||
|
||||
execve_exit:
|
||||
do_exit(ret);
|
||||
panic("already exit: %e.\n", ret);
|
||||
}
|
||||
\end{minted}
|
||||
|
||||
这里的 \mintinline{C}{do_execve} 就释放了当前内核进程的内存空间,并且调用了 \mintinline{C}{load_icode}
|
||||
\begin{minted}{C}
|
||||
/* load_icode - load the content of binary program(ELF format) as the new content of current process
|
||||
* @binary: the memory addr of the content of binary program
|
||||
* @size: the size of the content of binary program
|
||||
*/
|
||||
static int
|
||||
load_icode(unsigned char *binary, size_t size) {
|
||||
...
|
||||
}
|
||||
\end{minted}
|
||||
|
||||
这里 \mintinline{C}{load_icode} 就会创建一个新的页目录,把内核空间中共用的部分复制过去,之后从程序文件(ELF格式)中读取程序头,根据各个段的地址在内存中分配空间,并相应设置权限,然后从程序文件中的内容复制到内存中,之后将当前进程的页目录设置为新创建的这个页目录。
|
||||
|
||||
最后设置当前中断帧的代码段,由于这里的代码段的特权级为3,所以(通过 \mintinline{asm}{eax} )返回之后继续执行代码就是以用户的特权级执行了。
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{enumerate}
|
||||
\end{document}
|
298
操作系统/实验报告/Lab67.tex
Normal file
298
操作系统/实验报告/Lab67.tex
Normal file
@ -0,0 +1,298 @@
|
||||
\documentclass[a4paper]{ctexart}
|
||||
\input{mypreamble}
|
||||
\renewcommand{\mychapternum}{6、7}
|
||||
\renewcommand{\mylabname}{调度器、同步互斥}
|
||||
\renewcommand{\mydate}{2024年6月10日}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\item \textbf{完成相关实验内容后,回答以下问题:}
|
||||
|
||||
\textbf{Lab6:}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[]{
|
||||
分析sched\_class中各个函数指针的用法,并结合Round Robin 调度算法描述ucore的调度执行过程。
|
||||
}{}
|
||||
{\kaishu\setlength{\parskip}{2em}
|
||||
先看代码:
|
||||
\begin{minted}{C}
|
||||
// The introduction of scheduling classes is borrrowed from Linux, and makes the
|
||||
// core scheduler quite extensible. These classes (the scheduler modules) encapsulate
|
||||
// the scheduling policies.
|
||||
struct sched_class {
|
||||
// the name of sched_class
|
||||
const char *name;
|
||||
// Init the run queue
|
||||
void (*init)(struct run_queue *rq);
|
||||
// put the proc into runqueue, and this function must be called with rq_lock
|
||||
void (*enqueue)(struct run_queue *rq, struct proc_struct *proc);
|
||||
// get the proc out runqueue, and this function must be called with rq_lock
|
||||
void (*dequeue)(struct run_queue *rq, struct proc_struct *proc);
|
||||
// choose the next runnable task
|
||||
struct proc_struct *(*pick_next)(struct run_queue *rq);
|
||||
// dealer of the time-tick
|
||||
void (*proc_tick)(struct run_queue *rq, struct proc_struct *proc);
|
||||
/* for SMP support in the future
|
||||
* load_balance
|
||||
* void (*load_balance)(struct rq* rq);
|
||||
* get some proc from this rq, used in load_balance,
|
||||
* return value is the num of gotten proc
|
||||
* int (*get_proc)(struct rq* rq, struct proc* procs_moved[]);
|
||||
*/
|
||||
};
|
||||
\end{minted}
|
||||
|
||||
\mintinline{C}{name} 即为调度类的名称, \mintinline{C}{init} 用来初始化运行队列(数据结构不一定是链表,可以是任何数据结构), \mintinline{C}{enqueue} 是(创建新的进程的时候)进程入队的函数; \mintinline{C}{dequeue} 是(进程结束的时候)进程出队的函数; \mintinline{C}{pick_next} 用来在就绪(RUNNABLE)状态的进程中选出下一个将要调度的进程; \mintinline{C}{proc_tick} 是在时钟中断时需要执行的函数。
|
||||
|
||||
\mintinline{C}{labcodes_answer/lab6_result} 中实现的是stride调度算法,而Round Robin调度算法可以在 \mintinline{C}{labcodes/lab6} 中找到:
|
||||
\begin{minted}{C}
|
||||
struct sched_class default_sched_class = {
|
||||
.name = "RR_scheduler",
|
||||
.init = RR_init,
|
||||
.enqueue = RR_enqueue,
|
||||
.dequeue = RR_dequeue,
|
||||
.pick_next = RR_pick_next,
|
||||
.proc_tick = RR_proc_tick,
|
||||
};
|
||||
\end{minted}
|
||||
|
||||
对于Round Robin(时间片轮转),$\mu$Core 的调度执行过程如下:
|
||||
调用 \mintinline{C}{RR_init} 初始化一个队列。之后每次触发时钟中断时,进入 \mintinline{C}{trap_dispatch} ,根据 \mintinline{C}{labcodes_answer/lab7_result/kern/trap/trap.c} :
|
||||
\begin{minted}{C}
|
||||
/* LAB6 YOUR CODE */
|
||||
/* IMPORTANT FUNCTIONS:
|
||||
* run_timer_list
|
||||
*----------------------
|
||||
* you should update your lab5 code (just add ONE or TWO lines of code):
|
||||
* Every tick, you should update the system time, iterate the timers, and trigger the timers which are end to call scheduler.
|
||||
* You can use one funcitons to finish all these things.
|
||||
*/
|
||||
\end{minted}
|
||||
|
||||
应该更新系统计时器,并且调用调度器的中断处理函数 \mintinline{C}{RR_proc_tick} :
|
||||
\begin{minted}{C}
|
||||
static void
|
||||
RR_proc_tick(struct run_queue *rq, struct proc_struct *proc) {
|
||||
if (proc->time_slice > 0) {
|
||||
proc->time_slice --;
|
||||
}
|
||||
if (proc->time_slice == 0) {
|
||||
proc->need_resched = 1;
|
||||
}
|
||||
}
|
||||
\end{minted}
|
||||
|
||||
在中断处理函数中更新进程还剩余的时间片( \mintinline{C}{proc->time_slice} ,如果时间片用完了就把进程标记为需要重新调度。执行完 \mintinline{C}{trap_dispatch} 之后,在 \mintinline{C}{trap} 函数中有这样几行:
|
||||
\begin{minted}{C}
|
||||
if (current->need_resched) {
|
||||
schedule();
|
||||
}
|
||||
\end{minted}
|
||||
|
||||
这就是在当前进程需要重新调度时再次执行 \mintinline{C}{schedule} ,再看 \mintinline{C}{schedule} 的代码:
|
||||
\begin{minted}{C}
|
||||
void
|
||||
schedule(void) {
|
||||
bool intr_flag;
|
||||
struct proc_struct *next;
|
||||
local_intr_save(intr_flag);
|
||||
{
|
||||
current->need_resched = 0;
|
||||
if (current->state == PROC_RUNNABLE) {
|
||||
sched_class_enqueue(current);
|
||||
}
|
||||
if ((next = sched_class_pick_next()) != NULL) {
|
||||
sched_class_dequeue(next);
|
||||
}
|
||||
if (next == NULL) {
|
||||
next = idleproc;
|
||||
}
|
||||
next->runs ++;
|
||||
if (next != current) {
|
||||
proc_run(next);
|
||||
}
|
||||
}
|
||||
local_intr_restore(intr_flag);
|
||||
}
|
||||
\end{minted}
|
||||
|
||||
这里当前进程是 \mintinline{C}{PROC_RUNNABLE} 状态,所以会把当前进程放入队列(末尾),之后把下一个进程(从队首)取出,如果下一个进程不是idle进程,就执行下一个进程。下一个进程继续执行直到时间片用完(或提前结束或进入等待状态),这样就实现了时间片轮转。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
如何在uCore OS中设计实现“多级反馈队列调度算法”?请给出概要设计,鼓励给出详细设计。
|
||||
}{
|
||||
\begin{itemize}
|
||||
\item 初始化函数:初始化所有的多级队列,每个队列有不同的时间片大小;
|
||||
\item 入队函数:新的进程应该进入最高优先级的队列;
|
||||
\item 出队函数:进程在哪个队列就从哪个队列里出队;
|
||||
\item 选出下一个调度的进程:按照优先级从高到低遍历每个队列,找到一个不为空的队列后,选出队首的进程;
|
||||
\item 时钟中断时执行:如果当前进程的时间片用完,这时候就需要把这个进程从当前队列中取出,放到更低的优先级队列中;如果已经是最低优先级队列,就按照时间片轮转的方式,从队首取出放到队尾;
|
||||
\item 时钟中断时,如果比当前进程更高的优先级队列中存在进程,那么将当前进程的状态改为 \mintinline{C}{PROC_RUNNABLE} 并调用 \mintinline{C}{schedule} 进行重新调度,这是为了实现高优先级对低优先级的抢占式调度;
|
||||
\item IO中断时,将当前进程标记为等待IO;等到调用 \mintinline{C}{wakeup_proc} 唤醒进程时,如果此进程被标记了等待IO,那么此时将进程放到最高优先级队列,此时该进程会被优先调度,这是为了确保IO密集型的进程优先得到调度。
|
||||
\end{itemize}
|
||||
}
|
||||
\end{enumerate}
|
||||
\textbf{Lab7:}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[]{
|
||||
uCore OS与理论课的信号量机制的实现方案有何不同?请给出 理论课中的信号量机制的实现方案 的概要设计。
|
||||
}{}
|
||||
{\kaishu\setlength{\parskip}{2em}
|
||||
理论课中的信号量机制的实现方案直接简单地关闭中断,修改信号量的值,再开中断。但是在$\mu$Core中在进入临界区之后要进行进程的等待和唤醒。也就是在 \mintinline{C}{__down} 函数中,关闭中断后,访问 \mintinline{C}{sem->value} ,如果此信号量的值大于0那么正常修改后开中断。否则,说明进程需要等待,这时重新开启中断后会将进程放入等待队列,并且触发一次进程调度。
|
||||
\begin{minted}{C}
|
||||
bool intr_flag;
|
||||
local_intr_save(intr_flag);
|
||||
if (sem->value > 0) {
|
||||
sem->value --;
|
||||
local_intr_restore(intr_flag);
|
||||
return 0;
|
||||
}
|
||||
wait_t __wait, *wait = &__wait;
|
||||
wait_current_set(&(sem->wait_queue), wait, wait_state);
|
||||
local_intr_restore(intr_flag);
|
||||
|
||||
schedule();
|
||||
\end{minted}
|
||||
|
||||
当该进程被唤醒,并且被再次调度到时,就将其移出等待队列:
|
||||
\begin{minted}{C}
|
||||
local_intr_save(intr_flag);
|
||||
wait_current_del(&(sem->wait_queue), wait);
|
||||
local_intr_restore(intr_flag);
|
||||
|
||||
if (wait->wakeup_flags != wait_state) {
|
||||
return wait->wakeup_flags;
|
||||
}
|
||||
\end{minted}
|
||||
|
||||
在 \mintinline{C}{__up} 中,关闭中断后,如果当前的等待队列中有进程,那么需要唤醒队首的一个进程,并且将信号量的值加一,之后再开中断。
|
||||
\begin{minted}{C}
|
||||
if ((wait = wait_queue_first(&(sem->wait_queue))) == NULL) {
|
||||
sem->value ++;
|
||||
}
|
||||
\end{minted}
|
||||
|
||||
理论课中的信号量机制的实现方案只需要在 \mintinline{C}{up} 里关中断,修改信号量的值,开中断,在 \mintinline{C}{down} 里关中断,修改信号量的值,开中断。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
用户级信号量与内核级信号量有何不同?请给出在现有的内核级信号量基础上实现用户级信号量的概要设计。
|
||||
}{}
|
||||
{\kaishu\setlength{\parskip}{2em}
|
||||
用户级信号量的创建、访问、修改都是在用户态完成的,而内核级信号量的创建、访问、修改都是在内核态完成的。
|
||||
|
||||
在现有的内核级信号量基础上实现用户级信号量,最简单的方式是使用内核级信号量对一个用户空间中的变量当作临界资源访问,比如可以在用户空间中这样实现PV操作(以下P用acquire表示,V用release表示)
|
||||
|
||||
\begin{minted}{C}
|
||||
#define SLEEP_TIME 10 // 检测间隔
|
||||
|
||||
typedef struct {
|
||||
int value; // 用户级信号量的值
|
||||
semaphore_t sem; // 内核级信号量
|
||||
} user_semaphore;
|
||||
|
||||
void acquire(*user_semaphore) {
|
||||
while (1) { // 不断检测用户级信号量的值
|
||||
down(user_semaphore->sem); // 进入临界区
|
||||
if (user_semaphore->value > 0) {
|
||||
user_semaphore->value--; // 修改用户级信号量
|
||||
up(user_semaphore->); // 退出临界区
|
||||
return;
|
||||
}
|
||||
up(user_semaphore->sem); // 退出临界区
|
||||
do_sleep(SLEEP_TIME); // 用户进程将自己挂起
|
||||
}
|
||||
}
|
||||
|
||||
void release(*user_semaphore) {
|
||||
down(user_semaphore->sem); // 进入临界区
|
||||
user_semaphore->value++; // 修改用户级信号量
|
||||
up(user_semaphore->sem); // 退出临界区
|
||||
}
|
||||
\end{minted}
|
||||
|
||||
这里不需要init函数,因为创建变量的时候可以直接给value赋初值。
|
||||
|
||||
可以作个类比,由于不能一直处于关中断的状态(万一因为故障没有开中断),所以用关中断实现内核级信号量用来实现内核线程的同步互斥;由于不能一直处于内核态(权限过高不安全),所以用内核级信号量实现用户级信号量用来实现用户进程或线程的同步互斥。
|
||||
|
||||
当然也可以使用系统调用来实现用户级信号量,这里就不详述了。
|
||||
}
|
||||
\end{enumerate}
|
||||
\item \textbf{程序设计与实现的基本思路}
|
||||
|
||||
{\kaishu
|
||||
虽然是任选一题完成,但是写完一个后顺手就把另一个写了。
|
||||
|
||||
\textbf{Lab6:}
|
||||
\begin{enumerate}
|
||||
\item 彩票进程调度算法,还是比较容易的,每个进程设置了一个新的属性: \mintinline{C}{uint32_t lab6_ticket_start;}
|
||||
用来表示进程的第一个彩票的位置,并且使用原先就有的 \mintinline{C}{uint32_t lab6_priority;} 来表示进程的彩票个数(优先级越高彩票越多)。也就是 \mintinline{C}{lab6_ticket_start} 到 \mintinline{C}{lab6_ticket_start + lab6_priority} 这一部分都是进程拥有的彩票。
|
||||
\item 但是后来发现这样的话在进程退出时很麻烦,彩票中间空了一段的话就很难随机抽取彩票了,所以不用 \mintinline{C}{uint32_t lab6_ticket_start;} 了,而是在选择下一个进程时把队列中的进程彩票数量(优先级)加起来和随机到的彩票比较;
|
||||
\item 在运行队列中加了一个 \mintinline{C}{uint32_t lab6_total_num;} 属性,用来记录目前所有的进程总共有多少彩票;
|
||||
\item init函数没什么改的,enqueue函数里需要每次把 \mintinline{C}{lab6_total_num} 加上当前进程的优先级,dequeue函数也是每次把 \mintinline{C}{lab6_total_num} 减去当前进程的优先级。这里要注意优先级可能为0,但是如果一个进程有0张彩票的话那这个进程永远不会被调度到了,所以这里优先级加了1。但在 \mintinline{C}{lab6_set_priority} 这个函数中已经有类似的操作了:
|
||||
\begin{minted}{C}
|
||||
//FOR LAB6, set the process's priority (bigger value will get more CPU time)
|
||||
void
|
||||
lab6_set_priority(uint32_t priority)
|
||||
{
|
||||
if (priority == 0)
|
||||
current->lab6_priority = 1;
|
||||
else current->lab6_priority = priority;
|
||||
}
|
||||
\end{minted}
|
||||
|
||||
不过如果创建进程时没有调用 \mintinline{C}{lab6_set_priority} 那么默认的优先级好像就是0,所以自己计算的时候加一还是有必要的。
|
||||
\item proc\_tick函数也不需要改,彩票调度也是每过一个时间片发一次彩票;
|
||||
\item 最重要的就是 \mintinline{C}{ticket_pick_next} 函数了,每次调用时先随机抽取一张彩票 \mintinline{C}{target_index} :
|
||||
\mint{C}|uint32_t target_index = rand() % rq->lab6_total_num;|
|
||||
然后遍历队列,每次把 \mintinline{C}{temp_ticket_num} 加上当前进程的优先级(加一),如果加上之后达到了 \mintinline{C}{target_index} ,那么也就说明这个彩票在这个进程拥有的彩票范围之间,那么就选择这个进程:
|
||||
\begin{minted}{C}
|
||||
struct proc_struct *p;
|
||||
int32_t temp_ticket_sum = 0;
|
||||
while (le != &rq->run_list)
|
||||
{
|
||||
p = le2proc(le, run_link);
|
||||
temp_ticket_sum += p->lab6_priority + 1;
|
||||
if (temp_ticket_sum >= target_index)
|
||||
break;
|
||||
le = list_next(le);
|
||||
}
|
||||
\end{minted}
|
||||
\item 之后就是要检验这个调度是否有问题了,只需要在 \mintinline{C}{proc.c} 中创建多个优先级不同的进程即可,会自动完成调度。(这里优先级为了看起来方便就使用了 \mintinline{C}{(rand() % 100) * 100} ,也可以设置其他的优先级)
|
||||
\begin{minted}{C}
|
||||
static int
|
||||
my_test_user_main(void *arg) {
|
||||
int num = (int)arg;
|
||||
int priority = (rand() % 100) * 100;
|
||||
cprintf("process %d, priority %d\n", num, priority);
|
||||
lab6_set_priority(priority);
|
||||
cprintf("process %d end\n", num);
|
||||
}
|
||||
\end{minted}
|
||||
\begin{minted}{C}
|
||||
int i = 0;
|
||||
for (; i < 10; i++) {
|
||||
int pid = kernel_thread(my_test_user_main, (void *)i, 0);
|
||||
struct proc_strucht *proc = find_proc(pid);
|
||||
}
|
||||
\end{minted}
|
||||
\end{enumerate}
|
||||
\textbf{Lab7:}
|
||||
\begin{enumerate}
|
||||
\item 读者写者问题的同步关系,更简单了,课件中已经给了代码,只需要稍微改改就能用:
|
||||
\begin{center}
|
||||
\includegraphics[width=0.8\linewidth]{imgs/2024-06-10-22-08-03.png}
|
||||
\end{center}
|
||||
|
||||
\item 原先的代码在 \mintinline{C}{lab7_result/kern/sync/check_sync.c} 实现了哲学家就餐问题,这里就新建了一个 \mintinline{C}{read_write_sync.c} 实现读者写者问题,并在 \mintinline{C}{proc.c} 中将原先的 \mintinline{C}{check_sync} 改为 \mintinline{C}{read_write_sync} 。
|
||||
\item 这里的读者写者问题只有一个缓冲区,信号量定义了两个, \mintinline{C}{semaphore_t mutex} 用来互斥,与课件中的 \mintinline{C}{mutex} 一样, \mintinline{C}{semaphore_t synchronization} 用来同步,相当于课件中的 \mintinline{C}{wrt} , \mintinline{C}{read_pos_write_neg} 相当于课件中的 \mintinline{C}{readcount} 。
|
||||
\item 但是对于信号量的初始化的操作要在主进程里做而不能在定义时赋初值,这里的主进程就是 \mintinline{C}{read_write_sync} ,在主进程中随机创建读者进程和写者进程(直到达到目标数量),并随机延迟,这样就能体现出读者和写者在不同情况下的互斥与同步是否正确;
|
||||
\item 读者和写者的读操作和写操作也用 \mintinline{C}{do_sleep} 来模拟延迟,并且在每个读者或写者完成所有操作后打印读取的结果或写入的结果便于观察。
|
||||
\end{enumerate}
|
||||
}
|
||||
\myitem{代码}{
|
||||
\item \url{https://gitea.shuishan.net.cn/10213903403/os_kernel_lab}
|
||||
\item 也可以看上传的附件。
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
115
操作系统/实验报告/mypreamble.tex
Normal file
115
操作系统/实验报告/mypreamble.tex
Normal file
@ -0,0 +1,115 @@
|
||||
\usepackage[margin=1in]{geometry}
|
||||
\usepackage{longtable}
|
||||
\usepackage{booktabs}
|
||||
\usepackage{zhnumber} % change section number to chinese
|
||||
% \usepackage{enumerate}
|
||||
\usepackage{enumitem}
|
||||
\usepackage{titlesec}
|
||||
\usepackage{fancyhdr}
|
||||
\usepackage{environ} % 加了这个再\def\myitem就不报错了
|
||||
% \usepackage[outputdir=./latex-output]{minted}
|
||||
\usepackage{float} % https://blog.csdn.net/qq_32623363/article/details/101095168
|
||||
\usepackage{fp}
|
||||
\usepackage{graphicx} % 原来includegraphics要使用参数要用graphicx,只是用graphics是没法带参数的
|
||||
\usepackage{tabularx}
|
||||
\usepackage{array}
|
||||
\usepackage{ragged2e}
|
||||
\usepackage{multirow}
|
||||
\usepackage{url}
|
||||
\usepackage{color}
|
||||
\usepackage{mylatex}
|
||||
\usepackage{totpages} % 不加这个会导致总页数出错
|
||||
\pagestyle{fancyplain}
|
||||
\fancyhead{}
|
||||
\fancyhead[C]{华东师范大学计算机科学与技术学院上机实践报告}
|
||||
\fancyfoot[C]{第 \thepage 页\quad 共 \ref{TotPages} 页}
|
||||
\renewcommand\thesection{\zhnum{section}}
|
||||
\renewcommand \thesubsection {\arabic{subsection}}
|
||||
\setlist[1]{label=\zhnum{enumi}、}
|
||||
\setlist[2]{listparindent=2em, labelindent=-1em, leftmargin=*, label=\arabic{enumii}、\ }
|
||||
\setlist[3]{listparindent=2em, leftmargin=*, label=(\arabic{enumiii})\ }
|
||||
\definecolor{shadecolor}{RGB}{204,232,207}
|
||||
\definecolor{bg}{rgb}{0.95,0.95,0.95}
|
||||
\setminted{breaklines=true, frame=single} % , bgcolor=bg
|
||||
\setmintedinline{bgcolor={}}
|
||||
\setitemize[1]{label=\textbullet}
|
||||
|
||||
\newcommand{\mydate}{
|
||||
2023年11月3日
|
||||
}
|
||||
|
||||
\newcommand{\mychapternum}{
|
||||
1
|
||||
}
|
||||
|
||||
\newcommand{\mylabname}{
|
||||
实验名称
|
||||
}
|
||||
|
||||
\newcommand{\myname}{
|
||||
姓名
|
||||
}
|
||||
|
||||
\newcommand{\mystudentnum}{
|
||||
e.g. 12345678902
|
||||
}
|
||||
|
||||
\input{myprivatepreamble}
|
||||
|
||||
\newcommand{\mytitle}{
|
||||
\title{\fontsize{15}{0}华东师范大学计算机科学与技术学院上机实践报告\vspace{-2em}}
|
||||
\date{}
|
||||
\maketitle
|
||||
|
||||
\begin{center}
|
||||
\begin{tabularx}{\textwidth}{XXl}
|
||||
\toprule
|
||||
\textbf{课程名称}:操作系统 & \textbf{年级}:2022级 & \textbf{上机实践日期}:\mydate \\
|
||||
\textbf{指导教师}:李东 & \textbf{姓名}:\myname & \textbf{学号}:\mystudentnum \\
|
||||
\multicolumn{3}{l}{\textbf{实验名称}:实验\zhnumber{\mychapternum}\quad\mylabname} \\
|
||||
\bottomrule
|
||||
\end{tabularx}
|
||||
\end{center}
|
||||
\addtocounter{table}{-1}
|
||||
\vspace{1em}
|
||||
}
|
||||
|
||||
\newcommand{\myitemx}[3][]{
|
||||
\item \textbf{#2}
|
||||
\begin{enumerate}[#1]
|
||||
#3
|
||||
\end{enumerate}
|
||||
}
|
||||
|
||||
% https://blog.csdn.net/u010801696/article/details/79477226
|
||||
\def\UrlBreaks{\do\A\do\B\do\C\do\D\do\E\do\F\do\G\do\H\do\I\do\J
|
||||
\do\K\do\L\do\M\do\N\do\O\do\P\do\Q\do\R\do\S\do\T\do\U\do\V
|
||||
\do\W\do\X\do\Y\do\Z\do\[\do\\\do\]\do\^\do\_\do\`\do\a\do\b
|
||||
\do\c\do\d\do\e\do\f\do\g\do\h\do\i\do\j\do\k\do\l\do\m\do\n
|
||||
\do\o\do\p\do\q\do\r\do\s\do\t\do\u\do\v\do\w\do\x\do\y\do\z
|
||||
\do\.\do\@\do\\\do\/\do\!\do\_\do\|\do\;\do\>\do\]\do\)\do\,
|
||||
\do\?\do\'\do+\do\=\do\#}
|
||||
|
||||
\renewcommand{\thefigure}{\mychapternum-\arabic{figure}}
|
||||
\renewcommand{\thetable}{\mychapternum-\arabic{table}}
|
||||
|
||||
|
||||
% https://mirrors.pku.edu.cn/ctan/info/svg-inkscape/InkscapePDFLaTeX.pdf
|
||||
% 这个只有PDFLaTeX才能用,filemod也是
|
||||
% \newcommand{\executeiffilenewer}[3]{%
|
||||
% \ifnum\pdfstrcmp{\pdffilemoddate{#1}}%
|
||||
% {\pdffilemoddate{#2}}>0%
|
||||
% {\immediate\write18{#3}}\fi%
|
||||
% }
|
||||
|
||||
|
||||
% 该命令用于控制 p{} 的情况
|
||||
\newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}}p{#1}} % 使用过程中,将p{4cm}换成P{4cm},小写改成大写即可!
|
||||
% 该命令用于控制 X 的情况
|
||||
\newcolumntype{Z}{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}X} % 使用过程中,将Z 换成 X,即可!
|
||||
|
||||
% 可利用 RaggedLeft Centering替换RaggedRight,实现靠右和居中 [代码对大小写敏感!!!!!!!!!!!!!!!!!!!!!!!!!!!!]
|
||||
|
||||
% 原文链接:https://blog.csdn.net/wanjiac/article/details/107494424
|
||||
|
||||
\setminted{fontsize=\zihao{6}, baselinestretch=1}
|
101
数字逻辑及实验/作业/mypreamble.tex
Normal file
101
数字逻辑及实验/作业/mypreamble.tex
Normal file
@ -0,0 +1,101 @@
|
||||
\usepackage[margin=1in]{geometry}
|
||||
\usepackage{longtable}
|
||||
\usepackage{booktabs}
|
||||
\usepackage{array}
|
||||
\usepackage{zhnumber} % change section number to chinese
|
||||
% \usepackage{enumerate}
|
||||
\usepackage{enumitem}
|
||||
\usepackage{titlesec}
|
||||
\usepackage{fancyhdr}
|
||||
\usepackage{environ} % 加了这个再\def\myitem就不报错了
|
||||
\usepackage[outputdir=./latex-output]{minted}
|
||||
\usepackage{extarrows}
|
||||
\usepackage{amssymb, amsfonts, amstext, amsmath, amsopn, amsthm}
|
||||
\usepackage{multirow}
|
||||
\usepackage{fp}
|
||||
\usepackage{multicol}
|
||||
\usepackage{pdfpages}
|
||||
\usepackage{hyperref}
|
||||
\usepackage{mylatex}
|
||||
\usepackage{subfiles}
|
||||
\usepackage{totpages} % 不加这个会导致总页数出错
|
||||
% \usepackage{pgfplots}
|
||||
% \pgfmathsetmacro{\totalpages}{\totalpages+1}
|
||||
% \setcounter{totalpages}{1}
|
||||
\pagestyle{fancyplain}
|
||||
\title{\heiti\zihao{2} 《数字逻辑及实验》作业}
|
||||
\author{\songti 岳锦鹏}
|
||||
\date{2023年9月18日}
|
||||
\fancyhead{}
|
||||
\fancyfoot[C]{第 \thepage 页\quad 共 \ref{TotPages} 页}
|
||||
\renewcommand\thesection{\zhnum{section}}
|
||||
\renewcommand \thesubsection {\arabic{subsection}}
|
||||
\setlist[1]{label=\arabic{enumi}.,listparindent=\parindent}
|
||||
\setlist[2]{label=(\arabic{enumii}),listparindent=\parindent}
|
||||
|
||||
% 就为了加个\noindent,但是没有装饰器,也没有继承,只能把原来的函数复制一份
|
||||
% TODO: 试试expl3中有没有类似装饰器和继承的写法
|
||||
\renewcommand{\includexopp}[2][1]{
|
||||
\executeiffilenewer{./xournalpp/#2.xopp}{./latex-output/xournalpp-output/#2.pdf}%
|
||||
{xournalpp -p ./latex-output/xournalpp-output/#2.pdf ./xournalpp/#2.xopp && pdfcrop ./latex-output/xournalpp-output/#2.pdf ./latex-output/xournalpp-output/#2.pdf}
|
||||
|
||||
\FPset\originwidth{#1}
|
||||
\FPset\one{1}
|
||||
|
||||
\FPifgt\originwidth\one
|
||||
\FPdiv\targetwidth\one\originwidth
|
||||
\begin{center}
|
||||
\noindent\includegraphics[width=\FPprint\targetwidth\linewidth]{./latex-output/xournalpp-output/#2.pdf}
|
||||
\end{center}
|
||||
\else
|
||||
\noindent\includegraphics[width=#1\linewidth]{./latex-output/xournalpp-output/#2.pdf}
|
||||
\fi
|
||||
}
|
||||
|
||||
|
||||
\newcommand{\mydate}{
|
||||
2023/09/23
|
||||
}
|
||||
|
||||
\newcommand{\mytitle}{
|
||||
\title{\fontsize{15}{0}华东师范大学计算机科学与技术学院上机实践报告\vspace{-2em}}
|
||||
\date{}
|
||||
\maketitle
|
||||
|
||||
\begin{longtable}[]{lll}
|
||||
\toprule\noalign{}
|
||||
\endhead
|
||||
\bottomrule\noalign{}
|
||||
\endlastfoot
|
||||
\textbf{课程名称}:数据结构 & \textbf{年级}:2022级 &
|
||||
\textbf{上机实践成绩}: \\
|
||||
\textbf{指导教师}:金健 & \textbf{姓名}:岳锦鹏 &
|
||||
\textbf{上机实践时间}:2学时 \\
|
||||
\textbf{上机实践名称}:第一章作业 & \textbf{学号}:10213903403 &
|
||||
\textbf{上机实践日期}:\mydate \\
|
||||
\end{longtable}
|
||||
}
|
||||
|
||||
|
||||
\def\getenum{%
|
||||
\ifnum\EnumitemId=1%
|
||||
enumi%
|
||||
\else
|
||||
\ifnum\EnumitemId=2%
|
||||
enumii%
|
||||
\else
|
||||
\ifnum\EnumitemId=3%
|
||||
enumiii%
|
||||
\else%
|
||||
enumiv%
|
||||
\fi
|
||||
\fi
|
||||
\fi%
|
||||
}
|
||||
|
||||
\newcommand{\cnitem}[1][]{
|
||||
\IfBlankF{#1}{
|
||||
\setcounter{\getenum}{#1-1}
|
||||
}
|
||||
\item
|
||||
}
|
18
数字逻辑及实验/作业/全部作业.tex
Normal file
18
数字逻辑及实验/作业/全部作业.tex
Normal file
@ -0,0 +1,18 @@
|
||||
\documentclass[a4paper]{ctexbook}
|
||||
\input{mypreamble}
|
||||
\title{\heiti\zihao{2} 《数字逻辑及实验》作业}
|
||||
\author{\songti 岳锦鹏}
|
||||
\newcommand{\mysignature}{10213903403 岳锦鹏}
|
||||
\date{2023年9月18日 —— 2023年12月28日}
|
||||
\begin{document}
|
||||
% \renewcommand{\bar}{\xoverline} % 这一行在编译时可以取消注释,注意一定要放在\begin{document}下面才有用
|
||||
% \renewcommand{\overline}{\xoverline} % 这样会导致递归展开错误,暂时未解决
|
||||
\maketitle
|
||||
\tableofcontents
|
||||
\subfile{第一章作业-订正.tex}
|
||||
\chapter{组合逻辑电路}
|
||||
\includepdf[pages={1-12}]{第二章作业.pdf}
|
||||
\subfile{第三章作业.tex}
|
||||
\subfile{第四章作业.tex}
|
||||
\subfile{第五章作业.tex}
|
||||
\end{document}
|
95
数字逻辑及实验/作业/实验报告/mypreamble.tex
Normal file
95
数字逻辑及实验/作业/实验报告/mypreamble.tex
Normal file
@ -0,0 +1,95 @@
|
||||
\usepackage[margin=1in]{geometry}
|
||||
\usepackage{longtable}
|
||||
\usepackage{booktabs}
|
||||
\usepackage{array}
|
||||
\usepackage{zhnumber} % change section number to chinese
|
||||
% \usepackage{enumerate}
|
||||
\usepackage{enumitem}
|
||||
\usepackage{titlesec}
|
||||
\usepackage{fancyhdr}
|
||||
\usepackage{environ} % 加了这个再\def\myitem就不报错了
|
||||
\usepackage[outputdir=./latex-output]{minted}
|
||||
\usepackage{subfiles}
|
||||
\usepackage{xcolor}
|
||||
\usepackage{booktabs}
|
||||
% \usepackage{tabularx}
|
||||
\usepackage{multirow}
|
||||
\usepackage{amsmath}
|
||||
\usepackage{caption}
|
||||
\usepackage{subcaption}
|
||||
\usepackage{graphics}
|
||||
\usepackage{mylatex}
|
||||
\usepackage{fp}
|
||||
% \usepackage{floatrow} % TODO: 出现未解决的报错,可能和别的包冲突
|
||||
\usepackage{totpages} % 不加这个会导致总页数出错
|
||||
\usepackage{flowchart}
|
||||
\usetikzlibrary{arrows}
|
||||
% \usepackage{pgfplots}
|
||||
% \pgfmathsetmacro{\totalpages}{\totalpages+1}
|
||||
% \setcounter{totalpages}{1}
|
||||
\pagestyle{fancyplain}
|
||||
\fancyhead{}
|
||||
\fancyhead[C]{华东师范大学计算机科学与技术学院上机实践报告}
|
||||
\fancyfoot[C]{第 \thepage 页\quad 共 \ref{TotPages} 页}
|
||||
\renewcommand\thesection{\zhnum{section}}
|
||||
\renewcommand \thesubsection {\arabic{subsection}}
|
||||
\setlist[1]{label=\zhnum{enumi}、, listparindent=\parindent}
|
||||
\setlist[2]{labelindent=-1em, leftmargin=*, label=\arabic{enumii}.\quad, listparindent=\parindent}
|
||||
|
||||
\newcommand{\mydate}{
|
||||
2023/09/23
|
||||
}
|
||||
|
||||
\newcommand{\mychapternum}{
|
||||
1
|
||||
}
|
||||
|
||||
\newcommand{\mytitle}{
|
||||
\title{\fontsize{15}{0}华东师范大学计算机科学与技术学院上机实践报告\vspace{-2em}}
|
||||
\date{}
|
||||
\maketitle
|
||||
\setlength{\tabcolsep}{2em}
|
||||
|
||||
\begin{longtable}[]{lll}
|
||||
\toprule\noalign{}
|
||||
\endhead
|
||||
\bottomrule\noalign{}
|
||||
\endlastfoot
|
||||
\textbf{课程名称}:数字逻辑及实验 & \textbf{年级}:2022级 &
|
||||
\textbf{上机实践成绩}: \\
|
||||
\textbf{指导教师}:施维良 & \textbf{姓名}:岳锦鹏 &
|
||||
\textbf{上机实践日期}:\mydate \\
|
||||
\textbf{实践编号}:实验\zhnumber{\mychapternum} & \textbf{学号}:10213903403 &
|
||||
\textbf{上机实践时间}:2学时 \\
|
||||
\end{longtable}
|
||||
\setcounter{table}{0} % 这个表格不应算,最好改成当前序号减一(TODO)
|
||||
}
|
||||
|
||||
% \def\myitem#1#2{
|
||||
% \item \textbf{#1}
|
||||
% \begin{enumerate}
|
||||
% #2
|
||||
% \end{enumerate}
|
||||
% }
|
||||
|
||||
\renewcommand{\thefigure}{\mychapternum.\arabic{figure}}
|
||||
\renewcommand{\thetable}{\mychapternum.\arabic{table}}
|
||||
|
||||
% 就为了加个\noindent,但是没有装饰器,也没有继承,只能把原来的函数复制一份
|
||||
% TODO: 试试expl3中有没有类似装饰器和继承的写法
|
||||
\renewcommand{\includexopp}[2][1]{
|
||||
\executeiffilenewer{./xournalpp/#2.xopp}{./latex-output/xournalpp-output/#2.pdf}%
|
||||
{xournalpp -p ./latex-output/xournalpp-output/#2.pdf ./xournalpp/#2.xopp && pdfcrop ./latex-output/xournalpp-output/#2.pdf ./latex-output/xournalpp-output/#2.pdf}
|
||||
|
||||
\FPset\originwidth{#1}
|
||||
\FPset\one{1}
|
||||
|
||||
\FPifgt\originwidth\one
|
||||
\FPdiv\targetwidth\one\originwidth
|
||||
\begin{center}
|
||||
\noindent\includegraphics[width=\FPprint\targetwidth\linewidth]{./latex-output/xournalpp-output/#2.pdf}
|
||||
\end{center}
|
||||
\else
|
||||
\noindent\includegraphics[width=#1\linewidth]{./latex-output/xournalpp-output/#2.pdf}
|
||||
\fi
|
||||
}
|
178
数字逻辑及实验/作业/实验报告/实验2.tex
Normal file
178
数字逻辑及实验/作业/实验报告/实验2.tex
Normal file
@ -0,0 +1,178 @@
|
||||
\documentclass[实验报告模板]{subfiles}
|
||||
|
||||
\renewcommand{\mydate}{2023/10/19}
|
||||
\renewcommand{\mychapternum}{2}
|
||||
|
||||
\captionsetup{labelformat=empty,labelsep=space}
|
||||
|
||||
|
||||
\begin{document}
|
||||
\renewcommand{\bar}{\xoverline} % 这一行在编译时可以取消注释,注意一定要放在\begin
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{实验目的}{
|
||||
\item 掌握利用基本门电路设计组合逻辑电路的方法。
|
||||
\item 验证所设计的电路的逻辑功能。
|
||||
}
|
||||
\myitem{实验内容及步骤}{
|
||||
\item 试使用与非门设计一个表决电路,其中 A、B、C、D 四个各自投票时,其分数
|
||||
分别为 3 分、2 分、1 分、1 分,只有得票总分大于 4 分时该提案通过。绿灯亮
|
||||
表示提案通过,红灯亮表示提案未通过。
|
||||
\item 试用门电路实现表 2.2 的逻辑功能。
|
||||
% \vspace{1em}\\
|
||||
% \includesvg{table.2-2}
|
||||
% \renewcommand {\thetable} {\thechapter{}.\arabic{table}}
|
||||
\begin{table}[h]
|
||||
\centering
|
||||
\caption{表2-2}
|
||||
\setlength{\tabcolsep}{2em}
|
||||
% \resizebox{\textwidth}{1.0in}{
|
||||
% \begin{tabularx}{\textwidth}{cp{5cm}c|cc}
|
||||
\begin{tabular}{ccc|cc}
|
||||
\toprule
|
||||
\multicolumn{3}{c}{输入} \vline& \multicolumn{2}{c}{输出}\\
|
||||
% \hline
|
||||
A & B & C & S1 & S2\\
|
||||
\midrule
|
||||
% \cline{1-3}\noalign{\bigskip}
|
||||
% \cline{4-5}
|
||||
0 & 0 & 0 & 0 & 0 \\
|
||||
0 & 0 & 1 & 1 & 0 \\
|
||||
0 & 1 & 0 & 1 & 0 \\
|
||||
0 & 1 & 1 & 0 & 1 \\
|
||||
1 & 0 & 0 & 1 & 0 \\
|
||||
1 & 0 & 1 & 0 & 1 \\
|
||||
1 & 1 & 0 & 0 & 1 \\
|
||||
1 & 1 & 1 & 1 & 1 \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{table}
|
||||
\item 试设计一个两位数的比较器。输入分别是 $A_0A_1$,和 $B_0B_1$,当 $A_0A_1 > B_0B_1$,时,输出
|
||||
为 $01$;当 $A_0A_1<B_0B_1$,时,输出为 $10$。要求用与非门电路实现。
|
||||
}
|
||||
\myitem{实验原理}{
|
||||
\item 首先画出真值表如下,设ST为10表示提案通过,即绿灯亮;ST为01表示提案未通过,即红灯亮。
|
||||
\pagebreak[4]
|
||||
\begin{table}[H]
|
||||
\centering
|
||||
\caption{第1题真值表}
|
||||
\begin{tabular}{cccc|cc}
|
||||
\toprule
|
||||
\multicolumn{4}{c}{输入} \vline& \multicolumn{2}{c}{输出}\\
|
||||
A & B & C & D & S & T\\
|
||||
\midrule
|
||||
0 & X & X & X & 0 & 1\\
|
||||
1 & 0 & 0 & X & 0 & 1\\
|
||||
1 & 0 & X & 0 & 0 & 1\\
|
||||
1 & X & 1 & 1 & 1 & 0\\
|
||||
1 & 1 & X & X & 1 & 0\\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{table}
|
||||
根据真值表,可以构造出逻辑表达式如下:
|
||||
$$
|
||||
S=AB+ACD=\overline{\overline{AB}\ \overline{ACD}}
|
||||
$$ $$
|
||||
T=\bar{S}
|
||||
$$\\
|
||||
% \doublespace
|
||||
根据逻辑表达式,可以画出电路图如下:\\
|
||||
\begin{figure}[H]
|
||||
\centering
|
||||
% \captionsetup{font={Large}}
|
||||
\begin{minipage}[H]{0.6\linewidth}
|
||||
\includesvg{2.1.drawio}
|
||||
\caption{2.1电路图}
|
||||
\end{minipage}
|
||||
\end{figure}
|
||||
\item 根据真值表,可以画出卡诺图如下:\\
|
||||
\pagebreak[4]
|
||||
% \resizebox{\columnwidth}{!}{
|
||||
\begin{figure}[H]
|
||||
\centering
|
||||
% \captionsetup{font={Huge}}
|
||||
\begin{minipage}[h]{0.3\linewidth}
|
||||
\centering
|
||||
\includesvg{2.2.S1}
|
||||
\caption{第2题S1}
|
||||
\end{minipage}
|
||||
% \import{./latex-output/svg-inkscape-output/}{2.2.S1.pdf_tex}
|
||||
% }
|
||||
\hspace{0.2\linewidth}
|
||||
% \resizebox{0.5\columnwidth}{!}{
|
||||
\begin{minipage}[h]{0.3\linewidth}
|
||||
\centering
|
||||
\includesvg{2.2.S2}
|
||||
\caption{第2题S2}
|
||||
\end{minipage}
|
||||
\end{figure}
|
||||
% \import{./latex-output/svg-inkscape-output/}{2.2.S2.pdf_tex}
|
||||
% }
|
||||
根据卡诺图,可以构造出逻辑表达式如下:
|
||||
$$
|
||||
S1=A \oplus B \oplus C
|
||||
$$ $$
|
||||
S2=AB+BC+AC=\overline{\overline{AB}\ \overline{BC}\ \overline{AC}}
|
||||
$$
|
||||
根据逻辑表达式,可以画出电路图如下:\\
|
||||
\begin{figure}[H]
|
||||
\centering
|
||||
% \captionsetup{font={Large}}
|
||||
\begin{minipage}[H]{0.6\linewidth}
|
||||
\includesvg{2.2.drawio}
|
||||
\caption{2.2电路图}
|
||||
\end{minipage}
|
||||
\end{figure}
|
||||
\item 根据题意画出真值表如下:\\
|
||||
\begin{table}[H]
|
||||
\centering
|
||||
\caption{第3题真值表}
|
||||
\begin{tabular}{cccc|cc}
|
||||
\toprule
|
||||
\multicolumn{4}{c}{输入} \vline& \multicolumn{2}{c}{输出}\\
|
||||
A0 & A1 & B0 & B1 & S0 & S1\\
|
||||
\midrule
|
||||
0 & 0 & 0 & 0 & 1 & 0 \\
|
||||
0 & 0 & 0 & 1 & 1 & 0 \\
|
||||
0 & 0 & 1 & X & 1 & 0 \\
|
||||
0 & 1 & 0 & 0 & 0 & 1 \\
|
||||
0 & 1 & 0 & 1 & 1 & 0 \\
|
||||
0 & 1 & 1 & X & 1 & 0 \\
|
||||
1 & 0 & 0 & X & 0 & 1 \\
|
||||
1 & 0 & 1 & 0 & 1 & 0 \\
|
||||
1 & 0 & 1 & 1 & 1 & 0 \\
|
||||
1 & 1 & 0 & X & 0 & 1 \\
|
||||
1 & 1 & 1 & 0 & 0 & 1 \\
|
||||
1 & 1 & 1 & 1 & 1 & 0 \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{table}
|
||||
根据真值表,可以画出S0的卡诺图如下:(S1可以由S0通过取反直接得到)\\
|
||||
\begin{figure}[H]
|
||||
\centering
|
||||
% \captionsetup{font={Huge}}
|
||||
\begin{minipage}[h]{0.5\linewidth}
|
||||
\includesvg{2.3.S0}
|
||||
\caption{第3题S0}
|
||||
\end{minipage}
|
||||
\end{figure}
|
||||
根据卡诺图,可以构造出逻辑表达式如下:
|
||||
$$
|
||||
S0=\bar{A0} \bar{A1}+ B0B1+\bar{A0} B0 + \bar{A0}B1 + \bar{A1} B0=\overline{\overline{\bar{A0} \bar{A1}}\ \overline{B0B1}\ \overline{\bar{A0} B0}\ \overline{\bar{A0}B_1}\ \overline{\bar{A1}B0}}
|
||||
$$\\
|
||||
% \pagebreak[1]
|
||||
根据逻辑表达式,可以画出电路图如下:
|
||||
\begin{figure}[H]
|
||||
\centering
|
||||
% \captionsetup{font={Large}}
|
||||
\begin{minipage}[h]{\linewidth}
|
||||
\includesvg{2.3.drawio}
|
||||
\caption{2.3电路图}
|
||||
\end{minipage}
|
||||
\end{figure}
|
||||
}
|
||||
\myitem{理论计算,实验结果及分析}{
|
||||
\item 经检验,理论正确。
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
110
数字逻辑及实验/作业/实验报告/实验3.tex
Normal file
110
数字逻辑及实验/作业/实验报告/实验3.tex
Normal file
@ -0,0 +1,110 @@
|
||||
\documentclass[实验报告模板]{subfiles}
|
||||
|
||||
\renewcommand{\mydate}{2023/10/26}
|
||||
\renewcommand{\mychapternum}{3}
|
||||
|
||||
\renewcommand{\thefigure}{\mychapternum.\arabic{figure}} % set caption label style to 1.1
|
||||
\renewcommand{\thetable}{\mychapternum.\arabic{table}}
|
||||
\renewcommand{\thesubfigure}{\arabic{subfigure}}
|
||||
\captionsetup{labelformat=default,labelsep=space}
|
||||
|
||||
\begin{document}
|
||||
\renewcommand{\bar}{\xoverline}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{实验目的}{
|
||||
\item 掌握中规模器件——数据选择器、数据分配器的特性及使用方法。
|
||||
\item 熟悉用数据选择器、数据分配器设计组合逻辑电路,并验证其逻辑功能。
|
||||
}
|
||||
\myitem{实验内容及步骤}{
|
||||
\item 测试八选一数据选择器 74LS151 的逻辑功能。
|
||||
\item 用 1 片八选一数据选择器 74LS151 加必要的门电路实现函数$Q=ABC+A \bar{C}DF+\bar{B}CD+BC \bar{D}F+\bar{C} \bar{D} \bar{F} + CD \bar{F}$并用实验验证。
|
||||
\item 用数据选择器和数据分配器(译码器)组成的信号传输系统如图 \ref{fig:3.7} 所示。
|
||||
当输入信号为 10010100 时(高位在前),数据开关控制地址选择信号逐次递增,
|
||||
记录输出信息并填入表 \ref{table:3.4} 中。
|
||||
}
|
||||
\myitem{实验原理}{
|
||||
\item 测试八选一数据选择器 74LS151 的逻辑功能。
|
||||
\begin{figure}[H]
|
||||
\centering
|
||||
% 用subfigure时,图像居中了,但标签没有底对齐了;
|
||||
% 用subfloat时,标签底对齐了,但图像不居中了。
|
||||
% \begin{subfigure}[H]{0.4\linewidth}
|
||||
% \includegraphics[width=1\linewidth]{imgs/2023-10-25-08-39-42.png}
|
||||
% \caption{引脚图}\label{fig:1a}
|
||||
% \end{subfigure}
|
||||
% \begin{subfigure}[H]{0.4\linewidth}
|
||||
% \includegraphics[width=1\linewidth]{imgs/2023-10-25-08-40-00.png}
|
||||
% \caption{引脚图}\label{fig:1b}
|
||||
% \end{subfigure}
|
||||
\subfloat[valign=middle][引脚图]{
|
||||
% \begin{minipage}[H]{0.4\linewidth}
|
||||
\label{fig:1a}\includegraphics[width=0.4\linewidth]{imgs/2023-10-25-08-39-42.png}
|
||||
% \end{minipage}
|
||||
}\quad
|
||||
\subfloat[valign=middle][引脚图]{
|
||||
\label{fig:1b}\includegraphics[width=0.4\linewidth]{imgs/2023-10-25-08-40-00.png}
|
||||
}\\
|
||||
\caption{八选一数据选择器 74LS151 的引脚图}\label{fig:1}
|
||||
\end{figure}
|
||||
\begin{table}[H]
|
||||
\caption{八选一数据选择器 74LS151 的真值表}\includegraphics[width=1\linewidth]{imgs/2023-10-25-09-24-14.png}
|
||||
\end{table}
|
||||
\item 用 1 片八选一数据选择器 74LS151 加必要的门电路实现函数$Q=ABC+A \bar{C}DF+\bar{B}CD+BC \bar{D}F+\bar{C} \bar{D} \bar{F} + CD \bar{F}$并用实验验证。\\
|
||||
根据原式画出卡诺图如下:\\
|
||||
\includesvg{3.2.1}
|
||||
将卡诺图降维成影射变量卡诺图如下:\\
|
||||
\includesvg{3.2.2}\\
|
||||
再次降维如下:\\
|
||||
% \small
|
||||
\includesvg{3.2.3}\\
|
||||
% \normalsize
|
||||
电路图如下:\\
|
||||
\begin{figure}[H]
|
||||
% \centering
|
||||
% \begin{minipage}[h]{0.5\linewidth}
|
||||
\centering
|
||||
\includesvgpdf{3.2.4.drawio}
|
||||
% \end{minipage}
|
||||
\caption{第2题电路图}
|
||||
\end{figure}
|
||||
\item 用数据选择器和数据分配器(译码器)组成的信号传输系统如图 \ref{fig:3.7} 所示。
|
||||
当输入信号为 10010100 时(高位在前),数据开关控制地址选择信号逐次递增,
|
||||
记录输出信息并填入表 \ref{table:3.4} 中。\\
|
||||
\begin{figure}[H]
|
||||
\centering
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-10-25-16-22-59.png}
|
||||
\caption{数据传输系统示意图}\label{fig:3.7}
|
||||
\end{figure}
|
||||
\begin{table}[H]
|
||||
\centering
|
||||
\setlength{\tabcolsep}{1.2em}
|
||||
\caption{第三题记录}\label{table:3.4}
|
||||
\begin{tabular}{c|ccc|cccccccc}
|
||||
\toprule
|
||||
$D_i$ & $A_2$ & $A_1$ & $A_0$ & $Y_7$ & $Y_6$ & $Y_5$ & $Y_4$ & $Y_3$ & $Y_2$ & $Y_1$ & $Y_0$\\
|
||||
\midrule
|
||||
0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 \\
|
||||
0 & 0 & 0 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & 1 \\
|
||||
1 & 0 & 1 & 0 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\
|
||||
0 & 0 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & 1 & 1 & 1 \\
|
||||
1 & 1 & 0 & 0 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\
|
||||
0 & 1 & 0 & 1 & 1 & 1 & 0 & 1 & 1 & 1 & 1 & 1 \\
|
||||
0 & 1 & 1 & 0 & 1 & 0 & 1 & 1 & 1 & 1 & 1 & 1 \\
|
||||
1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{table}
|
||||
}
|
||||
\myitem{思考题}{
|
||||
\item 试设计用八选一数据选择器构成三十二选一的逻辑图。
|
||||
\begin{figure}[H]
|
||||
\centering
|
||||
% \begin{minipage}[h]{0.5\linewidth}
|
||||
\includegraphics[width=1\linewidth]{./xournal/3.ex.pdf}
|
||||
% \end{minipage}
|
||||
\caption{思考题}
|
||||
\end{figure}
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
86
数字逻辑及实验/作业/实验报告/实验4.tex
Normal file
86
数字逻辑及实验/作业/实验报告/实验4.tex
Normal file
@ -0,0 +1,86 @@
|
||||
\documentclass[实验报告模板]{subfiles}
|
||||
|
||||
\renewcommand{\mydate}{2023/11/16}
|
||||
\renewcommand{\mychapternum}{4}
|
||||
|
||||
\renewcommand{\thefigure}{\mychapternum.\arabic{figure}}
|
||||
\renewcommand{\thetable}{\mychapternum.\arabic{table}}
|
||||
|
||||
\setlist[3]{label=\mycircle{\arabic{enumiii}} }
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{实验目的}{
|
||||
\item 掌握 74LS74 双 D 触发器的逻辑功能及测试方法。
|
||||
\item 了解 D 触发器的简单应用。
|
||||
}
|
||||
\myitem{实验内容及步骤}{
|
||||
\item 验证 74LS74 双 D 触发器的逻辑功能(只需对其中的一个 D 触发器测试功
|
||||
能)。
|
||||
\item 用 D 触发器组成一个计数器。
|
||||
}
|
||||
\myitem{实验原理}{
|
||||
% enumitem的文档中:
|
||||
% NOTE
|
||||
% New 3.6
|
||||
% If you find these parameters baffling, you are not alone. You can visualize them
|
||||
% by writing \DrawEnumitemLabel just before the first item (or in first), which draws 4 rules
|
||||
% from top to bottom, labelindent, labelwidth, labelsep, itemindent (thin if positive, thick
|
||||
% if negative); the leftmargin is marked with two vertical rules.
|
||||
% \DrawEnumitemLabel
|
||||
\item 验证 74LS74 双 D 触发器的逻辑功能(只需对其中的一个 D 触发器测试功
|
||||
能)。
|
||||
|
||||
按引脚图接好线路,在 CP 端接 1kHz 的方波,使 $S_D=R_D=1$,在 D=0、D=1、D=
|
||||
$\overline{Q_n}$ 三种情况下分别记录 Q 端(指示灯亮、暗情况)。注意时钟脉冲(CP)和输
|
||||
出脉冲的相位关系。
|
||||
|
||||
\begin{figure}[H]
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-11-15-14-15-27.png}
|
||||
\caption{74LS74 双 D 触发器的引脚图和波形图}\label{fig:4.2}
|
||||
\end{figure}
|
||||
\begin{table}[H]
|
||||
\caption{74LS74 的功能表}\label{table:4.2}
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-11-15-14-18-01.png}
|
||||
\end{table}
|
||||
\noindent
|
||||
\begin{minipage}[h]{0.5\linewidth}
|
||||
% https://blog.sciencenet.cn/blog-465809-1040538.html
|
||||
% 浮动元素无法直接放入盒子中,于是只能用H强制固定位置,因此导致前面的浮动元素也不得不用H强制固定位置
|
||||
\begin{table}[H]
|
||||
\caption{附录中的 74LS74 的功能表}
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-11-15-14-21-38.png}
|
||||
\end{table}
|
||||
\end{minipage}
|
||||
\begin{minipage}[h]{0.5\linewidth}
|
||||
\begin{figure}[H]
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-11-15-14-22-34.png}
|
||||
\caption{附录中的 74LS74 的引脚图}
|
||||
\end{figure}
|
||||
\end{minipage}
|
||||
|
||||
\item 用 D 触发器组成一个计数器。
|
||||
\begin{enumerate}
|
||||
\item 按图\ref{fig:4.3} 所示连接,时钟脉冲用10kHz,采用指示灯的亮、暗情况,观察$CP$、$Q_A$、$Q_B$、$Q_C$、$Q_D$。\label{enum:1}
|
||||
\item 把图\ref{fig:4.3} 中$CP_B$接$\overline{Q_A}$、$CP_C$接$\overline{Q_B}$,$CP_D$接$\overline{Q_C}$,用指示灯的亮、暗情况,观察$CP$、$Q_A$、$Q_B$、$Q_C$、$Q_D$。\label{enum:2}
|
||||
\end{enumerate}
|
||||
|
||||
根据指示灯的亮、暗情况,分析这两种计数器属于何种计数器。
|
||||
\begin{figure}[H]
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-11-15-14-40-04.png}
|
||||
\caption{用 D 触发器组成计数器}\label{fig:4.3}
|
||||
\end{figure}
|
||||
|
||||
在不使用清零输入的情况下,按照$Q_D$最高位,$Q_A$最低位的顺序来看,\ref{enum:1} 中的输出从1111按照二进制数的算术顺序不断减少到0000,之后重置为1111,如此往复,即十进制的从15自减到0,之后重置为15,再自减的循环;而\ref{enum:2} 中的输出从0000按照二进制数的算术顺序不断增加到1111,之后重置为0000,如此往复;即十进制的从0自增到15,之后重置为0,再自增的循环。
|
||||
|
||||
将清零输入置为1的时候,输出为0000,清零输出变回0后,继续从0000开始计数。
|
||||
|
||||
综上所述,这两种计数器, \ref{enum:1} 为减法计数器, \ref{enum:2} 为加法计数器。
|
||||
|
||||
区别: \ref{enum:1} 的计数是不断减少的, \ref{enum:2} 的计数是不断增加的;
|
||||
|
||||
联系: \ref{enum:1} 和 \ref{enum:2} 都是异步计数器,每一级的D触发器的时钟信号接了上一级的输出。
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
191
数字逻辑及实验/作业/实验报告/实验5.tex
Normal file
191
数字逻辑及实验/作业/实验报告/实验5.tex
Normal file
@ -0,0 +1,191 @@
|
||||
\documentclass[实验报告模板]{subfiles}
|
||||
|
||||
\renewcommand{\mydate}{2023/11/23}
|
||||
\renewcommand{\mychapternum}{5}
|
||||
|
||||
\renewcommand{\thefigure}{\mychapternum.\arabic{figure}}
|
||||
\renewcommand{\thetable}{\mychapternum.\arabic{table}}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{实验目的}{
|
||||
\item 掌握计数、译码和显示电路的工作原理,熟悉其电路结构。
|
||||
\item 测试计数器 74LS90 的逻辑功能。
|
||||
\item 用 74LS90、74LS248 和共阴极 LED 显示器(2ES102)组成数字计数显示单元。
|
||||
}
|
||||
\myitem{实验内容及步骤}{
|
||||
\item 把 74LS90 接成二进制计数器,用指示灯的亮、暗情况,观察并记录时钟脉冲和输出脉冲。(时钟脉冲频率用 1kHz)
|
||||
\item 把 74LS90 接成五进制计数器, 用指示灯的亮、暗情况,记录时钟脉冲及$Q_B$、$Q_C$、$Q_D$的输出脉冲。(时钟脉冲频率用 1kHz)
|
||||
\item 把 74LS90 接成 8421 码十进制计数器,用指示灯的亮、暗情况,记录时钟及$Q_A$、$Q_B$、$Q_C$、$Q_D$各点亮、暗情况。
|
||||
\item 按 图 \ref{fig:5.8} 所示,将译码器 74LS248 和显示器 2ES102 连接起来,分别输入 图 \ref{table:5.4} 所示的数据,把 74LS248 的(a、b、c、d、e、f、g)输出状况和显示结果填入 图 \ref{table:5.4} 中,验证其逻辑功能。
|
||||
\item 按实验 图 \ref{fig:5.9} 所示,把实验箱上的 Q1、Q2、Q3、Q4 和 74LS90 的 Q1、Q2、Q3、Q4联接起来,输入 1Hz 脉冲,观察显示器显示结果。若把各位的 RBI 接地,BI/RBO 接个位的 RBI,重复上述过程,观察显示结果。
|
||||
\item * 对 图 \ref{fig:5.9} 的实验做改进,使它成为 12 进制,显示规律为 1、2、3、4$\cdots\cdots$9、10、11、12、1、2、……即从 12 不是返回到 0,而是返回到 1。 % 哪种省略号更好呢?
|
||||
\begin{figure}
|
||||
\subfloat[原理图]{
|
||||
\includegraphics[width=0.7\linewidth]{imgs/2023-11-23-11-44-56.png}
|
||||
}
|
||||
\subfloat[引脚图]{
|
||||
\includegraphics[width=0.3\linewidth]{imgs/2023-11-23-11-43-05.png}
|
||||
}
|
||||
\caption{74LS90的原理图和引脚图}\label{fig:5.1}
|
||||
\end{figure}
|
||||
\begin{figure}
|
||||
\subfloat[原理图]{
|
||||
\begin{minipage}{0.6\linewidth}
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-11-23-11-48-44.png}\\
|
||||
\vspace{-1.66em}\\
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-11-23-11-46-57.png}
|
||||
\end{minipage}
|
||||
}
|
||||
\subfloat[引脚图]{
|
||||
\includegraphics[width=0.4\linewidth]{imgs/2023-11-23-11-47-20.png}
|
||||
}
|
||||
\caption{74LS248 内部原理及其引脚图}\label{fig:5.6}
|
||||
\end{figure}
|
||||
\begin{figure}
|
||||
\subfloat[valign=middle][二进制计数器]{
|
||||
\label{fig:5.2} \includegraphics[width=0.5\linewidth]{imgs/2023-11-22-19-28-59.png}
|
||||
}
|
||||
\subfloat[valign=middle][五进制计数器]{
|
||||
\label{fig:5.3} \includegraphics[width=0.5\linewidth]{imgs/2023-11-22-19-30-30.png}
|
||||
}
|
||||
|
||||
\subfloat[valign=middle][8421码十进制计数器]{
|
||||
\label{fig:5.4} \includegraphics[width=0.5\linewidth]{imgs/2023-11-22-19-30-47.png}
|
||||
}
|
||||
\subfloat[valign=middle][5421码十进制计数器]{
|
||||
\label{fig:5.5} \includegraphics[width=0.5\linewidth]{imgs/2023-11-22-19-33-17.png}
|
||||
}
|
||||
\caption{74LS90的四种不同的计数方式}
|
||||
\end{figure}
|
||||
\begin{figure}
|
||||
\centering
|
||||
\includegraphics[width=0.5\linewidth]{imgs/2023-11-22-20-02-01.png}
|
||||
\caption{数码管原理图}
|
||||
\end{figure}
|
||||
\begin{table}
|
||||
\caption{共阴数码管对应的码值表}
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-11-22-20-02-32.png}
|
||||
\end{table}
|
||||
\begin{figure}
|
||||
\begin{minipage}[b]{0.5\linewidth}
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-11-22-16-50-13.png}
|
||||
\caption{2ES102 引脚段划图}\label{fig:5.7}
|
||||
\end{minipage}
|
||||
\begin{minipage}[b]{0.5\linewidth}
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-11-22-16-53-31.png}
|
||||
\caption{译码显示成分}\label{fig:5.8}
|
||||
\end{minipage}
|
||||
\end{figure}
|
||||
\begin{figure}
|
||||
\centering
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-11-22-19-14-01.png}
|
||||
\caption{两位二-十进制计数、译码、显示}\label{fig:5.9}
|
||||
\end{figure}
|
||||
}
|
||||
\vfil
|
||||
\pagebreak[2]
|
||||
\myitem{实验原理}{
|
||||
\item 把 74LS90 接成二进制计数器,用指示灯的亮、暗情况,观察并记录时钟脉冲和输出脉冲。(时钟脉冲频率用 1kHz)
|
||||
|
||||
\begin{zhongwen}
|
||||
$\overline{CP_0}$的下降沿触发,即$CP_0$的上升沿触发。
|
||||
\end{zhongwen}
|
||||
\begin{figure}[H]
|
||||
\subfloat[valign=middle][二进制计数器]{
|
||||
\label{fig:5.2} \includegraphics[width=0.5\linewidth]{imgs/2023-11-22-19-28-59.png}
|
||||
}
|
||||
\subfloat[valign=middle][时钟脉冲和输出脉冲]{
|
||||
\label{fig:5.1.1}\includexopp[0.5]{5.1.1}
|
||||
}
|
||||
\end{figure}
|
||||
|
||||
\item 把 74LS90 接成五进制计数器, 用指示灯的亮、暗情况,记录时钟脉冲及$Q_B$、$Q_C$、$Q_D$的输出脉冲。(时钟脉冲频率用 1kHz)
|
||||
|
||||
\begin{zhongwen}
|
||||
$\overline{CP_1}$的下降沿触发,即$CP_1$的上升沿触发。
|
||||
\end{zhongwen}
|
||||
\begin{figure}[H]
|
||||
\subfloat[valign=middle][五进制计数器]{
|
||||
\label{fig:5.3} \includegraphics[width=0.5\linewidth]{imgs/2023-11-22-19-30-30.png}
|
||||
}
|
||||
\subfloat[valign=middle][时钟脉冲和输出脉冲]{
|
||||
\label{fig:5.1.2}\includexopp[0.5]{5.1.2}
|
||||
}
|
||||
\end{figure}
|
||||
|
||||
\item 把 74LS90 接成 8421 码十进制计数器,用指示灯的亮、暗情况,记录时钟及$Q_A$、$Q_B$、$Q_C$、$Q_D$各点亮、暗情况。
|
||||
|
||||
\begin{zhongwen}
|
||||
$\overline{CP_0}$的下降沿触发,即$CP_0$的上升沿触发。
|
||||
$\overline{CP_1}$的下降沿触发,即$Q_0$的下降沿触发。
|
||||
\end{zhongwen}
|
||||
\begin{figure}[H]
|
||||
\subfloat[valign=middle][8421码十进制计数器]{
|
||||
\label{fig:5.4} \includegraphics[width=0.5\linewidth]{imgs/2023-11-22-19-30-47.png}
|
||||
}
|
||||
\subfloat[valign=middle][时钟脉冲和输出脉冲]{
|
||||
\label{fig:5.1.2}\includexopp[0.5]{5.1.3}
|
||||
}
|
||||
\end{figure}
|
||||
|
||||
\item 按 图 \ref{fig:5.8} 所示,将译码器 74LS248 和显示器 2ES102 连接起来,分别输入 图 \ref{table:5.4} 所示的数据,把 74LS248 的(a、b、c、d、e、f、g)输出状况和显示结果填入 图 \ref{table:5.4} 中,验证其逻辑功能。
|
||||
|
||||
\begin{table}[H]
|
||||
\centering
|
||||
\tabcolsep=1em
|
||||
\caption{74LS248 译码}\label{table:5.4}
|
||||
(可以看到$Q_D$应该是高位,$Q_A$应该是低位。)
|
||||
\begin{tabular}{cccccc}
|
||||
\toprule
|
||||
LT & RBI & RBO & $Q_A\quad Q_B\quad Q_C\quad Q_D$ & a b c d e f g & 显示字符 \\
|
||||
\midrule
|
||||
H & Φ & H & 0 0 0 0 & 1111110 & 0 \\
|
||||
H & Φ & H & 0 1 0 0 & 1101101 & 2 \\
|
||||
H & Φ & H & 0 1 0 1 & 0000000 & 空\\
|
||||
H & Φ & H & 1 0 0 0 & 0110000 & 1 \\
|
||||
H & Φ & H & 0 0 1 0 & 0110011 & 4 \\
|
||||
H & Φ & H & 1 0 0 1 & 1111011 & 9 \\
|
||||
Φ & Φ & L & Φ Φ Φ Φ & 0000000 & 空 \\
|
||||
H & L & Φ & 0 0 0 0 & 0000000 & 空 \\
|
||||
L & Φ & H & Φ Φ Φ Φ & 1111111 & 8 \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{table}
|
||||
|
||||
\item 按实验 图 \ref{fig:5.9} 所示,把实验箱上的 Q1、Q2、Q3、Q4 和 74LS90 的 Q1、Q2、Q3、Q4联接起来,输入 1Hz 脉冲,观察显示器显示结果。
|
||||
\begin{figure}[H]
|
||||
\centering
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-11-22-19-14-01.png}
|
||||
\caption{两位二-十进制计数、译码、显示}\label{fig:5.9}
|
||||
\end{figure}
|
||||
|
||||
\begin{zhongwen}
|
||||
此时显示器在时钟信号的驱动下,每次时钟信号上升沿时变化一次,从$00、01$、$02$、$\cdots\cdots$一直增加到$99$,之后再变回$00$,如此循环。
|
||||
\end{zhongwen}
|
||||
|
||||
若把个位的 RBI 接地,十位的 BI/RBO 接个位的 RBI,重复上述过程,观察显示结果。
|
||||
|
||||
\begin{zhongwen}
|
||||
此时当十位为0时,显示器将只显示个位,即从$0$、$1$、$2$、$\cdots\cdots$一直增加到$99$,之后再变回$0$,如此循环。
|
||||
\end{zhongwen}
|
||||
|
||||
\item * 对 图 \ref{fig:5.9} 的实验做改进,使它成为 12 进制,显示规律为 1、2、3、4 $\cdots\cdots$ 9、10、11、12、1、2、……即从 12 不是返回到 0,而是返回到 1。 % 哪种省略号更好呢?
|
||||
|
||||
\begin{zhongwen}
|
||||
12在此电路中的表示为10010,即十位的$Q_A$为1,个位的$Q_B$为1,其余的$Q$均为0,此时要让它返回到1,即个位的$Q_A$为1,其余的$Q$均为0。那么由于个位的$CP_1$的时钟信号驱动,个位的$Q_A$本来就会在时钟信号上升沿时变为1,因此考虑在$Q$输出10010时将十位的$Q_A$和个位的$Q_B$在下一时刻变为0,其中十位的$Q_A$容易变0,直接将清零端输入1即可,但个位不容易只让$Q_B$清零而$Q_A$正常变1,因此尝试换个思路,改变个位的输出,让它在个位为0010时阻塞$Q_B$的输出,而且也要阻塞$Q_A$向$CP_2$的信号,否则会导致$CP_2$驱动的$Q_B$发生进位。
|
||||
\end{zhongwen}
|
||||
|
||||
\begin{figure}[H]
|
||||
\centering
|
||||
\includexopp[0.9]{5.1.6}
|
||||
\caption{十二进制计数}
|
||||
\end{figure}
|
||||
|
||||
\begin{zhongwen}
|
||||
图中将十位的$Q_A$和个位的$Q_B$通过与门,用来检测计数是否到达12(当未到达12时十位的$Q_A$和个位的$Q_B$不会同时输出为1,而且也不会计数超过12),到达12后使用一个D触发器将它的状态记录下来,在下一时刻阻塞个位的$Q_B$的输出信号以及$Q_A$向$CP_2$的信号,此时$Q_A$未受到影响,从0变为1,而$Q_B$的输出被阻塞,于是晶体管输出01。此时未到达12,于是再后面一时刻,D触发器复位,不再阻塞,但此时$Q_A$也变为0了,于是$CP_2$仍然不会产生下降沿,于是$Q_B$仍然保持1(这里考虑到了竞争和冒险问题,$CP_1$驱动的D触发器输出,以及$CP_1$驱动的$Q_A$,根据原理图能看到都是只经过了一个触发器,因此可以认为延时相近,不会产生竞争和冒险的情况),此时晶体管输出为02,那么之后的时刻时钟信号可以正常驱动计数器继续计数了。
|
||||
\end{zhongwen}
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
59
数字逻辑及实验/作业/实验报告/实验6.tex
Normal file
59
数字逻辑及实验/作业/实验报告/实验6.tex
Normal file
@ -0,0 +1,59 @@
|
||||
\documentclass[实验报告模板]{subfiles}
|
||||
|
||||
\renewcommand{\mydate}{2023/12/7}
|
||||
\renewcommand{\mychapternum}{6}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{实验目的}{
|
||||
\item 掌握 Mealy 型时序电路设计方法。
|
||||
\item 验证所设计电路的逻辑功能。
|
||||
\item 体会状态分配对电路复杂性的影响。
|
||||
}
|
||||
\myitem{实验内容及步骤}{
|
||||
\item 设计一同步序列检测器,当输入序号为 1001 时,输出一个“1”即
|
||||
输入 X 序列为 0100110011……
|
||||
输出 Y 序列为 0000100010……
|
||||
选用 D 触发器,做这个实验。
|
||||
}
|
||||
\myitem{实验原理}{
|
||||
\item
|
||||
|
||||
\begin{zhongwen}
|
||||
若采用米利模型,则需要4个状态,分别为:$S_0$无输入、$S_1$输入1、$S_2$输入10、$S_3$输入100这几个状态。则可以画出状态转换图如下:
|
||||
\begin{figure}[H]
|
||||
\includexopp[1.8]{6.1.1}
|
||||
\caption{状态转换图(米利模型)}
|
||||
\end{figure}
|
||||
|
||||
好像也不用画状态转换图,下面我们来证明检测长度为$n$的序列的同步序列检测器至少有$n$个状态。
|
||||
\begin{proof}
|
||||
|
||||
这里用米利模型举例,摩尔模型一般状态比米利模型多(猜测可能是至少$n+1$个状态,待证)。
|
||||
|
||||
$\forall i = 0, 1, \ldots , n-1$,设$S_i$表示已经正确检测了序列的前$i$个位的状态(可能存在等价状态),那么只有$S_{n-1}$在下一次转换时可能输出$1$(第$n$位也正确时),其余状态在下一次转换时均只能输出$0$,也就是说$S_{n-1}$与其他状态均不等价。
|
||||
|
||||
对于$\forall S_j,S_k \in \{ S_i \ |\ i = 0,1, \ldots ,n-1\}$ $(j<k)$ ,若$S_j$和$S_k$等价,那么经过相同的输入后这两个状态应转换到相同的状态或等价的状态。那么对于$S_j$和$S_k$,将序列的后$n-k-1$位作为输入,此时$S_k$应转换到$S_{n-1}$,而$S_j$转换到$S_{j+n-1-k}$。因为$j+n-1-k<n-1$,所以$S_{j+n-1-k}$与$S_{n-1}$必定不等价,则$S_j$与$S_k$也必定不等价,产生矛盾。
|
||||
|
||||
所以$\{ S_i\ |\ i=0,1, \ldots ,n-1 \}$中的状态均不等价,于是此同步序列检测器至少有$n$个状态。
|
||||
|
||||
\end{proof}
|
||||
|
||||
因此检测1001序列最少需要4个状态,而状态编码也不需要仔细调整,因为只有一个状态可能会在转换到次态时输出1,同时状态的转换可以直接使用移位寄存器,所以可以直接画出逻辑电路图如下:
|
||||
|
||||
图中$X$代表输入,$CP$代表时钟信号,$Y$代表输出。
|
||||
\begin{figure}[H]
|
||||
\includexopp[1.5]{6.1.2}
|
||||
\caption{米利模型}
|
||||
\end{figure}
|
||||
\begin{figure}[H]
|
||||
\includexopp[1.5]{6.1.3}
|
||||
\caption{摩尔模型}
|
||||
\end{figure}
|
||||
|
||||
这样的逻辑电路会在输入$1001001$时输出两次1,题目中也未说明这样的情况,就认为这样是对的吧。
|
||||
\end{zhongwen}
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
78
数字逻辑及实验/作业/实验报告/实验7.tex
Normal file
78
数字逻辑及实验/作业/实验报告/实验7.tex
Normal file
@ -0,0 +1,78 @@
|
||||
\documentclass[实验报告模板]{subfiles}
|
||||
|
||||
\renewcommand{\mydate}{2023/12/14}
|
||||
\renewcommand{\mychapternum}{7}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{实验目的}{
|
||||
\item 掌握任意进制分频器的设计方法。
|
||||
\item 掌握同步计数器 74LS161 多级级联的方法。
|
||||
\item 研究不同连接方式对分频数的影响。
|
||||
}
|
||||
\myitem{实验内容及步骤}{
|
||||
\item 利用 74LS161 的清零端($C_r$)设计一个 12 分频器,当时钟频率为 1Hz 时,用发光二极管显示 74LS161 $Q_{A}\sim Q_{D}$ 的输出状态,并填入表 \ref{7.6} 中。
|
||||
\item 利用 74LS161 的置数端($L_{D}$)设计一个 12 分频器。当时钟频率为 1Hz 时,用发光二极管显示 74LS161 $Q_{A}\sim Q_{D}$ 的输出状态,并填入表 \ref{7.6} 中。当时钟频率为 10kHz时,观察 $O_{C}$ 与 CP 的指示灯亮、暗情况。
|
||||
\item 用两片 74LS161 和 74LS04 设计 33 分频器,输入时钟频率为 10kHz 时,观察 CP脉冲、$O_{C_1}$ 和 $O_{C_2}$ 的指示灯亮、暗情况。
|
||||
\item 当分频器为 22 分频器时,把\#2 74LS161 的 P 和 T 对调,观察并记录 CP 脉冲、$O_{C_1}$ 和 $O_{C_2}$ 的指示灯亮、暗情况。
|
||||
}
|
||||
\begin{table}[h]
|
||||
\centering
|
||||
\tabcolsep=1em
|
||||
\caption{}\label{7.6}
|
||||
\begin{tabular}{c|ccccc|ccccc}
|
||||
\toprule
|
||||
\multirow{2}{*}{时钟} & \multicolumn{5}{c}{利用$Cr$端} \vline& \multicolumn{5}{c}{利用$L_{D}$端} \\
|
||||
& $Q_{D}$ & $Q_{C}$& $Q_{B}$ & $Q_{A}$ & $O_{C}$ & $Q_{D}$ & $Q_{C}$& $Q_{B}$ & $Q_{A}$ & $O_{C}$ \\
|
||||
\midrule
|
||||
0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0\\
|
||||
1 & 0 & 0 & 0 & 1 & 0 & 0 & 1 & 0 & 1 & 0\\
|
||||
2 & 0 & 0 & 1 & 0 & 0 & 0 & 1 & 1 & 0 & 0\\
|
||||
3 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 1 & 0\\
|
||||
4 & 0 & 1 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0\\
|
||||
5 & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 0 & 1 & 0\\
|
||||
6 & 0 & 1 & 1 & 0 & 0 & 1 & 0 & 1 & 0 & 0\\
|
||||
7 & 0 & 1 & 1 & 1 & 0 & 1 & 0 & 1 & 1 & 0\\
|
||||
8 & 1 & 0 & 0 & 0 & 1 & 1 & 1 & 0 & 0 & 0\\
|
||||
9 & 1 & 0 & 0 & 1 & 1 & 1 & 1 & 0 & 1 & 0\\
|
||||
10 & 1 & 0 & 1 & 0 & 1 & 1 & 1 & 1 & 0 & 0\\
|
||||
11 & 1 & 0 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1\\
|
||||
12 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0\\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{table}
|
||||
\myitem{实验原理}{
|
||||
\item 利用 74LS161 的清零端($C_r$)设计一个 12 分频器,当时钟频率为 1Hz 时,用发光二极管显示 74LS161 $Q_{A}\sim Q_{D}$ 的输出状态,并填入表 \ref{7.6} 中。
|
||||
|
||||
\includexopp[1.5]{7.1.1}
|
||||
|
||||
\item 利用 74LS161 的置数端($L_{D}$)设计一个 12 分频器。当时钟频率为 1Hz 时,用发光二极管显示 74LS161 $Q_{A}\sim Q_{D}$ 的输出状态,并填入表 \ref{7.6} 中。当时钟频率为 10kHz时,观察 $O_{C}$ 与 CP 的指示灯亮、暗情况。
|
||||
|
||||
\begin{zhongwen}
|
||||
因为通过置数端设计分频器时,假设在置数端固定输入$x$,则$n$位计数器的计数范围是$[x ,2^{n}-1]$,这其中共有$(2^{n}-1)-x+1 = 2^{n}-x$个数。令$2^{n}-x=y$,则$x=2^{n}-y$,也就是想要得到$y$分频器,只需要在置数端固定输入$2^{n}-y$。
|
||||
|
||||
当然这样对于回答题目来说已经足够了,但需要将二进制转化成十进制,做减法,再转回二进制,那么是否有更简便的方法呢?接下来就要回顾二进制的补码表示的相关概念。我们知道对于一个正整数$a$,有$a+(-a)=0$,为了使二进制数也有这样的规律,我们引入了负数的补码表示,使用补码表示后,只需要对$a$和$-a$进行正常的二进制加法,结果就是0。注意,由于问题限定在$n$位二进制数中,因此考虑到溢出的情况,应该是$\left( a+(-a) \right) \operatorname{mod} 2^{n}=0$,所以由于$x+y=2^{n}$,所以$(x+y)\operatorname{mod} 2^{n}=0$,所以若$x=a$,则$y=-a$,即$x$和$y$互为相反数(在补码表示的意义下),所以想要得到$y$分频器,只需要计算$-y$的$n$位二进制补码表示,即是置数端的固定输入。
|
||||
|
||||
12转换成二进制是 1100 , 取 $-12$ 的补码,为 0100,即正数的$16-12 = 4$。
|
||||
\end{zhongwen}
|
||||
|
||||
\includexopp[1.5]{7.2.1}
|
||||
|
||||
\item 用两片 74LS161 和 74LS04 设计 33 分频器,输入时钟频率为 10kHz 时,观察 CP脉冲、$O_{C_1}$ 和 $O_{C_2}$ 的指示灯亮、暗情况。
|
||||
|
||||
\begin{zhongwen}
|
||||
33转换成二进制是 0010 0001 ,取 $-33$ 的补码,为 1101 1111 ,即正数的 $256-33 = 223$。
|
||||
\end{zhongwen}
|
||||
|
||||
\includexopp[1.5]{7.3.1}
|
||||
|
||||
\item 当分频器为 22 分频器时,把\#2 74LS161 的 P 和 T 对调,观察并记录 CP 脉冲、$O_{C_1}$ 和 $O_{C_2}$ 的指示灯亮、暗情况。
|
||||
|
||||
\begin{zhongwen}
|
||||
应该是会从22分频变成$22-15=7$分频,因为 \#2 74LS161的计数状态为1111时就会传递清零信号,此时 \#1 74LS161 的计数状态应该是0000,而对调前是要在 \#1 也是1111时才会传递清零信号的,所以这相当于跳过了15个状态提前清零了。
|
||||
|
||||
\end{zhongwen}
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
87
数字逻辑及实验/作业/实验报告/实验报告模板.tex
Normal file
87
数字逻辑及实验/作业/实验报告/实验报告模板.tex
Normal file
@ -0,0 +1,87 @@
|
||||
\documentclass[a4paper]{ctexart}
|
||||
\input{mypreamble}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\title{\fontsize{15}{0}华东师范大学计算机科学与技术学院上机实践报告\vspace{-2em}}
|
||||
\date{}
|
||||
\maketitle
|
||||
|
||||
\begin{longtable}[]{lll}
|
||||
\toprule\noalign{}
|
||||
\endhead
|
||||
\bottomrule\noalign{}
|
||||
\endlastfoot
|
||||
\textbf{课程名称}:数据结构 & \textbf{年级}:2022级 &
|
||||
\textbf{上机实践成绩}: \\
|
||||
\textbf{指导教师}:金健 & \textbf{姓名}:金小健 &
|
||||
\textbf{上机实践时间}:2学时 \\
|
||||
\textbf{上机实践名称}:第一章作业 & \textbf{学号}:xxxxxxxxxx &
|
||||
\textbf{上机实践日期}:2023/09/23 \\
|
||||
\end{longtable}
|
||||
|
||||
\begin{enumerate}
|
||||
\item \textbf{实验目的}
|
||||
|
||||
\begin{enumerate}
|
||||
\item
|
||||
从第1条起填写基本目的。
|
||||
\end{enumerate}
|
||||
\item \textbf{实验内容}
|
||||
|
||||
\begin{enumerate}
|
||||
\item
|
||||
结合实验目的填写。
|
||||
\item
|
||||
在预习时,对程序或过程中出现的问题,都写在这里,以便真正上机实践时有针对性的查找答案,并填充相应的实验步骤、过程、结果和分析,以及总结。
|
||||
\end{enumerate}
|
||||
\item \textbf{实验原理}
|
||||
|
||||
\begin{enumerate}
|
||||
\item
|
||||
参考实验教材
|
||||
\end{enumerate}
|
||||
\item \textbf{实验步骤}
|
||||
|
||||
\begin{enumerate}
|
||||
\item
|
||||
参考实验教材
|
||||
\end{enumerate}
|
||||
\item \textbf{调试}\textbf{过程、结果和分析}
|
||||
|
||||
\begin{enumerate}
|
||||
\item
|
||||
参考教材,结合自己实际,对调试过程进行记录和分析。
|
||||
\end{enumerate}
|
||||
\item \textbf{总结}
|
||||
|
||||
\begin{enumerate}
|
||||
\item
|
||||
预习时提出的问题有没有解决,实验目的有没有达到
|
||||
\item
|
||||
如果实现了,作一下评价
|
||||
\item
|
||||
如果未实现,总结一下原因(并不一定每次都必定要完全实现预定目标的,只要原因分析得恰当,同样是好的)
|
||||
\item
|
||||
有没有新的疑问或想法
|
||||
\end{enumerate}
|
||||
\item \textbf{附件}
|
||||
|
||||
\begin{enumerate}
|
||||
\item
|
||||
程序代码。
|
||||
\end{enumerate}
|
||||
\end{enumerate}
|
||||
|
||||
|
||||
\noindent \textbf{说明:}
|
||||
|
||||
文件命名格式:学号+第一章作业.doc
|
||||
|
||||
\noindent 例如:
|
||||
|
||||
52051201004第一章作业.doc
|
||||
|
||||
52051201004第二章作业.doc
|
||||
|
||||
\end{document}
|
274
数字逻辑及实验/作业/第一章作业-订正.tex
Normal file
274
数字逻辑及实验/作业/第一章作业-订正.tex
Normal file
@ -0,0 +1,274 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
|
||||
\fancyhead{}
|
||||
\fancyhead[C]{\mysignature}
|
||||
\begin{document}
|
||||
\renewcommand{\bar}{\xoverline} % 这一行在编译时可以取消注释,注意一定要放在\begin{document}下面才有用
|
||||
\chapter{逻辑代数基础}
|
||||
% 思考题和习题 1、2、4、5、6、8、9
|
||||
\begin{enumerate}
|
||||
|
||||
\item 运用基本定理证明下列等式。
|
||||
\begin{enumerate}
|
||||
\item $AB+\bar{A}C+\bar{B}C = AB+C $
|
||||
\begin{proof}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\\
|
||||
&\begin{aligned}
|
||||
AB+\bar{A}C+\bar{B}C & = AB+(\bar{A}+\bar{B})C \\
|
||||
& = AB+\overline{AB}C \\
|
||||
& = AB+C \\
|
||||
\end{aligned}
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{proof}
|
||||
\item $BC+D+\bar{D}(\bar{B}+\bar{C})(DA+B)=B+D$
|
||||
\begin{proof}
|
||||
$$
|
||||
\begin{aligned}
|
||||
BC+D+\bar{D}(\bar{B}+\bar{C})(DA+B) & = BC+D+(\bar{B}+\bar{C})(DA+B) \\
|
||||
& = BC+D+\overline{BC}(DA+B) \\
|
||||
& = BC+D+DA+B \\
|
||||
& = B+D \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{proof}
|
||||
\item $ABC+\bar{A}\bar{B}\bar{C}=\overline{A\bar{B}+B\bar{C}+C\bar{A}}$
|
||||
\begin{proof}
|
||||
$$
|
||||
\begin{aligned}
|
||||
ABC+\bar{A}\bar{B}\bar{C} & = (A+\bar{A})(A+\bar{B})(A+\bar{C})(B+\bar{A})(B+\bar{B})(B+\bar{C})(C+\bar{A})(C+\bar{B})(C+\bar{C}) \\
|
||||
& = (A+\bar{B})(A+\bar{C})(B+\bar{A})(B+\bar{C})(C+\bar{A})(C+\bar{B}) \\
|
||||
& = \overline{A\bar{B}+A\bar{C}+B\bar{A}+B\bar{C}+C\bar{A}+C\bar{B}} \\
|
||||
& \xlongequal{\textit{冗余律}} \overline{A\bar{B}+B\bar{C}+C\bar{A}} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{proof}
|
||||
\item $AB+BC+CA=(A+B)(B+C)(C+A)$
|
||||
\begin{proof}
|
||||
$$
|
||||
\begin{aligned}
|
||||
(A+B)(B+C)(C+A) & = ABC+ABA+ACC+ACA+BBC+BBA+BCC+BCA \\
|
||||
& = ABC+AB+AC+AC+BC+BA+BC+ABC \\
|
||||
& = ABC+AB+AC+BC \\
|
||||
& = AB+BC+CA \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{proof}
|
||||
\item $\bar{A}BC+AB+A\bar{C}=BC+A\bar{C}$
|
||||
\begin{proof}
|
||||
$$
|
||||
\begin{aligned}
|
||||
\bar{A}BC+AB+A\bar{C} & = B(\bar{A}C+A)+A\bar{C} \\
|
||||
& = B(C+A)+A\bar{C} \\
|
||||
& = BC+AB+A\bar{C} \\
|
||||
& = BC+A\bar{C} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{proof}
|
||||
\item $\overline{A\bar{B}+\bar{A}B}=(A+\bar{B})(\bar{A}+B)$
|
||||
\begin{proof}
|
||||
$$
|
||||
\begin{aligned}
|
||||
\overline{A\bar{B}+\bar{A}B} & = \overline{A\bar{B}}\ \overline{\bar{A}B} \\
|
||||
& = (\bar{A}+B)(A+\bar{B}) \\
|
||||
& = (A+\bar{B})(\bar{A}+B) \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{proof}
|
||||
\item $\bar{A}\bar{B}+AB+BC=\bar{A}\bar{B}+AB+\bar{A}C$
|
||||
\begin{proof}
|
||||
$$
|
||||
\begin{aligned}
|
||||
\bar{A}\bar{B}+AB+BC & = \bar{A}\bar{B}+AB+BC(A+\bar{A}) \\
|
||||
& = \bar{A}\bar{B}+AB+BCA+BC\bar{A} \\
|
||||
& = \bar{A}\bar{B}+AB+\bar{A}BC \\
|
||||
& = \bar{A}(\bar{B}+BC)+AB \\
|
||||
& = \bar{A}(\bar{B}+C)+AB \\
|
||||
& = \bar{A}\bar{B}+AB+\bar{A}C \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{proof}
|
||||
\end{enumerate}
|
||||
|
||||
\item 用逻辑代数定理化简下列逻辑函数式。
|
||||
\begin{enumerate}
|
||||
\item $AB+\bar{A}B\bar{C}+BC$
|
||||
$$
|
||||
\begin{aligned}
|
||||
AB+\bar{A}B\bar{C}+BC & = B(A+\bar{A}\bar{C}+C) \\
|
||||
& = B(A+\bar{C}+C) \\
|
||||
& = B \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\item $\bar{A}\bar{B}\bar{C}+A\bar{B}\bar{C}+A\bar{B}C$
|
||||
$$
|
||||
\begin{aligned}
|
||||
\bar{A}\bar{B}\bar{C}+A\bar{B}\bar{C}+A\bar{B}C & = \bar{B}(\bar{A}\bar{C}+A\bar{C}+AC) \\
|
||||
& = \bar{B}(\bar{C}+AC) \\
|
||||
& = \bar{B}(\bar{C}+A) \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\item $ab(cd+\bar{c}d)$
|
||||
$$
|
||||
ab(cd+\bar{c}d)=abd
|
||||
$$
|
||||
\item $[x \overline{(xy)}][y \overline{(xy)}]$
|
||||
$$
|
||||
\begin{aligned}
|
||||
\relax[x \overline{(xy)}][y \overline{(xy)}] & = xy\overline{(xy)}\ \overline{(xy)} \\
|
||||
& = xy\overline{(xy)} \\
|
||||
& = 0 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\item $\overline{(a+b)}\ \overline{(\bar{a}+\bar{b})}$
|
||||
$$
|
||||
\begin{aligned}
|
||||
\overline{(a+b)}\ \overline{(\bar{a}+\bar{b})} & = \bar{a}\bar{b}ab \\
|
||||
& = 0 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\item $\bar{a} \bar{b} \bar{c}+\bar{a} \bar{b}c+a \bar{b}\bar{c}+abc$
|
||||
$$
|
||||
\begin{aligned}
|
||||
\bar{a} \bar{b}\bar{c}+\bar{a} \bar{b}c+a \bar{b}\bar{c}+abc & = \bar{a} \bar{b}+a\bar{b}\bar{c}+abc \\
|
||||
& = \bar{b}(\bar{a}+a\bar{c})+abc \\
|
||||
& = \bar{b}(\bar{a}+\bar{c})+abc \\
|
||||
& = \bar{b}\overline{ac}+bac \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{enumerate}
|
||||
\item[4.] 用卡诺图化简下列最小项表达式.\\
|
||||
$G=f(a,b,c)=\sum m(1,3,5,6,7)$\\
|
||||
\includesvg{1.4.G}\\
|
||||
$$
|
||||
G=f(a,b,c)=ab+c
|
||||
$$
|
||||
$H=f(w,x,y,z)=\sum m(0,2,8,10)$\\
|
||||
\includesvg{1.4.H}\\
|
||||
$$
|
||||
H=f(w,x,y,z)=\bar{x}\bar{z}
|
||||
$$
|
||||
|
||||
\newpage
|
||||
$I=f(w,x,y,z)=\sum m(1,3,4,6,9,12,14,15)$\\
|
||||
\includesvg{1.4.I}\\
|
||||
$$
|
||||
I=f(w,x,y,z)=x\oplus z\oplus (wyz)
|
||||
$$
|
||||
|
||||
\vspace{10em}
|
||||
$J=f(a,b,c)=\sum m(0,1,2,3,4,5,7)$\\
|
||||
\includesvg{1.4.J}\\
|
||||
$$
|
||||
J=f(a,b,c)=\sum M(6)=\bar{a}+\bar{b}+c
|
||||
$$
|
||||
|
||||
\newpage
|
||||
$K=f(a,b,c,d)=\sum m(3,4,5,7,9,13,14,15)$\\
|
||||
\includesvg{1.4.K}\\
|
||||
$$
|
||||
K=f(a,b,c,d)=bd+\bar{a}b \bar{c}+\bar{a}cd+abc+\bar{ac}d
|
||||
$$
|
||||
|
||||
\vspace{10em}
|
||||
$L=f(a,b,c,d)=\sum m(0,1,2,5,6,7,8,9,13,14)$\\
|
||||
\includesvg{1.4.L}\\
|
||||
$$
|
||||
L=f(a,b,c,d)=\bar{b}\bar{c}+\bar{c}d+\bar{a}bc+\bar{a}c \bar{d}+bc \bar{d}
|
||||
$$
|
||||
|
||||
\newpage
|
||||
\item[5.] 用卡诺图化简下列最大项表达式。\\
|
||||
$H=f(a,b,c,d)=\prod M(2, 3, 4, 6, 7, 10, 11, 12) $\\
|
||||
\includesvg{1.5.H}\\
|
||||
$$
|
||||
H=f(a,b,c,d)=(a+\bar{c})(\bar{b}+c+d)(b+\bar{c})
|
||||
$$
|
||||
|
||||
\vspace{10em}
|
||||
$F=f(u,v,w,x,y)=\prod M(0, 2, 8, 10, 16, 18, 24, 26)$\\
|
||||
\includesvg{1.5.F}\\
|
||||
$$
|
||||
F=f(u,v,w,x,y)=w+y
|
||||
$$
|
||||
|
||||
\newpage
|
||||
\item[6.] 化简下列带任意项的逻辑函数。\\
|
||||
$V=f(a,b,c,d)=\sum m(2,3,4,5,13, 15)+\sum d(8,9,10, 11)$\\
|
||||
\includesvg{1.6.V}\\
|
||||
$$
|
||||
V=f(a,b,c,d)=ad+\bar{b}c+\bar{a}b \bar{c}
|
||||
$$
|
||||
|
||||
\vspace{10em}
|
||||
$Y=f(u,v,w,x)=\sum m(1, 5, 7, 9, 13, 15)+\sum d(8, 10, 11, 14)$\\
|
||||
\includesvg{1.6.Y}\\
|
||||
$$
|
||||
Y=f(u,v,w,x)=x \overline{\bar{u}\bar{v}w}=x(u+v+\bar{w})
|
||||
$$
|
||||
|
||||
\newpage
|
||||
$P=f(r,s,t,u)=\sum m(0, 2, 4, 8, 10, 14)+\sum d(5,6,7,12)$\\
|
||||
\includesvg{1.6.P}\\
|
||||
$$
|
||||
P=f(r,s,t,u)=\bar{u}
|
||||
$$
|
||||
|
||||
\vspace{10em}
|
||||
$H=f(a,b,c,d,e)=\sum m(5,7,9,12,13,14,17,19,20,22,25,27,28,30)+\sum d(8,10,24,26)$\\
|
||||
\includesvg{1.6.H}\\
|
||||
$$
|
||||
H=f(a,b,c,d,e) = a \bar{c}e + ac \bar{e}+\bar{a}\bar{b}ce+bcd \bar{e}+b \bar{c}\bar{d}+\bar{a}bc \bar{d}
|
||||
$$
|
||||
|
||||
\newpage
|
||||
$I=f(d,e,f,g,h)=\prod M(5,7,8,21,23,26,30)\cdot \prod D(10,14,24,28)$\\
|
||||
\includesvg{1.6.I}\\
|
||||
$$
|
||||
I=f(d,e,f,g,h)=(e+\bar{f}+\bar{h})(\bar{e}+\bar{g}+h)(d+\bar{e}+f+h)
|
||||
$$
|
||||
|
||||
\vspace{10em}
|
||||
\item[8.] 将下列逻辑函数化简成与非形式最简式。\\
|
||||
$U=f(a,b,c,d)=\sum m(3,4,6,11,12,14)$\\
|
||||
\includesvg{1.8.U}\\
|
||||
$$
|
||||
U=f(a,b,c,d)=b \bar{d}+\bar{b}cd = \overline{\overline{b \bar{d}}\ \overline{\bar{b}cd}}
|
||||
$$
|
||||
|
||||
\newpage
|
||||
$V=f(a,b,c,d)=\sum m (0,1,2,5,8,10,13)$\\
|
||||
\includesvg{1.8.V}\\
|
||||
$$
|
||||
\begin{aligned}
|
||||
&V=f(a,b,c,d)=(\overline{a \oplus b \oplus d}+\bar{a}\bar{b})\overline{cd}=\overline{a\oplus b\oplus d \overline{\bar{a}\bar{b}}}\overline{cd}=\overline{(\bar{a}b+a \bar{b}) \oplus d}\ \overline{cd} \\
|
||||
&=\overline{\overline{(\bar{a}b +a \bar{b})}d}\ \overline{(\bar{a}b+a \bar{b})\bar{d}}\ \overline{cd}=\overline{\overline{\bar{a}b} \overline{a \bar{b}} d} \ \overline{\overline{\overline{\bar{a}b} \overline{a \bar{b}}}\bar{d}}\ \overline{cd}\\
|
||||
\end{aligned}
|
||||
$$
|
||||
|
||||
\vspace{10em}
|
||||
$W=f(a,b,c,d) = \sum m(3,5,7,10,11)$\\
|
||||
\includesvg{1.8.W}\\
|
||||
$$
|
||||
W=f(a,b,c,d)=\bar{a}cd+\bar{a}bd+a \bar{b}\bar{c}d+a \bar{b}c \bar{d} = \overline{\overline{\bar{a}cd}\ \overline{\bar{a}bd}\ \overline{a \bar{b}\bar{c}d}\ \overline{a \bar{b}c \bar{d}}}
|
||||
$$
|
||||
|
||||
\newpage
|
||||
\item[9.] 将下列逻辑函数化简成或非形式最简式。\\
|
||||
$G=f(a,b,c,d)=\prod M(0,1,2,5,8,10,13) $\\
|
||||
\includesvg{1.9.G}\\
|
||||
$$
|
||||
G=f(a,b,c,d)=(b+d)(c+\bar{d}+a \bar{b}\bar{c})=\overline{\overline{b+d}\ \overline{c+\bar{d}+\overline{\bar{a}+b+c}}}
|
||||
$$
|
||||
|
||||
\vspace{10em}
|
||||
$H=f(a,b,c,d)=\prod M(3,5,7,9,11)$\\
|
||||
\includesvg{1.9.H}\\
|
||||
$$
|
||||
H=f(a,b,c,d) = \bar{d}+\bar{a} \bar{b}\bar{c}+ab=\bar{d}+\overline{a+b+c}+\overline{\bar{a}+\bar{b}}
|
||||
$$
|
||||
\end{enumerate}
|
||||
|
||||
\end{document}
|
274
数字逻辑及实验/作业/第一章作业.tex
Normal file
274
数字逻辑及实验/作业/第一章作业.tex
Normal file
@ -0,0 +1,274 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
|
||||
\fancyhead{}
|
||||
\fancyhead[C]{\mysignature}
|
||||
\begin{document}
|
||||
\renewcommand{\bar}{\xoverline} % 这一行在编译时可以取消注释,注意一定要放在\begin{document}下面才有用
|
||||
\chapter{逻辑代数基础}
|
||||
% 思考题和习题 1、2、4、5、6、8、9
|
||||
\begin{enumerate}
|
||||
|
||||
\item 运用基本定理证明下列等式。
|
||||
\begin{enumerate}
|
||||
\item $AB+\bar{A}C+\bar{B}C = AB+C $
|
||||
\begin{proof}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\\
|
||||
&\begin{aligned}
|
||||
AB+\bar{A}C+\bar{B}C & = AB+(\bar{A}+\bar{B})C \\
|
||||
& = AB+\overline{AB}C \\
|
||||
& = AB+C \\
|
||||
\end{aligned}
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{proof}
|
||||
\item $BC+D+\bar{D}(\bar{B}+\bar{C})(DA+B)=B+D$
|
||||
\begin{proof}
|
||||
$$
|
||||
\begin{aligned}
|
||||
BC+D+\bar{D}(\bar{B}+\bar{C})(DA+B) & = BC+D+(\bar{B}+\bar{C})(DA+B) \\
|
||||
& = BC+D+\overline{BC}(DA+B) \\
|
||||
& = BC+D+DA+B \\
|
||||
& = B+D \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{proof}
|
||||
\item $ABC+\bar{A}\bar{B}\bar{C}=\overline{A\bar{B}+B\bar{C}+C\bar{A}}$
|
||||
\begin{proof}
|
||||
$$
|
||||
\begin{aligned}
|
||||
ABC+\bar{A}\bar{B}\bar{C} & = (A+\bar{A})(A+\bar{B})(A+\bar{C})(B+\bar{A})(B+\bar{B})(B+\bar{C})(C+\bar{A})(C+\bar{B})(C+\bar{C}) \\
|
||||
& = (A+\bar{B})(A+\bar{C})(B+\bar{A})(B+\bar{C})(C+\bar{A})(C+\bar{B}) \\
|
||||
& = \overline{A\bar{B}+A\bar{C}+B\bar{A}+B\bar{C}+C\bar{A}+C\bar{B}} \\
|
||||
& \xlongequal{\textit{冗余律}} \overline{A\bar{B}+B\bar{C}+C\bar{A}} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{proof}
|
||||
\item $AB+BC+CA=(A+B)(B+C)(C+A)$
|
||||
\begin{proof}
|
||||
$$
|
||||
\begin{aligned}
|
||||
(A+B)(B+C)(C+A) & = ABC+ABA+ACC+ACA+BBC+BBA+BCC+BCA \\
|
||||
& = ABC+AB+AC+AC+BC+BA+BC+ABC \\
|
||||
& = ABC+AB+AC+BC \\
|
||||
& = AB+BC+CA \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{proof}
|
||||
\item $\bar{A}BC+AB+A\bar{C}=BC+A\bar{C}$
|
||||
\begin{proof}
|
||||
$$
|
||||
\begin{aligned}
|
||||
\bar{A}BC+AB+A\bar{C} & = B(\bar{A}C+A)+A\bar{C} \\
|
||||
& = B(C+A)+A\bar{C} \\
|
||||
& = BC+AB+A\bar{C} \\
|
||||
& = BC+A\bar{C} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{proof}
|
||||
\item $\overline{A\bar{B}+\bar{A}B}=(A+\bar{B})(\bar{A}+B)$
|
||||
\begin{proof}
|
||||
$$
|
||||
\begin{aligned}
|
||||
\overline{A\bar{B}+\bar{A}B} & = \overline{A\bar{B}}\ \overline{\bar{A}B} \\
|
||||
& = (\bar{A}+B)(A+\bar{B}) \\
|
||||
& = (A+\bar{B})(\bar{A}+B) \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{proof}
|
||||
\item $\bar{A}\bar{B}+AB+BC=\bar{A}\bar{B}+AB+\bar{A}C$
|
||||
\begin{proof}
|
||||
$$
|
||||
\begin{aligned}
|
||||
\bar{A}\bar{B}+AB+BC & = \bar{A}\bar{B}+AB+BC(A+\bar{A}) \\
|
||||
& = \bar{A}\bar{B}+AB+BCA+BC\bar{A} \\
|
||||
& = \bar{A}\bar{B}+AB+\bar{A}BC \\
|
||||
& = \bar{A}(\bar{B}+BC)+AB \\
|
||||
& = \bar{A}(\bar{B}+C)+AB \\
|
||||
& = \bar{A}\bar{B}+AB+\bar{A}C \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{proof}
|
||||
\end{enumerate}
|
||||
|
||||
\item 用逻辑代数定理化简下列逻辑函数式。
|
||||
\begin{enumerate}
|
||||
\item $AB+\bar{A}B\bar{C}+BC$
|
||||
$$
|
||||
\begin{aligned}
|
||||
AB+\bar{A}B\bar{C}+BC & = B(A+\bar{A}\bar{C}+C) \\
|
||||
& = B(A+\bar{C}+C) \\
|
||||
& = B \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\item $\bar{A}\bar{B}\bar{C}+A\bar{B}\bar{C}+A\bar{B}C$
|
||||
$$
|
||||
\begin{aligned}
|
||||
\bar{A}\bar{B}\bar{C}+A\bar{B}\bar{C}+A\bar{B}C & = \bar{B}(\bar{A}\bar{C}+A\bar{C}+AC) \\
|
||||
& = \bar{B}(\bar{C}+AC) \\
|
||||
& = \bar{B}(\bar{C}+A) \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\item $ab(cd+\bar{c}d)$
|
||||
$$
|
||||
ab(cd+\bar{c}d)=abd
|
||||
$$
|
||||
\item $[x \overline{(xy)}][y \overline{(xy)}]$
|
||||
$$
|
||||
\begin{aligned}
|
||||
\relax[x \overline{(xy)}][y \overline{(xy)}] & = xy\overline{(xy)}\ \overline{(xy)} \\
|
||||
& = xy\overline{(xy)} \\
|
||||
& = 0 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\item $\overline{(a+b)}\ \overline{(\bar{a}+\bar{b})}$
|
||||
$$
|
||||
\begin{aligned}
|
||||
\overline{(a+b)}\ \overline{(\bar{a}+\bar{b})} & = \bar{a}\bar{b}ab \\
|
||||
& = 0 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\item $\bar{a} \bar{b} \bar{c}+\bar{a} \bar{b}c+a \bar{b}\bar{c}+abc$
|
||||
$$
|
||||
\begin{aligned}
|
||||
\bar{a} \bar{b}\bar{c}+\bar{a} \bar{b}c+a \bar{b}\bar{c}+abc & = \bar{a} \bar{b}+a\bar{b}\bar{c}+abc \\
|
||||
& = \bar{b}(\bar{a}+a\bar{c})+abc \\
|
||||
& = \bar{b}(\bar{a}+\bar{c})+abc \\
|
||||
& = \bar{b}\overline{ac}+bac \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{enumerate}
|
||||
\item[4.] 用卡诺图化简下列最小项表达式.\\
|
||||
$G=f(a,b,c)=\sum m(1,3,5,6,7)$\\
|
||||
\includesvg{1.4.G}\\
|
||||
$$
|
||||
G=f(a,b,c)=a \bar{b}+c
|
||||
$$
|
||||
$H=f(w,x,y,z)=\sum m(0,2,8,10)$\\
|
||||
\includesvg{1.4.H}\\
|
||||
$$
|
||||
H=f(w,x,y,z)=\bar{x}\bar{z}
|
||||
$$
|
||||
|
||||
\newpage
|
||||
$I=f(w,x,y,z)=\sum m(1,3,4,6,9,12,14,15)$\\
|
||||
\includesvg{1.4.I}\\
|
||||
$$
|
||||
I=f(w,x,y,z)=x\oplus z\oplus (wyz)
|
||||
$$
|
||||
|
||||
\vspace{10em}
|
||||
$J=f(a,b,c)=\sum m(0,1,2,3,4,5,7)$\\
|
||||
\includesvg{1.4.J}\\
|
||||
$$
|
||||
J=f(a,b,c)=\sum M(6)=\bar{a}+b+c
|
||||
$$
|
||||
|
||||
\newpage
|
||||
$K=f(a,b,c,d)=\sum m(3,4,5,7,9,13,14,15)$\\
|
||||
\includesvg{1.4.K}\\
|
||||
$$
|
||||
K=f(a,b,c,d)=bd+\bar{a}b \bar{c}+\bar{a}cd+abc
|
||||
$$
|
||||
|
||||
\vspace{10em}
|
||||
$L=f(a,b,c,d)=\sum m(0,1,2,5,6,7,8,9,13,14)$\\
|
||||
\includesvg{1.4.L}\\
|
||||
$$
|
||||
L=f(a,b,c,d)=\bar{b}\bar{c}+\bar{c}d+\bar{a}bc+\bar{a}c \bar{d}+bc \bar{d}
|
||||
$$
|
||||
|
||||
\newpage
|
||||
\item[5.] 用卡诺图化简下列最大项表达式。\\
|
||||
$H=f(a,b,c,d)=\prod M(2, 3, 4, 6, 7, 10, 11, 12) $\\
|
||||
\includesvg{1.5.H}\\
|
||||
$$
|
||||
H=f(a,b,c,d)=(a+\bar{c})(\bar{b}+c+d)(\bar{a}+b+\bar{c})
|
||||
$$
|
||||
|
||||
\vspace{10em}
|
||||
$F=f(u,v,w,x,y)=\prod M(0, 2, 8, 10, 16, 18, 24, 26)$\\
|
||||
\includesvg{1.5.F}\\
|
||||
$$
|
||||
F=f(u,v,w,x,y)=w+y
|
||||
$$
|
||||
|
||||
\newpage
|
||||
\item[6.] 化简下列带任意项的逻辑函数。\\
|
||||
$V=f(a,b,c,d)=\sum m(2,3,4,5,13, 15)+\sum d(8,9,10, 11)$\\
|
||||
\includesvg{1.6.V}\\
|
||||
$$
|
||||
V=f(a,b,c,d)=b \bar{c}+\bar{b}c
|
||||
$$
|
||||
|
||||
\vspace{10em}
|
||||
$Y=f(u,v,w,x)=\sum m(1, 5, 7, 9, 13, 15)+\sum d(8, 10, 11, 14)$\\
|
||||
\includesvg{1.6.Y}\\
|
||||
$$
|
||||
Y=f(u,v,w,x)=x \overline{\bar{u}\bar{v}w}=x(u+v+\bar{w})
|
||||
$$
|
||||
|
||||
\newpage
|
||||
$P=f(r,s,t,u)=\sum m(0, 2, 4, 8, 10, 14)+\sum d(5,6,7,12)$\\
|
||||
\includesvg{1.6.P}\\
|
||||
$$
|
||||
P=f(r,s,t,u)=\bar{u}
|
||||
$$
|
||||
|
||||
\vspace{10em}
|
||||
$H=f(a,b,c,d,e)=\sum m(5,7,9,12,13,14,17,19,20,22,25,27,28,30)+\sum d(8,10,24,26)$\\
|
||||
\includesvg{1.6.H}\\
|
||||
$$
|
||||
H=f(a,b,c,d,e) = a \bar{c}e + ac \bar{e}+\bar{a}\bar{b}ce+bcd \bar{e}+b \bar{c}\bar{d}+\bar{a}bc \bar{d}
|
||||
$$
|
||||
|
||||
\newpage
|
||||
$I=f(d,e,f,g,h)=\prod M(5,7,8,21,23,26,30)\cdot \prod D(10,14,24,28)$\\
|
||||
\includesvg{1.6.I}\\
|
||||
$$
|
||||
I=f(d,e,f,g,h)=(e+\bar{f}+\bar{h})(\bar{e}+\bar{g}+h)(d+\bar{e}+f+h)
|
||||
$$
|
||||
|
||||
\vspace{10em}
|
||||
\item[8.] 将下列逻辑函数化简成与非形式最简式。\\
|
||||
$U=f(a,b,c,d)=\sum m(3,4,6,11,12,14)$\\
|
||||
\includesvg{1.8.U}\\
|
||||
$$
|
||||
U=f(a,b,c,d)=b \bar{d}+\bar{b}cd = \overline{\overline{b \bar{d}}\ \overline{\bar{b}cd}}
|
||||
$$
|
||||
|
||||
\newpage
|
||||
$V=f(a,b,c,d)=\sum m (0,1,2,5,8,10,13)$\\
|
||||
\includesvg{1.8.V}\\
|
||||
$$
|
||||
\begin{aligned}
|
||||
&V=f(a,b,c,d)=(\overline{a \oplus b \oplus d}+\bar{a}\bar{b})\overline{cd}=\overline{a\oplus b\oplus d \overline{\bar{a}\bar{b}}}\overline{cd}=\overline{(\bar{a}b+a \bar{b}) \oplus d}\ \overline{cd} \\
|
||||
&=\overline{\overline{(\bar{a}b +a \bar{b})}d}\ \overline{(\bar{a}b+a \bar{b})\bar{d}}\ \overline{cd}=\overline{\overline{\bar{a}b} \overline{a \bar{b}} d} \ \overline{\overline{\overline{\bar{a}b} \overline{a \bar{b}}}\bar{d}}\ \overline{cd}\\
|
||||
\end{aligned}
|
||||
$$
|
||||
|
||||
\vspace{10em}
|
||||
$W=f(a,b,c,d) = \sum m(3,5,7,10,11)$\\
|
||||
\includesvg{1.8.W}\\
|
||||
$$
|
||||
W=f(a,b,c,d)=\bar{a}cd+\bar{a}bd+a \bar{b}\bar{c}d+a \bar{b}c \bar{d} = \overline{\overline{\bar{a}cd}\ \overline{\bar{a}bd}\ \overline{a \bar{b}\bar{c}d}\ \overline{a \bar{b}c \bar{d}}}
|
||||
$$
|
||||
|
||||
\newpage
|
||||
\item[9.] 将下列逻辑函数化简成或非形式最简式。\\
|
||||
$G=f(a,b,c,d)=\prod M(0,1,2,5,8,10,13) $\\
|
||||
\includesvg{1.9.G}\\
|
||||
$$
|
||||
G=f(a,b,c,d)=(b+d)(c+\bar{d}+a \bar{b}\bar{c})=\overline{\overline{b+d}\ \overline{c+\bar{d}+\overline{\bar{a}+b+c}}}
|
||||
$$
|
||||
|
||||
\vspace{10em}
|
||||
$H=f(a,b,c,d)=\prod M(3,5,7,9,11)$\\
|
||||
\includesvg{1.9.H}\\
|
||||
$$
|
||||
H=f(a,b,c,d) = \bar{d}+\bar{a} \bar{b}\bar{c}+ab=\bar{d}+\overline{a+b+c}+\overline{\bar{a}+\bar{b}}
|
||||
$$
|
||||
\end{enumerate}
|
||||
|
||||
\end{document}
|
31
数字逻辑及实验/作业/第三章作业.tex
Normal file
31
数字逻辑及实验/作业/第三章作业.tex
Normal file
@ -0,0 +1,31 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
|
||||
\fancyhead{}
|
||||
\fancyhead[C]{\mysignature}
|
||||
% 4、6、7、13、15、20
|
||||
\setcounter{chapter}{2}
|
||||
|
||||
\begin{document}
|
||||
\chapter{触发器及其基本应用电路}
|
||||
\begin{enumerate}
|
||||
\itemsep 1em
|
||||
\item[4.] 已知正边沿触发的D触发器的CP和D端的波形如下图所示,试画出它的Q端波形,假定Q的初始值为0。
|
||||
\includexopp{3.4}
|
||||
\item[6.] 已知负边沿翻转的主从型JK触发器的CP和J、K端的波形如下图所示,试画出它的Q端波形,假定Q的初始值为0。
|
||||
\includexopp{3.6}
|
||||
\pagebreak[4]
|
||||
\item[7.] 按照下图给出的逻辑关系画出输出Q的波形,假定Q的初始值为000。
|
||||
\includexopp[0.9]{3.7}
|
||||
\item[13.] 下图是基本RS触发器的一个典型应用——抗抖动开关电路。在按动开关时,由于触点的抖动,可能在开关按下或松开的瞬间产生一串脉冲如(b)所示的波形,试画出RS触发器的输出波形。
|
||||
\includexopp[0.9]{3.13}
|
||||
\item[15.] 试用一个3位异步二进制计数器和一个3-8译码器,构成一个顺序脉冲发生器,要画出原理图和输出波形图。\\
|
||||
\vspace{1em}\\
|
||||
由于异步计数器在时钟的上升沿可能会造成不稳定暂态,所以在时钟信号为0时才让译码器使能,此时异步计数器的输出基本已经稳定。
|
||||
\includexopp{3.15}
|
||||
\pagebreak[4]
|
||||
\item[20.] 试设计一个数据流转换电路,其转换规律如下:若输入数据流中出现连续3个“1”时,将最后一个“1”转换为“0”。注意:一旦有转换发生,其后的转换过程中对输入“1”的个数进行的计数将重新开始,即输入连续多个“1”时,转换为“0”的数据是每3个“1”中有一个。\\
|
||||
\vspace{1em}\\
|
||||
使用移位寄存器,存储输入数据流中的连续3个信号,将这三个信号通过与非门,再连接到最靠近输入信号的触发器的复位信号上,也就是在这三个信号同时为“1”时将最后一个“1”转换为“0”。
|
||||
\includexopp{3.20}
|
||||
\end{enumerate}
|
||||
\end{document}
|
263
数字逻辑及实验/作业/第五章作业.tex
Normal file
263
数字逻辑及实验/作业/第五章作业.tex
Normal file
@ -0,0 +1,263 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
|
||||
\fancyhead{}
|
||||
\fancyhead[C]{\mysignature}
|
||||
% 1、2、10、11、3、4、7、8、13
|
||||
\setcounter{chapter}{4}
|
||||
|
||||
\begin{document}
|
||||
\renewcommand{\bar}{\xoverline}
|
||||
\chapter{异步时序电路}
|
||||
|
||||
\begin{enumerate}
|
||||
\columnseprule=0.5pt
|
||||
\item 分析下图所示电路。
|
||||
\begin{enumerate}
|
||||
\item 写出状态流程表,画出状态转换图。
|
||||
\item 假定系统初始状态为$Y_1=0$,画出下图所示输入波形对应的输出波形,并据此分析电路功能。
|
||||
\end{enumerate}
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-12-24-15-02-47.png}
|
||||
|
||||
\begin{multicols}{2}
|
||||
\begin{zhongwen}
|
||||
\noindent
|
||||
先写出激励方程和输出方程:
|
||||
$$
|
||||
\begin{aligned}
|
||||
&Y_1=\overline{\overline{x_1\ \overline{x_2}}\ \overline{x_2\ y_1}}=x_1 \overline{x_2}+x_2y_1\\
|
||||
&Y_2=\overline{y_1}\ x_1\ x_2\\
|
||||
&z=Y_2\\
|
||||
\end{aligned}
|
||||
$$
|
||||
再写出状态流程表:
|
||||
\includexopp{5.1.1}
|
||||
将$x_1x_2y_1y_2$作为系统总态,画出状态转换图:
|
||||
\includexopp{5.1.2}
|
||||
再画出波形图:
|
||||
\includexopp{5.1.3}
|
||||
于是可以分析出功能为:当$x_2$在$x_1$之前先变为1时,输出$x_1x_2$,否则输出0。
|
||||
|
||||
\end{zhongwen}
|
||||
\end{multicols}
|
||||
|
||||
\item 分析下图所示电路。
|
||||
\begin{enumerate}
|
||||
\item 写出状态流程表,画出状态转换图。
|
||||
\item 假定系统初始状态为$Y_1Y_2=00$,画出在下图所示输入波形下的输出波形,并据此分析电路功能。
|
||||
\end{enumerate}
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-12-24-16-04-57.png}
|
||||
|
||||
\begin{multicols}{2}
|
||||
\begin{zhongwen}
|
||||
\noindent
|
||||
先写出激励方程和输出方程:
|
||||
$$
|
||||
\begin{aligned}
|
||||
&Y_1=\overline{\overline{y_1\ y_2}\ \overline{y_1\ x_1}\ \overline{y_2\ x_2}}=y_1y_2+y_1x_1+y_2x_2 \\
|
||||
&Y_2=\overline{\overline{y_2\ x_2}\ \overline{\overline{y_1}\ y_2}\ \overline{\overline{y_1}\ \overline{x_2}}}=y_2x_2+\bar{y_1}y_2+\bar{y_1}x_1\bar{x_2} \\
|
||||
&z=y_1y_2x_2 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
再写出状态流程表:
|
||||
\includexopp{5.2.1}
|
||||
将$x_1x_2y_1y_2$作为系统总态,画出状态转换图:
|
||||
\includexopp{5.2.2}
|
||||
再画出波形图:
|
||||
\includexopp{5.2.3}
|
||||
于是可以分析出功能为:当$x_1$为0时,输出为0;当$x_1$出现上升沿后,输出$x_2$的第一个脉冲(如果$x_1$在$x_2$的脉冲期间上升,则输出当前脉冲)。
|
||||
\end{zhongwen}
|
||||
\end{multicols}
|
||||
\pagebreak[4]
|
||||
|
||||
\item 设计一个基本型异步时序电路,输入$x_1$、$x_2$,输出$z$。如果输入变量个数按二进制增加,则输出为1,反之输出为0.所谓按二进制增加是指$x_1x_2=00\to 10\to 11$或$00\to 10\to 11$。
|
||||
\begin{multicols}{2}
|
||||
\begin{zhongwen}
|
||||
\noindent
|
||||
用$S_0,S_1,S_2,S_3$表示系统状态,画出状态转换图:
|
||||
\includexopp{5.3.1}
|
||||
图中的$S_1$和$S_2$状态的输出为1,$S_0$和$S_3$状态的输出为0。
|
||||
再写出状态流程表:
|
||||
\includexopp{5.3.2}
|
||||
显然状态已经最简了,无法合并了。
|
||||
之后分配状态,根据输出,$S_1,S_2$应该相邻,$S_0,S_3$应该相邻。
|
||||
为了避免竞争,$S_0,S_1$应该相邻,$S_2,S_3$应该相邻。
|
||||
因此可以分配$S_0=00,S_1=01,S_2=11,S_3=10$。
|
||||
重新写出状态流程表:
|
||||
\includexopp{5.3.3}
|
||||
据此分别画出$Y_1,Y_2,z$的卡诺图:
|
||||
\includexopp{5.3.4}
|
||||
检查任意项,不会发生临界竞争。\\
|
||||
于是可以得到激励方程和输出方程:
|
||||
$$
|
||||
\begin{aligned}
|
||||
&Y_1=y_1x_1+y_1x_2+x_1x_2=\overline{\overline{x_1y_1}\ \overline{x_2y_1}\ \overline{x_1x_2}} \\
|
||||
&Y_2=\bar{y_1}x_1+\bar{y_1}x_2+x_1x_2 = \overline{\overline{\bar{y_1}x_1}\ \overline{\bar{y_1}x_2}\ \overline{x_1x_2}} \\
|
||||
&z=y_2 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
则可以画出逻辑电路图:
|
||||
\includexopp{5.3.5}
|
||||
\end{zhongwen}
|
||||
\end{multicols}
|
||||
\pagebreak[4]
|
||||
|
||||
\item 设计一个单脉冲发生器,两个输入为$x_1$、$x_2$,输出$z$,其中$x_1$为连续的脉冲信号,$x_2$为一个开关信号,要求当$x_2$从高跳变到低后,$z$输出一个完整的$x_1$脉冲,并只有在输出$z$变低以后,$x_2$才能再次由低到高,其波形如下图所示。
|
||||
\begin{center}
|
||||
\noindent
|
||||
\includegraphics[width=0.8\linewidth]{imgs/2023-12-24-20-23-25.png}
|
||||
\end{center}
|
||||
\begin{zhongwen}
|
||||
\begin{multicols}{2}
|
||||
“并只有在输出$z$变低以后,$x_2$才能再次由低到高”这句话是根据输出限制输入?那也就是说只是限制输入的变化的情况的,用来简化题目的。
|
||||
|
||||
根据波形图可以划分出5个状态:\\
|
||||
$S_0$:初始状态,$x_2$为0,$z$保持0;\\
|
||||
$S_1$:$x_2$变为1,$z$仍然为0;\\
|
||||
$S_2$:$x_2$在$x_1$为1时从1变0,当前脉冲不能算,等待下一个$x_1$的脉冲;\\
|
||||
$S_3$:$x_2$和$x_1$都是0,下一个$x_1$上升沿即可将$z$置为1;\\
|
||||
$S_4$:$x_2$从1变0后$x_1$的首个脉冲期间,$z$为1。\\
|
||||
|
||||
直接画出状态流程表:
|
||||
\includexopp{5.4.1}
|
||||
根据隐含表查看状态是否可以化简:
|
||||
\includexopp[1.5]{5.4.2}
|
||||
可以发现$S_1$和$S_2$等价(对啊,之前怎么没想到呢,$S_1$和$S_2$都是等待转换到$S_3$的状态,也就是说要转换到$S_3$必须要输入为00),因此状态可以合并。
|
||||
|
||||
接下来分配状态,根据输出,$S_0,\{ S_1,S_2 \},S_3$应该相邻;为了避免竞争,$\{ S_1,S_2 \},S_3$应该相邻,$S_4,S_0$应该相邻,$S_3,S_4$应该相邻。
|
||||
因此可以分配$S_0=00,\{ S_1,S_2 \}=01,S_3=11,S_4=10$。重新写出状态流程表:
|
||||
\includexopp{5.4.3}
|
||||
据此分别画出$Y_1,Y_2,z$的卡诺图:
|
||||
\includexopp{5.4.4}
|
||||
检查任意项,不会发生临界竞争。
|
||||
于是可以得到激励方程和输出方程:
|
||||
$$
|
||||
\begin{aligned}
|
||||
&Y_1=y_2 \bar{x_1} \bar{x_2}+y_1 x_1 \bar{x_2}=\overline{\overline{y_2 \bar{x_1} \bar{x_2}}\ \overline{y_1x_1 \bar{x_2}}} \\
|
||||
&Y_2=x_2+y_2 \bar{x_1}+ \bar{y_1}y_2 = \overline{\bar{x_2}\ \overline{y_2 \bar{x_1}}\ \overline{\bar{y_1} y_2}}\\
|
||||
&z=y_1 \bar{y_2} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
则可以画出逻辑电路图:
|
||||
\end{multicols}
|
||||
\includexopp[1.5]{5.4.5}
|
||||
\end{zhongwen}
|
||||
|
||||
\item[7.] 试用基本型异步时序电路的设计方法设计一个负边沿触发的D触发器,要求写出详细的设计过程。提示:将时钟$CP$与激励$D$作为异步电路的两个输入。
|
||||
|
||||
\begin{zhongwen}
|
||||
首先考虑状态如何设计,输出为1和输出为0肯定是两个不同的状态,那么先假设就这两个状态。之后考虑状态如何转换,输出为0到输出为1的条件是$D$为1并且$CP$下降沿。如果将输入状态用$D$和$CP$表示,那么就是从11变化到10的时候。那么在状态流程表上就是这样的。
|
||||
\includexopp[1.5]{5.7.1}
|
||||
可以看到,对于状态A,从11变成10的时候($CP$下降沿的时候$D$为1)要改变状态到B,但是从00到10的时候($CP$不是下降沿)不改变状态;同理对于状态B,从01变成00的时候($CP$下降沿的时候$D$为0)要改变状态到A,但是从10到00的时候($CP$不是下降沿)不改变状态。
|
||||
|
||||
但是一个系统总态只能对应一个激励状态,也就是状态流程表中一个格子只能填一个状态,因此这就需要拆分状态。将A拆分为$A_1,A_2$,其中$A_1$表示不改变状态的情况,$A_2$表示要改变到B的情况;同理,将B拆分为$B_1,B_2$,其中$B_1$表示不改变状态的情况,$B_2$表示要改变到A的情况。即可得到状态流程表如下:
|
||||
\includexopp[1.5]{5.7.2}
|
||||
图中的稳定状态已经圈出。可以注意到:系统总态为$11A_1$的格子的激励状态为$A_2$,不是稳定状态,因此这也就避免了系统总态从$11A_1$到$10A_1$的情况,所以$10A_1$的激励状态就可以填入$A_1$了,同理系统总态为$00A_2$的格子的激励状态为$A_1$,这也不是稳定状态,这也就避免了系统总态从$00A_2$到$10A_2$的情况,所以$10A_2$的激励状态就可以填入$B$了($B_1$或$B_2$均可)。因此这样就解决了拆分前无法填入的问题。
|
||||
|
||||
另外还可以注意到系统总态为$01A_1$和$01A_2$的这两个格子只填了A,代表着填入$A_1$或$A_2$均可,因为这里填$A_1$还是$A_2$不会影响输出也不会影响接下来的状态转换。
|
||||
|
||||
之后根据状态相邻的关系分配状态避免竞争。观察从不稳定状态转化到稳定状态的过程,可以看到$A_1A_2$应该相邻,$B_1B_2$应该相邻。因此可以分配状态如下:$A_1: 00, A_2: 01, B_1: 11, B_2:00$。之后可以得到新的状态流程表:
|
||||
\includexopp[1.5]{5.7.3}
|
||||
其中,系统总态($D,CP,y_1,y_2$)为$1001$的格子虽然只要填入B对应的状态就可以了,也就是1d,但是为了防止竞争的产生,这是填入了11;同理系统总态为$0010$的格子也填入了00而不是0d。
|
||||
|
||||
于是可以画出$Y_1,Y_2,z$的卡诺图:
|
||||
\includexopp[0.9]{5.7.4}\\
|
||||
要注意防止卡诺圈相切造成冒险。
|
||||
|
||||
于是可以得到激励方程和输出方程(这里就不化成与非的形式了,电路图中直接使用与非门即可):
|
||||
$$
|
||||
\begin{aligned}
|
||||
&Y_1=y_1y_2+y_1CP+y_1D+y_2D \bar{CP} \\
|
||||
&Y_2=\bar{y_1}CP+y_1y_2 \bar{CP}+\bar{y_1}y_2D+y_1D \bar{CP}+y_2D \bar{CP} \\
|
||||
&z=y_1 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
|
||||
则可以画出逻辑电路图:
|
||||
\includexopp[1.5]{5.7.5}
|
||||
|
||||
\end{zhongwen}
|
||||
\pagebreak[1]
|
||||
|
||||
\item[8.] 试用基本型异步时序电路的设计方法设计一个正边沿触发的JK触发器,要求写出详细的设计过程。提示:将时钟$CP$与激励$J$、$K$作为异步电路的3个输入。
|
||||
|
||||
\begin{multicols}{2}
|
||||
\begin{zhongwen}
|
||||
\noindent
|
||||
同样用上题的做法,先画出未拆分状态的状态流程表:
|
||||
\includexopp{5.8.1}
|
||||
拆分状态后的状态流程表:
|
||||
\includexopp{5.8.2}
|
||||
分配状态后:
|
||||
\includexopp{5.8.3}
|
||||
$Y_1,Y_2$的卡诺图($z=y_1$,不用画了):
|
||||
\includexopp{5.8.4}
|
||||
激励方程与输出方程:\\
|
||||
$Y_1=y_1 \bar{y_2}+ y_1 \bar{K}+ \bar{y_2} J\ CP + y_1K \bar{CP}$ \\
|
||||
$Y_2=y_1K \bar{CP} + y_1y_2K+y_2K\ CP+\bar{y_1}y_2\ CP+\bar{y_1} \bar{J}\ CP$ \\
|
||||
$z=y_1$ \\
|
||||
逻辑电路图:
|
||||
\includexopp{5.8.5}
|
||||
\end{zhongwen}
|
||||
\end{multicols}
|
||||
\pagebreak[4]
|
||||
|
||||
\item[10.] 分析在下面的状态流程表中是否存在临界竞争。若存在则试用最简单的方法消除之。\\
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-12-27-20-54-39.png}
|
||||
|
||||
\begin{multicols}{2}
|
||||
\begin{zhongwen}
|
||||
\includexopp{5.10.1}
|
||||
可以看到存在临界竞争。当系统总态(用$x_1x_2y_1y_2$表示)为0111时和1100时会发生临界竞争。可以直接改变对应位置的激励状态来消除临界竞争:
|
||||
\includexopp{5.10.2}
|
||||
\end{zhongwen}
|
||||
\end{multicols}
|
||||
|
||||
\item[11.] 试分析下图电路的可靠性,并在不改变电路逻辑功能的前提下修改电路,以确保工作稳定。
|
||||
\begin{center}
|
||||
\includegraphics[width=0.5\linewidth]{imgs/2023-12-27-21-09-40.png}
|
||||
\end{center}
|
||||
|
||||
\begin{multicols}{2}
|
||||
\begin{zhongwen}
|
||||
首先写出激励方程和输出方程(好像输出就是激励)。
|
||||
$$
|
||||
\begin{aligned}
|
||||
Y_1&=\overline{\overline{y_1\ \overline{x_1}}\ \overline{x_1\ y_2}}=y_1 \bar{x_1}+x_1y_2 \\
|
||||
Y_2&=\overline{\overline{x_1\ y_2}\ \overline{y_1x_2 \bar{x_1}}\ \overline{y_1x_1 \bar{x_2}}\ \overline{\bar{x_1} \bar{x_2} \bar{y_1}}} \\
|
||||
&= x_1y_2+y_1x_2 \bar{x_1}+y_1x_1 \bar{x_2}+\bar{x_1} \bar{x_2} \bar{y_1} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
之后写出状态流程表:
|
||||
\includexopp{5.11.1}
|
||||
$Y_1$应增加冗余项 $y_1y_2$,$Y_2$应增加冗余项$y_1y_2x_2$。\\
|
||||
消除临界竞争,$Y_1$需要再增加一项$y_1x_1 \bar{x_2}$。
|
||||
$Y_1=y_1 \bar{x_1}+x_1y_2+y_1y_2+y_1x_1 \bar{x_2}$ \\
|
||||
$Y_2=x_1y_2+y_1x_2\bar{x_1}+y_1x_1 \bar{x_2}+ \bar{x_1} \bar{x_2} \bar{y_1} + y_1y_2x_2$ \\
|
||||
逻辑电路图修改为:
|
||||
\includexopp{5.11.2}
|
||||
\end{zhongwen}
|
||||
\end{multicols}
|
||||
|
||||
\item[13.] 试用$D$触发器设计一个13进制异步计数器。
|
||||
\begin{multicols}{2}
|
||||
\begin{zhongwen}
|
||||
以$x$作为输入,$y_0,y_1,y_2,y_3$作为从低位到高位的输出,画出时序波形图:
|
||||
\includexopp{5.13.1}
|
||||
假设D触发器为上升沿有效。根据时钟选择的原则,$CP_0=x$,画出$y_0$的卡诺图如下:
|
||||
\includexopp{5.13.2}
|
||||
$D_0=Q_{0,n+1}=\bar{Q_3} \bar{Q_0}+\bar{Q_2} \bar{Q_0}$
|
||||
|
||||
$CP_1=\bar{y_0}$,观察可以发现每次$y_0$的下降沿都会触发$y_1$翻转,所以$Q_1$可以接成T触发器。
|
||||
|
||||
$CP_2=x$,其实$CP_2$的卡诺图不需要画了,反正当作全1了。画出$y_2$的卡诺图如下:
|
||||
\includexopp[2]{5.13.3}
|
||||
$D_2=Q_{2,n+1}=\bar{Q_3} Q_2 \bar{Q_1} + \bar{Q_3} Q_2 \bar{Q_0} + \bar{Q_2}Q_1Q_0$
|
||||
|
||||
$CP_3=\bar{y_2}$,同样观察可以发现每次$y_2$的下降沿都会触发$y_3$翻转,所以$Q_3$也可以接成T触发器。
|
||||
|
||||
所以画出逻辑电路图如下:
|
||||
\includexopp{5.13.4}
|
||||
\end{zhongwen}
|
||||
\end{multicols}
|
||||
\end{enumerate}
|
||||
\end{document}
|
330
数字逻辑及实验/作业/第四章作业.tex
Normal file
330
数字逻辑及实验/作业/第四章作业.tex
Normal file
@ -0,0 +1,330 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
\usepackage{fp}
|
||||
|
||||
\fancyhead{}
|
||||
\fancyhead[C]{\mysignature}
|
||||
% 1、2、5、8、10、11、15、18、20
|
||||
\setcounter{chapter}{3}
|
||||
|
||||
\begin{document}
|
||||
\renewcommand{\bar}{\xoverline}
|
||||
\chapter{同步时序电路}
|
||||
|
||||
\begin{enumerate}
|
||||
\cnitem[1] 在下图所示电路中,设初始状态为$Q_1=Q_2=Q_3=0$。
|
||||
\includexopp[0.8]{4.1.0}
|
||||
\begin{enumerate}
|
||||
\itemsep 1em
|
||||
\item 写出状态转换表,画出状态转换图。
|
||||
|
||||
% multicols只能两栏一样
|
||||
% 两栏不一样可以用vwcol,不过可能不一定能处理非文本。
|
||||
% 还是用minipage吧
|
||||
\begin{zhongwen}
|
||||
\begin{minipage}{0.8\linewidth}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&Q_{1(n+1)}=X\oplus Q_{1n} \\
|
||||
&Q_{2(n+1)}=(Q_{1n}X)\oplus Q_{2n} \\
|
||||
&Q_{3(n+1)}=(Q_{2n}Q_{1n}X)\oplus Q_{3n} \\
|
||||
&Z_1=Q_{2n}Q_{3n} \\
|
||||
&Z_2=\overline{Q_{3n}} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
状态转换表为:
|
||||
\begin{table}[H]
|
||||
% \centering
|
||||
\begin{tabular}{c|c|cc|cc}
|
||||
\toprule
|
||||
$状态$ & $Q_3Q_2Q_1$ & $次态X=0$ & $次态X=1$ & $输出Z_1$ & $输出Z_2$ \\
|
||||
\midrule
|
||||
$S_0$ & $000$ & $000$ & $001$ & $0$ & $1$ \\
|
||||
$S_1$ & $001$ & $001$ & $010$ & $0$ & $1$ \\
|
||||
$S_2$ & $010$ & $010$ & $011$ & $0$ & $1$ \\
|
||||
$S_3$ & $011$ & $011$ & $100$ & $0$ & $1$ \\
|
||||
$S_4$ & $100$ & $100$ & $101$ & $0$ & $0$ \\
|
||||
$S_5$ & $101$ & $101$ & $110$ & $0$ & $0$ \\
|
||||
$S_6$ & $110$ & $110$ & $111$ & $1$ & $0$ \\
|
||||
$S_7$ & $111$ & $111$ & $000$ & $1$ & $0$ \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{table}
|
||||
\end{minipage}
|
||||
\begin{minipage}{0.2\linewidth}
|
||||
状态转换图为:\\(输出为$Z_1Z_2$)\\
|
||||
\includexopp{4.1.1}
|
||||
\end{minipage}
|
||||
\end{zhongwen}
|
||||
|
||||
\item 分别画出$X=0$和$X=1$的输出波形。
|
||||
|
||||
\begin{minipage}{0.3\linewidth}
|
||||
\includexopp{4.1.2.1}
|
||||
$$
|
||||
X=0
|
||||
$$
|
||||
\end{minipage}
|
||||
\hfill
|
||||
\begin{minipage}{0.6\linewidth}
|
||||
\includexopp{4.1.2.2}
|
||||
$$
|
||||
X=1
|
||||
$$
|
||||
\end{minipage}
|
||||
|
||||
\end{enumerate}
|
||||
|
||||
\item 分析下图电路,画出状态转换图并说明其逻辑功能。
|
||||
|
||||
% \includegraphics[width=0.8\linewidth]{imgs/2023-11-26-19-03-38.png}
|
||||
\includexopp[0.8]{4.2.0}
|
||||
|
||||
\begin{zhongwen}
|
||||
\noindent % 可以取消缩进
|
||||
\begin{minipage}{0.55\linewidth}
|
||||
输出与当前时刻输入相关,为米利模型。
|
||||
$$
|
||||
\begin{aligned}
|
||||
&Q_{1(n+1)}=X \overline{Q_{1n}}+X Q_{1n}=X \\
|
||||
&Q_{2(n+1)}=Z \overline{Q_{2n}}+Z Q_{2n}=Z \\
|
||||
&Z=(X+Q_{1n})\ \overline{Q_{2n}} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
状态转换表:
|
||||
\begin{table}[H]
|
||||
\begin{tabular}{c|c|cc}
|
||||
\toprule
|
||||
$\multirow{2}{*}{现态}$ & \multirow{2}{*}{$编码Q_1Q_2$} & \multicolumn{2}{c}{$次态Q_{1(n+1)}Q_{2(n+1)}/输出Z$} \\
|
||||
$ $ & $ $ & $X=0$ & $X=1$ \\
|
||||
\midrule
|
||||
$S_0$ & $00$ & $00/0$ & $11/1$ \\
|
||||
$S_1$ & $01$ & $00/0$ & $10/0$ \\
|
||||
$S_2$ & $10$ & $01/1$ & $11/1$ \\
|
||||
$S_3$ & $11$ & $00/0$ & $10/0$ \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{table}
|
||||
\end{minipage}
|
||||
\begin{minipage}{0.45\linewidth}
|
||||
状态转换图:\\
|
||||
\includexopp{4.2.1}
|
||||
\end{minipage}
|
||||
|
||||
没看出这是什么逻辑功能。
|
||||
\end{zhongwen}
|
||||
|
||||
\cnitem[5] 试用1个4位二进制同步计数器构成一个可变进制同步计数器。该计数器有一个控制端$S$,要求当$S=0$时实现十进制计数功能,$S=1$时实现十二进制计数功能。画出电路图和状态转换图。
|
||||
|
||||
\begin{zhongwen}
|
||||
当$S=0$时,计数器从0到9计数,即当计数器等于9时传递清零信号;
|
||||
当$S=1$时,计数器从0到11计数,即当计数器等于11时传递清零信号。
|
||||
设$Q_3$为高位,$Q_0$为低位。由于9为二进制的1001,在计数为0到8时不会出现$Q_3$和$Q_0$同时为1的情况,因此可以直接将$Q_3$和$Q_0$通过一个与非门来检测是否到达9;同理,12为二进制的1011,在计数为0到10时不会出现$Q_0,Q_1,Q_3$同时为1的情况,因此可以直接将$Q_0,Q_1,Q_3$通过一个与非门来检测是否到达11,这里为了利用之前检测9用到的与非门,于是增加了一个非门和一个二输入与非门。之后这两种检测的输出需要通过$X$来进行选择,当$X=0$时选择检测9的输出,当$X=1$时选择检测11的输出,之后将输出传递回同步计数器的清零输入端,这样在下一个时刻,计数器就清零了,并且检测到输出后可以通过一个非门,就可以表示进位输出了。
|
||||
|
||||
\includexopp[0.9]{4.5.1}
|
||||
\end{zhongwen}
|
||||
|
||||
\cnitem[8] 设计一个“110”序列检测器。当连续输入“110”后输出为1,其余情况输出为0。
|
||||
|
||||
\begin{zhongwen}
|
||||
首先设$Q_0$为第一级状态,$Q_1$为第二级状态,用$Q_1Q_0$表示状态,使用两位的移位寄存器,即为左移。使用米利模型,则可以可以画出状态转换图如下:
|
||||
|
||||
\includexopp[2]{4.8.1}
|
||||
|
||||
由于状态转换图比较简单,因此不需要状态转换表和卡诺图,可以直接画出逻辑电路图如下:
|
||||
|
||||
\includexopp[2]{4.8.2}
|
||||
|
||||
其中$X$为输入,$CP$为时钟信号,$Y$为输出。
|
||||
|
||||
如果使用摩尔模型,同样利用移位寄存器,可以直接一步画出逻辑电路图如下:
|
||||
|
||||
\includexopp[2]{4.8.3}
|
||||
|
||||
其中$X$为输入,$CP$为时钟信号,$Y$为输出。
|
||||
\end{zhongwen}
|
||||
|
||||
\cnitem[10] 设计一个串行4位奇偶校验电路。一组4位数码从$X_1$输入,输入到第4个数码时,字同步信号$X_2=1$,表示一个字(4位)输入结束。当4个数码中的“1”的个数为奇数时,输出$Z=1$,否则输出为0。
|
||||
|
||||
\begin{zhongwen}
|
||||
根据题意,可以设$S_0$表示当前已经接收的1的个数为偶数,$S_1$表示当前已经接收的1的个数为奇数,输入用$X_1X_2$表示,使用米利模型,则可以画出状态转换图如下:
|
||||
|
||||
\includexopp[2]{4.10.1}
|
||||
|
||||
用$Q=0$表示$S_0$,$Q=1$表示$S_1$,$Q_n$表示现态,$Q_{n+1}$表示次态,$Y$表示输出,则可以画出卡诺图如下:
|
||||
|
||||
\includexopp[2]{4.10.2}
|
||||
|
||||
因此$Q_{n+1}=X_1 \bar{X_2} \bar{Q_n} + \bar{X_1} \bar{X_2} Q_n$,$Y=X_1X_2 \bar{Q_n} + \bar{X_1} X_2 Q_n$。由于表达式和JK触发器的表达式接近,所以可以使用JK触发器,于是可以将$Q_{n+1}$的表达式写为$Q_{n+1}=X_1 \bar{X_2} \bar{Q_n} + \overline{X_1+X_2}Q_n$,因此$J=X_1 \bar{X_2}$,$K=X_1+X_2$,于是画出逻辑电路图如下:
|
||||
|
||||
\includexopp[1.5]{4.10.3}
|
||||
\end{zhongwen}
|
||||
|
||||
\cnitem[11] 试用JK触发器设计一个同步四进制计数器,它有2个控制端,其功能如下:
|
||||
|
||||
\begin{table}[H]
|
||||
\centering
|
||||
\tabcolsep=2em
|
||||
\begin{tabular}{cc||cc}
|
||||
\toprule
|
||||
$X_1X_2$ & 功能 & $X_1X_2$ & 功能 \\
|
||||
\midrule
|
||||
$00$ & 保持 & $10$ & 减法计数 \\
|
||||
$01$ & 加法计数 & $11$ & 本输入不允许出现 \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{table}
|
||||
|
||||
\begin{zhongwen}
|
||||
用$Q_1Q_0$表示计数的状态,其中$Q_1$为高位,$Q_0$为低位。则可以画出$Q_1$和$Q_0$的卡诺图如下:
|
||||
|
||||
\includexopp[1.3]{4.11.1}
|
||||
|
||||
由于JK触发器的状态转换方程为$Q_{n+1}=J \bar{Q_n}+\bar{K}Q_n$,因此需要将卡诺图表达成这样的形式,因此在$Q_{1(n+1)}$的卡诺图上,$Q_{1n}=0$的部分圈1,$Q_{1n}=1$的部分全部取反,也就是圈0(但仍然是写成积之和的形式,仍然是0表示反变量输入),在$Q_{0(n+1)}$的卡诺图上同理。
|
||||
|
||||
% $$
|
||||
% \begin{aligned}
|
||||
% Q_{1(n+1)} & = \bar{X_2}Q_{1n}Q_{0n}+\bar{X_1}Q_{1n} \bar{Q_{0n}}+\bar{X_1} \bar{X_2}Q_{1n}+X_1 \bar{Q_{1n}} \bar{Q_{0n}}+X_2 \bar{Q_{1n}}Q_{0n} \\
|
||||
% &=(\bar{X_2}Q_{0n}+\bar{X_1} \bar{Q_{0n}}+\bar{X_1} \bar{X_2})Q_{1n}+(X_1 \bar{Q_{0n}}+X_2Q_{0n}) \bar{Q_{1n}} \\
|
||||
% \end{aligned}
|
||||
% $$
|
||||
|
||||
$$
|
||||
Q_{1(n+1)}=\bar{Q_{1n}}(X_1 \bar{Q_{0n}}+X_2Q_{0n})+Q_{1n} \overline{X_2Q_{0n}+X_1\bar{Q_{0n}}}
|
||||
$$
|
||||
$$
|
||||
Q_{0(n+1)}=(X_2+X_1)\bar{Q_{0n}} + \overline{X_1+X_2} Q_{0n}
|
||||
$$
|
||||
|
||||
比较JK触发器的状态转换方程可得到:
|
||||
|
||||
$$
|
||||
J_1=X_1 \bar{Q_{0n}}+X_2 Q_{0n}
|
||||
$$
|
||||
% $$
|
||||
% \begin{aligned}
|
||||
% K_1 & = \overline{\bar{X_2}Q_{0n}+\bar{X_1} \bar{Q_{0n}}+\bar{X_1} \bar{X_2}} \\
|
||||
% & = \overline{\bar{X_2}Q_{0n}}\ \overline{\bar{X_1} \bar{Q_{0n}}}\ \overline{\bar{X_1}\bar{X_2}} \\
|
||||
% & = (X_2+\bar{Q_{0n}})(X_1+Q_{0n})(X_1+X_2) \\
|
||||
% \end{aligned}
|
||||
% $$
|
||||
$$
|
||||
K_1=X_2Q_{0n} + X_1\bar{Q_{0n}}
|
||||
$$
|
||||
$$
|
||||
J_0=X_1+X_2
|
||||
$$
|
||||
$$
|
||||
K_0=X_1+X_2
|
||||
$$
|
||||
|
||||
则画出逻辑电路图如下:
|
||||
|
||||
\includexopp[1.5]{4.11.2}
|
||||
\end{zhongwen}
|
||||
|
||||
\cnitem[15] 试用D触发器设计一个同步时序电路,能够满足下列状态转换图要求。
|
||||
|
||||
\includexopp[1.5]{4.15.0}
|
||||
|
||||
\begin{zhongwen}
|
||||
从状态转换图可以看出是米利模型,用$Q_1Q_2Q_3$表示状态,$X$表示输入,$Y$表示输出,则可以画出卡诺图如下:
|
||||
|
||||
\includexopp[1.5]{4.15.1}
|
||||
|
||||
$$
|
||||
Q_{1(n+1)}=\bar{Q_{3n}}X
|
||||
$$
|
||||
$$
|
||||
Q_{2(n+1)}=\bar{Q_{3n}} \bar{X} + Q_{2n}Q_{3n}X
|
||||
$$
|
||||
$$
|
||||
Q_{3(n+1)}=\bar{Q_{1n}} \bar{Q_{2n}} \bar{Q_{3n}} \bar{X} + \bar{Q_{1n}}Q_{3n}\bar{X}
|
||||
$$
|
||||
$$
|
||||
Y=\bar{Q_{1n}}\bar{Q_{2n}}Q_{3n}+\bar{Q_{1n}}Q_{3n}X
|
||||
$$
|
||||
|
||||
检查冗余状态,冗余状态的次态只能为$000,010,100$三种,均在正常状态,冗余状态检查通过。
|
||||
|
||||
逻辑电路图如下:
|
||||
|
||||
\includexopp[1.5]{4.15.2}
|
||||
\end{zhongwen}
|
||||
|
||||
\cnitem[18] 设计一个单双脉冲发生电路,要求如下:
|
||||
当控制端$M=0$时,产生单脉冲序列,如下图(a)所示。其中脉冲宽度为1个时钟周期,间隔宽度为10个时钟周期。
|
||||
当控制端$M=1$时,产生双脉冲序列,如下图(b)所示。其中脉冲宽度均为1个时钟周期,两个脉冲之间的间隔为1个时钟周期,每组脉冲之间的间隔宽度为10个时钟周期。
|
||||
|
||||
\includexopp[1.2]{4.18.0}
|
||||
|
||||
\begin{zhongwen}
|
||||
由于需要精确10个时钟周期,考虑用计数器实现。当$M=0$时,输出的周期为11个时钟周期,于是可以让计数器从0到10计数;当$M=1$时,输出的周期为13个时钟周期,于是可以让计数器从0到12计数。而输出可以检测计数器的状态,当计数器的状态为10或12时输出1,否则输出0,这样当$M=0$时计数器到达10后就回到1了,所以是单脉冲序列;当$M=1$时计数器的状态为10时输出1,11时输出0,12时输出1,所以是双脉冲序列。
|
||||
|
||||
\includexopp[1.2]{4.18.1}
|
||||
|
||||
上图中$CP$为时钟信号,$M$为控制端,$Y$为输出端。
|
||||
\end{zhongwen}
|
||||
|
||||
\cnitem[20] 试用JK触发器(每个触发器只有一组JK输入)和必要的门电路设计一个满足下列状态关系的同步时序电路,要求电路尽可能简单。
|
||||
|
||||
\includexopp{4.20.0}
|
||||
|
||||
\begin{zhongwen}
|
||||
首先使用隐含表法进行状态化简:
|
||||
|
||||
\includexopp[2]{4.20.1}
|
||||
|
||||
可知$S_0$与$S_5$等价,$S_1$、$S_4$、$S_6$等价。
|
||||
于是原状态转换表可化为:
|
||||
|
||||
\begin{table}[H]
|
||||
\centering
|
||||
\tabcolsep=2em
|
||||
\begin{tabular}{c|c|c|c|c}
|
||||
\toprule
|
||||
\multirow{2}{*}{现态} & \multicolumn{2}{c}{次态} \vline& \multicolumn{2}{c}{输出} \\
|
||||
$ $ & $X=0$ & $X=1$ & $X=0$ & $X=1$ \\
|
||||
\midrule
|
||||
$S_0$ & $S_0$ & $S_1$ & $0$ & $1$ \\
|
||||
$S_1$ & $S_1$ & $S_3$ & $0$ & $0$ \\
|
||||
$S_2$ & $S_3$ & $S_1$ & $1$ & $0$ \\
|
||||
$S_3$ & $S_0$ & $S_1$ & $1$ & $1$ \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{table}
|
||||
|
||||
根据状态编码的分配规则,将$S_0S_1S_2S_3$分别编码为$00,01,10,11$。
|
||||
用$Q_1Q_0$表示状态,$Y$表示输出。
|
||||
则卡诺图如下:
|
||||
|
||||
\includexopp{4.20.2}
|
||||
|
||||
$$
|
||||
Q_{1(n+1)}=Q_{1n} \overline{X+ \bar{Q_{0n}}}+\bar{Q_{1n}}Q_{0n}X
|
||||
$$
|
||||
$$
|
||||
Q_{0(n+1)}=Q_{0n} \overline{0}+\bar{Q_{0n}}X
|
||||
$$
|
||||
$$
|
||||
Y=Q_{1n} \bar{X}+\bar{Q_{0n}} X+Q_{1n} \bar{Q_{0n}}
|
||||
$$
|
||||
|
||||
$$
|
||||
J_1=Q_{0n}X
|
||||
$$
|
||||
$$
|
||||
K_1=X+\bar{Q_{0n}}
|
||||
$$
|
||||
$$
|
||||
J_0=X
|
||||
$$
|
||||
$$
|
||||
K_0=0
|
||||
$$
|
||||
|
||||
逻辑电路图如下:
|
||||
|
||||
\includexopp[1.5]{4.20.3}
|
||||
\end{zhongwen}
|
||||
\end{enumerate}
|
||||
\end{document}
|
57
数据结构/作业/10213903403第一章作业.tex
Normal file
57
数据结构/作业/10213903403第一章作业.tex
Normal file
@ -0,0 +1,57 @@
|
||||
\documentclass[实验报告模板]{subfiles}
|
||||
|
||||
% \clearpage
|
||||
% \fancyfoot[C]{第 \thepage 页\quad 共 \thetotalpages 页}
|
||||
\renewcommand{\mydate}{
|
||||
2023/09/22
|
||||
}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{实验目的}{
|
||||
\item 回顾之前学习过的语言语法(任何语言都可以),旨在解决数据结构实际问题。
|
||||
}
|
||||
\myitem{实验内容}{
|
||||
\item 输入 10 名学生的成绩,计算总分和平均分,输出平均分。
|
||||
\item 输入 10 个学生的成绩,输出高于平均分的学生成绩。
|
||||
}
|
||||
\myitem{实验原理}{
|
||||
\item 程序设计原理。
|
||||
}
|
||||
\myitem{实验步骤}{
|
||||
\item 问题抽象
|
||||
\item 编写程序
|
||||
\item 调试程序
|
||||
\item 完善总结
|
||||
}
|
||||
\myitem{调试过程、结果和分析}{
|
||||
\item JavaScript总体以异步执行为特点,因此不能简单地使用for循环来重复读取输入数据,需要在事件中调用函数来达到重复执行的目的;
|
||||
\item JavaScript不像Python有内置的sum函数,因此需要使用Array.reduce方法实现求和。
|
||||
}
|
||||
\myitem{总结}{
|
||||
\item 使用JavaScript实现,效果不错;
|
||||
\item 简单考虑,暂时不考虑输入错误的情况;
|
||||
\item 总体时间复杂度为O(n),空间复杂度为O(n);
|
||||
\item 对于第1题,只需要计算总分和平均分时,可以不使用数组,只使用一个变量记录总分,最后计算平均分,可以将空间复杂度降为O(1),而第2题可能无法降低空间复杂度了;
|
||||
\item 学生数10与主要功能解耦,便于更改学生数。
|
||||
}
|
||||
\myitem{附件}{
|
||||
\item 输入 10 名学生的成绩,计算总分和平均分,输出平均分。\\
|
||||
(JavaScript, Node.js环境)
|
||||
\inputminted[linenos=true,breaklines=true]{javascript}{../JavaScript/第一章作业1.1.js}
|
||||
% PDFLaTeX暂时无法导入文件名含有中文的代码文件
|
||||
% 使用XeLaTeX时:
|
||||
% (./latex-output/_minted-第一章作业/default.pygstyle)
|
||||
% runsystem(pygmentize -l "javascript" -f latex -P commandprefix=PYG -F tokenmerge -P stripnl="False" -o ./latex-output/_minted-第一章作业/EB9C1F6C899584BBD96A7EA2CCA6A26247E0DCB0F1FF070BB839FDEA77D6714A.pygtex ../JavaScript/第一章作业1.1.js)...executed.
|
||||
% 使用PDFLaTeX时:
|
||||
% (./latex-output/_minted-第一章作业/default.pygstyle)
|
||||
% runsystem(pygmentize -l "javascript" -f latex -P commandprefix=PYG -F tokenmerge -P stripnl="False" -o ./latex-output/_minted-第一章作业/CDD4D8FBCEF7B3B45864487BE6CE9E9E.pygtex ../JavaScript/\CTEX@char@nnn {231}{172}{172}\CTEX@char@nnn {228}{184}{128}\CTEX@char@nnn {231}{171}{160}\CTEX@char@nnn {228}{189}{156}\CTEX@char@nnn {228}{184}{154}1.1.js)...executed.
|
||||
\itemsep 3em
|
||||
\item 输入 10 个学生的成绩,输出高于平均分的学生成绩。\\
|
||||
(JavaScript, Node.js环境)
|
||||
\thetotalpages
|
||||
\inputminted[linenos=true,breaklines=true]{javascript}{../JavaScript/第一章作业1.2.js}
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
58
数据结构/作业/10213903403第七章作业.tex
Normal file
58
数据结构/作业/10213903403第七章作业.tex
Normal file
@ -0,0 +1,58 @@
|
||||
\documentclass[实验报告模板]{subfiles}
|
||||
|
||||
\renewcommand{\mydate}{
|
||||
2023/12/15
|
||||
}
|
||||
\renewcommand{\mychapternum}{7}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{实验目的}{
|
||||
\item 使用第七章的知识解决查找树的综
|
||||
合问题。
|
||||
}
|
||||
\myitem{实验内容}{
|
||||
\item 给出 N 个正整数作为二叉排序树的节点插入顺序.判断这串序列是否是
|
||||
该二叉树的先序序列或者是该二叉排序树的镜像树的先序序列.镜像树
|
||||
指的是交换根结点的左右子树形成的二叉树,如果对于输入的序列与二
|
||||
叉排序树的先序序列一致,则输出 Yes,并输出该二叉排序树的后序序
|
||||
列.若对于输入的序列与二叉排序树的镜像树的先序序列一致,则输出
|
||||
Yes,并输出该二叉排序树的后序序列.其余情况输出 No.
|
||||
|
||||
\item 根据二叉排序树的镜像树的后序遍历序列作为顺序,构造平衡二叉树。
|
||||
}
|
||||
\myitem{实验原理}{
|
||||
\item 程序设计原理。
|
||||
}
|
||||
\myitem{实验步骤}{
|
||||
\item 问题抽象
|
||||
\item 编写程序
|
||||
\item 调试程序
|
||||
\item 完善总结
|
||||
}
|
||||
\myitem{调试过程、结果和分析}{
|
||||
\item 树的结构确实不好调试,尤其是平衡二叉树,但好在可以进行中序遍历,正确的情况下中序遍历的结果应该是排好序的;
|
||||
\item 对于镜像树,可以修改比较操作的函数定义,就像C++内置的make\_heap一样,当然由于镜像树是对称的,可以直接在遍历时先遍历右子树,再遍历左子树,也能实现;
|
||||
\item 两道题的输入输出有关联性,第二题的输入是第一题的输出但又不完全是,第一题输出的是原二叉树的后序遍历结果,但第二题要使用第一题的镜像数的后序遍历结果,因此可以使用文件记录输出结果,第二题就可以进行输入重定向。
|
||||
}
|
||||
\myitem{总结}{
|
||||
\item 遵循指针应在初始化时分配资源,以及将资源交给变量作用域和变量生命周期自动管理,此次代码中将每个节点的左右指针都使用unique\_ptr定义,这样就不需要自己进行delete删除分配的资源了;
|
||||
\item 但是使用unique\_ptr要注意,此指针指向的对象不能再被其他对象指向,因此需要使用move进行转移资源的所有权,这在旋转子树时尤其明显;
|
||||
\item 借助std::function和匿名函数,我们可以很方便地实现简单的函数回调,尤其是涉及到类和对象的成员函数的时候;
|
||||
\item 类中的this是常量指针,是不能改变它所指向的地址的,即不能对*this赋值;
|
||||
\item C++中有类似Python的迭代器,也能用匿名函数实现类似JavaScript的回调;
|
||||
\item 但是C++中没法直接使用 this->left\_child \&\& this->left\_child->postorder\_traversal(output),因为逻辑与操作中的函数调用会返回void,而void无法转换为bool类型;
|
||||
\item C++中的模板自动类型推断,还有解包参数,和Python、JavaScript中有相似之处,但又不完全一样,仍需深入了解。
|
||||
}
|
||||
\myitem{附件}{
|
||||
\itemsep 5em
|
||||
\item 第七章作业1.cpp
|
||||
\inputminted[]{cpp}{../C++/第七章作业/第七章作业1.cpp}
|
||||
\item 第七章作业2.cpp
|
||||
\inputminted[]{cpp}{../C++/第七章作业/第七章作业2.cpp}
|
||||
\item CMakeLists.txt
|
||||
\inputminted[]{cmake}{../C++/第七章作业/CMakeLists.txt}
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
107
数据结构/作业/10213903403第三章作业.tex
Normal file
107
数据结构/作业/10213903403第三章作业.tex
Normal file
@ -0,0 +1,107 @@
|
||||
\documentclass[实验报告模板]{subfiles}
|
||||
|
||||
\renewcommand{\mydate}{
|
||||
2023/10/20
|
||||
}
|
||||
\renewcommand{\mychapternum}{3}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{实验目的}{
|
||||
\item 使用第三章知识解决链表队列问题。
|
||||
}
|
||||
\myitem{实验内容}{
|
||||
\item 使用链队列模拟银行窗口业务。假设每位客户有 2 项信息:序号、金
|
||||
额。早上开张后,按随机时间有客户上门办理业务,假设携带的现金是
|
||||
1-20 万之间的随机数。来一位客户,就将其加入队列,等待办理业务。
|
||||
假设办理业务所需要消耗的时间和金额成正比(可设置一个系数),位
|
||||
于队头的客户办理完业务后,就从队列中移走。请编写程序动态模拟这
|
||||
个过程。
|
||||
\item (选做)在第一题的基础上,如果银行有多个窗口。
|
||||
\begin{enumerate}
|
||||
\item 客户过来时挑队列最短的排队,后面不会换队列。
|
||||
\item 如果排队过程中,出现相邻队列比自己所排队列短,则可以重新
|
||||
选择队列。
|
||||
\end{enumerate}
|
||||
}
|
||||
\myitem{实验原理}{
|
||||
\item 程序设计原理。
|
||||
}
|
||||
\myitem{实验步骤}{
|
||||
\item 问题抽象
|
||||
\item 编写程序
|
||||
\item 调试程序
|
||||
\item 完善总结
|
||||
}
|
||||
\myitem{调试过程、结果和分析}{
|
||||
\item C++采用面向对象的方式设计复杂程序时,要处理非常多的类型,因此可能会比较复杂;
|
||||
\item 传参数有引用传递、指针传递、值传递;
|
||||
\item 类的模板是静态多态,类的继承是动态多态;
|
||||
\item 子类对父类函数的重写、重载、覆盖;
|
||||
\item 私有、保护、公共、友元的成员访问权限;
|
||||
\item 比起Python和JavaScript,C++的各种类型、各种限制、各种访问权限非常复杂,由于初次调试这种复杂的程序,出现各种错误时也需要查资料解决,导致花费大约三天时间才完成这次作业;
|
||||
\item 但也许这就是C++这种强类型语言的特点,编写代码时需要对类型进行非常确定的定义(模板可能是例外),但这也保证了运行效率和安全性;
|
||||
\item 此次作业没有尝试使用异步、多线程、多进程等并发执行方式来提升执行效率并改善图形(命令行)界面体验,之后可以尝试加入;
|
||||
\item 也是初次使用cmake进行程序的构建、测试、打包,cmake用来管理这种多文件的复杂程序时确实比较方便。
|
||||
}
|
||||
\myitem{总结}{
|
||||
\item 对于这种较为复杂的程序,首先考虑它的架构,由于此程序需要使用到链队列的模型,而且还需要进行图形化或命令行的展示,因此考虑采用MVC架构,但又由于程序功能较少,因此不想使用多线程或异步的事件循环,因此尝试是否能在单线程同步的架构下实现MVC架构;
|
||||
\item 事实证明是可以在单线程同步的架构下实现MVC架构的,但是可能一些细节会有所更改,例如:
|
||||
\begin{enumerate}
|
||||
\item MVC中的Controller接受用户事件并通知Model,这种行为在没有事件循环的情况下采用了View直接调用Model来实现;
|
||||
\item Model通知View进行修改的行为,改为View直接依赖Model,之后更改View的时候只需调用View::refresh的方法,View就会从自己已经绑定的Model中获取数据并进行刷新。
|
||||
\end{enumerate}
|
||||
但是这样造成了View依赖Model,Controller依赖View和Model,也许可能不太符合MVC。
|
||||
\item 之后就需要考虑如何拆分各个模块,这里采用了面向对象的思想:
|
||||
\begin{enumerate}
|
||||
\item Model: 链队列的实现、客户对象;
|
||||
\item View: 背景界面、排队的显示、客户的显示、走路过程中的客户的显示;
|
||||
\item Controller:实现主循环,单个Controller绑定Model和View,调度Model和View的更新;
|
||||
\item MVC: 调用主循环,综合多个Controller,统一调度所有Controller的更新,之后所有View一起更新;
|
||||
\item main: 实现根据用户输入进行调整调用参数,是入口文件。
|
||||
\end{enumerate}
|
||||
每个文件中也有类之间的继承关系:
|
||||
\begin{enumerate}
|
||||
\item SingleQueueModel继承了Model;
|
||||
\item SimpleQueueView继承了QueueView,QueueView继承了View;
|
||||
\item SingleQueueController继承了Controller,DriftingController也继承了Controller。
|
||||
\end{enumerate}
|
||||
\item 虽然采用面向对象,总体是成功实现了,但各个模块之间的职责划分仍不是特别清晰,并且产生了很多依赖关系,因此仍需改进。
|
||||
\item 由于时间有限,暂未实现相邻队列换位的模拟。
|
||||
}
|
||||
\item \textbf{附件}\\
|
||||
运行时截图:\\
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-10-29-10-52-02.png}
|
||||
\begin{enumerate}
|
||||
\item 单个队列\\
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-10-29-10-38-47.png}
|
||||
\item 多个队列\\
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-10-29-10-40-00.png}
|
||||
\item 自定义\\
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-10-29-10-53-57.png}\\
|
||||
\vspace{1em}\\
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-10-29-10-45-41.png}
|
||||
代码:\\
|
||||
\begin{enumerate}
|
||||
\itemsep 5em
|
||||
\item constants.h
|
||||
\inputminted[linenos=true,breaklines=true]{cpp}{../C++/第三章作业/include/constants.h}
|
||||
\item model.hpp
|
||||
\inputminted[linenos=true,breaklines=true]{cpp}{../C++/第三章作业/include/model.hpp}
|
||||
\item view.hpp
|
||||
\inputminted[linenos=true,breaklines=true]{cpp}{../C++/第三章作业/include/view.hpp}
|
||||
\item controller.hpp
|
||||
\inputminted[linenos=true,breaklines=true]{cpp}{../C++/第三章作业/include/controller.hpp}
|
||||
\item MVC.h
|
||||
\inputminted[linenos=true,breaklines=true]{cpp}{../C++/第三章作业/include/MVC.h}
|
||||
\item MVC.cpp
|
||||
\inputminted[linenos=true,breaklines=true]{cpp}{../C++/第三章作业/src/MVC.cpp}
|
||||
\item main.cpp
|
||||
\inputminted[linenos=true,breaklines=true]{cpp}{../C++/第三章作业/src/main.cpp}
|
||||
\item CMakeLists.txt
|
||||
\inputminted[linenos=true,breaklines=true]{cmake}{../C++/第三章作业/CMakeLists.txt}
|
||||
\end{enumerate}
|
||||
\end{enumerate}
|
||||
\end{enumerate}
|
||||
\end{document}
|
56
数据结构/作业/10213903403第二章作业.tex
Normal file
56
数据结构/作业/10213903403第二章作业.tex
Normal file
@ -0,0 +1,56 @@
|
||||
\documentclass[实验报告模板]{subfiles}
|
||||
|
||||
\renewcommand{\mydate}{
|
||||
2023/10/10
|
||||
}
|
||||
\renewcommand{\mychapternum}{2}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{实验目的}{
|
||||
\item 使用第二章知识解决约瑟夫环问题(复杂版)。
|
||||
}
|
||||
\myitem{实验内容}{
|
||||
\item 在原有约瑟夫环的基础上,输入参与这场游戏的人数 n 与自杀报数 m,
|
||||
输出为最后两个幸存者的位置序号。
|
||||
\item 在第一题的基础上,输入参与这场游戏的人数 n 与两个自杀报数 a 和
|
||||
b,按照一次 a 一次 b 的顺序自杀(a,b 可以为负数,正数代表正向,
|
||||
负数代表反向),输出为最后两个幸存者的位置序号。
|
||||
}
|
||||
\myitem{实验原理}{
|
||||
\item 程序设计原理。
|
||||
}
|
||||
\myitem{实验步骤}{
|
||||
\item 问题抽象
|
||||
\item 编写程序
|
||||
\item 调试程序
|
||||
\item 完善总结
|
||||
}
|
||||
\myitem{调试过程、结果和分析}{
|
||||
\item 简单考虑,暂时不考虑输入错误或者输入为0的情况;
|
||||
\item JavaScript没有指针的概念,所以使用对象的引用代替;
|
||||
\item JavaScript在严格模式下暂时无法直接删除对象,因此移除结点时无法完全销毁一个节点;
|
||||
\item 最后只留下两个,而不是$\min(\mathrm{abs}(a), \mathrm{abs}(b))-1$个;
|
||||
\item 删除的结点应该作为第0个,此时往前a个或往后b个,一开始如果a是正数那么应该按照$1, 2, 3, \ldots $的顺序遍历,如果a是负数那么应该按照$n, n-1, n-2, \ldots $的顺序遍历;
|
||||
\item 由于此问题中只涉及到初始化链表、删除单个结点两个操作,因此链表的添加结点、清空、销毁等操作暂不需要实现。
|
||||
}
|
||||
\myitem{总结}{
|
||||
\item 由于JavaScript的异步性质,需要进行连续多个输入时,可以将回调过程封装成Promise对象后,使用async创建异步函数,在其中使用await可以方便使用Promise对象,避免大量回调,同时也可以结合循环、分支等结构,实现更复杂的控制;
|
||||
\item 抽象出了结点对象和链表对象,并且实现了从当前节点开始寻找第n个结点(可以为负数)的方法;
|
||||
\item 整个文件中只有input和main\_函数与Node.js环境耦合,即使用了readline模块,而主要功能放在main函数中,因此在浏览器环境中可以直接调用main函数,方便代码复用。
|
||||
}
|
||||
\myitem{附件}{
|
||||
\itemsep 3em
|
||||
\item 在原有约瑟夫环的基础上,输入参与这场游戏的人数 n 与自杀报数 m,
|
||||
输出为最后两个幸存者的位置序号。\\
|
||||
(JavaScript,Node.js环境)
|
||||
\inputminted[linenos=true,breaklines=true]{javascript}{../JavaScript/第二章作业1.js}
|
||||
\item 在第一题的基础上,输入参与这场游戏的人数 n 与两个自杀报数 a 和
|
||||
b,按照一次 a 一次 b 的顺序自杀(a,b 可以为负数,正数代表正向,
|
||||
负数代表反向),输出为最后两个幸存者的位置序号。\\
|
||||
(JavaScript,Node.js环境)
|
||||
\inputminted[linenos=true,breaklines=true]{javascript}{../JavaScript/第二章作业2.js}
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
89
数据结构/作业/10213903403第五章作业.tex
Normal file
89
数据结构/作业/10213903403第五章作业.tex
Normal file
@ -0,0 +1,89 @@
|
||||
\documentclass[实验报告模板]{subfiles}
|
||||
|
||||
\renewcommand{\mydate}{
|
||||
2023/11/10
|
||||
}
|
||||
\renewcommand{\mychapternum}{5}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{实验目的}{
|
||||
\item 使用第五章的知识解决树的综合问
|
||||
题。
|
||||
}
|
||||
\myitem{实验内容}{
|
||||
\item 用顺序表或链表形式实现一棵树,树中节点存放 2 个内容:整数编号,
|
||||
和字符串的文本。每个节点的编号,是整棵树自上而下,自左而右依次
|
||||
编号的。构造这棵树的方式:一行代表 1 个节点对应的儿子节点,第 1
|
||||
个数据是编号,后续字符串以空白字符分隔,依次作为该节点的儿子,
|
||||
并自动编号。如果新录入的编号,在已有树中不存在,则发出错误提
|
||||
示;如果新录入节点后,对原有的编号有影响,则更新原有编号,使满
|
||||
足编号自上而下、自左而右依次编号的规则。假设树根为 0 号节点,一
|
||||
开始就存在。(注:允许在节点上,增加层次字段,比如,0 号节点的
|
||||
层次为 1;1 号节点“张三”的层次为 2)\\
|
||||
输入案例:\\
|
||||
0\ 张三\ 李四\ 王五\qquad
|
||||
:表示,3 个人都是 0 号节点的儿子\\
|
||||
2\ 师大\ 统计\ 计算机\qquad
|
||||
:表示,3 个院系是李四儿子\\
|
||||
0\ 赵六\qquad
|
||||
:表示,0 号节点下增加 1 个儿子,此时,
|
||||
2 号节点的儿子编号将需要更新
|
||||
\item 在第 1 题的基础上,将树转换成二叉树,遵循左孩子右兄弟的原则。
|
||||
}
|
||||
\myitem{实验原理}{
|
||||
\item 程序设计原理。
|
||||
}
|
||||
\myitem{实验步骤}{
|
||||
\item 问题抽象
|
||||
\item 编写程序
|
||||
\item 调试程序
|
||||
\item 完善总结
|
||||
}
|
||||
\myitem{调试过程、结果和分析}{
|
||||
\item VSCode调试很方便,但用了CLion后发现CLion调试的手感更好,仔细思考后发现可能原因之一是有时候CLion启动调试和重启调试更快,虽然可能只有一秒甚至不到一秒的时间,但在注意力高度集中找bug时不到一秒的间断也可能造成分心;
|
||||
\item 还有可能的原因是CLion的变量监视窗口可以步入步过时保持展开的层级;
|
||||
\item 而且CLion的自动补全更加完善,比如输入一个带参数的函数名会自动加好括号并将光标移动到括号内,输入一个无参数的函数名会自动加括号并将光标移动到括号右侧,删除左括号会自动删除相邻的右括号等等;
|
||||
}
|
||||
\myitem{总结}{
|
||||
\item 虽然C++的智能指针可以自动管理对象的生命周期,但也许在这种不需要长期维护,也不需要安全性的项目上使用原始指针更方便,只是要自己实现析构函数罢了;
|
||||
\item 为了简化代码便于从一个入口文件直接编译,直接使用了include cpp源文件的方法,可以从main.cpp入口直接编译;
|
||||
\item 将此题中的树转化成二叉树后,此题中的遍历方式不是先序中序后序层序中的任何一种,非常有创新点!
|
||||
\includegraphics[width=1em]{imgs/028E9BA6.pdf}
|
||||
受到广度优先搜索的启发,代码中采用了标准库中的队列实现,遍历每个节点时将它的左节点入队,每个节点出队时将它扩展到所有的右节点依次遍历;
|
||||
\item 虽然代码中也维护了线索化的标志域,不过好像没有用到线索化二叉树;
|
||||
\item 在命令行输出时要计算每个节点的宽度,防止子节点相互遮挡;
|
||||
\item 还能做的更好,但由于时间原因,就暂时这样了,以后可以完善一下,比如可以在命令行输出得更美观一些,使用多线程等。
|
||||
}
|
||||
\item \textbf{附件}
|
||||
|
||||
\textbf{说明:}
|
||||
\begin{enumerate}
|
||||
\item 由于多叉树实现的复杂度太高,此题直接使用二叉树完成。
|
||||
\item 为了便于阅读,使用CodeGeeX生成了部分代码的注释,注释不一定正确或有用,仅供参考。
|
||||
\end{enumerate}
|
||||
\textbf{运行时截图:}\\
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-11-12-21-09-15.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-11-12-21-09-45.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-11-12-21-10-00.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-11-12-21-10-48.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-11-12-21-11-06.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-11-12-21-11-36.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-11-12-21-11-50.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-11-12-21-12-13.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-11-12-21-12-26.png}
|
||||
\textbf{代码:}
|
||||
\begin{enumerate}
|
||||
\itemsep 5em
|
||||
\item bitree.cpp
|
||||
\inputminted[linenos=true, breaklines=true]{cpp}{../C++/第五章作业/bitree.cpp}
|
||||
\item view.cpp
|
||||
\inputminted[linenos=true, breaklines=true]{cpp}{../C++/第五章作业/view.cpp}
|
||||
\item main.cpp
|
||||
\inputminted[linenos=true, breaklines=true]{cpp}{../C++/第五章作业/main.cpp}
|
||||
\item CMakeLists.txt
|
||||
\inputminted[linenos=true, breaklines=true]{cmake}{../C++/第五章作业/CMakeLists.txt}
|
||||
\end{enumerate}
|
||||
\end{enumerate}
|
||||
\end{document}
|
63
数据结构/作业/10213903403第八章作业.tex
Normal file
63
数据结构/作业/10213903403第八章作业.tex
Normal file
@ -0,0 +1,63 @@
|
||||
\documentclass[实验报告模板]{subfiles}
|
||||
|
||||
\renewcommand{\mydate}{
|
||||
2023/12/29
|
||||
}
|
||||
\renewcommand{\mychapternum}{8}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{实验目的}{
|
||||
\item 使用第八章的知识解决排序的综合
|
||||
问题。
|
||||
}
|
||||
\myitem{实验内容}{
|
||||
\item 给定一个序列,使用快速排序将其从小到大进行排列。
|
||||
\item 给定一个序列,构造一个大根堆。
|
||||
}
|
||||
\myitem{实验原理}{
|
||||
\item 程序设计原理。
|
||||
}
|
||||
\myitem{实验步骤}{
|
||||
\item 问题抽象
|
||||
\item 编写程序
|
||||
\item 调试程序
|
||||
\item 完善总结
|
||||
}
|
||||
\myitem{调试过程、结果和分析}{
|
||||
\item 两道题分别对应了快速排序和堆排序。
|
||||
\item 快速排序要注意好起点和终点的位置选取,作为比较标准的元素放在最前面,开始位置为数组的开始,开始元素为这个元素后面的一个元素,结束元素为数组末尾的元素。需要维护两个指针,分别从开始往后移动和从末尾往前移动,用来标记下一个要交换的位置。最后这两个指针交汇时的位置就是比较标准的元素需要放置的位置了。
|
||||
\item 堆排序要注意不同的操作,构造堆时从最后一个非叶子节点开始往前逐个下沉,当然也可以看做向一个空的堆中不断插入来完成构造;插入操作是先插入到末尾然后上浮;弹出操作是将堆顶的元素弹出,之后把末尾的元素放到对顶再下沉。
|
||||
\item 下沉操作比上浮操作更复杂一点,因为要比较父节点和左右两个子节点,把最大的子节点换上了,而上浮操作只需要和父节点比较就行。
|
||||
\item 快速排序的
|
||||
输入:\\
|
||||
20\\
|
||||
41 40 19 8 5 5 17 32 39 32 98 95 68 56 60 59 67 94 77 98
|
||||
|
||||
输出:\\
|
||||
5 5 8 17 19 32 32 39 40 41 56 59 60 67 68 77 94 95 98 98
|
||||
|
||||
\item 大根堆的
|
||||
输入:\\
|
||||
20\\
|
||||
41 40 19 8 5 5 17 32 39 32 98 95 68 56 60 59 67 94 77 98
|
||||
|
||||
输出:\\
|
||||
逐个插入后,逐个弹出输出的结果为:\\
|
||||
98 98 95 94 77 68 67 60 59 56 41 40 39 32 32 19 17 8 5 5\\
|
||||
一次性初始化后,逐个弹出输出的结果为:\\
|
||||
98 98 95 94 77 68 67 60 59 56 41 40 39 32 32 19 17 8 5 5
|
||||
}
|
||||
\myitem{总结}{
|
||||
\item 在大根堆排序时,如果不使用弹出,而是每次把堆顶的元素和堆末尾的元素交换,之后将堆的长度减一,这样操作完成后就会形成升序排列。如果每次把堆顶的元素弹出,并且输出,这样操作完成后就会形成降序排列。这里使用的是弹出方式。
|
||||
}
|
||||
\myitem{附件}{
|
||||
\itemsep 5em
|
||||
\item 第八章作业1.cpp
|
||||
\inputminted[]{cpp}{../C++/第八章作业/第八章作业1.cpp}
|
||||
\item 第八章作业2.cpp
|
||||
\inputminted[]{cpp}{../C++/第八章作业/第八章作业2.cpp}
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
78
数据结构/作业/10213903403第六章作业.tex
Normal file
78
数据结构/作业/10213903403第六章作业.tex
Normal file
@ -0,0 +1,78 @@
|
||||
\documentclass[实验报告模板]{subfiles}
|
||||
|
||||
\renewcommand{\mydate}{
|
||||
2023/11/24
|
||||
}
|
||||
\renewcommand{\mychapternum}{6}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{实验目的}{
|
||||
\item 使用第六章的知识解决图的综合问
|
||||
题。
|
||||
}
|
||||
\myitem{实验内容}{
|
||||
\item 某国有 n 个城市,他们之间没有路连通,因此交通十分不便,现决定修
|
||||
建公路,任务由各个城市共同完成。修建分为 n 轮,在每一轮,每个城
|
||||
市选择一个与它最近的城市,申请修往该城市的公路,政府负责审批这
|
||||
些申请决定是否同意修建。
|
||||
|
||||
政府审批规则如下:
|
||||
|
||||
I.如果两个城市申请修建同一条公路,则让后申请修建的城市重新选择
|
||||
未申请修建的公路。
|
||||
|
||||
II.如果三个或以上城市申请修建的公路成环,即 A 申请修建 AB,B 申
|
||||
请修建 BC,C 申请修建 CA,则政府将否决其中最短的一条公路的修建申
|
||||
请。
|
||||
|
||||
III.其他情况一律同意。
|
||||
|
||||
一轮修建后,若干城市将会直接或间接相连,连通的城市被看作一个
|
||||
league,下一轮修建中,league 被看作为一个城市。当所有的城市都连
|
||||
通时,则修建完毕。根据上述规则计算需要修建的公路的总长度。
|
||||
|
||||
\item 每个城市的规模大小是不同的(在初始需要赋值),在每个城市申请修
|
||||
建通往其他城市的道路时,需要查看城市规模系数$\alpha $,若规模小于目标
|
||||
城市,则政府拒绝修建,若两个城市规模相等,则修建过后两座城市形
|
||||
成的 league 城市规模系数$\alpha $增一,若大于目标城市,则同意修建,规
|
||||
模系数不变。当城市规模系数$\alpha $到达限定系数$\beta $后,我们认为该 league
|
||||
已经到达“稳定”,不再与任何其他城市修建公路。根据上述规则计算
|
||||
需要修建的公路的总长度。
|
||||
}
|
||||
\myitem{实验原理}{
|
||||
\item 程序设计原理。
|
||||
}
|
||||
\myitem{实验步骤}{
|
||||
\item 问题抽象
|
||||
\item 编写程序
|
||||
\item 调试程序
|
||||
\item 完善总结
|
||||
}
|
||||
\myitem{调试过程、结果和分析}{
|
||||
\item 子类继承父类的时候应该不需要手动调用父类的析构函数,因为编译器会自动调用;
|
||||
\item 调试带有随机性质的程序要先把随机数种子固定下来,调试完再用时间戳作为随机种子;
|
||||
\item 类的保护属性在类外能直接访问?
|
||||
}
|
||||
\myitem{总结}{
|
||||
\item 采用何种设计架构要综合考虑项目周期、系统复杂度、掌握熟练度等一系列因素,比如虽然这次的题可能有在时间复杂度或空间复杂度上更优的算法来解决,但是考虑到时间有限,还是使用了比较容易实现的思路;
|
||||
\item CLion的自动补全确实更加顺手,而且还能自动生成构造函数、析构函数等;
|
||||
\item 此次也没有进行非常复杂的对象设计,只实现了并查集的类、图的类、复杂图的类;
|
||||
\item 由于需要多次合并城市为一个联盟,所以使用了并查集;
|
||||
\item 做题之前可以先考虑是否可以简化问题,比如这次的题的第二条规则就是无效的;
|
||||
\item 输出的方式不一定要像图形界面,可以用文字表示,比如图可以用邻接矩阵、关系矩阵表示。
|
||||
}
|
||||
\myitem{附件}{
|
||||
\itemsep 5em
|
||||
\item graph.cpp
|
||||
\inputminted[linenos=true, breaklines=true]{cpp}{../C++/第六章作业/graph.hpp}
|
||||
\item 第六章作业1.cpp
|
||||
\inputminted[linenos=true, breaklines=true]{cpp}{../C++/第六章作业/第六章作业1.cpp}
|
||||
\item 第六章作业2.cpp
|
||||
\inputminted[linenos=true, breaklines=true]{cpp}{../C++/第六章作业/第六章作业2.cpp}
|
||||
\item CMakeLists.txt
|
||||
\inputminted[linenos=true, breaklines=true]{cmake}{../C++/第六章作业/CMakeLists.txt}
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
65
数据结构/作业/10213903403第四章作业.tex
Normal file
65
数据结构/作业/10213903403第四章作业.tex
Normal file
@ -0,0 +1,65 @@
|
||||
\documentclass[实验报告模板]{subfiles}
|
||||
|
||||
\renewcommand{\mydate}{
|
||||
2023/10/27
|
||||
}
|
||||
\renewcommand{\mychapternum}{4}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{实验目的}{
|
||||
\item 使用第四章知识解决数组和字符串
|
||||
的问题。
|
||||
}
|
||||
\myitem{实验内容}{
|
||||
\item 给你一个 m 行 n 列的矩阵 matrix,请按照顺时针螺旋顺序,返回矩
|
||||
阵中的所有元素。
|
||||
\item 给定一个字符串,输出所有长度至少为 2 的回文子串。回文子串即从左
|
||||
往右输出和从右往左输出结果是一样的字符串,比如:abba,
|
||||
cccdeedccc 都是回文字符串。
|
||||
}
|
||||
\myitem{实验原理}{
|
||||
\item 程序设计原理。
|
||||
}
|
||||
\myitem{实验步骤}{
|
||||
\item 问题抽象
|
||||
\item 编写程序
|
||||
\item 调试程序
|
||||
\item 完善总结
|
||||
}
|
||||
\myitem{调试过程、结果和分析}{
|
||||
\item Python的切片取反时要注意stop的参数可能会小于0,就变成负向索引了。例如正向切片时使用a[i:j + 1]可以取出[i,j + 1)区间,即[i,j]闭区间内的元素,但要是反向切片的话,因为切片的区间包含start但不包含stop,所以应该为(i - 1, j],也就是start为j,stop为i - 1,即a[j:i - 1:-1],但是如果i = 0的时候,正向切片是取出[0, j + 1)区间内的元素,但反向取就变成了(-1, j],而-1在切片中是负向索引,而每个元素的位置肯定小于等于最后一个元素所在的位置,因此不管j怎么取,最终的结果都是空的序列。因此最终的代码采用了先赋值再切片防止出现这样的情况。
|
||||
}
|
||||
\item \textbf{总结}
|
||||
\begin{enumerate}
|
||||
\itemsep 1.6em
|
||||
\item 在不考虑复杂度的情况下,Python实现功能真的特别方便;
|
||||
\item Python的and和or有短路规则,即:and连接的前后两个操作数,如果前一个操作数的逻辑取值为假,则会直接返回前一个操作数(注意是返回原操作数而不是False也不是0,这和C/C++中不一样);如果前一个操作数的逻辑取值为真,则会返回后一个操作数(注意也是返回原操作数)。同理,or连接的前后两个操作,如果前一个操作数的逻辑取值为真,则会返回前一个操作数;如果前一个操作数的逻辑取值为假,则会返回后一个操作数;
|
||||
\item 空列表、空字典、空元组、空集合、空字符串、0的逻辑取值为假;
|
||||
\item 列表可以直接使用加号拼接;
|
||||
\item 单个星号“*”表示按位置参数解包操作符,即把星号后面的操作数按顺序依次取出作为位置参数;
|
||||
\item zip函数的功能是依次把传递给它的每个位置参数同时取出一个元素并进行组合,(不好描述,建议看官方文档)可以理解为矩阵转置,以下是官方文档中的解释:\\
|
||||
\url{https://docs.python.org/zh-cn/3/library/functions.html#zip}
|
||||
\item 如果将二维列表看成是矩阵的话,zip函数和*操作符一起使用是真正的矩阵转置,之后[::-1]这样的切片操作表示将外层列表反向,一个二维矩阵转置再反向后就相当于这个二维矩阵逆时针旋转了90度;
|
||||
\item matrix[0]表示这个矩阵的第一行,matrix[1:]表示这个矩阵去掉第一行后的部分,所以将矩阵去掉第一行的部分逆时针旋转90度,再去掉第一行,再逆时针旋转90度,不断重复这样的操作就可以顺时针遍历矩阵中的元素;
|
||||
\item \_\_import\_\_可以导入模块并返回模块,sys.stdin是标准输入,sys.stdin.readlines()是读取标准输入并按行存储,之后使用列表解析式,对每一行line.split()表示按空白字符分割,之后返回的就是一个二维列表;
|
||||
\item “:=”是赋值表达式,会将表达式右端赋值给左端并返回表达式右端的值,相当于C/C++中的“=”;
|
||||
\item f"..."是格式化字符串字面值,参考官方文档:\\
|
||||
\url{https://docs.python.org/zh-cn/3/reference/lexical_analysis.html#formatted-string-literals}
|
||||
\item “\_”存储最后一次求值的结果,也可以用来命名无需使用的变量,参考官方文档:\\
|
||||
\url{https://docs.python.org/zh-cn/3/reference/lexical_analysis.html#reserved-classes-of-identifiers}\\
|
||||
这里使用是为了防止在Jupyter等交互式解释器中运行此段代码时Jupyter自动返回最后一次求值的结果。
|
||||
\end{enumerate}
|
||||
\myitem{附件}{
|
||||
\itemsep 5em
|
||||
\item 给你一个 m 行 n 列的矩阵 matrix,请按照顺时针螺旋顺序,返回矩
|
||||
阵中的所有元素。
|
||||
\inputminted[linenos=true, breaklines=true]{python3}{../Python/第四章作业4.1.py}
|
||||
\item 给定一个字符串,输出所有长度至少为 2 的回文子串。回文子串即从左
|
||||
往右输出和从右往左输出结果是一样的字符串,比如:abba,
|
||||
cccdeedccc 都是回文字符串。
|
||||
\inputminted[linenos=true, breaklines=true]{python3}{../Python/第四章作业4.2.py}
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
75
数据结构/作业/mypreamble.tex
Normal file
75
数据结构/作业/mypreamble.tex
Normal file
@ -0,0 +1,75 @@
|
||||
\usepackage[margin=1in]{geometry}
|
||||
\usepackage{longtable}
|
||||
\usepackage{booktabs}
|
||||
\usepackage{array}
|
||||
\usepackage{zhnumber} % change section number to chinese
|
||||
% \usepackage{enumerate}
|
||||
\usepackage{enumitem}
|
||||
\usepackage{titlesec}
|
||||
\usepackage{fancyhdr}
|
||||
\usepackage{graphicx}
|
||||
\usepackage{environ} % 加了这个再\def\myitem就不报错了
|
||||
\usepackage{hyperref}
|
||||
\usepackage{mylatex}
|
||||
% \usepackage{url}
|
||||
% \PassOptionsToPackage{hyphens}{url}
|
||||
% \usepackage{breakurl} // 这个包总是会报错,可能是和别的什么包冲突了,所以只能用传统的一大段文字的办法实现网址换行
|
||||
\usepackage[outputdir=./latex-output]{minted}
|
||||
\usepackage{subfiles}
|
||||
\usepackage{totpages} % 不加这个会导致总页数出错
|
||||
% \usepackage{pgfplots}
|
||||
% \pgfmathsetmacro{\totalpages}{\totalpages+1}
|
||||
% \setcounter{totalpages}{1}
|
||||
\pagestyle{fancyplain}
|
||||
\fancyhead{}
|
||||
\fancyhead[C]{华东师范大学计算机科学与技术学院上机实践报告}
|
||||
\fancyfoot[C]{第 \thepage 页\quad 共 \ref{TotPages} 页}
|
||||
\renewcommand\thesection{\zhnum{section}}
|
||||
\renewcommand \thesubsection {\arabic{subsection}}
|
||||
\setlist[1]{label=\zhnum{enumi}、}
|
||||
\setlist[2]{labelindent=-1em, leftmargin=*, label=\arabic{enumii}.\quad}
|
||||
\setlist[3]{labelindent=1em, leftmargin=*, label=(\arabic{enumiii})}
|
||||
\setminted{linenos=true, breaklines=true}
|
||||
|
||||
\newcommand{\mydate}{
|
||||
2023/09/23
|
||||
}
|
||||
|
||||
\newcommand{\mychapternum}{
|
||||
1
|
||||
}
|
||||
|
||||
\newcommand{\mytitle}{
|
||||
\title{\fontsize{15}{0}华东师范大学计算机科学与技术学院上机实践报告\vspace{-2em}}
|
||||
\date{}
|
||||
\maketitle
|
||||
|
||||
\begin{longtable}[]{lll}
|
||||
\toprule\noalign{}
|
||||
\endhead
|
||||
\bottomrule\noalign{}
|
||||
\endlastfoot
|
||||
\textbf{课程名称}:数据结构 & \textbf{年级}:2022级 &
|
||||
\textbf{上机实践成绩}: \\
|
||||
\textbf{指导教师}:金健 & \textbf{姓名}:岳锦鹏 &
|
||||
\textbf{上机实践时间}:2学时 \\
|
||||
\textbf{上机实践名称}:第\zhnumber{\mychapternum}章作业 & \textbf{学号}:10213903403 &
|
||||
\textbf{上机实践日期}:\mydate \\
|
||||
\end{longtable}
|
||||
}
|
||||
|
||||
% \def\myitem#1#2{
|
||||
% \item \textbf{#1}
|
||||
% \begin{enumerate}
|
||||
% #2
|
||||
% \end{enumerate}
|
||||
% }
|
||||
|
||||
% https://blog.csdn.net/u010801696/article/details/79477226
|
||||
\def\UrlBreaks{\do\A\do\B\do\C\do\D\do\E\do\F\do\G\do\H\do\I\do\J
|
||||
\do\K\do\L\do\M\do\N\do\O\do\P\do\Q\do\R\do\S\do\T\do\U\do\V
|
||||
\do\W\do\X\do\Y\do\Z\do\[\do\\\do\]\do\^\do\_\do\`\do\a\do\b
|
||||
\do\c\do\d\do\e\do\f\do\g\do\h\do\i\do\j\do\k\do\l\do\m\do\n
|
||||
\do\o\do\p\do\q\do\r\do\s\do\t\do\u\do\v\do\w\do\x\do\y\do\z
|
||||
\do\.\do\@\do\\\do\/\do\!\do\_\do\|\do\;\do\>\do\]\do\)\do\,
|
||||
\do\?\do\'\do+\do\=\do\#}
|
14
数据结构/作业/使用示例.tex
Normal file
14
数据结构/作业/使用示例.tex
Normal file
@ -0,0 +1,14 @@
|
||||
\documentclass[实验报告模板]{subfiles}
|
||||
|
||||
\renewcommand{\mydate}{
|
||||
2023/09/25
|
||||
}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{列表标题}{
|
||||
\item 列表内容
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
87
数据结构/作业/实验报告模板.tex
Normal file
87
数据结构/作业/实验报告模板.tex
Normal file
@ -0,0 +1,87 @@
|
||||
\documentclass[a4paper]{ctexart}
|
||||
\input{mypreamble}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\title{\fontsize{15}{0}华东师范大学计算机科学与技术学院上机实践报告\vspace{-2em}}
|
||||
\date{}
|
||||
\maketitle
|
||||
|
||||
\begin{longtable}[]{lll}
|
||||
\toprule\noalign{}
|
||||
\endhead
|
||||
\bottomrule\noalign{}
|
||||
\endlastfoot
|
||||
\textbf{课程名称}:数据结构 & \textbf{年级}:2022级 &
|
||||
\textbf{上机实践成绩}: \\
|
||||
\textbf{指导教师}:金健 & \textbf{姓名}:金小健 &
|
||||
\textbf{上机实践时间}:2学时 \\
|
||||
\textbf{上机实践名称}:第一章作业 & \textbf{学号}:xxxxxxxxxx &
|
||||
\textbf{上机实践日期}:2023/09/23 \\
|
||||
\end{longtable}
|
||||
|
||||
\begin{enumerate}
|
||||
\item \textbf{实验目的}
|
||||
|
||||
\begin{enumerate}
|
||||
\item
|
||||
从第1条起填写基本目的。
|
||||
\end{enumerate}
|
||||
\item \textbf{实验内容}
|
||||
|
||||
\begin{enumerate}
|
||||
\item
|
||||
结合实验目的填写。
|
||||
\item
|
||||
在预习时,对程序或过程中出现的问题,都写在这里,以便真正上机实践时有针对性的查找答案,并填充相应的实验步骤、过程、结果和分析,以及总结。
|
||||
\end{enumerate}
|
||||
\item \textbf{实验原理}
|
||||
|
||||
\begin{enumerate}
|
||||
\item
|
||||
参考实验教材
|
||||
\end{enumerate}
|
||||
\item \textbf{实验步骤}
|
||||
|
||||
\begin{enumerate}
|
||||
\item
|
||||
参考实验教材
|
||||
\end{enumerate}
|
||||
\item \textbf{调试}\textbf{过程、结果和分析}
|
||||
|
||||
\begin{enumerate}
|
||||
\item
|
||||
参考教材,结合自己实际,对调试过程进行记录和分析。
|
||||
\end{enumerate}
|
||||
\item \textbf{总结}
|
||||
|
||||
\begin{enumerate}
|
||||
\item
|
||||
预习时提出的问题有没有解决,实验目的有没有达到
|
||||
\item
|
||||
如果实现了,作一下评价
|
||||
\item
|
||||
如果未实现,总结一下原因(并不一定每次都必定要完全实现预定目标的,只要原因分析得恰当,同样是好的)
|
||||
\item
|
||||
有没有新的疑问或想法
|
||||
\end{enumerate}
|
||||
\item \textbf{附件}
|
||||
|
||||
\begin{enumerate}
|
||||
\item
|
||||
程序代码。
|
||||
\end{enumerate}
|
||||
\end{enumerate}
|
||||
|
||||
|
||||
\noindent \textbf{说明:}
|
||||
|
||||
文件命名格式:学号+第一章作业.doc
|
||||
|
||||
\noindent 例如:
|
||||
|
||||
52051201004第一章作业.doc
|
||||
|
||||
52051201004第二章作业.doc
|
||||
|
||||
\end{document}
|
53
数理统计/作业/mypreamble.tex
Normal file
53
数理统计/作业/mypreamble.tex
Normal file
@ -0,0 +1,53 @@
|
||||
\usepackage{fancyhdr}
|
||||
\usepackage{enumitem}
|
||||
\usepackage{titlesec}
|
||||
\usepackage{amssymb, amsfonts, amstext, amsmath, amsopn, amsthm}
|
||||
\usepackage{booktabs}
|
||||
\usepackage{bm}
|
||||
\usepackage{pgfplots}
|
||||
\usepackage{hyperref}
|
||||
|
||||
\usepackage{totpages}
|
||||
\usepackage{mylatex}
|
||||
\usepackage{subfiles}
|
||||
|
||||
\fancyfoot[C]{第 \thepage 页\quad 共 \ref{TotPages} 页}
|
||||
\renewcommand\thesection{\thechapter.\arabic{section}}
|
||||
\renewcommand \thesubsection {\arabic{subsection}}
|
||||
\renewcommand{\labelenumii}{(\arabic{enumii})}
|
||||
\title{《数理统计》作业}
|
||||
\author{岳锦鹏}
|
||||
\newcommand{\mysignature}{10213903403 岳锦鹏}
|
||||
\date{2024年2月27日——2024年6月18日}
|
||||
\setlist[1]{listparindent=\parindent}
|
||||
\setlist[2]{listparindent=\parindent}
|
||||
|
||||
\definecolor{shadecolor}{RGB}{204,232,207}
|
||||
|
||||
\def\myitem#1#2{
|
||||
\item \text{#1}
|
||||
\begin{enumerate}
|
||||
#2
|
||||
\end{enumerate}
|
||||
}
|
||||
|
||||
\makeatletter
|
||||
\newcommand*\xwidehat[2][0.75]{%
|
||||
\sbox{\myboxA}{$\m@th#2$}%
|
||||
\setbox\myboxB\null% Phantom box
|
||||
\ht\myboxB=\ht\myboxA%
|
||||
\dp\myboxB=\dp\myboxA%
|
||||
\wd\myboxB=#1\wd\myboxA% Scale phantom
|
||||
\sbox\myboxB{$\m@th\,\widehat{\copy\myboxB}\,$}% Overlined phantom
|
||||
\setlength\mylenA{\the\wd\myboxA}% calc width diff
|
||||
\addtolength\mylenA{-\the\wd\myboxB}%
|
||||
\ifdim\wd\myboxB<\wd\myboxA%
|
||||
\rlap{\hskip 0.5\mylenA\usebox\myboxB}{\usebox\myboxA}%
|
||||
\else
|
||||
\hskip -0.5\mylenA\rlap{\usebox\myboxA}{\hskip 0.5\mylenA\usebox\myboxB}%
|
||||
\fi}
|
||||
\makeatother
|
||||
|
||||
\let\kaishu\relax % 清除旧定义
|
||||
\newCJKfontfamily\kaishu{KaiTi}[AutoFakeBold] % 重定义 \kaishu
|
||||
\newcommand{\boldkai}[1]{{\bfseries\kaishu #1}}
|
6
数理统计/作业/mysubpreamble.tex
Normal file
6
数理统计/作业/mysubpreamble.tex
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
\pagestyle{fancyplain}
|
||||
\fancyhead{}
|
||||
\fancyhead[C]{\mysignature}
|
||||
\fancyfoot[C]{第 \thepage 页\quad 共 \ref{TotPages} 页}
|
||||
\definecolor{shadecolor}{named}{white}
|
22
数理统计/作业/全部作业.tex
Normal file
22
数理统计/作业/全部作业.tex
Normal file
@ -0,0 +1,22 @@
|
||||
\documentclass[a4paper]{ctexbook}
|
||||
\input{mypreamble}
|
||||
\begin{document}
|
||||
\maketitle
|
||||
\tableofcontents
|
||||
\setcounter{chapter}{4}
|
||||
\chapter{统计量及其分布}
|
||||
\subfile{第一周作业}
|
||||
\subfile{第二周作业}
|
||||
\subfile{第三周作业}
|
||||
\subfile{第四周作业}
|
||||
\chapter{参数估计}
|
||||
\subfile{第五周作业}
|
||||
\subfile{第六周作业}
|
||||
\subfile{第七周作业}
|
||||
\subfile{第九周作业}
|
||||
\subfile{第十二周作业}
|
||||
\chapter{假设检验}
|
||||
\subfile{第十三周作业}
|
||||
\subfile{第十四周作业}
|
||||
\subfile{第十五周作业}
|
||||
\end{document}
|
264
数理统计/作业/期中考试.tex
Normal file
264
数理统计/作业/期中考试.tex
Normal file
@ -0,0 +1,264 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
\input{mysubpreamble}
|
||||
\begin{document}
|
||||
\renewcommand{\labelenumii}{(\alph{enumii})}
|
||||
\setcounter{chapter}{6}
|
||||
\setcounter{section}{5}
|
||||
\section*{期中考试}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[]{
|
||||
(10') 设$X_1, \cdots ,X_n (n>6)$是来自指数分布$p(x,\lambda)=\lambda e^{-\lambda x} I(x\geqslant 0)$的样本,其中$\lambda>0$。用$X_{(i)}$表示样本的第$i$个次序统计量。求解:
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswerSolution[]{
|
||||
$\lambda$的充分统计量$T$;
|
||||
}{
|
||||
样本联合密度为
|
||||
$$
|
||||
p(x_1,x_2, \cdots ;\lambda)=\lambda^{n} e^{-n \bar{x} \lambda} I(x_{(1)}\geqslant 0)
|
||||
$$
|
||||
由由因子分解定理知,$T=\bar{x}$为$\lambda$的充分统计量。
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
$\operatorname{Cov}(X_{(3)}, X_{(6)})$。
|
||||
}{
|
||||
设$Y=\lambda X$,则$Y_1,Y_2, \cdots ,Y_n$为来自$\operatorname{Exp}(1)$的样本,所以$\operatorname{Cov}(X_{(3)},X_{(6)})=\frac{1}{\lambda^{2}}\operatorname{Cov}(Y_{(3)},Y_{(6)})$,下面只需求三个量:$E(Y_{(3)}Y_{(6)}),\ E(Y_{(3)}),\ E(Y_{(6)})$。
|
||||
$$
|
||||
\begin{aligned}
|
||||
\because p_{3}(u)&=\frac{n!}{2!(n-3)!} F^{2}(u) [1-F(u)]^{n-3} p(u) \\
|
||||
&=\frac{n!}{2!(n-3)!} (1-e^{-u})^{2} e^{-(n-2)u} I(u\geqslant 0) \\
|
||||
\therefore E(Y_{(3)}) &= \int_{0}^{+\infty} u p_3(u) \mathrm{d}u=\int_{0}^{+\infty} \frac{n!}{2!(n-3)!} u(1-e^{-u})^{2} e^{-(n-2)u} \mathrm{d}u \\
|
||||
&= \frac{n^{4} -3n^{2}+6n -2}{n(n-1)(n-2)} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
同理算出$E(Y_{(6)})$与$E(Y_{(3)}Y_{(6)})$后可计算出
|
||||
$$
|
||||
\operatorname{Cov}(X_{(3)},X_{(6)})=\frac{1}{\lambda^{2}} \operatorname{Cov}(Y_{(3)},Y_{6})=\frac{1}{\lambda^{2}}\left[ E(Y_{(3)}Y_{(6)}) - E(Y_{(3)})E(Y_{(6)}) \right]
|
||||
$$
|
||||
}
|
||||
\end{enumerate}
|
||||
\questionandanswer[]{
|
||||
(15') 设$X_i, \ i=1,2,3$独立且都分别服从$N(i, i^{2})$,利用$X_i$构造下面分布的统计量:
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[]{
|
||||
自由度为3的$\chi^{2}$分布;
|
||||
}{
|
||||
$$
|
||||
\left( \frac{X_1-1}{1} \right) ^{2}+\left( \frac{X_2-2}{2} \right) ^{2}+\left( \frac{X_3-3}{3} \right) ^{2} = \chi^{2}(3)
|
||||
$$
|
||||
}
|
||||
\questionandanswer[]{
|
||||
自由度为2的$t$分布;
|
||||
}{
|
||||
$$
|
||||
\frac{(X_1-1)\sqrt{2}}{\sqrt{\left( \frac{X_2-2}{2} \right) ^{2}+\left( \frac{X_3-3}{3} \right) ^{2}}} \sim t(2)
|
||||
$$
|
||||
}
|
||||
\questionandanswer[]{
|
||||
自由度为1, 2的$F$分布。
|
||||
}{
|
||||
$$
|
||||
\frac{\left( \frac{X_1-1}{1} \right) ^{2}}{\left( \frac{X_2-2}{2} \right) ^{2}+\left( \frac{X_3-3}{3} \right) ^{2}} \sim F(1,2)
|
||||
$$
|
||||
}
|
||||
\end{enumerate}
|
||||
\questionandanswer[3]{
|
||||
(10') 设$X_1, \cdots ,X_n$是来自均值为$\mu$,方差为$\sigma^{2}$的总体的简单样本。
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswerProof[]{
|
||||
证明:如果$\sum_{i=1}^{n} a_i=1$,则估计量$\sum_{i=1}^{n} a_i X_i$是$\mu$的一个无偏估计量;
|
||||
}{
|
||||
$$
|
||||
E\left( \sum_{i=1}^{n} a_i X_i \right) =\sum_{i=1}^{n} a_i (EX_{i})=\left( \sum_{i=1}^{n} a_i \right) \mu = 1 \cdot \mu = \mu
|
||||
$$
|
||||
所以估计量$\sum_{i=1}^{n} a_i X_i$是$\mu$的一个无偏估计量。
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
在所有这类形式的估计量中求一个最小方差者,并计算其方差。
|
||||
}{
|
||||
$$
|
||||
\operatorname{Var}\left( \sum_{i=1}^{n} a_i X_i \right) =\left( \sum_{i=1}^{n} a_i^{2} \right) \sigma^{2} = \left( \sum_{i=1}^{n} a_i^{2} \cdot \sum_{i=1}^{n} 1^{2} \right) \sigma^{2} \frac{1}{n} \geqslant \left( \sum_{i=1}^{n} a_i \right) ^{2} \sigma^{2}
|
||||
$$
|
||||
所以当$\sum_{i=1}^{n} a_i=1$时方差最小,为$\sigma^{2}$。
|
||||
}
|
||||
\end{enumerate}
|
||||
\questionandanswer[4]{
|
||||
(15') 设简单样本$X_1, \cdots ,X_n \sim F$。对给定常数$x_0$,令$F_n(x_0)=\frac{1}{n} \sum_{i=1}^{n} I(X_i \leqslant x_0)$。回答以下问题:
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswerProof[]{
|
||||
证明$F_n(x_0)$是$F(x_0)$的无偏估计;
|
||||
}{
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\because \sum_{i=1}^{n} I(x_i \leqslant x_0)\text{为} n \text{重伯努利的独立和形式} \\
|
||||
&\therefore E\left( \sum_{i=1}^{n} I(x_i \leqslant x_0) \right) =n E(I (x_1\leqslant x_0)) = nF(x_0) \\
|
||||
\end{aligned}
|
||||
$$
|
||||
}
|
||||
\questionandanswerProof[]{
|
||||
证明$F_n(x_0)$是$F(x_0)$的相合估计;
|
||||
}{
|
||||
由于$E(F_n(x_0))=F(x_0)$, $\operatorname{Var}(F_n(x_0))=\frac{1}{n} F_n(x_0) (1\cdot F(x_0)) \to 0$ $(n \to \infty)$,因此$F_n(x_0)$是$F(x_0)$的相合估计。
|
||||
}
|
||||
\questionandanswerProof[]{
|
||||
证明$F_n(x_0)$的渐近正态性。
|
||||
}{
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\because F_n(x_0) \text{为独立和} \\
|
||||
&\therefore \text{由中心极限定理知} \sqrt{n} (F_n(x_0)-F(x_0)) \xrightarrow{L} N(0, F(x_0) (1-F(x_0))) \\
|
||||
\end{aligned}
|
||||
$$
|
||||
}
|
||||
\end{enumerate}
|
||||
\questionandanswer[5]{
|
||||
(15') 设随机变量$Y_1, \cdots ,Y_n$满足
|
||||
$$
|
||||
Y_i = x_i \beta + \varepsilon_i, \ i=1, \cdots ,n,
|
||||
$$
|
||||
其中$x_1, \cdots ,x_n$是固定常数,$\varepsilon_1, \cdots , \varepsilon_n$独立同分布于$N(0, \sigma^{2})$,其中$\sigma^{2}$未知。回答以下问题:
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswerSolution[]{
|
||||
求关于$(\beta,\sigma^{2})$的一个2维充分统计量。
|
||||
}{
|
||||
由于$Y_1,Y_2, \cdots ,Y_n$的联合密度函数为$Y_1 \sim N(x_i\beta, \alpha^{2})$,
|
||||
$$
|
||||
\begin{aligned}
|
||||
&L= \prod_{i=1}^{n} \frac{1}{\sqrt{2\pi} \sigma} e^{-\frac{1}{2\sigma^{2}}(Y_i-x_i \beta)^{2}} \\
|
||||
&=\left( \frac{1}{\sqrt{2\pi} \sigma} \right) ^{n} \exp \left\{ -\frac{1}{2\sigma^{2}} \sum_{i=1}^{n} (Y_i-x_i\beta)^{2} \right\} \\
|
||||
&=\left( \frac{1}{\sqrt{2\pi} \sigma} \right) ^{n} \cdot e^{-\frac{1}{2\sigma^{2}} \sum_{i=1}^{n} Y_i^{2}} \cdot e^{\frac{1}{2\sigma^{2}} \sum_{i=1}^{n} 2 x_i Y_i \beta} e^{-\frac{1}{2\sigma^{2}} \sum_{i=1}^{n} x_i^{2} \beta^{2}} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
设$T_1=\sum_{i=1}^{n} Y_i^{2}$, $T_2=\sum_{i=1}^{n} x_i Y_i$,有因子分解定理知$(T_1, T_2)$为$(\beta, \alpha^{2})$的二维充分统计量。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
求$\beta$的MLE并证明它是$\beta$的一个无偏估计;
|
||||
}{
|
||||
令$\frac{\mathrm{d}L}{\mathrm{d}\beta}=0$,得$-\frac{1}{\sigma^{2}} \sum_{i=1}^{n} (Y_i - x_i \beta) x_i = 0 \implies \hat{\beta}_{ML}=\frac{\sum_{i=1}^{n} Y_i x_i}{\sum_{i=1}^{x} x_i^{2}}=\frac{\overline{Y x}}{ \overline{x ^{2}}}$。
|
||||
|
||||
$$
|
||||
\begin{aligned}
|
||||
E\left( \hat{\beta}_{ML} \right) &=E\left( \frac{1}{\sum_{i=1}^{n} x_i^{2}} \sum_{i=1}^{n} x_i Y_i \right) =\frac{1}{\sum_{i=1}^{n} x_i^{2}} \sum_{i=1}^{n} E(x_i Y_i) = \frac{1}{\sum_{i=1}^{n} x_i^{2}} \sum_{i=1}^{n} x_i (EY_{i}) \\
|
||||
&=\frac{1}{\sum_{i=1}^{n} x_i^{2}} \sum_{i=1}^{n} x_i(x_i \beta) = \beta \\
|
||||
\end{aligned}
|
||||
$$
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
求$\beta$的MLE的分布。
|
||||
}{
|
||||
$$
|
||||
\hat{\beta}_{ML} = \frac{\sum_{i=1}^{n} x_i Y_i}{\sum_{i=1}^{n} x_i^{2}}
|
||||
$$
|
||||
}
|
||||
\end{enumerate}
|
||||
\questionandanswer[6]{
|
||||
(15') 设$X_1, X_2, \cdots , X_n$是来自$N(\mu,1)$的简单随机样本,其中$\mu$未知。用$\bar{X}$表示样本均值。令$p=P(X_1\geqslant 0)$,回答以下问题:
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswerSolution[]{
|
||||
求$p$的极大似然估计$\hat{p}$;
|
||||
}{
|
||||
因为$\mu$的MLE为$\bar{x}$,而$p = P(X_1\geqslant 0)=P\left( \frac{x_1-\mu}{1} \geqslant -\mu \right) =1-\Phi(-\mu)=\Phi(\mu)$,
|
||||
所以由MLE的不变性知 $\hat{P}_{MLE} = \Phi(\bar{x})$
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
求$\sqrt{n}(\hat{p}-p)$的极限分布;
|
||||
}{
|
||||
因为$\hat{\mu} = \bar{x} \sim N(\mu, \frac{1}{n})$,设$g(x)= \Phi(x)$,由Delta方法知
|
||||
$$
|
||||
\sqrt{n} \left( \hat{p} - p \right) =\sqrt{n} \left( \Phi(\bar{x}) -\Phi(\mu) \right) = \xrightarrow{L} N(0, \phi^{2}(\mu) \frac{1}{n})
|
||||
$$
|
||||
其中$\phi$为标准正态分布的概率密度函数。
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
求$p$的UMVUE。
|
||||
}{
|
||||
$\Phi\left( \sqrt{\frac{n}{n-1}} \cdot \bar{x} \right) $为$p$的UMVME。
|
||||
}
|
||||
\end{enumerate}
|
||||
\questionandanswerSolution[]{
|
||||
(10') 已知总体密度为$p(x;\theta) = \theta^{2} x^{\theta^{2}-1} (\theta>0, 0<x<1)$。若有容量为$n$的样本,求参数$\theta$无偏估计的C-R下界。
|
||||
}{
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\because &\ln p&=2 \ln \theta + (\theta^{2}-1) \ln x \\
|
||||
&&\frac{\partial \ln p}{\partial \theta}& = \frac{2}{\theta} + 2\theta \ln x \\
|
||||
&&\frac{\partial ^{2} \ln p}{\partial \theta^{2}}& = -\frac{2}{\theta^{2}} + 2\ln x \\
|
||||
&\therefore& I(\theta) &= - E\left( \frac{\partial ^{2}\ln p}{\partial \theta^{2}} \right) =\frac{2}{\theta^{2}} - 2E(\ln x) \\
|
||||
&&&=\frac{2}{\theta^{2}} - 2\int_{0}^{1} \ln x \cdot \theta^{2} x^{\theta^{2}-1} \mathrm{d}x = \frac{2}{\theta^{2}} + \frac{2}{\theta^{2}} = \frac{4}{\theta^{2}} \\
|
||||
&\therefore&& \text{C-R下界为} \frac{1}{nI(\theta)} = \frac{\theta^{2}}{4n} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
}
|
||||
\questionandanswerSolution[8]{
|
||||
设$X_1, \cdots ,X_n$是来自泊松分布Poisson($\lambda$)(其中$\lambda >0$)的一个样本。参数$\lambda$的先验分布是$\phi(\lambda)=e^{-\lambda}$(其中$\lambda>0$),求$\lambda$的后验密度和贝叶斯估计。
|
||||
}{
|
||||
后验分布为
|
||||
$$
|
||||
\begin{aligned}
|
||||
h(\theta |X_1, \cdots ,X_n) &= c \prod_{i=1}^{n} f(x_i |\lambda) \cdot \pi(\lambda) \\
|
||||
&=\frac{\lambda^{X_1+X_2+ \cdots +X_n}}{x_1! x_2!\cdots X_n!} e^{-n\lambda} e^{-\lambda} \\
|
||||
&=c \lambda^{\sum_{i=1}^{n} x_i} e^{-(n+1) \lambda} \sim \operatorname{Ga}\left( \sum_{i=1}^{n} x_i +1, n+1 \right) \\
|
||||
\end{aligned}
|
||||
$$
|
||||
后验均值为贝叶斯估计 $\displaystyle \hat{\lambda} = \frac{\sum_{i=1}^{n} x_i + 1}{n+1}$。
|
||||
}
|
||||
\end{enumerate}
|
||||
\subsection*{附加题}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[]{
|
||||
(10') 设$X_1, \cdots X_n, X_{n+1}$是来自$N(\mu,\sigma^{2})$的样本,记$\bar{X}_n = \frac{1}{n} \sum_{i=1}^{n} X_i, \ S_n^{2} = \frac{1}{n-1} \sum_{i=1}^{n} (X_i-\bar{X}_n)^{2}$。求解:
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswerSolution[]{
|
||||
常数$a$和$b$使得$T=(a X_{n+1} + b \bar{X}_n)/S_n$服从$t$分布,并指出$t$分布的自由度;
|
||||
}{
|
||||
若$T=(a X_{n+1} + b \bar{X}_n)/S_n$服从$t$分布,则因为$X_{n+1}, \bar{X}_n$都与$S_n$独立,所以
|
||||
$$
|
||||
\begin{aligned}
|
||||
ET=0 &\implies a E(X_{n+1}) + b(\bar{X}_{n}) = 0 \\
|
||||
&\implies a \mu + b \mu =0 \implies a = -b \\
|
||||
\end{aligned}
|
||||
$$
|
||||
又因为$\displaystyle \frac{(\bar{X}_n - X_{n+1})}{\sqrt{\frac{n+1}{n} }\sigma}=\frac{\bar{X}_n - \mu-(X_{n+1}-\mu)}{\sqrt{\frac{n+1}{n}} \sigma}\sim N(0,1)$,$\displaystyle \frac{(n-1) S_n^{2}}{\sigma^{2}} \sim \chi^{2}(n-1)$,所以
|
||||
$$
|
||||
T=\left.\frac{(\bar{X}_n-X_{n+1})}{\sqrt{\frac{n+1}{n}}\sigma} \middle/ \sqrt{\frac{(n-1)S_n^{2}}{\sigma^{2}(n-1)}}\right. \sim t(n-1)
|
||||
$$
|
||||
整理得
|
||||
$
|
||||
\displaystyle \sqrt{\frac{n}{n+1}} (\bar{X}_n-X_{n+1}) /S_n \sim t(n-1)
|
||||
$\\
|
||||
即$a=\pm \sqrt{\frac{n}{n+1}}$, $b=\mp \sqrt{\frac{n}{n+1}}$,自由度为$n-1$。
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
计算$\mathbb{E}(S_n^{3})$。
|
||||
}{
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\because X = \frac{(n-1)S_n^{2}}{\sigma^{2}} \sim \chi^{2}(n-1) \\
|
||||
&\therefore X\text{的密度函数为} p(x)= \frac{\left( \frac{1}{2} \right) ^{\frac{n-1}{2}}}{\Gamma\left( \frac{n-1}{2} \right) }x^{\frac{n}{2}-1} e^{-\frac{x}{2}}\ (x>0) \\
|
||||
\end{aligned}
|
||||
$$
|
||||
取$y=\sqrt{x}$,则$Y=\sqrt{X}$的密度函数为
|
||||
$$
|
||||
g(y)= p(x) \frac{\mathrm{d}x}{\mathrm{d}y} =p(x) \cdot 2y = p(y^{2})\cdot 2y = \frac{\left( \frac{1}{2} \right) ^{\frac{n-1}{2}}}{\Gamma\left( \frac{n-1}{2} \right) } \cdot 2y^{n-2} \cdot y \cdot e^{-\frac{y^{2}}{2}}
|
||||
$$
|
||||
$$
|
||||
\begin{aligned}
|
||||
E(Y^{3}) &= \int_{0}^{+\infty} y^{3}g(y) \mathrm{d}y = \int_{0}^{+\infty} \frac{2\left( \frac{1}{2} \right) ^{\frac{n-1}{2}}}{\Gamma\left( \frac{n-1}{2} \right) } y^{n+1} \cdot e^{-\frac{y^{2}}{2}} \mathrm{d}y \\
|
||||
&=\frac{2^{\frac{n+1}{2}}}{\Gamma\left( \frac{n-1}{2} \right) } \int_{0}^{+\infty} y^{n+1} e^{-\frac{y^{2}}{2}} \mathrm{d}y = \begin{cases}
|
||||
\frac{2^{\frac{n+1}{2}}}{\Gamma\left( \frac{n-1}{2} \right) } (2k-1)!!,\quad & n=2k-1 \\
|
||||
\frac{2^{\frac{n+1}{2}}}{\Gamma\left( \frac{n-1}{2} \right) } (2k)!!,\quad & n=2k \\
|
||||
\end{cases}
|
||||
\end{aligned}
|
||||
$$
|
||||
由$\displaystyle \sqrt{\frac{(n-1)S_n^{2}}{\sigma^{2}}}=Y \implies E S_n^{3}=\left( \frac{\sigma}{\sqrt{n-1}} \right) ^{3} \cdot E(Y^{3})$代入即得。
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{enumerate}
|
||||
\textbf{注:}正常题总分为100分,附加题总分为10分。总评分为两者之和,但总评分不超过100分。
|
||||
\end{document}
|
175
数理统计/作业/第一周作业.tex
Normal file
175
数理统计/作业/第一周作业.tex
Normal file
@ -0,0 +1,175 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
\input{mysubpreamble}
|
||||
\begin{document}
|
||||
\setcounter{chapter}{5}
|
||||
\section{总体与样本}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[2]{
|
||||
某市要调查成年男子的吸烟率,特聘请50名统计专业本科生作街头随机调查,要求每位学生调查100名成年男子,问该项调查的总体和样本分别是什么,总体用什么分布描述为宜?
|
||||
}{
|
||||
总体是成年男子,样本是$50\times 100=5000$名成年男子。总体应该用正态分布描述为宜。
|
||||
}
|
||||
\questionandanswer[4]{
|
||||
为估计鱼塘里有多少条鱼,一位统计学家设计了一个方案如下:从鱼塘中打捞出一网鱼,计有$n$条,涂上不会被水冲刷掉的红漆后放回,一天后再从鱼塘里打捞一网,发现共有$m$条鱼,而涂有红漆的鱼则有$k$条,你能估计出鱼塘里大概有多少鱼吗?该问题的总体和样本又分别是什么呢?
|
||||
}{
|
||||
鱼塘里大概有$\displaystyle \frac{m}{k}\cdot n$条鱼。将打捞鱼看做随机抽样的过程,则该问题的总体是鱼塘里的鱼,样本是打捞出的鱼。
|
||||
}
|
||||
\questionandanswer[5]{
|
||||
某厂生产的电容器的使用寿命服从指数分布,为了解其平均寿命,从中抽出$n$件产品测其实际使用寿命,试说明什么是总体,什么是样本,并指出样本的分布.
|
||||
}{
|
||||
总体是某厂生产的电容器,样本是抽出的$n$件产品,样本近似服从指数分布。
|
||||
}
|
||||
\end{enumerate}
|
||||
|
||||
\section{样本数据的整理与显示}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[1]{
|
||||
以下是某工厂通过抽样调查得到的10名工人一周内生产的产品数,试由这批数据构造经验分布函数并作图。
|
||||
$$
|
||||
149 \quad 156 \quad 160 \quad 138 \quad 149 \quad 153 \quad 153 \quad 169 \quad 156 \quad 156
|
||||
$$
|
||||
}{
|
||||
先将数据排序:138 149*2 153*2 156*3 160 169
|
||||
|
||||
\includexopp[1.5]{5.2.1}
|
||||
}
|
||||
\questionandanswer[5]{
|
||||
40种刊物的月发行量(单位 百册)如下:\\
|
||||
5954 \quad
|
||||
5022 \quad
|
||||
14667 \quad
|
||||
6582 \quad
|
||||
6870 \quad
|
||||
1840 \quad
|
||||
2662 \quad
|
||||
4508 \quad
|
||||
1208 \quad
|
||||
3852 \quad
|
||||
618 \quad
|
||||
3008 \quad
|
||||
1268 \quad
|
||||
1978 \quad
|
||||
7963 \quad
|
||||
2048 \quad
|
||||
3077 \quad
|
||||
993 \quad
|
||||
353 \quad
|
||||
14263 \quad
|
||||
1714 \quad
|
||||
11127 \quad
|
||||
6926 \quad
|
||||
2047 \quad
|
||||
714 \quad
|
||||
5923 \quad
|
||||
6006 \quad
|
||||
14267 \quad
|
||||
1697 \quad
|
||||
13876 \quad
|
||||
4001 \quad
|
||||
2280 \quad
|
||||
1223 \quad
|
||||
12579 \quad
|
||||
13588 \quad
|
||||
7315 \quad
|
||||
4538 \quad
|
||||
13304 \quad
|
||||
1615 \quad
|
||||
8612 \quad
|
||||
\begin{enumerate}
|
||||
\item 建立该批数据的频数分布表,取组距为1700(百册);
|
||||
\item 画出直方图。
|
||||
\end{enumerate}
|
||||
}{
|
||||
\begin{minipage}{0.3\linewidth}
|
||||
\begin{table}[H]
|
||||
\begin{tabular}{ccc}
|
||||
\toprule
|
||||
下限 & 上限 & 频率\\
|
||||
\midrule
|
||||
300 & 1999 & 12 \\
|
||||
2000 & 3699 & 6 \\
|
||||
3700 & 5399 & 5 \\
|
||||
5400 & 7099 & 6 \\
|
||||
7100 & 8799 & 3 \\
|
||||
8800 & 10499 & 0 \\
|
||||
10500 & 12199 & 1 \\
|
||||
12200 & 13899 & 4 \\
|
||||
13900 & 15599 & 3 \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{table}
|
||||
\end{minipage}
|
||||
\hfill
|
||||
\begin{minipage}{0.7\linewidth}
|
||||
\includesvgpdf{5.2.5}
|
||||
\end{minipage}
|
||||
|
||||
(频数分布表和直方图均通过Excel完成,坐标轴的标签无法与刻度对齐)
|
||||
}
|
||||
\questionandanswer[6]{
|
||||
对下列数据构造茎叶图:\\
|
||||
472 \quad
|
||||
425 \quad
|
||||
447 \quad
|
||||
377 \quad
|
||||
341 \quad
|
||||
369 \quad
|
||||
412 \quad
|
||||
399 \quad
|
||||
400 \quad
|
||||
382 \quad
|
||||
366 \quad
|
||||
425 \quad
|
||||
399 \quad
|
||||
398 \quad
|
||||
423 \quad
|
||||
384 \quad
|
||||
418 \quad
|
||||
392 \quad
|
||||
372 \quad
|
||||
418 \quad
|
||||
374 \quad
|
||||
385 \quad
|
||||
439 \quad
|
||||
408 \quad
|
||||
429 \quad
|
||||
428 \quad
|
||||
430 \quad
|
||||
413 \quad
|
||||
405 \quad
|
||||
381 \quad
|
||||
403 \quad
|
||||
479 \quad
|
||||
381 \quad
|
||||
443 \quad
|
||||
441 \quad
|
||||
433 \quad
|
||||
399 \quad
|
||||
379 \quad
|
||||
386 \quad
|
||||
387 \quad
|
||||
}{
|
||||
\begin{center}
|
||||
\renewcommand{\arraystretch}{0.8}
|
||||
% \lineskip=0.1em
|
||||
\begin{tabular}{r|l}
|
||||
34 & 1 \\
|
||||
35 & \\
|
||||
36 & 6 9 \\
|
||||
37 & 2 4 7 9 \\
|
||||
38 & 1 1 2 4 5 6 7 \\
|
||||
39 & 2 8 9 9 9 \\
|
||||
40 & 0 3 5 8 \\
|
||||
41 & 2 3 8 8 \\
|
||||
42 & 3 5 5 8 9 \\
|
||||
43 & 0 3 9 \\
|
||||
44 & 1 3 7 \\
|
||||
45 & \\
|
||||
46 & \\
|
||||
47 & 2 9 \\
|
||||
\end{tabular}
|
||||
\end{center}
|
||||
}
|
||||
|
||||
\end{enumerate}
|
||||
\end{document}
|
136
数理统计/作业/第七周作业.tex
Normal file
136
数理统计/作业/第七周作业.tex
Normal file
@ -0,0 +1,136 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
\input{mysubpreamble}
|
||||
\begin{document}
|
||||
\setcounter{chapter}{6}
|
||||
\setcounter{section}{3}
|
||||
\section{最小方差无偏估计}
|
||||
\begin{enumerate}
|
||||
\questionandanswerProof[1]{
|
||||
设总体概率函数是$p(x;\theta), x_1,x_2, \cdots ,x_n$ 是其样本,$T=T(x_1,x_2, \cdots ,x_n)$是$\theta$的充分统计量,则对$g(\theta)$的任一估计$\hat{g}$,令$\tilde{g}=E(\hat{g}|T)$,证明:$MSE(\tilde{g})\leqslant MSE(\hat{g})$。这说明,在均方误差准则下,人们只需要考虑基于充分统计量的估计。
|
||||
}{
|
||||
$$
|
||||
\begin{aligned}
|
||||
\operatorname{MSE}(\hat{g})&=E((\hat{g} - g(\theta))^{2})= E\left( (\hat{g} - \tilde{g} + \tilde{g} -g(\theta))^{2} \right) \\
|
||||
&=E(\hat{g}-\tilde{g})^{2} + 2E(\hat{g}-\tilde{g})(\tilde{g} - g(\theta) ) + E(\tilde{g}-g(\theta))^{2} \\
|
||||
&=E(\hat{g} - \tilde{g})^{2}+2E(\hat{g}-\tilde{g})(\tilde{g}-g(\theta))+\operatorname{MSE}(\tilde{g}) \\
|
||||
\end{aligned}
|
||||
$$
|
||||
其中
|
||||
$$
|
||||
E(\hat{g}-\tilde{g})(\tilde{g}-g(\theta))=E(E((\hat{g}-\tilde{g})(\tilde{g}-g(\theta))|T))
|
||||
$$
|
||||
由于$T$是充分统计量,所以$E(\tilde{g}-g(\theta))$与$T$无关,所以
|
||||
$$
|
||||
\begin{aligned}
|
||||
E (\hat{g}-\tilde{g})(\tilde{g}-g(\theta))&=E(\tilde{g}-g(\theta)) E(E(\hat{g}-\tilde{g}|T)) \\
|
||||
&=[E(\tilde{g}) -E(g(\theta))]E(E(\hat{g}-\tilde{g}|T)) = 0 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
所以
|
||||
$$
|
||||
\operatorname{MSE}(\hat{g}) = E(\hat{g}-\tilde{g})^{2}+\operatorname{MSE}(\tilde{g})\geqslant \operatorname{MSE}(\tilde{g})
|
||||
$$
|
||||
}
|
||||
\questionandanswerProof[3]{
|
||||
设$T$是$g(\theta)$的UMVUE,$\hat{g}$是$g(\theta)$的无偏估计,证明:若$\operatorname{Var}(\hat{g})<\infty$,则$\operatorname{Cov}(T,\hat{g})\geqslant 0$。
|
||||
}{
|
||||
由于$T$是$g(\theta)$的UMVUE,所以$E(T)=g(\theta), \operatorname{Var}(T)<\infty$;由于$\hat{g}$是$g(\theta)$的无偏估计,所以$E(\hat{g})=0$。从而$E(T-\hat{g})=E(T)-E(\hat{g})=0$,且$\operatorname{Var}(T-\hat{g})=\operatorname{Var}(T)+\operatorname{Var}(\hat{g})+\operatorname{Cov}(T,\hat{g})<\infty$(应该不存在方差有限但协方差无限的情况吧),所以根据判断准则,
|
||||
$$
|
||||
0=\operatorname{Cov}(T,T-\hat{g})=\operatorname{Var}(T)-\operatorname{Cov}(T,\hat{g})
|
||||
$$
|
||||
所以$\operatorname{Cov}(T,\hat{g})=\operatorname{Var}(T)>0$。
|
||||
}
|
||||
\questionandanswerProof[5]{
|
||||
设总体$p(x;\theta)$的费希尔信息量存在,若二阶导数$\displaystyle \frac{\partial ^{2}}{\partial \theta^{2}}p(x;\theta)$对一切的$\theta \in \Theta$存在,证明费希尔信息量
|
||||
$$
|
||||
I(\theta)=-E\left( \frac{\partial ^{2}}{\partial \theta^{2}}\ln p(x;\theta) \right)
|
||||
$$
|
||||
}{
|
||||
$$
|
||||
\begin{aligned}
|
||||
-E\left( \frac{\partial ^{2}}{\partial \theta^{2}} \ln p(x;\theta) \right) =&-\int_{-\infty}^{+\infty} \frac{\partial ^{2} \ln p(x;\theta)}{\partial \theta^{2}} p(x;\theta)\mathrm{d}x \\
|
||||
=&\int_{-\infty}^{+\infty} \left( \frac{\partial \ln p(x;\theta)}{\partial \theta} \right) ^{2} p(x;\theta) \mathrm{d}x \\
|
||||
=&\int_{-\infty}^{+\infty} \frac{\partial \ln p(x;\theta)}{\partial \theta} \frac{\partial \ln p(x;\theta)}{\partial p(x;\theta)} \frac{\partial p(x;\theta)}{\partial \theta} p(x;\theta) \mathrm{d}x \\
|
||||
=&\int_{-\infty}^{+\infty} \frac{\partial \ln p(x;\theta)}{\partial \theta} \frac{1}{p(x;\theta)} \frac{\partial p(x;\theta)}{\partial \theta} p(x;\theta) \mathrm{d}x \\
|
||||
=&\int_{-\infty}^{+\infty} \frac{\partial \ln p(x;\theta)}{\partial \theta} \frac{\partial p(x;\theta)}{\partial \theta} \mathrm{d}x \\
|
||||
=& E_{x} \left( \frac{\partial \ln p(x;\theta)}{\partial \theta} \right) ^{2} = I(\theta) \\
|
||||
\end{aligned}
|
||||
$$
|
||||
}
|
||||
\questionandanswer[6]{
|
||||
设总体密度函数为$p(x;\theta)=\theta x^{\theta-1}, 0<x<1, \theta>0$, $x_1,x_2, \cdots ,x_n$是样本。
|
||||
}{}
|
||||
|
||||
\begin{enumerate}
|
||||
\questionandanswerSolution[]{
|
||||
求$g(\theta)=\dfrac{1}{\theta}$的最大似然估计;
|
||||
}{
|
||||
对数似然函数为
|
||||
$$
|
||||
\ln L(\theta)=\sum_{i=1}^{n} \ln \theta x^{\theta-1}=\sum_{i=1}^{n} \left( \ln \theta+(\theta-1) \ln x_i \right) =n \ln \theta+(\theta-1) \sum_{i=1}^{n} \ln x_i
|
||||
$$
|
||||
对$\theta$求导并令其为0,
|
||||
$$
|
||||
\frac{\partial L(\theta)}{\partial \theta} = \frac{n}{\theta}+\sum_{i=1}^{n} x_i = 0
|
||||
$$
|
||||
则$\theta$的最大似然估计为$\hat{\theta} = \dfrac{n}{\sum_{i=1}^{n} x_i}$,根据最大似然估计的不变性,$g(\theta)=\dfrac{1}{\theta}$的最大似然估计为
|
||||
$$
|
||||
\widehat{g(\theta)}=\frac{1}{\hat{\theta}}=\frac{1}{n} \sum_{i=1}^{n} x_i
|
||||
$$
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
求$g(\theta)$的有效估计。
|
||||
}{
|
||||
可以猜测上一小题中的
|
||||
$
|
||||
\widehat{g(\theta)}=\frac{1}{n} \sum_{i=1}^{n} x_i
|
||||
$
|
||||
为有效估计,接下来验证一下。
|
||||
|
||||
% $$
|
||||
% \frac{\theta}{\theta+2}-\left( \frac{\theta}{\theta+1} \right) ^{2} = \frac{\theta}{\theta^{3} + 4 \theta^{2} + 5 \theta + 2}
|
||||
% $$
|
||||
可以计算得到总体的方差为$\dfrac{1}{\theta^{2}}$,因此 $g(\hat{\theta})=\bar{x}$的方差为$\dfrac{1}{n \theta^{2}} $。
|
||||
|
||||
由于$\ln p(x;\theta) = \ln \theta +(\theta-1)\ln x$,
|
||||
$$
|
||||
\frac{\partial \ln p(x;\theta)}{\partial \theta}=\frac{1}{\theta}+\ln x, \quad \frac{\partial^{2} \ln p(x;\theta)}{\partial \theta^{2}}=-\frac{1}{\theta^{2}}, \quad I(\theta)=-E\left( \frac{\partial ^{2}\ln p(x;\theta)}{\partial \theta^{2}} \right) =\frac{1}{\theta^{2}}
|
||||
$$
|
||||
所以$I(\frac{1}{\theta})=\theta^{2}$,所以
|
||||
$$
|
||||
\operatorname{Var}(\widehat{g(\theta)})= \frac{1}{n \theta^{2}}=\frac{1}{I(\frac{1}{\theta})}=\frac{1}{I(g(\theta))}
|
||||
$$
|
||||
因此$\widehat{g(\theta)}=\frac{1}{n} \sum_{i=1}^{n} x_i$为$g(\theta)$的有效估计。
|
||||
}
|
||||
\end{enumerate}
|
||||
\questionandanswerSolution[7]{
|
||||
设总体密度函数为$\displaystyle p(x;\theta)=\frac{2\theta}{x^{3}} e^{-\frac{\theta}{x^{2}}},x>0,\theta>0$,求$\theta$的费希尔信息量$I(\theta)$。
|
||||
}{
|
||||
$$
|
||||
\ln p(x;\theta)=\ln 2+\ln \theta-3\ln x -\frac{\theta}{x^{2}}
|
||||
$$
|
||||
$$
|
||||
\frac{\partial \ln p(x;\theta)}{\partial \theta}=\frac{1}{\theta} - \frac{1}{x^{2}}, \quad \frac{\partial ^{2}\ln p(x;\theta)}{\partial \theta^{2}} = -\frac{1}{\theta^{2}}
|
||||
$$
|
||||
所以
|
||||
$$
|
||||
I(\theta)=-E\left( \frac{\partial ^{2}\ln p(x;\theta)}{\partial \theta^{2}} \right) =\frac{1}{\theta^{2}}
|
||||
$$
|
||||
}
|
||||
\questionandanswerProof[10]{
|
||||
设$x_1,x_2, \cdots ,x_n$是来自$\operatorname{Ga}(\alpha,\lambda)$的样本,$\alpha>0$已知,试证明$\dfrac{\bar{x}}{\alpha}$是$g(\lambda)=\dfrac{1}{\lambda}$的有效估计,从而也是UMVUE。
|
||||
}{
|
||||
$$
|
||||
p(x;\lambda) = \frac{\lambda^{\alpha}}{\Gamma(\alpha)} x^{\alpha-1} e^{-\lambda x}, x>0; \quad \ln p(x;\lambda)=\alpha\ln \lambda-\ln \Gamma(\alpha)+(\alpha-1)\ln x-\lambda x
|
||||
$$
|
||||
$$
|
||||
\frac{\partial \ln p(x;\lambda)}{\partial \lambda}=\frac{\alpha}{\lambda}-x; \quad \frac{\partial ^{2} \ln p(x;\lambda)}{\partial \lambda^{2}}=-\frac{\alpha}{\lambda^{2}}
|
||||
$$
|
||||
所以
|
||||
$$
|
||||
I(\lambda)=-E\left( \frac{\partial ^{2}\ln p(x;\lambda)}{\partial \lambda^{2}} \right) =\frac{\alpha}{\lambda^{2}}; \quad \text{C-R下界}=\frac{(g'(\lambda))^{2}}{n I(\lambda)}=\frac{(-\frac{1}{\lambda^{2}})^{2}}{n \frac{\alpha}{\lambda^{2}}} = \frac{1}{\alpha \lambda^{2} n}
|
||||
$$
|
||||
由于总体的方差为$\dfrac{\alpha}{\lambda^{2}}$,所以$\bar{x}$的方差为$\dfrac{\alpha}{n \lambda^{2}}$,所以$\dfrac{\bar{x}}{\alpha}$的方差为$\dfrac{1}{n \alpha \lambda^{2}}$,等于C-R下界。
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
92
数理统计/作业/第三周作业.tex
Normal file
92
数理统计/作业/第三周作业.tex
Normal file
@ -0,0 +1,92 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
\input{mysubpreamble}
|
||||
\begin{document}
|
||||
\setcounter{chapter}{5}
|
||||
\setcounter{section}{3}
|
||||
\section{三大抽样分布}
|
||||
\begin{enumerate}
|
||||
\questionandanswerSolution[2]{
|
||||
设$x_1,x_2, \cdots ,x_n$是来自$N(\mu,16)$的样本,问$n$多大时才能使得$P(\left\vert \bar{x}-\mu \right\vert<1 )\geqslant 0.95$成立?
|
||||
}{
|
||||
由于$\bar{x}\sim N(\mu,\frac{16}{n})$,根据切比雪夫不等式,
|
||||
$$
|
||||
P(\left\vert \bar{x}-E \bar{x} \right\vert <\varepsilon)\geqslant 1-\frac{\operatorname{Var}\bar{x}}{\varepsilon}
|
||||
$$
|
||||
$$
|
||||
P(\left\vert \bar{x}-\mu \right\vert <1)\geqslant 1-\frac{16}{n}
|
||||
$$
|
||||
$$
|
||||
\frac{16}{n}=0.95 \Rightarrow n=\frac{16}{0.95} = \frac{320}{19} \approx 16.8421052631579
|
||||
$$
|
||||
因为$n$为整数,所以$n$至少为17时才能使得$P(\left\vert \bar{x}-\mu \right\vert<1 )\geqslant 0.95$成立。
|
||||
}
|
||||
\questionandanswerSolution[4]{
|
||||
由正态总体$N(\mu,\sigma^{2})$抽取容量为20的样本,试求$P\left( 10\sigma^{2}\leqslant \displaystyle \sum_{i=1}^{20} (x_i-\mu)^{2}\leqslant 30\sigma^{2} \right) $。
|
||||
}{
|
||||
由于$\displaystyle s^{2}=\frac{1}{19}\sum_{i=1}^{20} (x_i-\mu)^{2}$, $\displaystyle \frac{19s^{2}}{\sigma^{2}} \sim \chi^{2}(n-1)$,
|
||||
所以$\displaystyle \frac{1}{\sigma^{2}}\sum_{i=1}^{20} (x_i-\mu)^{2}\sim \chi^{2}(n-1)$。
|
||||
所以
|
||||
$$
|
||||
\begin{aligned}
|
||||
&P\left( 10\sigma^{2}\leqslant \sum_{i=1}^{20} (x_i-\mu)^{2}\leqslant 30\sigma^{2} \right) = P\left( 10\leqslant \frac{1}{\sigma^{2}}\sum_{i=1}^{20} (x_i-\mu)^{2}\leqslant 30 \right) \\
|
||||
&=\int_{10}^{30} \frac{\left( \frac{1}{2} \right) ^{\frac{20}{2}}}{\Gamma\left( \frac{20}{2}-1 \right) } y^{\frac{20}{2}}e^{-\frac{y}{2}} \mathrm{d}y = \int_{10}^{30} \frac{\left( \frac{1}{2} \right) ^{10}}{9!} y^{9}e^{-\frac{y}{2}} \mathrm{d}y \approx 0.898318281994385 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\begin{center}
|
||||
\includegraphics[width=0.2\linewidth]{imgs/2024-03-20-14-05-40.png}
|
||||
\end{center}
|
||||
}
|
||||
\questionandanswerSolution[6]{
|
||||
设$x_1,x_2, \cdots ,x_n$是来自$N(\mu,1)$的样本,试确定最小的常数$c$,使得对任意的$\mu\geqslant 0$,有$P(\left\vert \bar{x} \right\vert <c)\leqslant \alpha$。
|
||||
}{
|
||||
这题什么意思?当$\mu=0$时,当$n \to \infty$时$\bar{x} \to 0$, $P(\left\vert \bar{x} \right\vert <c) \to 1$,怎么可能$P(\left\vert \bar{x} \right\vert <c)\leqslant \alpha$呢?
|
||||
}
|
||||
\questionandanswerProof[8]{
|
||||
设随机变量$X\sim F(n,m)$,证明$\displaystyle Z=\frac{n}{m}X \left\slash \left( 1+\frac{n}{m}X \right) \right.$服从贝塔分布,并指出其参数。
|
||||
}{
|
||||
设$Y=\dfrac{n}{m}X$,则
|
||||
$$
|
||||
p_{Y}(y)=\frac{\Gamma\left( \frac{m+n}{2} \right) }{\Gamma\left( \frac{m}{2} \right) \Gamma\left( \frac{n}{2} \right) } y^{\frac{m}{2}-1}(1+y)^{-\frac{m+n}{2}}
|
||||
$$
|
||||
$$
|
||||
Z=\frac{Y}{1+Y} = 1 - \frac{1}{1+Y} \Longrightarrow Y=\frac{1}{1-Z}-1=\frac{Z}{1-Z}
|
||||
$$
|
||||
所以
|
||||
$$
|
||||
\begin{aligned}
|
||||
&p_{Z}(z)=\frac{\Gamma(\frac{m+n}{2})}{\Gamma(\frac{m}{2})\Gamma(\frac{n}{2})}\left( \frac{z}{1-z} \right) ^{\frac{m}{2}-1} \left( \frac{1}{1-z} \right) ^{- \frac{m+n}{2}} \\
|
||||
&=\frac{\Gamma(\frac{m+n}{2})}{\Gamma(\frac{m}{2})\Gamma(\frac{n}{2})} \left( \frac{z}{1-z} \right) ^{\frac{m}{2}} \left( \frac{1-z}{z} \right) \left( 1-z \right) ^{\frac{m}{2}} \left( 1-z \right) ^{\frac{n}{2}} \\
|
||||
&=\frac{\Gamma(\frac{m+n}{2})}{\Gamma(\frac{m}{2})\Gamma(\frac{n}{2})}z^{\frac{m}{2}}(1-z)^{\frac{n}{2}}\left( \frac{1-z}{z} \right) \\
|
||||
&=\frac{\Gamma(\frac{m+n}{2})}{\Gamma(\frac{m}{2})\Gamma(\frac{n}{2})} z^{\frac{m}{2}-1} (1-z)^{\frac{n}{2}+1} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
|
||||
所以$Z$服从贝塔分布,其参数为$\dfrac{m}{2}$和$\dfrac{n}{2}$。
|
||||
}
|
||||
\questionandanswerSolution[9]{
|
||||
设$x_1,x_2$是来自$N(0,\sigma^{2})$的样本,试求$\displaystyle Y=\left( \frac{x_1+x_2}{x_1-x_2} \right) ^{2}$的分布。
|
||||
}{
|
||||
$$
|
||||
Y=\left( \frac{x_1+x_2}{x_1-x_2} \right) ^{2}=\left( \frac{\frac{x_1}{x_2}+1}{\frac{x_1}{x_2}-1} \right) ^{2}=\left( 1+\frac{2}{\frac{x_1}{x_2}-1} \right) ^{2}
|
||||
$$
|
||||
其中$\dfrac{x_1}{x_2}$的概率密度函数为
|
||||
$$
|
||||
\begin{aligned}
|
||||
p_{\frac{x_1}{x_2}}(t)&=\int_{-\infty}^{+\infty} \left\vert x \right\vert p(x,tx) \mathrm{d}x=\int_{-\infty}^{+\infty} \left\vert x \right\vert \phi(x)\phi(tx) \mathrm{d}x =\int_{-\infty}^{+\infty} \left\vert x \right\vert \frac{1}{\sqrt{2\pi}}e^{\frac{-\sigma^{2}x^{2}}{2}}\cdot \frac{1}{\sqrt{2\pi}}e^{\frac{-\sigma^{2}t^{2}x^{2}}{2}} \mathrm{d}x \\
|
||||
&=\frac{1}{\sigma^{2}\pi}\int_{0}^{+\infty} x e^{\frac{-\sigma^{2}x^{2}}{2}(1+t^{2})} \mathrm{d}x = \frac{1}{\pi \sigma^{4} (t^{2} + 1)} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
设随机变量$Z=1+\frac{2}{\frac{x_1}{x_2}-1}$,则$\frac{x_1}{x_2}=1+\frac{2}{Z-1}$, $Y=Z^{2}$,所以
|
||||
$$
|
||||
p_{Z}(z)=\frac{1}{\pi\sigma^{4}\left[ \left( 1+\frac{2}{z-1} \right) ^{2}+1 \right] } = \frac{(z - 1)^{2}}{\pi \sigma^{4} ((z - 1)^{2} + (z + 1)^{2})}
|
||||
$$
|
||||
$$
|
||||
\begin{aligned}
|
||||
p_{Y}(y)&=p_{Z}(\sqrt{y})+p_{Z}(-\sqrt{y})=\frac{(\sqrt{y} - 1)^{2}}{\pi \sigma^{4} ((\sqrt{y} - 1)^{2} + (\sqrt{y} + 1)^{2})}+\frac{(\sqrt{y} - 1)^{2}}{\pi \sigma^{4} ((\sqrt{y} - 1)^{2} + (\sqrt{y} + 1)^{2})} \\
|
||||
&= \frac{- 2 \sqrt{y} + y + 1}{\pi \sigma^{4} (y + 1)} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
此即为$Y$的概率密度函数。
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
297
数理统计/作业/第九周作业.tex
Normal file
297
数理统计/作业/第九周作业.tex
Normal file
@ -0,0 +1,297 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
\input{mysubpreamble}
|
||||
\begin{document}
|
||||
\renewcommand{\bar}{\xoverline}
|
||||
\renewcommand{\hat}{\xwidehat}
|
||||
\setcounter{chapter}{6}
|
||||
\setcounter{section}{4}
|
||||
\begin{enumerate}
|
||||
\questionandanswerSolution[11]{
|
||||
设$x_1,x_2, \cdots ,x_m \overset{\text{i.i.d.}}{\sim} N(a, \sigma^{2}), y_1,y_2, \cdots y_n\overset{\text{i.i.d.}}{\sim}N(a,2\sigma^{2})$,求$a$和$\sigma^{2}$的UMVUE。
|
||||
}{
|
||||
根据贝叶斯估计的方法,$\hat{a}$和$\widehat{\sigma^{2}}$应为两个信息源的加权平均,权重为方差的倒数,即
|
||||
$$
|
||||
\hat{a}= \frac{\frac{1}{m\sigma^{2}}}{\frac{1}{m\sigma^{2}}+\frac{1}{2n\sigma^{2}}} \bar{x} + \frac{\frac{1}{2n\sigma^{2}}}{\frac{1}{m\sigma^{2}}+\frac{1}{2n\sigma^{2}}} \bar{y} = \frac{2 \bar{x} n + \bar{y} m}{m + 2 n}
|
||||
$$
|
||||
$$
|
||||
\widehat{\sigma^{2}}=\frac{\frac{1}{m\sigma^{2}}}{\frac{1}{m\sigma^{2}}+\frac{1}{2n\sigma^{2}}} s_{x}^{2} + \frac{\frac{1}{2n\sigma^{2}}}{\frac{1}{m\sigma^{2}}+\frac{1}{2n\sigma^{2}}} s_{y}^{2} = \frac{m s_{y}^{2} + 2 n s_{x}^{2}}{m + 2 n}
|
||||
$$
|
||||
对$0$的任一无偏估计$\varphi(x_1,x_2, \cdots ,x_m,y_1,y_2, \cdots ,y_n)$,$\operatorname{Cov}(\hat{a},\varphi)=0, \operatorname{Cov}(\widehat{\sigma^{2}},\varphi)=0$,所以$\hat{a}$和$\widehat{\sigma^{2}}$是UMVUE。
|
||||
}
|
||||
\questionandanswerProof[12]{
|
||||
设$x_1,x_2, \cdots ,x_n\overset{\text{i.i.d.}}{\sim}N(\mu,1)$,求$\mu^{2}$的UMVUE。证明此UMVUE,达不到C-R不等式的下界,即它不是有效估计。
|
||||
}{
|
||||
直观上来看,$\mu^{2}$的UMVUE应该是$\bar{x}^{2}$。接下来计算C-R不等式的下界,由于$I(\mu)=1$,所以C-R不等式的下界为
|
||||
$$
|
||||
\frac{[g'(\mu)]^{2}}{n I(\mu)}=\frac{(2\mu)^{2}}{n} = \frac{4\mu^{2}}{n}
|
||||
$$
|
||||
由于$\bar{x}\sim N(\mu, \frac{1}{n})$,所以$(n(\bar{x}-\mu)) \sim \chi^{2}(1)$
|
||||
$$
|
||||
\operatorname{Var} \bar{x}^{2} = E \bar{x}^{4} - (E \bar{x}^{2})^{2} =\text{实在是不会算了} > \frac{4\mu^{2}}{n}
|
||||
$$
|
||||
所以此UMVUE达不到C-R不等式的下界,即它不是有效估计。
|
||||
}
|
||||
\questionandanswer[14]{
|
||||
设$x_1,x_2, \cdots x_n$为独立同分布变量,$0<\theta<1$,
|
||||
$$
|
||||
P(x_1=-1)=\frac{1-\theta}{2}, \quad P(x_1=0)=\frac{1}{2}, \quad P(x_1=1)=\frac{\theta}{2}
|
||||
$$
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswerSolution[]{
|
||||
求$\theta$的MLE $\hat{\theta}_1$并问$\hat{\theta}_1$是否是无偏的;
|
||||
}{
|
||||
设在$x_1,x_2, \cdots ,x_n$中有$n_{-1}$个$-1$,$n_{0}$个$0$,$n_1$个$1$,则对数极大似然函数为
|
||||
$$
|
||||
\begin{aligned}
|
||||
\ln L(n_{-1},n_{0},n_1;\theta)&=\ln \left[ \left( \frac{1-\theta}{2} \right) ^{n_{-1}} \left( \frac{1}{2} \right) ^{n_0} \left( \frac{\theta}{2} \right) ^{n_1} \right] \\
|
||||
&=n_{-1}\ln \left( \frac{1-\theta}{2} \right) +n_0 \ln \frac{1}{2}+n_1 \ln \frac{\theta}{2} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
对$\theta$求偏导并令其为0
|
||||
$$
|
||||
\frac{\partial L}{\partial \theta}=-\frac{1}{2}\frac{2 n_{-1}}{1-\theta}+ \frac{1}{2}\frac{2n_1}{\theta} = \frac{n_1}{\theta}-\frac{n_{-1}}{1-\theta} = 0
|
||||
$$
|
||||
则最大似然估计为
|
||||
$$
|
||||
\hat{\theta}_1 = \frac{n_{1}}{n_{1} + n_{-1}}
|
||||
$$
|
||||
根据重期望公式,
|
||||
$$
|
||||
E \hat{\theta}_1 = E\left( E\left( \frac{n_1}{n_1+n_{-1}} \middle| n_1+n_{-1} \right) \right)
|
||||
$$
|
||||
其中
|
||||
$$
|
||||
E\left( \frac{n_1}{n_1+n_{-1}}\middle| n_1+n_{-1} \right) =E\left( \frac{n_1}{m}\middle| n_1+n_{-1}=m \right) = \frac{1}{m} \times m \frac{\frac{\theta}{2}}{\frac{1-\theta}{2}+\frac{\theta}{2}} = \theta
|
||||
$$
|
||||
所以$E \hat{\theta}_1 = E(\theta)= \theta$,即$\hat{\theta}_1$是无偏估计。
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
求$\theta$的矩估计$\hat{\theta}_2$;
|
||||
}{
|
||||
设总体为$X$,则
|
||||
$$
|
||||
EX = -1 \times \frac{1-\theta}{2}+0\times \frac{1}{2}+1\times \frac{\theta}{2} = \theta - \frac{1}{2}
|
||||
$$
|
||||
所以矩估计$\hat{\theta}_2 = \bar{x}+\frac{1}{2}$。
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
计算$\theta$的无偏估计的方差的C-R下界。
|
||||
}{
|
||||
$$
|
||||
p(x;\theta)=\begin{cases}
|
||||
\frac{1-\theta}{2},\quad & x=-1 \\
|
||||
\frac{1}{2},\quad & x=0 \\
|
||||
\frac{\theta}{2},\quad & x=1 \\
|
||||
0, \quad &\text{其他} \\
|
||||
\end{cases}, \quad \ln p(x;\theta)=\begin{cases}
|
||||
\ln (1-\theta)-\ln 2,\quad & x=-1 \\
|
||||
-\ln 2,\quad & x=0 \\
|
||||
\ln \theta-\ln 2,\quad & x=1 \\
|
||||
0,\quad & \text{其他} \\
|
||||
\end{cases},
|
||||
$$
|
||||
$$
|
||||
\frac{\partial \ln p(x;\theta)}{\partial \theta}=\begin{cases}
|
||||
-\frac{1}{1-\theta},\quad & x=-1 \\
|
||||
0,\quad & x=0 \\
|
||||
\frac{1}{\theta},\quad & x=1 \\
|
||||
0,\quad & \text{其他} \\
|
||||
\end{cases},\quad \left( \frac{\partial \ln p(x;\theta)}{\partial \theta} \right) ^{2} = \begin{cases}
|
||||
\frac{1}{(1-\theta)^{2}},\quad & x=-1 \\
|
||||
\frac{1}{\theta^{2}},\quad & x=1 \\
|
||||
0,\quad & \text{其他} \\
|
||||
\end{cases}
|
||||
$$
|
||||
所以
|
||||
$$
|
||||
I(\theta)=E\left( \frac{\partial \ln p(x;\theta)}{\partial \theta} \right) ^{2}=\frac{1}{(1-\theta)^{2}}\times \frac{1-\theta}{2}+\frac{1}{\theta^{2}}\times \frac{\theta}{2} = \frac{1}{2 \theta (1-\theta )}
|
||||
$$
|
||||
所以$\theta$的无偏估计的方差的C-R下界为
|
||||
$$
|
||||
\frac{1}{n I(\theta)}=\frac{2\theta(1-\theta)}{n}
|
||||
$$
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{enumerate}
|
||||
\section{贝叶斯估计}
|
||||
\begin{enumerate}
|
||||
\questionandanswerSolution[2]{
|
||||
设总体为均匀分布$U(\theta,\theta+1)$,$\theta$的先验分布是$U(10,16)$。现有三个观测值:$11.7, 12.1, 12.0$。求$\theta$的后验分布。
|
||||
}{
|
||||
$$
|
||||
p(X|\theta)=\begin{cases}
|
||||
1^{3},\quad & \theta\in [11.1,11.7] \\
|
||||
0,\quad & \theta \not \in [11.1,11.7] \\
|
||||
\end{cases}=1_{[11.1,11.7]}(\theta), \quad \pi(\theta)=\frac{1}{6}1_{[10,16]}(\theta)
|
||||
$$
|
||||
所以$h(X,\theta)=p(X|\theta)\pi(\theta)=\frac{1}{6} 1_{[11.1,11.7]}(\theta)$,\quad $m(X)=\int_{-\infty}^{+\infty} \frac{1}{6}1_{[11.1,11.7]}(\theta) \mathrm{d}\theta = \frac{1}{6}\times 0.7$。
|
||||
所以$\theta$的后验分布为
|
||||
$$
|
||||
\pi(\theta|X)=\frac{h(X,\theta)}{m(X)}=\frac{1}{0.7} 1_{[11.1,11.7]}(\theta) = \frac{10}{7} 1_{[11.1,11.7]}(\theta)
|
||||
$$
|
||||
}
|
||||
\questionandanswer[3]{
|
||||
设$x_1,x_2, \cdots ,x_n$是来自几何分布的样本,总体分布列为
|
||||
$$
|
||||
P(X=k|\theta)=\theta(1-\theta)^{k}, \quad k=0,1,2, \cdots ,
|
||||
$$
|
||||
$\theta$的先验分布是均匀分布$U(0,1)$。
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswerSolution[]{
|
||||
求$\theta$的后验分布;
|
||||
}{
|
||||
$$
|
||||
p(\theta|x_1,x_2, \cdots ,x_n)=\frac{p(x_1,x_2, \cdots ,x_n|\theta)\pi(\theta)}{\int_{0}^{1} p(x_1,x_2, \cdots ,x_n|\theta)\pi(\theta) \mathrm{d}\theta} = \frac{\prod_{i=1}^{n} \left[ \theta(1-\theta)^{x_i} \right] 1_{[0,1]}(\theta)}{\int_{0}^{1} \prod_{i=1}^{n} \left[ \theta(1-\theta)^{x_i} \right] \mathrm{d}\theta}
|
||||
$$
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
若$4$次观测值为$4,3,1,6$,求$\theta$的贝叶斯估计。
|
||||
}{
|
||||
$$
|
||||
E(\theta|4,3,1,6) = \int_{0}^{1} \theta p(\theta|4,3,1,6) \mathrm{d}\theta = \text{实在算不出来了}
|
||||
$$
|
||||
}
|
||||
\end{enumerate}
|
||||
\questionandanswerProof[5]{
|
||||
验证:正态总体方差(均值已知)的共轭先验分布是倒伽马分布(称$X$服从倒伽马分布,如果$\frac{1}{X}$服从倒伽马分布。
|
||||
}{
|
||||
设总体$X\sim N(\mu,\sigma^{2})$,且$\sigma^{2}\sim \operatorname{IG}(\alpha,\gamma)$,则$\frac{1}{\sigma^{2}}\sim \operatorname{Ga}(\alpha,\lambda)$,所以
|
||||
$$
|
||||
h(X|\sigma^{2})=p(X|\sigma^{2})p(\sigma^{2})= \frac{1}{\sqrt{2\pi}\sigma} e^{-\frac{1}{2}\sum_{i=1}^{n} \left( \frac{x-\mu}{\sigma} \right) ^{2}} \cdot \frac{\lambda^{\alpha}}{\Gamma(\alpha)}\left( \frac{1}{\sigma^{2}} \right) ^{\alpha-1} e^{-\frac{1}{\sigma^{2}}}
|
||||
$$
|
||||
$$
|
||||
p(\sigma^{2}|X)=\frac{p(X|\sigma^{2})p(\sigma^{2})}{\int_{0}^{+\infty} p(X|\sigma^{2})p(\sigma^{2}) \mathrm{d}\sigma^{2}} = \frac{\frac{1}{\sqrt{2\pi}\sigma} e^{-\frac{1}{2}\sum_{i=1}^{n} \left( \frac{x-\mu}{\sigma} \right) ^{2}} \cdot \frac{\lambda^{\alpha}}{\Gamma(\alpha)}\left( \frac{1}{\sigma^{2}} \right) ^{\alpha-1} e^{-\frac{1}{\sigma^{2}}}}{\int_{0}^{+\infty} \frac{1}{\sqrt{2\pi}\sigma} e^{-\frac{1}{2}\sum_{i=1}^{n} \left( \frac{x-\mu}{\sigma} \right) ^{2}} \cdot \frac{\lambda^{\alpha}}{\Gamma(\alpha)}\left( \frac{1}{\sigma^{2}} \right) ^{\alpha-1} e^{-\frac{1}{\sigma^{2}}} \mathrm{d}\sigma^{2}}
|
||||
$$
|
||||
计算可得$p(\sigma^{2}|X)$也是倒伽马分布的概率密度函数,因此$\sigma^{2}$的后验分布也是倒伽马分布,从而正态总体方差(均值已知)的共轭先验分布是倒伽马分布。
|
||||
}
|
||||
\questionandanswer[6]{
|
||||
设$x_1,x_2, \cdots ,x_n$是来自如下总体的一个样本
|
||||
$$
|
||||
p(x|\theta) = \frac{2x}{\theta^{2}}, \quad 0<x<\theta
|
||||
$$
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswerSolution[]{
|
||||
若$\theta$的先验分布为均匀分布$U(0,1)$,求$\theta$的后验分布;
|
||||
}{
|
||||
$$
|
||||
\begin{aligned}
|
||||
&h(x_1,x_2, \cdots ,x_n,\theta)=P(x_1,x_2, \cdots ,x_n|\theta)\pi(\theta) \\
|
||||
=&\prod_{i=1}^{n} \frac{2 x_i}{\theta^{2}} 1_{[0,\theta]}(x_i) 1_{[0,1]}(\theta) =1_{0<x_{(1)}}1_{x_{(n)}<\theta} \frac{1}{\theta^{2n}} \prod_{i=1}^{n} 2
|
||||
x_i 1_{[0,1]}(\theta) \\
|
||||
\end{aligned}
|
||||
$$
|
||||
$$
|
||||
\begin{aligned}
|
||||
&m(x_1,x_2, \cdots x_n)=\int_{0}^{1} h(x_1,x_2, \cdots ,x_n,\theta) \mathrm{d}\theta = 1_{0<x_{(1)}} \prod_{i=1}^{n} 2 x_i \int_{0}^{1} 1_{x_{(n)}<\theta} \frac{1}{\theta^{2n}} \mathrm{d}\theta \\
|
||||
=&1_{0<x_{(1)}} \prod_{i=1}^{n} 2 x_i \int_{x_{(n)}}^{1} \frac{1}{\theta^{2n}} \mathrm{d}x = 1_{0<x_{(1)}} \left(-2n+1-(-2n+1)x_{(n)}^{-2n+1}\right) \prod_{i=1}^{n} 2 x_i \\
|
||||
\end{aligned}
|
||||
$$
|
||||
所以$\theta$的后验分布为
|
||||
$$
|
||||
\pi(\theta|x_1, \cdots ,x_n)=\frac{h(x_1, \cdots ,x_n,\theta)}{m(x_1, \cdots ,x_n)} = \frac{1_{x_{(n)}<\theta} 1_{[0,1]}(\theta)}{\theta^{2n} \left(-2n+1-(-2n+1)x_{(n)}^{-2n+1}\right)}
|
||||
$$
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
若$\theta$的先验分布为$\pi(\theta)=3 \theta^{2}, 0<\theta<1$,求$\theta$的后验分布。
|
||||
}{
|
||||
$$
|
||||
\begin{aligned}
|
||||
&h(x_1,x_2, \cdots ,x_n,\theta)=P(x_1,x_2, \cdots ,x_n|\theta)\pi(\theta) \\
|
||||
=&\prod_{i=1}^{n} \frac{2 x_i}{\theta^{2}} 1_{[0,\theta]}(x_i) 3\theta^{2}1_{[0,1]}(\theta) =1_{0<x_{(1)}}1_{x_{(n)}<\theta} \frac{3\theta^{2}}{\theta^{2n}} \left(\prod_{i=1}^{n} 2 x_i\right) 1_{[0,1]}(\theta) \\
|
||||
\end{aligned}
|
||||
$$
|
||||
$$
|
||||
\begin{aligned}
|
||||
&m(x_1,x_2, \cdots x_n)=\int_{0}^{1} h(x_1,x_2, \cdots ,x_n,\theta) \mathrm{d}\theta = 1_{0<x_{(1)}} \prod_{i=1}^{n} 2 x_i \int_{0}^{1} 1_{x_{(n)}<\theta} \frac{3\theta^{2}}{\theta^{2n}} \mathrm{d}\theta \\
|
||||
=&1_{0<x_{(1)}} \prod_{i=1}^{n} 2 x_i \int_{x_{(n)}}^{1} \frac{3\theta^{2}}{\theta^{2n}} \mathrm{d}x = 1_{0<x_{(1)}} \left(9-6n-(9-6n)x_{(n)}^{3-2n}\right) \prod_{i=1}^{n} 2 x_i \\
|
||||
\end{aligned}
|
||||
$$
|
||||
所以$\theta$的后验分布为
|
||||
$$
|
||||
\pi(\theta|x_1, \cdots ,x_n)=\frac{h(x_1, \cdots ,x_n,\theta)}{m(x_1, \cdots ,x_n)} = \frac{1_{x_{(n)}<\theta} 1_{[0,1]}(\theta)}{\theta^{2n} \left(9-6n-(9-6n)x_{(n)}^{3-2n}\right)}
|
||||
$$
|
||||
}
|
||||
\end{enumerate}
|
||||
\questionandanswer[8]{
|
||||
设$x_1,x_2, \cdots ,x_n$是来自均匀分布$U(0,\theta)$的样本,$\theta$的先验分布是帕雷托分布,其密度函数为$\displaystyle \pi(\theta)=\frac{\beta\theta_0^{\beta}}{\theta^{\beta+1}}, \theta>\theta_0$,其中$\beta,\theta_0$是两个已知的常数。
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswerProof[]{
|
||||
验证:帕雷托分布是$\theta$的共轭先验分布;
|
||||
}{
|
||||
令$X=\{ x_1,x_2, \cdots ,x_n \}$,则 $P(X|\theta)=\prod_{i=1}^{n} \frac{1}{\theta} 1_{[0,\theta]}(x_i)=\frac{1}{\theta^{n}}1_{x_{(1)}\geqslant 0} 1_{x_{(n)}\leqslant \theta}$
|
||||
$$
|
||||
h(X,\theta)=P(X|\theta)\pi(\theta)=\frac{\beta \theta_0^{\beta}}{\theta^{\beta+1+n}} 1_{x_{(1)}\geqslant 0} 1_{x_{(n)}\leqslant \theta}
|
||||
$$
|
||||
$$
|
||||
m(X)=\int_{x_{(n)}}^{+\infty} h(X,\theta) \mathrm{d}\theta= \beta \theta_0^{\beta} 1_{x_{(1)}\geqslant 0} \int_{x_{(n)}}^{+\infty} \theta^{-\beta-1-n} \mathrm{d}\theta = \frac{\beta \theta_0^{\beta} 1_{x_{(1)}\geqslant 0}}{\beta+n} x_{(n)}^{-\beta-n}
|
||||
$$
|
||||
% 所以
|
||||
$$
|
||||
P(\theta|X)=\frac{h(X,\theta)}{m(X)}=\frac{\frac{1_{x_{(n)}\leqslant \theta}}{\theta^{\beta+n+1}}}{\frac{x_{(n)}^{-\beta-n}}{\beta+n}} = \frac{(\beta+n)x_{(n)}^{\beta+n}}{\theta^{\beta+n-1}} 1_{x_{(n)}\leqslant \theta}
|
||||
$$
|
||||
所以$\theta$的后验分布为参数为$\beta+n$和$x_{(n)}$的帕雷托分布,从而帕雷托分布是$\theta$的共轭先验分布。
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
求$\theta$的贝叶斯估计。
|
||||
}{
|
||||
$\theta$的贝叶斯估计为
|
||||
$$
|
||||
\begin{aligned}
|
||||
\hat{\theta} = \int_{x_{(n)}}^{+\infty} \theta p(\theta|X) \mathrm{d}\theta = \int_{x_{(n)}}^{+\infty} \frac{\theta (\beta+n) x_{(n)}^{\beta+n}}{\theta^{\beta+n+1}} \mathrm{d}\theta = \frac{\beta+n}{\beta+n-1} x_{(n)}
|
||||
\end{aligned}
|
||||
$$
|
||||
}
|
||||
\end{enumerate}
|
||||
\questionandanswerProof[12]{
|
||||
从正态总体$N(\theta,2^{2})$中随机抽取容量为$100$的样本,又设$\theta$的先验分布为正态分布,证明:不管先验分布的标准差为多少,后验分布的标准差一定小于$\frac{1}{5}$。
|
||||
}{
|
||||
设样本为$X$,$\theta$的先验分布为$N(\mu,\sigma^{2})$,则$\theta$的后验概率密度函数为
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\pi(\theta|X) = c f(X|\theta) f(\theta) \\
|
||||
&=c \left( \prod_{i=1}^{n} \frac{1}{2\sqrt{2\pi}} e^{-\frac{1}{2} \left( \frac{x_i-\theta}{2} \right) ^{2}} \right) \cdot \frac{1}{\sqrt{2\pi} \sigma} e^{-\frac{1}{2} \left( \frac{\theta-\mu}{\sigma} \right) ^{2}} \\
|
||||
&=c e^{-\frac{1}{2} \left( \frac{\theta-\mu}{\sigma} \right) ^{2} - \frac{1}{2} \sum_{i=1}^{n} \left( \frac{x_i-\theta}{2} \right) ^{2}} \\
|
||||
&\geqslant ce^{-\frac{1}{2} \cdot 25 (\theta-\mu-\bar{x})^{2}} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
所以后验分布的标准差一定小于$\frac{1}{5}$。
|
||||
}
|
||||
\questionandanswerProof[13]{
|
||||
设随机变量$X$服从负二项分布,其概率分布为
|
||||
$$
|
||||
f(x|p)=\binom{x-1}{k-1} p^{k} (1-p)^{x-k}, \quad x=k,k+1, \cdots
|
||||
$$
|
||||
证明其成功概率$p$的共轭先验分布族为贝塔分布族。
|
||||
}{
|
||||
设$X=\{ x_1,x_2, \cdots ,x_n \}$。设$p$的先验分布为贝塔分布$Be(a,b)$,则$\pi(p)=\frac{1}{B(a,b)} p^{a-1}(1-p)^{b-1}$,所以
|
||||
$$
|
||||
\begin{aligned}
|
||||
P(p|X)&= c \cdot h(X,p)=c \cdot P(X|p)\pi(p) =c \left(\prod_{i=1}^{n} \mathrm{C}_{x_i-1}^{k-1} p^{k} (1-p)^{x_i-k}\right) \frac{1}{B(a,b)}p^{a-1} (1-p)^{b-1} \\
|
||||
&=c p^{nk} (1-p)^{-nk} (1-p)^{\sum_{i=1}^{n} x_i} p^{a-1} (1-p)^{b-1} \\
|
||||
&=c p^{nk+a-1} (1-p)^{\sum_{i=1}^{n} x_i-nk+b-1} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
其中$c$为与$p$无关的数。
|
||||
|
||||
所以$p$的后验分布为$\displaystyle Be(nk+a, \sum_{i=1}^{n} x_i -nk +b)$,从而$p$的共轭先验分布族为贝塔分布族。
|
||||
}
|
||||
\questionandanswerSolution[14]{
|
||||
从一批产品中抽检$100$个,发现$3$个不合格,假定该产品不合格率$\theta$的先验分布为贝塔分布$Be(2,200)$,求$\theta$的后验分布。
|
||||
}{
|
||||
设总体为$X$,则$X\sim b(100, \theta)$,所以
|
||||
$$
|
||||
\begin{aligned}
|
||||
P(\theta|X) &=c\cdot P(X|\theta) \pi(\theta) = c\cdot \mathrm{C}_{100}^{3} \theta^{3} (1-\theta)^{97} \frac{1}{B(2,200)} \theta^{1} (1-\theta)^{199} \\
|
||||
&=c \cdot \theta^{4} (1-\theta)^{296} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
其中$c$为与$\theta$无关的数。
|
||||
|
||||
所以$\theta$的后验分布为$Be(5,297)$。
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
299
数理统计/作业/第二周作业.tex
Normal file
299
数理统计/作业/第二周作业.tex
Normal file
@ -0,0 +1,299 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
\input{mysubpreamble}
|
||||
\begin{document}
|
||||
\setcounter{chapter}{5}
|
||||
\setcounter{section}{2}
|
||||
\section{统计量及其分布}
|
||||
\begin{enumerate}
|
||||
\questionandanswerSolution[1]{
|
||||
在一本书上我们随机地检查了10页,发现每页上的错误数为:
|
||||
$$
|
||||
4 \quad 5 \quad 6 \quad 0 \quad 3 \quad 1 \quad 4 \quad 2 \quad 1 \quad 4
|
||||
$$
|
||||
试计算其样本均值、样本方差和样本标准差。
|
||||
}{
|
||||
$$
|
||||
\bar{x}=\frac{4+5+6+0+3+1+4+2+1+4}{10} = 3
|
||||
$$
|
||||
$$
|
||||
s^{2}=\frac{1}{10-1}\sum_{i=1}^{10}(x_i-\bar{x})^{2}=\frac{34}{9} \approx 3.778
|
||||
$$
|
||||
$$
|
||||
s=\sqrt{\frac{34}{9}}\approx 1.944
|
||||
$$
|
||||
}
|
||||
\questionandanswerProof[2]{
|
||||
证明:对任意常数$c,d$,有
|
||||
$$
|
||||
\sum_{i=1}^{n}(x_i-c)(y_i-d)=\sum_{i=1}^{n}(x_i-\bar{x})(y_i-\bar{y})+n(\bar{x}-c)(\bar{y}-d)
|
||||
$$
|
||||
}{
|
||||
根据性质$\displaystyle \sum_{i=1}^{n}x_i=\sum_{i=1}^{n}\bar{x},\ \sum_{i=1}^{n}y_i=\sum_{i=1}^{n}\bar{y}$可得
|
||||
$$
|
||||
\begin{aligned}
|
||||
\text{右边}&=\sum_{i=1}^{n}(x_i-\bar{x})(y_i-\bar{y})+\sum_{i=1}^{n}(\bar{x}-c)(\bar{y}-d) \\
|
||||
&=\sum_{i=1}^{n}\left[ (x_i-\bar{x})(y_i-\bar{y})+(\bar{x}-c)(\bar{y}-d) \right] \\
|
||||
&=\sum_{i=1}^{n}(x_i y_i -\bar{x}y_i-\bar{y}x_i+\bar{x}\bar{y}+\bar{x}\bar{y}-\bar{x}d-\bar{y}c+cd) \\
|
||||
% &=\sum_{i=1}^{n}[(x_i-\bar{x})y_i - (x_i-\bar{x})\bar{y}+(\bar{x}-c)\bar{y}-(\bar{x}-c)d] \\
|
||||
% =\sum_{i=1}^{n}[(x_i-\bar{x}+\bar{x}-c)\bar{y}]
|
||||
&=\sum_{i=1}^{n}x_i y_i-\bar{x}\sum_{i=1}^{n}y_i -\bar{y}\sum_{i=1}^{n}x_i+n \bar{x}\bar{y} +n \bar{x}\bar{y}-n \bar{x}d- n\bar{y}c+ ncd \\
|
||||
&=\sum_{i=1}^{n}x_i y_i- n \bar{x}\bar{y} -n \bar{y}\bar{x}+n \bar{x}\bar{y}+n \bar{x}\bar{y}- \sum_{i=1}^{n}x_i d - \sum_{i=1}^{n}y_i c+\sum_{i=1}^{n}cd \\
|
||||
&=\sum_{i=1}^{n}(x_i y_i-x_id-y_ic+cd) \\
|
||||
&=\sum_{i=1}^{n}(x_i-c)(y_i-d) = \text{左边} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
}
|
||||
\questionandanswerSolution[3]{
|
||||
设$x_1,x_2, \cdots ,x_n$和$y_1,y_2, \cdots ,y_n$是两组样本观测值,且有如下关系:
|
||||
$$
|
||||
y_i=3 x_i-4, i=1,2, \cdots ,n
|
||||
$$
|
||||
试求样本均值$\bar{x}$和$\bar{y}$间的关系以及样本方差$s_{x}^{2}$和$s_{y}^{2}$间的关系。
|
||||
}{
|
||||
$$
|
||||
\bar{y}=\frac{1}{n}\sum_{i=1}^{n}y_i=\frac{1}{n}\sum_{i=1}^{n}(3 x_i-4)=3\cdot \frac{1}{n}\sum_{i=1}^{n} x_i -4=3\bar{x}-4
|
||||
$$
|
||||
$$
|
||||
\begin{aligned}
|
||||
s_{y}^{2}&=\frac{1}{n-1}\sum_{i=1}^{n} (y_i-\bar{y})^{2}=\frac{1}{n-1}\sum_{i=1}^{n} (3 x_i-4-(3 \bar{x}-4))^{2}=\frac{1}{n-1}\sum_{i=1}^{n} [3(x_i-\bar{x})]^{2} \\
|
||||
&=9 \cdot \frac{1}{n-1}\sum_{i=1}^{n} (x_i-\bar{x})^{2}=9 s_{x}^{2} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
}
|
||||
\questionandanswerProof[5]{
|
||||
从同一总体中抽取两个容量分别为$n,m$的样本,样本均值分别为$\bar{x}_1, \bar{x}_2$,样本方差分别为$s_1^{2}, s_2^{2}$,将两组样本合并,其均值、方差分别为$\bar{x}, s^{2}$,证明:
|
||||
$$
|
||||
\bar{x}=\frac{n \bar{x}_1+m \bar{x}_2}{n+m}
|
||||
$$
|
||||
$$
|
||||
s^{2}=\frac{(n-1)s_1^{2}+(m-1)s_2^{2}}{n+m-1}+\frac{nm(\bar{x}_1-\bar{x}_2)^{2}}{(n+m)(n+m+1)}
|
||||
$$
|
||||
}{
|
||||
$$
|
||||
\bar{x}=\frac{1}{n+m}\left( \sum_{i=1}^{n} x_{1_{i}} +\sum_{i=1}^{m} x_{2_{i}} \right) =\frac{n \bar{x}_1+m \bar{x}_2}{n+m}
|
||||
$$
|
||||
$$
|
||||
\begin{aligned}
|
||||
s^{2}&=\frac{1}{n+m-1} \left( \sum_{i=1}^{n} (x_{1i}-\bar{x})^{2}+\sum_{j=1}^{m} \left( x_{2j}-\bar{x} \right) ^{2} \right) \\
|
||||
&=\frac{1}{n+m-1}\left( \sum_{i=1}^{n} \left( x_{1i}-\frac{n \bar{x}_1+m \bar{x}_2}{n+m} \right) ^{2}+\sum_{i=1}^{n} \left( x_{2j}-\frac{n \bar{x}_1+m \bar{x}_2}{n+m} \right) ^{2} \right) \\
|
||||
&=\frac{(n-1)s_1^{2}+(m-1)s_2^{2}}{n+m-1}+\frac{nm(\bar{x}_1-\bar{x}_2)^{2}}{(n+m)(n+m+1)} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
}
|
||||
\questionandanswerSolution[8]{
|
||||
设$x_1,x_2, \cdots ,x_n$是来自$U(-1,1)$的样本,试求$E(\bar{x})$和$\operatorname{Var}(\bar{x})$。
|
||||
}{
|
||||
设随机变量$X \sim U(-1,1)$,则
|
||||
$$
|
||||
E(\bar{x})=EX=\frac{-1+1}{2}=0
|
||||
$$
|
||||
$$
|
||||
\operatorname{Var}(\bar{x})=\frac{\operatorname{Var}(X)}{n}=\frac{\frac{(-1-1)^{2}}{12}}{n}=\frac{1}{3n}
|
||||
$$
|
||||
}
|
||||
\questionandanswerProof[9]{
|
||||
设总体二阶矩存在,$x_1,x_2, \cdots ,x_n$是样本,证明$x_i-\bar{x}$与$x_j-\bar{x}\ (i\neq j)$的相关系数为$-(n-1)^{-1}$。
|
||||
}{
|
||||
根据样本均值的性质,$E(x_i-\bar{x})=E (x_j- \bar{x})=0$。
|
||||
|
||||
设随机变量$X$表示从总体中抽出的一个样本,则$EX^{2}$存在。
|
||||
$$
|
||||
E(x_i-\bar{x})(x_j-\bar{x})=E(x_i x_j - \bar{x} x_i - \bar{x} x_j + \bar{x}^{2})= E x_i x_j - \bar{x}E x_i - \bar{x} E x_j + \bar{x}^{2}
|
||||
$$
|
||||
将$x_i$与$x_j$看作独立的两次抽样,则$x_i,x_j\overset{\text{i.i.d.}}{\sim}X $,所以$E x_i x_j=E x_i E x_j=(EX)^{2},$\\
|
||||
$E x_i=EX, E x_j=EX$。
|
||||
所以
|
||||
$$
|
||||
E(x_i-\bar{x})(x_j-\bar{x})=(EX)^{2}-2 \bar{x}EX + \bar{x}^{2}=\frac{1}{1-n}=-(n-1)^{-1}
|
||||
$$
|
||||
}
|
||||
\questionandanswerProof[10]{
|
||||
设$x_1,x_2, \cdots ,x_n$为一个样本,$\displaystyle s^{2}=\frac{1}{n-1}\sum_{i=1}^{n} (x_i-\bar{x})^{2}$是样本方差,试证:
|
||||
$$
|
||||
\frac{1}{n(n-1)}\sum_{i<j}(x_i-x_j)^{2} =s^{2}
|
||||
$$
|
||||
}{
|
||||
$$
|
||||
\begin{aligned}
|
||||
% s^{2}= \frac{1}{n-1}\sum_{i=1}^{n} (x_i-\bar{x})^{2}=
|
||||
&\frac{1}{n(n-1)}\sum_{i<j}(x_i-x_j)^{2}=\frac{1}{n(n-1)} \sum_{i<j}(x_i-\bar{x}+\bar{x}-x_j)^{2} \\
|
||||
&=\frac{1}{n(n-1)}\sum_{i<j} [(x_i-\bar{x})^{2}+2(x_i-\bar{x})(\bar{x}-x_j)+(\bar{x}-x_j)^{2}] \\
|
||||
&=\frac{1}{n(n-1)}\cdot \frac{1}{2}\sum_{i=1,2, \cdots ,n;j=1,2, \cdots ,n} [(x_i-\bar{x})^{2}+2(x_i-\bar{x})(\bar{x}-x_j)+(\bar{x}-x_j)^{2}] \\
|
||||
&=\frac{1}{2n(n-1)}\left[ n \sum_{i=1}^{n} (x_i-\bar{x})^{2}+0+n\sum_{j=1}^{n} (x_j-\bar{x})^{2} \right] \\
|
||||
&=\frac{1}{n-1}\sum_{i=1}^{n} (x_i-\bar{x})^{2} = s^{2} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
}
|
||||
\questionandanswerProof[11]{
|
||||
设总体4阶中心距$\nu_4=E[x-E(x)]^{4}$存在,试证:对样本方差$\displaystyle s^{2}=\frac{1}{n-1} \sum_{i=1}^{n} (x_i-\bar{x})^{2}$,有
|
||||
$$
|
||||
\operatorname{Var}(s^{2})=\frac{n(\nu-\sigma^{4})}{(n-1)^{2}}-\frac{2(\nu_4-2\sigma^{4})}{(n-1)^{2}}+\frac{\nu-3\sigma^{4}}{n(n-1)^{2}}
|
||||
$$
|
||||
其中$\sigma^{2}$为总体$X$的方差。
|
||||
}{
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\text{右边}=\frac{n^{2}\nu_4-n^{2}\sigma^{4}-2n\nu_4+4n\sigma^{4}+\nu_4-3\sigma^{4}}{n(n-1)^{2}} \\
|
||||
&=\frac{\nu_4(n^{2}-2n+1)-\sigma^{4}(n^{2}-4n+3)}{n(n-1)^{2}} \\
|
||||
&=\frac{\nu_4(n-1)^{2}-\sigma^{4}(n-1)(n-3)}{n(n-1)^{2}} \\
|
||||
&=\frac{\nu_4}{n}-\frac{\sigma^{4}(n-3)}{n(n-1)} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
$$
|
||||
\begin{aligned}
|
||||
\text{左边}=E(s^{2})^{2}-(Es ^{2})^{2}=Es ^{4}-(Es ^{2})^{2}=E s^{4}-\sigma^{4}
|
||||
\end{aligned}
|
||||
$$
|
||||
实在证明不出来了。
|
||||
}
|
||||
\questionandanswerProof[12]{
|
||||
设总体$X$的3阶矩存在,若$x_1,x_2, \cdots ,x_n$是取自该总体的简单随机样本,$\bar{x}$为样本均值,$s^{2}$为样本方差,试证:$\operatorname{Cov}(\bar{x}, s^{2})=\dfrac{\nu_3}{n}$,其中$\nu_3=E[x-E(x)]^{3}$。
|
||||
}{
|
||||
$$
|
||||
E \bar{x}=EX, Es ^{2}=\operatorname{Var}X
|
||||
$$
|
||||
$$
|
||||
E(\bar{x} s^{2})=E\left( \frac{1}{n}\sum_{i=1}^{n} x_i+\frac{1}{n-1}\sum_{i=1}^{n} (x_i-\bar{x})^{2} \right)
|
||||
$$
|
||||
$$
|
||||
\operatorname{Var}\bar{x}=\frac{\operatorname{Var}X}{n}, \operatorname{Var}s ^{2}=\operatorname{Var}\left( \frac{1}{n-1}\sum_{i=1}^{n} (x_i-\bar{x})^{2} \right)
|
||||
$$
|
||||
也证明不出来了。
|
||||
}
|
||||
\questionandanswerSolution[15]{
|
||||
从指数总体$\operatorname{Exp}(\frac{1}{\theta})$抽取了40个样品,试求$\bar{x}$的渐近分布。
|
||||
}{
|
||||
设随机变量$X$表示从总体中抽出的一个样本,则
|
||||
$$
|
||||
EX=\frac{1}{\frac{1}{\theta}}=\theta,\ \operatorname{Var}X=\frac{1}{\left( \frac{1}{\theta} \right) ^{2}}=\theta^{2}
|
||||
$$
|
||||
所以$\bar{x}$的渐近分布为$N(\theta, \theta^{2})$。
|
||||
}
|
||||
\questionandanswerSolution[17]{
|
||||
设$x_1,x_2, \cdots x_{20}$是从二点分布$b(1,p)$抽取的样本,试求样本均值$\bar{x}$的渐近分布。
|
||||
}{
|
||||
设随机变量$X$表示从总体中抽出的一个样本,则
|
||||
$$
|
||||
EX=p,\ \operatorname{Var}X=p(1-p)
|
||||
$$
|
||||
所以$\bar{x}$的渐近分布为$N(p, p(1-p))$。
|
||||
}
|
||||
\questionandanswerSolution[23]{
|
||||
设总体$X$服从几何分布,即$P(X=k)=pq^{k-1}, k=1,2, \cdots $,其中$0<p<1,q=1-p,\\ x_1,x_2, \cdots ,x_n$为该总体的样本,求$x_{(n)}, x_{(1)}$的概率分布。
|
||||
}{
|
||||
设总体$X$的概率密度函数为$p(x)$,分布函数为$F(x)$,则
|
||||
$$
|
||||
F(x)=\sum_{k=1}^{\left\lfloor x \right\rfloor} pq^{k-1}=\frac{p-pq^{\left\lfloor x \right\rfloor}}{1-q}
|
||||
$$
|
||||
$$
|
||||
p_{x_{(n)}}(x)=\frac{n!}{(n-1)!}[F(x)]^{n-1}p(x)=n pq^{\left\lfloor x \right\rfloor-1}\left[ \frac{p-pq^{\left\lfloor x \right\rfloor}}{1-q} \right] ^{n-1}
|
||||
$$
|
||||
$$
|
||||
p_{x_{(1)}}=\frac{n!}{(n-1)!}[1-F(x)]^{n-1}p(x)=npq^{\left\lfloor x \right\rfloor-1}\left[ 1-\frac{p-pq^{\left\lfloor x \right\rfloor}}{1-q} \right] ^{n-1}
|
||||
$$
|
||||
}
|
||||
\questionandanswer[28]{
|
||||
设总体$X$的分布函数$F(x)$是连续的,$x_{(1)},x_{(2)}, \cdots ,x_{(n)}$为取自此总体的次序统计量,设$\eta_i=F(x_{(i)})$,试证:
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswerProof[-]{
|
||||
\item $\eta_1\leqslant \eta_2\leqslant \cdots\leqslant \eta_n$,且$\eta_i$是来自均匀分布$U(0,1)$总体的次序统计量。
|
||||
}{
|
||||
因为$x_{(1)}\leqslant x_{(2)}\leqslant \cdots\leqslant x_{(n)}$且$F(x)$单调,$\eta_i=F(x_{(i)})$,所以$\eta_1\leqslant \eta_2\leqslant \cdots\leqslant \eta_n$。
|
||||
}
|
||||
\questionandanswerProof[-]{
|
||||
\item $\displaystyle E(\eta_i)=\frac{i}{n+1}, \ \operatorname{Var}(\eta_i)=\frac{i(n+1-i)}{(n+1)^{2}(n+2)},1\leqslant i\leqslant n$
|
||||
}{
|
||||
设总体的概率密度函数为$p(x)$,则$\eta_i$的分布函数为
|
||||
$$
|
||||
p_{(i)}(x)=\frac{n!}{(i-1)!(n-i)!}[F(x)]^{i-1}[1-F(x)]^{n-i}p(x)
|
||||
$$
|
||||
$$
|
||||
\begin{aligned}
|
||||
E(\eta_i)&=\sum_{i=1}^{n} F(x_{(i)})p_{(i)}(x_{(i)}) \\
|
||||
&=\sum_{i=1}^{n} F(x_{(i)}) \frac{n!}{(i-1)!(n-i)!}[F(x_{(i)})]^{i-1}[1-F(x_{(i)})]^{n-i}p(x) \\
|
||||
&=\sum_{i=1}^{n} \frac{n!}{(i-1)!(n-i)!}[F(x_{(i)})]^{i}[1-F(x_{(i)})]^{n-i}p(x) \\
|
||||
\end{aligned}
|
||||
$$
|
||||
$$
|
||||
\operatorname{Var}(\eta_i)=
|
||||
$$
|
||||
实在是不会了。
|
||||
}
|
||||
\questionandanswerProof[-]{
|
||||
\item $\eta_i$和$\eta_j$的协方差矩阵为
|
||||
$
|
||||
\begin{bmatrix}
|
||||
\frac{a_1(1-a_1)}{n+2} & \frac{a_1(1-a_2)}{n+2} \\
|
||||
\frac{a_1(1-a_2)}{n+2} & \frac{a_2(1-a_2)}{n+2} \\
|
||||
\end{bmatrix}
|
||||
$
|
||||
,其中$\displaystyle a_1=\frac{i}{n+1}, a_2=\frac{j}{n+1}$。
|
||||
}{
|
||||
$$
|
||||
E(\eta_i)=\frac{i}{n+1},\ E(\eta_j)=\frac{j}{n+1},\ E(\eta_i \eta_j)=
|
||||
$$
|
||||
实在是不会了。
|
||||
}
|
||||
\end{enumerate}
|
||||
\questionandanswerProof[32]{
|
||||
设总体$X$的密度函数为
|
||||
$
|
||||
p(x)=\begin{cases}
|
||||
3x^{2},\quad & 0<x<1, \\
|
||||
0,\quad & \text{其他}, \\
|
||||
\end{cases}
|
||||
$
|
||||
,$x_{(1)}\leqslant x_{(2)}\leqslant \cdots\leqslant x_{(5)}$为容量为5的取自此总体的次序统计量,试证$\dfrac{x_{(2)}}{x_{(4)}}$与$x_{(4)}$相互独立。
|
||||
}{
|
||||
根据相互独立的定理,需要证明$\displaystyle \forall x,y,\ p_{\frac{x_{(2)}}{x_{(4)}}}(x)\cdot p_{x_{(4)}}(y)=p_{\frac{x_{(2)}}{x_{(4)}},x_{(4)}}(x,y)$,之后就不会了。
|
||||
}
|
||||
\questionandanswer[35]{
|
||||
对下列数据构造箱线图:\\
|
||||
472 \quad
|
||||
425 \quad
|
||||
447 \quad
|
||||
377 \quad
|
||||
341 \quad
|
||||
369 \quad
|
||||
412 \quad
|
||||
419 \quad
|
||||
400 \quad
|
||||
382 \quad
|
||||
366 \quad
|
||||
425 \quad
|
||||
399 \quad
|
||||
398 \quad
|
||||
423 \quad
|
||||
384 \quad
|
||||
418 \quad
|
||||
392 \quad
|
||||
372 \quad
|
||||
418 \quad
|
||||
374 \quad
|
||||
385 \quad
|
||||
439 \quad
|
||||
428 \quad
|
||||
429 \quad
|
||||
428 \quad
|
||||
430 \quad
|
||||
413 \quad
|
||||
405 \quad
|
||||
381 \quad
|
||||
403 \quad
|
||||
479 \quad
|
||||
381 \quad
|
||||
443 \quad
|
||||
441 \quad
|
||||
433 \quad
|
||||
419 \quad
|
||||
379 \quad
|
||||
386 \quad
|
||||
387 \quad
|
||||
}{
|
||||
\begin{center}
|
||||
\includegraphics[width=0.5\linewidth]{imgs/5.3.35.png}
|
||||
\end{center}
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
6
数理统计/作业/第五六周作业.tex
Normal file
6
数理统计/作业/第五六周作业.tex
Normal file
@ -0,0 +1,6 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
\input{mysubpreamble}
|
||||
\begin{document}
|
||||
\subfile{第五周作业}
|
||||
\subfile{第六周作业}
|
||||
\end{document}
|
216
数理统计/作业/第五周作业.tex
Normal file
216
数理统计/作业/第五周作业.tex
Normal file
@ -0,0 +1,216 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
\input{mysubpreamble}
|
||||
\begin{document}
|
||||
\renewcommand{\bar}{\xoverline}
|
||||
\renewcommand{\hat}{\xwidehat}
|
||||
\setcounter{chapter}{6}
|
||||
\section{点估计的概念与无偏性}
|
||||
\begin{enumerate}
|
||||
\questionandanswerProof[3]{
|
||||
设$\hat{\theta}$是参数$\theta$的无偏估计,且有$\operatorname{Var}(\hat{\theta})>0$,试证$(\hat{\theta})^{2}$不是$\theta^{2}$的无偏估计。
|
||||
}{
|
||||
由题意可知$E\hat{\theta}=\theta$,$\operatorname{Var}\hat{\theta}=E\hat{\theta}^{2}-(E\hat{\theta})^{2}>0$,所以$E\hat{\theta}^{2}>(E\hat{\theta})^{2}=\theta^{2}$,所以$\hat{\theta}^{2}$不是$\theta^{2}$的无偏估计。
|
||||
}
|
||||
\questionandanswerSolution[4]{
|
||||
设总体$X\sim N(\mu,\sigma^{2}), x_1,x_2, \cdots ,x_{n}$是来自该总体的一个样本。试确定常数$c$使$\displaystyle c\sum_{i=1}^{n-1} (x_{i+1}-x_{i})^{2}$为$\sigma^{2}$的无偏估计。
|
||||
}{
|
||||
$$
|
||||
\begin{aligned}
|
||||
Ec\sum_{i=1}^{n-1} (x_{i+1}-x_{i})^{2}&=Ec\sum_{i=1}^{n-1} (x_{i+1}^{2}-2x_{i}x_{i+1} + x_i^{2}) \\
|
||||
&=c\sum_{i=1}^{n-1} Ex_{i+1}^{2}-2c\sum_{i=1}^{n-1} Ex_{i}x_{i+1}+c\sum_{i=n}^{n-1} Ex_{i}^{2} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
因为总体$X\sim N(\mu,\sigma)$,所以$\forall i=1,2, \cdots ,n$ ,$Ex_{i}=\mu, \operatorname{Var}x_i=Ex_{i}^{2}-(Ex_{i})^{2}=\sigma^{2}$,从而$Ex_{i}^{2}=\sigma^{2}+\mu^{2}$。由于$x_i$与$x_{i+1}$独立,所以$Ex_{i}x_{i+1}=Ex_{i}\cdot Ex_{i+1}=\mu^{2}$。所以
|
||||
$$
|
||||
\begin{aligned}
|
||||
\text{上式}&=c \sum_{i=1}^{n-1} (\sigma^{2}+\mu^{2})-2c\sum_{i=1}^{n-1} \mu^{2}+c\sum_{i=1}^{n-1} (\sigma^{2}+\mu^{2}) \\
|
||||
&=2c(n-1)(\sigma^{2}+\mu^{2})-2c(n-1)\mu^{2} \\
|
||||
&=2c(n-1)\sigma^{2} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
所以当$\displaystyle c=\frac{1}{2(n-1)}$时,$\displaystyle c\sum_{i=1}^{n-1} (x_{i+1}-x_{i})^{2}$为$\sigma^{2}$的无偏估计。
|
||||
}
|
||||
\questionandanswerProof[5]{
|
||||
设$x_1,x_2, \cdots ,x_n$是来自下列总体的简单样本,
|
||||
$$
|
||||
p(x,\theta)=\begin{cases}
|
||||
1,\quad & \theta-\frac{1}{2}\leqslant x\leqslant \theta+\frac{1}{2} \\
|
||||
0,\quad & \text{其他} \\
|
||||
\end{cases}\quad -\infty<\theta<\infty
|
||||
$$
|
||||
证明样本均值$\bar{x}$及$\frac{1}{2}(x_{(1)}+x_{(n)})$都是$\theta$的无偏估计,问何者更有效?
|
||||
}{
|
||||
$E \bar{x}=\theta$,$\operatorname{Var}\bar{x}=\frac{1}{n}\times \frac{1}{12}=\frac{1}{12n}$。
|
||||
|
||||
而$E \frac{1}{2}(x_{(1)}+x_{(n)}) $为样本中最小值和最大值的平均,虽然计算不出,但理论上也应该是$\theta$。但是似乎不像样本均值一样覆盖了样本全部的信息,所以应该是$\operatorname{Var}\bar{x}\leqslant \operatorname{Var} \frac{1}{2}(x_{(1)}+x_{(n)})$,即$\bar{x}$更有效。
|
||||
}
|
||||
\questionandanswerSolution[9]{
|
||||
设有$k$台一起,已知用第$i$台仪器测量的标准差为$\sigma_i(i=1,2, \cdots ,k)$。用这些仪器独立地对某一物理量$\theta$各观察一次,分别得到$x_1,x_2, \cdots ,x_k$,设仪器都没有系统偏差。问$a_1,a_2, \cdots ,a_k$应取何值,方能使$\displaystyle \hat{\theta}=\sum_{i=1}^{k} a_i x_i$ 成为$\theta$的无偏估计,且方差达到最小?
|
||||
}{
|
||||
$$
|
||||
E \hat{\theta}=E\sum_{i=1}^{k} a_i x_i= \sum_{i=1}^{k} a_i E x_i=\theta \sum_{i=1}^{k} a_i=\theta \Longrightarrow \sum_{i=1}^{k} a_i=1
|
||||
$$
|
||||
$$
|
||||
\operatorname{Var} \hat{\theta}=\operatorname{Var} \sum_{i=1}^{k} a_i x_i=\sum_{i=1}^{k} a_i^{2} \operatorname{Var}x_i=\sum_{i=1}^{k} a_i^{2} \sigma_i^{2}
|
||||
$$
|
||||
所以原问题可以转化为
|
||||
$$
|
||||
\mathop{\arg\min}_{a_i}
|
||||
\quad \sum_{i=1}^{k} a_i^{2}\sigma_i^{2}
|
||||
\ \ ,\quad \text{s.t.}
|
||||
\ \ \sum_{i=1}^{k} a_i=1
|
||||
$$
|
||||
|
||||
对此可以使用拉格朗日乘数法。
|
||||
令
|
||||
$$
|
||||
f(a_1, \cdots ,a_n, \lambda)=\sum_{i=1}^{k} a_i^{2}\sigma_i^{2}+\lambda \left( \sum_{i=1}^{k} a_i - 1 \right)
|
||||
$$
|
||||
则
|
||||
$$
|
||||
\begin{cases}
|
||||
\forall i=1,2, \cdots ,k,\quad f'_{a_i}=2 a_i \sigma_i^{2}+\lambda=0 \\
|
||||
f'_{\lambda}=\sum_{i=1}^{k} a_i - 1=0 \\
|
||||
\end{cases}
|
||||
$$
|
||||
解得
|
||||
$$
|
||||
\begin{cases}
|
||||
\forall i=1,2, \cdots ,k, \quad a_i=\displaystyle \frac{\frac{1}{2\sigma_i^{2}}}{\sum_{i=1}^{k} \frac{1}{2\sigma_i^{2}}} \\
|
||||
\lambda=\displaystyle -\frac{1}{\sum_{i=1}^{k} \frac{1}{2\sigma_i^{2}}} \\
|
||||
\end{cases}
|
||||
$$
|
||||
|
||||
所以$\forall i=1,2, \cdots ,k, \quad a_i=\displaystyle \frac{\frac{1}{2\sigma_i^{2}}}{\sum_{i=1}^{k} \frac{1}{2\sigma_i^{2}}}$,方能使$\displaystyle \hat{\theta}=\sum_{i=1}^{k} a_i x_i$ 成为$\theta$的无偏估计,且方差达到最小。
|
||||
}
|
||||
\questionandanswerSolution[11]{
|
||||
设总体$X$服从正态分布$N(\mu,\sigma^{2})$,$x_1,x_2, \cdots ,x_n$为来自总体$X$的样本,为了得到标准差$\sigma$的估计量,考虑统计量:
|
||||
$$
|
||||
y_1=\frac{1}{n}\sum_{i=1}^{n} \left\vert x_i-\bar{x} \right\vert ,\quad \bar{x}=\frac{1}{n}\sum_{i=1}^{n} x_i, \quad n\geqslant 2
|
||||
$$
|
||||
$$
|
||||
y_2=\frac{1}{n(n-1)} \sum_{i=1}^{n} \sum_{j=1}^{n} \left\vert x_i-x_j \right\vert ,\quad n\geqslant 2
|
||||
$$
|
||||
求常数$C_1$与$C_2$,使得$C_1y_1$与$C_2y_2$都是$\sigma$的无偏估计。
|
||||
}{
|
||||
由于$\forall i,j=1,2, \cdots ,n(i\neq j), \quad x_i\sim N(\mu,\sigma^{2}),x_j\sim N(\mu,\sigma^{2}), \bar{x}\sim N(\mu,\frac{\sigma^{2}}{n})$且它们应该相互独立。
|
||||
所以
|
||||
$$
|
||||
x_i-\bar{x}\sim N(0, \sigma^{2}+\frac{\sigma^{2}}{n}), \quad x_i-x_j\sim N(0, 2\sigma^{2})
|
||||
$$
|
||||
因为$Y\sim N(0,\sigma^{2})$时$E\left\vert Y \right\vert =\sigma \sqrt{\frac{2}{\pi}}$,所以
|
||||
$$
|
||||
E\left\vert x_i-\bar{x} \right\vert =\sqrt{\sigma^{2}+\frac{\sigma^{2}}{n}}\sqrt{\frac{2}{\pi}}=\sigma\sqrt{1+\frac{1}{n}}\sqrt{\frac{2}{\pi}}, \quad E\left\vert x_i-x_j \right\vert = \sqrt{2}\sigma\sqrt{\frac{2}{\pi}}=\frac{2\sigma}{\sqrt{\pi}}
|
||||
$$
|
||||
所以
|
||||
$$
|
||||
EC_1y_1=C_1\frac{1}{n}\times n \cdot \sigma\sqrt{1+\frac{1}{n}}\sqrt{\frac{2}{\pi}}=\sigma \Longrightarrow C_1=\frac{1}{\sqrt{1+\frac{1}{n}}\sqrt{\frac{2}{\pi}}} = \sqrt{\frac{n\pi}{2n+2}}
|
||||
$$
|
||||
$$
|
||||
EC_2y_2=C_2 \frac{1}{n(n-1)} (n^{2}-n) \cdot \frac{2\sigma}{\sqrt{\pi}}=\sigma \Longrightarrow C_2=\frac{\sqrt{\pi}}{2}
|
||||
$$
|
||||
|
||||
所以
|
||||
$$
|
||||
C_1=\sqrt{\frac{n\pi}{2n+2}}, \quad C_2=\frac{\sqrt{\pi}}{2}
|
||||
$$
|
||||
}
|
||||
\end{enumerate}
|
||||
\section{矩估计及相合性}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[3]{
|
||||
设总体分布列如下,$x_1,x_2, \cdots ,x_n$是样本,试求未知参数的矩估计:
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswerSolution[]{
|
||||
$P(X=k)=\frac{1}{N}, k=0,1,2, \cdots ,N-1$,$N$(正整数)是未知参数;
|
||||
}{
|
||||
$$
|
||||
EX = \sum_{k=0}^{N-1} k \cdot \frac{1}{N}=\frac{1}{N}\cdot \frac{N(N-1)}{2}=\frac{N-1}{2}
|
||||
$$
|
||||
所以$N=2EX+1$,所以$N$的矩估计为
|
||||
$$
|
||||
\hat{N}=2 \bar{x}+1
|
||||
$$
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
$P(X=k)=(k-1)\theta^{2}(1-\theta)^{k-2},\quad k=2,3, \cdots ,\quad 0<\theta<1$。
|
||||
}{
|
||||
$\displaystyle
|
||||
EX=\sum_{k=2}^{\infty} k(k-1)\theta^{2}(1-\theta)^{k-2} = \frac{2}{\theta}
|
||||
$
|
||||
,所以$\theta=\dfrac{2}{EX}$,所以$\theta$的矩估计为
|
||||
$\displaystyle
|
||||
\hat{\theta}=\frac{2}{\bar{x}}
|
||||
$。
|
||||
}
|
||||
\end{enumerate}
|
||||
\questionandanswer[4]{
|
||||
设总体密度函数如下,$x_1,x_2, \cdots ,x_n$是样本,试求未知参数的矩估计:
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswerSolution[]{
|
||||
$p(x;\theta)=\frac{2}{\theta^{2}}(\theta-x),\quad 0<x<\theta, \quad \theta>0$;
|
||||
}{
|
||||
$\displaystyle
|
||||
EX=\int_{0}^{\theta} x\frac{2}{\theta^{2}}(\theta-x) \mathrm{d}x = \frac{\theta}{3}
|
||||
$
|
||||
,所以$\theta=3EX$,所以$\theta$的矩估计是$\hat{\theta}=3 \bar{x}$。
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
$p(x;\theta)=(\theta+1)x^{\theta},\quad 0<x<1,\quad \theta>0$;
|
||||
}{
|
||||
$\displaystyle EX=\int_{0}^{1} x(\theta+1)x^{\theta} \mathrm{d}x = \frac{\theta + 1}{\theta + 2} $,所以$\theta$的矩估计是$\displaystyle \hat{\theta}=\frac{1}{1-\bar{x}}-2$。
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
$p(x;\theta)=\sqrt{\theta}x^{\sqrt{\theta}-1},\quad 0<x<1, \quad ,\theta>0$;
|
||||
}{
|
||||
$\displaystyle
|
||||
EX=\int_{0}^{1} x\sqrt{\theta}x^{\sqrt{\theta}-1} \mathrm{d}x = \frac{\sqrt{\theta}}{\sqrt{\theta} + 1}
|
||||
$
|
||||
,所以$\theta$的矩估计是$\displaystyle \hat{\theta}=\left( \frac{\bar{x}}{1-\bar{x}} \right) ^{2}$。
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
$\displaystyle p(x;\theta,\mu)=\frac{1}{\theta}e^{-\frac{x-\mu}{\theta}}, \quad x>\mu,\quad \theta>0$。
|
||||
}{
|
||||
$$
|
||||
EX=\int_{\mu}^{+\infty} x \cdot \frac{1}{\theta}e^{-\frac{x-\mu}{\theta}} \mathrm{d}x=\theta+\mu
|
||||
$$
|
||||
$$
|
||||
EX^{2}=\int_{\mu}^{+\infty} x^{2}\cdot \frac{1}{\theta}e^{-\frac{x-\mu}{\theta}} \mathrm{d}x = 2\theta^{2}+2\mu \theta+\mu^{2}
|
||||
$$
|
||||
$$
|
||||
\operatorname{Var}X=EX^{2}-(EX)^{2}=2\theta^{2}+2\mu \theta+\mu^{2}-(\theta+\mu)^{2} = \theta^{2}
|
||||
$$
|
||||
所以$\theta$和$\mu$的矩估计是
|
||||
$$
|
||||
\hat{\theta}=s, \quad \hat{\mu}=\bar{x}-s
|
||||
$$
|
||||
}
|
||||
\end{enumerate}
|
||||
\questionandanswerSolution[5]{
|
||||
设总体为$N(\mu,1)$,现对该总体观测$n$次,发现有$k$次观测值为正,使用频率替换方法求$\mu$的估计。
|
||||
}{
|
||||
设总体为$X$,则根据频率替换方法,$P(X>0)=\dfrac{k}{n}$。设标准正态分布的累积分布函数为$\Phi(x)$,则
|
||||
$$
|
||||
\frac{k}{n}=P(X>0)=P\left( \frac{x-\mu}{1}>\frac{0-\mu}{1} \right) =1-P\left( \frac{x-\mu}{1}\leqslant -\mu \right) =1-\Phi(-\mu)
|
||||
$$
|
||||
所以$\mu$的估计为
|
||||
$$
|
||||
\hat{\mu}=-\Phi^{-1}(1-\frac{k}{n})
|
||||
$$
|
||||
}
|
||||
\questionandanswerSolution[7]{
|
||||
设总体$X$服从二项分布$b(m,p)$,其中$m,p$为未知参数,$x_1,x_2, \cdots ,x_n$为$X$的一个样本,求$m$与$p$的矩估计。
|
||||
}{
|
||||
因为
|
||||
$\displaystyle
|
||||
EX=mp,\ \operatorname{Var}X=mp(1-p)
|
||||
$
|
||||
,所以$\displaystyle p=1-\frac{\operatorname{Var}X}{EX}$,$\displaystyle m=\frac{EX}{p}=\frac{(EX)^{2}}{EX-\operatorname{Var}X}$,所以$m$与$p$的矩估计为
|
||||
$$
|
||||
m=1-\frac{s}{\bar{x}},\qquad p=\frac{\bar{x}^{2}}{\bar{x}-s}
|
||||
$$
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
268
数理统计/作业/第六周作业.tex
Normal file
268
数理统计/作业/第六周作业.tex
Normal file
@ -0,0 +1,268 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
\input{mysubpreamble}
|
||||
\begin{document}
|
||||
\renewcommand{\bar}{\xoverline}
|
||||
\renewcommand{\hat}{\xwidehat}
|
||||
\setcounter{chapter}{6}
|
||||
\section{最大似然估计与EM算法}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[2]{
|
||||
设总体概率函数如下,$x_1,x_2, \cdots ,x_n$是样本,试求未知参数的最大似然估计。
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswerSolution[]{
|
||||
$p(x;\theta)=c \theta^{c} x^{-(c+1)},x>\theta,\theta>0,c>0$已知;
|
||||
}{
|
||||
对数似然函数
|
||||
$$
|
||||
\begin{aligned}
|
||||
\ln L(\theta)&=\ln \prod_{i=1}^{n} p(x_i|\theta)=\ln \prod_{i=1}^{n} c \theta^{c} x_i^{-(c+1)} \\
|
||||
&= \sum_{i=1}^{n} \ln (c\theta^{c}x_i^{-(c+1)})=\sum_{i=1}^{n} (\ln c+c\ln \theta-(c+1)\ln x_i) \\
|
||||
&=n\ln c+nc\ln \theta-(c+1)\sum_{i=1}^{n} \ln x_i \\
|
||||
\end{aligned}
|
||||
$$
|
||||
只需要让$\theta$尽量大即可使似然函数取到最大值,又因为$\theta<x$,所以$\theta$的最大似然估计为$\hat{\theta}=x_{(1)}$。
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
$p(x;\theta,\mu)=\displaystyle \frac{1}{\theta}e^{-\frac{x-\mu}{\theta}},x>\mu,\theta>0$;
|
||||
}{
|
||||
对数似然函数
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\ln L(\theta,\mu)=\ln \prod_{i=1}^{n} p(x;\theta,\mu)=\ln \prod_{i=1}^{n} \frac{1}{\theta}e^{-\frac{x-\mu}{\theta}} \\
|
||||
&=\sum_{i=1}^{n} \ln \left( \frac{1}{\theta}e^{-\frac{x-\mu}{\theta}} \right) =\sum_{i=1}^{n} (-\ln \theta-\frac{x-\mu}{\theta}) \\
|
||||
&=-n\ln \theta - \frac{1}{\theta}\sum_{i=1}^{n} x_i+\frac{n\mu}{\theta} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
|
||||
对于$\mu$,由于$\ln L(\theta,\mu)$关于$\mu$是线性关系,所以只需要$\mu$尽量大即可使似然函数取到最大值,而$\mu<x$,所以$\hat{\mu}=x_{(1)}$。
|
||||
|
||||
对于$\theta$,则需要求偏导,令
|
||||
$$
|
||||
\frac{\partial \ln L(\theta,\mu)}{\partial \theta}=-\frac{n}{\theta}+\frac{1}{\theta^{2}}\sum_{i=1}^{n} x_i-\frac{n\mu}{\theta^{2}}=0
|
||||
$$
|
||||
则可解得$\theta=\displaystyle \frac{1}{n}\sum_{i=1}^{n} x_i-\mu = \bar{x}-\mu$。此时$\ln L(\theta,\mu)$关于$\theta$最大。
|
||||
|
||||
所以$\hat{\mu}=x_{(1)}$, $\hat{\theta}=\bar{x}-x_{(1)}$。
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
$p(x;\theta)=(k\theta)^{-1}, \theta<x<(k+1)\theta, \theta>0,k>0$已知。
|
||||
}{
|
||||
对数似然函数
|
||||
$$
|
||||
\ln L(\theta)=\ln \prod_{i=1}^{n} (k\theta)^{-1}=\sum_{i=1}^{n} \ln (k\theta)^{-1}=\sum_{i=1}^{n} (-k\theta)=-nk\theta
|
||||
$$
|
||||
只要$\theta$尽量小即可使似然函数取得最大值。由于$\theta<x<(k+1)\theta$且$k>0$,所以$\frac{\theta}{k+1}<\frac{x}{k+1}<\theta$,所以$\theta$的最大似然估计为$\hat{\theta}=\dfrac{x_{(n)}}{k+1}$。
|
||||
}
|
||||
\end{enumerate}
|
||||
\questionandanswerSolution[4]{
|
||||
一地质学家为研究密歇根湖的湖滩地区的岩石成分,随机地自该地区取100个样品,每个样品有10块石子,记录了每个样品中属石灰石的石子数。假设这100次观察柜互独立,求这地区石子中石灰石的比例$p$的最大似然估计。该地质学家所得的数据如下:
|
||||
|
||||
\begin{tabular}{c|ccccccccccc}
|
||||
样本中的石子数 & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 \\
|
||||
\hline
|
||||
样品个数 & 0 & 1 & 6 & 7 & 23 & 26 & 21 & 12 & 3 & 1 & 0 \\
|
||||
\end{tabular}
|
||||
}{
|
||||
当已知石灰石的比例为$p$时,并且如果每次抽样都是随机抽样,那么每个石子是石灰石的概率就是$p$,由于每个样品有10块石子,所以一次抽样服从二项分布$b(10,p)$,则概率函数为
|
||||
$$
|
||||
p(k;p)=\mathrm{C}_{10}^{k}p^{k}(1-p)^{10-k}
|
||||
$$
|
||||
|
||||
设表格中的第一行为$x_i(i=0,1, \cdots ,10)$,第二行为$a_i(i=0,1, \cdots, 10)$,则对数似然函数为
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\ln L(p)=\ln \prod_{i=1}^{n} \left( \mathrm{C}_{10}^{x_i} p^{x_i}(1-p)^{10-x_i} \right) ^{a_i} \\
|
||||
&=\sum_{i=1}^{n} a_i\left( \ln \mathrm{C}_{10}^{x_i}+x_i\ln p+(10-x_i)\ln (1-p) \right) \\
|
||||
&=\sum_{i=1}^{n} a_i \ln \mathrm{C}_{10}^{x_i} +\ln p \sum_{i=1}^{n} a_i x_i+\ln (1-p)\sum_{i=1}^{n} a_i(10-x_i) \\
|
||||
\end{aligned}
|
||||
$$
|
||||
令
|
||||
$$
|
||||
\frac{\mathrm{d}\ln L(p)}{\mathrm{d}p} = \frac{\sum_{i=1}^{n} a_i x_i}{p}-\frac{\sum_{i=1}^{n} a_i(10-x_i)}{1-p}=0
|
||||
$$
|
||||
解得
|
||||
$$
|
||||
p=\frac{\sum_{i=1}^{n} a_i x_i}{10 \sum_{i=1}^{n} a_i}= \frac{\sum_{i=1}^{n} a_i \frac{x_i}{10}}{\sum_{i=1}^{n} a_i}
|
||||
$$
|
||||
即以样品个数为权重,样品中石灰石比例的加权平均值。
|
||||
|
||||
所以
|
||||
$$
|
||||
\hat{p}=\frac{\sum_{i=1}^{n} a_i x_i}{10 \sum_{i=1}^{n} a_i} = \frac{
|
||||
\begin{split}
|
||||
0\times 0+1\times 1+6\times 2+7\times 3+23\times 4+26\times 5 \\+21\times 6+12\times 7+3\times 8+1\times 9+0\times 10
|
||||
\end{split}
|
||||
}{10\times 100} = 0.499
|
||||
$$
|
||||
}
|
||||
\questionandanswerSolution[5]{
|
||||
在遗传学研究中经常要从截尾二项分布中抽样,其总体概率函数为
|
||||
$$
|
||||
p(X=k;p)=\frac{\displaystyle \binom{m}{k}p^{k}(1-p)^{m-k}}{1-(1-p)^{m}},\quad k=1,2, \cdots ,m
|
||||
$$
|
||||
若已知$m=2,x_1,x_2, \cdots ,x_n$是样本,试求$p$的最大似然估计。
|
||||
}{
|
||||
对数似然函数为
|
||||
$$
|
||||
\begin{aligned}
|
||||
\ln L(p)&= \ln \prod_{i=1}^{n} \frac{\displaystyle \binom{m}{x_i}p^{x_i}(1-p)^{m-x_i}}{1-(1-p)^{m}} \\
|
||||
&=\sum_{i=1}^{n} \left[ \ln \binom{m}{x_i}+x_i\ln p+(m-x_i)\ln (1-p)-\ln (1-(1-p)^{m}) \right] \\
|
||||
&=\sum_{i=1}^{n} \ln \binom{m}{x_i}+\ln p \sum_{i=1}^{n} x_i+\ln (1-p)\sum_{i=1}^{n} (m-x_i)-n\ln (1-(1-p)^{m}) \\
|
||||
\end{aligned}
|
||||
$$
|
||||
令
|
||||
$$
|
||||
\frac{\mathrm{d}\ln L(p)}{\mathrm{d}p}=\frac{\sum_{i=1}^{n} x_i}{p}-\frac{\sum_{i=1}^{n} (m-x_i)}{1-p}-n \frac{-m(1-p)^{m-1}}{1-(1-p)^{m}}=0
|
||||
% m=2
|
||||
% solve(latex2sympy(r"\frac{\sum_{i=1}^{n} x_i}{p}-\frac{\sum_{i=1}^{n} (m-x_i)}{1-p}-n \frac{-m(1-p)^{m-1}}{1-(1-p)^{m}}=0"), p)
|
||||
$$
|
||||
由于$m=2$,所以
|
||||
$$
|
||||
\frac{\sum_{i=1}^{n} x_i}{p}-\frac{\sum_{i=1}^{n} (2-x_i)}{1-p}+\frac{2n(1-p)}{1-(1-p)^{2}}=0
|
||||
% [ p = - \frac{\sqrt{(- 8 n x_{i} + 16 n + x_{i}^{2} \sum_{i=1}^{n} 1 - 8 x_{i} \sum_{i=1}^{n} 1 + 16 \sum_{i=1}^{n} 1) \sum_{i=1}^{n} 1}}{2 \cdot (2 n + 2 \sum_{i=1}^{n} 1)} + \frac{4 n + 2 \sum_{i=1}^{n} 2 + 2 \sum_{i=1}^{n} - x_{i} + 3 \sum_{i=1}^{n} x_{i}}{2 \cdot (2 n + \sum_{i=1}^{n} 2 + \sum_{i=1}^{n} - x_{i} + \sum_{i=1}^{n} x_{i})}, \ p = \frac{\sqrt{(- 8 n x_{i} + 16 n + x_{i}^{2} \sum_{i=1}^{n} 1 - 8 x_{i} \sum_{i=1}^{n} 1 + 16 \sum_{i=1}^{n} 1) \sum_{i=1}^{n} 1}}{2 \cdot (2 n + 2 \sum_{i=1}^{n} 1)} + \frac{4 n + 2 \sum_{i=1}^{n} 2 + 2 \sum_{i=1}^{n} - x_{i} + 3 \sum_{i=1}^{n} x_{i}}{2 \cdot (2 n + \sum_{i=1}^{n} 2 + \sum_{i=1}^{n} - x_{i} + \sum_{i=1}^{n} x_{i})}, \ n = \frac{- p (p - 1)^{2} (\sum_{i=1}^{n} x_{i} + \sum_{i=1}^{n} (2 - x_{i})) + p (\sum_{i=1}^{n} x_{i} + \sum_{i=1}^{n} (2 - x_{i})) + (p - 1)^{2} \sum_{i=1}^{n} x_{i} - \sum_{i=1}^{n} x_{i}}{2 p (p - 1)^{2}}]
|
||||
$$
|
||||
即
|
||||
$$
|
||||
\frac{n \bar{x}}{p}- \frac{2-n \bar{x}}{1-p}+\frac{2n(1-p)}{1-(1-p)^{2}}=0
|
||||
$$
|
||||
解得$p$的最大似然估计为
|
||||
$$
|
||||
\hat{p} = \frac{\bar{x} n + 4 n + 4}{4 (n + 1)} \pm \frac{\sqrt{\bar{x}^{2} n^{2} - 8 \bar{x} n^{2} - 8 \bar{x} n + 16 n + 16}}{4 (n + 1)}
|
||||
$$
|
||||
}
|
||||
\questionandanswerSolution[6]{
|
||||
已知在文学家萧伯纳的 "The Intelligent Woman's Guide to Socialism and Capitalism" 一书中 ,一个句子的单词数$X$近似地服从对数正态分布,即$Z=\ln X\sim N(\mu,\sigma^{2})$。今从该书中随机地取20个句子,这些句子中的单词数分别为
|
||||
$$
|
||||
52\quad24\quad15\quad67\quad15\quad22\quad63\quad26\quad16\quad32\quad7\quad33\quad28\quad14\quad7\quad29\quad10\quad6\quad59\quad30
|
||||
$$
|
||||
求该书中一个句子单词数均值$E(X)=e^{\mu+\frac{\sigma^{2}}{2}}$的最大似然估计。
|
||||
}{}
|
||||
|
||||
{\kaishu
|
||||
根据题意,由于$Z=\ln X \sim N(\mu,\sigma^{2})$,可以将一个句子的单词数先取自然对数,此时即可使用正态分布的最大似然估计来估计$\mu$和$\sigma^{2}$。
|
||||
\begin{minted}[frame=single]{python}
|
||||
import numpy as np
|
||||
|
||||
a = np.array([52,24,15,67,15,22,63,26,16,32,7,33,28,14,7,29,10,6,59,30])
|
||||
print(np.log(a))
|
||||
# [3.95124372 3.17805383 2.7080502 4.20469262 2.7080502 3.09104245
|
||||
# 4.14313473 3.25809654 2.77258872 3.4657359 1.94591015 3.49650756
|
||||
# 3.33220451 2.63905733 1.94591015 3.36729583 2.30258509 1.79175947
|
||||
# 4.07753744 3.40119738]
|
||||
|
||||
print(np.mean(np.log(a)))
|
||||
# 3.0890326915239807
|
||||
print(np.var(np.log(a)))
|
||||
# 0.5081312851436304
|
||||
\end{minted}
|
||||
|
||||
所以$\hat{\mu}\approx 3.0890326915239807$, $\widehat{(\sigma^{2})}\approx 0.5081312851436304$。
|
||||
|
||||
再根据最大似然估计的不变性,直接计算$\displaystyle e^{\hat{\mu}+\frac{\widehat{(\sigma^{2})}}{2}}$。
|
||||
\begin{minted}[frame=single]{python}
|
||||
np.exp(np.mean(np.log(a)) + np.var(np.log(a)) / 2)
|
||||
# 28.306694575039742
|
||||
\end{minted}
|
||||
|
||||
则该书中一个句子单词数均值$E(X)=e^{\mu+\frac{\sigma^{2}}{2}}$的最大似然估计约为$28.306694575039742$。
|
||||
}
|
||||
\questionandanswer[7]{
|
||||
设总体$X\sim U(\theta,2\theta)$,其中$\theta>0$是未知参数,$x_1,x_2, \cdots ,x_n$为取自该总体的样本,$\bar{x}$为样本均值。
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswerProof[]{
|
||||
证明$\hat{\theta}=\dfrac{2}{3} \bar{x}$是参数$\theta$的无偏估计和相合估计;
|
||||
}{
|
||||
$$
|
||||
E \hat{\theta}=E \frac{2}{3} \bar{x}= E \frac{2}{3} \frac{1}{n}\sum_{i=1}^{n} x_i=\frac{2}{3} \frac{1}{n} \sum_{i=1}^{n} EX=\frac{2}{3} \frac{1}{n} n \frac{\theta+2\theta}{2}=\theta
|
||||
$$
|
||||
$$
|
||||
\operatorname{Var} \hat{\theta}=\operatorname{Var} \frac{2}{3} \bar{x}=\frac{2}{3} \frac{n \operatorname{Var}X}{n^{2}}=\frac{2\operatorname{Var}X}{3n} \xrightarrow{n \to \infty} 0
|
||||
$$
|
||||
所以$\hat{\theta} = \dfrac{2}{3} \bar{x}$是参数$\theta$的无偏估计和相合估计。
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
求$\theta$的最大似然估计,它是无偏估计吗?是相合估计吗?
|
||||
}{
|
||||
$$
|
||||
\ln L(\theta)= \ln \prod_{i=1}^{n} 1_{[\theta,2\theta]}(x_i) \cdot \frac{1}{\theta}=\frac{1}{\theta} \sum_{i=1}^{n} \ln 1_{[\theta,2\theta]}(x_i)
|
||||
$$
|
||||
要使似然函数最大,则需要$\theta$尽量小,同时要满足$\theta\leqslant x_i\leqslant 2\theta$,即$\frac{\theta}{2}\leqslant \frac{x_i}{2}\leqslant \theta$,所以$\theta$的最大似然估计为$\hat{\theta}=\dfrac{x_{(n)}}{2}$。
|
||||
|
||||
下面验证无偏性。
|
||||
$$
|
||||
E \hat{\theta}=\frac{1}{2} \int_{\theta}^{2\theta} x \frac{n}{\theta} \left( \frac{x-\theta}{\theta} \right) ^{n-1} \mathrm{d}x = \frac{\theta (2 n + 1)}{2 (n + 1)} \xrightarrow{n \to \infty} \theta
|
||||
$$
|
||||
所以$\hat{\theta}$不是无偏估计,但是是渐近无偏估计。
|
||||
|
||||
下面验证相合性。
|
||||
$$
|
||||
E \hat{\theta}^{2} = \frac{1}{4} \int_{\theta}^{2\theta} x^{2} \frac{n}{\theta} \left( \frac{x-\theta}{\theta} \right) ^{n-1} \mathrm{d}x=\frac{\theta^{2} (n^{2} + 2 n + \frac{1}{2})}{n^{2} + 3 n + 2}
|
||||
$$
|
||||
$$
|
||||
\operatorname{Var}\hat{\theta} = E\hat{\theta}^{2} - (E \hat{\theta})^{2}=
|
||||
\frac{n \theta^{2}}{4 (n^{3} + 4 n^{2} + 5 n + 2)} \xrightarrow{n \to \infty} 0
|
||||
$$
|
||||
所以$\hat{\theta}$是相合估计。
|
||||
}
|
||||
\end{enumerate}
|
||||
\questionandanswer[8]{
|
||||
设$x_1,x_2, \cdots ,x_n$是来自密度函数为$p(x;\theta)=e^{-(x-\theta)},x>\theta$的总体的样本。
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswerSolution[]{
|
||||
求$\theta$的最大似然估计$\hat{\theta}_1$,它是否是相合估计?是否是无偏估计?
|
||||
}{
|
||||
$$
|
||||
\ln L(\theta)= \ln \prod_{i=1}^{n} e^{-(x-\theta)}=\sum_{i=1}^{n} (-(x_i-\theta))= -\sum_{i=1}^{n} x_i+ n \theta
|
||||
$$
|
||||
要让似然函数最大,$\theta$要尽量大,同时$\theta<x$,所以$\theta$的最大似然估计为$\hat{\theta}=x_{(1)}$。
|
||||
|
||||
$\hat{\theta}=x_{(1)}$的概率函数为
|
||||
$$
|
||||
p(x)=n \left[1-\int_{\theta}^{x} e^{-(t-\theta)} \mathrm{d}t\right]^{n-1} e^{-(x-\theta)} = n (e^{\theta - x})^{n}
|
||||
$$
|
||||
则可以验证无偏性
|
||||
$$
|
||||
E \hat{\theta}_1= \int_{\theta}^{+\infty} x n(e^{\theta-x})^{n} \mathrm{d}x = \frac{1}{n} + \theta \xrightarrow{n \to \infty} \theta
|
||||
$$
|
||||
所以$\hat{\theta}_1$不是无偏估计,但是是渐近无偏估计。
|
||||
|
||||
下面验证相合性。
|
||||
$$
|
||||
E \hat{\theta}_1^{2}=\int_{\theta}^{+\infty} x^{2}n(e^{\theta-x})^{n} \mathrm{d}x=\frac{2}{n^{2}}+\frac{2}{n} \theta+\theta^{2}
|
||||
$$
|
||||
$$
|
||||
\operatorname{Var} \hat{\theta}_1=E \hat{\theta}_1^{2}-(E \hat{\theta})^{2}=\frac{2}{n^{2}}+\frac{2}{n}\theta+\theta^{2}- \left( \frac{1}{n}+\theta \right) ^{2} = \frac{1}{n^{2}} \xrightarrow{n \to \infty} 0
|
||||
$$
|
||||
所以$\hat{\theta}_1$是相合估计。
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
求$\theta$的矩估计$\hat{\theta}_2$,它是否是相合估计?是否是无偏估计?
|
||||
}{
|
||||
$$
|
||||
EX=\int_{\theta}^{+\infty} x e^{-(x-\theta)} \mathrm{d}x = \theta + 1
|
||||
$$
|
||||
所以$\hat{\theta}_2=1- \bar{x}$。
|
||||
$$
|
||||
E \hat{\theta}_2=E(1-\bar{x})=1-EX=\theta
|
||||
$$
|
||||
所以$\hat{\theta}_2$是无偏估计。
|
||||
$$
|
||||
\operatorname{Var} \hat{\theta}_2=\operatorname{Var}(1-\bar{x})=\frac{\operatorname{Var}X}{n} \xrightarrow{n \to \infty} 0
|
||||
$$
|
||||
所以$\hat{\theta}_2$是相合估计。
|
||||
}
|
||||
\end{enumerate}
|
||||
\questionandanswerProof[10]{
|
||||
证明:对正态分布$N(\mu,\sigma^{2})$,若只有一个观测值,则$\mu,\sigma^{2}$的最大似然估计不存在。
|
||||
}{
|
||||
设此观测值为$x$,则似然函数为
|
||||
$$
|
||||
L(\mu, \theta)=\frac{1}{\sqrt{2\pi}} e^{-\left( \frac{x-\mu}{\sigma} \right) ^{2}}
|
||||
$$
|
||||
要使似然函数最大,则$\left( \frac{x-\mu}{\sigma} \right) ^{2}$应尽量小,则$\frac{(x-\mu)^{2}}{\sigma^{2}} \to 0$,所以$\mu =x, \sigma^{2}=\infty$,由于$\infty \not \in \mathbb{R}$,所以$\mu,\sigma^{2}$的最大似然估计不存在。
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
231
数理统计/作业/第十三周作业.tex
Normal file
231
数理统计/作业/第十三周作业.tex
Normal file
@ -0,0 +1,231 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
\input{mysubpreamble}
|
||||
\begin{document}
|
||||
\setcounter{chapter}{7}
|
||||
\section{假设检验的基本思想与概念}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[1]{
|
||||
设$x_1,x_2, \cdots ,x_n$是来自$N(\mu,1)$的样本,考虑如下假设检验问题
|
||||
$$
|
||||
H_0: \mu=2 \quad \mathrm{vs}\quad H_1:\mu=3,
|
||||
$$
|
||||
若检验由拒绝域为$W=\{ \bar{x}\geqslant 2.6 \}$确定。
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswerSolution[]{
|
||||
当$n=20$时求检验犯两类错误的概率;
|
||||
}{
|
||||
第一类错误:$\alpha=P(\bar{x}\geqslant 2.6|H_0)$,当$H_0$成立即$\mu=2$时$\bar{x}\sim N\left(2,\frac{1}{20}\right)$,所以
|
||||
$$
|
||||
\alpha=P\left( \frac{\bar{x}-2}{\sqrt{\frac{1}{20}}}\geqslant \frac{2.6-2}{\sqrt{\frac{1}{20}}} \right) = 1-\Phi\left( \frac{2.6-2}{\sqrt{\frac{1}{20}}} \right) = 0.0036452
|
||||
$$
|
||||
\begin{center}
|
||||
\includegraphics[width=0.3\linewidth]{imgs/2024-05-27-16-38-24.png}
|
||||
\end{center}
|
||||
|
||||
第二类错误:$\beta=P(\bar{x}<2.6|H_1)$,当$H_1$成立即$\mu=3$时$\bar{x}\sim N\left( 3,\frac{1}{20} \right) $,所以
|
||||
$$
|
||||
\beta=P\left( \frac{\bar{x}-3}{\sqrt{\frac{1}{20}}}<\frac{2.6-3}{\sqrt{\frac{1}{20}}} \right) =\Phi\left( \frac{2.6-3}{\sqrt{\frac{1}{20}}} \right) =0.036819
|
||||
$$
|
||||
\begin{center}
|
||||
\includegraphics[width=0.3\linewidth]{imgs/2024-05-27-16-41-54.png}
|
||||
\end{center}
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
如果要使得检验犯第二类错误的概率$\beta\leqslant 0.01$,$n$最小应取多少?
|
||||
}{
|
||||
$$
|
||||
\beta=P(\bar{x}<2.6|H_1)=P\left( \frac{\bar{x}-3}{\sqrt{\frac{1}{n}}}<\frac{2.6-3}{\sqrt{\frac{1}{n}}} \right) \leqslant 0.01
|
||||
$$
|
||||
即$\Phi\left( \frac{-0.4}{\sqrt{\frac{1}{n}}} \right) \leqslant 0.01$,即$\Phi\left( \frac{0.4}{\sqrt{\frac{1}{n}}} \right) \geqslant 0.99$,即$\frac{0.4}{\sqrt{\frac{1}{n}}}\geqslant 2.33 $,解得$ n \geqslant 33.930625$,所以$n$最小应取34.
|
||||
}
|
||||
\questionandanswerProof[]{
|
||||
证明:当$n \to \infty$时,$\alpha \to 0, \beta \to 0$。
|
||||
}{
|
||||
$$
|
||||
\alpha=P\left( \frac{\bar{x}-2}{\sqrt{\frac{1}{n}}}\geqslant \frac{2.6-2}{\sqrt{\frac{1}{n}}} \right) =1-\Phi\left( \frac{0.6}{\sqrt{\frac{1}{n}}} \right) \xrightarrow{n \to \infty} 0
|
||||
$$
|
||||
$$
|
||||
\beta=P\left( \frac{\bar{x}-3}{\sqrt{\frac{1}{n}}}<\frac{2.6-3}{\sqrt{\frac{1}{n}}} \right) =\Phi \left( \frac{-0.4}{\sqrt{\frac{1}{n}}} \right) \xrightarrow{n \to \infty}0
|
||||
$$
|
||||
}
|
||||
\end{enumerate}
|
||||
\questionandanswerSolution[3]{
|
||||
设$x_1,x_2, \cdots ,x_{16}$是来自正态总体$N(\mu,4)$的样本,考虑检验问题
|
||||
$$
|
||||
H_0:\mu=6\quad \mathrm{vs}\quad H_1:\mu\neq 6
|
||||
$$
|
||||
拒绝域取为$W=\{ \left\vert \bar{x}-6 \right\vert \geqslant c \}$,试求$c$使得检验的显著性水平为$0.05$,并求该检验在$\mu=6.5$处犯第二类错误的概率。
|
||||
}{
|
||||
当$H_0$成立即$\mu=6$时,$\bar{x}\sim N(\mu, \frac{4}{16})=N(6, \frac{1}{4})$,所以
|
||||
$$
|
||||
p = P\left( \left\vert \bar{x}-6 \right\vert \geqslant c | \mu=6 \right) =P\left( \frac{\left\vert \bar{x}-6 \right\vert }{\frac{1}{2}} \geqslant 2c \middle| \mu=6\right) =2(1-\Phi(2c)) = 0.05
|
||||
$$
|
||||
则$\Phi(2c)=0.975$,所以$2c=1.96$,从而$\bm{c=0.98}$。
|
||||
|
||||
当$\mu=6.5$时,$\bar{x} \sim N(6.5, 0.25)$,所以该检验在$\mu=6.5$处犯第二类错误的概率为
|
||||
$$
|
||||
\begin{aligned}
|
||||
\bm{\beta} &= P\left( \left\vert \bar{x}-6 \right\vert < c \ \middle|\ \mu=6.5 \right) = P\left( 5.02<\bar{x}<6.98 \right) \\
|
||||
&=P\left( \frac{5.02-6.5}{0.5}<\bar{x}<\frac{6.98-6.5}{0.5} \right) =\Phi\left( \frac{6.98-6.5}{0.5} \right) - \Phi\left( \frac{5.02-6.5}{0.5} \right) \bm{ = 0.8299317} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\begin{center}
|
||||
\includegraphics[width=0.3\linewidth]{imgs/2024-05-29-14-19-20.png}
|
||||
\end{center}
|
||||
}
|
||||
\questionandanswerSolution[4]{
|
||||
设总体为均匀分布$U(0, \theta)$,$x_1,x_2, \cdots ,x_n$是样本,考虑检验问题
|
||||
$$
|
||||
H_0: \theta\geqslant 3 \quad\mathrm{vs}\quad H_1:\theta<3,
|
||||
$$
|
||||
拒绝域取为$W=\{ x_{(n)}\leqslant 2.5 \}$,求检验犯第一类错误的最大值$\alpha$,若要使得该最大值$\alpha$不超过$0.05$,$n$至少应取多大?
|
||||
}{
|
||||
$x_{(n)}$的密度函数为$f_n(x)=\frac{nx^{n-1}}{\theta^{n}} 1_{(0,\theta)}(x)$,所以检验犯第一类错误的概率为
|
||||
$$
|
||||
\alpha' = P(x_{(n)}\leqslant 2.5|H_0)=P(x_{(n)}\leqslant 2.5|\theta\geqslant 3)=\int_{0}^{2.5} \frac{n x^{n-1}}{\theta^{n}} \mathrm{d}x = \left(\frac{5}{2}\right)^{n} \theta^{- n}
|
||||
$$
|
||||
当$\theta$取$3$时$\alpha'$取到最大值$\bm{\alpha} = \left( \frac{5}{2} \right) ^{n} 3^{-n} \bm{= \left(\frac{6}{5}\right)^{- n}}$,而$\alpha = \left( \frac{6}{5} \right) ^{-n}= 0.05 $解得$ n = - \frac{\ln{(20)}}{- \ln{(6)} + \ln{(5)}} =16.4310371534373$,所以$n$至少应取$\bm{17}$。
|
||||
}
|
||||
|
||||
\questionandanswer[8]{
|
||||
设$x_1,x_2, \cdots ,x_{30}$为取自泊松分布$P(\lambda)$的随机样本。
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[]{
|
||||
试给出单侧假设检验问题$H_0:\lambda\leqslant 0.1\ \ \mathrm{vs}\ \ H_1:\lambda>0.1$的显著性水平$\alpha=0.05$的检验;
|
||||
}{
|
||||
由于泊松分布关于参数$\lambda$具有可加性,所以$\sum_{k=1}^{n} x_k\sim P(30\lambda)$,所以选取$\sum_{k=1}^{n} x_k$作为统计量,设拒绝域为$W$,则
|
||||
$$
|
||||
P(W|H_0)=P(W|\lambda\leqslant 0.1)= \sum_{k=c}^{\infty} \frac{(30\lambda)^{k}}{k!} e^{-30\lambda} \leqslant 0.05
|
||||
$$
|
||||
当$\lambda$越大则犯第一类错误的概率越大,所以此时$\lambda$可以取$0.1$,则
|
||||
$$
|
||||
\sum_{k=c}^{\infty} \frac{(30\lambda)^{k}}{k!} e^{-30\lambda} = \sum_{k=c}^{\infty} \frac{3^{k}}{k!}e^{-3}
|
||||
$$
|
||||
\begin{center}
|
||||
\includegraphics[width=0.3\linewidth]{imgs/2024-05-29-15-56-01.png}
|
||||
\includegraphics[width=0.3\linewidth]{imgs/2024-05-29-15-55-51.png}
|
||||
\end{center}
|
||||
(图中的$50$可以为任何较大的自然数)可以看到当$c$取$6$时上式大于$0.05$,当$c$取$7$时上式小于$0.05$,所以所求检验的拒绝域为$\displaystyle W= \left\{ \sum_{k=1}^{30} x_k\geqslant 7 \right\} $。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
求此检验的势函数$\beta(\lambda)$在$\lambda=0.05,0.2,0.3, \cdots ,0.9$时的值,并据此画出$\beta(\lambda)$的图像。
|
||||
}{
|
||||
$$
|
||||
\begin{aligned}
|
||||
\beta(\lambda)&= P_{\lambda} \left( \sum_{k=1}^{30} x_i \geqslant 7 \right) = \sum_{k=7}^{\infty} \frac{(30\lambda)^{k}}{k!} e^{-30 \lambda} \\
|
||||
& = (- 1012500 \lambda^{6} - 202500 \lambda^{5} - 33750 \lambda^{4} - 4500 \lambda^{3} - 450 \lambda^{2} - 30 \lambda + e^{30 \lambda} - 1) e^{- 30 \lambda} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
使用\LaTeX 的 pgfplots 宏包画图如下:
|
||||
|
||||
\begin{center}
|
||||
\noindent\hspace{-6em} % ylabel会导致图片偏右,需要向左移动回来
|
||||
\begin{tikzpicture}
|
||||
\begin{axis}[
|
||||
xlabel={$\lambda$},
|
||||
ylabel={$\beta(\lambda)$}
|
||||
]
|
||||
\addplot[domain=0:1] {(- 1012500*x^6 - 202500*x^5 - 33750 *x^4 - 4500 *x^3 - 450 *x^2 - 30 *x + e^(30*x) - 1)* e^(-30*x)};
|
||||
\end{axis}
|
||||
\end{tikzpicture}
|
||||
\end{center}
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{enumerate}
|
||||
\section{正态总体参数假设检验}
|
||||
说明:本节习题均采用拒绝域的形式完成,在可以计算检验的$p$值时要求计算出$p$值。
|
||||
\begin{enumerate}
|
||||
\questionandanswerSolution[]{
|
||||
有一批枪弹,出厂时,其初速率$v \sim N(950, 100)$(单位:m/s)。经过较长时间储存,取9发进行测试,得样本值(单位:m/s)如下:
|
||||
$$
|
||||
914\quad 920\quad 910\quad 934\quad 953\quad 945\quad 912\quad 924\quad 940
|
||||
$$
|
||||
据经验,枪弹经储存后其初速率仍服从正态分布,且标准差保持不变,问是否可以认为这批枪弹的初速率有显著降低($\alpha=0.05$)?
|
||||
}{
|
||||
设总体的均值为$\mu$,则待检验的原假设$H_0$和备选假设$H_1$分别为
|
||||
$$
|
||||
H_0:\mu=950 \quad\mathrm{vs}\quad H_1:\mu<950
|
||||
$$
|
||||
拒绝域为$\{ u\leqslant u_{\alpha} \}$,即$\left\{ \frac{\bar{x}-950}{10/3}\leqslant u_{0.05} \right\} $即 $\left\{ \bar{x}\leqslant -1.645\times \frac{10}{3}+950 \approx 944.5167 \right\} $。
|
||||
|
||||
根据样本计算得出$\bar{x}=928$,在拒绝域内,因此可以认为这批枪弹的初速率有显著降低。
|
||||
|
||||
再计算$p$值,
|
||||
$$
|
||||
p=\Phi\left( \frac{928-950}{10/3} \right) = \bm{2.0665\times 10^{-11}} < 0.05
|
||||
$$
|
||||
}
|
||||
\questionandanswerSolution[5]{
|
||||
设需要对某正态总体的均值进行假设检验
|
||||
$$
|
||||
H_0:\mu=15 \quad\mathrm{vs}\quad H_1:\mu<15
|
||||
$$
|
||||
已知$\sigma^{2}=2.5$,取$\alpha=0.05$,若要求当$H_1$中的$\mu\leqslant 13$时犯第二类错误的概率不超过$0.05$,求所需的样本容量。
|
||||
}{
|
||||
由于已知$\sigma^{2}=2.5$,所以拒绝域为$\left\{ \frac{\bar{x}-15}{\sqrt{2.5/n}}\leqslant u_{0.05} \right\} $
|
||||
$$
|
||||
\beta=P\left( \frac{\bar{x}-15}{\sqrt{2.5/n}} >u_{0.05} \middle| \mu\leqslant 13 \right) \leqslant 0.05
|
||||
$$
|
||||
其中
|
||||
$$
|
||||
\begin{aligned}
|
||||
P\left( \frac{\bar{x}-15}{\sqrt{2.5/n}}>u_{0.05} \right) &=P\left( \frac{\bar{x}-\mu+\mu-15}{\sqrt{2.5 /n}} >u_{0.05} \right) =P\left( \frac{\bar{x}-\mu}{\sqrt{2.5 /n}}>u_{0.05}+\frac{15-\mu}{\sqrt{2.5 /n}} \right) \\
|
||||
&=1-\Phi\left( -1.645+\frac{15-\mu}{\sqrt{2.5 /n}} \right) \leqslant 0.05 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
所以
|
||||
$\displaystyle
|
||||
\Phi\left( -1.645+\frac{15-\mu}{\sqrt{2.5 /n}} \right) \geqslant 0.95
|
||||
$
|
||||
,从而
|
||||
$\displaystyle
|
||||
-1.645+\frac{15-\mu}{\sqrt{2.5 /n}} \geqslant 1.645
|
||||
$
|
||||
需要在$\mu\leqslant 13$时成立,由于左侧关于$\mu$递减,所以当$\mu=13$时,解$-1.645+\frac{15-13}{\sqrt{2.5 /n} }=1.645 $可得$ n = 6.7650625$,所以所需的样本容量至少为$\bm{7}$。
|
||||
|
||||
}
|
||||
\questionandanswer[6]{
|
||||
从一批钢管中抽取10根,测得其内径(单位:mm)为
|
||||
$$
|
||||
100.36\quad 100.31\quad 99.99\quad 100.11\quad 100.64\quad 100.85\quad 99.42\quad 99.91\quad 99.35\quad 100.10
|
||||
$$
|
||||
设这批钢管内径服从正态分布$N(\mu,\sigma^{2})$,试分别在下列条件下检验假设($\alpha=0.05$):
|
||||
$$
|
||||
H_0:\mu=100 \quad\mathrm{vs}\quad H_1:\mu>100
|
||||
$$
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswerSolution[]{
|
||||
已知$\sigma=0.5$;
|
||||
}{
|
||||
拒绝域为
|
||||
$\displaystyle
|
||||
\left\{ \frac{\bar{x}-100}{0.5/\sqrt{10}}\geqslant u_{1-\alpha} \right\} = \left\{ \bar{x} \geqslant u_{0.95} \times 0.5 \sqrt{10} + 100 \right\} =\left\{ \bar{x}\geqslant 102.60 \right\}
|
||||
$
|
||||
|
||||
根据样本计算得出$\bar{x}=100.104$,不在拒绝域中,所以不能拒绝原假设。
|
||||
|
||||
再计算$p$值,
|
||||
$$
|
||||
p=1-\Phi\left( \frac{100.104-100}{0.5} \right) = \bm{0.082385} >0.05
|
||||
$$
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
$\sigma$未知。
|
||||
}{
|
||||
拒绝域为
|
||||
$$
|
||||
\left\{ \frac{\bar{x}-100}{s /\sqrt{10}} \geqslant t_{0.95}(9) \right\} = \left\{ \frac{\bar{x}-100}{s /\sqrt{10}}\geqslant 1.8331 \right\}
|
||||
$$
|
||||
根据样本计算得出$\bar{x}=100.104, s=0.4759598489$,所以 $\frac{\bar{x}-100}{s /\sqrt{10}}=0.690976092663247$不在拒绝域内,所以不能拒绝原假设。
|
||||
|
||||
再计算$p$值,
|
||||
$$
|
||||
p=P_{t\sim t(9)}\left( t \geqslant 0.690976092663247 \right) > 1-0.7027 = \bm{0.2973} > 0.05
|
||||
$$
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{enumerate}
|
||||
\end{document}
|
300
数理统计/作业/第十二周作业.tex
Normal file
300
数理统计/作业/第十二周作业.tex
Normal file
@ -0,0 +1,300 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
\input{mysubpreamble}
|
||||
\begin{document}
|
||||
\setcounter{chapter}{6}
|
||||
\setcounter{section}{5}
|
||||
\section{区间估计}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[3]{
|
||||
$0.50, 1.25, 0.80, 2.00$是取自总体$X$的样本,已知$Y=\ln X$服从正态分布$N(\mu,1)$。
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswerSolution[]{
|
||||
求$\mu$的置信水平为$95\%$的置信区间;
|
||||
}{
|
||||
$$
|
||||
\frac{1-0.95}{2} = 0.025
|
||||
,\quad
|
||||
u_{0.025} = -1.96
|
||||
,\quad
|
||||
\frac{u_{0.025}}{\sqrt{n}}=\frac{-1.96}{\sqrt{4}}=-0.98
|
||||
$$
|
||||
$$
|
||||
\overline{\ln x} = \frac{1}{4}(\ln 0.50+ \ln 1.25+\ln 0.80+\ln 2.00) = 0
|
||||
$$
|
||||
所以$\mu$的置信水平为$95\%$的置信区间为$[-0.98, 0.98]$。
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
求$X$的数学期望的置信水平为$95\%$的置信区间。
|
||||
}{
|
||||
$$
|
||||
EX = E e^{Y} = e^{EY} = e^{\mu}
|
||||
$$
|
||||
所以$EX$的置信水平为$95\%$的置信区间为$[e^{-0.98}, e^{0.98}],即[0.3753110988514, 2.66445624192942]$。
|
||||
}
|
||||
\end{enumerate}
|
||||
\questionandanswer[5]{
|
||||
已知某种材料的抗压强度$X\sim N(\mu,\sigma^{2})$,现随机地抽取10个试件进行抗压试验,测得数据如下:
|
||||
$$
|
||||
482\quad 493\quad 457\quad 471\quad 510\quad 446\quad 435\quad 418\quad 394\quad 469
|
||||
$$
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswerSolution[]{
|
||||
求平均抗压强度$\mu$的置信水平为$95\%$的置信区间;
|
||||
}{
|
||||
由于$\sigma$未知,所以$\mu$的置信区间为$\left[ \bar{x}-t_{1-0.025}(10-1)s/ \sqrt{10}, \bar{x}+t_{1-0.025}(10-1)s /\sqrt{10} \right] $
|
||||
之后计算得
|
||||
$$
|
||||
\bar{x}=457.5,\quad s\approx 35.21757768
|
||||
$$
|
||||
所以$\mu$的置信水平为$95\%$的置信区间为
|
||||
$$
|
||||
[457.5- 2.2622\times 35.21757768/ \sqrt{10}, 457.5-2.2622\times 35.21757768 /\sqrt{10}]
|
||||
$$
|
||||
即
|
||||
$$
|
||||
[432.306385526736, 482.693614473264]
|
||||
$$
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
若已知$\sigma=30$,求平均抗压程度$\mu$的置信水平为$95\%$的置信区间;
|
||||
}{
|
||||
由于$\sigma$已知,所以$\mu$的$95\%$置信区间为$\left[ \bar{x}-u_{0.975}\sigma/\sqrt{n}, \bar{x}+u_{0.975}\sigma/\sqrt{n} \right] $,代入得
|
||||
$$
|
||||
\left[ 457.5-1.96\times 30 / \sqrt{10}, 457.5 + 1.96\times 30 /\sqrt{10} \right]
|
||||
$$
|
||||
即
|
||||
$$
|
||||
\left[ 438.90580735821, 476.09419264179 \right]
|
||||
$$
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
求$\sigma$的置信水平为$95\%$的置信区间。
|
||||
}{
|
||||
$\mu$未知时$\sigma$的置信水平为$95\%$的置信区间为$\left[ \frac{s\sqrt{n-1}}{\sqrt{\chi^{2}_{0.975}(n-1)}}, \frac{s\sqrt{n-1}}{\sqrt{\chi^{2}_{0.025}(n-1)}} \right] $,代入得
|
||||
$$
|
||||
\left[ \frac{35.21757768\times \sqrt{10-1}}{\sqrt{19.0228}}, \frac{35.21757768\times \sqrt{10-1}}{\sqrt{2.7004}} \right]
|
||||
$$
|
||||
即
|
||||
$$
|
||||
\left[ 24.2238693218913, 64.2934434191729 \right]
|
||||
$$
|
||||
}
|
||||
\end{enumerate}
|
||||
\questionandanswerSolution[6]{
|
||||
在一批货物中随机抽取80件,发现有11件不合格品,试求这批货物的不合格品率的置信水平为$0.90$的置信区间。
|
||||
}{
|
||||
样本的分布为$b(1,p)$。由于样本量较大,可以使用近似置信区间,即\\
|
||||
$\left[ \bar{x}-u_{0.95}\sqrt{\frac{\bar{x}(1-\bar{x})}{n}}, \bar{x}+u_{0.95}\sqrt{\frac{\bar{x}(1-\bar{x})}{n}} \right] $
|
||||
,其中$\bar{x}=\frac{11}{80} = 0.1375$,$n=80$,$u_{0.95}=1.645$,代入得
|
||||
$$
|
||||
\left[ 0.1375-1.645 \times \sqrt{\frac{0.1375\times (1-0.1375)}{80}}, 0.1375+1.645\times \sqrt{\frac{0.1375\times (1-0.1375)}{80}} \right]
|
||||
$$
|
||||
即
|
||||
$$
|
||||
\left[ 0.0741638282314373, 0.200836171768563 \right]
|
||||
$$
|
||||
}
|
||||
\questionandanswer[9]{
|
||||
设从总体$X\sim N(\mu_1,\sigma_1^{2})$和总体$Y\sim N(\mu_2,\sigma_2^{2})$中分别抽取容量为$n_1=10,n_2=15$的独立样本,可计算得$\bar{x}=82, s_x^{2}=56.5, \bar{y}=76, s_y^{2}=52.4$。
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswerSolution[]{
|
||||
若已知$\sigma_1^{2}=64, \sigma_2^{2}=49$,求$\mu_1-\mu_2$的置信水平为$95\%$的置信区间;
|
||||
}{
|
||||
$\sigma_1^{2}$和$\sigma_2^{2}$均已知,则$\mu_1-\mu_2$的置信水平为$95\%$的置信区间为\\
|
||||
$\left[ \bar{x}-\bar{y}-u_{0.975}\sqrt{\frac{\sigma_1^{2}}{n_1} +\frac{\sigma_2^{2}}{n_2}}, \bar{x}-\bar{y}+u_{0.975}\sqrt{\frac{\sigma_1^{2}}{n_1}+\frac{\sigma_2^{2}}{n_2}} \right] $,代入得
|
||||
$$
|
||||
\left[ 82-76-1.96\times \sqrt{\frac{64}{10}+\frac{49}{15}},\ 82-76+1.96\times \sqrt{\frac{64}{10}+\frac{49}{15}} \right]
|
||||
$$
|
||||
即
|
||||
$$
|
||||
\left[ -0.0938876480180258,\ 12.093887648018 \right]
|
||||
$$
|
||||
}\questionandanswerSolution[]{
|
||||
若已知$\sigma_1^{2}=\sigma_2^{2}$,求$\mu_1-\mu_2$的置信水平为$95\%$的置信区间;
|
||||
}{
|
||||
$\sigma_1^{2}=\sigma_2^{2}$未知,则$\mu_1-\mu_2$的置信水平为$95\%$的置信区间为\\
|
||||
$$
|
||||
\left[\bar{x}-\bar{y} - \sqrt{\frac{n_1+n_2}{n_1n_2}}s_w t_{0.975}(n_1+n_2-2),\ \bar{x}-\bar{y}+\sqrt{\frac{n_1+n_2}{n_1n_2}}s_w t_{0.975}(n_1+n_2-2)\right]
|
||||
$$
|
||||
其中$\displaystyle s_w^{2} = \frac{(n_1-1)s_{x}^{2}+(n_2-1)s_{y}^{2}}{n_1+n_2-2}$,$t_{0.975}(23)=2.0687$,代入得
|
||||
$$
|
||||
s_w^{2}=\frac{(10-1)\times 56.5+(15-1)\times 52.4}{10+15-2} = \frac{12421}{230}
|
||||
$$
|
||||
置信区间为
|
||||
$$
|
||||
\left[ 82-76-\sqrt{\frac{10+15}{10\times 15}} \sqrt{\frac{12421}{230}}\times 2.0687,\ 82-76+\sqrt{\frac{10+15}{10\times 15}}\sqrt{\frac{12421}{230}}\times 2.0687 \right]
|
||||
$$
|
||||
即
|
||||
$$
|
||||
\left[ -0.206349837966326,\ 12.2063498379663 \right]
|
||||
$$
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
若对$\sigma_1^{2},\sigma_2^{2}$一无所知,求$\mu_1-\mu_2$的置信水平为$95\%$的置信区间;
|
||||
}{
|
||||
此时为一般场合下,$\mu_1-\mu_2$的置信水平为$95\%$的近似置信区间为\\
|
||||
$[\bar{x}-\bar{y}-s_0 t_{0.975}(l),\ \bar{x}-\bar{y}+s_0 t_{0.975}(l)]$,其中$s_0^{2} = \frac{s_{x}^{2}}{n_1}+\frac{s_y^{2}}{n_2}=\frac{56.5}{10}+\frac{52.4}{15} = \frac{2743}{300}$, \\
|
||||
$\displaystyle l=\frac{s_0^{4}}{\frac{s_{x}^{4}}{n_1^{2}(n_1-1)}+\frac{s_y^{4}}{n_2^{2}(n_2-1)}} = \frac{\left( \frac{2743}{300} \right) ^{2}}{\frac{56.5^{2}}{10^{2}(10-1)}+\frac{52.4^{2}}{15^{2}(15-1)}} = \frac{52668343}{2783727} \approx 18.92008\approx 19$,\\
|
||||
$t_{0.975}(19)=2.0930$。
|
||||
|
||||
所以置信区间为
|
||||
$$
|
||||
\left[ 82-76-\sqrt{\frac{2743}{300}}\times 2.0930, \ 82-76+\sqrt{\frac{2743}{300}}\times 2.0930 \right]
|
||||
$$
|
||||
即
|
||||
$$
|
||||
\left[ -0.328801942179367, \ 12.3288019421794 \right]
|
||||
$$
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
求$\sigma_1^{2}/\sigma_2^{2}$的置信水平为$95\%$的置信区间。
|
||||
}{
|
||||
置信区间为
|
||||
$$
|
||||
\left[\frac{s_{x}^{2}}{s_y^{2}}\cdot \frac{1}{F_{0.975}(9, 14)},\ \frac{s_{x}^{2}}{s_y^{2}}\cdot \frac{1}{F_{0.025}(9,14)} \right]
|
||||
$$
|
||||
由于$F_{\frac{\alpha}{2}}(n_1,n_2) = {1}/{F_{1-\frac{\alpha}{2}}(n_2,n_1)}$,所以可以代入得
|
||||
$$
|
||||
\left[ \frac{56.5}{52.4}\cdot \frac{1}{3.21},\ \frac{56.5}{52.4}\cdot {3.80} \right]
|
||||
$$
|
||||
即
|
||||
$$
|
||||
\left[0.335901643242729,\ 4.09732824427481 \right]
|
||||
$$
|
||||
}
|
||||
\end{enumerate}
|
||||
\questionandanswerSolution[12]{
|
||||
设某电子产品的寿命服从指数分布,其密度函数为$\lambda e^{-\lambda x}I_{\{ x>0 \}}$,现从此批产品中抽取容量为9的样本,测得寿命为(单位:千小时)
|
||||
$$
|
||||
15\quad 45\quad 50\quad 53\quad 60\quad 65\quad 70\quad 83\quad 90
|
||||
$$
|
||||
求平均寿命$1/\lambda$的置信水平为0.9的置信区间和置信上、下限。
|
||||
}{
|
||||
首先尝试构造枢轴量,设样本为$x_1,x_2, \cdots ,x_9$,则$x_1,x_2, \cdots x_9\overset{\text{i.i.d.}}{\sim}\operatorname{Exp}(\lambda)$,则$\sum_{i=1}^{9} x_i \sim \operatorname{Ga}(9, \lambda)$,所以${2\lambda}\sum_{i=1}^{9} x_i \sim \operatorname{Ga}(9, \frac{1}{2})=\chi^{2}(18)$,分布不依赖于$\lambda$,所以$G=2\lambda\sum_{i=1}^{9} x_i$为枢轴量,所以
|
||||
$$
|
||||
P\left( \chi^{2}_{0.05}(18)\leqslant G\leqslant \chi^{2}_{0.95}(18) \right) = 0.9
|
||||
$$
|
||||
$$
|
||||
P\left( \frac{\chi^{2}_{0.05}(18)}{2\sum_{i=1}^{9} x_i}\leqslant \lambda\leqslant \frac{\chi^{2}_{0.95}(18)}{2\sum_{i=1}^{9} x_i} \right) =0.9
|
||||
$$
|
||||
所以$\lambda$的置信水平为0.9的双侧置信区间为
|
||||
$$
|
||||
\left[ \frac{\chi^{2}_{0.05}(18)}{2\sum_{i=1}^{9} x_i}, \ \frac{\chi^{2}_{0.95}(18)}{2\sum_{i=1}^{9} x_i} \right] = \left[ \frac{9.3905}{2\times 531},\ \frac{28.8693}{2\times 531} \right] = \left[ 0.00884227871939736,\ 0.0271838983050847 \right]
|
||||
$$
|
||||
同理,单侧置信上限为
|
||||
$$
|
||||
\frac{\chi^{2}_{0.9}(18)}{2\sum_{i=1}^{9} x_i}=\frac{25.9894}{2\times 531} = 0.0244721280602637
|
||||
$$
|
||||
单侧置信下限为
|
||||
$$
|
||||
\frac{\chi^{2}_{0.1}(18)}{2\sum_{i=1}^{9} x_i}=\frac{10.8649}{2\times 531} = 0.0102306026365348
|
||||
$$
|
||||
所以$\frac{1}{\lambda}$的置信水平为0.9的置信区间为
|
||||
$$
|
||||
\left[ \frac{2\times 531}{28.8693}, \ \frac{2\times 531}{9.3905} \right] = \mathbf{\left[ 36.7864825264208, \ 113.093019541025 \right]}
|
||||
$$
|
||||
单侧置信上限为
|
||||
$$
|
||||
\frac{2\times 531}{10.8649} = \mathbf{97.74595256284}
|
||||
$$
|
||||
单侧置信下限为
|
||||
$$
|
||||
\frac{2\times 531}{25.9894} = \mathbf{40.8628133008073}
|
||||
$$
|
||||
}
|
||||
\questionandanswerSolution[13]{
|
||||
设总体$X$的密度函数为
|
||||
$$
|
||||
p(x;\theta)=\frac{1}{\pi\left[ 1+(x-\theta)^{2} \right] }, \quad -\infty<x<\infty, \quad -\infty<\theta<\infty
|
||||
$$
|
||||
$x_1,x_2, \cdots ,x_n$为抽自此总体的简单随机样本,求位置参数$\theta$的置信水平近似为$1-\alpha$的置信区间。
|
||||
}{
|
||||
设$m_{0.5}$表示样本中位数,则根据例5.3.10,当然$n$较大时,$m_{0.5}\sim N\left( \theta, \frac{\pi^{2}}{4n} \right) $,将$m_{0.5}$看作样本容量为1的样本,则$m_{0.5}$服从方差已知,期望未知的正态分布,所以$\theta$的置信水平近似为$1-\alpha$的置信区间为
|
||||
$$
|
||||
\left[ m_{0.5}-u_{1-\frac{\alpha}{2}} \sqrt{\frac{\pi^{2}}{4n}} / \sqrt{1} , \ m_{0.5}+u_{1-\frac{\alpha}{2}}\sqrt{\frac{\pi^{2}}{4n}} / \sqrt{1}\right]
|
||||
$$
|
||||
即
|
||||
$$
|
||||
\left[ m_{0.5}-u_{1-\frac{\alpha}{2}} \frac{\pi}{2 \sqrt{n}} , \ m_{0.5}+u_{1-\frac{\alpha}{2}}\frac{\pi}{2\sqrt{n}}\right]
|
||||
$$
|
||||
|
||||
}
|
||||
\questionandanswerSolution[14]{
|
||||
设$x_1,x_2, \cdots ,x_n$为抽自正态总体$N(\mu,16)$的简单随机样本,为使得$\mu$的置信水平为$1-\alpha$的置信区间的长度不大于给定的$L$,试问样本容量$n$至少要多少?
|
||||
}{
|
||||
$\sigma^{2}=16$已知,则置信区间为$\left[ \bar{x}-u_{1-\frac{\alpha}{2}}\sigma / \sqrt{n}, \bar{x}+u_{1-\frac{\alpha}{2}}\sigma / \sqrt{n} \right] $,区间长度为$2 u_{1-\frac{\alpha}{2}}\times 4 / \sqrt{n}\leqslant L$,则$\displaystyle n \geqslant \left( \frac{8 u_{1-\frac{\alpha}{2}}}{L} \right) ^{2}=\frac{64 u_{1-\frac{\alpha}{2}}^{2}}{L^{2}}$。
|
||||
}
|
||||
\questionandanswerSolution[16]{
|
||||
设$x_1,x_2, \cdots ,x_n$是来自$U(\theta-\frac{1}{2}, \theta+\frac{1}{2})$的样本,求$\theta$的置信水平为$1-\alpha$的置信区间(提示:证明$\displaystyle \frac{x_{(n)}+x_{(1)}}{2}-\theta$为枢轴量,并求出对应的密度函数)。
|
||||
}{
|
||||
设总体为$X$,则$X\sim U(\theta-\frac{1}{2}, \theta+\frac{1}{2})$,则$X-\theta+\frac{1}{2}\sim U(0,1)$,则根据例5.3.9,$(Y,Z)=\left( x_{(1)}-\theta+\frac{1}{2}, x_{(n)}-\theta+\frac{1}{2} \right) $的联合密度函数为
|
||||
$$
|
||||
p(y,z)=n(n-1)(z-y)^{n-2}
|
||||
$$
|
||||
再根据卷积公式,$y+z=x_{(1)}+x_{(n)}-2\theta+1$的概率密度函数为
|
||||
$$
|
||||
p(x)=\int_{0}^{1} n(n-1)(x-2t)^{n-2} \mathrm{d}t = \frac{n}{2} x^{n-1} - \frac{n}{2} (x-2)^{n-1}
|
||||
$$
|
||||
所以$\frac{(y+z)-1}{2}=\frac{x_{(1)}+x_{(n)}}{2}-\theta$的概率密度函数为
|
||||
$$
|
||||
p'(x) = \frac{n}{2}(2x+1)^{n-1}-\frac{n}{2}(2x-1)^{n-1}
|
||||
$$
|
||||
显然与$\theta$无关,所以令$G=\frac{x_{(1)}+x_{(n)}}{2}-\theta$即为枢轴量,则可知
|
||||
$$
|
||||
\int_{- \frac{1-\alpha^{\frac{1}{n}}}{2}}^{\frac{1-\alpha ^{\frac{1}{n}}}{2}} \frac{n}{2}(2x+1)^{n-1}-\frac{n}{2}(2x-1)^{n-1} \mathrm{d}x = 1-\alpha
|
||||
$$
|
||||
所以
|
||||
$
|
||||
-\frac{1-\alpha ^{\frac{1}{n}}}{2} \leqslant G=\frac{x_{(1)}+x_{(n)}}{2}-\theta\leqslant \frac{1-\alpha ^{\frac{1}{n}}}{2}
|
||||
$
|
||||
,所以
|
||||
$
|
||||
\frac{x_{(1)}+x_{(n)}}{2}-\frac{1-\alpha ^{\frac{1}{n}}}{2} \leqslant \theta \leqslant \frac{x_{(1)}+x_{(n)}}{2}+\frac{1-\alpha ^{\frac{1}{n}}}{2}
|
||||
$
|
||||
所以$\theta$的置信水平为$1-\alpha$的置信区间为
|
||||
$$
|
||||
\left[ \frac{x_{(1)}+x_{(n)}}{2}-\frac{1-\alpha ^{\frac{1}{n}}}{2},\ \frac{x_{(1)}+x_{(n)}}{2}+\frac{1-\alpha ^{\frac{1}{n}}}{2} \right]
|
||||
$$
|
||||
}
|
||||
\questionandanswer[19]{
|
||||
设总体$X$的密度函数为
|
||||
$$
|
||||
p(x,\theta)=e^{-(x-\theta)} I_{\{ x>\theta \}}, \quad -\infty<\theta<\infty,
|
||||
$$
|
||||
$x_1,x_2, \cdots ,x_n$为抽自此总体的简单随机样本。
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswerProof[]{
|
||||
证明:$x_{(1)}-\theta$的分布与$\theta$无关,并求出此分布;
|
||||
}{
|
||||
令$y = x-\theta$,则$p(y) = e^{-y}I_{\{ y>0 \}}$。
|
||||
由于$y=x-\theta$是单调增函数,所以$y_{(1)}=x_{(1)}-\theta$。
|
||||
$F(y)=\int_{0}^{y} e^{-t} \mathrm{d}t=1-e^{-y}$,从而次序统计量$y_{(1)}=x_{(1)}-\theta$的概率密度函数为
|
||||
$$
|
||||
p_{(1)}(y) = \frac{n!}{0!(n-1)!} [F(y)]^{0} \left[ 1-F(y) \right] ^{n-1} p(y) = n \left( e^{-y} \right) ^{n-1} e^{-y} I_{\{ y>0 \}} = ne^{-ny} I_{\{ y>0 \}}
|
||||
$$
|
||||
所以$x_{(1)}-\theta \sim \operatorname{Exp}(n)$,与$\theta$无关。
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
求$\theta$的置信水平为$1-\alpha$的置信区间。
|
||||
}{
|
||||
$$
|
||||
P(c\leqslant x_{(1)}-\theta\leqslant d)=\int_{c}^{d} ne^{-ny} \mathrm{d}y
|
||||
$$
|
||||
因为被积函数在$[0,+\infty)$上单调递减,所以区间长度最短则$c=0$,所以
|
||||
$$
|
||||
\int_{0}^{d} n e^{-ny} \mathrm{d}y = \left. -e^{-ny} \right|_{0}^{d} = 1-e^{-nd} = 1-\alpha
|
||||
$$
|
||||
所以 $d = \dfrac{-\ln \alpha}{n}$。
|
||||
|
||||
而$c \leqslant x_{(1)}-\theta\leqslant d \implies x_{(1)}-d\leqslant \theta\leqslant x_{(1)}-c\implies x_{(1)}+\frac{\ln \alpha}{n}\leqslant \theta\leqslant x_{(1)}$,所以$\theta$的置信水平为$1-\alpha$的置信区间为
|
||||
$$
|
||||
\left[ x_{(1)}+\frac{\ln \alpha}{n},\ x_{(1)} \right]
|
||||
$$
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{enumerate}
|
||||
\end{document}
|
168
数理统计/作业/第十五周作业.tex
Normal file
168
数理统计/作业/第十五周作业.tex
Normal file
@ -0,0 +1,168 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
\input{mysubpreamble}
|
||||
\begin{document}
|
||||
\setcounter{chapter}{7}
|
||||
\setcounter{section}{3}
|
||||
\section{似然比检验与分布拟合检验}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[3]{
|
||||
设$x_1,x_2, \cdots ,x_n$为来自指数分布$\operatorname{Exp}(\lambda_1)$的样本,$y_1,y_2, \cdots ,y_m$为来自指数分布$\operatorname{Exp}(\lambda_1)$的样本,且两组样本独立,其中$\lambda_1,\lambda_2$是未知的正参数。
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswerSolution[]{
|
||||
求假设$H_0:\lambda_1=\lambda_2 \quad\mathrm{vs}\quad H_1:\lambda_1\neq \lambda_2$的似然比检验;
|
||||
}{
|
||||
参数空间为$\Theta_0 = \{ (\lambda_1,\lambda_2)| \lambda_1 = \lambda_2 >0 \}$,$\Theta = \{ (\lambda_1,\lambda_2)|\lambda_1>0, \lambda_2>0 \}$。最大似然估计为
|
||||
$$
|
||||
\hat{\lambda_1} = \frac{n}{\sum_{i=1}^{n} x_i}, \hat{\lambda_2} = \frac{m}{\sum_{i=1}^{m} y_i}, \hat{\lambda_0}=\frac{n+m}{\sum_{i=1}^{n} x_i + \sum_{i=1}^{m} y_i}
|
||||
$$
|
||||
所以似然比检验为
|
||||
$$
|
||||
\Lambda = \frac{\left( \frac{n}{\sum_{i=1}^{n} x_i} \right) ^{n} \left( \frac{m}{\sum_{i=1}^{m} y_i} \right) ^{m}}{\left( \frac{n+m}{\sum_{i=1}^{n} x_i + \sum_{i=1}^{m} y_i} \right) ^{n+m}}
|
||||
$$
|
||||
}
|
||||
\questionandanswerProof[]{
|
||||
证明上述检验法的拒绝域仅依赖于比值 $\displaystyle \left. \sum_{i=1}^{n} x_i \middle/ \sum_{i=1}^{n} y_i \right.$;
|
||||
}{
|
||||
此检验的拒绝域为
|
||||
$$
|
||||
\{ \Lambda \geqslant c \}= \left\{ \left. \sum_{i=1}^{n} x_i \middle/ \sum_{i=1}^{n} y_i \right. \leqslant \cdot \text{或} \left. \sum_{i=1}^{n} x_i \middle/ \sum_{i=1}^{n} y_i \right. \geqslant \cdot \right\}
|
||||
$$
|
||||
这说明仅依赖于比值$\displaystyle \left. \sum_{i=1}^{n} x_i \middle/ \sum_{i=1}^{n} y_i \right.$。
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
求统计量 $\displaystyle \left. \sum_{i=1}^{n} x_i \middle/ \sum_{i=1}^{n} y_i \right. $在原假设成立下的分布。
|
||||
}{
|
||||
因为 $\sum_{i=1}^{n} x_i \sim \operatorname{Ga}(n, \lambda_1)$, $\sum_{i=1}^{m} y_i \sim \operatorname{Ga}(m, \lambda_2)$,所以在原假设成立下,
|
||||
$$
|
||||
\left. \sum_{i=1}^{n} x_i \middle/ \sum_{i=1}^{n} y_i \right. \sim F(2n, 2m)
|
||||
$$
|
||||
}
|
||||
\end{enumerate}
|
||||
\questionandanswerProof[4]{
|
||||
设$x_1,x_2, \cdots ,x_n$为来自正态总体$N(\mu,\sigma^{2})$的 i.i.d. 样本,其中$\mu,\sigma^{2}$未知。证明关于假设$H_0:\mu\leqslant \mu_0 \quad\mathrm{vs}\quad H_1:\mu>\mu_0$的单侧$t$检验是似然比检验(显著性水平$\alpha < \frac{1}{2}$)。
|
||||
}{
|
||||
似然比统计量为
|
||||
$$
|
||||
\Lambda = \frac{(2\pi \hat{\sigma})^{-\frac{n}{2}} \exp (-\frac{n}{2})}{(2\pi \hat{\sigma}_0^{2})^{-\frac{n}{2}}\exp (-\frac{n}{2})}
|
||||
$$
|
||||
拒绝域为 $\displaystyle \{ \Lambda\geqslant c \}=\left\{ \frac{\sqrt{n}(\bar{x}-\mu_0)}{s}\geqslant t_{1-\alpha}(n-1) \right\} $,这说明似然比检验此时就是单侧$t$检验。
|
||||
}
|
||||
\questionandanswerSolution[6]{
|
||||
掷一颗骰子60次,结果如下
|
||||
\begin{center}
|
||||
\begin{tabular}{ccccccc}
|
||||
\toprule
|
||||
点数 & 1 & 2 & 3 & 4 & 5 & 6 \\
|
||||
\midrule
|
||||
次数 & 7 & 8 & 12 & 11 & 9 & 13 \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{center}
|
||||
试在显著性水平为0.05下检验这颗骰子是否均匀。
|
||||
}{
|
||||
这是分布拟合优度检验:
|
||||
$$
|
||||
\chi^{2} = \sum_{i=1}^{6} \frac{(n_i - 10)^{2}}{10}=2.8, \quad W=\{ \chi^{2}\geqslant \chi^{2}_{0.95}(5)=11.0705 \}
|
||||
$$
|
||||
所以不拒绝原假设,即认为这颗骰子均匀。
|
||||
}
|
||||
\questionandanswerSolution[9]{
|
||||
在一批灯泡中抽取300只作寿命试验,其结果如下:
|
||||
\begin{center}
|
||||
\begin{tabular}{ccccc}
|
||||
\toprule
|
||||
寿命(h) & <100 & [100,200) & [200,300) & $\geqslant 300$ \\
|
||||
% \midrule
|
||||
灯泡数 & 121 & 78 & 43 & 58 \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{center}
|
||||
在显著性水平为0.05下能否认为灯泡寿命服从指数分布$\operatorname{Exp}(0.005)$?
|
||||
}{
|
||||
也是分布拟合优度检验。题目中寿命分为了四个区间,由于指数分布的累计分布函数为$e^{-\lambda t}$,所以当$\lambda=0.005$时这四个区间的的概率$p$以及$np$分别为
|
||||
$$
|
||||
p=diff([e^{-300 \lambda}, e^{-200 \lambda}, e^{-100 \lambda},1]) \approx [0.2231, 0.1447, 0.2387, 0.3935]
|
||||
$$
|
||||
$$
|
||||
np = 300 \times [0.2231, 0.1447, 0.2387, 0.3935] \approx [66.93, 43.41, 71.61, 118.05]
|
||||
$$
|
||||
所以$\chi^{2} = \sum_{axis=0} \frac{(x-np)^{2}}{np} \approx 1.8393$,拒绝域为$\{ \chi^{2}\geqslant \chi^{2}_{0.995}(3)\approx 7.8147 \}$,所以不能拒绝原假设,所以认为灯泡寿命服从指数分布 $\operatorname{Exp}(0.005)$。
|
||||
|
||||
}
|
||||
\questionandanswerSolution[10]{
|
||||
下表是上海1875年到1955年的81年间,根据其中63年观察到的一年中(5月到9月)下暴雨次数的整理资料
|
||||
\begin{center}
|
||||
\begin{tabular}{ccccccccccc}
|
||||
\toprule
|
||||
$i$ & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & $\geqslant 9$ \\
|
||||
\midrule
|
||||
$n_i$ & 4 & 8 & 14 & 19 & 10 & 4 & 2 & 1 & 1 & 0 \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{center}
|
||||
试检验一年中暴雨次数是否服从泊松分布($\alpha=0.05$)。
|
||||
}{
|
||||
由于泊松分布的参数的矩估计和最大似然估计是一样的,所以这里只需要计算样本的均值即 $\sum_{i=0}^{9} ( n_i \times i )/ 63 = 2.8571$,即为$\hat{\lambda}$。
|
||||
|
||||
为了满足每一类的样本观测次数不小于5,需要合并$i\leqslant 1$和$i\geqslant 5$。
|
||||
|
||||
之后计算 $\sum_{k=1}^{5} (n_k - n \hat{p_{k}})^{2} / n \hat{p_{k}}\approx 2.4995$,拒绝域为 $W=\{ \chi^{2}\geqslant \chi^{2}_{0.95}(5-1-1)\approx 7.8147 \}$,所以不能拒绝原假设,所以可以认为一年中暴雨次数服从泊松分布。
|
||||
|
||||
}
|
||||
\questionandanswerProof[12]{
|
||||
设按有无特性A与B将$n$个样品分成四类,组成$2\times 2$列联表:
|
||||
\begin{center}
|
||||
\begin{tabular}{c|cc|c}
|
||||
\toprule
|
||||
$ $ & $B$ & $\bar{B}$ & 合计 \\
|
||||
\hline
|
||||
$A$ & $a$ & $b$ & $a+b$ \\
|
||||
$\bar{A}$ & $c$ & $d$ & $c+d$ \\
|
||||
\hline
|
||||
合计 & $a+c$ & $b+d$ & $n$ \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{center}
|
||||
其中$n=a+b+c+d$,试证明此时列联表独立性检验的$\chi^{2}$统计量可以表示成
|
||||
$$
|
||||
\chi^{2} = \frac{n(ad-bc)^{2}}{(a+b)(c+d)(a+c)(b+d)}
|
||||
$$
|
||||
}{
|
||||
对于$a$,最大似然估计为$\frac{(a+c)(a+b)}{n^{2}}$,同理可以计算其他参数的最大似然估计,所以检验统计量为
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\chi^{2} = \frac{\left( a-\frac{(a+b)(a+c)}{n} \right) ^{2}}{\frac{(a+b)(a+c)}{n}} + \frac{\left( b - \frac{(a+b)(b+d)}{n} \right)^{2} }{\frac{(a+b)(b+d)}{n}} + \frac{\left( c-\frac{(a+c)(c+d)}{n} \right) ^{2}}{\frac{(a+c)(c+d)}{n}} + \frac{\left( d-\frac{(c+d)(b+d)}{n} \right) ^{2}}{\frac{(c+d)(b+d)}{n}} \\
|
||||
&= \frac{\begin{split}
|
||||
(a + b) (a + c) (d n - (b + d) (c + d))^{2} + (a + b) (b + d) (c n - (a + c) (c + d))^{2}\\ + (a + c) (c + d) (b n - (a + b) (b + d))^{2} + (b + d) (c + d) (a n - (a + b) (a + c))^{2}
|
||||
\end{split}}{n (a + b) (a + c) (b + d) (c + d)} \\
|
||||
&= \frac{n(ad-bc)^{2}}{(a + b) (a + c) (b + d) (c + d)} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
}
|
||||
\questionandanswerSolution[13]{
|
||||
在研究某种新措施对猪白痢的防治效果问题时,获得了如下数据:
|
||||
\begin{center}
|
||||
\begin{tabular}{c|cc|c|c}
|
||||
\toprule
|
||||
& 存活数 & 死亡数 & 合计 & 死亡率 \\
|
||||
\hline
|
||||
对照 & 114 & 36 & 150 & 24\% \\
|
||||
新措施 & 132 & 18 & 150 & 12\% \\
|
||||
\hline
|
||||
合计 & 246 & 54 & 300 & 18\% \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{center}
|
||||
试问新措施对防治该种疾病是否有显著疗效($\alpha=0.05$)?
|
||||
}{
|
||||
原假设为新措施对该种疾病无显著疗效。
|
||||
根据第12题计算统计量
|
||||
$$
|
||||
\chi^{2} = \frac{300\times (114\times 18 - 132\times 36)^{2}}{(114+36)(36+18)(18+132)(132+114)} = \frac{300}{41} \approx 7.31707317073171
|
||||
$$
|
||||
此时$r=c=2$,所以$(r-1)(c-1)=1$,所以$\chi^{2}_{0.95}(1)=3.8415$,所以拒绝域为$\{ \chi^{2}\geqslant 3.8415 \}$,所以拒绝原假设,所以新措施对防治该种疾病有显著疗效。
|
||||
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
189
数理统计/作业/第十四周作业.tex
Normal file
189
数理统计/作业/第十四周作业.tex
Normal file
@ -0,0 +1,189 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
\input{mysubpreamble}
|
||||
\begin{document}
|
||||
\setcounter{chapter}{7}
|
||||
\setcounter{section}{2}
|
||||
\begin{enumerate}
|
||||
\questionandanswerSolution[14]{
|
||||
在针织品漂白工艺过程中,要考察温度对针织品断裂强力(主要质量指标)的影响。为了比较70℃与80℃的影响有无差别,在这两个温度下,分别重复做了8次试验,得数据(单位:N)如下:
|
||||
|
||||
70℃时的强力:\quad 20.5\quad 18.8\quad 19.8\quad 20.9\quad 21.5\quad 19.5\quad 21.0\quad 21.2,
|
||||
|
||||
80℃时的强力:\quad 17.7\quad 20.3\quad 20.0\quad 18.8\quad 19.0\quad 20.1\quad 20.0\quad 19.l.
|
||||
|
||||
根据经验,温度对针织品断裂强度的波动没有影响。问在70℃时的平均断裂强力与80℃时的平均断裂强力间是否有显著差别(假定断裂强力服从正态分布,取a= 0.05)?
|
||||
}{
|
||||
使用$t$检验,检验的问题为
|
||||
$$
|
||||
H_0:\mu_1=\mu_2 \quad\mathrm{vs}\quad H_1:\mu_1\neq \mu_2
|
||||
$$
|
||||
根据样本计算得出$\bar{x}=20.4, \bar{y}=19.375, s_{u}=\sqrt{\frac{1}{8+8-2} (8\sigma^{2}_{x}+8\sigma^{2}_{y})}=0.9147599217$。
|
||||
\begin{center}
|
||||
\includegraphics[width=0.3\linewidth]{imgs/2024-06-01-14-45-03.png}
|
||||
\end{center}
|
||||
$$
|
||||
t=\frac{\bar{x}-\bar{y}}{s_u \sqrt{\frac{1}{8}+\frac{1}{8}}}=\frac{20.4-19.375}{0.9147599217 \sqrt{\frac{1}{8}+\frac{1}{8}}} \approx 2.2410, \quad W=\{ \left\vert t \right\vert \geqslant t_{0.975}(14) \}= \{ \left\vert t \right\vert \geqslant 2.1448 \}
|
||||
$$
|
||||
$t$在拒绝域内,所以拒绝原假设,所以在70℃时的平均断裂强力与80℃时的平均断裂强力间\boldkai{有显著差别}。
|
||||
|
||||
再计算$p$值,$\displaystyle p=2(1-\Phi(\left\vert 2.2410 \right\vert ))=0.012513 < 0.05$,确实应拒绝原假设。
|
||||
}
|
||||
\questionandanswerSolution[15]{
|
||||
一药厂生产一种新的止痛片,厂方希望验证服用新药片后至开始起作用的时间间隔较原有止痛片至少缩短一半,因此厂方提出需检验假设
|
||||
$$
|
||||
H_0:\mu_1=2\mu_2 \quad\mathrm{vs}\quad H_1:\mu_1>2\mu_2
|
||||
$$
|
||||
此处$\mu_1,\mu_2$分别是服用原有止痛片和服用新止痛片后至开始起作用的时间间隔的总体的均值。设两总体均为正态分布且方差分别为已知值$\sigma_1^{2},\sigma_2^{2}$,现分别在两总体中取一样本$x_1,x_2, \cdots ,x_n$和$y_1,y_2, \cdots ,y_m$,设两个样本独立。试给出上述假设检验问题的检验统计量及拒绝域.
|
||||
}{
|
||||
使用$u$检验,检验统计量为 $\displaystyle u=\frac{\bar{x} - 2\bar{y}}{\sqrt{\frac{\sigma_1^{2}}{n}+\frac{4\sigma_2^{2}}{m}}}$,拒绝域为$\displaystyle W=\{ u\geqslant u_{1-\alpha} \}$。
|
||||
}
|
||||
\questionandanswer[26]{
|
||||
测得两批电子器件的样品的电阻(单位:$\Omega$)为
|
||||
|
||||
A批($x$):\qquad 0.140\quad 0.138\quad 0.143\quad 0.142\quad 0.144\quad 0.137;
|
||||
|
||||
B批($y$):\qquad 0.135\quad 0.140\quad 0.142\quad 0.136\quad 0.138\quad 0.140.
|
||||
|
||||
设这两批器材的电阻值分别服从分布$N(\mu_1, \sigma_1^{2}), N(\mu_2, \sigma_2^{2})$,且两样本独立。
|
||||
}{
|
||||
使用Excel计算如下:
|
||||
\begin{table}[H]
|
||||
\tiny\centering
|
||||
\begin{tabular}{ccccccccccc}
|
||||
x & y & & & & & & & & & \\
|
||||
0.14 & 0.135 & & & F-检验 双样本方差分析 & & & & t-检验: 双样本异方差假设 & & \\
|
||||
0.138 & 0.14 & & & & & & & & & \\
|
||||
0.143 & 0.142 & & & & x & y & & & x & y \\
|
||||
0.142 & 0.136 & & & 平均 & 0.140667 & 0.1385 & & 平均 & 0.140667 & 0.1385 \\
|
||||
0.144 & 0.138 & & & 方差 & 7.87E-06 & 7.1E-06 & & 方差 & 7.87E-06 & 7.1E-06\\
|
||||
0.137 & 0.14 & & & 观测值 & 6 & 6 & & 观测值 & 6 & 6 \\
|
||||
& & & & df & 5 & 5 & & 假设平均差 & 0 & \\
|
||||
& & & & F & 1.107981 & & & df & 10 & \\
|
||||
& & & & P(F<=f) 单尾 & 0.456576 & & & t Stat & 1.371845 & \\
|
||||
& & & & F 单尾临界 & 5.050329 & & & P(T<=t) 单尾 & 0.100051 & \\
|
||||
& & & & & & & & t 单尾临界 & 1.812461 & \\
|
||||
& & & & & & & & P(T<=t) 双尾 & 0.200102 & \\
|
||||
& & & & & & & & t 双尾临界 & 2.228139 & \\
|
||||
& & & & & & & & & & \\
|
||||
\end{tabular}
|
||||
\end{table}
|
||||
}
|
||||
\begin{enumerate}
|
||||
\questionandanswerSolution[]{
|
||||
试检验两个总体的方差是否相等(取$\alpha=0.05$)。
|
||||
}{
|
||||
使用$F$检验,不能拒绝原假设,所以相等。
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
试检验两个总体的均值是否相等(取$\alpha=0.05$)。
|
||||
}{
|
||||
使用$t$检验,不能拒绝原假设,所以相等。
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{enumerate}
|
||||
\section{其他分布参数的假设检验}
|
||||
\begin{enumerate}
|
||||
\questionandanswerSolution[2]{
|
||||
某厂一种元件平均使用 寿命为1200 h(偏低) ,现厂里进行技术革新,革新后任选8个元件进行寿命试验,测得寿命数据如下
|
||||
$$
|
||||
2686\quad 2001\quad 2082\quad 792\quad 1660\quad 4105\quad 1416\quad 2089
|
||||
$$
|
||||
假定元件寿命服从指数分布,取$\alpha=0.05$,问革新后元件的平均寿命是否有明显提高?
|
||||
}{
|
||||
使用$\chi^{2}$检验假设
|
||||
$$
|
||||
H_0: \theta \leqslant 1200 \quad\mathrm{vs}\quad H_1:\theta>1200
|
||||
$$
|
||||
$\chi^{2} = \frac{2\times 8 \bar{x}}{1200}\approx 28.0517$,拒绝域为$\{ \chi^{2}\geqslant \chi^{2}_{0.95}(2\times 8)\approx 26.2962 \}$,所以拒绝原假设,革新后元件的平均寿命\boldkai{有明显提高}。
|
||||
}
|
||||
\questionandanswerSolution[3]{
|
||||
有人称某地成年人中大学毕业生比率不低于30\%。为检验之,随机调查该地15名成年人,发现有3名大学毕业生,取$\alpha=0.05$,问该人看法是否成立?并给出检验的$p$值。
|
||||
}{
|
||||
样本的分布为$x\sim b(15, p')$,检验的假设为
|
||||
$$
|
||||
H_0: p'\geqslant 0.3 \quad\mathrm{vs}\quad H_1: p'<0.3
|
||||
$$
|
||||
检验的$p$值为$p=P(x\leqslant 3)$,其中$x\sim b(15,0.3)$,所以
|
||||
$$
|
||||
\bm{p}=\sum_{k=0}^{3} \mathrm{C}_{15}^{k} 0.3^{k} 0.7^{15-k} \approx \bm{0.2968679279} > 0.05
|
||||
$$
|
||||
\begin{center}
|
||||
\includegraphics[width=0.3\linewidth]{imgs/2024-06-02-09-31-54.png}
|
||||
\end{center}
|
||||
所以不能拒绝原假设,只能认为该人的看法\boldkai{成立}。
|
||||
}
|
||||
\questionandanswerSolution[4]{
|
||||
某大学随机调查120名男同学,发现有50人非常喜欢看武侠小说,而随机调查的85名女同学中有23人喜欢,用大样本检验方法在$\alpha=0.05$下确认男女同学在喜爱武侠小说方面有无显著差异?并给出检验的$p$值。
|
||||
}{
|
||||
使用大样本$u$检验,
|
||||
$$
|
||||
u=\frac{\frac{50}{120}-\frac{23}{85}}{\sqrt{\frac{50}{120}\left( 1-\frac{50}{120} \right) /120 + \frac{23}{85}\left( 1-\frac{23}{85} \right) /85}} \approx 2.21548089304598
|
||||
$$
|
||||
$$
|
||||
\bm{p}=2(1-\Phi(2.21548089304598)) \bm{\approx 0.026728} < 0.05
|
||||
$$
|
||||
所以男女同学在喜爱武侠小说方面\boldkai{有显著差异}。
|
||||
}
|
||||
\questionandanswerSolution[6]{
|
||||
通常每平方米某种布上的疵点数服从泊松分布,现观测该种布100 $\mathrm{m}^{2}$,发现有126个疵点,在显著性水平为0.05下能否认为该种布每平方米上平均疵点数不超过1个?并给出检验的$p$值。
|
||||
}{
|
||||
设总体为$X\sim \operatorname{Poi}(\lambda)$,使用大样本检验假设
|
||||
$$
|
||||
H_0: \lambda\leqslant 1 \quad\mathrm{vs}\quad H_1: \lambda>1
|
||||
$$
|
||||
由于$EX=\operatorname{Var}X = \lambda$,所以$u = \frac{\sqrt{100} \left( \frac{126}{100}-1 \right) }{\sqrt{\frac{126}{100}}} \approx 2.31626409657434$,$p$值为
|
||||
$$
|
||||
\bm{p} = 1-\Phi\left( 2.31626409657434 \right) \bm{\approx 0.010272} < 0.05
|
||||
$$
|
||||
所以拒绝原假设,因此该种布每平方米上平均疵点数\boldkai{超过1个}。
|
||||
}
|
||||
\questionandanswer[9]{
|
||||
有—批电子产品共50台,产销双方协商同意找出一个检验方案,使得当次品率$p\leqslant p_0=0.04$时拒绝的概率不超过0.05,而当$p>p_1=0.30$时,接受的概率不超过0.10,请你帮助找出适当的检验方案。
|
||||
}{}
|
||||
\begin{solution}
|
||||
|
||||
{\kaishu
|
||||
这里的次品率如何定义?是指这50台电子产品中次品的频率?还是所有生产的产品的频率?前者的总体是这50台电子产品,并且是不放回抽样,那么对应的是超几何分布。后者的总体是所有生产的产品,可以近似看作放回抽样,那么对应的是二项分布。由于生产的电子产品一般不止50台,所以这里认为是后者。
|
||||
|
||||
设样本为$x\sim b(n, p)$,由于只有$50$台电子产品用于检验,所以$n\leqslant 50$,而$p$就是次品率。
|
||||
% 两次检验的假设为
|
||||
% $$
|
||||
% H_0:p\leqslant p_0=0.04 \quad\mathrm{vs}\quad H_1:p>0.04
|
||||
% $$
|
||||
% $$
|
||||
% H_0':p>p_1=0.30 \quad\mathrm{vs}\quad H_1':p\leqslant 0.30
|
||||
% $$
|
||||
拒绝域为$\{ x>c \}$,$P(x, n, p)=\mathrm{C}_{n}^{x} p^{x}(1-p)^{n-x}$。所以需要求出$n$和$x$使得
|
||||
$$
|
||||
\sum_{x=c+1}^{n} \mathrm{C}_{n}^{x}0.04^{x}(1-0.04)^{n-x} \leqslant 0.05
|
||||
$$
|
||||
$$
|
||||
\sum_{x=0}^{c} \mathrm{C}_{n}^{x} 0.30^{x} (1-0.30)^{n-x} \leqslant 0.10
|
||||
$$
|
||||
遍历$n$与$c$所有可能的取值($n = 1,2, \cdots ,50$, $c=0,1, \cdots ,n$)即可找到合适的$n$和$c$。
|
||||
\begin{minted}[breaklines=true, baselinestretch=1, frame=single, framesep=1em]{python}
|
||||
from latex2sympy2 import latex2sympy
|
||||
from sympy.abc import c, n
|
||||
import pandas as pd
|
||||
|
||||
verify1 = latex2sympy(r"\sum_{x=c+1}^{n} \binom{n}{x} 0.04^{x}(1-0.04)^{n-x} \leqslant 0.05")
|
||||
verify2 = latex2sympy(r"\sum_{x=0}^{c} \binom{n}{x} 0.30^{x} (1-0.30)^{n-x} \leqslant 0.10")
|
||||
|
||||
result = []
|
||||
for _n in range(1, 51):
|
||||
line = []
|
||||
for _c in range(0, _n + 1):
|
||||
line.append(verify1.subs({n:_n, c:_c}) and verify2.subs({n:_n, c:_c}))
|
||||
for _c in range(_n + 1, 51):
|
||||
line.append(False)
|
||||
result.append(line)
|
||||
|
||||
pd.DataFrame(result)
|
||||
\end{minted}
|
||||
|
||||
观察结果即可发现在所有结果为 \mintinline{Python}{True} 的位置里,$n$最小取15,对应的$c$为2,也就是\boldkai{取出15个产品进行检测,次品数大于2时就拒绝,否则就接受}。
|
||||
}
|
||||
|
||||
\end{solution}
|
||||
\end{enumerate}
|
||||
\end{document}
|
183
数理统计/作业/第四周作业.tex
Normal file
183
数理统计/作业/第四周作业.tex
Normal file
@ -0,0 +1,183 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
\input{mysubpreamble}
|
||||
\begin{document}
|
||||
\setcounter{chapter}{5}
|
||||
\setcounter{section}{4}
|
||||
\section{充分统计量}
|
||||
\begin{enumerate}
|
||||
\questionandanswerProof[1]{
|
||||
设$x_1,x_2, \cdots ,x_n$是来自几何分布
|
||||
$$
|
||||
P(X=x)=\theta(1-\theta)^{x},\quad x=0,1,2, \cdots
|
||||
$$
|
||||
的样本,证明 $\displaystyle T=\sum_{i=1}^{n} x_i$是充分统计量。
|
||||
}{
|
||||
$$
|
||||
p(x_1,x_2, \cdots ,x_n;\theta)=\prod_{i=1}^{n} \theta(1-\theta)^{x_i}=\theta^{n}(1-\theta)^{\sum_{i=1}^{n} x_i}=\theta^{n}(1-\theta)^{T}
|
||||
$$
|
||||
取$g(T,\theta)=\theta^{n}(1-\theta)^{T}, h(X)=1$,
|
||||
由因子分解定理可知 $\displaystyle T=\sum_{i=1}^{n} x_i$是$\theta$的充分统计量。
|
||||
}
|
||||
\questionandanswer[3]{
|
||||
设总体为如下离散分布:
|
||||
\begin{tabular}{c|cccc}
|
||||
$x$ & $a_1$ & $a_2$ & $\cdots$ & $a_k$ \\
|
||||
\hline
|
||||
$p$ & $p_1$ & $p_2$ & $\cdots$ & $p_k$ \\
|
||||
\end{tabular}。
|
||||
$x_1,x_2, \cdots ,x_n$是来自该总体的样本,
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswerProof[]{
|
||||
证明次序统计量$(x_{(1)},x_{(2)}, \cdots , x_{(n)})$是充分统计量;
|
||||
}{
|
||||
设$T=(x_{(1)},x_{(2)}, \cdots , x_{(n)})$,$X$表示一次取样。则
|
||||
$$
|
||||
\begin{aligned}
|
||||
P(X=(x_1,x_2, \cdots ,x_n)|T=t) &= \frac{P(X=(x_1,x_2, \cdots ,x_n), T=t)}{P(T=t)} \\
|
||||
&=\frac{\prod_{i=1}^{n} p_{i}}{\mathrm{P}_{n}^{n}\prod_{i=1}^{n} p_{i}}=\frac{1}{\mathrm{P}_{n}^{n}}=\frac{1}{n!} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
可见与$T$无关,所以次序统计量$(x_{(1)},x_{(2)}, \cdots , x_{(n)})$是充分统计量。
|
||||
}
|
||||
\questionandanswer[]{
|
||||
以$n_j$表示$x_1,x_2, \cdots ,x_n$中等于$a_j$的个数,证明$(n_1,n_2, \cdots ,n_k)$是充分统计量。
|
||||
}{
|
||||
设$T=(n_1,n_2, \cdots , n_k)$,$X$表示一次取样。则
|
||||
$$
|
||||
\begin{aligned}
|
||||
P(X=(x_1,x_2, \cdots ,x_n)|T=t) &= \frac{P(X=(x_1,x_2, \cdots ,x_n), T=t)}{P(T=t)} \\
|
||||
&=\frac{\prod_{j=1}^{n} p_j}{\mathrm{P}_{n}^{n} \prod_{j=1}^{n} p_j^{n_j}} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
应该与$T$无关,所以$(n_1,n_2, \cdots ,n_k)$是充分统计量。
|
||||
}
|
||||
\end{enumerate}
|
||||
\questionandanswerSolution[8]{
|
||||
设$x_1,x_2, \cdots ,x_n$是来自拉普拉斯(Laplace)分布
|
||||
$$
|
||||
p(x;\theta)=\frac{1}{2\theta} e^{-\frac{\left\vert x \right\vert }{\theta}}, \theta>0
|
||||
$$
|
||||
的样本,试给出一个充分统计量。
|
||||
}{
|
||||
设$X$表示一次取样,则
|
||||
$$
|
||||
\begin{aligned}
|
||||
P(X=(x_1,x_2, \cdots ,x_n);\theta)&=\prod_{i=1}^{n} p(x_i;\theta)=\prod_{i=1}^{n} \frac{1}{2\theta} e^{-\frac{\left\vert x \right\vert }{\theta}} = \left( \frac{1}{2\theta} \right) ^{n} e^{-\frac{1}{\theta}\sum_{i=1}^{n} \left\vert x_i \right\vert }\\
|
||||
% =\left( \frac{1}{2\theta} \right) ^{n} \left( e^{\sum_{i=1}^{n} \left\vert x_i \right\vert } \right) ^{-\frac{1}{\theta}} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
令$T=\displaystyle \sum_{i=1}^{n} \left\vert x_i \right\vert $,则上式$=\displaystyle \left( \frac{1}{2\theta} \right) ^{n} \left( e^{-\frac{T}{\theta}} \right) $。则可以令$g(T,\theta)=\displaystyle \left( \frac{1}{2\theta} \right) ^{n} \left( e^{-\frac{T}{\theta}} \right)$, $h(X)=1$,由因子分解定理可知$T=\displaystyle \sum_{i=1}^{n} \left\vert x_i \right\vert $是$\theta$的充分统计量。
|
||||
}
|
||||
\questionandanswer[10]{
|
||||
设$x_1,x_2, \cdots ,x_n$是来自正态分布$N(\mu,\sigma^{2})$的样本。
|
||||
}{}
|
||||
\begin{enumerate}
|
||||
\questionandanswerSolution[]{
|
||||
在$\mu$已知时给出$\sigma^{2}$的一个充分统计量。
|
||||
}{
|
||||
$$
|
||||
p(x_1,x_2, \cdots ,x_n; \sigma^{2})=(2\pi\sigma^{2})^{-\frac{n}{2}} \exp \left\{ -\frac{1}{2\sigma^{2}} \sum_{i=1}^{n} (x_i-\mu)^{2}\right\}
|
||||
$$
|
||||
所以可以令$\displaystyle T=\sum_{i=1}^{n} (x_i-\mu)^{2}$,则$T$是$\sigma^{2}$的一个充分统计量。
|
||||
}
|
||||
\questionandanswerSolution[]{
|
||||
在$\sigma^{2}$已知时给出$\mu$的一个充分统计量。
|
||||
}{
|
||||
$$
|
||||
\begin{aligned}
|
||||
p(x_1,x_2, \cdots ,x_n; \sigma^{2})&=(2\pi\sigma^{2})^{-\frac{n}{2}} \exp \left\{ -\frac{1}{2\sigma^{2}} \sum_{i=1}^{n} (x_i-\mu)^{2}\right\} \\
|
||||
&=(2\pi \sigma^{2})^{-\frac{n}{2}} \exp \left\{ -\frac{n\mu^{2}}{2\sigma^{2}} \right\} \exp \left\{ -\frac{1}{2\sigma^{2}}\sum_{i=1}^{n} x_i^{2} \right\} \exp \left\{ \frac{\mu}{\sigma^{2}}\sum_{i=1}^{n} x_i \right\} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
% 理论上来说,对于正态分布的参数$\mu$,可以使用样本均值$\displaystyle \bar{x}= \sum_{i=1}^{n} x_i$来估计,但无法使用因子分解定理证明,那只能认为$\bar{x}$是$\mu$的一个充分统计量了。
|
||||
令$\displaystyle T=\sum_{i=1}^{n} x_i$,则$\displaystyle g(\mu, T)=(2\pi \sigma^{2})^{-\frac{n}{2}} \exp \left\{ -\frac{n\mu^{2}}{2\sigma^{2}} \right\}\exp \left\{ \frac{\mu}{\sigma^{2}}T \right\}$,$\displaystyle h(\overrightarrow{x})=\exp \left\{ -\frac{1}{2\sigma^{2}}\sum_{i=1}^{n} x_i^{2} \right\} $。
|
||||
所以$T$是$\mu$的一个充分统计量。
|
||||
|
||||
}
|
||||
\end{enumerate}
|
||||
\questionandanswerSolution[11]{
|
||||
设$x_1,x_2, \cdots ,x_n$是来自均匀分布$U(\theta_1, \theta_2)$的样本,试给出一个充分统计量。
|
||||
}{
|
||||
$$
|
||||
p(x_1,x_2, \cdots ,x_n; \theta_1, \theta_2)= \prod_{i=1}^{n} \frac{1}{\theta_2-\theta_1} 1_{[\theta_1, \theta_2]}(x_i)=\left( \frac{1}{\theta_2-\theta_1} \right) ^{n} 1_{[\theta_1,\theta_2]}(x_{(1)}, x_{(n)})
|
||||
$$
|
||||
所以$(x_{(1)}, x_{(n)})$是一个充分统计量。
|
||||
}
|
||||
\questionandanswerSolution[12]{
|
||||
设$x_1,x_2, \cdots ,x_n$是来自均匀分布$U(\theta,2\theta), \theta>0$的样本,试给出充分统计量。
|
||||
}{
|
||||
$$
|
||||
p(x_1,x_2, \cdots ,x_n; \theta)=\prod_{i=1}^{n} \frac{1}{\theta} 1_{[\theta,2\theta]}(x_i)=\frac{1}{\theta^{n}} 1_{[\theta, 2\theta]}(x_{(1)}, x_{(n)})
|
||||
$$
|
||||
所以$(x_{(1)}, x_{(n)})$是一个充分统计量。
|
||||
}
|
||||
\questionandanswerSolution[17]{
|
||||
设$\displaystyle \binom{x_i}{y_i}, i=1,2, \cdots ,n$是来自正态分布族
|
||||
$$
|
||||
\left\{ N\left( \binom{\theta_1}{\theta_2}, \begin{pmatrix}
|
||||
\sigma_1^{2} & \rho\sigma_1\sigma_2 \\
|
||||
\rho\sigma_1\sigma_2 & \sigma_2^{2} \\
|
||||
\end{pmatrix} \right) \ ;\ -\infty<\theta_1,\theta_2<\infty, \sigma_1,\sigma_2>0,\left\vert \rho \right\vert \leqslant 1 \right\}
|
||||
$$
|
||||
的一个二维样本,寻求$(\theta_1,\sigma_1,\theta_2,\sigma_2,\rho)$的充分统计量。
|
||||
}{
|
||||
$$
|
||||
\begin{aligned}
|
||||
&p\left( \binom{x_i}{y_i};(\theta_1,\sigma_1,\theta_2,\sigma_2,\rho) \right) = \prod_{i=1}^{n} \frac{1}{2\pi\sigma_1\sigma_2\sqrt{1-\rho^{2}}} \exp \left\{ -\frac{1}{2(1-\rho^{2})}(a_i^{2}+b_i^{2}-2\rho a_i b_i) \right\} \\
|
||||
&=\left( \frac{1}{2\pi\sigma_1\sigma_2\sqrt{1-\rho^{2}}} \right) ^{n} \exp \left\{ -\frac{1}{2(1-\rho^{2})} \left( \sum_{i=1}^{n} a_i^{2}+\sum_{i=1}^{n} b_i^{2}-2\rho \sum_{i=1}^{n} a_i b_i \right)\right\} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
其中
|
||||
$$
|
||||
\sum_{i=1}^{n} a_i^{2}=\sum_{i=1}^{n} \left( \frac{x_i-\theta_1}{\sigma_1} \right) ^{2}=\frac{1}{\sigma_1^{2}}\sum_{i=1}^{n} (x_i^{2}-2\theta_1 x_i+\theta_1^{2})=\frac{1}{\sigma_1^{2}}\sum_{i=1}^{n} x_i^{2}-\frac{2\theta_1}{\sigma_1^{2}}\sum_{i=1}^{n} x_i+ \frac{\theta_1^{2}}{\sigma_1^{2}}
|
||||
$$
|
||||
$$
|
||||
\sum_{i=1}^{n} b_i^{2}=\sum_{i=1}^{n} \left( \frac{y_i-\theta_2}{\sigma_2} \right) ^{2}=\frac{1}{\sigma_2^{2}}\sum_{i=1}^{n} (y_i^{2}-2\theta_2 y_i+\theta_2^{2})=\frac{1}{\sigma_2^{2}}\sum_{i=1}^{n} y_i^{2}-\frac{2\theta_2}{\sigma_2^{2}}\sum_{i=1}^{n} y_i+\frac{\theta_2^{2}}{\sigma_2^{2}}
|
||||
$$
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\sum_{i=1}^{n} a_i b_i =\sum_{i=1}^{n} \left( \frac{x_i-\theta_1}{\sigma_1} \right) \left( \frac{y_i-\theta_2}{\sigma_2} \right) =\frac{1}{\sigma_1\sigma_2}\sum_{i=1}^{n} (x_i y_i- \theta_1 y_i - \theta_2 x_i+\theta_1 \theta_2) \\
|
||||
&=\frac{1}{\sigma_1\sigma_2}\sum_{i=1}^{n} x_i y_i- \frac{\theta_1}{\sigma_1\sigma_2}\sum_{i=1}^{n} y_i - \frac{\theta_2}{\sigma_1\sigma_2}\sum_{i=1}^{n} x_i+\frac{n\theta_1\theta_2}{\sigma_1\sigma_2} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
仔细观察即可发现
|
||||
$$
|
||||
\left( \sum_{i=1}^{n} x_i,\ \sum_{i=1}^{n} x_i^{2},\ \sum_{i=1}^{n} y_i,\ \sum_{i=1}^{n} y_i^{2},\ \sum_{i=1}^{n} x_i y_i \right)
|
||||
$$
|
||||
是此二维正态分布的充分统计量。
|
||||
}
|
||||
\questionandanswerProof[19]{
|
||||
设$x_1,x_2, \cdots ,x_n$是来自两参数指数分布
|
||||
$$
|
||||
p(x;\theta,\mu)=\frac{1}{\theta} e^{-\frac{x-\mu}{\theta}}, \quad x>\mu, \theta>0
|
||||
$$
|
||||
的样本,证明$(\bar{x},x_{(1)})$是充分统计量。
|
||||
}{
|
||||
$$
|
||||
\begin{aligned}
|
||||
&p(x_1,x_2, \cdots ,x_n; \theta,\mu)=\prod_{i=1}^{n} \frac{1}{\theta} e^{-\frac{x_i-\mu}{\theta}}=\frac{1}{\theta^{n}} \exp \left\{ -\frac{1}{\theta} \sum_{i=1}^{n} (x_i-\mu) \right\} \\
|
||||
=&\frac{1}{\theta^{n}} \exp \left\{ -\frac{1}{\theta}\sum_{i=1}^{n} x_i \right\} \exp \left\{ \frac{n\mu}{\theta} \right\} , \quad x_1,x_2, \cdots ,x_n > \mu \\
|
||||
\end{aligned}
|
||||
$$
|
||||
其中$x_1,x_2, \cdots ,x_n>\mu \iff x_{(1)} > \mu$,并且$\displaystyle \sum_{i=1}^{n} x_i=n \bar{x}$,
|
||||
所以$(\bar{x}, x_{(1)})$是充分统计量。
|
||||
}
|
||||
\questionandanswerSolution[20]{
|
||||
设随机变量$Y_i\sim N(\beta_0+\beta_1 x_i, \sigma^{2}), i=1,2, \cdots ,n$,诸$Y_i$独立,$x_1,x_2, \cdots ,x_n$是已知常数,证明$\displaystyle \left( \sum_{i=1}^{n} Y_i,\ \sum_{i=1}^{n} x_i Y_i,\ \sum_{i=1}^{n} Y_i^{2} \right) $是充分统计量。
|
||||
}{
|
||||
$$
|
||||
\begin{aligned}
|
||||
&p(Y_1,Y_2, \cdots ,Y_n; \beta_0, \beta_1, \sigma^{2})=\prod_{i=1}^{n} \frac{1}{\sqrt{2\pi}\sigma} \exp \left\{ -\frac{1}{2}\left( \frac{Y_i-(\beta_0+\beta_1 x)}{\sigma} \right) ^{2} \right\} \\
|
||||
=&\left( \frac{1}{\sqrt{2\pi}\sigma} \right) ^{n} \exp \left\{ -\frac{1}{2\sigma^{2}} \sum_{i=1}^{n} \left( Y_i-\beta_0-\beta_1 x_i \right) ^{2} \right\} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
其中
|
||||
$$
|
||||
\sum_{i=1}^{n} (Y_i-\beta_0-\beta_1 x_i)^{2}=\sum_{i=1}^{n} Y_i^{2}+n \beta_0^{2}+n\beta_1^{2}\sum_{i=1}^{n} x_i^{2} - 2\beta_0\sum_{i=1}^{n} Y_i -2\beta_1 \sum_{i=1}^{n} x_i Y_i + \beta_0\beta_1 \sum_{i=1}^{n} x_i
|
||||
$$
|
||||
其中$\beta_0,\beta_1, \sigma$为参数,$x_1,x_2, \cdots ,x_n$已知,
|
||||
所以$\displaystyle \left( \sum_{i=1}^{n} Y_i,\ \sum_{i=1}^{n} x_i Y_i,\ \sum_{i=1}^{n} Y_i^{2} \right) $是充分统计量。
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
55
概率论/mypreamble.tex
Normal file
55
概率论/mypreamble.tex
Normal file
@ -0,0 +1,55 @@
|
||||
\usepackage[margin=1in]{geometry}
|
||||
\usepackage{environ} % 加了这个再\def\myitem就不报错了
|
||||
\usepackage{extarrows}
|
||||
\usepackage{amssymb, amsfonts, amstext, amsmath, amsopn, amsthm}
|
||||
% \usepackage{mathrsfs} % \mathscr
|
||||
\usepackage{enumitem}
|
||||
\usepackage{setspace}
|
||||
\usepackage{color}
|
||||
\usepackage{mylatex}
|
||||
\usepackage{diagbox}
|
||||
\usepackage{makecell}
|
||||
\usepackage{mathtools} % \coloneqq 在好几个包里都出现了,不知道引入哪个最好
|
||||
% \usepackage{floatflt}
|
||||
% \usepackage{wrapfig}
|
||||
\usepackage{picinpar}
|
||||
% \usepackage{cutwin}
|
||||
% https://www.zhihu.com/question/26837705 试了好几个,发现能在列表和证明环境中完美使用的只有picinpar
|
||||
\usepackage{amsrefs}
|
||||
\usepackage{hyperref}
|
||||
\usepackage{subfiles}
|
||||
|
||||
|
||||
\setlist[1]{label=\arabic{enumi}., listparindent=\parindent}
|
||||
\setlist[2]{label=(\arabic{enumii}), listparindent=\parindent}
|
||||
\definecolor{shadecolor}{RGB}{204,232,207}
|
||||
|
||||
\def\myitem#1#2{
|
||||
\item \textbf{#1}
|
||||
\begin{enumerate}
|
||||
#2
|
||||
\end{enumerate}
|
||||
}
|
||||
|
||||
\ExplSyntaxOn
|
||||
\cs_set:Nn \rawquestionandanswer:Nnnn {%
|
||||
\begin{shaded}%
|
||||
\ifstrequal{#2}{-}{}{\format_item:Nn #1{#2}} #3%
|
||||
\end{shaded}%
|
||||
\begin{zhongwen}%
|
||||
#4%
|
||||
\end{zhongwen}%
|
||||
}
|
||||
\cs_set:Nn \format_item:Nn {
|
||||
\IfBlankTF{#2}{
|
||||
\item
|
||||
}{
|
||||
\item[#1{#2}]
|
||||
}
|
||||
}
|
||||
\cs_set:Nn \simple_format:n {R#1.}
|
||||
\newcommand{\questionandanswer}[3][]{%
|
||||
\rawquestionandanswer:Nnnn \simple_format:n {#1}{#2}{#3}
|
||||
}
|
||||
\ExplSyntaxOff
|
||||
% 成功实现了,而且下划线也没问题!!!似乎是函数式程序设计,或者装饰器模式?
|
18
概率论/全部作业.tex
Normal file
18
概率论/全部作业.tex
Normal file
@ -0,0 +1,18 @@
|
||||
\documentclass[a4paper]{ctexbook}
|
||||
\input{mypreamble}
|
||||
\title{\heiti\zihao{2} 《概率论》作业}
|
||||
\author{\songti 岳锦鹏}
|
||||
\newcommand{\mysignature}{10213903403 岳锦鹏}
|
||||
\date{2023年9月30日 —— 2024年1月4日}
|
||||
\begin{document}
|
||||
\renewcommand{\bar}{\xoverline} % 这一行在编译时可以取消注释,注意一定要放在\begin{document}下面才有用
|
||||
% \renewcommand{\overline}{\xoverline} % 这样会导致递归展开错误,暂时未解决
|
||||
\maketitle
|
||||
\tableofcontents
|
||||
\subfile{单元作业1}
|
||||
\subfile{单元作业2}
|
||||
\subfile{单元作业3}
|
||||
\subfile{单元作业4}
|
||||
\subfile{单元作业5}
|
||||
\subfile{单元作业6}
|
||||
\end{document}
|
159
概率论/单元作业1.tex
Normal file
159
概率论/单元作业1.tex
Normal file
@ -0,0 +1,159 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
|
||||
\begin{document}
|
||||
\chapter{单元作业1}
|
||||
\begin{enumerate}
|
||||
\item 证明$P(AB)\ge P(A)+P(B)-1$。
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&设\Omega 表示全集,则A \in \Omega, B \in \Omega \\
|
||||
&\therefore A\cup B\in \Omega \\
|
||||
&\therefore P(A\cup B)\le P(\Omega) \\
|
||||
&\therefore P(A)+P(B)-P(AB)\le 1 \\
|
||||
&\therefore P(AB)\ge P(A)+P(B)-1 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 一副标准扑克牌52张一张一张轮流分发给给4名游戏者,求每人恰好得到1张A的概率。
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&设A表示事件“每人恰好得到一张A”,由盒子模型可知: \\
|
||||
&P(A) = \frac{\mathrm{P}_{4}^{4}}{4^{4}} = \frac{4!}{256} = \frac{3}{32} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 设$P(A)=0.7,P(A-B)=0.3$,求概率$P(\overline{AB})$。
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
P(\overline{AB})&=1-P(AB)=1-P(A-(A-B)) \\
|
||||
&=1-(P(A)-P(A-B))=1-(0.7-0.3)=0.6 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 设$P(A)=a,P(B)=b,P(A\cup B)=c$,求概率$P(\overline{\bar{A}\cup \bar{B}})$。
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
P(\overline{\bar{A}\cup \bar{B}})=P(A\cap B)=P(A)+P(B)-P(A\cup B)=a+b-c
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 设$A,B\in \mathcal{F}$,证明$P(A)=P(AB)+P(A \bar{B}), \quad P(A\triangle B)=P(A)+P(B)-2P(AB)$。
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&设\Omega 表示全集 \\
|
||||
P(A)&=P(A\cap \Omega)=P(A\cap (B\cup \bar{B})) \\
|
||||
&=P(A(B+\bar{B}))=P(AB+A \bar{B})=P(AB)+P(A \bar{B}) \\
|
||||
P(A \triangle B)&=P((A\backslash B)\cup (B\backslash A))=P((A-(AB))+(B-(AB))) \\
|
||||
&=P(A)-P(AB)+P(B)-P(AB)=P(A)+P(B)-2P(AB) \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 设$\Omega =(-\infty, \infty), A=\{ x\in \Omega: 1\le x\le 5 \}, B=\{ x\in \Omega:3<x<7 \},C=\{ x\in \Omega:x<0 \}$,求下列事件$\bar{A}, A\cup B,B \bar{C}, \bar{A}\cap \bar{B}\cap \bar{C}, (A\cup B)C$。
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\bar{A}=\{ x\in \Omega: x < 1 或x>5 \} \\
|
||||
&A\cup B=\{ x\in \Omega: 1\le x<7 \} \\
|
||||
&B \bar{C}=\{ x\in \Omega:3<x<7 \} \\
|
||||
&\bar{A}\cap \bar{B}\cap \bar{C}=\{ x\in \Omega:0\le x<1或x\ge 7 \} \\
|
||||
&(A\cup B)C=\varnothing \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 设\textit{I}是任意指标集,$\{ A_i, i\in I \}$是一事件类,证明$\overline{\displaystyle \bigcup_{i \in I} A_i}=\displaystyle \bigcap_{i \in I} \overline{A_i}$, \quad $\overline{\displaystyle \bigcap_{i \in I} A_i}=\displaystyle \bigcup_{i \in I} \overline{A_i}$。
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\forall x\in \overline{\bigcup_{i \in I} A_i},\ 即x \notin \bigcup_{i \in I} A_i, 即 \\
|
||||
&\forall i \in I,x \notin A_i, \\
|
||||
&\therefore \forall i \in I, x\in \overline{A_i} \\
|
||||
&\therefore x\in \bigcap_{i \in I} \overline{A_i} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\begin{equation}
|
||||
\therefore \overline{\bigcup_{i \in I} A_i} \subseteq \bigcap_{i \in I} \overline{A_i} \tag{1}\label{eq:7.1}
|
||||
\end{equation}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\forall x\in \bigcap_{i \in I} \overline{A_i}, 即 \\
|
||||
&\forall i \in I,x\in \overline{A_i} \\
|
||||
&\therefore \forall i\in I,x \notin A_i \\
|
||||
&\therefore x\notin \bigcup_{i \in I} A_i \\
|
||||
&\therefore x\in \overline{\bigcup_{i \in I} A_i} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\begin{equation}
|
||||
\therefore \bigcap_{i \in I} \overline{A_i} \subseteq \overline{\bigcup_{i \in I} A_i} \tag{2}\label{eq:7.2}
|
||||
\end{equation}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&由\eqref{eq:7.1}\eqref{eq:7.2}可知,\overline{\bigcup_{i \in I} A_i}=\bigcap_{i \in I} \overline{A_i} \\
|
||||
&由对偶公式可知, \overline{\overline{\bigcup_{i \in I} A_i}}=\overline{\bigcap_{i \in I} \overline{A_i}} \\
|
||||
&\therefore \overline{\bigcap_{i \in I} \overline{A_i}}=\bigcup_{i \in I} A_i \\
|
||||
&\because \{ \overline{A_i}|i\in I \}也是一事件类 \\
|
||||
&\therefore 将\overline{A_i}替换为A_i后可得 \\
|
||||
&\overline{\bigcap_{i \in I} A_i}=\bigcup_{i \in I} \overline{A_i} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 从装有10双不同尺码或不同样式的皮鞋的箱子中, 任取4只, 求恰能成1双的概率。
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&设A表示事件“恰能成1双”,B表示事件“恰能成2双”,C表示事件“不能成双”, \\
|
||||
&则由不返回抽样模型可知: \\
|
||||
P(A)&=1-P(B)-P(C)=1-\frac{\mathrm{C}_{10}^{2}}{\mathrm{C}_{20}^{4}}-\frac{\mathrm{C}_{20}^{1}\mathrm{C}_{18}^{1}\mathrm{C}_{16}^{1}\mathrm{C}_{14}^{1}}{\mathrm{P}_{20}^{4}} \\
|
||||
&=1-\frac{\binom{10}{2}}{\binom{20}{4}}-\frac{\binom{20}{1}\binom{18}{1}\binom{16}{1}\binom{14}{1}}{\binom{20}{4}\times 4!} = \frac{96}{323} \approx 0.297213622291022 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 现从有15名男生和30名女生的班级中随机挑选10名同学参加某项课外活动, 求在被挑选的同学中恰好有3名男生的概率。
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&设A表示事件“在被挑选的同学中恰好有3名男生”,则 \\
|
||||
&P(A)=\frac{\mathrm{C}_{15}^{3}\mathrm{C}_{30}^{7}}{\mathrm{C}_{45}^{10}}=\frac{\binom{15}{3}\binom{30}{7}}{\binom{45}{10}} = \frac{3958500}{13633279} \approx 0.290355680390609 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 设$\mathcal{F}$是$\Omega$上的事件域,$A,B\in \mathcal{F}$,证明$A\cup B,AB\in \mathcal{F}$。
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&设A_1=A,A_2=B,\forall n>2,A_n=\varnothing \\
|
||||
&\because \mathcal{F}是\Omega上的事件域,\forall n\geqslant 1,A_n\in \mathcal{F} \\
|
||||
&\therefore \bigcup_{n=1}^{\infty}A_n=A\cup B\in \mathcal{F} \\
|
||||
&又\because A,B\in \mathcal{F} \\
|
||||
&\therefore \bar{A},\bar{B}\in \mathcal{F} \\
|
||||
&同理,\bar{A}\cup \bar{B}\in \mathcal{F} \\
|
||||
&\therefore \overline{\bar{A}\cup \bar{B}}=AB\in \mathcal{F} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\end{enumerate}
|
||||
\end{document}
|
198
概率论/单元作业2.tex
Normal file
198
概率论/单元作业2.tex
Normal file
@ -0,0 +1,198 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
|
||||
\begin{document}
|
||||
\renewcommand{\bar}{\xoverline}
|
||||
\chapter{单元作业2}
|
||||
\begin{enumerate}
|
||||
\item 三人独立地对同一目标进行射击, 各人击中目标的概率分别是0.7, 0.8, 0.6, 求目标被击中的概率.
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&将三人击中目标的事件分别表示为A、B、C, \\
|
||||
&则P(A)=0.7, P(B)=0.8, P(C)=0.6, \\
|
||||
&P(目标被击中) = P(A\cup B\cup C) \\
|
||||
&\because 三人独立射击 \\
|
||||
&\therefore A、B、C相互独立 \\
|
||||
&\therefore \bar{A}、\bar{B}、\bar{C}相互独立 \\
|
||||
\end{aligned}
|
||||
$$ $$
|
||||
\begin{aligned}
|
||||
\therefore P(A\cup B\cup C)&=P(\overline{\bar{A} \bar{B} \bar{C}}) = 1 - P(\bar{A} \bar{B} \bar{C}) \\
|
||||
&=1 - P(\bar{A})P(\bar{B})P(\bar{C}) \\
|
||||
&=1 - (1-P(A))(1-P(B))(1-P(C)) \\
|
||||
&=1-(1-0.7)*(1-0.8)*(1-0.6) \\
|
||||
&= 0.976 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
|
||||
\item 制作某个产品有两个关键工序, 第一道和第二道工序的不合格品的概率分别为3\%和5\%, 假定两道工序互不影响, 试问该产品为不合格品的概率(答案保留至小数点后4位).
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&令A:第一道工序不合格,B:第二道工序不合格 \\
|
||||
&则P(A)=0.03,P(B)=0.05 \\
|
||||
&则P(该产品为不合格品)=P(A\cup B) \\
|
||||
&\because 两道工序互不影响 \\
|
||||
&\therefore A与B相互独立 \\
|
||||
&\therefore \bar{A}与\bar{B}相互独立 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
$$
|
||||
\begin{aligned}
|
||||
\therefore P(A\cup B)&=P(\overline{\bar{A}\bar{B}})=1-P(\bar{A}\bar{B}) \\
|
||||
&=1-P(\bar{A})P(\bar{B}) \\
|
||||
&=1- (1-P(A))(1-P(B)) \\
|
||||
&=1-(1-0.03)(1-0.05) \\
|
||||
&= 0.0785 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\myitem{甲乙丙三个同学同时独立参加考试, 不及格的概率分别为: 0.2, 0.3, 0.4,}{
|
||||
\item 求恰有2位同学不及格的概率;\label{1}
|
||||
\item 若已知3位同学中有2位不及格,求其中1位是同学乙的概率. \label{2}
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&设A、B、C分别表示事件甲不合格、乙不合格、丙不合格 \\
|
||||
&则P(A)=0.2, P(B)=0.3, P(C)=0.4 \\
|
||||
&P(\bar{A})=0.8, P(\bar{B})=0.7, P(\bar{C})=0.6 \\
|
||||
&且A、B、C相互独立 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\ref{1}
|
||||
$$
|
||||
\begin{aligned}
|
||||
P(恰有2位同学不合格)&=P(AB \bar{C}+A \bar{B} C+\bar{A}BC) \\
|
||||
&=P(A)P(B)P(\bar{C})+P(A)P(\bar{B})P(C)+P(\bar{A})P(B)P(C) \\
|
||||
&=0.2\times 0.3\times 0.6+0.2\times 0.7\times 0.4+0.8\times 0.3\times 0.4 \\
|
||||
&= 0.188 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\ref{2}
|
||||
\setlength{\lineskip}{2.5pt}
|
||||
\setlength{\lineskiplimit}{2.5pt}
|
||||
$$
|
||||
\begin{aligned}
|
||||
% \setstretch{1.5}
|
||||
P(其中1位是同学乙)&=P(\left. B\ \right|\ 恰有2位同学不合格) \\
|
||||
&=\frac{P(B\cap 恰有2位同学不合格)}{P(恰有2位同学不合格)} \\
|
||||
&=\frac{P(AB \bar{C} + \bar{A} BC)}{P(AB \bar{C}+A \bar{B}C+\bar{A}BC)} \\
|
||||
&=\frac{P(A)P(B)P(\bar{C})+P(\bar{A})P(B)P(C)}{P(A)P(B)P(\bar{C})+P(A)P(\bar{B})P(C)+P(\bar{A})P(B)P(C)} \\
|
||||
&=\frac{0.2\times 0.3\times 0.6+0.8\times 0.3\times 0.4}{0.2\times 0.3\times 0.6+0.2\times 0.7\times 0.4+0.8\times 0.3\times 0.4} \\
|
||||
&= \frac{33}{47} \\
|
||||
&\approx 0.702127659574468 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
}
|
||||
\item 甲袋中装有2个白球和4个黑球, 乙袋中装有3个白球和2个黑球, 现随机地从乙袋中取出一球放入甲袋, 然后从甲袋中随机取出一球, 试求从甲袋中取得的球是白球的概率.
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&设A表示从乙袋中取出的是白球,B表示从甲袋中取出的是白球 \\
|
||||
则P(B) &= P(A)P(B|A)+P(\bar{A})P(B|\bar{A}) \\
|
||||
&=\frac{3}{3+2}\times \frac{2+1}{2+4+1}+\frac{2}{3+2}\times \frac{2}{2+4+1} \\
|
||||
&= \frac{13}{35} \\
|
||||
&\approx 0.371428571428571 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 设n只罐子的每一只中装有4个白球和6个黑球, 另有一只罐子中装有5个白球和5个黑球.从这n+1个罐子中随机地选择一只罐子, 从中任取两个球, 结果发现两个都是黑球. 已知在此条件下, 有5个白球和3个黑球留在选出的罐子中的条件概率是1/7, 求n的值.
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&设A表示事件:选中的是第n+1个罐子 \\
|
||||
&设B表示事件:取出的两个都是黑球 \\
|
||||
&则事件:有5个白球和3个黑球留在选出的罐子中,\\
|
||||
&即选中的是第n+1个罐子,并且取出的两个都是黑球, 可表示为AB\\
|
||||
&\therefore P(A|B)=\frac{1}{7}, P(A)=\frac{1}{n+1} \\
|
||||
& P(B|A)=\frac{\mathrm{C}_{5}^{2}}{\mathrm{C}_{10}^{2}}=\frac{2}{9} \\
|
||||
\therefore P(B)&=P(A)P(B|A)+P(\bar{A})P(B|\bar{A})\\
|
||||
&=\frac{1}{n+1}\times \frac{\mathrm{C}_{5}^{2}}{\mathrm{C}_{10}^{2}}+\frac{n}{n+1}\times \frac{\mathrm{C}_{6}^{2}}{\mathrm{C}_{10}^{2}} \\
|
||||
&=\frac{3 n + 2}{9 (n + 1)} \\
|
||||
% &\because A与B相互独立 \\
|
||||
\therefore P(A|B)&=\frac{P(A)P(B|A)}{P(B)} \\
|
||||
&=\frac{\frac{1}{n+1}\times \frac{2}{9}}{\frac{3n+2}{9(n+1)}} \\
|
||||
&= \frac{2}{3 n + 2} = \frac{1}{7} \\
|
||||
&\therefore n=4 \\
|
||||
% solve(latex2sympy(r"\frac{2}{3 n + 2} = \frac{1}{7}")) = {n: 4} = []
|
||||
% solve(latex2sympy(r"\frac{1}{2} = n"))
|
||||
% var["n"]
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 设有三张卡片, 第一张两面皆为红色, 第二张两面皆为黄色, 第三张一面是红色一面是黄色. 随机地选择一张卡片并随机地选择其中一面. 如果已知此面是红色, 求另一面也是红色的概率.
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&设A、B、C分别表示选到了第一、二、三张卡片,设R表示选择的一面是红色。 \\
|
||||
&则P(A) = P(B) = P(C) = \frac{1}{3} \\
|
||||
&P(R|A)=1, P(R|B)=0, P(R|C)=\frac{1}{2} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
$$
|
||||
\begin{aligned}
|
||||
则P(另一面也是红色) &= P(A|R) \\
|
||||
&=\frac{P(A)P(R|A)}{P(A)P(R|A)+P(B)P(R|B)+P(C)P(R|C)} \\
|
||||
&=\frac{\frac{1}{3}\times 1}{\frac{1}{3}\times 1+\frac{1}{3}\times 0+\frac{1}{3}\times \frac{1}{2}} \\
|
||||
&= \frac{2}{3} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 从装有r个红球和w个白球的盒子中不返回的取出两只, 求事件“第一只为红球, 第二只为白球”的概率.
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&设A表示取出的两只球一红一白 \\
|
||||
&则P(第一只为红球,第二只为白球) = \frac{P(A)}{\mathrm{P}_{2}^{2}} \\
|
||||
&=\frac{\frac{\mathrm{C}_{r}^{1}\mathrm{C}_{w}^{1}}{\mathrm{C}_{r+w}^{2}}}{\mathrm{P}_{2}^{2}} \\
|
||||
&=\frac{\frac{\binom{r}{1}\binom{w}{1}}{\binom{r+w}{2}}}{2!} \\
|
||||
&= \frac{r w}{(r + w) (r + w - 1)} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 已知$P(A)=\frac{1}{4}, P(B|A)=\frac{1}{3},P(A|B)=\frac{1}{2}$,求概率$P(A\cup B)$。
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&P(AB) = P(B|A)P(A) = \frac{1}{3}\times \frac{1}{4} = \frac{1}{12} \\
|
||||
&P(B)=\frac{P(AB)}{P(A|B)}=\frac{\frac{1}{12}}{\frac{1}{2}} = \frac{1}{6} \\
|
||||
&\therefore P(A\cup B)=P(A)+P(B)-P(AB) \\
|
||||
&=\frac{1}{4}+\frac{1}{6} - \frac{1}{12} \\
|
||||
&= \frac{1}{3} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 设$P(A)=P(B)=\frac{1}{3},P(A|B)=\frac{1}{6}$,求概率$P(\bar{A}|\bar{B})$。
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&P(AB)=P(B)P(A|B)=\frac{1}{3}\times \frac{1}{6} = \frac{1}{18} \\
|
||||
&P(\bar{A} \bar{B})=P(\overline{A\cup B}) = 1 - P(A\cup B)=1 - (P(A)+P(B)-P(AB))\\
|
||||
&=1 - (\frac{1}{3}+\frac{1}{3}-\frac{1}{18}) = \frac{7}{18}\\
|
||||
&P(\bar{B}) = 1-P(B) = 1 - \frac{1}{3} = \frac{2}{3} \\
|
||||
&\therefore P(\bar{A}|\bar{B})=\frac{P(\bar{A} \bar{B})}{P(\bar{B})}=\frac{\frac{7}{18}}{\frac{2}{3}} = \frac{7}{12} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\end{enumerate}
|
||||
\end{document}
|
168
概率论/单元作业3.tex
Normal file
168
概率论/单元作业3.tex
Normal file
@ -0,0 +1,168 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
|
||||
\begin{document}
|
||||
\chapter{单元作业3}
|
||||
\begin{enumerate}
|
||||
\item 试用随机变量$X$的分布函数$F_{X}(x)$表示随机变量$-\min(X,0)$的分布函数。
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
% F_{-\min(X,0)}(x)=-\min(F_{X}(x),0)
|
||||
F_{-\min(X,0)}(x) & = P(-\min(X,0)\leqslant x) \\
|
||||
& = P(\min(X,0)\geqslant -x) \\
|
||||
& = P(X\geqslant -x, 0\geqslant -x) \\
|
||||
& = P(X\geqslant -x, x\geqslant 0) \\
|
||||
&=\begin{cases} P(X\geqslant -x), & x\geqslant 0 \\ 0, & x<0 \end{cases} \\
|
||||
&=\begin{cases} 1-P(X<-x), & x\geqslant 0 \\ 0, & x<0 \end{cases} \\
|
||||
&=\begin{cases} 1-F_{X}(-x-0), & x\geqslant 0 \\ 0, & x<0 \end{cases} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 设随机变量$X$等可能地取值0和1, 求$X$的分布函数。
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
F_{X}(x)=\begin{cases} 0, & x<0 \\ \frac{1}{2}, & 0\leqslant x<1 \\ 1, & x\geqslant 1 \end{cases}
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 设离散型随机变量X的分布列为$\displaystyle P(X=k)=\frac{c}{2^{k}}, \quad k=0, 1, 2, \ldots $,求常数$c$的值。
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\because \sum_{k = 0}^{\infty}\frac{c}{2^{k}}=1 \\
|
||||
&\therefore c \sum_{k=0}^{\infty}\frac{1}{2^{k}}=c \frac{1}{1-\frac{1}{2}}=2c=1 \\
|
||||
&\therefore c=\frac{1}{2} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 设随机变量$X$的概率密度函数为$p(x)=\begin{cases} ce^{-\sqrt{x}}, & x>0 \\ 0, & x\leqslant 0 \end{cases}$,求常数$c$。
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\because \int_{-\infty}^{+\infty} p(x) \mathrm{d}x=1 \\
|
||||
&\therefore \int_{0}^{+\infty} ce^{-\sqrt{x}} \mathrm{d}x=c \int_{0}^{+\infty} e^{-\sqrt{x}} \mathrm{d}x = 2c=1 \\
|
||||
&\therefore c=\frac{1}{2} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 设$X\sim N(10,4)$,求概率$P(6<X\leqslant 9)$和$P(7\leqslant X<12)$。
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\mu =10,\sigma ^{2}=4,\sigma =2 \\
|
||||
&\therefore \frac{x-10}{2}\sim N(0,1) \\
|
||||
P(6<X\leqslant 9) & = P(\frac{6-10}{2}<\frac{X-10}{2}\leqslant \frac{9-10}{2}) \\
|
||||
& = \Phi (\frac{9-10}{2})-\Phi (\frac{6-10}{2}) \\
|
||||
& = \Phi (-0.5)-\Phi (-2) \\
|
||||
& = \Phi (2)-\Phi (0.5) \\
|
||||
& \approx 0.9772-0.6915 \\
|
||||
& = 0.2857 \\
|
||||
P(7\leqslant X<12) & = P(\frac{7-10}{2}\leqslant \frac{X-10}{2}< \frac{12-10}{2}) \\
|
||||
& = \Phi (\frac{12-10}{2}-0)-\Phi (\frac{7-10}{2}-0) \\
|
||||
& = \Phi (1)-\Phi (-1.5) \\
|
||||
& = \Phi (1)-(1-\Phi (1.5)) \\
|
||||
& \approx 0.8413-(1-0.9332) \\
|
||||
& = 0.7745 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 设$X\sim \operatorname{Exp} (\lambda )$,求$\lambda $使得$P(X>1)=2P(X>2)$。
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
由P(X>1)&=2P(X>2)可知: \\
|
||||
\int_{1}^{+\infty} \lambda e^{-\lambda x} \mathrm{d}x&=2\int_{2}^{+\infty} \lambda e^{-\lambda x} \mathrm{d}x \\
|
||||
\left. - e^{- \lambda x} \right|_{1}^{+\infty}&=-2\left. e^{- \lambda x} \right|_{2}^{+\infty} \\
|
||||
e^{-\lambda }&=2e^{-2\lambda } \\
|
||||
2(e^{-\lambda })^{2}-e^{-\lambda }&=0 \\
|
||||
e^{-\lambda }(2e^{-\lambda }-1)&=0 \\
|
||||
\end{aligned} \hspace{5em}
|
||||
\begin{aligned}
|
||||
&\because e^{-\lambda }\neq 0 \\
|
||||
&\therefore 2e^{-\lambda }-1=0 \\
|
||||
&\therefore e^{-\lambda }=\frac{1}{2} \\
|
||||
&\therefore \lambda =-\ln (\frac{1}{2})=\ln 2 \\
|
||||
% &\left. \frac{(- \lambda x - 1) e^{- \lambda x}}{\lambda} \right|_{1}^{+\infty} =2\left. \frac{(- \lambda x - 1) e^{- \lambda x}}{\lambda} \right|_{2}^{+\infty} \\
|
||||
% &0-\frac{(-\lambda -1)e^{-\lambda }}{\lambda }=2 (0-\frac{(-2\lambda -1)e^{-2\lambda }}{\lambda }) \\
|
||||
% &(\lambda +1)e^{-\lambda }=2(2\lambda +1)e^{-2\lambda } \\
|
||||
% &\lambda e^{-\lambda }+e^{-\lambda }=4\lambda e^{-2\lambda }+2e^{-2\lambda } \\
|
||||
% &使用fx-991 \mathrm{CN}\ \mathrm{X}解得\lambda =2857100 \\
|
||||
% solve(latex2sympy(r"0-\frac{(-\lambda -1)e^{-\lambda }}{\lambda }=2 (0-\frac{(-2\lambda -1)e^{-2\lambda }}{\lambda })"))
|
||||
% solve(0 - (-y - 1)*exp(-y)/y - 2*(0 - (-1*2*y - 1)*exp(-1*2*y)/y))
|
||||
\end{aligned}
|
||||
$$
|
||||
\begin{center}
|
||||
% \includegraphics[width=0.5\linewidth]{imgs/2023-11-08-13-38-39.png}
|
||||
\end{center}
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 设随机变量$X$服从几何分布$\operatorname{Ge}(p)$,求$X$的数学期望$EX$。
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\because 0<p<1 \\
|
||||
&\therefore EX=\sum_{k=1}^{\infty}kp(1-p)^{k-1} = \frac{1}{p} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 设随机变量$X$服从几何分布$\operatorname{Ge}(p)$,求$X$的方差$\operatorname{Var}X$。
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\because 0<p<1 \\
|
||||
\therefore \operatorname{Var}X & = EX^{2}-(EX)^{2} \\
|
||||
& = \sum_{k=1}^{\infty}k^{2}p(1-p)^{k-1} - \left( \frac{1}{p} \right) ^{2} \\
|
||||
& = \frac{2 - p}{p^{2}} - \frac{1}{p^{2}} \\
|
||||
& = \frac{1-p}{p^{2}} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 设随机变量$X$服从Gamma分布$\operatorname{Ga}(\alpha ,\lambda )$,求数学期望$EX^{n}$。
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
EX^{n} & = \int_{-\infty}^{+\infty} x^{n}p(x) \mathrm{d}x \\
|
||||
&=\int_{0}^{+\infty} x^{n} \cdot \frac{\lambda ^{\alpha }}{\Gamma (\alpha )}x^{\alpha -1}e^{-\lambda x} \mathrm{d}x \\
|
||||
&=\frac{1}{\lambda ^{n}\Gamma(\alpha )}\int_{0}^{+\infty} (\lambda x)^{n+\alpha -1}e^{-\lambda x} \mathrm{d}(\lambda x) \\
|
||||
&=\frac{\Gamma(n+\alpha )}{\lambda ^{n}\Gamma(\alpha )} \\
|
||||
&=\frac{\alpha (\alpha +1)\cdots(\alpha +n-1)}{\lambda ^{n}} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 设随机变量$X$服从均匀分布$U(0,1)$,计算随机变量$X^{3}$的方差。
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
由题意可知,X的概率密度函数为p(x)=\begin{cases} 0, & x<0 或x>1\\ 1, & 0\leqslant x\leqslant 1 \end{cases}
|
||||
$$
|
||||
$$
|
||||
\begin{aligned}
|
||||
\operatorname{Var}X^{3} & = E(X^{3})^{2}-(EX^{3})^{2} \\
|
||||
&=\int_{-\infty}^{+\infty} x^{6}p(x) \mathrm{d}x-\left( \int_{-\infty}^{+\infty} x^{3}p(x) \mathrm{d}x \right) ^{2} \\
|
||||
&=\int_{0}^{1} x^{6} \mathrm{d}x-\left( \int_{0}^{1} x^{3} \mathrm{d}x \right) ^{2} \\
|
||||
& = \frac{9}{112} \\
|
||||
& \approx 0.0803571428571429 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\end{enumerate}
|
||||
\end{document}
|
228
概率论/单元作业4.tex
Normal file
228
概率论/单元作业4.tex
Normal file
@ -0,0 +1,228 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
|
||||
\begin{document}
|
||||
\chapter{单元作业4}
|
||||
\begin{enumerate}
|
||||
\item 若二维离散型随机变量$(X,Y)$有联合分布列如下:
|
||||
|
||||
\begin{center}
|
||||
% \renewcommand\arraystretch{1.5}
|
||||
\begin{tabular}{c|ccc}
|
||||
% \hline
|
||||
\diagbox{$X$}{$Y$} & $0$ & $1$ & $2$ \\
|
||||
\hline
|
||||
$0$ & $\frac{1}{2}$ & $\frac{1}{8}$ & $\frac{1}{4}$ \\
|
||||
% \hline
|
||||
$1$ & $\frac{1}{16}$ & $\frac{1}{16}$ & $0$ \\
|
||||
% \hline
|
||||
\end{tabular}
|
||||
\end{center}
|
||||
求$X$与$Y$的边际分布列。
|
||||
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
|
||||
$X$和$Y$的边际分布列分别为
|
||||
|
||||
\begin{center}
|
||||
\renewcommand\arraystretch{1.5}
|
||||
\begin{tabular}{c|cc}
|
||||
$X$ & $0$ & $1$ \\
|
||||
\hline
|
||||
$P$ & \makecell{$\dfrac{7}{8}$} & $\dfrac{1}{8}$ \\
|
||||
\end{tabular} \qquad
|
||||
\begin{tabular}{c|ccc}
|
||||
$Y$ & $0$ & $1$ & $2$ \\
|
||||
\hline
|
||||
$P$ & $\dfrac{9}{16}$ & $\dfrac{3}{16}$ & $\dfrac{1}{4}$ \\
|
||||
\end{tabular}
|
||||
\end{center}
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
|
||||
\item 设随机变量$(X,Y)$的概率密度函数为
|
||||
$$
|
||||
p(x,y)=\begin{cases}
|
||||
3x,\quad & \text{若}0<y<x<1; \\
|
||||
0,\quad & \text{其他}. \\
|
||||
\end{cases}
|
||||
$$
|
||||
求$X$与$Y$的边际概率密度函数,并判断$X$与$Y$是否互相独立。
|
||||
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
|
||||
\begin{window}[0,r,
|
||||
{\includexopp[0.3]{4.2.1}},
|
||||
{}]
|
||||
$$
|
||||
\begin{aligned}
|
||||
p_{X}(x)&=\int_{-\infty}^{+\infty} p(x,y) \mathrm{d}y=\begin{cases}
|
||||
\int_{0}^{x} 3x \mathrm{d}y,\quad & 0\leqslant x\leqslant 1 \\
|
||||
0,\quad & x<0 \text{或} x>1 \\
|
||||
\end{cases}\\
|
||||
&=\begin{cases}
|
||||
3x^{2},\quad & 0\leqslant x\leqslant 1 \\
|
||||
0,\quad & x<0 或x>1 \\
|
||||
\end{cases}
|
||||
\end{aligned}
|
||||
$$
|
||||
|
||||
$$
|
||||
\begin{aligned}
|
||||
p_{Y}(y)&=\int_{-\infty}^{+\infty} p(x,y) \mathrm{d}x=\begin{cases}
|
||||
\int_{y}^{1} 3x \mathrm{d}x, \quad & 0\leqslant y\leqslant 1 \\
|
||||
0,\quad & x<0 或 x>1 \\
|
||||
\end{cases}\\
|
||||
&=\begin{cases}
|
||||
\frac{3}{2}-\frac{3}{2}y^{2},\quad & 0\leqslant y\leqslant 1 \\
|
||||
0,\quad & y<0 或 y>1 \\
|
||||
\end{cases}
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{window}
|
||||
|
||||
\noindent$p(1,1)=3,p_{X}(1)=3,p_{Y}(1)=0$,于是$p(1,1)\neq p_{X}(1)\cdot p_{Y}(1)$,所以$X$和$Y$互相不独立。
|
||||
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
|
||||
\item 设随机变量$X$与$Y$相互独立,且$X$服从均匀分布$U(0,1)$,$Y$服从指数分布$\operatorname{Exp}(1)$。求
|
||||
|
||||
\begin{enumerate}
|
||||
\item $(X,Y)$的联合概率密度函数$p(x,y)$;
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
|
||||
$$
|
||||
p_{X}(x)=\begin{cases}
|
||||
1,\quad & x\in [0,1] \\
|
||||
0,\quad & x<0 或 x>1 \\
|
||||
\end{cases}\quad p_{Y}(y)=\begin{cases}
|
||||
e^{-y},\quad & y\geqslant 0 \\
|
||||
0,\quad & y< 0 \\
|
||||
\end{cases}
|
||||
$$
|
||||
|
||||
$$
|
||||
p(x,y)=\begin{cases}
|
||||
e^{-y},\quad & x\in [0,1], y\geqslant 0 \\
|
||||
0,\quad & 其他 \\
|
||||
\end{cases}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 概率$P(X+Y\leqslant 1)$;
|
||||
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
|
||||
令$Z=X+Y$,则随机变量$Z$的概率密度函数为
|
||||
$$
|
||||
p_{Z}(z)=\int_{-\infty}^{+\infty} p_{X}(x)p_{Y}(z-x) \mathrm{d}x=\begin{cases}
|
||||
\int_{0}^{1} e^{x-z} \mathrm{d}x ,\quad & z>1\\
|
||||
\int_{0}^{z} e^{x-z} \mathrm{d}x,\quad & 0\leqslant z\leqslant 1 \\
|
||||
0,\quad & z<0 \\
|
||||
\end{cases}=\begin{cases}
|
||||
e^{1-z}-e^{-z},\quad & z>1 \\
|
||||
1-e^{-z},\quad & 0\leqslant z\leqslant 1 \\
|
||||
0,\quad & z<0 \\
|
||||
\end{cases}
|
||||
$$
|
||||
所以
|
||||
$$
|
||||
P(X+Y\leqslant 1)=\int_{-\infty}^{1} p_{Z}(z) \mathrm{d}z=\int_{0}^{1} (1-e^{-z}) \mathrm{d}z=1+(\frac{1}{e}-1)=\frac{1}{e}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 概率$P(X\leqslant Y)$。
|
||||
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
令随机变量$Z=X-Y$,则$Z$的概率密度函数为
|
||||
$$
|
||||
p_{Z}(z)=\int_{-\infty}^{+\infty} p(x,x-z) \mathrm{d}x=\begin{cases}
|
||||
0,\quad & z>1 \\
|
||||
\int_{z}^{1} e^{z-x} \mathrm{d}x,\quad & 0\leqslant z\leqslant 1 \\
|
||||
\int_{0}^{1} e^{z-x} \mathrm{d}x,\quad & z<0 \\
|
||||
\end{cases}=\begin{cases}
|
||||
0,\quad & z>1 \\
|
||||
1-e^{z-1},\quad & 0\leqslant z\leqslant 1 \\
|
||||
e^{z}-e^{z-1},\quad & z<0 \\
|
||||
\end{cases}
|
||||
$$
|
||||
所以
|
||||
$$
|
||||
P(X\leqslant Y)=P(X-Y\leqslant 0)=\int_{-\infty}^{0} (e^{z}-e^{z-1}) \mathrm{d}z=1-\frac{1}{e}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\end{enumerate}
|
||||
|
||||
\item 设随机变量$(X,Y)$的概率密度函数为
|
||||
$$
|
||||
p(x,y)=\begin{cases}
|
||||
Ae^{-(3x+2y)},\quad & x>0,y>0; \\
|
||||
0,\quad & \text{otherwise}. \\
|
||||
\end{cases}
|
||||
$$
|
||||
求:
|
||||
\begin{enumerate}
|
||||
\item 常数$A$的值;
|
||||
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\int_{-\infty}^{+\infty} \int_{-\infty}^{+\infty} p(x,y) \mathrm{d}x \mathrm{d}y=\int_{0}^{+\infty} \int_{0}^{+\infty} Ae^{-(3x+2y)} \mathrm{d}x \mathrm{d}y=\int_{0}^{+\infty} \left. -\frac{1}{3}Ae^{-(3x+2y)} \right|_{0}^{+\infty} \mathrm{d}y\\
|
||||
=&\int_{0}^{+\infty} \frac{1}{3}Ae^{-2y} \mathrm{d}y=\left. -\frac{1}{6}Ae^{-2y} \right|_{0}^{+\infty}=\frac{1}{6}A=1
|
||||
\end{aligned}
|
||||
$$
|
||||
所以常数$A$的值为$6$。
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 分布函数$F(x,y)$;
|
||||
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
|
||||
由题意可知,当$x\leqslant 0$ 或$y\leqslant 0$时,$F(x,y)=0$。
|
||||
|
||||
当$x>0,y>0$时,$
|
||||
\displaystyle F(x,y)
|
||||
=\int_{0}^{y} \int_{0}^{x} 6e^{-(3u+2v)} \mathrm{d}u \mathrm{d}v
|
||||
=\int_{0}^{y} \left. -2e^{-(3u+2v)} \right|_{0}^{x} \mathrm{d}v
|
||||
=\int_{0}^{y} \left(2e^{-2v}-2e^{-(3x+2v)}\right) \mathrm{d}v
|
||||
=\left. -e^{-2v} \right|_{0}^{y}+\left. e^{-(3x+2v)} \right|_{0}^{y}
|
||||
=-e^{-2y}+1+e^{-(3x+2y)}-e^{-3x}
|
||||
=e^{-(3x+2y)}-e^{-3x}-e^{-2y}+1
|
||||
$
|
||||
|
||||
所以
|
||||
$$
|
||||
\begin{aligned}
|
||||
F(x,y)=\begin{cases}
|
||||
e^{-(3x+2y)}-e^{-3x}-e^{-2y}+1,\quad & x>0,y>0 \\
|
||||
0,\quad & \text{otherwise} \\
|
||||
\end{cases}
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 概率$P(-2<X\leqslant 2,-3<Y\leqslant 3)$。
|
||||
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&P(-2<X\leqslant 2,-3<Y\leqslant 3)=P(X\leqslant 2,Y\leqslant 3)=F(2,3)\\
|
||||
=&e^{-(3\times 2+2\times 3)}-e^{-3\times 2}-e^{-2\times 3}+1 \\
|
||||
=&1 +e^{-12} - 2e^{-6}
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\end{enumerate}
|
||||
\end{enumerate}
|
||||
|
||||
\end{document}
|
239
概率论/单元作业5.tex
Normal file
239
概率论/单元作业5.tex
Normal file
@ -0,0 +1,239 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
\setlength{\textheight}{300em}
|
||||
% \PassOptionsToPackage{papersize={170mm, 1000em}}{geometry}
|
||||
% \usepackage[textheight=1em]{geometry}
|
||||
\setlength{\paperheight}{300em}
|
||||
|
||||
\begin{document}
|
||||
\chapter{单元作业5}
|
||||
\begin{enumerate}
|
||||
\questionandanswer[]{设随机变量$X$与$Y$满足$EX=EY=0$, $\operatorname{Var}X=\operatorname{Var}Y=1$, $\operatorname{Cov}(X,Y)=\rho $,证明$E\max(X^{2},Y^{2})\leqslant 1+\sqrt{1-\rho ^{2}}$}{
|
||||
\begin{proof}
|
||||
|
||||
因为$\operatorname{Cov}(X,Y)=EXY-EXEY=\rho $,而$EX=EY=0$,所以$EXY=\rho $。\\
|
||||
而$\operatorname{Var}X=EX^{2}-(EX)^{2}=EX^{2}=1$,$\operatorname{Var}Y=EY^{2}-(EY)^{2}=EY^{2}=1$。
|
||||
|
||||
根据$\max(a,b)=\frac{\left\vert a+b \right\vert +\left\vert a-b \right\vert }{2}$和期望的线性性质,
|
||||
\begin{equation}\label{eq:1}\tag{1}
|
||||
E \max(X^{2},Y^{2})=E \frac{\left\vert X^{2}+Y^{2} \right\vert +\left\vert X^{2}-Y^{2} \right\vert }{2}=\frac{1}{2}E\left\vert X^{2}+Y^{2} \right\vert +\frac{1}{2}E\left\vert X^{2}-Y^{2} \right\vert
|
||||
\end{equation}
|
||||
|
||||
其中,$E\left\vert X^{2}+Y^{2} \right\vert =E(X^{2}+Y^{2})=EX^{2}+EY^{2}=2$,
|
||||
$E\left\vert X^{2}-Y^{2} \right\vert =E\left\vert X+Y \right\vert \left\vert X-Y \right\vert $。
|
||||
根据Cauchy-Schwarz不等式,$\left(E\left\vert X+Y \right\vert \left\vert X-Y \right\vert\right) ^{2}\leqslant E\left\vert X+Y \right\vert ^{2}E\left\vert X-Y \right\vert ^{2}$。
|
||||
|
||||
其中$E\left\vert X+Y \right\vert ^{2}=E(X^{2}+2XY+Y^{2})=EX^{2}+2EXY+EY^{2}=2+2\rho $,\\
|
||||
$E\left\vert X-Y \right\vert ^{2}=E(X^{2}-2XY+Y^{2})=EX^{2}-2XY+EY^{2}=2-2\rho $。
|
||||
|
||||
因此$\left( E\left\vert X+Y \right\vert \left\vert X-Y \right\vert \right) ^{2}\leqslant (2+2\rho )(2-2\rho )=4(1-\rho ^{2})$,两边同取根号可得
|
||||
$$E\left\vert X^{2}-Y^{2} \right\vert =E\left\vert X+Y \right\vert \left\vert X-Y \right\vert \leqslant 2\sqrt{1-\rho ^{2}}$$
|
||||
|
||||
再代入回 \eqref{eq:1} ,即可得到
|
||||
$$
|
||||
E\max(X^{2},Y^{2})\leqslant \frac{1}{2}\times 2+\frac{1}{2}\times 2\sqrt{1-\rho ^{2}}=1+\sqrt{1-\rho ^{2}}
|
||||
$$
|
||||
|
||||
\end{proof}
|
||||
}
|
||||
\questionandanswer[]{设随机变量$(X,Y)$服从均匀分布$U(D)$,其中$D=\{ (x,y)\ |\ x^{2}+y^{2}\leqslant 1 \}$,求$X$与$Y$的协方差。}{
|
||||
\begin{proof}[解]
|
||||
|
||||
设$p(x,y)$表示随机变量$(X,Y)$的联合概率密度函数,则可以得到
|
||||
$$
|
||||
p(x,y)=\begin{cases}
|
||||
\frac{1}{\pi },\quad & (x,y)\in D \\
|
||||
0,\quad & (x,y)\not \in D \\
|
||||
\end{cases}
|
||||
$$
|
||||
$$
|
||||
EX=\iint xp(x,y)\mathrm{d}x\mathrm{d}y=\iint_{D}x \cdot \frac{1}{\pi }\mathrm{d}x\mathrm{d}y\xlongequal{\textit{对称性}} 0
|
||||
$$
|
||||
$$
|
||||
EY=\iint yp(x,y)\mathrm{d}x\mathrm{d}y=\iint_{D}y \cdot \frac{1}{\pi }\mathrm{d}x\mathrm{d}y\xlongequal{\textit{对称性}} 0
|
||||
$$
|
||||
$$
|
||||
EXY=\iint xyp(x,y)\mathrm{d}x\mathrm{d}y=\iint_{D}xy \cdot \frac{1}{\pi }\mathrm{d}x\mathrm{d}y\xlongequal{\textit{对称性}} 0
|
||||
$$
|
||||
所以$X$与$Y$的协方差为
|
||||
$$
|
||||
\operatorname{Cov}(X,Y)=EXY-EXEY=0
|
||||
$$
|
||||
|
||||
\end{proof}
|
||||
}
|
||||
\questionandanswer[]{设随机变量$(X,Y)$服从均匀分布$U(D)$,其中$D=\{ (x,y)\ |\ 0<x<y<1 \}$,求相关系数$\operatorname{Corr}(X,Y)$。}{
|
||||
\begin{proof}[解]
|
||||
|
||||
设$p(x,y)$表示随机变量$(X,Y)$的联合概率密度函数,则可以得到
|
||||
$$
|
||||
p(x,y)=\begin{cases}
|
||||
2,\quad & 0<x<y<1 \\
|
||||
0,\quad & \textit{其他} \\
|
||||
\end{cases}
|
||||
$$
|
||||
$$
|
||||
EX=\iint xp(x,y)\mathrm{d}x\mathrm{d}y=\iint_{D}x\cdot 2\mathrm{d}x\mathrm{d}y=\int_0^{1}\int_0^{y}2x\mathrm{d}x\mathrm{d}y = \frac{1}{3}
|
||||
$$
|
||||
$$
|
||||
EY=\iint yp(x,y)\mathrm{d}x\mathrm{d}y=\iint_{D}y\cdot 2\mathrm{d}x\mathrm{d}y=\int_0^{1}\int_0^{y}2y\mathrm{d}x\mathrm{d}y = \frac{2}{3}
|
||||
$$
|
||||
$$
|
||||
EXY=\iint xyp(x,y)\mathrm{d}x\mathrm{d}y=\iint_{D}xy\cdot 2\mathrm{d}x\mathrm{d}y=\int_0^{1}\int_0^{y}2xy\mathrm{d}x\mathrm{d}y = \frac{1}{4}
|
||||
$$
|
||||
所以$X$与$Y$的协方差为
|
||||
$$
|
||||
\operatorname{Cov}(X,Y)=EXY-EXEY=\frac{1}{4}-\frac{1}{3}\times \frac{2}{3} = \frac{1}{36}
|
||||
$$
|
||||
还需要计算
|
||||
$$
|
||||
EX^{2}=\iint x^{2}p(x,y)\mathrm{d}x\mathrm{d}y=\iint_{D} x^{2}\cdot 2\mathrm{d}x\mathrm{d}y=\int_0^{1}\int_0^{y}2x^{2}\mathrm{d}x\mathrm{d}y = \frac{1}{6}
|
||||
$$
|
||||
$$
|
||||
EY^{2}=\iint y^{2}p(x,y)\mathrm{d}x\mathrm{d}y=\iint_{D}y^{2}\cdot 2\mathrm{d}x\mathrm{d}y=\int_0^{1}\int_0^{y}2y^{2}\mathrm{d}x\mathrm{d}y = \frac{1}{2}
|
||||
$$
|
||||
所以$X$与$Y$的相关系数为
|
||||
$$
|
||||
\begin{aligned}
|
||||
\operatorname{Corr}(X,Y)&=\frac{\operatorname{Cov}(X,Y)}{\sqrt{\operatorname{Var}X\cdot \operatorname{Var}Y}}=\frac{\operatorname{Cov}(X,Y)}{\sqrt{(EX^{2}-(EX)^{2})\cdot (EY^{2}-(EY)^{2})}}\\
|
||||
&=\frac{\dfrac{1}{36}}{\sqrt{\left( \dfrac{1}{6}-\left( \dfrac{1}{3} \right) ^{2} \right) \left( \dfrac{1}{2}-\left( \dfrac{2}{3} \right) ^{2} \right) }} = \dfrac{1}{2}\\
|
||||
\end{aligned}
|
||||
$$
|
||||
|
||||
\end{proof}
|
||||
}
|
||||
\questionandanswer[]{设随机变量$(X,Y)$的联合概率密度函数为$p(x,y)=\begin{cases}
|
||||
e^{-y},\quad & 0<x<y \\
|
||||
0,\quad & \text{otherwise} \\
|
||||
\end{cases}$, 设$y>0$,求在$Y=y$时$X$的条件概率密度函数$p_{X|Y}(x|y)$,条件数学期望$E(X|Y=y)$。进一步地,利用重期望公式求$EX$。}{
|
||||
\begin{proof}[解]
|
||||
|
||||
先计算边际概率密度函数
|
||||
$$
|
||||
p_{Y}(y)=\int_{-\infty}^{+\infty} p(x,y) \mathrm{d}x=\begin{cases}
|
||||
\int_{0}^{y} e^{-y} \mathrm{d}x,\quad & y>0 \\
|
||||
0,\quad & y\leqslant 0 \\
|
||||
\end{cases}=\begin{cases}
|
||||
ye^{-y},\quad & y>0 \\
|
||||
0,\quad & y\leqslant 0 \\
|
||||
\end{cases}
|
||||
$$
|
||||
之后计算条件概率密度函数
|
||||
$$
|
||||
p_{X|Y}(x|y)=\frac{p(x,y)}{p_{Y}(y)}=\begin{cases}
|
||||
\frac{1}{y},\quad & 0<x<y \\
|
||||
0,\quad & 0< y\leqslant x \textit{或}y>0,x\leqslant 0 \\
|
||||
\end{cases}
|
||||
$$
|
||||
根据数学期望的定义,
|
||||
$$
|
||||
E(X|Y=y)=\int_{-\infty}^{+\infty} x p_{X|Y}(x|y) \mathrm{d}x = \int_{0}^{y} x\cdot \frac{1}{y} \mathrm{d}x = \frac{y}{2}
|
||||
$$
|
||||
再利用重期望公式,
|
||||
$$
|
||||
EX=\int_{-\infty}^{+\infty} E(X|Y=y)p_{Y}(y) \mathrm{d}y=\int_{0}^{+\infty} \frac{y}{2}\cdot ye^{-y} \mathrm{d}y = 1
|
||||
$$
|
||||
|
||||
\end{proof}
|
||||
}
|
||||
\questionandanswer[]{设$X$服从指数分布$\operatorname{Exp}(\lambda )$,求$Y=[X]$的分布。(这里符号$[a]$表示不超过$a$的最大整数。}{
|
||||
\begin{proof}[解]
|
||||
|
||||
由于$Y=[X]$是离散型分布,所以求出$Y$的分布列即可
|
||||
$$
|
||||
p_i=\int_{i}^{i+1} \lambda e^{-\lambda x} \mathrm{d}x = (e^{\lambda} - 1) e^{- \lambda (i + 1)}
|
||||
$$
|
||||
|
||||
\end{proof}
|
||||
}
|
||||
\questionandanswer[]{设随机变量$X$服从标准正态分布$N(0,1)$, $a>0$,记$Y=\begin{cases}
|
||||
X,\quad & \left\vert X \right\vert <a \\
|
||||
-X,\quad & \left\vert X \right\vert \geqslant a \\
|
||||
\end{cases}$,求随机变量$Y$的分布。}{
|
||||
\begin{proof}[解]
|
||||
|
||||
因为$X\sim N(0,1)$,所以$-X\sim N(0,1)$,所以随机变量$Y$服从标准正态分布$N(0,1)$,即
|
||||
$$
|
||||
Y\sim N(0,1)
|
||||
$$
|
||||
|
||||
\end{proof}
|
||||
}
|
||||
\questionandanswer[]{设二维随机变量$(X,Y)$的联合概率密度函数为 $$
|
||||
p(x,y)=\begin{cases}
|
||||
2,\quad & \textit{若}0<x<y<1; \\
|
||||
0,\quad & \textit{其他.} \\
|
||||
\end{cases}
|
||||
$$ 求
|
||||
\begin{enumerate}
|
||||
\item 随机变量$T=X-Y$的概率密度函数$p_{T}(t)$;
|
||||
\item 概率$P(Y-X\leqslant \frac{1}{2})$。
|
||||
\end{enumerate}
|
||||
}{
|
||||
\begin{proof}[解]
|
||||
|
||||
\begin{enumerate}
|
||||
\item
|
||||
根据连续情形的卷积公式,
|
||||
$$
|
||||
p_{T}(t)=\int_{-\infty}^{+\infty} p(x,x-t) \mathrm{d}x=\begin{cases}
|
||||
\int_{0}^{t+1} 2 \mathrm{d}x,\quad & -1<t<0 \\
|
||||
0,\quad & t\leqslant -1 \textit{或}t\geqslant 0 \\
|
||||
\end{cases}=\begin{cases}
|
||||
2t+2,\quad & -1<t<0 \\
|
||||
0,\quad & t\leqslant -1\textit{或}t\geqslant 0 \\
|
||||
\end{cases}
|
||||
$$
|
||||
|
||||
\item
|
||||
$$
|
||||
P(Y-X\leqslant \frac{1}{2})=P(X-Y\geqslant \frac{1}{2})=P(T\geqslant \frac{1}{2})=0
|
||||
$$
|
||||
\end{enumerate}
|
||||
|
||||
\end{proof}
|
||||
}
|
||||
\questionandanswer[]{设$X$与$Y$独立同分布,共同分布为$N(0,1)$,求概率$P(\left\vert X+Y \right\vert \leqslant \left\vert X-Y \right\vert )$。}{
|
||||
\begin{proof}[解]
|
||||
|
||||
% 根据正态分布的可加性,
|
||||
% $$
|
||||
% X+Y\sim N(0,2),\quad X-Y\sim N(0,2)
|
||||
% $$
|
||||
% 又因为
|
||||
% $$
|
||||
% \begin{aligned}
|
||||
% p_{(X+Y,X-Y)}(u,v) & = p_{(X,Y)} \left(\frac{u+v}{2},\frac{u-v}{2}\right) \left\vert J(u,v) \right\vert \\
|
||||
% & = p_{X} \left( \frac{u+v}{2} \right) p_{Y} \left( \frac{u-v}{2} \right) \begin{vmatrix}
|
||||
% \frac{1}{2} & \frac{1}{2} \\
|
||||
% \frac{1}{2} & -\frac{1}{2} \\
|
||||
% \end{vmatrix}\\
|
||||
% &=\frac{1}{2}\varphi\left(\frac{u+v}{2}\right)\varphi\left(\frac{u-v}{2}\right)\\
|
||||
% &=\frac{1}{2}\cdot \frac{1}{\sqrt{2\pi }}e^{-\frac{1}{2} \left( \frac{u+v}{2} \right) ^{2}}\cdot \frac{1}{\sqrt{2\pi }}e^{-\frac{1}{2}\left( \frac{u-v}{2} \right) ^{2}} \\
|
||||
% &=\frac{1}{\sqrt{2\pi }\cdot \sqrt{2}}\frac{1}{\sqrt{2\pi }\cdot \sqrt{2}}e^{-\frac{1}{8}\left( 2u^{2}+2v^{2} \right) } \\
|
||||
% &=\frac{1}{\sqrt{2\pi }\sqrt{2}}e^{-\frac{u^{2}}{2\cdot 2}}\cdot \frac{1}{\sqrt{2\pi }\sqrt{2}}e^{-\frac{v^{2}}{2\cdot 2}} \\
|
||||
% &=p_{X+Y}(u)\cdot p_{X-Y}(v) \\
|
||||
% \end{aligned}
|
||||
% $$
|
||||
% 所以$X+Y$与$X-Y$相互独立,从而独立同分布,所以$\left\vert X+Y \right\vert $与$\left\vert X-Y \right\vert $也独立同分布,
|
||||
% 设他们的概率密度函数为$p_1(x)$,则根据独立同分布的可加性,$\left\vert X+Y \right\vert -\left\vert X-Y \right\vert $的概率密度函数可表示为$p_2(x)=p_1(x)+p_1(-x)$,是偶函数,于是
|
||||
% $$
|
||||
% P(\left\vert X+Y \right\vert \leqslant \left\vert X-Y \right\vert )=P(\left\vert X+Y \right\vert -\left\vert X-Y \right\vert \leqslant 0) = \frac{1}{2}
|
||||
% $$
|
||||
|
||||
$$
|
||||
\begin{aligned}
|
||||
P(\left\vert X+Y \right\vert \leqslant \left\vert X-Y \right\vert ) & = P\left( (X+Y)^{2}\leqslant (X-Y)^{2} \right) \\
|
||||
& = P(X^{2}+2XY+Y^{2}\leqslant X^{2}-2XY+Y^{2}) \\
|
||||
& = P(4XY\leqslant 0) \\
|
||||
& = P(XY\leqslant 0) \\
|
||||
&=P(X\leqslant 0,Y>0) + P(X>0,Y\leqslant 0) \\
|
||||
&\xlongequal{X\textit{与}Y\textit{}独立}P(X\leqslant 0)P(Y>0)+P(X>0)P(Y\leqslant 0) \\
|
||||
&\xlongequal{X\sim N(0,1),Y\sim N(0,1)}\frac{1}{2}\times \frac{1}{2}+\frac{1}{2}\times \frac{1}{2} \\
|
||||
&=\frac{1}{2} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
|
||||
\end{proof}
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
156
概率论/单元作业6.tex
Normal file
156
概率论/单元作业6.tex
Normal file
@ -0,0 +1,156 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
\setlength{\textheight}{210em}
|
||||
\setlength{\paperheight}{210em}
|
||||
|
||||
\begin{document}
|
||||
\chapter{单元作业6}
|
||||
\begin{enumerate}
|
||||
\item 证明随机变量$X$的特征函数是实值函数当且仅当$X$与$-X$同分布。
|
||||
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
|
||||
设$X$的特征函数为$f_{X}(t)$,则
|
||||
$$
|
||||
\begin{aligned}
|
||||
X的特征函数是实值函数 \iff& f_{X}(t)=\overline{f_{X}(t)} \\
|
||||
\iff& f_{X}(t)=f_{X}(-t) \\
|
||||
\iff& Ee^{itX}=Ee^{i(-t)X} \\
|
||||
\iff& Ee^{itX}=Ee^{it(-X)} \\
|
||||
\iff& f_{X}(t)=f_{-X}(t) \\
|
||||
\iff& X与-X同分布 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
|
||||
\item 设随机变量$X$的特征函数为$f(t)=\left( \frac{2-it}{2} \right) ^{-2}$,求$EX$和$\operatorname{Var}X$。
|
||||
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
|
||||
% 根据唯一性定理的推论,可知$X$的概率密度函数为
|
||||
% $$
|
||||
% p(x)=\frac{1}{2\pi }\int_{-\infty}^{+\infty} e^{-itx}\left( \frac{2-it}{2} \right) ^{-2} \mathrm{d}t
|
||||
% $$
|
||||
根据特征函数的性质,可知
|
||||
$$
|
||||
iEX = \left. f'(t) \right|_{t=0}=\left. \left( -\frac{i}{2}\cdot (-2)\left( \frac{2-it}{2} \right) ^{-3} \right) \right|_{t=0}=i\cdot 1^{-3}=i
|
||||
$$
|
||||
$$
|
||||
-EX^{2}=i^{2}EX^{2}=\left. f''(t) \right|_{t=0}=\left.\left( i\cdot \left( -\frac{i}{2} \right) \cdot (-3)\left( \frac{2-it}{2} \right) ^{-4} \right) \right|_{t=0}=\left( -\frac{3}{2} \right) \cdot 1^{-4}=-\frac{3}{2}
|
||||
$$
|
||||
所以有
|
||||
$$
|
||||
EX=1, \qquad EX^{2}=\frac{3}{2}, \qquad \operatorname{Var}X=EX^{2}-(EX)^{2}=\frac{3}{2}-1^{2}=\frac{1}{2}
|
||||
$$
|
||||
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
|
||||
\item 设$X_i$独立同分布,且$X_i\sim \operatorname{Exp}(\lambda ),i=1,2, \ldots ,n$。试用特征函数的方法证明:
|
||||
$$
|
||||
Y_n=\sum_{i=1}^{n}X_i\sim \operatorname{Ga}(n,\lambda )
|
||||
$$
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
|
||||
根据题意可知$X_i$的概率密度函数为$p(x)=\begin{cases}
|
||||
\lambda e^{-\lambda x},\quad & x>0 \\
|
||||
0,\quad & x\leqslant 0 \\
|
||||
\end{cases}$。根据特征函数的定义,计算$X_i$的特征函数$f(t)$:
|
||||
$$
|
||||
\begin{aligned}
|
||||
f(t)&=Ee^{itX_{i}}=\int_{-\infty}^{+\infty} e^{itx}p(x) \mathrm{d}x=\int_{0}^{+\infty} e^{itx}\lambda e^{-\lambda x} \mathrm{d}x=\frac{\lambda}{it-\lambda }\int_{0}^{+\infty} e^{(it-\lambda )x} \mathrm{d}(it-\lambda )x \\
|
||||
&=\frac{\lambda}{it-\lambda }\cdot \left. e^{(it-\lambda )x} \right|_{0}^{+\infty}=\frac{\lambda }{it-\lambda } \cdot \left( \lim_{x \to +\infty}e^{itx-\lambda x}-1 \right)=\frac{\lambda}{it-\lambda }\cdot \left( \lim_{x \to +\infty}e^{-\lambda x}e^{itx} -1 \right) \\
|
||||
\end{aligned}
|
||||
$$
|
||||
对于$\displaystyle \lim_{x \to +\infty}e^{-\lambda x}e^{itx}$,设$a=e^{-\lambda x}e^{itx}$,将其看作复数的模长辐角表示法,则$a$的模长为$e^{-\lambda x}$,辐角为$tx$。由于$\lambda >0$,所以当$x \to +\infty$时,$a$的模长$e^{-\lambda x} \to 0$(辐角$tx \to +\infty$,但不重要),因此$\displaystyle \lim_{x \to +\infty}e^{-\lambda x}e^{itx}=\lim_{x \to +\infty}a=0$。
|
||||
|
||||
于是$\displaystyle f(t)=\frac{\lambda}{it-\lambda }\cdot (0-1)=\frac{\lambda }{\lambda -it}$。
|
||||
|
||||
由于$X_i$相互独立,所以$Y_n$的特征函数为:
|
||||
$$
|
||||
g(t)=\left[ f(t) \right] ^{n}=\left( \frac{\lambda }{\lambda -it} \right) ^{n}
|
||||
$$
|
||||
|
||||
再计算$Y\sim \operatorname{Ga}(n,\lambda )$的特征函数:
|
||||
$$
|
||||
\begin{aligned}
|
||||
h(t)&=Ee^{itY}=\int_{-\infty}^{+\infty} e^{itx}p(x) \mathrm{d}x=\int_{0}^{+\infty} e^{itx} \frac{\lambda ^{n}}{\Gamma (n)}x^{n-1}e^{-\lambda x} \mathrm{d}x \\
|
||||
&=\frac{\lambda ^{n}}{(\lambda -it)^{n}}\int_{0}^{+\infty} \frac{(\lambda -it)^{n}}{\Gamma (n)}x^{n-1}e^{(it-\lambda )x} \mathrm{d}x \\
|
||||
\end{aligned}
|
||||
$$
|
||||
注意到$\displaystyle \frac{(\lambda -it)^{n}}{\Gamma (n)}x^{n-1}e^{(it-\lambda )}$(零延拓后)为$\operatorname{Ga}(n, \lambda -it)$的概率密度函数,根据分布函数的正则性,$\displaystyle \int_{0}^{+\infty} \frac{(\lambda -it)^{n}}{\Gamma (n)}x^{n-1}e^{(it-\lambda )} \mathrm{d}x=1$,所以
|
||||
$$
|
||||
h(t)=\frac{\lambda ^{n}}{(\lambda -it)^{n}}=\left( \frac{\lambda }{\lambda -it} \right) ^{n}=g(t)
|
||||
$$
|
||||
根据特征函数的唯一性,$Y_n$与$Y$同分布,即
|
||||
$$
|
||||
Y_n=\sum_{i=1}^{n}X_i\sim \operatorname{Ga}(n,\lambda )
|
||||
$$
|
||||
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
|
||||
\item 设$X_n\xrightarrow{P}X,X_n\xrightarrow{P}Y$。证明$P(X=Y)=1$。
|
||||
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
|
||||
根据依概率收敛的运算性质,有
|
||||
$$
|
||||
0=X_n-X_n\xrightarrow{P}X-Y
|
||||
$$
|
||||
即对任意的$\varepsilon>0$,有
|
||||
$$
|
||||
\lim_{n \to \infty} P(\left\vert 0-(X-Y) \right\vert \geqslant \varepsilon)=\lim_{n \to \infty}P(\left\vert X-Y \right\vert \geqslant \varepsilon)=P(\left\vert X-Y \right\vert \geqslant \varepsilon)=0
|
||||
$$
|
||||
令$\varepsilon \to 0$,则根据概率的下连续性,可得
|
||||
$$
|
||||
P(\left\vert X-Y \right\vert >0)=0
|
||||
$$
|
||||
由于$\left\vert X-Y \right\vert \geqslant 0$,所以
|
||||
$$
|
||||
P(\left\vert X-Y \right\vert =0)=1-P(\left\vert X-Y \right\vert >0)=1
|
||||
$$
|
||||
即$P(X=Y)=1$。
|
||||
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
|
||||
\item 证明$\displaystyle \lim_{n \to \infty}E\left( \frac{\left\vert X_n \right\vert }{1+\left\vert X_n \right\vert } \right) =0$当且仅当$X_n\xrightarrow{P}0$。
|
||||
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
|
||||
对任意的$\varepsilon>0$,$1=1_{\{ \left\vert X_n \right\vert \leqslant \varepsilon \}}+1_{\{ \left\vert X_n \right\vert >\varepsilon \}}$。所以有如下不等式:
|
||||
|
||||
$$
|
||||
\begin{aligned}
|
||||
\frac{\left\vert X_n \right\vert }{1+\left\vert X_n \right\vert }&=\frac{\left\vert X_n \right\vert }{1+\left\vert X_n \right\vert }1_{\{ \left\vert X_n \right\vert \leqslant \varepsilon \}}+\frac{\left\vert X_n \right\vert }{1+\left\vert X_n \right\vert }1_{\{ \left\vert X_n \right\vert >\varepsilon \}} \\
|
||||
&\leqslant \left\vert X_n \right\vert 1_{\{ \left\vert X_n \right\vert \leqslant \varepsilon \}}+1_{\{ \left\vert X_n \right\vert >\varepsilon \}}\leqslant \varepsilon+1_{\{ \left\vert X_n \right\vert >\varepsilon \}} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
等式两边同时取期望,则
|
||||
$$
|
||||
E\left( \frac{\left\vert X_n \right\vert }{1+\left\vert X_n \right\vert } \right) \leqslant E(\varepsilon+1_{\{ \left\vert X_n \right\vert >\varepsilon \}})=\varepsilon+E(1_{\{ \left\vert X_n \right\vert >\varepsilon \}})
|
||||
$$
|
||||
若$X_n\xrightarrow{P}0$,则$\displaystyle \lim_{n \to \infty}P(\left\vert X_n \right\vert >\varepsilon)=0$,所以$\displaystyle \lim_{n \to \infty}E(1_{\{ \left\vert X_n \right\vert >\varepsilon \}})=0$。
|
||||
于是上述不等式两边同时取$n \to 0$时的极限可得
|
||||
$$
|
||||
\lim_{n \to \infty}E\left( \frac{\left\vert X_n \right\vert }{1+\left\vert X_n \right\vert } \right) \leqslant \varepsilon
|
||||
$$
|
||||
所以$\displaystyle \lim_{n \to \infty}E\left( \frac{\left\vert X_n \right\vert }{1+\left\vert X_n \right\vert } \right) =0$。
|
||||
|
||||
若$\displaystyle \lim_{n \to \infty}E\left( \frac{\left\vert X_n \right\vert }{1+\left\vert X_n \right\vert } \right) =0$,这里使用和书上不同的方法。根据马尔可夫不等式的一般形式,有
|
||||
$$
|
||||
P(\left\vert X_n \right\vert >\varepsilon)\leqslant \frac{E\left( \frac{\left\vert X_n \right\vert }{1+\left\vert X_n \right\vert } \right) }{\frac{\varepsilon}{1+\varepsilon}}
|
||||
$$
|
||||
不等式两边同时取$n \to 0$时的极限可得$\displaystyle \lim_{n \to \infty}P(\left\vert X_n \right\vert >\varepsilon)=0$,即$X_n\xrightarrow{P}0$。
|
||||
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\end{enumerate}
|
||||
\end{document}
|
110
深度学习/实验/Retrieval_task/实验报告.tex
Normal file
110
深度学习/实验/Retrieval_task/实验报告.tex
Normal file
@ -0,0 +1,110 @@
|
||||
\documentclass[a4paper]{ctexart}
|
||||
\usepackage[margin=1in]{geometry}
|
||||
\usepackage{booktabs}
|
||||
\usepackage{hyperref}
|
||||
\usepackage{graphicx}
|
||||
\usepackage[numbers]{gbt7714}
|
||||
\RequirePackage[outputdir=./latex-output]{minted}
|
||||
\setlength{\belowcaptionskip}{1em}
|
||||
|
||||
\title{《深度学习》实验报告}
|
||||
\author{姓名:岳锦鹏\qquad 学号:10213903403\qquad 专业:统计学-计算机\qquad 学院:统计学院}
|
||||
\date{2024年6月8日}
|
||||
\ctexset {
|
||||
section = {
|
||||
name = {,、},
|
||||
format += \raggedright,
|
||||
number = \chinese{section},
|
||||
},
|
||||
subsection = {
|
||||
% name = {(,)},
|
||||
number = \arabic{subsection}
|
||||
}
|
||||
}
|
||||
|
||||
\begin{document}
|
||||
\maketitle
|
||||
\section{实验环境}
|
||||
\noindent requirements.txt:
|
||||
\begin{minted}[frame=leftline, framesep=1em, framerule=1pt]{python}
|
||||
numpy
|
||||
paddlepaddle-gpu
|
||||
scikit-learn
|
||||
tqdm
|
||||
\end{minted}
|
||||
这些代码库的作用是什么已经显而易见了,其中 \mintinline{Python}{scikit-learn (sklearn)} 只是用来分训练验证集的。
|
||||
|
||||
\section{实验过程}
|
||||
\subsection{实验思路}
|
||||
\subsubsection{确定首次召回个数}
|
||||
先尝试了一下完全不使用baseline的方法,直接从全部的几千个文档中召回3个文档,发现效果完全不如baseline,于是想到了采用二次召回,第一次采用baseline的方法,从几千个文档中召回一部分,第二次再从召回的这些文档中选出3个。关于第一次召回多少,我首先做了按照baseline的方式直接计算余弦相似度的top k召回率的实验,结果如 表 \ref{first retrieve num} 所示,可以看到当首次召回数量达到500个时已经有很高的召回率了,所以后续的实验都在首次召回500个文章下进行。
|
||||
\begin{table}[h]
|
||||
\centering \caption{直接计算余弦相似度的召回率} \label{first retrieve num}
|
||||
\begin{tabular}{cc}
|
||||
\toprule
|
||||
Recall@100 & 0.75 \\
|
||||
Recall@500 & 0.93 \\
|
||||
Recall@5000 & 0.99 \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{table}
|
||||
|
||||
\subsubsection{二次召回方案选择}
|
||||
从500个里召回3个,仍然是一个复杂的任务,尝试过几种方案:
|
||||
\begin{enumerate}
|
||||
\item 将其当做分类问题,输入一个查询,500个文章,输出这500个文章的概率。缺点是效率可能较低,而且实验后发现效果也不好;
|
||||
\item 双塔编码(cross encoder)和point wise 对比学习\cite{jianshu},给定一个查询和一个文章,模型给出一个得分,对于查询和对应的文章(正例),得分应该更高;对于查询和不对应的文章(负例),得分应该更低,这里的负例一般是从文章库中随机选取。实验后发现不管正负例的比例是多少,效果都不好;
|
||||
\item 单塔编码,query通过查询编码器,fact通过文章编码器,之后计算编码后的向量的余弦相似度,如果不使用对比学习会导致模型把所有的文章都编码得非常相似,所以这里还是需要使用对比学习。那么如何选取负例?实验过还是从文章库中随机选取负例,效果还是不好,于是查找资料,发现了这样一篇文章:\cite{aistudio},里面提到了In-batch Negatives策略,即将一个批次内其他样本都作为负例,尝试后发现效果有很大提升,从baseline的0.2121提升到了0.4059。
|
||||
\end{enumerate}
|
||||
|
||||
最终选择了单塔编码的方案,并且使用了In-batch Negatives策略。
|
||||
\subsection{数据预处理部分}
|
||||
先使用 \mintinline{Python}{sklearn} 中的 \mintinline{Python}{train_test_split} 按8:2的比例分出训练集和验证集。对于训练集和验证集,先把首次召回500个的工作全部完成,即对于每一个查询,先召回500个文章,存放在内存中,训练时在这500 $\times $ num of queries 个样本里训练。
|
||||
\subsection{模型构建}
|
||||
这里需要做的就是在单塔编码中,如何编码查询,如何编码文章。其实非常简单,就是多层全连接层,使用ReLU作为激活函数,并且使用了残差连接,如图 \ref{model structure} 所示。
|
||||
\begin{figure}[h]
|
||||
\centering
|
||||
\includegraphics[width=1\linewidth]{模型结构图.png}
|
||||
\caption{模型结构图}\label{model structure}
|
||||
(图中的N表示batch size,EMB表示嵌入维度。)
|
||||
\end{figure}
|
||||
|
||||
由于query和fact的每一行是对应的,所以将query和fact通过编码器后的向量,在对角线的位置表示查询和文档对应时的相似度(正例),而非对角线的位置表示非对应时的相似度(负例),所以此矩阵应该和单位矩阵相近,所以可以用交叉熵损失。在实际代码中使用了小于1的margin来代替1形成对角阵。
|
||||
|
||||
这里只使用简单的线性层加残差连接,是因为试了很多种结构,比如更深的带残差块的线性层,比如Transformer(Decoder only),效果都没有简单的线性层效果好。
|
||||
|
||||
\section{实验结果}
|
||||
(以下召回率都是指Recall@3)
|
||||
|
||||
% 训练集和验证集比例为8:2,batch size设为1024,训练370轮,优化器为Adam,在验证集上的召回率为0.48165760869565216,提交后(在测试集上)的召回率为0.452148。
|
||||
|
||||
% 不区分训练集和验证集,batch size设为4096,训练1300轮,优化器为Adam,提交后(在测试集上)的召回率为0.529622。
|
||||
|
||||
% 不区分训练集和验证集,batch size设为2048,训练2500步(iter steps)(不是轮(epochs)了),优化器为Adam,提交后(在测试集上)的召回率为0.523275。
|
||||
|
||||
% 不区分训练集和验证集,batch size设为2048,训练2600步,优化器为AdamW,提交后(在测试集上)的召回率为0.523926。
|
||||
|
||||
% 不区分训练集和验证集,batch size设为2048,训练5100步,优化器为AdamW,将模型参数与输入输出的数据类型从float32改为float64,提交后(在测试集上)的召回率为0.584635。
|
||||
|
||||
结果如表 \ref{hyper-parameters} 所示。
|
||||
\begin{table}[h]
|
||||
\centering
|
||||
\caption{尝试不同的超参数}\label{hyper-parameters}
|
||||
\begin{tabular}{cccccccc}
|
||||
\toprule
|
||||
序号 & 是否有验证集 & batch size & epoch / step & 优化器 & 数据类型 & 验证集召回率 & 测试集召回率 \\
|
||||
\midrule
|
||||
0 & \multicolumn{4}{c}{baseline 无需训练} & float32 & / & 0.212077 \\
|
||||
1 & 是 & 1024 & 370 epochs & Adam & float32 & 0.481658 & 0.452148 \\
|
||||
2 & 否 & 4096 & 1300 epochs & Adam & float32 & / & 0.529622 \\
|
||||
3 & 否 & 2048 & 2500 steps & Adam & float32 & / & 0.523275 \\
|
||||
4 & 否 & 2048 & 2600 steps & AdamW & float32 & / & 0.523926 \\
|
||||
5 & 否 & 2048 & 5100 steps & AdamW & float64 & / & 0.584635 \\
|
||||
6 & 否 & 8192 & 9500 steps & AdamW & float64 & / & \textbf{0.606283} \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{table}
|
||||
|
||||
\bibliography{ref}
|
||||
|
||||
\end{document}
|
441
深度学习/实验讲解/lab4.tex
Normal file
441
深度学习/实验讲解/lab4.tex
Normal file
@ -0,0 +1,441 @@
|
||||
% https://zhuanlan.zhihu.com/p/165140693
|
||||
% https://zhuanlan.zhihu.com/p/36868831
|
||||
|
||||
%声明文档类型和比例
|
||||
\documentclass[aspectratio=169, 10pt, utf8, mathserif]{ctexbeamer}
|
||||
%调用相关的宏包
|
||||
% \usepackage{beamerfoils}
|
||||
|
||||
\usepackage[outputdir=./latex-output]{minted}
|
||||
|
||||
\usepackage{multicol}
|
||||
\setminted{breaklines=true, fontsize=\zihao{-6}}
|
||||
% \PassOptionsToPackage{fontsize=\zihao{-6}}{minted}
|
||||
|
||||
\definecolor{shadecolor}{RGB}{204,232,207}
|
||||
|
||||
\usetheme{Berlin} %主题包之一,直接换名字即可
|
||||
\setbeamertemplate{page number in head/foot}[totalframenumber]
|
||||
|
||||
\usecolortheme{beaver} %主题色之一,直接换名字即可。
|
||||
\usefonttheme{professionalfonts}
|
||||
|
||||
% 设置用acrobat打开就会全屏显示
|
||||
\hypersetup{pdfpagemode=FullScreen}
|
||||
|
||||
% 设置logo
|
||||
% \pgfdeclareimage[height=2cm, width=2cm]{university-logo}{120701101}
|
||||
% \logo{\pgfuseimage{university-logo}}
|
||||
|
||||
\parskip=1.2em
|
||||
|
||||
%--------------正文开始---------------
|
||||
\begin{document}
|
||||
|
||||
%每个章节都有小目录
|
||||
\AtBeginSubsection[]
|
||||
{
|
||||
\begin{frame}<beamer>
|
||||
\tableofcontents[currentsection,currentsubsection]
|
||||
\end{frame}
|
||||
}
|
||||
|
||||
\title{《深度学习》实验4讲解}
|
||||
\subtitle{多层感知机/全连接层}
|
||||
\author[岳锦鹏]{岳锦鹏 \\ \small 10213903403}
|
||||
|
||||
\date{\today}
|
||||
\begin{frame}
|
||||
%\maketitle
|
||||
\titlepage
|
||||
\end{frame}
|
||||
|
||||
\begin{frame}
|
||||
\frametitle{目录}
|
||||
\tableofcontents[hideallsubsections]
|
||||
\end{frame}
|
||||
|
||||
\section{整体浏览}
|
||||
|
||||
\begin{frame}[fragile]
|
||||
首先逐个观察每个填空的部分需要完成哪些内容。
|
||||
|
||||
可以看到需要完成ReLU的反向传播过程。
|
||||
\begin{minted}{python}
|
||||
class Relu:
|
||||
def __init__(self):
|
||||
self.mem = {}
|
||||
|
||||
def forward(self, x):
|
||||
self.mem['x'] = x
|
||||
return np.where(x > 0, x, np.zeros_like(x))
|
||||
|
||||
def backward(self, grad_y):
|
||||
'''
|
||||
grad_y: same shape as x
|
||||
'''
|
||||
|
||||
# ==========
|
||||
# todo '''请完成激活函数的梯度后传'''
|
||||
# ==========
|
||||
|
||||
\end{minted}
|
||||
\end{frame}
|
||||
|
||||
\begin{frame}[fragile]
|
||||
对于主要的模型部分,需要完成计算损失。
|
||||
\begin{minted}{python}
|
||||
def compute_loss(self, log_prob, labels):
|
||||
'''
|
||||
log_prob is the predicted probabilities
|
||||
labels is the ground truth
|
||||
Please return the loss
|
||||
'''
|
||||
|
||||
# ==========
|
||||
# todo '''请完成多分类问题的损失计算 损失为: 交叉熵损失 + L2正则项'''
|
||||
# ==========
|
||||
|
||||
|
||||
\end{minted}
|
||||
\end{frame}
|
||||
|
||||
\begin{frame}[fragile]
|
||||
按照给定的网络结构完成前向传播过程。
|
||||
\begin{minted}{python}
|
||||
def forward(self, x):
|
||||
'''
|
||||
x is the input features
|
||||
Please return the predicted probabilities of x
|
||||
'''
|
||||
|
||||
# ==========
|
||||
# todo '''请搭建一个MLP前馈神经网络 补全它的前向传播 MLP结构为FFN --> RELU --> FFN --> Softmax'''
|
||||
# ==========
|
||||
|
||||
|
||||
\end{minted}
|
||||
\end{frame}
|
||||
|
||||
\begin{frame}[fragile]
|
||||
完成主模型的后向传播,注意这里可以使用其中各层的反向传播函数。
|
||||
\begin{minted}{python}
|
||||
def backward(self, label):
|
||||
'''
|
||||
label is the ground truth
|
||||
Please compute the gradients of self.W1 and self.W2
|
||||
'''
|
||||
|
||||
# ==========
|
||||
# todo '''补全该前馈神经网络的后向传播算法'''
|
||||
# ==========
|
||||
|
||||
|
||||
\end{minted}
|
||||
\end{frame}
|
||||
|
||||
\begin{frame}[fragile]
|
||||
更新参数,这里要注意不要忘记正则项的损失。
|
||||
\begin{minted}{python}
|
||||
def update(self):
|
||||
'''
|
||||
Please update self.W1 and self.W2
|
||||
'''
|
||||
|
||||
# ==========
|
||||
# todo '''更新该前馈神经网络的参数'''
|
||||
# ==========
|
||||
|
||||
\end{minted}
|
||||
\end{frame}
|
||||
|
||||
\section{逐个实现}
|
||||
\subsection{ReLU的反向传播}
|
||||
|
||||
\begin{frame}[fragile]
|
||||
\begin{multicols}{2}
|
||||
首先看ReLU的反向传播,由于ReLU的公式为(符号和课件中保持一致所以用了$a$和$x$)
|
||||
$$
|
||||
a = \begin{cases}
|
||||
x,\quad & x>0 \\
|
||||
0,\quad & x\leqslant 0 \\
|
||||
\end{cases}
|
||||
$$
|
||||
所以显然
|
||||
$$
|
||||
\frac{\mathrm{d}a}{\mathrm{d}x} = \begin{cases}
|
||||
1,\quad & x>0 \\
|
||||
0,\quad & x\leqslant 0 \\
|
||||
\end{cases}
|
||||
$$
|
||||
\columnbreak
|
||||
\begin{minted}{python}
|
||||
class Relu:
|
||||
def __init__(self):
|
||||
self.mem = {}
|
||||
|
||||
def forward(self, x):
|
||||
self.mem['x'] = x
|
||||
return np.where(x > 0, x, np.zeros_like(x))
|
||||
|
||||
def backward(self, grad_y):
|
||||
'''
|
||||
grad_y: same shape as x
|
||||
'''
|
||||
|
||||
# ==========
|
||||
# todo '''请完成激活函数的梯度后传'''
|
||||
# ==========
|
||||
|
||||
\end{minted}
|
||||
\end{multicols}
|
||||
\end{frame}
|
||||
|
||||
\begin{frame}[fragile]
|
||||
|
||||
\begin{multicols}{2}
|
||||
由于要计算梯度时要根据输入$x$是否大于0判断,所以这里使用了\mintinline{python}{self.mem}来记忆上次输入的$x$,在反向传播的时候就可以使用记忆的$x$来进行分支,这里可以利用 numpy的批量操作能力实现,\mintinline{python}{grad_y}是传入的梯度,返回的结果应为本层梯度与传入梯度的乘积:
|
||||
$$
|
||||
return = \frac{\mathrm{d}a}{\mathrm{d}x} \times grad\_y=\begin{cases}
|
||||
grad\_y,\quad & x>0 \\
|
||||
0,\quad & x\leqslant 0 \\
|
||||
\end{cases}
|
||||
$$
|
||||
因此写出代码如下:
|
||||
\columnbreak
|
||||
\begin{minted}{python}
|
||||
class Relu:
|
||||
def __init__(self):
|
||||
self.mem = {}
|
||||
|
||||
def forward(self, x):
|
||||
self.mem['x'] = x
|
||||
return np.where(x > 0, x, np.zeros_like(x))
|
||||
|
||||
def backward(self, grad_y):
|
||||
'''
|
||||
grad_y: same shape as x
|
||||
'''
|
||||
|
||||
# ==========
|
||||
# todo '''请完成激活函数的梯度后传'''
|
||||
return np.where(self.mem['x'] > 0, grad_y, np.zeros_like(grad_y))
|
||||
# ==========
|
||||
|
||||
\end{minted}
|
||||
\end{multicols}
|
||||
\mint{python}|return np.where(self.mem['x'] > 0, grad_y, np.zeros_like(grad_y))|
|
||||
\end{frame}
|
||||
|
||||
\subsection{交叉熵损失+L2正则项}
|
||||
\begin{frame}[fragile]
|
||||
\begin{multicols}{2}
|
||||
交叉熵损失的函数为
|
||||
$$
|
||||
loss=\sum_{\text{每个类别}i} -y_i \log(\hat{y}_i)
|
||||
$$
|
||||
L2正则项的损失为
|
||||
$
|
||||
\lambda \left\Vert W \right\Vert
|
||||
$,$\lambda$为系数,$W$为权重,距离用的是欧几里得距离,即
|
||||
$$\displaystyle \sqrt{\sum_{W\text{中的每个参数}x} x^{2} }$$
|
||||
|
||||
这里有两层网络,也就是两层权重,所以
|
||||
$$
|
||||
L2 = \lambda_1 \left\Vert W_1 \right\Vert +\lambda_2 \left\Vert W_2 \right\Vert
|
||||
$$
|
||||
\columnbreak
|
||||
\begin{minted}{python}
|
||||
def compute_loss(self, log_prob, labels):
|
||||
'''
|
||||
log_prob is the predicted probabilities
|
||||
labels is the ground truth
|
||||
Please return the loss
|
||||
'''
|
||||
|
||||
# ==========
|
||||
# todo '''请完成多分类问题的损失计算 损失为: 交叉熵损失 + L2正则项'''
|
||||
# ==========
|
||||
|
||||
|
||||
\end{minted}
|
||||
\end{multicols}
|
||||
\end{frame}
|
||||
|
||||
\begin{frame}[fragile]
|
||||
\begin{multicols}{2}
|
||||
\mintinline{python}{log_prob}应该是希望传入已经经过$\log$计算的$\hat{y}$,但是在lab4.ipynb里发现其实是没有经过$\log$计算的\mintinline{python}{pred_y},这里还得自己计算$\log(\hat{y})$,但是$\log (\hat{y}_i)$由于在前向传播的时候计算过就提前缓存在\mintinline{python}{self.log_value}了。
|
||||
|
||||
\mintinline{python}{labels}|$y$和\mintinline{python}{self.log_value}|$\log(\hat{y})$是one-hot编码的,形状为[批大小,类别数],根据公式在类别数维度求和,所以是\mintinline{python}{axis=1}。注意还要在批大小维度求平均,即\mintinline{python}{.mean(0)}。
|
||||
|
||||
计算距离这里直接使用了\mintinline{python}{np.linalg.norm}。
|
||||
\columnbreak
|
||||
\begin{minted}{python}
|
||||
def compute_loss(self, log_prob, labels):
|
||||
'''
|
||||
log_prob is the predicted probabilities
|
||||
labels is the ground truth
|
||||
Please return the loss
|
||||
'''
|
||||
|
||||
# ==========
|
||||
# todo '''请完成多分类问题的损失计算 损失为: 交叉熵损失 + L2正则项'''
|
||||
return - np.sum(labels * self.log_value, axis=1).mean(0) + self.lambda1 * np.linalg.norm(self.W1) + self.lambda1 * np.linalg.norm(self.W2)
|
||||
# ==========
|
||||
|
||||
|
||||
\end{minted}
|
||||
\end{multicols}
|
||||
\end{frame}
|
||||
|
||||
\subsection{主模型的前向传播}
|
||||
|
||||
\begin{frame}[fragile]
|
||||
\begin{multicols}{2}
|
||||
这里$x$的形状是[批大小,28,28],这里的两个28分别是图像高度和宽度,而且可以观察到\mintinline{python}{self.W1}的形状是[100, 785],但是$28\times 28=784$,说明需要把高度和宽度拉平后还需要拼接一个\mintinline{python}{np.ones}来替代偏置项的作用。即
|
||||
\mint{python}|np.concatenate((x.reshape(x.shape[0], -1), np.ones((x.shape[0], 1))), axis=1)|
|
||||
|
||||
在\mintinline{python}{Matmul.backward}的注释中可以看到\\
|
||||
\mintinline{python}{x: shape(d, N)},所以拼接好之后还需要进行转置。
|
||||
\columnbreak
|
||||
\begin{minted}{python}
|
||||
def forward(self, x):
|
||||
'''
|
||||
x is the input features
|
||||
Please return the predicted probabilities of x
|
||||
'''
|
||||
|
||||
# ==========
|
||||
# todo '''请搭建一个MLP前馈神经网络 补全它的前向传播 MLP结构为FFN --> RELU --> FFN --> Softmax'''
|
||||
# ==========
|
||||
|
||||
|
||||
\end{minted}
|
||||
\end{multicols}
|
||||
\end{frame}
|
||||
|
||||
\begin{frame}[fragile]
|
||||
\begin{multicols}{2}
|
||||
在\mintinline{python}{Softmax.forward}的注释中可以看到\mintinline{python}{x: shape(N, c)},因此在进行Softmax操作前还需要再转置回来。
|
||||
|
||||
理论上这时候就可以直接返回了,不需要用到\mintinline{python}{self.log},$\log$是在计算交叉熵时才会用到的操作,但是在lab4.ipynb中非要先反向传播再计算损失,反向传播需要\mintinline{python}{self.log.backward},但这又需要先调用过\mintinline{python}{self.log.forward}才能把输入记忆到\mintinline{python}{self.mem}中,才能正确返回梯度。
|
||||
|
||||
那没办法,只能先调用一下\mintinline{python}{self.log.forward}把结果缓存起来。
|
||||
\columnbreak
|
||||
\begin{minted}{python}
|
||||
def forward(self, x):
|
||||
'''
|
||||
x is the input features
|
||||
Please return the predicted probabilities of x
|
||||
'''
|
||||
|
||||
# ==========
|
||||
# todo '''请搭建一个MLP前馈神经网络 补全它的前向传播 MLP结构为FFN --> RELU --> FFN --> Softmax'''
|
||||
y = np.concatenate((x.reshape(x.shape[0], -1), np.ones((x.shape[0], 1))), axis=1).T # 这形状真难弄
|
||||
y = self.mul_h1.forward(self.W1, y)
|
||||
y = self.relu.forward(y)
|
||||
y = self.mul_h2.forward(self.W2, y).T
|
||||
y = self.softmax.forward(y)
|
||||
# print(y)
|
||||
# 唉没办法,非要先反向传播再计算损失,那只能把log的结果缓存起来了
|
||||
self.log_value = self.log.forward(y)
|
||||
return y
|
||||
# ==========
|
||||
|
||||
|
||||
\end{minted}
|
||||
\end{multicols}
|
||||
\end{frame}
|
||||
|
||||
\subsection{主模型的反向传播}
|
||||
\begin{frame}[fragile]
|
||||
\begin{multicols}{2}
|
||||
前面的准备工作都实现了后,这里就很简单了,只需要逐层反向传播就行了。
|
||||
|
||||
注意交叉熵损失为
|
||||
$$
|
||||
loss=\sum_{\text{每个类别}i} -y_i \log(\hat{y}_i)
|
||||
$$
|
||||
所以
|
||||
$$
|
||||
\frac{\mathrm{d}loss}{\mathrm{d}\log(\hat{y}_i)}= -y_i
|
||||
$$
|
||||
因此首个梯度为 \mintinline{python}{-label},后续的反向传播就交给各层的\mintinline{python}{backward}函数了。
|
||||
\columnbreak
|
||||
\begin{minted}{python}
|
||||
def backward(self, label):
|
||||
'''
|
||||
label is the ground truth
|
||||
Please compute the gradients of self.W1 and self.W2
|
||||
'''
|
||||
|
||||
# ==========
|
||||
# todo '''补全该前馈神经网络的后向传播算法'''
|
||||
# ==========
|
||||
|
||||
|
||||
\end{minted}
|
||||
\end{multicols}
|
||||
\end{frame}
|
||||
|
||||
\begin{frame}[fragile]
|
||||
\begin{multicols}{2}
|
||||
仍然要注意在Softmax反向传播后需要转置一下。
|
||||
|
||||
\mintinline{python}{Matmul.backward}返回的结果为\mintinline{python}{return grad_x, grad_W},这也提示了全连接层要保留对输入和对参数的求导,对输入的求导用来继续反向传播,对参数的求导用来更新参数。
|
||||
\columnbreak
|
||||
\begin{minted}{python}
|
||||
def backward(self, label):
|
||||
'''
|
||||
label is the ground truth
|
||||
Please compute the gradients of self.W1 and self.W2
|
||||
'''
|
||||
|
||||
# ==========
|
||||
# todo '''补全该前馈神经网络的后向传播算法'''
|
||||
temp = self.log.backward(-label)
|
||||
temp = self.softmax.backward(temp).T
|
||||
temp, self.gradient2 = self.mul_h2.backward(temp)
|
||||
temp = self.relu.backward(temp)
|
||||
temp, self.gradient1 = self.mul_h1.backward(temp)
|
||||
# ==========
|
||||
|
||||
|
||||
\end{minted}
|
||||
\end{multicols}
|
||||
\end{frame}
|
||||
|
||||
\subsection{更新参数}
|
||||
\begin{frame}[fragile]
|
||||
\begin{multicols}{2}
|
||||
更新参数只需要按照公式即可,不要忘记L2正则项的梯度,以下以$W_1$为例,$W_2$同理。
|
||||
|
||||
$W_1^{(i,j)}$表示$W_1$的第$i$行$j$列的元素,lr表示learning rate,即学习率。
|
||||
$$
|
||||
\frac{\mathrm{d}L2}{\mathrm{d}W_1^{(i,j)}}= \frac{2 \lambda_1 W_1^{(i,j)}}{\left\Vert W_1 \right\Vert }
|
||||
$$
|
||||
|
||||
$$
|
||||
W_1 = W_1 - \left( \frac{\mathrm{d}loss}{\mathrm{d}W_1}+\frac{\mathrm{d}L2}{\mathrm{d}W_1} \right) \times lr
|
||||
$$
|
||||
\columnbreak
|
||||
\begin{minted}{python}
|
||||
def update(self):
|
||||
'''
|
||||
Please update self.W1 and self.W2
|
||||
'''
|
||||
|
||||
# ==========
|
||||
# todo '''更新该前馈神经网络的参数'''
|
||||
self.W1 -= (self.gradient1 + 2 * self.lambda1 * self.W1 / np.linalg.norm(self.W1)) * self.lr
|
||||
self.W2 -= (self.gradient2 + 2 * self.lambda1 * self.W2 / np.linalg.norm(self.W2)) * self.lr
|
||||
# ==========
|
||||
|
||||
\end{minted}
|
||||
\end{multicols}
|
||||
\end{frame}
|
||||
|
||||
\begin{frame}
|
||||
\zihao{-4}\centering{感谢观看!}
|
||||
\end{frame}
|
||||
\end{document}
|
40
离散数学/作业/mypreamble.tex
Normal file
40
离散数学/作业/mypreamble.tex
Normal file
@ -0,0 +1,40 @@
|
||||
\usepackage[margin=1in]{geometry}
|
||||
\usepackage{amsmath}
|
||||
\usepackage{amssymb, amsfonts, amstext, amsopn, amsthm}
|
||||
\usepackage[outputdir=./latex-output]{minted}
|
||||
\usepackage{subfiles}
|
||||
\usepackage{mylatex}
|
||||
\usepackage{fancyhdr}
|
||||
\usepackage{zhnumber} % change chapter number to chinese
|
||||
\usepackage{longtable}
|
||||
\usepackage{booktabs}
|
||||
\usepackage{enumitem}
|
||||
\usepackage{multicol}
|
||||
\usepackage{hyperref}
|
||||
\usepackage{subfig}
|
||||
\usepackage{tasks}
|
||||
\usepackage{appendix}
|
||||
\usepackage{gbt7714}
|
||||
\usepackage{totpages} % 不加这个会导致总页数出错
|
||||
\fancyfoot[C]{第 \thepage 页\quad 共 \ref{TotPages} 页}
|
||||
\renewcommand\thesection{\thechapter.\arabic{section}}
|
||||
\renewcommand \thesubsection {\arabic{subsection}}
|
||||
\renewcommand{\labelenumii}{(\arabic{enumii})}
|
||||
\title{《离散数学》作业}
|
||||
\author{岳锦鹏}
|
||||
\newcommand{\mysignature}{10213903403 岳锦鹏}
|
||||
\date{2023年9月19日 —— 2023年12月31日}
|
||||
\setlist[1]{listparindent=\parindent}
|
||||
\setlist[2]{listparindent=\parindent}
|
||||
|
||||
\def\myitem#1#2{
|
||||
\item \text{#1}
|
||||
\begin{enumerate}
|
||||
#2
|
||||
\end{enumerate}
|
||||
}
|
||||
|
||||
% \newcommand{\mycircle}[1]{\large{\textcircled{\normalsize#1}}\normalsize}
|
||||
\setminted{linenos=true, breaklines=true, baselinestretch=0.85}
|
||||
|
||||
\bibliographystyle{gbt7714-numerical}
|
24
离散数学/作业/全部作业.tex
Normal file
24
离散数学/作业/全部作业.tex
Normal file
@ -0,0 +1,24 @@
|
||||
\documentclass[a4paper]{ctexbook}
|
||||
\input{mypreamble}
|
||||
\begin{document}
|
||||
\maketitle
|
||||
\tableofcontents
|
||||
\setcounter{page}{0} % 这样会导致目录的最后一页页码为0,TODO: 待修复
|
||||
\subfile{第一周作业}
|
||||
\subfile{第二周作业}
|
||||
\chapter{数论基础}
|
||||
\subfile{第三周作业}
|
||||
\subfile{第四周作业}
|
||||
\subfile{第五周作业}
|
||||
\subfile{第七周作业}
|
||||
\subfile{第八周作业}
|
||||
\subfile{第十周作业}
|
||||
\subfile{第十二周作业}
|
||||
\subfile{第十三周作业}
|
||||
\subfile{第十四周作业}
|
||||
\subfile{第十五周作业}
|
||||
\subfile{第十六周作业}
|
||||
\appendix
|
||||
\chapter{附录}
|
||||
\subfile{课程项目}
|
||||
\end{document}
|
204
离散数学/作业/第一周作业.tex
Normal file
204
离散数学/作业/第一周作业.tex
Normal file
@ -0,0 +1,204 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
% \documentclass[a4paper]{ctexart}
|
||||
\usepackage[margin=1in]{geometry} % 设置边距,符合Word设定
|
||||
% \usepackage{ctex}
|
||||
\usepackage{lipsum}
|
||||
\usepackage{amssymb, amsfonts, amstext, amsmath, amsopn, amsthm}
|
||||
% \usepackage{fontspec}
|
||||
\usepackage{minted}
|
||||
% \usepackage{shellesc}
|
||||
% \usepackage{regexpatch}
|
||||
% \usepackage{xpatch}
|
||||
% \usepackage{l3regex}
|
||||
\usepackage{expl3}
|
||||
\usepackage{environ}
|
||||
\usepackage{mylatex}
|
||||
% \setmainfont{Microsoft YaHei}
|
||||
% \setCJKmainfont{SimSun}
|
||||
\date{2023年9月14日}
|
||||
\begin{document}
|
||||
\chapter{集合论基础}
|
||||
\section{集合的概念和术语}
|
||||
|
||||
\renewcommand{\labelenumii}{(\arabic{enumii})}
|
||||
\begin{enumerate}
|
||||
\item
|
||||
给出集合{-3,-2,-1,0,1,2,3}的谓词表示法。
|
||||
|
||||
$\{ x|x \in \mathbb{Z}, -3\le x\le 3 \}$
|
||||
\item
|
||||
判断2和{2}是否下列集合的元素。
|
||||
|
||||
\begin{enumerate}
|
||||
|
||||
\item
|
||||
|
||||
$\{ x| {x\text{是大于1的整数}} \}$
|
||||
|
||||
2是, {2}不是。
|
||||
\item
|
||||
|
||||
$\{ x|x {\text{是某整数的平方}} \}$
|
||||
|
||||
2不是,{2}不是。
|
||||
\item
|
||||
|
||||
$\{ 2,\{ 2 \} \}$
|
||||
|
||||
2是,{2}是。
|
||||
\item
|
||||
|
||||
$\{ \{ 2 \},\{ \{ 2 \} \} \}$
|
||||
|
||||
2不是,{2}是。
|
||||
\item
|
||||
|
||||
$\{ \{ 2 \},\{ 2,\{ 2 \} \} \}$
|
||||
|
||||
2不是,{2}是。
|
||||
\item
|
||||
|
||||
$\{ \{ \{ 2 \} \} \}$
|
||||
|
||||
2不是,{2}不是。
|
||||
\end{enumerate}
|
||||
|
||||
\item
|
||||
下列哪些命题成立?哪些不成立?为什么?
|
||||
\begin{enumerate}
|
||||
\item
|
||||
|
||||
$\emptyset \in \{ \emptyset,\{ \emptyset \} \}$
|
||||
|
||||
成立。
|
||||
\item
|
||||
|
||||
$\emptyset\subseteq \{ \emptyset,\{ \emptyset \} \} $
|
||||
|
||||
成立。
|
||||
\item
|
||||
|
||||
$\{ \emptyset \}\subseteq \{ \emptyset,\{ \emptyset \} \}$
|
||||
|
||||
成立。
|
||||
\item
|
||||
|
||||
$\{ \{ \emptyset \} \}\subseteq \{ \emptyset,\{ \emptyset \} \}$
|
||||
|
||||
成立。
|
||||
\end{enumerate}
|
||||
\end{enumerate}
|
||||
|
||||
\section{集合的运算}
|
||||
\renewcommand{\labelenumii}{(\arabic{enumii})}
|
||||
\begin{enumerate}
|
||||
\item
|
||||
设A是ECNU二年级学生的集合,B是ECNU必须学习离散数学的学生的集合。请用A和B表示ECNU不必学习离散数学的二年级的学生的集合。\\
|
||||
$A\setminus B$
|
||||
\item
|
||||
设A是集合,下列命题是否必定成立?
|
||||
\begin{enumerate}
|
||||
|
||||
\item
|
||||
$A\in P(A)$\\
|
||||
是。
|
||||
\item
|
||||
$A \subseteq P(A)$\\
|
||||
否。
|
||||
\item
|
||||
$\{ A \}\in P(A)$\\
|
||||
否。
|
||||
\item
|
||||
$\{ A \} \subseteq P(A)$\\
|
||||
是。
|
||||
\end{enumerate}
|
||||
\item
|
||||
设A和B是任意集合,证明 $P(A)\cap P(B)=P(A\cap B)$。\\
|
||||
\begin{proof}
|
||||
\ExplSyntaxOn
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
证明:&\\
|
||||
&X \in P(A) \cap P(B)\\
|
||||
\Leftrightarrow &X \in P(A) 且 X \in P(B)\\
|
||||
\Leftrightarrow &X \subseteq A, X \subseteq B\\
|
||||
\Leftrightarrow &X \subseteq A \cap B\\
|
||||
\Leftrightarrow &X \in P(A \cap B)\\
|
||||
\therefore &P(A)\cap P(B) = P(A\cap B)\\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\ExplSyntaxOff
|
||||
\end{proof}
|
||||
|
||||
\item
|
||||
设A是任意集合,$A^3=(A×A)×A=A×(A×A)$是否成立?为什么?\\
|
||||
\ExplSyntaxOn
|
||||
\begin{zhongwen}
|
||||
$不一定,假设A=\{ 1 \},则A^3=\{ (1,1,1) \}, (A\times A)\times A=\{ ((1,1),1) \}, A\times (A\times A)=\{ (1,(1,1)) \}$
|
||||
\end{zhongwen}
|
||||
\ExplSyntaxOff
|
||||
|
||||
\item
|
||||
设A、B、C和D是集合,证明:若A、B、C和D均非空集,且A×B=C×D,那么A=C且B=D。\\
|
||||
% {\ctex@fontset{middle}}
|
||||
|
||||
\begin{proof}
|
||||
\ExplSyntaxOn
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&假设 A \neq C 或 B \neq D\\
|
||||
&则\exists x, x \in A, x \notin C 或x \in C, x \notin A\\
|
||||
&或\exists y, y \in B, y \notin D 或y \in D, y \notin B\\
|
||||
&不妨设\exists x, x \in A, x \notin C\\
|
||||
&\because B 非空\\
|
||||
&\therefore 设b \in B\\
|
||||
&则(x,b) \in A\times B\\
|
||||
&\because x \notin C\\
|
||||
&\therefore (x,b) \notin C\times D\\
|
||||
&\therefore A\times B \neq C \times D\\
|
||||
&与已知矛盾\\
|
||||
&\therefore 若A、B、C和D均非空集,且A×B=C×D,\\
|
||||
&那么A=C且B=D。\\
|
||||
\end{aligned}
|
||||
$$
|
||||
% \endbf
|
||||
\end{zhongwen}
|
||||
\ExplSyntaxOff
|
||||
\end{proof}
|
||||
|
||||
\item *编写一个程序,输入任意一个自然数n,输出P({1,2,…,n})的所有元素。 \\
|
||||
(JavaScript,Nodejs环境)
|
||||
\begin{minted}{javascript}
|
||||
const readline = require("readline");
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
});
|
||||
|
||||
let n;
|
||||
|
||||
function get_pow_set(end_num) {
|
||||
end_num = parseInt(end_num);
|
||||
let pow_set = [[]];
|
||||
for (let i = 1; i <= end_num; i++) {
|
||||
pow_set = pow_set.concat(pow_set.map((ele) => {
|
||||
return ele.concat([i]);
|
||||
}));
|
||||
}
|
||||
return pow_set;
|
||||
}
|
||||
|
||||
rl.question("", (answer) => {
|
||||
n = parseInt(answer);
|
||||
console.log(get_pow_set(n));
|
||||
rl.close();
|
||||
});
|
||||
|
||||
\end{minted}
|
||||
|
||||
\end{enumerate}
|
||||
|
||||
\end{document}
|
79
离散数学/作业/第七周作业.tex
Normal file
79
离散数学/作业/第七周作业.tex
Normal file
@ -0,0 +1,79 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
\pagestyle{fancyplain}
|
||||
\fancyhead{}
|
||||
\fancyhead[C]{\mysignature}
|
||||
\setcounter{chapter}{4}
|
||||
\setcounter{section}{1}
|
||||
|
||||
\begin{document}
|
||||
\section{谓词公式的等值演算和前束范式}
|
||||
\begin{enumerate}
|
||||
\item 指出谓词公式$\forall x\forall y(P(x,y)\lor Q(y,z))\land \exists xR(x,y)$的指导变元、量词的辖域、约束变元和自由变元。
|
||||
\begin{figure}[h]
|
||||
\centering
|
||||
\includexopp[0.8]{7.1.1}
|
||||
\end{figure}
|
||||
\item 求谓词公式$\forall x \forall y (P(x,y) \leftrightarrow Q(x,y)) \to \exists x \forall y R(x,y)$的前束范式。
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\forall x \forall y(P(x,y) \leftrightarrow Q(x,y)) \to \exists x \forall y R(x, y) \\
|
||||
=&\forall x \forall y(P(x,y)\leftrightarrow Q(x,y)) \to \exists z \forall uR(z, u) & (换名) \\
|
||||
=&\lnot (\forall x\forall y(P(x,y)\leftrightarrow Q(x,y)))\lor \exists z\forall uR(z,u) & (消去\to ) \\
|
||||
=&\exists x\exists y(\lnot (P(x,y)\leftrightarrow Q(x,y)))\lor \exists z\forall u R(z,u) & (内移\lnot )\\
|
||||
=&\exists x\exists y\exists z\forall u(\lnot (P(x,y)\leftrightarrow Q(x,y))\lor R(z,u)) & (量词前移) \\
|
||||
=&\exists x\exists y\exists z\forall u((P(x,y)\leftrightarrow Q(x,y))\to R(z,u)) & (恢复\to (非必要)) \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\end{enumerate}
|
||||
\section{一阶逻辑的推理理论}
|
||||
\begin{enumerate}
|
||||
\item 构造$\forall x(P(x)\lor Q(x)), \forall x(Q(x) \to \lnot R(x)), \forall xR(x) \Rightarrow \forall xP(x)$的形式证明。
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
$$设y为任意的个体变量$$
|
||||
\begin{enumerate}[label=\mycircle{\arabic{enumii}},leftmargin=\linewidth/4,rightmargin=\linewidth/4]
|
||||
\item $\forall x(P(x)\lor Q(x))$\hfill 前提引入
|
||||
\item $P(y)\lor Q(y)$\hfill \mycircle{1} US规则
|
||||
\item $\forall x(Q(x)\to \lnot R(x))$\hfill 前提引入
|
||||
\item $Q(y)\to \lnot R(y)$\hfill \mycircle{3} US规则
|
||||
\item $\forall xR(x)$ \hfill 前提引入
|
||||
\item $R(y)$\hfill \mycircle{5} US规则
|
||||
\item $\lnot Q(y)$\hfill \mycircle{4} \mycircle{6} 拒取式
|
||||
\item $P(y)$ \hfill \mycircle{2} \mycircle{7} 析取三段论
|
||||
\item $\forall xP(x)$\hfill \mycircle{8} UG规则
|
||||
\end{enumerate}
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 证明下面的推理:\\
|
||||
“每个科研工作者都是努力工作的。每个努力工作而又聪明的人都取得事业的成功。某个人是科研工作者并且聪明。所以,某人事业取得成功。”
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&设P(x): x是科研工作者,Q(x): x努力工作,R(x): x聪明,S(x): x取得事业的成功, \\
|
||||
&e: 某个人,则需要证明: \\
|
||||
&\forall x(P(x)\to Q(x)), \forall x (Q(x)\land R(x)\to S(x)), P(e)\land R(e) \Rightarrow S(e) \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
\begin{enumerate}[label=\mycircle{\arabic{enumii}},leftmargin=\linewidth/4,rightmargin=\linewidth/4]
|
||||
\item $P(e)\land R(e)$\hfill 前提引入
|
||||
\item $P(e)$\hfill \mycircle{1} 化简
|
||||
\item $R(e)$\hfill \mycircle{1} 化简
|
||||
\item $\forall x(P(x)\to Q(x))$\hfill 前提引入
|
||||
\item $P(e)\to Q(e)$\hfill \mycircle{4} US规则
|
||||
\item $Q(e)$\hfill \mycircle{2} \mycircle{5} 假言推理
|
||||
\item $Q(e)\land R(e)$\hfill \mycircle{3} \mycircle{6} 合取引入
|
||||
\item $\forall x(Q(x)\land R(x)\to S(x))$\hfill 前提引入
|
||||
\item $Q(e)\land R(e)\to S(e)$\hfill \mycircle{8} US规则
|
||||
\item $S(e)$\hfill \mycircle{7} \mycircle{9} 假言推理
|
||||
\end{enumerate}
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\end{enumerate}
|
||||
\end{document}
|
206
离散数学/作业/第三周作业.tex
Normal file
206
离散数学/作业/第三周作业.tex
Normal file
@ -0,0 +1,206 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
\usepackage{titlesec}
|
||||
\pagestyle{fancyplain}
|
||||
\fancyhead{}
|
||||
\fancyhead[C]{\mysignature}
|
||||
\setcounter{chapter}{2}
|
||||
|
||||
\begin{document}
|
||||
% \titleformat{\chapter}{}
|
||||
\chapter{命题逻辑}
|
||||
\section{命题}
|
||||
\begin{enumerate}
|
||||
\myitem{下列语句哪些是命题?}{
|
||||
\item 2是正数吗?
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
不是。
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\item $x^{2}+x+1=0$
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
是。
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\item 我要上学。
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
是。
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\item 明年2月1日下雨。
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
是。
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\item 如果股票涨了,那么我就赚钱。
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
是。
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
}
|
||||
\item 将当当网的图书高级搜索符号化:http://search.dangdang.com/AdvanceSearch/AdvanceSearch.aspx?c=0
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&介质=\{\}\land 书名=\{\}\land 作者译者=\{\}\land 关键词=\{\}\land 出版社=\{\}\land ISBN=\{\}\land 包装=\{\} \\
|
||||
&\land 分类=\{\}\land \{最低价格\} \le 价格 \le \{最高价格\}\land \{最低折扣\}\le 折扣\le \{最高折扣\} \\
|
||||
&\land \{最早出版时间\}\le 出版时间\le \{最晚出版时间\}\land 库存状态=\{\} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\item 请将语句“除非你已满16周岁,否则只要你身高不足1.2米就不能乘公园的滑行铁道”符号化。
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&令p:你已满16周岁,q:你身高足1.2米,r:你能乘公园的滑行铁道。 \\
|
||||
&命题符号化为:\lnot p \to (\lnot q \to \lnot r) \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\item p、q、r为如下命题: \par
|
||||
\qquad p:你得流感了 \par
|
||||
\qquad q:你错过了最后的考试 \par
|
||||
\qquad r:这门课你通过了 \\
|
||||
请用自然语言表达命题$(p \to \lnot r)\lor (q \to \lnot r)$。
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
如果你得流感了,那么这门课你没通过,或者如果你错过了最后的考试,那么这门课你没通过。
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\myitem{判断下列命题的真值:}{
|
||||
\item \begin{zhongwen}
|
||||
$若1+1=3,则2+2=4$
|
||||
\end{zhongwen}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
最外层的蕴含式的前件为假,所以此命题的真值为1。
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\item \begin{zhongwen}
|
||||
$若鸟会飞,则1+1=3$
|
||||
\end{zhongwen}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&在考虑例外的情况下(\exists 不会飞的鸟类): \\
|
||||
&\qquad 最外层的蕴含式的前件为假,所以此命题的真值为1。 \\
|
||||
&在不考虑例外的情况下: \\
|
||||
&\qquad 最外层的蕴含式的前件为真,但后件为假,所以此命题的真值为0。 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
}
|
||||
\item 构造一个只含命题变量p、q和r的命题公式A,满足:p、q和r的任意一个赋值是A的成真赋值当且仅当p、q和r中恰有两个为真
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
A=(p\land q\land \lnot r)\lor (p\land \lnot q\land r)\lor (\lnot p\land q\land r)
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{enumerate}
|
||||
\section{等值演算}
|
||||
\begin{enumerate}
|
||||
\myitem{将下列两个命题符号化,并分别用真值表和等值演算的方法证明所得到的那两个命题公式是等值的。}{
|
||||
\item 你不会休息所以就不会工作,你没有丰富的知识所以你就不会工作。
|
||||
\item 你会工作所以一定会休息并具有丰富的知识。
|
||||
}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
令&p:你会休息,q:你会工作,r:你有丰富的知识 \\
|
||||
则&(1)符号化为(\lnot p \to \lnot q)\land (\lnot r \to \lnot q) \\
|
||||
&(2)符号化为q \to p \land r \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
以下是真值表:
|
||||
$$
|
||||
\begin{longtable}{ccccc}
|
||||
\hline
|
||||
$p$ & $q$ & $r$ & $(\lnot p \to \lnot q)\land (\lnot r \to \lnot q)$ & $q \to p \land r$ \\
|
||||
\hline
|
||||
0 & 0 & 0 & 1 & 1 \\
|
||||
0 & 0 & 1 & 1 & 1 \\
|
||||
0 & 1 & 0 & 0 & 0 \\
|
||||
0 & 1 & 1 & 0 & 0 \\
|
||||
1 & 0 & 0 & 1 & 1 \\
|
||||
1 & 0 & 1 & 1 & 1 \\
|
||||
1 & 1 & 0 & 0 & 0 \\
|
||||
1 & 1 & 1 & 1 & 1 \\
|
||||
\hline
|
||||
\end{longtable}
|
||||
$$
|
||||
\begin{aligned}
|
||||
以下是等值演算: \\
|
||||
(\lnot p \to \lnot q)\land (\lnot r \to \lnot q) & = (p\lor \lnot q)\land (r\lor \lnot q) \\
|
||||
& = (p\land r)\lor \lnot q \\
|
||||
& = \lnot q\lor (p\land r) \\
|
||||
& = q \to p\land r \\
|
||||
\end{aligned}
|
||||
$$
|
||||
$$
|
||||
所以(\lnot p \to \lnot q)\land (\lnot r \to \lnot q)与q \to p \land r等值。
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 用等值演算的方法证明命题恒等式$p \to (q \to p)=\lnot p \to (p \to \lnot q)$
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
\lnot p \to (p \to \lnot q) & = p \lor (p \to \lnot q) \\
|
||||
& = p \lor (\lnot p \lor \lnot q) \\
|
||||
& = \lnot p \lor \lnot q \lor p \\
|
||||
& = p \to (\lnot q \lor p) \\
|
||||
& = p \to (q \to p) \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\myitem{一教师要从3名学生A、B和C中选派1$\sim $2人参加市级科技竞赛,需满足以下条件:}{
|
||||
\item 若A去,则C同去;
|
||||
\item 若B去,则C不能去;
|
||||
\item 若C不去,则A或B可以去。
|
||||
}
|
||||
问该如何选派?\\
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&令a:A去,b:B去,c:C去 \\
|
||||
则需满足:& \quad (a \to c)\land (b \to \lnot c) \land (\lnot c \to a \lor b)\land \lnot (a\land b\land c) \\
|
||||
&=(\lnot a \lor c)\land (\lnot b \lor \lnot c)\land (c \lor (a \lor b))\land (\lnot a\lor \lnot b\lor \lnot c) \\
|
||||
&=(\lnot a \lor c)\land (\lnot b \lor \lnot c)\land (a \lor b\lor c)\land (\lnot a\lor \lnot b\lor \lnot c) \\
|
||||
&=(\lnot a\lor \lnot b\lor c)\land (\lnot a\lor b\lor c)\land (\lnot a\lor \lnot b\lor \lnot c)\land (a\lor \lnot b\lor \lnot c)\land (a\lor b\lor c) \\
|
||||
&=\bigwedge M(0,3,4,6,7) \\
|
||||
&=\bigvee m(1,2,5) \\
|
||||
&=(\lnot a\land \lnot b\land c)\lor (\lnot a\land b\land \lnot c)\lor (a\land \lnot b\land c) \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\begin{flalign*}
|
||||
即选派C或选派B或选派AC。&&\\
|
||||
\end{flalign*}
|
||||
\end{zhongwen}
|
||||
\end{enumerate}
|
||||
\end{document}
|
201
离散数学/作业/第二周作业.tex
Normal file
201
离散数学/作业/第二周作业.tex
Normal file
@ -0,0 +1,201 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
\usepackage{mylatex}
|
||||
\pagestyle{fancy}
|
||||
\fancyhead{}
|
||||
\fancyhead[C]{\mysignature}
|
||||
\setcounter{chapter}{1}
|
||||
\setcounter{section}{2}
|
||||
|
||||
\begin{document}
|
||||
\section{集合运算的性质}
|
||||
\begin{enumerate}
|
||||
\item[9.] \ExplSyntaxOn
|
||||
\begin{zhongwen}
|
||||
$设A、B、C是集合,证明下列结论:$
|
||||
\end{zhongwen}
|
||||
\ExplSyntaxOff
|
||||
\begin{enumerate}
|
||||
\item[(3)] \ExplSyntaxOn
|
||||
\begin{zhongwen}
|
||||
$若A\cap B=\varnothing,则A-B=A$
|
||||
\end{zhongwen}
|
||||
\ExplSyntaxOff
|
||||
\begin{proof}
|
||||
\ExplSyntaxOn
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\because A\cap B=\varnothing\\
|
||||
&\therefore \forall x \in A \implies x\notin B\\
|
||||
&\therefore \forall x \in A\implies x\in \bar{B}\\
|
||||
&\therefore A \subseteq \bar{B}\\
|
||||
&\therefore A\cap \bar{B}=A\\
|
||||
&\therefore A-B=A\\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\ExplSyntaxOff
|
||||
\end{proof}
|
||||
\end{enumerate}
|
||||
\item[11.] \ExplSyntaxOn
|
||||
\begin{zhongwen}
|
||||
$指出下列集合等式成立的充分必要条件,其中A、B和C是集合:$
|
||||
\end{zhongwen}
|
||||
\ExplSyntaxOff
|
||||
\begin{enumerate}
|
||||
\item[(5)] $(A-B)\cap (A-C)=\varnothing$
|
||||
$$
|
||||
\begin{aligned}
|
||||
&(A-B)\cap (A-C)=A\cap \bar{B}\cap A \cap \bar{C}=A\cap \bar{B}\cap \bar{C}=A-B-C=\varnothing\\
|
||||
&\iff A-B-C=\varnothing\\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{enumerate}
|
||||
\item[13.] \ExplSyntaxOn
|
||||
\begin{zhongwen}
|
||||
$设A和B是集合,集合运算对称差\oplus 定义如下:A\oplus B=(A-B)\cup (B-A).\\证明下列恒等式,其中A、B和C是任意集合:$
|
||||
\end{zhongwen}
|
||||
\ExplSyntaxOff
|
||||
\begin{enumerate}
|
||||
\item[(5)] $A\oplus B=(A\cup B)-(A\cap B)$
|
||||
\begin{proof}
|
||||
\ExplSyntaxOn
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
(A\cup B)-(A\cap B) & = (A\cup B)\cap \overline{A\cap B} \\
|
||||
& = (A\cup B)\cap (\bar{A}\cup \bar{B}) \\
|
||||
& = ((A\cup B)\cap \bar{A})\cup ((A\cup B)\cap \bar{B}) \\
|
||||
& = (B\cap \bar{A})\cup (A\cap \bar{B}) \\
|
||||
& = (A-B)\cup (B-A) \\
|
||||
& = A\oplus B \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\ExplSyntaxOff
|
||||
\end{proof}
|
||||
\end{enumerate}
|
||||
\item[21.] \textit{设A、B、C和D是任意集合.请证明:}
|
||||
\begin{enumerate}
|
||||
\item $(A\times C)\cap (B\times D)=(A\cap B)\times (C\cap D)$
|
||||
\begin{proof}
|
||||
\ExplSyntaxOn
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
\forall (x,y), \quad&(x,y)\in (A\times C)\cap (B\times D)\\
|
||||
\iff &(x,y)\in (A\times C)且(x,y)\in (B\times D)\\
|
||||
\iff &x\in A,y\in C且x\in B,y\in D\\
|
||||
\iff &x\in A\cap B且y\in C\cap D\\
|
||||
\iff &(x,y)\in (A\cap B)\times (C\cap D)\\
|
||||
\therefore \quad&(A\times C)\cap (B\times D)=(A\cap B)\times (C\cap D)\\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\ExplSyntaxOff
|
||||
\end{proof}
|
||||
\end{enumerate}
|
||||
\item[22.] \textit{设$\{ A_\beta|\beta\in B \}$是以B为下标集的集合族.证明下列恒等式.}
|
||||
\begin{enumerate}
|
||||
\item $\overline{\displaystyle \bigcup_{\beta\in B} A_\beta}=\displaystyle \bigcap_{\beta\in B} \overline{A_\beta}$
|
||||
\begin{proof}
|
||||
% \ExplSyntaxOn
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
\forall x, \quad&x\in \overline{\bigcup_{\beta\in B}A_\beta}\\
|
||||
\iff& x\notin \bigcup_{\beta\in B} A_\beta\\
|
||||
\iff&\lnot (\exists \beta\in B, x\in A_\beta)\\
|
||||
\iff&\forall \beta\in B, x\notin A_\beta\\
|
||||
\iff&\forall \beta\in B, x\in \overline{A_\beta}\\
|
||||
\iff&x\in \bigcap_{\beta\in B} \overline{A_\beta}\\
|
||||
\therefore \quad&\overline{\bigcup_{\beta\in B} A_\beta}=\bigcap_{\beta\in B} \overline{A_\beta}\\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
% \ExplSyntaxOff
|
||||
\end{proof}
|
||||
\end{enumerate}
|
||||
\item[24.] \textit{设集合族$\{A_n|n\in \mathbb{N}\}$,令$B_0=A_0$,$B_n=A_n-\displaystyle \bigcup_{k=0}^{n-1} A_k(n>0) $.证明:}
|
||||
\begin{enumerate}
|
||||
\item[(2)] $\displaystyle\bigcup_{ n\in \mathbb{N}} A_n =\displaystyle \bigcup_{n\in \mathbb{N}} B_n$
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\because B_n=A_n-\displaystyle \bigcup_{k=0}^{n-1}A_k(n>0)\\
|
||||
&\therefore \forall n>0, B_n\in A_n\\
|
||||
&\forall x\in \bigcup_{n\in \mathbb{N}} B_n \iff\exists n_0\in \mathbb{N},x\in B_{n_0}\implies x\in A_{n_0}\\
|
||||
&\therefore \displaystyle \bigcup_{n\in \mathbb{N}}A_n\supseteq \bigcup_{n\in \mathbb{N}} B_n \\
|
||||
&\forall x\in \displaystyle \bigcup_{n\in \mathbb{N}} A_n, 则 \exists n\in \mathbb{N},x\in A_{n} \\
|
||||
&设C_x=\{ n|x\in A_n \} \\
|
||||
&设n_1=\min{C_x} \\
|
||||
&则x\in A_{n_1}且\forall n_2<n_1,x\notin A_{n_2} \\
|
||||
&\therefore x\notin \displaystyle \bigcup_{k=0}^{n_1-1}A_k \\
|
||||
&\therefore x\in A_{n_1}-\bigcup_{k=0}^{n_1-1}A_k \\
|
||||
&\therefore x\in B_{n_1} \\
|
||||
&\therefore x\in \displaystyle \bigcup_{n\in \mathbb{N}} B_n \\
|
||||
&\therefore \bigcup_{n\in \mathbb{N}}A_n \subseteq \bigcup_{n\in \mathbb{N}} B_n \\
|
||||
&\therefore \bigcup_{n\in \mathbb{N}} A_n =\bigcup_{n\in \mathbb{N}} B_n \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\end{enumerate}
|
||||
\end{enumerate}
|
||||
\section{有限集合的计数}
|
||||
\begin{enumerate}
|
||||
\item[26.] \textit{以1开头或者以00结束的不同的字节(8位的二进制串)有多少个?}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&设A为以1开头的不同的字节,B为以00结束的不同的字节。 \\
|
||||
&则\left\vert 以1开头或者以00结束的不同的字节 \right\vert =\left\vert A\cup B \right\vert =\left\vert A \right\vert +\left\vert B \right\vert -\left\vert A\cap B \right\vert =2^{7}+2^{6}-2^{5} = 160 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\item[27.] \begin{zhongwen}
|
||||
$在1\sim 200的正整数中,$
|
||||
\end{zhongwen}
|
||||
\begin{enumerate}
|
||||
\item[(3)] \begin{zhongwen}
|
||||
$含因子3或5,但不同时含因子3和5的正整数共有多少个?$
|
||||
\end{zhongwen}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&设A为1\sim 200中含因子3的正整数,B为1\sim 200中含因子5的正整数 \\
|
||||
&则\left\vert 在1\sim 200的正整数中 含因子3或5,但不同时含因子3和5的正整数 \right\vert \\
|
||||
&= \left\vert A\oplus B \right\vert =\left\vert A \right\vert +\left\vert B \right\vert -2\left\vert A\cap B \right\vert =66+40-2*13 = 80 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
*用JavaScript再验证一下:
|
||||
\begin{minted}{javascript}
|
||||
> a =[]
|
||||
[]
|
||||
> for (let i = 1; i<=200; i++){
|
||||
... a.push(i);
|
||||
... }
|
||||
> a.reduce((out, cur) => {
|
||||
... if ((cur%3==0 || cur%5==0) && cur%15!=0) out.push(cur);
|
||||
... return out;
|
||||
... }, Array()).length
|
||||
80
|
||||
\end{minted}
|
||||
\item[(5)] \begin{zhongwen}
|
||||
$与15互素的正整数(即与15之间的最大公因子为1的那些正整数)共有多少个?$
|
||||
\end{zhongwen}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&A与B的定义和上题相同 \\
|
||||
&则\left\vert 在1\sim 200的正整数中与15互素的正整数 \right\vert \\
|
||||
&=\left\vert 1\sim 200的正整数 \right\vert -\left\vert A\cup B \right\vert \\
|
||||
&=200-(\left\vert A \right\vert +\left\vert B \right\vert -\left\vert A\cap B \right\vert )=200-(66+40-13) = 107 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{enumerate}
|
||||
\end{enumerate}
|
||||
\end{document}
|
125
离散数学/作业/第五周作业.tex
Normal file
125
离散数学/作业/第五周作业.tex
Normal file
@ -0,0 +1,125 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
\pagestyle{fancyplain}
|
||||
\fancyhead{}
|
||||
\fancyhead[C]{\mysignature}
|
||||
\setcounter{chapter}{3}
|
||||
\setcounter{section}{2}
|
||||
|
||||
\begin{document}
|
||||
\chapter{一阶逻辑}
|
||||
\section{谓词、量词和谓词公式}
|
||||
\begin{enumerate}
|
||||
\item 用谓词公式表达语句“所有的运动员都钦佩某些教练”,个体域为全总个体域。
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&由于个体域为全总个体域, \\
|
||||
&设P(x)表示x为运动员,Q(x)表示x为教练,R(x,y)表示x钦佩y, \\
|
||||
&注意到“某些”表示复数,则语句“所有的运动员都钦佩某些教练”可表示为: \\
|
||||
&\forall x(P(x) \to \exists y\exists z((y \neq z)\land Q(y)\land Q(z) \land R(x,y)\land R(x,z))) \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 用谓词公式表达语句“本班的学生都已学过微积分”,个体域分别取ECNU的学生集合和本班的学生集合。
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&当个体域取ECNU的学生集合时, \\
|
||||
&设P(x)表示x为本班的学生,Q(x)表示x已学过微积分, \\
|
||||
&则语句“本班的学生都已学过微积分”可表示为: \\
|
||||
&\forall x(P(x) \to Q(x)) \\
|
||||
&当个体域取本班的学生集合时, \\
|
||||
&设Q(x)表示x已学过微积分, \\
|
||||
&则语句“本班的学生都已学过微积分”可表示为: \\
|
||||
&\forall x Q(x) \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 用谓词公式表达语句“班上无人恰给另外两个同班同学发过电子邮件”,个体域取本班学生的集合。
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&由于个体域为本班学生的集合, \\
|
||||
&设P(x, y)表示x给y发过电子邮件, \\
|
||||
&则语句“班上无人恰给另外两个同班同学发过电子邮件”可表示为: \\
|
||||
&\lnot \exists x(\exists y\exists z((y\neq z)\land P(x,y)\land P(x,z)\land \forall w((w \neq y)\land (w\neq z) \to \lnot P(x,w)))) \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 将$\forall x(C(x)\lor \exists y(C(y)\land F(x,y)))$翻译成汉语,其中C(x)表示x有电脑,F(x,y) 表示x和y是同班同学,个体域是学校全体学生的集合。
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&对于学校中的任何一个学生,他有电脑,或者存在一个他的同班同学有电脑。 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 给定解释I如下:\\
|
||||
个体域$D: \{ -2,3,6 \}$;\\
|
||||
个体常元$a: 6$;\\
|
||||
谓词$P: 2 > 1, Q(x): x\leqslant 3, R(x): x>5$。\\
|
||||
求出谓词公式$\forall x(P \to Q(x))\lor R(a)$在解释I下的真值。
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\forall x(P \to Q(x))\lor R(a)在解释I下的真值为: \\
|
||||
&((P \to Q(-2))\land (P \to Q(3))\land (P \to Q(6)))\lor R(6) \\
|
||||
&=(((2>1) \to (-2\leqslant 3))\land ((2>1) \to (3\leqslant 3))\land ((2>1) \to (6\leqslant 3)))\lor (6>5) \\
|
||||
&=((1 \to 1)\land (1 \to 1)\land (1 \to 0))\lor 1\\
|
||||
&=(1\land 1\land 0)\lor 1 \\
|
||||
&=0\lor 1 \\
|
||||
&=1 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item[书上3.] 请将下列谓词公式翻译为汉语,并指出每个命题的真值,这里个体域为实数集。
|
||||
\begin{enumerate}
|
||||
\item $\forall x(x^{2}=x)$;
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
对于任何一个实数x,都有x^{2}=x
|
||||
$$
|
||||
$$
|
||||
真值为0
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\item $\exists x(2x=x)$;
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
存在一个实数x,满足2x=x
|
||||
$$
|
||||
$$
|
||||
真值为1
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\item $\exists x(x^{2}+3x-2=x)$;
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
存在一个实数x,使得x^{2}+3x-2=x
|
||||
$$
|
||||
$$
|
||||
真值为1
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\item $\forall x(x-3<x)$;
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
对于任意一个实数x,都有x-3<x
|
||||
$$
|
||||
$$
|
||||
真值为1
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{enumerate}
|
||||
\end{enumerate}
|
||||
\end{document}
|
211
离散数学/作业/第八周作业.tex
Normal file
211
离散数学/作业/第八周作业.tex
Normal file
@ -0,0 +1,211 @@
|
||||
% \PassOptionsToClass{twocolumn}{ctexbook} % 这个得在设置文档类之前使用才有效
|
||||
% \PassOptionsToPackage{twocolumn}{ctexbook} % 这样没用
|
||||
\documentclass[全部作业]{subfiles}
|
||||
% \usepackage{multicol} % 已经放到mypreamble里了
|
||||
% 以下这样和\setlength{\columnseprule}{1pt}应该是一样的
|
||||
\columnseprule=1pt
|
||||
\columnsep=30pt
|
||||
|
||||
\pagestyle{fancyplain}
|
||||
\fancyhead{}
|
||||
\fancyhead[C]{\mysignature}
|
||||
\setcounter{chapter}{4}
|
||||
|
||||
\begin{document}
|
||||
\chapter{关系}
|
||||
\section{关系的概念}
|
||||
\begin{enumerate}
|
||||
\item 集合$X=\{a,b,c\}$上的一个关系R的关系矩阵如下,请写出这个关系。(注:矩阵的第1、2、3行以及第1、2、3列,分别对应X中的元素a、b、c)。
|
||||
$$
|
||||
\begin{bmatrix} 1 & 0 & 1 \\ 0 & 1 & 0 \\ 1 & 0 & 1 \\\end{bmatrix}
|
||||
$$
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
R = \{ (a,a),(a,c),(b,b), (c,a), (c,c) \}
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 一集合上的一个关系的关系图如下图所示,请写出这个关系。
|
||||
\begin{center}
|
||||
\includegraphics[width=0.3\linewidth]{imgs/2023-11-11-10-13-03.png}
|
||||
\end{center}
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
R=\{ (a,a),(a,b),(b,a),(b,b),\\(c,a),(c,c),(c,d),(d,d) \}
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 设X和Y都是有限集,$|X|=m$,$|Y|=n$。问X到Y的不同的关系有多少个?
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
X到Y的不同的关系有2^{m\times n}个。
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\end{enumerate}
|
||||
\section{关系的运算}
|
||||
\begin{enumerate}
|
||||
\item 设R是X到Y的二元关系,S是Y到Z的二元关系,证明$(R \circ S)^{-1}=S^{-1}\circ R^{-1}$。
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
\forall (z, x),\qquad &(z, x)\in (R\circ S)^{-1} \\
|
||||
\iff& (x, z)\in R\circ S \\
|
||||
\iff&\exists y\in Y, \ \ \text{s.t.} \ (x,y)\in R \land (y,z)\in S \\
|
||||
\iff& \exists y\in Y,\ \ \text{s.t.} \ (y,x)\in R^{-1}\land (z,y)\in S^{-1} \\
|
||||
\iff&(z,x)\in S^{-1}\circ R^{-1} \\
|
||||
\end{aligned}
|
||||
$$
|
||||
$$
|
||||
\therefore (R\circ S)^{-1}=S^{-1}\circ R^{-1}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 设R、S、T都是X上的关系。证明:$R\circ (S\cap T)\subseteq (R\circ S)\cap (R\circ T)$, $(R\cap S)\circ T \subseteq (R\circ T)\cap (S\circ T)$。
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\forall (x,w)\in R\circ (S\cap T) \\
|
||||
&即 \exists y\in X,\ \ \text{s.t.} \ (x,y)\in R\land (y,w)\in S\cap T \\
|
||||
&\therefore (x,y)\in R, (y,w)\in S,(y,w)\in T \\
|
||||
&\therefore (x,w)\in R\circ S, (x,w)\in R\circ T \\
|
||||
&\therefore (x,w)\in (R\circ S)\cap (R\circ T) \\
|
||||
&\therefore R\circ (S\cap T)\subseteq (R\circ T)\cap (S\circ T) \\
|
||||
\end{aligned}
|
||||
$$
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\forall (x,w)\in (R\cap S)\circ T \\
|
||||
&即\exists z\in X,\ \ \text{s.t.} \ (x,z)\in R\cap S\land (z,w)\in T \\
|
||||
&\therefore (x,z)\in R,(x,z)\in S,(z,w)\in T \\
|
||||
&\therefore (x,w)\in R\circ T,(x,w)\in S\circ T \\
|
||||
&\therefore (x,w)\in (R\circ T)\cap (S\circ T) \\
|
||||
&\therefore (R\cap S)\circ T \subseteq (R\circ T)\cap (S\circ T) \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\end{enumerate}
|
||||
\section{关系的特殊性质及其闭包}
|
||||
\begin{enumerate}
|
||||
\item 下列关系是否是自反、反自反、对称、反对称和传递的?
|
||||
\begin{enumerate}
|
||||
\item 集合$X=\{1,2,…,9,10\}$,$X$上的关系$R=\{(x,y) | x+y=10\}$
|
||||
\item 任意集合$X$上的恒等关系$I_{X}$。
|
||||
\item 任意集合$X$上的空关系$\varnothing $。
|
||||
\begin{table}[H]
|
||||
\centering
|
||||
\tabcolsep=0.5em
|
||||
\begin{tabular}{c|ccccc}
|
||||
\toprule
|
||||
关系 & 自反 & 反自反 & 对称 & 反对称 & 传递\\
|
||||
\midrule
|
||||
(1) $R$ &否 & 否 & 是 & 否 & 否 \\
|
||||
(2) $I_{X}$ &是 & 否 & 是 & 是 & 是 \\
|
||||
(3) $\varnothing $ &否 & 是 & 是 & 是 & 是 \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{table}
|
||||
\end{enumerate}
|
||||
\item 设$X$是所有人组成的集合,定义$X$上的关系$R_1$和$R_2$:$aR_1b$当且仅当$a$比$b$高,$aR_2b$当且仅当$a$和$b$有共同的祖父母。问关系$R_1$和$R2$是否是自反、反自反、对称、反对称、传递的?
|
||||
\begin{table}[H]
|
||||
\centering
|
||||
\begin{tabular}{c|ccccc}
|
||||
\toprule
|
||||
关系 & 自反 & 反自反 & 对称 & 反对称 & 传递\\
|
||||
\midrule
|
||||
$R_1$ & 否 & 是 & 否 & 是 & 是 \\
|
||||
$R_2$ & 是 & 否 & 是 & 否 & 是 \\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{table}
|
||||
\item* 下面的论证试图证明:如果集合S上的关系R是对称和传递的,那么R必定也是自反的。请指出其中的错误。\\
|
||||
“由对称性,从xRy可推出yRx,再由传递性,可从xRy和yRx推出xRx。于是,对任意x$\in $S,xRx成立,所以R是自反的”
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&对于\forall x\in S,并不一定\exists y\in S,\ \ \text{s.t.} \ xRy \\
|
||||
&当\lnot\exists y(y\in S\land xRy)时上述论证无效。 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 证明:若$R$是$X$上自反和传递的关系,则$R^2$=$R$。
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\forall (x,z)\in R^{2}\\
|
||||
&\Rightarrow\exists y\in X,\ \ \text{s.t.} \ (x,y)\in R\land (y,z)\in R \\
|
||||
&\because R是传递的 \\
|
||||
&\therefore (x,z)\in R \\
|
||||
&\therefore R^{2} \subseteq R \\
|
||||
&\forall (x,z)\in R \\
|
||||
&\because R是自反的 \\
|
||||
&\therefore (z,z)\in R \\
|
||||
&\therefore (x,z) \in R^{2} \\
|
||||
&\therefore R \subseteq R^{2} \\
|
||||
&综上所述,R^{2}=R \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 设$X$是有限集,$|X|=n$。问$X$上有多少个不同的:
|
||||
\begin{enumerate}
|
||||
\item* 对称关系?
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
即n维对称矩阵的个数,
|
||||
$$
|
||||
$$
|
||||
2^{\frac{n(n+1)}{2}}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\item* 反对称关系?
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&n维矩阵的每组对称位置只有00、01、10\\
|
||||
&三种情况,对角线每个位置可以为0或1,\\
|
||||
\end{aligned}
|
||||
$$
|
||||
$$
|
||||
3^{\frac{n(n-1)}{2}}\times 2^{n}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\item 既非自反又非反自反的关系?
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
即对角线既不是全1,也不是全0的n维矩阵个数,
|
||||
$$
|
||||
$$
|
||||
(2^{n}-2)\times 2^{n^{2}-n}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{enumerate}
|
||||
\item 设$R_1$和$R_2$是$X$上的关系。证明$t(R_1\cup R_2)\supseteq t(R_1)\cup t(R_2)$。
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\because t(R)=\bigcup_{i=1} ^{\infty}R^{i} \\
|
||||
&\therefore 原式可转化为\bigcup_{i=1} ^{\infty}(R_1\cup R_2)^{i}\supseteq \bigcup_{j=1} ^{\infty}R_1^{j}\cup \bigcup_{k=1} ^{\infty}R_2^{k} \\
|
||||
&之后实在不会做了。 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\end{enumerate}
|
||||
\end{document}
|
119
离散数学/作业/第十三周作业.tex
Normal file
119
离散数学/作业/第十三周作业.tex
Normal file
@ -0,0 +1,119 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
|
||||
\pagestyle{fancyplain}
|
||||
\fancyhead{}
|
||||
\fancyhead[C]{\mysignature}
|
||||
\setcounter{chapter}{6}
|
||||
\setcounter{section}{1}
|
||||
|
||||
\begin{document}
|
||||
\section{集合的基数}
|
||||
\label{cardinality}
|
||||
\begin{enumerate}
|
||||
\item 集合$\{ x\ |\ x\in \mathbb{Z},\text{且}x\text{不能被3整除} \}$是否是可数集?若是,则给出自然数集$\mathbb{N}$与它之间的一个一一对应。
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
|
||||
将给定的集合记为$A$,它是可数集。
|
||||
|
||||
给出一一对应的函数如下:
|
||||
$$
|
||||
f\colon \mathbb{N} \to A, x \mapsto \begin{cases}
|
||||
\displaystyle (-1)^{\left\lfloor \frac{x}{2} \right\rfloor}\times 3 \left\lfloor \frac{x+2}{4} \right\rfloor + 1 , & x为偶数,x\geqslant 0 \vspace{1em} \\
|
||||
\displaystyle (-1)^{\left\lfloor \frac{x}{2} \right\rfloor}\times 3 \left\lfloor \frac{x+2}{4} \right\rfloor + 2 , & x为奇数,x\geqslant 0 \\
|
||||
\end{cases}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
|
||||
\item 设集合族$\{ A_n\ |\ n\in \mathbb{N} \}$和$\{ B_n\ |\ n\in \mathbb{N} \}$中的集合都是两两不相交的($i\neq j$时$A_i\cap A_j=\varnothing $,$B_i\cap B_j=\varnothing $),且对任意$n\in \mathbb{N}$,$A_n\sim B_n$。请证明$\displaystyle \bigcup_{n\in \mathbb{N}} A_n \sim \bigcup_{n\in \mathbb{N}} B_n$。
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
|
||||
对于$\forall n\in \mathbb{N}$,$A_n\sim B_n$,所以存在一一对应的$f_n: A_n \to B_n$。
|
||||
|
||||
那么可以定义$f$如下:
|
||||
$$
|
||||
f\colon \bigcup_{n\in \mathbb{N}} A_n \to \bigcup_{n\in \mathbb{N}} B_n, x \mapsto \begin{cases}
|
||||
f_1(x) , & x\in A_1 \\
|
||||
f_2(x) , & x\in A_2 \\
|
||||
\cdots , & \cdots \\
|
||||
f_n(x) , & x\in A_n \\
|
||||
\end{cases}
|
||||
$$
|
||||
|
||||
因为$\{ A_n\ |\ n\in \mathbb{N} \}$两两不相交,所以$f$是一个函数,下面证明$f$是一一对应的。
|
||||
|
||||
对于任意的$\displaystyle y \in \bigcup_{n\in \mathbb{N}} B_n$,由于$\{ B_n\ |\ n\in \mathbb{N} \}$两两不相交,则必定存在唯一的$ i \in \mathbb{N}$使得$y \in B_i$,而$f_i:A_i \to B_i$是一一对应的,所以必定存在唯一的$\displaystyle x\in A_i \subseteq \bigcup_{n\in \mathbb{N}} A_n$使得$f(x)=y$,因此$f$是一一对应的。
|
||||
|
||||
由于构造出了$\displaystyle \bigcup_{n\in \mathbb{N}} A_n$和$\displaystyle \bigcup_{n\in \mathbb{N}} B_i$之间的一一对应的函数,所以$\displaystyle \bigcup_{n\in \mathbb{N}} A_n \sim \bigcup_{n\in \mathbb{N}} B_n$。
|
||||
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
|
||||
\item 设$F$是$X$到$Y$的所有函数所组成的集合,$F=\{ f\ |\ f:X \to Y \}$,$\left\vert X \right\vert =n$。证明$F\sim Y^{n}$ \label{functioncardinality}。
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
|
||||
对于$\forall f \in F$,$f$都唯一对应于一个$\left\vert X \right\vert $行$\left\vert Y \right\vert $列的关系矩阵,并且每行有且仅有一个1。
|
||||
那么每一行这个1的位置有$\left\vert Y \right\vert $种情况,一共有$\left\vert X \right\vert $行,所以一共有$\left\vert Y \right\vert ^{\left\vert X \right\vert }=\left\vert Y \right\vert ^{n}$种情况。
|
||||
所以$\left\vert F \right\vert =\left\vert Y \right\vert ^{n}$。
|
||||
|
||||
$Y^{n}$表示集合的笛卡尔积,所以有$\left\vert Y \right\vert ^{n}=\left\vert Y^{n} \right\vert $。
|
||||
|
||||
所以$\left\vert F \right\vert =\left\vert Y \right\vert ^{n}=\left\vert Y^{n} \right\vert $,所以$F\sim Y^{n}$。
|
||||
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
|
||||
\item *证明无限可数集的所有有限子集组成一个可数集。
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
|
||||
设$A$为无限可数集,则$A$可以和$\mathbb{N}$一一对应,所以可以将$A$记为$\{ a_i\ |\ i\in \mathbb{N} \}$。
|
||||
|
||||
对于$\forall M \in \mathbb{N}$,取$B_{M}=\{ a_i\ |\ i\in \mathbb{N},i\leqslant M \}$,则$A$的所有有限子集可以记作
|
||||
$$
|
||||
\bigcup_{M\in \mathbb{N}} P(B_{M})
|
||||
$$
|
||||
|
||||
而对于$\forall M\in \mathbb{N}$,$a_{M+1} \not \in B_{M}$,$a_{M+1}\in B_{M+1}$,所以$\{ a_{M+1} \}\not \in P(B_{M})$,$\{ a_{M+1} \}\in P(B_{M+1})$,所以
|
||||
$$
|
||||
\bigcup_{1\leqslant m\leqslant M} P(B_{m}) \subsetneqq \bigcup_{1\leqslant m\leqslant M+1} P(B_{m})
|
||||
$$
|
||||
|
||||
所以对于有限集合$\displaystyle \bigcup_{1\leqslant m\leqslant M} P(B_{m})$和$\displaystyle \bigcup_{1\leqslant m\leqslant M+1} P(B_{m})$,有
|
||||
$$
|
||||
\left\vert \bigcup_{1\leqslant m\leqslant M} P(B_{m}) \right\vert +1\leqslant \left\vert \bigcup_{1\leqslant m\leqslant M+1} P(B_{m}) \right\vert
|
||||
$$
|
||||
|
||||
根据极限的定义可知
|
||||
$$
|
||||
\left\vert\bigcup_{M\in \mathbb{N}} P(B_{M})\right\vert=\left\vert\lim_{M \to \infty} \bigcup_{1\leqslant m\leqslant M} P(B_{m}) \right\vert \geqslant \lim_{M \to \infty}\left\vert \bigcup_{1\leqslant m\leqslant M} P(B_{m}) \right\vert =+\infty
|
||||
$$
|
||||
|
||||
所以A的所有有限子集$\displaystyle \bigcup_{n\in \mathbb{N}} P(B_{M})$是无限集,并且能找到$\mathbb{N}$到$\displaystyle \bigcup_{n\in \mathbb{N}} P(B_{M})$的映射,所以$\displaystyle \left\vert \bigcup_{n\in \mathbb{N}} P(B_{M}) \right\vert \leqslant $可数集的基数,并且$\displaystyle \left\vert \bigcup_{n\in \mathbb{N}} P(B_{M}) \right\vert \geqslant $可数集的基数。
|
||||
|
||||
所以A的所有有限子集$\displaystyle \bigcup_{n\in \mathbb{N}} P(B_{M})$是可数集。
|
||||
|
||||
即 无限可数集的所有有限子集组成一个可数集。
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\end{enumerate}
|
||||
|
||||
\section{不可解问题}
|
||||
\begin{enumerate}
|
||||
\item *设集合$F=\{ f\ |\ \mathbb{N} \to M \}$,其中$M$为正偶数集。证明:$F$中存在这样的函数$f$,计算$f$的C程序不存在。
|
||||
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
|
||||
由于C程序的集合是可数的,因此只需证明$F$为不可数集合。
|
||||
|
||||
根据 \ref{cardinality} 节的第 \ref{functioncardinality} 题可知,$
|
||||
\left\vert F \right\vert = \left\vert M \right\vert ^{\left\vert \mathbb{N} \right\vert }$,所以$F\sim \{ f\ |\ f:\mathbb{N} \to \mathbb{N} \}$,即$F$与问题集等势,所以$F$不可数。
|
||||
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\end{enumerate}
|
||||
\end{document}
|
101
离散数学/作业/第十二周作业.tex
Normal file
101
离散数学/作业/第十二周作业.tex
Normal file
@ -0,0 +1,101 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
|
||||
\pagestyle{fancyplain}
|
||||
\fancyhead{}
|
||||
\fancyhead[C]{\mysignature}
|
||||
\setcounter{chapter}{5}
|
||||
|
||||
\begin{document}
|
||||
\chapter{函数}
|
||||
\section{函数的概念和性质}
|
||||
\begin{enumerate}
|
||||
\item $f:X \to Y$。对任意$M \subseteq X$,定义$f(M)=\{ f(x)\ |\ x\in M \}$。对于任意$A,B \subseteq X$,
|
||||
\begin{enumerate}
|
||||
\item 证明$f(A\cup B)=f(A)\cup f(B)$;
|
||||
\begin{proof}
|
||||
|
||||
\begin{zhongwen}
|
||||
$\forall Z \in f(A\cup B)$,则$\exists x \in A\cup B$,使得$Z=f(x)$,因此$x\in A$或者$x\in B$。
|
||||
|
||||
若$x\in A$,则$Z\in f(A)$;若$x\in B$,则$Z\in f(B)$。
|
||||
|
||||
于是$Z\in f(A)\cup f(B)$。
|
||||
|
||||
所以$f(A\cup B) \subseteq f(A)\cup f(B)$。\label{1}
|
||||
|
||||
$\forall Z\in f(A)\cup f(B)$,则$Z\in f(A)$或$Z\in f(B)$。
|
||||
|
||||
若$Z\in f(A)$,则$\exists x \in A$,使得$Z=f(x)$,因此$x\in A\cup B$,所以$Z\in f(A\cup B)$。
|
||||
|
||||
所以$f(A)\cup f(B) \subseteq f(A\cup B)$。
|
||||
|
||||
所以$f(A\cup B)=f(A)\cup f(B)$。
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 举例说明$f(A\cap B)\neq f(A)\cap f(B)$。
|
||||
|
||||
\begin{zhongwen}
|
||||
若$f,A,B$定义如下:
|
||||
$$
|
||||
f\colon \mathbb{R} \to \mathbb{R}, x \mapsto x^{2}
|
||||
$$
|
||||
$$A=(-\infty, 0]\quad B=[0,+\infty)$$
|
||||
|
||||
则$f(A\cap B)=f(\{ 0 \})=\{ 0 \}$,$f(A)\cap f(B)=[0,+\infty)$,
|
||||
|
||||
则$f(A\cap B)\neq f(A)\cap f(B)$。
|
||||
\end{zhongwen}
|
||||
\end{enumerate}
|
||||
|
||||
\item $f:X \to Y$,下列命题是否成立?
|
||||
\begin{enumerate}
|
||||
\item $f$是一对一的当且仅当对任意$a,b \in X$,当$f(a)=f(b)$时,必有$a=b$。
|
||||
|
||||
\begin{zhongwen}
|
||||
成立,即一对一的定义的逆否命题。
|
||||
\end{zhongwen}
|
||||
\item $f$是一对一的当且仅当对任意$a,b \in X$,当$f(a)\neq f(b)$时,必有$a\neq b$。
|
||||
|
||||
\begin{zhongwen}
|
||||
不成立,取$X=\{ 1,2 \}$,$f(x)=\{ \{ 1,1 \},\{ 2,1 \} \}$。则$f$为$X$到$Y$的函数,且满足$\forall a,b \in X$,$f(a)\neq f(b) \Rightarrow a\neq b$,但$f$不是一对一的。
|
||||
\end{zhongwen}
|
||||
\end{enumerate}
|
||||
|
||||
\item 下图展示了五个关系的关系图。问:这些关系中,哪些是函数?哪些是一对一的函数?哪些是到上的函数?哪些是一一对应?\\
|
||||
\includegraphics[width=1\linewidth]{imgs/2023-12-04-06-31-00.png}
|
||||
|
||||
\begin{zhongwen}
|
||||
设从左到右分别为图1、2、3、4、5。
|
||||
|
||||
图1、2、3、4是函数;
|
||||
|
||||
图1、3是一对一的函数;
|
||||
|
||||
图2、3是到上的函数;
|
||||
|
||||
图3是一一对应的函数。
|
||||
\end{zhongwen}
|
||||
|
||||
\item $f:X \to Y$, $g:Y \to Z$。命题“$f \circ g$是一对一的当且仅当$f$和$g$都是一对一的”是否成立?
|
||||
|
||||
\begin{zhongwen}
|
||||
成立。
|
||||
|
||||
若$f$和$g$都是一对一的,则$f \circ g$是一对一的为定理6.1.2,现给出证明如下:
|
||||
|
||||
\begin{proof}
|
||||
|
||||
由$f$是一对一的可知$\forall a,b \in X$且$a\neq b$,有$f(a)\neq f(b)$,而$g$也是一对一的,所以$g(f(a))\neq g(f(b))$,即$f\circ g(a)\neq f\circ g(b)$,所以$f\circ g$是一对一的。
|
||||
|
||||
\end{proof}
|
||||
|
||||
下证若$f\circ g$是一对一的,则$f$和$g$都是一对一的。
|
||||
|
||||
\begin{proof}
|
||||
|
||||
反证,若$f$和$g$都不是一对一的,则$\exists a,b \in X$,使得$f(a)=f(b)$,因此$g(f(a))=g(f(b))$,即$f\circ g(a)=f\circ g(b)$,所以$f\circ g$也不是一对一的。
|
||||
|
||||
\end{proof}
|
||||
\end{zhongwen}
|
||||
\end{enumerate}
|
||||
\end{document}
|
192
离散数学/作业/第十五周作业.tex
Normal file
192
离散数学/作业/第十五周作业.tex
Normal file
@ -0,0 +1,192 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
|
||||
\pagestyle{fancyplain}
|
||||
\fancyhead{}
|
||||
\fancyhead[C]{\mysignature}
|
||||
\setcounter{chapter}{7}
|
||||
\setcounter{section}{2}
|
||||
|
||||
\begin{document}
|
||||
\section{图的连通性}
|
||||
\begin{enumerate}
|
||||
\item 设简单无向图$G=(V,E)$,若$\delta (G)\geqslant k (k\geqslant 1)$。请证明:$G$有长度为$k$的基本通路。
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
|
||||
使用数学归纳法,
|
||||
|
||||
由于$\delta (G)\geqslant k\geqslant 1$,所以$G$中存在边,从而$G$不是零图,因此必定有长度为1的基本通路。
|
||||
|
||||
假设$G$中存在长度为$m-1$的基本通路$\alpha $ $(m\leqslant k)$,则$\alpha $中的顶点总数为$m$(基本通路的顶点互不相同)。那么对于$\alpha $两端的其中一个端点$v$,$\alpha $去除$v$后的顶点总数为$m-1$。由于$d(v)\geqslant \delta (G)\geqslant k\geqslant m>m-1$,即$v$的度数大于$\alpha $中去除$v$后的顶点总数,所以与$v$相连的边中必定存在一条边$e$连接了不在$\alpha $中的顶点$v'$,于是将边$e$和顶点$v'$加入到$\alpha $中,就构成了长度为$m$的基本通路。
|
||||
|
||||
所以$\forall m \in \mathbb{N}, 1\leqslant m\leqslant k$,$G$有长度为$m$的基本通路。自然地,$G$有长度为$k$的基本通路。
|
||||
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
|
||||
\item 证明:若无向图$G$没有长度为奇数的基本回路,则$G$没有任何长度为奇数的回路。
|
||||
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
|
||||
证明原命题的逆否命题“若$G$中存在一条长度为奇数的回路,则$G$中必定存在长度为奇数的基本回路。”
|
||||
|
||||
若$G$中存在一条长度为奇数的回路$\alpha $,则可以设$\alpha =v_0e_1v_1e_2\cdots e_k v_k$,$\alpha $的长度$k$为奇数。若$\alpha $是基本回路,则$G$中存在长度为奇数的基本回路。
|
||||
|
||||
若$\alpha $不是基本回路,则其中存在相同的顶点,不妨设$v_i=v_j$, $0\leqslant i<j\leqslant k$,于是$\alpha $的子序列$v_i e_{i+1} v_{i+1} e_{i+2}\cdots e_j v_j$构成一个回路,记为$\alpha '$,并且从$\alpha $中删除$\alpha '$后(保留顶点$v_i$)仍然是一个回路,记为$\alpha ''$,并且$\alpha '$和$\alpha ''$的长度之和为原始回路$\alpha $的长度$k$。因为$k$为正奇数,所以将其拆分成两个正整数之和后其中必定有一个正整数为奇数,即$\alpha '$和$\alpha ''$中必定有一个长度为奇数。取这个长度为奇数的回路,记为$\alpha_1$,则可以对$\alpha_1$重复上述拆分回路的过程,得到长度为奇数的回路$\alpha_2, \cdots \cdots$。注意到$\alpha $的有限性,上述拆分回路的过程不可能无限进行,最后一次拆分过程结束后,所得到的回路就是长度为奇数的基本回路。
|
||||
|
||||
总之,$G$中必定存在长度为奇数的基本回路。
|
||||
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
|
||||
\item 证明:在任何无向图中,任何奇数度的顶点都有通路到某个其他的奇数度顶点。
|
||||
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
|
||||
对于任何一个无向图$G$,在其中任取一个奇数度的顶点$v$,使用反证法。
|
||||
|
||||
假设对于所有以$v$为一端的通路,通路的另一端的顶点都是偶数度的,那么将$v$与这些顶点以及与它们相连的边全部取出,即构成$G$的一个连通分量$G'$。在$G'$中,只有$v$是奇数度的,其它所有顶点都是偶数度的,那么$G'$的度数之和为奇数,不满足握手定理,因此这种情况不可能发生。
|
||||
|
||||
所以$v$必定有通路到某个其他的奇数度顶点。
|
||||
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
|
||||
\item 分别求出下列三个无向图的各个连通分量。
|
||||
\begin{center}
|
||||
\includegraphics[width=0.8\linewidth]{imgs/2023-12-24-08-27-46.png}
|
||||
\end{center}
|
||||
|
||||
\begin{proof}[解]
|
||||
|
||||
\begin{center}
|
||||
\includexopp[0.7]{7.3.4}
|
||||
\end{center}
|
||||
\end{proof}
|
||||
|
||||
\end{enumerate}
|
||||
|
||||
\section{最短通路和Dijkstra算法}
|
||||
\section{图着色}
|
||||
\begin{enumerate}
|
||||
\item 无向图的色数为1意味着什么?
|
||||
|
||||
\begin{zhongwen}
|
||||
图中不存在边。
|
||||
\end{zhongwen}
|
||||
|
||||
\item 一大学有5个专业委员会:物理、化学、数学、生物、计算机,6位院士:B、C、D、G、S、W。专业委员会由院士组成,物理委员会有院士:C、S和W,化学委员会有院士:C、D和W;数学委员会有院士:B、C、G和S;生物委员会有院士:B和G;计算机委员会有院士:D和G。每个专业委员会每周开一小时例会,所有成员都不能缺席。如果某院士同时是两个专业委员会的成员,那么这两个专业委员会的例会就不能安排在同一个时间。现要为这些例会安排时间,希望它们的时间尽可能集中。问最少需要几个开会时间?请给出一种安排。
|
||||
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
|
||||
首先将专业委员会和院士的关系整理成如下表格:
|
||||
|
||||
\begin{center}
|
||||
\begin{tabular}{cc} % tabular里用\centering会导致一直在编译停不下来
|
||||
\toprule
|
||||
专业委员会 & 院士\\
|
||||
\midrule
|
||||
物理&C、S、W\\
|
||||
化学&C、D、W\\
|
||||
数学&B、C、G、S\\
|
||||
生物&B、G\\
|
||||
计算机&D、G\\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\end{center}
|
||||
|
||||
之后根据“如果某院士同时是两个专业委员会的成员,那么这两个专业委员会的例会就不能安排在同一个时间”构造图,将专业委员会作为顶点,如果这两个专业委员会有相同的院士,那么就在这两个顶点之间连一条边,问题即可转化为图着色问题。于是构造出下方左图:
|
||||
|
||||
\begin{center}
|
||||
\includesvgpdf[0.45]{7.5.2.drawio}
|
||||
\hfill
|
||||
\includesvgpdf[0.45]{7.5.2-colour.drawio}
|
||||
\end{center}
|
||||
|
||||
设此图为$G$,由于存在$C_3$的结构,因此$\chi (G)\geqslant 3$,又因为此图不是完全图也不是奇圈,所以根据Brooks定理,$\chi (G)\leqslant \Delta (G)=4$。
|
||||
|
||||
那么尝试找到色数为3的着色方案,即上方右图。
|
||||
|
||||
因此最少需要3个开会时间,即物理和计算机同一时间开会,化学和生物同一时间开会,数学单独时间开会。
|
||||
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\end{enumerate}
|
||||
\pagebreak[1]
|
||||
|
||||
\section{图的同构}
|
||||
\begin{enumerate}
|
||||
\item 有3个顶点的不同构的简单无向图有多少个?
|
||||
|
||||
\begin{zhongwen}
|
||||
3个。(分别为一条边、两条边、三条边的情况)
|
||||
\end{zhongwen}
|
||||
|
||||
\item 证明:若无向图G不是连通图,则其补图必为连通图。
|
||||
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
|
||||
设$G$的补图为$G'$,下证$G'$是连通图。
|
||||
|
||||
在$G'$中任取两个顶点,若这两个顶点在$G$中不相邻,那么根据补图的定义,它们在$G'$中必定相邻,从而是连通的。
|
||||
|
||||
若这两个顶点(设为$v_1,v_2$)在$G$中相邻,即它们在$G$中是连通的,而$G$不是连通图,所以必定存在另一个顶点$v_3$,使得$v_1$与$v_3$不连通,$v_2$与$v_3$不连通,从而$v_1$与$v_3$不相邻,$v_2$与$v_3$不相邻。那么根据补图的定义,在$G'$中$v_1$与$v_3$相邻,$v_2$与$v_3$相邻,所以$v_1$与$v_2$在$G'$中连通。
|
||||
|
||||
所以在$G'$中任取两个顶点,它们都是连通的,因此$G'$是连通图。
|
||||
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\end{enumerate}
|
||||
|
||||
\chapter{具有特殊性质的图}
|
||||
\section{欧拉图}
|
||||
\begin{enumerate}
|
||||
\item 一房子的平面图如图。问能否从前门进去,最后从后门出去,走过所有的门且每扇门只经过一次?
|
||||
\begin{center}
|
||||
\includegraphics[width=0.3\linewidth]{imgs/2023-12-24-10-01-59.png}
|
||||
\end{center}
|
||||
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
|
||||
将每个房间作为一个顶点,如果两个房间之间有门,则在这两个房间之间连一条边,同时将前门外的空间也作为一个顶点,后门外的空间也作为一个顶点,则可以构造出图如下:
|
||||
|
||||
\begin{center}
|
||||
\includexopp[0.8]{8.1.1}
|
||||
\end{center}
|
||||
|
||||
对于该图,只有前门外的顶点和后门外的顶点度数为1,是奇数,其它顶点的度数都是偶数,因此存在从前门外顶点到后门外顶点的欧拉通路,因为门与图中的边对应,所以能从前门进去,最后从后门出去,走过所有的门且每扇门只经过一次。
|
||||
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
|
||||
\item 对于有16个扇区和4个探测器的磁鼓,给出一种合理的0-1赋值。
|
||||
|
||||
\begin{zhongwen}
|
||||
% 虽然可以借助欧拉图来做,但是比较复杂,这里使用一个比较简便的方法。
|
||||
\begin{proof}[解]
|
||||
|
||||
% 首先,4个探测器探测出的0-1序列最多有$2^{4}=16$种情况,也即4位二进制串的数量。要区分16个扇区,则必定这16种情况要和16个扇区一一对应,也即每个4位二进制串都对应了一个扇区。因此必定有一个扇区与1111对应,也有一个扇区与0000对应,好吧这样还是很麻烦,还是用欧拉图来做吧。
|
||||
|
||||
以所有的3位二进制串为顶点,对于两个二进制串,如果前一个二进制串的后2位等于后一个二进制串的前2位,则从前一个二进制串到后一个二进制串连一条有向边。可以构造出图如下:
|
||||
|
||||
\begin{center}
|
||||
\includesvgpdf[0.5]{8.1.2.drawio}
|
||||
\end{center}
|
||||
|
||||
值得注意的是,上图也可以看成是数字逻辑电路中3位移位寄存器的状态转换图。
|
||||
|
||||
% 在上图中寻找到一条欧拉回路:$000\to 001\to 010\to 101\to 011\to 111\to 110\to 100\to 000$,这个好像是经过了所有顶点但没有经过所有的边?那个把图中的所有顶点换成边,所有边换成顶点的操作叫什么?好像这样操作之后就是欧拉通路,而且是3位的欧拉通路,但是这个本来能解决4位的问题转换后只能解决3位了,感觉好像和米利模型、摩尔模型也有关系,因为米利模型比摩尔模型可以用更少的状态。
|
||||
|
||||
在上图中寻找到一条欧拉回路:$110\to 100\to 000\to 000\to 001\to 011\to 111\to 111\to 110\to 101\to 010\to 100\to 001\to 010\to 101\to 011\to 110 $。
|
||||
|
||||
依次选取这条欧拉回路所经过的每个节点(终点除外)的最后一位,则可得到一个满足要求的0-1赋值为$0000111101001011$。
|
||||
|
||||
\end{proof}
|
||||
\end{zhongwen}
|
||||
\end{enumerate}
|
||||
\end{document}
|
67
离散数学/作业/第十六周作业.tex
Normal file
67
离散数学/作业/第十六周作业.tex
Normal file
@ -0,0 +1,67 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
|
||||
\pagestyle{fancyplain}
|
||||
\fancyhead{}
|
||||
\fancyhead[C]{\mysignature}
|
||||
\setcounter{chapter}{8}
|
||||
\setcounter{section}{1}
|
||||
|
||||
\begin{document}
|
||||
\section{哈密顿图}
|
||||
\begin{enumerate}
|
||||
\item 说明下图不是哈密顿图。
|
||||
\begin{center}
|
||||
\includegraphics[width=0.3\linewidth]{imgs/2023-12-30-09-42-18.png}
|
||||
\end{center}
|
||||
|
||||
\begin{zhongwen}
|
||||
由于在此图中找不到哈密顿回路,所以此图不是哈密顿图。
|
||||
\end{zhongwen}
|
||||
\item *证明任意竞赛图都有有向哈密顿通路。
|
||||
|
||||
\begin{zhongwen}
|
||||
不会。
|
||||
\end{zhongwen}
|
||||
\item 为了测试计算机网络上的所有连接和设备,可以在网络上发一个诊断消息。为了测试所有的连接,应当使用什么种类的通路?为了测试所有的设备呢?
|
||||
|
||||
\begin{zhongwen}
|
||||
为了测试所有的连接,应当使用欧拉通路;为了测试所有的设备,应当使用哈密顿通路。
|
||||
\end{zhongwen}
|
||||
\end{enumerate}
|
||||
|
||||
\section{平面图}
|
||||
\begin{enumerate}
|
||||
\item 设简单连通图$G$有$n$个顶点、$e$条边。若$G$是平面图,请证明:$e\leqslant 3n-6$。\label{question:1}
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
|
||||
因为$G$是简单图,所以其面的次数都不小于3,根据欧拉公式的推论,有
|
||||
$$
|
||||
e\leqslant \frac{3}{3-2}\times (n-2)=3n-6
|
||||
$$
|
||||
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
|
||||
\item 若简单连通图$G$有$n$个顶点、$e$条边,则$G$的厚度至少为$\left\lceil e/(3n-6) \right\rceil $。(简单图$G$的厚度是指$G$的平面子图的最小个数,这些子图的并是$G$。)
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
|
||||
设$G$的厚度为$m$,则可以将$G$看做$m$个平面子图的并,将这些平面子图设为$G_1,G_2, \ldots G_m$,则$ G=\bigcup_{i=1}^{m} G_i$。对$\forall i=1,2, \ldots , m$,设$G_i$的顶点数为$n_i$,边数为$e_i$。则根据第 \ref{question:1} 题,有$0<e_i\leqslant 3 n_i - 6$,所以
|
||||
$$
|
||||
\forall i=1,2, \ldots ,m, \quad e_i\leqslant 3 n_i-6\leqslant 3n-6
|
||||
$$
|
||||
对不等式进行求和可得
|
||||
$$
|
||||
e \leqslant \sum_{i=1}^{m}e_i \leqslant \sum_{i=1}^{m}(3n-6)=m(3n-6)
|
||||
$$
|
||||
所以有
|
||||
$$
|
||||
m\geqslant \frac{e}{3n-6}
|
||||
$$
|
||||
注意到$G$的厚度$m$为整数,所以$G$的厚度至少为$\left\lceil e/(3n-6) \right\rceil $。
|
||||
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\end{enumerate}
|
||||
\end{document}
|
205
离散数学/作业/第十周作业.tex
Normal file
205
离散数学/作业/第十周作业.tex
Normal file
@ -0,0 +1,205 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
|
||||
\pagestyle{fancyplain}
|
||||
\fancyhead{}
|
||||
\fancyhead[C]{\mysignature}
|
||||
\setcounter{chapter}{5}
|
||||
\setcounter{section}{3}
|
||||
|
||||
\begin{document}
|
||||
\section{等价关系和划分}
|
||||
\begin{enumerate}
|
||||
\item 设X是所有人组成的集合,如下定义的关系哪些是X上的等价关系?
|
||||
\begin{enumerate}[rightmargin=\linewidth/3]
|
||||
\item $\{ \left. (a,b) \right|\text{a是b的兄弟} \}$\hfill 不是
|
||||
\item $\{ \left. (a,b) \right|\text{a与b的年龄相差不超过3岁} \}$\hfill 不是
|
||||
\item $\{ \left. (a,b) \right|\text{a和b有相同的祖父} \}$\hfill 是
|
||||
\item $\{ \left. (a,b) \right|\text{a与b相识} \}$\hfill 不是
|
||||
\item $\{ \left. (a,b) \right|\text{a与b会说同一种语言} \}$\hfill 是
|
||||
\end{enumerate}
|
||||
\item 若$R_1$和$R_2$是$X$上的等价关系,则$X^{2}-R_1$、$R_1-R_2$、$R_1^{2}$、$t(R_1\cup R_2)$是否也都是$X$上的等价关系?为什么?
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\because \forall x \in X, (x,x)\in R_1 \quad \therefore (x,x)\not \in X^{2}-R_1 \quad\therefore X^{2}-R_1不是X上的等价关系;\\
|
||||
\\
|
||||
&\because X^{2}是X上的等价关系 \quad \therefore 若取R_1=X^{2},则R_1-R_2不是X上的等价关系; \\
|
||||
&若取R_2=\varnothing ,则R_1-R_2是X上的等价关系; \\
|
||||
&\therefore R_1-R_2不一定是X上的等价关系 \\
|
||||
\\
|
||||
&R_1^{2}=R_1,是X上的等价关系 \\
|
||||
\\
|
||||
&\forall x\in X,(x,x)\in R_1 \subseteq R_1\cup R_2\subseteq t(R_1\cup R_2) \quad\therefore t(R_1\cup R_2)是自反关系\\
|
||||
&由上一节的例题可知,对称关系的并也是对称关系,对称关系的传递闭包也是对称关系\\
|
||||
&\therefore t(R_1\cup R_2)是对称关系 \\
|
||||
&t(R_1\cup R_2)是传递闭包,所以是传递关系 \\
|
||||
&因此,t(R_1\cup R_2)是X上的等价关系 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 设$X=\{ \left. (x,y) \right|\text{x和y是不为零的实数} \}$,$E$是$X$上的关系:$(x_1,y_1)E(x_2,y_2)$当且仅当$\displaystyle \frac{y_1}{x_1}=\frac{y_2}{x_2}$且$x_1\cdot x_2>0$。
|
||||
证明$E$是$X$上的等价关系,并给出$[(x,y)]_{E}$的几何解释。
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\forall (x,y)\in X,则x \neq 0,y\neq 0\quad\therefore x\cdot x=x^{2}>0,\frac{y}{x}=\frac{y}{x} \quad \therefore (x,y)E(x,y),即E是自反关系 \\
|
||||
&\forall ((x_1,y_1),(x_2,y_2))\in E,即x_1\cdot x_2>0,\frac{y_1}{x_1}=\frac{y_2}{x_2},则x_2\cdot x_1>0,\frac{y_2}{x_2}=\frac{y_1}{x_1} \\
|
||||
&\therefore ((x_2,y_2),(x_1,y_1))\in E,即 E是对称关系 \\
|
||||
&\forall ((x_1,y_1),(x_2,y_2)),((x_2,y_2),(x_3,y_3))\in E,即x_1\cdot x_2>0,x_2\cdot x_3>0,\frac{y_1}{x_1}=\frac{y_2}{x_2},\frac{y_2}{x_2}=\frac{y_3}{x_3}\\
|
||||
&\therefore x_1\cdot x_3>0,\frac{y_1}{x_1}=\frac{y_3}{x_3}\quad \therefore ((x_1,y_1),(x_3,y_3))\in E,即E是传递关系 \\
|
||||
&\therefore E是X上的等价关系 \\
|
||||
&[(x,y)]_{E}表示从原点出发并经过(x,y)的某一条射线去除原点 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 下面哪些$\mathbb{Z}$的子集簇构成$\mathbb{Z}$的划分?为什么?
|
||||
\begin{enumerate}
|
||||
\item \{偶数集,奇数集\}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&构成,令\pi =\{ 偶数集,奇数集 \},则偶数集\neq \varnothing ,奇数集\neq \varnothing \\
|
||||
&偶数集\cap 奇数集=\varnothing,\quad 偶数集\cup 奇数集=\mathbb{Z} \\
|
||||
&\therefore \{ 偶数集,奇数集 \}构成\mathbb{Z}的划分 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\item \{正整数集,负整数集\}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
不构成,\because 0\in \mathbb{Z},但0\not \in 正整数集\cup 负整数集,即正整数集\cup 负整数集\neq \mathbb{Z}
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\item \{能被3整除的整数的集合,被3除余数为1的整数的集合,被3除余数为2的整数的集合\}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
构成,因为任何一个整数除以3的余数只能是0或1或2.
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\item \{小于-100的整数的集合,绝对值不超过100的整数的集合,大于100的整数的集合\}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
构成,任何一个整数必然在且只在这三个集合中的某一个集合中。
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\item \{不能被3整除的整数的集合,偶数集合,被6除余数为3的整数的集合\}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&不构成,\because 2\in 不能被3整除的整数的集合\cap 偶数集合, \\
|
||||
&即 不能被3整除的整数的集合\cap 偶数集合\neq \varnothing \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{enumerate}
|
||||
\end{enumerate}
|
||||
\section{偏序关系}
|
||||
\begin{enumerate}
|
||||
\item 下列集合关于整除关系$|$构成偏序集。请分别画出它们的哈斯图,判断它们是否是全序集,给出它们的极大元、极小元、最大元、最小元。
|
||||
\begin{multicols}{2}
|
||||
\begin{enumerate}
|
||||
\item $\{ 2,4,8,16 \}$;
|
||||
|
||||
% \centering
|
||||
% \includegraphics[1\linewidth]{imgs/5.5.1.drawio.png}
|
||||
\hspace{5em}\includesvgpdf[0.1]{5.5.1.drawio}
|
||||
|
||||
极大元:16,极小元:2;\\
|
||||
最大元:16,最小元:2。
|
||||
|
||||
\item $\{ 2,3,4,5,9,10,80 \}$。
|
||||
|
||||
\includesvgpdf[0.8]{5.5.2.drawio}
|
||||
|
||||
极大元:80、9,极小元:2、5、3;\\
|
||||
最大元:无,最小元:无。
|
||||
\end{enumerate}
|
||||
\end{multicols}
|
||||
\pagebreak[2]
|
||||
\item 证明:
|
||||
\begin{enumerate}
|
||||
\item 偏序集的最小元也必定是其极小元;
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&对于任意的偏序集(X,\leqslant ),若a\in X是它的最小元,取个体域为X\\
|
||||
&则\forall x(a\leqslant x) \\
|
||||
&\because 偏序关系具有反对称性, \\
|
||||
&\therefore \forall x((x=a)\lor \lnot (x\leqslant a)) \\
|
||||
&\therefore \forall x(\lnot (x\neq a\land x\leqslant a)) \\
|
||||
&\therefore \lnot \exists x(x<a) \\
|
||||
&\therefore a是(X,\leqslant )的极小元 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 任意全序集至多只有一个极小元,即全序集的极小元是唯一的。
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&对于任意的全序集(X,\leqslant ),假设a,b \in X都是它的极小元,取个体域为X \\
|
||||
&则\lnot \exists x(x<a)\land \lnot \exists y(y<b) \\
|
||||
&\therefore \forall x(\lnot (x<a))\land \forall y(\lnot (y<b)) \\
|
||||
&\therefore \lnot (b<a)\land \lnot (a<b) \\
|
||||
&\because (X,\leqslant )是全序集 \\
|
||||
&\therefore a\leqslant b\land b\leqslant a \\
|
||||
&\therefore a=b \\
|
||||
&因此,全序集的极小元是唯一的。 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\end{enumerate}
|
||||
\item 设$R$是$X$上自反、传递的关系,$S=R\cap R^{-1}$。
|
||||
\begin{enumerate}
|
||||
\item 证明$S$是$X$上的等价关系。
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\forall x\in X,(x,x)\in R\quad \therefore (x,x)\in R^{-1}\quad \therefore (x,x)\in R\cap R^{-1}=S,即S是自反关系 \\
|
||||
&\forall (x,y)\in S,即(x,y)\in R\land (x,y)\in R^{-1}\quad \therefore (y,x)\in R^{-1}\land (y,x)\in R\\
|
||||
&\therefore (y,x)\in R\cap R^{-1}=S,即S是对称关系\\
|
||||
&\forall (x,y),(y,z)\in S,即(x,y)\in R\land (x,y)\in R^{-1}\land (y,z)\in R\land (y,z)\in R^{-1} \\
|
||||
&\therefore (x,y)\in R\land (y,z)\in R,\quad (y,x)\in R\land (z,y)\in R \\
|
||||
&\therefore (x,z)\in R,(z,x)\in R \\
|
||||
&\therefore (x,z)\in R,(x,z)\in R^{-1},即(x,z)\in R\cap R^{-1}=S,即S是传递关系 \\
|
||||
&因此,S是X上的等价关系。 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 在$X/S$上定义关系$T: ([x]_{S},[y]_{S})\in T$当且仅当$(x,y)\in R$。证明$T$是$X/S$上的偏序关系。
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\forall [x]_{S}\in X/S,则x\in X\quad \because R是X上的自反关系\quad \therefore (x,x)\in R\\
|
||||
&\therefore ([x]_{S},[x]_{S})\in T,即T是自反关系 \\
|
||||
&\forall ([x]_{S},[y]_{S})\in T,即(x,y)\in R,若[x]_{S}\neq [y]_{S},则(x,y)\not \in S \\
|
||||
&\therefore (x,y)\not \in R\lor (x,y)\not \in R^{-1} \\
|
||||
&\because (x,y)\in R\quad \therefore (x,y)\not \in R^{-1} \quad \therefore (y,x)\not \in R\\
|
||||
&\therefore ([y]_{S},[x]_{S})\not \in T,即T是反对称关系 \\
|
||||
&\forall ([x]_{S},[y]_{S}),([y]_{S},[z]_{S})\in T,即(x,y)\in R,(y,z)\in R\\
|
||||
&\because R是X上的传递关系\quad \therefore (x,z)\in R \\
|
||||
&\therefore ([x]_{S},[z]_{S})\in T,即T是传递关系 \\
|
||||
&因此,T是X/S上的偏序关系。 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\end{enumerate}
|
||||
\end{enumerate}
|
||||
\end{document}
|
93
离散数学/作业/第十四周作业.tex
Normal file
93
离散数学/作业/第十四周作业.tex
Normal file
@ -0,0 +1,93 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
|
||||
\pagestyle{fancyplain}
|
||||
\fancyhead{}
|
||||
\fancyhead[C]{\mysignature}
|
||||
\setcounter{chapter}{6}
|
||||
|
||||
\begin{document}
|
||||
\chapter{图论基础}
|
||||
\section{图及其表示}
|
||||
\begin{enumerate}
|
||||
\item 6个学生:Alice、Bob、Carol、Dean、Santos和tom,其中,Alice和Carol不和,Dean和Carol不和,Santos、Tom和Alice两两不和。请给出表示这种情形的图模型。
|
||||
|
||||
\begin{zhongwen}
|
||||
用顶点表示学生,如果两个学生之间不和则连一条无向边,则可以表示成左图;如果两个学生相和则连一条无向边,则可以表示成右图。
|
||||
|
||||
\begin{figure}[H]
|
||||
\centering
|
||||
\subfloat[不和图]{
|
||||
\includesvgpdf[0.4]{7.1.1.drawio}
|
||||
}
|
||||
\hfill
|
||||
\subfloat[相和图]{
|
||||
\includesvgpdf[0.4]{7.1.2.drawio}
|
||||
}
|
||||
\end{figure}
|
||||
\end{zhongwen}
|
||||
|
||||
\item 至少含一个顶点的$C_3$的子图有多少个?
|
||||
|
||||
\begin{zhongwen}
|
||||
\begin{proof}[解]
|
||||
|
||||
含一个顶点的,点的情况有$\mathrm{C}_{3}^{1}=3$种,无法形成边,所以有$3\times 1=3$种情况;
|
||||
|
||||
含两个顶点的,点的情况有$\mathrm{C}_{3}^{2}=3$种,可以没有边或者有1条边,所以有$3\times 2=6$种情况;
|
||||
|
||||
含3个顶点的,点的情况有$\mathrm{C}_{3}^{3}=1$种,边的情况为$2^{3}$种,所以有$1\times 2^{3}=8$种情况。
|
||||
|
||||
所以至少含一个顶点的$C_3$的子图有$3+6+8=17$个。
|
||||
|
||||
\end{proof}
|
||||
\end{zhongwen}
|
||||
|
||||
\item 证明:在顶点个数不小于2的简单无向图中,必有度数相同的顶点。
|
||||
|
||||
\begin{zhongwen}
|
||||
\begin{proof}
|
||||
|
||||
使用归纳法,首先,对于顶点数为2的简单无向图,这两个顶点之间要么有一条边要么没有边,而这两种情况它们的度都是相同的。
|
||||
|
||||
假设对于顶点数为$k(k\geqslant 2)$的简单无向图,必有度数相同的顶点。那么对于顶点数为$k+1$的简单无向图,如果存在一个顶点的度为0,那么去除这个顶点后其他顶点构成$k$个顶点的简单无向图,因此它们之中必有度数相同的顶点。
|
||||
|
||||
如果不存在一个顶点的度数为0,即所有顶点的度数都至少为1,之后就不会了。
|
||||
|
||||
\end{proof}
|
||||
\end{zhongwen}
|
||||
|
||||
\item 对哪些n值来说下列图是偶图?
|
||||
\begin{tasks}[](2)
|
||||
\task $K_n$
|
||||
\hfill $n = 2$ \hfill
|
||||
\task $C_n$
|
||||
\hfill $n\geqslant 3$且为偶数 \hfill
|
||||
\task $W_n$
|
||||
\hfill $n\in \varnothing $ \hfill
|
||||
\task $Q_n$
|
||||
\hfill $n$为任意正整数 \hfill
|
||||
\end{tasks}
|
||||
\end{enumerate}
|
||||
|
||||
\section{握手定理}
|
||||
\begin{enumerate}
|
||||
\item 简单无向图$G$有$n$个顶点,$n+1$条边,证明$G$中至少有一个顶点的度大于或等于3。
|
||||
\begin{zhongwen}
|
||||
\begin{proof}
|
||||
|
||||
反证法,设$G=(V,E)$,假设$G$中所有顶点的度都小于3,即$\forall v\in V$, $d(v)<3$即$d(v)\leqslant 2$,又已知$\left\vert V \right\vert =n$, $\left\vert E \right\vert =n+1$,那么根据握手定理,则有
|
||||
$$
|
||||
2(n+1)=2\left\vert E \right\vert =\sum_{v\in V}d(v)\leqslant 2n
|
||||
$$
|
||||
而这是不可能的,因此$G$中至少有一个顶点的度大于或等于3。
|
||||
|
||||
\end{proof}
|
||||
\end{zhongwen}
|
||||
\item *一天晚上张先生夫妇参加了一个聚会,参加聚会的人中还有另外三对夫妇,他们相互握了手。假设没有人自己与自己握手,没有夫妻之间的握手,且同两个人握手不超过一次。当其他人告诉张先生,他或她握了多少次手时,答案都不相同。问张先生和太太分别握了几次手?
|
||||
|
||||
\begin{zhongwen}
|
||||
想了半天也想不出来怎么做。
|
||||
\end{zhongwen}
|
||||
|
||||
\end{enumerate}
|
||||
\end{document}
|
80
离散数学/作业/第四周作业.tex
Normal file
80
离散数学/作业/第四周作业.tex
Normal file
@ -0,0 +1,80 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
\pagestyle{fancyplain}
|
||||
\fancyhead{}
|
||||
\fancyhead[C]{\mysignature}
|
||||
\setcounter{chapter}{3}
|
||||
\setcounter{section}{2}
|
||||
|
||||
\begin{document}
|
||||
\section{范式和联结词的功能完备集}
|
||||
\begin{enumerate}
|
||||
\item 通过等值演算求$p \to (p\land (q \to p))$的主析取范式和主合取范式。
|
||||
\begin{proof}[解]
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
p \to (p \land (q \to p))&=\lnot p\lor (p\land (\lnot q\lor p))=\lnot p\lor ((p\lor 0)\land (p\lor \lnot q)) \\
|
||||
&=\lnot p \lor (p\lor (0 \land \lnot q)) = \lnot p \lor p = 1 \\
|
||||
&=(p\land q)\lor (p\land \lnot q)\lor (\lnot p\land q)\lor (\lnot p\land \lnot q) \qquad (主析取范式)\\
|
||||
\end{aligned}
|
||||
$$
|
||||
$$
|
||||
因为原式为永真式,所以无主合取范式。
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 证明$\{ \lnot ,\to \}$是功能完备集。
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
&\lnot p=\lnot p \\
|
||||
&p\lor q=\lnot p \to q \\
|
||||
&\because \{ \lnot ,\lor \}是功能完备集 \\
|
||||
&\therefore \{ \lnot ,\to \}是功能完备集 \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\end{enumerate}
|
||||
\section{命题逻辑的推理理论}
|
||||
\begin{enumerate}
|
||||
\item 证明$p \to (q \to s),q,p\lor \lnot r \Rightarrow r \to s$。
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
\begin{enumerate}[label=\mycircle{\arabic{enumii}},leftmargin=\linewidth/4,rightmargin=\linewidth/4]
|
||||
\item $r$\hfill 附加前提引入
|
||||
\item $p\lor \lnot r$ \hfill 前提引入
|
||||
\item $p$\hfill \mycircle{1}\mycircle{2}析取三段论
|
||||
\item $p \to (q \to s)$\hfill 前提引入
|
||||
\item $q \to s$\hfill \mycircle{3}\mycircle{4}假言推理
|
||||
\item $q$ \hfill 前提引入
|
||||
\item $s$ \hfill \mycircle{5}\mycircle{6}假言推理
|
||||
\end{enumerate}
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\item 构造下列推理的形式证明:
|
||||
“今天下午没有出太阳并且今天比昨天冷。只有今天下午出太阳,我们才去游泳。若我们不去游泳,则我们乘独木舟游览。若我们乘独木舟游览,则我们在黄昏时回家。 所以,我们在黄昏时回家。”
|
||||
\begin{proof}
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
\begin{aligned}
|
||||
令&p:今天下午出太阳,q:今天比昨天冷,r:我们去游泳, \\
|
||||
&s:我们乘独木舟游览,t:我们在黄昏时回家 \\
|
||||
&则需要证明:\lnot p \land q,r \to p,\lnot r \to s, s \to t \Rightarrow t \\
|
||||
\end{aligned}
|
||||
$$
|
||||
\begin{enumerate}[label=\mycircle{\arabic{enumii}},leftmargin=\linewidth/4,rightmargin=\linewidth/4]
|
||||
\item $\lnot p\land q$\hfill 前提引入
|
||||
\item $\lnot p$\hfill \mycircle{1}化简
|
||||
\item $r \to p$\hfill 前提引入
|
||||
\item $\lnot r$\hfill \mycircle{2}\mycircle{3}拒取式
|
||||
\item $\lnot r \to s$\hfill 前提引入
|
||||
\item $s$\hfill \mycircle{4}\mycircle{5}假言推理
|
||||
\item $s \to t$\hfill 前提引入
|
||||
\item $t$\hfill \mycircle{6}\mycircle{7}假言推理
|
||||
\end{enumerate}
|
||||
\end{zhongwen}
|
||||
\end{proof}
|
||||
\end{enumerate}
|
||||
\end{document}
|
316
离散数学/作业/课程项目.tex
Normal file
316
离散数学/作业/课程项目.tex
Normal file
@ -0,0 +1,316 @@
|
||||
\documentclass[全部作业]{subfiles}
|
||||
\usepackage{titlesec} % 只在这个文件里的序言里用到了\titlelabel
|
||||
\usepackage{titletoc}
|
||||
|
||||
\pagestyle{fancyplain}
|
||||
\fancyhead{}
|
||||
\fancyhead[C]{\mysignature}
|
||||
% \titlelabel{\thechapter}
|
||||
% \renewcommand{\section}{\section*}
|
||||
\titlelabel{} % 去除序号,但是在主文件中不去除
|
||||
% \titleformat{\section}{}{}{0pt}{} % 去除section的序号但是不去除别的
|
||||
|
||||
\begin{document}
|
||||
% appendices环境设置的服务好像还是用了“第一章”
|
||||
% 因此使用\appendix命令,但是放到主文件里
|
||||
|
||||
\section{课程项目——函数式程序设计及其发展历史和研究现状综述}
|
||||
\ifSubfilesClassLoaded{
|
||||
\ctexset{section/numbering = false,
|
||||
subsection/numbering = false,
|
||||
subsection/format += \centering,
|
||||
subsubsection/numbering = false,
|
||||
secnumdepth = 0,
|
||||
tocdepth = 3,
|
||||
}
|
||||
% \titlecontents*{lsubsection}[0pt]
|
||||
% {\small\itshape}{}{}
|
||||
% {}[ \textbullet\ ][.]
|
||||
% \titlecontents{subsection}[0pt]{}{}{}{}[]
|
||||
% \contentspush{12}
|
||||
% \setcounter{tocdepth}{3}
|
||||
\subsection{目录}
|
||||
\startcontents
|
||||
% \tableofcontents
|
||||
\printcontents{l}{2}[3]{}
|
||||
}{}
|
||||
|
||||
\subsection{摘要}
|
||||
本文没有过多晦涩难懂的理论知识,例如函数式程序设计中的Monad、范畴等概念,也没有冗长的介绍发展历史,而是更多从实际使用的角度,讲述函数式程序设计在实际业务场景中如何使用。
|
||||
\subsection{发展历史}
|
||||
首先,让我们看一下函数式程序设计的定义。以下内容在维基百科(The Free Dictionary网站)中找到,这里认为“函数式程序设计”和“函数式编程”同义。
|
||||
|
||||
在计算机科学中,函数式编程是一种编程范式,其中程序是通过应用和组合函数来构造的。它是一种声明性编程范例,其中函数定义是将值映射到其他值的表达式树,而不是一系列命令式语句 更新 程序的运行状态 。\cite{wikidefination}
|
||||
|
||||
那么函数式程序设计的历史可以追溯到$\lambda $演算\cite{zhihuJS1},并且发展出了很多函数式编程语言,这里就不详细展开了。
|
||||
|
||||
\subsection{研究现状}
|
||||
要真正搞懂函数式程序设计,我们先要明白什么是状态。以及状态和逻辑如何分离。
|
||||
|
||||
我们知道,程序是由输入、处理、输出组成。那么有一个直接的问题是我每次使用这个程序,并且给定相同的输入,是否都能得到同样的输出呢?如果只是从算法题(OJ, Online Judge)的角度看,那确实是这样。
|
||||
|
||||
我们遇到的算法题总是给你一些输入,让你输出某个结果,就像课程项目中的一部分题:“输入……,输出……”,这种题目的直观感受就是给定一个输入,那么必定会产生某个输出(甚至有时候只有唯一的正确输出)。
|
||||
|
||||
但是脱离算法题的框架呢?比如我要实现读取好几个文件的内容,之后把他们拼接起来放到一个新的文件里。这样的情况是不是就没有输入了?那文件不同,得到的输出结果也不同了。这就是一种典型的文件IO(输入输出)操作。
|
||||
|
||||
再举个例子,之前的数据结构课上的作业,要实现模拟队列动态变化,这个的输出又是什么呢?可以看到这个的输出其实是有时间维度的,在每个时间都应该输出不同的内容。因此这很难用无状态的方式来输出。那这个例子再扩展出去就是图形用户界面(GUI)了,这就是典型的输出不仅和状态有关,还和当前时刻的输入有关(也就类似数字逻辑及实验中的米利模型的有限状态机)。
|
||||
|
||||
因此,根据个人的理解,状态就是除了代码之外的,会影响程序的行为的东西。那么与之相对的,代码体现的就是程序的逻辑。因此,数据库、文件、外部服务,都可以看作是状态。
|
||||
|
||||
搞清楚了状态,我们接下来考虑为什么要分离状态和逻辑?主要的原因是为了便于备份和迁移。让我们先看一个例子:
|
||||
|
||||
假设有需求要请求一个网址并且把响应保存到本地。那么自然的写法可能是这样(用Python举例):
|
||||
|
||||
\begin{minted}{python}
|
||||
import requests
|
||||
url = input("请输入网址")
|
||||
filename = input("请输入文件名")
|
||||
res = requests.get(url)
|
||||
with open(filename, "wb") as f:
|
||||
f.write(res.content)
|
||||
\end{minted}
|
||||
|
||||
但考虑如果要多次使用这个功能,那么每次使用,都会将响应保存到运行的工作目录下,而如果每次都在代码文件所在的目录下运行,那么时间长了,就会在这个目录里产生很多下载的文件,看起来非常杂乱。
|
||||
|
||||
假设在之后的某一天,我们想把这个功能的源代码加入版本控制中,并且放到开源平台,但又不想把下载的响应文件一起公开,那么还需要添加到忽略列表等操作。
|
||||
|
||||
又过了一段时间,需要备份这些下载的响应内容,那么只能把整个目录连带代码文件一起备份,但是代码已经使用版本控制进行管理了,再进行备份只能备份当前版本,这就非常冗余。
|
||||
|
||||
但是,如果将状态和逻辑进行了分离,也就是把响应全部放到同一个位置,和代码逻辑分离开,这样在备份和迁移的时候都非常方便,而这就需要用到函数式程序设计了。
|
||||
|
||||
接下来我们结合几个实际的应用场景来具体讲解函数式程序设计如何使用。
|
||||
|
||||
\subsubsection{Serverless}
|
||||
目前,Serverless架构也算是一个比较活跃的话题,它主要是将静态的页面文件和动态的请求分离开,静态页面由云服务器的存储实现,并且还能方便实现CDN(内容分发网络)加速;而动态的请求也可以由云厂商提供的事件驱动的函数计算服务来实现,当收到请求后进行函数计算并返回结果给前端,这里就把整个应用拆分成了各个函数,因此需要用到函数式程序设计。
|
||||
|
||||
\subsubsection{数据预处理}
|
||||
在深度学习的任务中,经常需要对数据进行预处理,而这些预处理可能分成很多步骤,并且有时候还需要把中间结果保存下载作为状态,以便下次使用时继续执行。比如自然语言处理的预处理可能就有分词、转词表、词嵌入。当数据量非常大的时候,如果中间某一步由于意外原因中断了,这时如果没有保存中间结果,那只能重新运行,这是非常浪费时间的。但是要保存中间结果就不可避免地要涉及到状态的存储。这时如果使用面向对象的方式,会是什么样的?
|
||||
\begin{minted}{python}
|
||||
class PreProcessing:
|
||||
def tokenize(self, text):
|
||||
...
|
||||
with open(self.token_path, "w") as f:
|
||||
f.write(result)
|
||||
return result
|
||||
|
||||
def token_to_id(self, tokens):
|
||||
...
|
||||
with open(self.id_path, "w") as f:
|
||||
for id_ in ids:
|
||||
print(id_, file=f)
|
||||
return ids
|
||||
|
||||
def id_to_embedding(self, ids):
|
||||
...
|
||||
paddle.save(embeddings, self.embedding_path)
|
||||
return embeddings
|
||||
|
||||
\end{minted}
|
||||
|
||||
这样会产生一个问题,每一个流程如何向下一个流程传递数据?直接通过函数的返回值传递?还是通过文件读取和写入来传递?直接通过函数的返回值传递的话,那怎么实现接续上次的运行结果?那还需要再单独写读取的方法?这样就会导致调用时非常麻烦。那如果全部使用文件的读取和写入,也就是把上述代码改成
|
||||
\begin{minted}{python}
|
||||
class PreProcessing:
|
||||
def tokenize(self):
|
||||
...
|
||||
with open(self.token_path, "w") as f:
|
||||
f.write(result)
|
||||
return result
|
||||
|
||||
def token_to_id(self):
|
||||
tokens = open(self.token_path).read()
|
||||
...
|
||||
with open(self.id_path, "w") as f:
|
||||
for id_ in ids:
|
||||
print(id_, file=f)
|
||||
return ids
|
||||
|
||||
def id_to_embedding(self, ids):
|
||||
with open(self.id_path, "r") as f:
|
||||
ids = [int(i) for i in f.readlines()]
|
||||
...
|
||||
paddle.save(embeddings, self.embedding_path)
|
||||
return embeddings
|
||||
|
||||
\end{minted}
|
||||
那这样的话,在第一次运行的时候,还需要判断文件是否存在,这也会导致复杂度提升。
|
||||
|
||||
并且最关键的问题是,从外部调用这些方法的时候,只看方法名称,不看文档,无法知道这个方法是有状态的还是无状态的,也就是说不知道这个方法是会把运行结果保存在文件中还是不保存,也不知道这个方法是否会从文件中读取内容。这样就非常不利于状态的统一管理。
|
||||
而且还有一个问题是面向对象很难将原先功能改成多进程并行处理,因为整个对象中保存了很多状态,而有些状态是在并行处理中用不到的,有些状态可能是需要用到并且需要共享的,这些状态如果没有很好地区分,就很难进行并行处理。
|
||||
|
||||
于是可以尝试使用函数式的方式改写上述功能:
|
||||
\begin{minted}{python}
|
||||
from pathlib import Path
|
||||
import asyncio
|
||||
|
||||
def tokenize(text):
|
||||
...
|
||||
return result
|
||||
|
||||
def token_to_id(token): # 注意这里的参数是单数,也就是单个token
|
||||
...
|
||||
return result
|
||||
|
||||
def id_to_embedding(ids): # 这里由于Embedding是矩阵形式,因此参数是复数
|
||||
...
|
||||
return result
|
||||
|
||||
def compose(*monads):
|
||||
asyncio.run(asyncio.gather(*monads))
|
||||
|
||||
async def monad(function, in_func=None, out_func=None): # 这样命名可能不太对,因为确实不太清楚这样是否符合真正的Monad的定义
|
||||
args = None
|
||||
if in_func:
|
||||
args = await in_func()
|
||||
result = function(args)
|
||||
if out_func:
|
||||
asyncio.create_task(lambda :await out_func(result))
|
||||
return result
|
||||
|
||||
def list_map(*args, **kwargs):
|
||||
return list(map(*args, **kwargs))
|
||||
|
||||
main = lambda token_path, id_path, embedding_path : compose(
|
||||
monad(tokenize,
|
||||
in_func=None,
|
||||
out_func=lambda x:Path(token_path).write_text(x)
|
||||
),
|
||||
monad(token_to_id,
|
||||
in_func=lambda :Path(token_path).read_text(),
|
||||
out_func=lambda file: lambda ids:list_map(
|
||||
lambda id_ : print(id_, file=file),
|
||||
ids)(open(id_path, "w")) # 这样写是为了完全使用函数式的写法,实际使用时如果这样写可读性非常差,而且Python有更多有用的语法,比如with,yield,列表解析式等,不太适合强行使用函数式
|
||||
),
|
||||
monad(id_to_embedding,
|
||||
in_func=lambda :list_map(int, Path(id_path).read_text().splitlines()),
|
||||
out_func=lambda embeddings:paddle.save(embeddings, embedding_path),
|
||||
),
|
||||
)
|
||||
|
||||
main(...)()
|
||||
\end{minted}
|
||||
|
||||
由于时间所限,一些细节可能不是非常准确,但总体思路大致就是这样,使用了函数式程序设计后,能非常清晰地看出数据的流动过程,以及什么时候使用了IO,并且能非常方便地改为并发执行。
|
||||
|
||||
不过也能看到,函数式程序设计也可能会导致代码可读性下降,虽然也可能是写得不太规范的原因。
|
||||
|
||||
\subsubsection{装饰器}
|
||||
装饰器实际上对应了函数式程序设计中高阶函数的概念,调用时传入一个函数,之后可以对这个函数进行修改,并且再返回。
|
||||
|
||||
例如,在Python中可以写一个测量函数调用需要的时间的装饰器:
|
||||
\begin{minted}{python}
|
||||
import time
|
||||
def measure_time(function):
|
||||
def inner(*args, **kwargs):
|
||||
start_time = time.time()
|
||||
result = function(*args, **kwargs)
|
||||
print(time.time() - start_time)
|
||||
return result
|
||||
return inner
|
||||
\end{minted}
|
||||
之后如果要测量一个函数的使用时间,就可以这样
|
||||
\begin{minted}[firstnumber=last]{python}
|
||||
@measure_time
|
||||
def test():
|
||||
time.sleep(1)
|
||||
|
||||
test()
|
||||
\end{minted}
|
||||
|
||||
那么在JavaScript中也可以有类似的实现(正式的JavaScript装饰器语法还在提案阶段,目前无法直接使用):
|
||||
\begin{minted}{javascript}
|
||||
const measure_time = func => (...args) => {
|
||||
const start_time = new Date();
|
||||
const result = func(...args);
|
||||
console.log(new Date() - start_time);
|
||||
return result;
|
||||
}
|
||||
|
||||
function func1(args) {
|
||||
do_some_thing(args);
|
||||
}
|
||||
|
||||
const func = measure_time(func1);
|
||||
func();
|
||||
\end{minted}
|
||||
|
||||
这里使用了JavaScript的箭头函数的语法特性,这种语法特性能非常方便地实现函数式程序设计的多种特性,如函数部分参数调用,柯里(curry)化等,详细内容可见参考文献\cite{zhihuJS1, zhihuJS2}。
|
||||
|
||||
同样,在C++中也可以实现装饰器的概念。
|
||||
\begin{minted}{cpp}
|
||||
#include <functional>
|
||||
#include <ctime>
|
||||
|
||||
template <typename RET, typename ... ARGS>
|
||||
std::function<RET(ARGS... args)> measure_time(std::function<RET(ARGS... args)> func) {
|
||||
return [=](ARGS... args) -> RET {
|
||||
time_t start_time = time(nullptr);
|
||||
RET result = func(args...);
|
||||
std::cout << time(nullptr) - start_time << std::endl;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
std::function<void(void)> do_something;
|
||||
|
||||
const func = measure_time(do_something);
|
||||
func();
|
||||
\end{minted}
|
||||
|
||||
上述代码参考\cite{zhihuc++1},同样也没经过测试,但大致思路体现了函数式程序设计的思想,包括lambda匿名函数等特性。
|
||||
|
||||
虽然不知道各种编程语言的装饰器是否是受到了函数式程序设计的启发,但可以看到它们都能实现装饰器的功能,这也是函数式程序设计在现代发展的体现。
|
||||
|
||||
\subsubsection{\LaTeX 排版}
|
||||
另一个非常需要函数式程序设计的思维的地方就是\LaTeX 排版了,在使用\LaTeX 的过程中,我曾经有这样一个需求:要在一个列表环境中使用多个\mintinline{latex}|\item|,但是它们有不同序号格式,比如有的格式是\mintinline{latex}|P\arabic{enumi}.|有的格式是\mintinline{latex}|R\arabic{enumi}.|,但是又希望序号能连续。因此在以前,只能使用\mintinline{latex}|\item[]|单独为每一项指定带格式的序号。但是在了解了函数式程序设计后,同时结合\LaTeX3的语法,写出了如下的\LaTeX 代码:
|
||||
\begin{minted}{latex}
|
||||
\def\getenum{%
|
||||
\ifnum\EnumitemId=1%
|
||||
enumi%
|
||||
\else
|
||||
\ifnum\EnumitemId=2%
|
||||
enumii%
|
||||
\else
|
||||
\ifnum\EnumitemId=3%
|
||||
enumiii%
|
||||
\else%
|
||||
enumiv%
|
||||
\fi
|
||||
\fi
|
||||
\fi%
|
||||
}
|
||||
|
||||
\ExplSyntaxOn
|
||||
\cs_set:Nn \rawquestionandanswer:Nnnn {%
|
||||
\ifstrequal{#2}{-}{}{\format_item:Nn #1{#2}} #3%
|
||||
#4%
|
||||
}
|
||||
\cs_set:Nn \format_item:Nn {
|
||||
\IfBlankTF{#2}{
|
||||
\stepcounter{\getenum}
|
||||
\item[#1{\csname the\getenum\endcsname}]
|
||||
% 完美结合了LaTeX2e和LaTeX3!
|
||||
}{
|
||||
\item[#1{#2}]
|
||||
}
|
||||
}
|
||||
\cs_set:Nn \Rformat:n {R#1.}
|
||||
\cs_set:Nn \Pformat:n {P#1.}
|
||||
\newcommand{\Rquestionandanswer}[3][]{%
|
||||
\rawquestionandanswer:Nnnn \Rformat:n {#1}{#2}{#3}
|
||||
}
|
||||
\newcommand{\Pquestionandanswer}[3][]{%
|
||||
\rawquestionandanswer:Nnnn \Pformat:n {#1}{#2}{#3}
|
||||
}
|
||||
\ExplSyntaxOff
|
||||
\end{minted}
|
||||
这里的\mintinline{latex}|\Rquestionandanswer|和\mintinline{latex}|\Pquestionandanswer|其实是使用了函数式程序设计中的部分参数调用的思想,对于原始的\mintinline{latex}|\rawquestionandanswer|,分别传入不同的格式,即\mintinline{latex}|\Rformat|和\mintinline{latex}|\Pformat|,形成了不同的函数,使用时直接调用\mintinline{latex}|\Rquestionandanswer|和\mintinline{latex}|\Pquestionandanswer|,传入剩余的参数,完成整个调用过程,这时之前定义的格式就会产生作用,形成不同的效果。
|
||||
|
||||
\subsection{总结}
|
||||
从上面这些例子中,我们可以看到虽然函数式程序设计听起来比较陌生,但其实它的思想在很多编程语言中早已有所体现。还要注意的是,在一些情况其实也不是很适合使用函数式程序设计,比如具有大量可变状态的图形用户界面。了解函数式程序设计,也许在目前来看,并不能给我们带来什么实质性的帮助,但也许受到了函数式的思想潜移默化的影响,在未来的某一天,实现某个功能的时候,突然就有了灵感,想到一个绝妙的设计方案。函数式程序设计归根结底还是一种编程范式,了解各种编程范式,一定不能生搬硬套,要学会灵活使用,最终达成高内聚低耦合的目的。
|
||||
|
||||
\phantomsection\addcontentsline{toc}{subsection}{参考文献} %将参考文献放进目录
|
||||
\bibliography{ref}
|
||||
\ifSubfilesClassLoaded{
|
||||
\stopcontents
|
||||
}{}
|
||||
\end{document}
|
191
离散数学/废稿.tex
Normal file
191
离散数学/废稿.tex
Normal file
@ -0,0 +1,191 @@
|
||||
|
||||
\newwrite\mywrite
|
||||
\immediate\openout\mywrite=\jobname.wrt
|
||||
\immediate\write\mywrite{abc}
|
||||
\immediate\closeout\mywrite
|
||||
|
||||
\newlength{\la}
|
||||
\settowidth{\la}{\fbox{这是一个带测量宽度的盒子}}
|
||||
\immediate\openout0=\jobname.txt
|
||||
\immediate\write0{\the\la}
|
||||
\immediate\closeout0
|
||||
% \ShellEscape{set /p xxx=&&wscript "msgbox \%xxx\%"}
|
||||
\immediate\write18{echo 222323}
|
||||
% \read
|
||||
\DeleteFile{\jobname.wrt}
|
||||
|
||||
|
||||
% \newenvironment{myenv}
|
||||
% {\begin{quotation}\small\itshape}{\end{quotation}}
|
||||
|
||||
% \newcommand{\replaced}[2][\relax]{\renewcommand{\tmpbox}{\fboxsep#1\colorbox{red}{\tmpbox}\par}\tmpbox}
|
||||
|
||||
|
||||
% \begin{myenv}
|
||||
% This is a test sentence.
|
||||
% \end{myenv}
|
||||
|
||||
% \replaced[10pt]{\begin{myenv}
|
||||
% This is another test sentence.
|
||||
% \end{myenv}}
|
||||
|
||||
% \newcommand{\code}[1]{\colorbox[RGB]{245,245,245}{\texttt{\detokenize{#1}}}}
|
||||
% ...
|
||||
% \code{std::string this_is_a_string = "\n";}
|
||||
% \xpatchcmd{\regex_replace_all:NnN}{hello}{goodbye}{\typeout{Patched!}}{\typeout{Patching failed!}}
|
||||
\ExplSyntaxOn
|
||||
|
||||
|
||||
% \newenvironment{zhongwen}{
|
||||
% \newsavebox{\rawinput}
|
||||
% \begin{lrbox}{\rawinput}
|
||||
% }{
|
||||
% \end{lrbox}
|
||||
% \immediate\write18{echo `\unhcopy\rawinput` > output.txt}
|
||||
% \newwrite\mywrite
|
||||
% \immediate\openout\mywrite=\jobname.wrt
|
||||
% \immediate\write\mywrite{\unhcopy\rawinput}
|
||||
% \regex_replace_all:nnN{a}{ifrfe}{\usebox{\rawinput}}
|
||||
% \unhcopy\rawinput
|
||||
% \unhcopy\rawinput
|
||||
% \unhcopy\rawinput
|
||||
% \immediate\write\mywrite{\unhcopy\rawinput}
|
||||
% \immediate\closeout\mywrite
|
||||
% }
|
||||
|
||||
% \newenvironment{zhongwen}{
|
||||
% \regex_replace_all:nnN{at}{is}
|
||||
% \begingroup
|
||||
% }{
|
||||
% % \egroup
|
||||
% \endgroup
|
||||
% }
|
||||
|
||||
% https://www.jianshu.com/p/6dfd27b7bd90
|
||||
|
||||
\cs_new:Nn \my_add:nn {
|
||||
#1 + #2
|
||||
}
|
||||
\int_eval:n {
|
||||
\my_add:nn {123} {456}
|
||||
}
|
||||
\str_new:N \temp
|
||||
\cs_new:Nn \zhongwenfunction:n {
|
||||
\str_set:NV \temp {#1}
|
||||
\regex_replace_all:nnN{[^\x00-\xff]+}{\\text\{\0\}}{\temp}
|
||||
% \temp
|
||||
\immediate\openout0=\jobname.zhongwen
|
||||
\immediate\write0{\temp}
|
||||
\immediate\closeout0
|
||||
\input{\jobname.zhongwen}
|
||||
% \DeleteFile{\jobname.zhongwen}
|
||||
% \new
|
||||
}
|
||||
\NewEnviron{myenv}{\zhongwenfunction:n{\BODY}}
|
||||
% \zhongwenfunction:n {
|
||||
% $$
|
||||
% a at is at is.
|
||||
% 中文
|
||||
% 中文2让中文
|
||||
% $$
|
||||
% }
|
||||
\begin{myenv}
|
||||
$$
|
||||
a at is at is.
|
||||
中文
|
||||
中文2让中文
|
||||
$$
|
||||
\end{myenv}
|
||||
|
||||
\NewEnviron{zhongwen}{
|
||||
\ExplSyntaxOn
|
||||
\str_set:NV \temp {\BODY}
|
||||
\regex_replace_all:nnN{[^\x00-\xff]+}{\\text\{\0\}}{\temp}
|
||||
% 应该可以使用\ifwindows和\iflinux来判断临时文件目录从而把临时文件放到临时文件目录里的
|
||||
\immediate\openout0=\jobname.zhongwen
|
||||
\immediate\write0{\temp}
|
||||
\immediate\closeout0
|
||||
\input{\jobname.zhongwen}
|
||||
\DeleteFile{\jobname.zhongwen}
|
||||
\ExplSyntaxOff
|
||||
}
|
||||
|
||||
\begin{zhongwen}
|
||||
$$
|
||||
中文中文
|
||||
飞机及哦额叫哦哦我i哦飞机饿哦i就发我哦佛偈哦哦哦挖机
|
||||
$$
|
||||
\end{zhongwen}
|
||||
|
||||
\newcommand{\mycommand}[1]{\expandafter\def\csname myenv\endcsname{#1}}
|
||||
\mycommand{abc}
|
||||
\verb|\begin{myenv}abc\end{myenv}|
|
||||
|
||||
\def\foo{hello}
|
||||
\def\bar{world}
|
||||
\def\baz{!}
|
||||
|
||||
\foo\ \bar\ \baz
|
||||
|
||||
fefef
|
||||
|
||||
% \xdef\zhongwen{\regex_replace_all:nnN{at}{is}{\zhongwen}}
|
||||
|
||||
% \begin{zhongwen}
|
||||
% a at is at is.
|
||||
% \end{zhongwen}
|
||||
|
||||
\def\openbox#1{\setbox#1=\hbox\bgroup}
|
||||
\def\closebox#1{\egroup\usebox#1}
|
||||
\openbox0 ... \closebox0
|
||||
|
||||
% \zhongwen {23232at is ao is at .}
|
||||
% \xdef\mycommand{$2323$}
|
||||
% \newsavebox{\mybox}
|
||||
|
||||
% \begin{lrbox}{\mybox}
|
||||
% fwojefjoiwejfio
|
||||
% \end{lrbox}
|
||||
|
||||
% \usebox{\mybox}
|
||||
% \usebox{\mybox}
|
||||
% \usebox{\mybox}
|
||||
% \usebox{\mybox}
|
||||
% \usebox{\mybox}
|
||||
|
||||
% \mycommand
|
||||
|
||||
|
||||
% \begin{zhongwen}
|
||||
% This is some text inside the environment.
|
||||
% \end{zhongwen}
|
||||
|
||||
% \xdef\myvariable{\begin{zhongwen}}
|
||||
% \expandafter\xdef\expandafter\myvariable\expandafter{\myvariable\end{zhongwen}}
|
||||
|
||||
|
||||
\str_new:N \l_my_tl
|
||||
\str_set:Nn \l_my_tl { That~cat. }
|
||||
\l_my_tl
|
||||
\regex_replace_all:nnN { at } { is } \l_my_tl
|
||||
\l_my_tl
|
||||
|
||||
% \regex_replace_once:nnn { at } { is } {This is a sample text with some words.} 11515632
|
||||
% \regex_replace_all:NnN
|
||||
% \replace
|
||||
% \regex_replace_all:nnn{\\b[a-z]+\\b}{X} This is a sample text with some words.
|
||||
% {<->}
|
||||
% {<*>}
|
||||
|
||||
换行
|
||||
|
||||
换行
|
||||
|
||||
换行
|
||||
\ExplSyntaxOff
|
||||
|
||||
换行
|
||||
|
||||
换行
|
||||
|
||||
换行
|
109
网络安全基础/实验报告/mypreamble.tex
Normal file
109
网络安全基础/实验报告/mypreamble.tex
Normal file
@ -0,0 +1,109 @@
|
||||
\usepackage[margin=1in]{geometry}
|
||||
\usepackage{longtable}
|
||||
\usepackage{booktabs}
|
||||
\usepackage{zhnumber} % change section number to chinese
|
||||
% \usepackage{enumerate}
|
||||
\usepackage{enumitem}
|
||||
\usepackage{titlesec}
|
||||
\usepackage{fancyhdr}
|
||||
\usepackage{environ} % 加了这个再\def\myitem就不报错了
|
||||
% \usepackage[outputdir=./latex-output]{minted}
|
||||
\usepackage{float} % https://blog.csdn.net/qq_32623363/article/details/101095168
|
||||
\usepackage{fp}
|
||||
\usepackage{graphicx} % 原来includegraphics要使用参数要用graphicx,只是用graphics是没法带参数的
|
||||
\usepackage{tabularx}
|
||||
\usepackage{array}
|
||||
\usepackage{ragged2e}
|
||||
\usepackage{multirow}
|
||||
\usepackage{url}
|
||||
\usepackage{color}
|
||||
\usepackage{mylatex}
|
||||
\usepackage{totpages} % 不加这个会导致总页数出错
|
||||
\pagestyle{fancyplain}
|
||||
\fancyhead{}
|
||||
\fancyhead[C]{华东师范大学计算机科学与技术学院上机实践报告}
|
||||
\fancyfoot[C]{第 \thepage 页\quad 共 \ref{TotPages} 页}
|
||||
\renewcommand\thesection{\zhnum{section}}
|
||||
\renewcommand \thesubsection {\arabic{subsection}}
|
||||
\setlist[1]{label=\zhnum{enumi}、}
|
||||
\setlist[2]{labelindent=-1em, leftmargin=*, label=\arabic{enumii}、\ }
|
||||
\setlist[3]{listparindent=2em, leftmargin=*, label=\arabic{enumiii}、\ }
|
||||
\definecolor{shadecolor}{RGB}{204,232,207}
|
||||
|
||||
\newcommand{\mydate}{
|
||||
2023年11月3日
|
||||
}
|
||||
|
||||
\newcommand{\mychapternum}{
|
||||
1
|
||||
}
|
||||
|
||||
\newcommand{\mylabname}{
|
||||
|
||||
}
|
||||
|
||||
\newcommand{\myname}{
|
||||
姓名
|
||||
}
|
||||
|
||||
\newcommand{\mystudentnum}{
|
||||
e.g. 12345678902
|
||||
}
|
||||
|
||||
\input{myprivatepreamble}
|
||||
|
||||
\newcommand{\mytitle}{
|
||||
\title{\fontsize{15}{0}华东师范大学计算机科学与技术学院上机实践报告\vspace{-2em}}
|
||||
\date{}
|
||||
\maketitle
|
||||
|
||||
\begin{center}
|
||||
\begin{tabularx}{\textwidth}{XXl}
|
||||
\toprule
|
||||
\textbf{课程名称}:网络安全基础 & \textbf{年级}:2022级 & \textbf{上机实践日期}:\mydate \\
|
||||
\textbf{指导教师}:黄新力 & \textbf{姓名}:\myname & \textbf{学号}:\mystudentnum \\
|
||||
\multicolumn{3}{l}{\textbf{实验名称}:实验\zhnumber{\mychapternum}\quad\mylabname} \\
|
||||
\bottomrule
|
||||
\end{tabularx}
|
||||
\end{center}
|
||||
\addtocounter{table}{-1}
|
||||
\vspace{1em}
|
||||
}
|
||||
|
||||
\newcommand{\myitemx}[3][]{
|
||||
\item \textbf{#2}
|
||||
\begin{enumerate}[#1]
|
||||
#3
|
||||
\end{enumerate}
|
||||
}
|
||||
|
||||
% https://blog.csdn.net/u010801696/article/details/79477226
|
||||
\def\UrlBreaks{\do\A\do\B\do\C\do\D\do\E\do\F\do\G\do\H\do\I\do\J
|
||||
\do\K\do\L\do\M\do\N\do\O\do\P\do\Q\do\R\do\S\do\T\do\U\do\V
|
||||
\do\W\do\X\do\Y\do\Z\do\[\do\\\do\]\do\^\do\_\do\`\do\a\do\b
|
||||
\do\c\do\d\do\e\do\f\do\g\do\h\do\i\do\j\do\k\do\l\do\m\do\n
|
||||
\do\o\do\p\do\q\do\r\do\s\do\t\do\u\do\v\do\w\do\x\do\y\do\z
|
||||
\do\.\do\@\do\\\do\/\do\!\do\_\do\|\do\;\do\>\do\]\do\)\do\,
|
||||
\do\?\do\'\do+\do\=\do\#}
|
||||
|
||||
\renewcommand{\thefigure}{\mychapternum-\arabic{figure}}
|
||||
\renewcommand{\thetable}{\mychapternum-\arabic{table}}
|
||||
|
||||
|
||||
% https://mirrors.pku.edu.cn/ctan/info/svg-inkscape/InkscapePDFLaTeX.pdf
|
||||
% 这个只有PDFLaTeX才能用,filemod也是
|
||||
% \newcommand{\executeiffilenewer}[3]{%
|
||||
% \ifnum\pdfstrcmp{\pdffilemoddate{#1}}%
|
||||
% {\pdffilemoddate{#2}}>0%
|
||||
% {\immediate\write18{#3}}\fi%
|
||||
% }
|
||||
|
||||
|
||||
% 该命令用于控制 p{} 的情况
|
||||
\newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}}p{#1}} % 使用过程中,将p{4cm}换成P{4cm},小写改成大写即可!
|
||||
% 该命令用于控制 X 的情况
|
||||
\newcolumntype{Z}{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}X} % 使用过程中,将Z 换成 X,即可!
|
||||
|
||||
% 可利用 RaggedLeft Centering替换RaggedRight,实现靠右和居中 [代码对大小写敏感!!!!!!!!!!!!!!!!!!!!!!!!!!!!]
|
||||
|
||||
% 原文链接:https://blog.csdn.net/wanjiac/article/details/107494424
|
38
网络安全基础/实验报告/实验一.tex
Normal file
38
网络安全基础/实验报告/实验一.tex
Normal file
@ -0,0 +1,38 @@
|
||||
\documentclass[a4paper]{ctexart}
|
||||
\input{mypreamble}
|
||||
\renewcommand{\mychapternum}{1}
|
||||
\renewcommand{\mylabname}{DES演示}
|
||||
\renewcommand{\mydate}{2024年3月26日}
|
||||
% \setlength{\textheight}{10000em}
|
||||
% \setlength{\paperheight}{10000em}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{实验目的}{
|
||||
\item DES单步加密演示实验
|
||||
\item DES算法演示实验
|
||||
\item 3DES 算法演示实验
|
||||
}
|
||||
\myitem{实验设备}{
|
||||
\item 49.52.5.80 上的虚拟机
|
||||
}
|
||||
\myitem{实验原理}{
|
||||
\item DES加密和解密
|
||||
}
|
||||
\myitemx[itemsep=1em]{实验步骤}{
|
||||
\item 见下页图:
|
||||
\begin{figure}[h]
|
||||
\centering
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1712027504144.png}
|
||||
\hfil
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1712027734857.png}
|
||||
\hfil
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1712027834513.png}
|
||||
\end{figure}
|
||||
}
|
||||
\myitem{实验结果总结}{
|
||||
\item 本次实验通过优良的图形用户界面、清晰的演示,使我清晰地了解了DES加密和解密的过程。
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
55
网络安全基础/实验报告/实验七.tex
Normal file
55
网络安全基础/实验报告/实验七.tex
Normal file
@ -0,0 +1,55 @@
|
||||
\documentclass[a4paper]{ctexart}
|
||||
\input{mypreamble}
|
||||
\renewcommand{\mychapternum}{7}
|
||||
\renewcommand{\mylabname}{素性、原根、ECC与SSH}
|
||||
\renewcommand{\mydate}{2024年5月7日}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{实验目的}{
|
||||
\item 素性测试编码实验
|
||||
\item 原根编码实验
|
||||
\item ECC签名编码实验(复习)
|
||||
\item 基于SSH协议的安全通信实验
|
||||
}
|
||||
\myitem{实验设备}{
|
||||
\item 49.52.5.80 上的虚拟机
|
||||
}
|
||||
\myitem{实验原理}{
|
||||
\item 素性、原根、ECC与SSH
|
||||
}
|
||||
\myitem{实验结果总结}{
|
||||
\item 本次实验介绍了素性测试与原根检测的原理与方法,并且使用Python和C++实现了素性测试与原根检测的功能。还介绍了SSH协议,并且使用OpenSSH实现了两台主机之间的安全通信。
|
||||
}
|
||||
\myitem{实验步骤}{
|
||||
\centering
|
||||
\item 素性测试编码实验
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-07-09-58-45.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-05-07-10-08-15.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1715047774229.png}
|
||||
|
||||
\item 原根编码实验
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-07-10-16-17.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-05-07-10-23-03.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1715048653431.png}
|
||||
|
||||
\item ECC签名编码实验(复习)
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-30-10-16-25.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-30-10-20-48.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-04-30-10-27-44.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1714444150414.png}
|
||||
|
||||
\item 基于SSH协议的安全通信实验
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-07-10-51-59.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-05-07-10-52-17.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-07-10-54-57.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-05-07-10-56-27.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1715050674206.png}
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
49
网络安全基础/实验报告/实验三.tex
Normal file
49
网络安全基础/实验报告/实验三.tex
Normal file
@ -0,0 +1,49 @@
|
||||
\documentclass[a4paper]{ctexart}
|
||||
\input{mypreamble}
|
||||
\renewcommand{\mychapternum}{3}
|
||||
\renewcommand{\mylabname}{AES、RSA、OpenSSL}
|
||||
\renewcommand{\mydate}{2024年4月9日}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{实验目的}{
|
||||
\item AES单步加密演示实验
|
||||
\item AES算法演示实验
|
||||
\item AES编码实验
|
||||
\item RSA编码实验
|
||||
\item 大数运算编码实验
|
||||
\item 利用对称密码对文件加密实验
|
||||
}
|
||||
\myitem{实验设备}{
|
||||
\item 49.52.5.80 上的虚拟机
|
||||
}
|
||||
\myitem{实验原理}{
|
||||
\item DES加密和解密
|
||||
}
|
||||
\myitemx[itemsep=1em]{实验步骤}{
|
||||
\item \includegraphics[height=1\textheight]{imgs/screen_shot_1712627647454.png}
|
||||
\item \includegraphics[width=1\linewidth]{imgs/2024-04-09-10-02-21.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-04-09-10-12-48.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1712628827832.png}
|
||||
\item \includegraphics[width=1\linewidth]{imgs/2024-04-09-10-23-14.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-09-10-27-20.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-09-10-30-15.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1712629869991.png}
|
||||
\item \includegraphics[width=1\linewidth]{imgs/2024-04-09-10-37-27.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-09-10-39-36.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-09-10-45-05.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1712630769193.png}
|
||||
\item \includegraphics[width=1\linewidth]{imgs/2024-04-09-10-54-36.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-04-09-10-57-28.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1712631488755.png}
|
||||
\item \includegraphics[width=1\linewidth]{imgs/2024-04-09-11-08-20.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-09-11-11-40.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-09-11-13-55.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1712632499452.png}
|
||||
}
|
||||
\myitem{实验结果总结}{
|
||||
\item 本实验使我充分了解了AES加密和解密的过程,以及RSA加密和解密的过程,中间还补充了大数运算相关的知识,最后的OpenSSL的介绍以及命令行的调用也非常实用。
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
51
网络安全基础/实验报告/实验九.tex
Normal file
51
网络安全基础/实验报告/实验九.tex
Normal file
@ -0,0 +1,51 @@
|
||||
\documentclass[a4paper]{ctexart}
|
||||
\input{mypreamble}
|
||||
\renewcommand{\mychapternum}{9}
|
||||
\renewcommand{\mylabname}{Linux身份认证管理}
|
||||
\renewcommand{\mydate}{2024年5月21日}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{实验目的}{
|
||||
\item Linux环境下使用openssl制作CA
|
||||
\item Linux环境下CA的日常操作
|
||||
\item Linux环境下CA签发数字证书
|
||||
}
|
||||
\myitem{实验设备}{
|
||||
\item 49.52.5.80 上的虚拟机
|
||||
}
|
||||
\myitem{实验原理}{
|
||||
\item Linux身份认证管理、PKI
|
||||
}
|
||||
\myitem{实验结果总结}{
|
||||
\item 本实验在Linux中使用openssl命令实现了CA的建立,用户申请证书的请求,CA对请求进行验证和颁发证书,CA吊销证书以及公布证书吊销列表等操作。学会独立创建自签名证书后,对日常的服务器维护非常有帮助。
|
||||
}
|
||||
\myitem{实验步骤}{
|
||||
\centering
|
||||
\item Linux环境下使用openssl制作CA
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-21-09-54-21.png}
|
||||
可以看到,操作机似乎并不是Kali。
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-21-10-04-10.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-05-21-10-09-51.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1716257454007.png}
|
||||
|
||||
\item Linux环境下CA的日常操作
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-21-10-23-04.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-21-10-24-57.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-21-10-26-59.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-21-10-28-34.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-05-21-10-30-02.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1716258740491.png}
|
||||
|
||||
\item Linux环境下CA签发数字证书
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-21-10-41-09.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-21-10-44-33.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-05-21-10-46-41.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1716259651372.png}
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
37
网络安全基础/实验报告/实验二.tex
Normal file
37
网络安全基础/实验报告/实验二.tex
Normal file
@ -0,0 +1,37 @@
|
||||
\documentclass[a4paper]{ctexart}
|
||||
\input{mypreamble}
|
||||
\renewcommand{\mychapternum}{2}
|
||||
\renewcommand{\mylabname}{DES使用}
|
||||
\renewcommand{\mydate}{2024年4月2日}
|
||||
% \setlength{\textheight}{500em}
|
||||
% \setlength{\paperheight}{500em}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{实验目的}{
|
||||
\item DES编码实验
|
||||
\item 3DES编码实验
|
||||
\item DES加解密实验
|
||||
}
|
||||
\myitem{实验设备}{
|
||||
\item 49.52.5.80 上的虚拟机
|
||||
}
|
||||
\myitem{实验原理}{
|
||||
\item DES加密和解密
|
||||
}
|
||||
\myitemx[itemsep=1em]{实验步骤}{
|
||||
\item \includegraphics[width=1\linewidth]{imgs/2024-04-02-10-19-09.png}
|
||||
\item \includegraphics[width=1\linewidth]{imgs/2024-04-02-10-31-48.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-02-10-37-08.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-02-10-38-14.png}
|
||||
\item \includegraphics[width=1\linewidth]{imgs/2024-04-02-10-46-20.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-02-10-47-50.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-02-10-49-48.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-02-10-50-41.png}
|
||||
}
|
||||
\myitem{实验结果总结}{
|
||||
\item 本实验使我充分了解了DES的加密和解密的过程,以及如何在Linux中使用Python和C实现DES、3DES的加密和解密。
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
58
网络安全基础/实验报告/实验五.tex
Normal file
58
网络安全基础/实验报告/实验五.tex
Normal file
@ -0,0 +1,58 @@
|
||||
\documentclass[a4paper]{ctexart}
|
||||
\input{mypreamble}
|
||||
\renewcommand{\mychapternum}{5}
|
||||
\renewcommand{\mylabname}{RSA}
|
||||
\renewcommand{\mydate}{2024年4月23日}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{实验目的}{
|
||||
\item RSA算法演示实验
|
||||
\item 算法编程演示实验
|
||||
\item 数字签名-RSA编码实验
|
||||
\item 加解密文本实验
|
||||
}
|
||||
\myitem{实验设备}{
|
||||
\item 49.52.5.80 上的虚拟机
|
||||
}
|
||||
\myitem{实验原理}{
|
||||
\item RSA加密和解密
|
||||
}
|
||||
\myitem{实验结果总结}{
|
||||
\item 本次实验使我更深刻地了解了RSA的加密和解密过程,以及如何使用C调用RSA的加密和解密流程,并且使用了OpenSSL的命令行工具实现了文本(或文件)的加密和解密。
|
||||
}
|
||||
\myitem{实验步骤}{
|
||||
\centering
|
||||
\item RSA算法演示实验
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-23-10-04-28.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-04-23-10-09-55.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1713838260195.png}
|
||||
|
||||
\item 算法编程演示实验
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-23-10-20-00.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-23-10-21-49.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-23-10-22-15.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-23-10-23-40.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-23-10-25-16.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-04-23-10-27-29.png}
|
||||
% \includegraphics[height=1\textheight]{imgs/screen_shot_1713839398250.png}
|
||||
|
||||
\item 数字签名-RSA编码实验
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-23-10-40-55.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-23-10-42-03.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-04-23-10-44-01.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1713840359131.png}
|
||||
|
||||
\item 加解密文本实验
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-23-11-16-08.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-04-23-11-17-22.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-04-23-11-19-40.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1713842407814.png}
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
67
网络安全基础/实验报告/实验八.tex
Normal file
67
网络安全基础/实验报告/实验八.tex
Normal file
@ -0,0 +1,67 @@
|
||||
\documentclass[a4paper]{ctexart}
|
||||
\input{mypreamble}
|
||||
\renewcommand{\mychapternum}{8}
|
||||
\renewcommand{\mylabname}{Windows身份认证管理}
|
||||
\renewcommand{\mydate}{2024年5月14日}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{实验目的}{
|
||||
\item Windows环境下独立根CA的安装和使用
|
||||
\item Windows环境下证书服务管理
|
||||
\item Windows环境下配置基于Web的SSL连接
|
||||
}
|
||||
\myitem{实验设备}{
|
||||
\item 49.52.5.80 上的虚拟机
|
||||
}
|
||||
\myitem{实验原理}{
|
||||
\item Windows身份认证管理、PKI
|
||||
}
|
||||
\myitem{实验结果总结}{
|
||||
\item 本次实验使用Windows Server 2008,完整演示了CA的建立,以及网站所有者如何向CA申请证书,CA如何颁发证书,如何吊销证书以及发布吊销列表,网站所有者如何使用颁发的证书将网站配置HTTPS服务。并且使用Sniffer工具说明了HTTPS相比于HTTP,将通信的数据进行了加密,更安全。
|
||||
}
|
||||
\myitem{实验步骤}{
|
||||
\centering
|
||||
\item Windows环境下独立根CA的安装和使用
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-14-10-01-20.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-14-10-03-31.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-14-10-05-51.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-14-10-07-04.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-14-10-07-53.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-14-10-08-57.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-14-10-10-43.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-14-10-12-37.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-14-10-18-53.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1715653239167_cr.png}
|
||||
|
||||
\item Windows环境下证书服务管理
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-14-10-34-51.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-14-10-35-22.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-14-10-37-33.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-14-10-38-14.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-14-10-38-53.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-14-10-39-55.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-05-14-10-40-29.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1715654506247_cr.png}
|
||||
|
||||
\item Windows环境下配置基于Web的SSL连接
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-14-10-52-20.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-14-10-53-01.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-14-10-54-33.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-14-10-55-32.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-14-11-00-10.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-14-11-02-14.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-14-11-04-23.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-14-11-07-20.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-14-11-09-45.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-14-11-10-21.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-14-11-11-59.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-05-14-11-14-24.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1715656554255_cr.png}
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
52
网络安全基础/实验报告/实验六.tex
Normal file
52
网络安全基础/实验报告/实验六.tex
Normal file
@ -0,0 +1,52 @@
|
||||
\documentclass[a4paper]{ctexart}
|
||||
\input{mypreamble}
|
||||
\renewcommand{\mychapternum}{6}
|
||||
\renewcommand{\mylabname}{数字签名}
|
||||
\renewcommand{\mydate}{2024年4月30日}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{实验目的}{
|
||||
\item DSA数字签名演示实验
|
||||
\item ECC签名编码实验
|
||||
\item DSA签名算法实验
|
||||
}
|
||||
\myitem{实验设备}{
|
||||
\item 49.52.5.80 上的虚拟机
|
||||
}
|
||||
\myitem{实验原理}{
|
||||
\item 数字签名
|
||||
}
|
||||
\myitem{实验结果总结}{
|
||||
\item 本次实验使我更深刻地了解了数字签名的概念、ECC和DSA算法的过程、以及如何使用Python实现数字签名。而且,在Linux中使用GPG创建自己的数字签名的过程使我了解了如何在开源代码仓库中对自己发布的发行版进行签名,以便他人验证。
|
||||
}
|
||||
\myitem{实验步骤}{
|
||||
\centering
|
||||
\item DSA数字签名演示实验
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-30-10-01-44.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-04-30-10-04-43.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1714442775208.png}
|
||||
|
||||
\item ECC签名编码实验
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-30-10-16-25.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-30-10-20-48.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-04-30-10-27-44.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1714444150414.png}
|
||||
|
||||
\item DSA签名算法实验
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-30-10-49-29.png}
|
||||
|
||||
由于虚拟机中没有执行很多“琐事/other action”,熵不够多,所以生成随机字节非常慢。这里就直接在服务器里执行了,可以发现由于服务器同时运行的东西很多,所以很快就生成完毕了。
|
||||
|
||||
\includegraphics[height=1\textheight]{imgs/2024-04-30-10-53-27.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-30-10-54-25.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-04-30-10-56-50.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-04-30-11-02-25.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1714446369702.png}
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
64
网络安全基础/实验报告/实验十.tex
Normal file
64
网络安全基础/实验报告/实验十.tex
Normal file
@ -0,0 +1,64 @@
|
||||
\documentclass[a4paper]{ctexart}
|
||||
\input{mypreamble}
|
||||
\renewcommand{\mychapternum}{10}
|
||||
\renewcommand{\mylabname}{协议分析和应用分析}
|
||||
\renewcommand{\mydate}{2024年5月28日}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{实验目的}{
|
||||
\item 协议分析-ARP协议解码详解
|
||||
\item 协议分析-ICMP协议解码详解
|
||||
\item 协议分析-IP协议解码详解
|
||||
\item 协议分析-TCP协议解码详解
|
||||
\item 应用分析-FTP文件传输应用分析
|
||||
}
|
||||
\myitem{实验设备}{
|
||||
\item 49.52.5.80 上的虚拟机
|
||||
}
|
||||
\myitem{实验原理}{
|
||||
\item ARP、ICMP、IP、TCP、FTP协议
|
||||
}
|
||||
\myitem{实验结果总结}{
|
||||
\item 本次实验使用科来网络分析系统,分析了ARP、ICMP、IP、TCP、FTP协议,实验步骤简洁有效,Windows XP与Windows Server 2003的操作系统复古怀旧,引起了我对曾经使用Windows XP系统的时光的回忆。
|
||||
}
|
||||
\myitem{实验步骤}{
|
||||
\centering
|
||||
\item 协议分析-ARP协议解码详解
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-28-09-57-29.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-28-09-58-33.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-28-10-02-11.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-28-10-03-12.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1716861848242.png}
|
||||
|
||||
\item 协议分析-ICMP协议解码详解
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-28-10-10-31.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-28-10-12-43.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-28-10-13-21.png}
|
||||
|
||||
\item 协议分析-IP协议解码详解
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-28-10-18-32.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-28-10-21-35.png}
|
||||
|
||||
\item 协议分析-TCP协议解码详解
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-28-10-32-16.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-28-10-32-51.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-28-10-34-13.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-28-10-34-39.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-28-10-35-43.png}
|
||||
|
||||
\item 应用分析-FTP文件传输应用分析
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-28-10-40-42.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-28-10-43-39.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-28-10-44-18.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-28-10-46-49.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-28-10-48-38.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-05-28-10-53-04.png}
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
76
网络安全基础/实验报告/实验十一.tex
Normal file
76
网络安全基础/实验报告/实验十一.tex
Normal file
@ -0,0 +1,76 @@
|
||||
\documentclass[a4paper]{ctexart}
|
||||
\input{mypreamble}
|
||||
\renewcommand{\mychapternum}{11}
|
||||
\renewcommand{\mylabname}{Windows系统VPN配置和Linux系统VPN配置}
|
||||
\renewcommand{\mydate}{2024年6月4日}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{实验目的}{
|
||||
\item Windows下IPSec安全通信实验
|
||||
\item Windows下IPSec VPN实验
|
||||
\item Windows下PPTP VPN实验
|
||||
\item Linux下PPTP服务器建设
|
||||
\item Linux下Openswan环境的搭建
|
||||
}
|
||||
\myitem{实验设备}{
|
||||
\item 49.52.5.80 上的虚拟机
|
||||
}
|
||||
\myitem{实验原理}{
|
||||
\item Windows系统VPN配置和Linux系统VPN配置
|
||||
}
|
||||
\myitem{实验结果总结}{
|
||||
\item 本次实验在Windows和Linux环境下分别进行了IPSec和PPTP等工作在不同层的VPN服务器的搭建,并且成功使用户登录了VPN服务器。VPN服务器的搭建过程并不容易,但复杂的步骤也间接确保了VPN的安全。
|
||||
}
|
||||
\myitem{实验步骤}{
|
||||
\centering
|
||||
\item Windows下IPSec安全通信实验
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-04-10-17-53.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-04-10-21-40.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-04-10-22-03.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1717467952871.png}
|
||||
|
||||
\item Windows下IPSec VPN实验
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-04-10-38-16.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-04-10-41-52.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-04-10-46-45.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-04-10-47-29.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-04-10-47-50.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-04-10-50-18.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-06-04-11-11-46.png}
|
||||
% \includegraphics[height=1\textheight]{imgs/screen_shot_1717469660933.png}
|
||||
|
||||
\item Windows下PPTP VPN实验
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-04-10-56-13.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-04-10-57-26.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-04-10-58-10.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-04-10-58-53.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-04-10-59-12.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-04-10-59-51.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-04-11-01-08.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-04-11-02-18.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-04-11-06-00.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-04-11-06-20.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-04-11-06-41.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-06-04-11-11-13.png}
|
||||
% \includegraphics[height=1\textheight]{imgs/screen_shot_1717470799133.png}
|
||||
|
||||
\item Linux下PPTP服务器建设
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-04-13-39-45.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-04-13-48-52.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-06-04-14-06-45.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1717481283782.png}
|
||||
|
||||
\item Linux下Openswan环境的搭建
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-04-14-26-03.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-06-04-14-31-52.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1717482755989.png}
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
86
网络安全基础/实验报告/实验十二.tex
Normal file
86
网络安全基础/实验报告/实验十二.tex
Normal file
@ -0,0 +1,86 @@
|
||||
\documentclass[a4paper]{ctexart}
|
||||
\input{mypreamble}
|
||||
\renewcommand{\mychapternum}{12}
|
||||
\renewcommand{\mylabname}{防火墙}
|
||||
\renewcommand{\mydate}{2024年6月11日}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{实验目的}{
|
||||
\item[] 第1章 iptables基本应用
|
||||
\item 1.1 Iptables基本操作实验
|
||||
\item 1.2 Iptables服务器配置与管理实验
|
||||
\item 1.3 Iptables基本实验及抓包分析实验
|
||||
\item[] 第3章 其他防火墙配置与应用
|
||||
\item 3.1 Outpost Firewall配置与使用实验
|
||||
\item 3.2 普通包过滤实验
|
||||
\item 3.3 包过滤防火墙配置和应用实验
|
||||
}
|
||||
\myitem{实验设备}{
|
||||
\item 49.52.5.80 上的虚拟机
|
||||
}
|
||||
\myitem{实验原理}{
|
||||
\item iptables和其他防火墙
|
||||
}
|
||||
\myitem{实验结果总结}{
|
||||
\item 本次实验讲解并演示了iptables的配置,虽然在命令行里添加删除不像在Windows里直接图形化界面直观,但好处是可以结合其他脚本批量操作。也讲解了Windows中其他防火墙的使用方法,但都没有Windows自带的防火墙方便免费好用。综上所述,Linux自带的iptables和Windows自带的防火墙是最好用的。
|
||||
}
|
||||
\myitem{实验步骤}{
|
||||
\centering
|
||||
\item Iptables基本操作实验
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-10-05-37.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-10-14-57.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-10-17-18.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-10-19-18.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-10-20-16.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-06-11-10-24-45.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1718072829316.png}
|
||||
|
||||
\item Iptables服务器配置与管理实验
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-10-28-15.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-10-33-04.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-10-36-24.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-06-11-10-38-04.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1718073591055.png}
|
||||
|
||||
\item Iptables基本实验及抓包分析实验
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-10-43-10.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-10-45-54.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-10-52-05.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-10-53-49.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-10-54-25.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-06-11-10-56-25.png}
|
||||
% \includegraphics[height=1\textheight]{imgs/screen_shot_1718074625502.png}
|
||||
|
||||
\item Outpost Firewall配置与使用实验
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-10-58-57.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-10-59-36.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-11-03-12.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-11-03-57.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-11-05-57.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-11-07-18.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-06-11-11-08-29.png}
|
||||
% \includegraphics[height=0.5\textheight]{imgs/screen_shot_1718075351903.png}
|
||||
|
||||
\item 普通包过滤实验
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-11-11-08.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-11-12-28.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-11-12-48.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-11-14-55.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-11-15-36.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-11-15-58.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-11-17-07.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-06-11-11-18-23.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1718075930688.png}
|
||||
|
||||
\item 包过滤防火墙配置和应用实验
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-13-01-04.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-13-13-44.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-13-15-17.png}
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-06-11-13-15-46.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-06-11-13-17-14.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1718083090706.png}
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
78
网络安全基础/实验报告/实验四.tex
Normal file
78
网络安全基础/实验报告/实验四.tex
Normal file
@ -0,0 +1,78 @@
|
||||
\documentclass[a4paper]{ctexart}
|
||||
\input{mypreamble}
|
||||
\renewcommand{\mychapternum}{4}
|
||||
\renewcommand{\mylabname}{MD5、SHA}
|
||||
\renewcommand{\mydate}{2024年4月16日}
|
||||
|
||||
\begin{document}
|
||||
\mytitle
|
||||
\begin{enumerate}
|
||||
\myitem{实验目的}{
|
||||
\item MD5单步运算演示实验
|
||||
\item MD5算法演示实验
|
||||
\item SHA-1算法演示实验
|
||||
\item MD5编码实验
|
||||
\item SHA编码实验
|
||||
\item SHA2-224编码实验
|
||||
\item SHA2-256编码实验
|
||||
}
|
||||
\myitem{实验设备}{
|
||||
\item 49.52.5.80 上的虚拟机
|
||||
}
|
||||
\myitem{实验原理}{
|
||||
\item DES加密和解密
|
||||
}
|
||||
\myitem{实验结果总结}{
|
||||
\item 本实验使我充分了解了MD5和SHA系列算法的原理、过程,以及如何使用Python实现。
|
||||
}
|
||||
\myitem{实验步骤}{
|
||||
\centering
|
||||
|
||||
\item MD5单步运算演示实验
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-16-10-04-34.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-04-16-10-09-39.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1713233513479.png}
|
||||
|
||||
\item MD5算法演示实验
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-16-10-16-20.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-04-16-10-17-17.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1713233883411.png}
|
||||
|
||||
\item SHA-1算法演示实验
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-16-10-25-32.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-04-16-10-29-31.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1713234649231.png}
|
||||
|
||||
\item MD5编码实验
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-16-10-36-11.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-04-16-10-37-49.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-04-16-10-39-47.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1713235219043.png}
|
||||
|
||||
\item SHA编码实验
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-16-10-46-10.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-04-16-10-47-12.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-04-16-10-49-36.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1713235847126.png}
|
||||
|
||||
\item SHA-224编码实验
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-16-10-56-12.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-04-16-10-56-56.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-04-16-10-58-29.png}
|
||||
\includegraphics[height=1\textheight]{imgs/screen_shot_1713236353250.png}
|
||||
|
||||
\item SHA-256编码实验
|
||||
|
||||
\includegraphics[width=1\linewidth]{imgs/2024-04-16-11-02-37.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-04-16-11-03-57.png}
|
||||
\includegraphics[height=1\textheight]{imgs/2024-04-16-11-04-49.png}
|
||||
|
||||
}
|
||||
\end{enumerate}
|
||||
\end{document}
|
68
计算机系统结构/作业/mypreamble.tex
Normal file
68
计算机系统结构/作业/mypreamble.tex
Normal file
@ -0,0 +1,68 @@
|
||||
\usepackage{amssymb, amsfonts, amstext, amsmath, amsopn, amsthm}
|
||||
\usepackage{booktabs}
|
||||
\usepackage[framemethod=TikZ]{mdframed}
|
||||
% \usepackage[tikz]{bclogo}
|
||||
\usepackage{fontawesome5}
|
||||
\usepackage{tabularx}
|
||||
\usepackage{array}
|
||||
\usepackage{ragged2e}
|
||||
\usepackage{bm}
|
||||
\usepackage{hyperref}
|
||||
|
||||
\usepackage{fancyhdr}
|
||||
\usepackage{enumitem}
|
||||
\usepackage{totpages}
|
||||
\usepackage{mylatex}
|
||||
\usepackage{subfiles}
|
||||
|
||||
\title{《计算机系统结构》作业}
|
||||
\author{岳锦鹏}
|
||||
\newcommand{\mysignature}{10213903403 岳锦鹏}
|
||||
\date{2024年3月17日——2024年6月18日}
|
||||
\setlist[1]{listparindent=\parindent}
|
||||
\setlist[2]{label=\alph{enumii}.,listparindent=\parindent}
|
||||
\definecolor{shadecolor}{RGB}{204,232,207}
|
||||
\definecolor{verificationColor}{RGB}{85,206,255} % 这颜色误差确实有点大啊,目前手动调的
|
||||
|
||||
\newcommand{\complicateditem}[3]{
|
||||
\item[\textbf{#1}] [#2]<#3>
|
||||
}
|
||||
|
||||
\renewcommand{\questionandanswer}[3][]{%
|
||||
\begin{shaded}%
|
||||
\ifstrequal{#1}{-}{}{\item[\textbf{#1}]} #2%
|
||||
\end{shaded}%
|
||||
\begin{zhongwen}%
|
||||
#3%
|
||||
\end{zhongwen}%
|
||||
}
|
||||
|
||||
\newmdenv[%
|
||||
frametitle={%
|
||||
\tikz[]
|
||||
\node[anchor=east,rectangle,fill=verificationColor]
|
||||
{ \faIcon{search}\ 验证一下};}, %
|
||||
% frametitlerule=true, %
|
||||
% frametitlebelowskip=10pt, %
|
||||
roundcorner=5pt, %
|
||||
innertopmargin=10pt,linecolor=verificationColor,%
|
||||
linewidth=2pt,topline=true, %
|
||||
frametitleaboveskip=\dimexpr-\ht\strutbox\relax,
|
||||
]{verification}
|
||||
|
||||
% \newenvironment{verification}{
|
||||
% \begin{bclogo}[couleur=verificationColor, arrondi =0.1 , logo=\bcloupe, noborder=true]{验证一下}
|
||||
% }{
|
||||
% \end{bclogo}
|
||||
% }
|
||||
|
||||
\usemintedstyle{staroffice} % 虽然这个没有颜色区分操作符与操作数,但是对于数字的强调很重要,因为汇编中的这些立即数都是比较重要,同时注释的字体也比较正常没有花体
|
||||
|
||||
% 该命令用于控制 p{} 的情况
|
||||
\newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}}p{#1}} % 使用过程中,将p{4cm}换成P{4cm},小写改成大写即可!
|
||||
% 该命令用于控制 X 的情况
|
||||
\newcolumntype{Z}{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}X} % 使用过程中,将Z 换成 X,即可!
|
||||
|
||||
\let\kaishu\relax % 清除旧定义
|
||||
\newCJKfontfamily\kaishu{KaiTi}[AutoFakeBold] % 重定义 \kaishu
|
||||
\newcommand{\boldkai}[1]{{\bfseries\kaishu #1}}
|
5
计算机系统结构/作业/mysubpreamble.tex
Normal file
5
计算机系统结构/作业/mysubpreamble.tex
Normal file
@ -0,0 +1,5 @@
|
||||
\pagestyle{fancyplain}
|
||||
\fancyhead{}
|
||||
\fancyhead[C]{\mysignature}
|
||||
\fancyfoot[C]{第 \thepage 页\quad 共 \ref{TotPages} 页}
|
||||
% \definecolor{shadecolor}{named}{white}
|
12
计算机系统结构/作业/全部作业.tex
Normal file
12
计算机系统结构/作业/全部作业.tex
Normal file
@ -0,0 +1,12 @@
|
||||
\documentclass[a4paper]{ctexbook}
|
||||
\input{mypreamble}
|
||||
\begin{document}
|
||||
\maketitle
|
||||
\tableofcontents
|
||||
\subfile{第一章作业}
|
||||
\subfile{第二章作业}
|
||||
\subfile{第三章作业}
|
||||
\subfile{第四章作业}
|
||||
\subfile{第五章作业1}
|
||||
\subfile{第五章作业2}
|
||||
\end{document}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user